Skip to content

Commit 2d57a6f

Browse files
committed
core: initialize RtcManagerDispatcher with remoteMediaOptions
1 parent 07a4845 commit 2d57a6f

6 files changed

Lines changed: 71 additions & 2 deletions

File tree

.changeset/common-clubs-fly.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@whereby.com/media": minor
3+
"@whereby.com/core": minor
4+
---
5+
6+
Add neverReceiveAudio p2p flag

packages/core/src/client/RoomConnection/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ export class RoomConnectionClient extends BaseClient<RoomConnectionState, RoomCo
318318
assistantKey: this.options.assistantKey || null,
319319
isNodeSdk: this.options.isNodeSdk || false,
320320
isAudioRecorder: this.options.isAudioRecorder ?? false,
321+
remoteMediaOptions: this.options.remoteMediaOptions ?? { receiveAudio: true, receiveVideo: true },
321322
};
322323

323324
this.store.dispatch(doAppStart(roomConfig));

packages/core/src/redux/slices/__tests__/app.unit.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe("appSlice", () => {
1212
isAudioRecorder: false,
1313
isDialIn: true,
1414
isNodeSdk: true,
15+
remoteMediaOptions: { receiveAudio: true, receiveVideo: false },
1516
roomKey: "roomKey",
1617
roomUrl: "https://some.url/roomName",
1718
userAgent: "userAgent",
@@ -29,6 +30,7 @@ describe("appSlice", () => {
2930
isAudioRecorder: false,
3031
isDialIn: true,
3132
isNodeSdk: true,
33+
remoteMediaOptions: { receiveAudio: true, receiveVideo: false },
3234
roomKey: "roomKey",
3335
roomName: "/roomName",
3436
roomUrl: "https://some.url/roomName",
@@ -57,6 +59,7 @@ describe("appSlice", () => {
5759
isAudioRecorder: false,
5860
isDialIn: false,
5961
isNodeSdk: true,
62+
remoteMediaOptions: { receiveAudio: true, receiveVideo: true },
6063
roomKey: "roomKey",
6164
roomName: "/roomName",
6265
roomUrl: "https://some.url/roomName",

packages/core/src/redux/slices/app.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { coreVersion } from "../../version";
77
* Reducer
88
*/
99

10+
type RemoteMediaOptions = { receiveVideo: boolean; receiveAudio: boolean };
1011
export interface AppConfig {
1112
assistantKey?: string | null;
1213
displayName: string;
@@ -16,6 +17,7 @@ export interface AppConfig {
1617
isDialIn?: boolean;
1718
isNodeSdk?: boolean;
1819
localMediaOptions?: LocalMediaOptions;
20+
remoteMediaOptions?: RemoteMediaOptions;
1921
roomKey: string | null;
2022
roomUrl: string;
2123
userAgent?: string;
@@ -31,6 +33,7 @@ export interface AppState {
3133
isAudioRecorder: boolean;
3234
isDialIn: boolean;
3335
isNodeSdk: boolean;
36+
remoteMediaOptions: RemoteMediaOptions;
3437
roomName: string | null;
3538
roomUrl: string | null;
3639
userAgent: string | null;
@@ -45,6 +48,7 @@ export const initialState: AppState = {
4548
isAudioRecorder: false,
4649
isDialIn: false,
4750
isNodeSdk: false,
51+
remoteMediaOptions: { receiveAudio: true, receiveVideo: true },
4852
roomName: null,
4953
roomUrl: null,
5054
userAgent: `core:${coreVersion}`,
@@ -95,3 +99,4 @@ export const selectAppExternalId = (state: RootState) => state.app.externalId;
9599
export const selectAppIsNodeSdk = (state: RootState) => state.app.isNodeSdk;
96100
export const selectAppInitialConfig = (state: RootState) => state.app.initialConfig;
97101
export const selectAppIgnoreBreakoutGroups = (state: RootState) => state.app.ignoreBreakoutGroups;
102+
export const selectAppRemoteMediaOptions = (state: RootState) => state.app.remoteMediaOptions;

packages/core/src/redux/slices/rtcConnection/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ import { selectSignalConnectionRaw, selectSignalConnectionSocket, socketReconnec
1414
import { createReactor, startAppListening } from "../../listenerMiddleware";
1515
import { selectRemoteClients, selectRemoteParticipants, streamStatusUpdated } from "../remoteParticipants";
1616
import { RemoteParticipant, StreamState } from "../../../RoomParticipant";
17-
import { selectAppIsNodeSdk, selectAppIsActive, doAppStop, selectAppIgnoreBreakoutGroups } from "../app";
17+
import {
18+
selectAppIsNodeSdk,
19+
selectAppIsActive,
20+
doAppStop,
21+
selectAppIgnoreBreakoutGroups,
22+
selectAppRemoteMediaOptions,
23+
} from "../app";
1824

1925
import {
2026
selectIsCameraEnabled,
@@ -208,6 +214,7 @@ export const doConnectRtc = createAppThunk(() => (dispatch, getState) => {
208214
const isCameraEnabled = selectIsCameraEnabled(state);
209215
const isMicrophoneEnabled = selectIsMicrophoneEnabled(state);
210216
const isNodeSdk = selectAppIsNodeSdk(state);
217+
const { receiveAudio, receiveVideo } = selectAppRemoteMediaOptions(state);
211218

212219
if (dispatcher || !socket) {
213220
return;
@@ -239,6 +246,7 @@ export const doConnectRtc = createAppThunk(() => (dispatch, getState) => {
239246
sfuVp9On: false,
240247
h264On: false,
241248
simulcastScreenshareOn: false,
249+
shouldReceiveMedia: { audio: receiveAudio, video: receiveVideo },
242250
},
243251
});
244252

packages/core/src/redux/tests/store/rtcConnection.spec.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ describe("actions", () => {
8888
roomName: null,
8989
roomUrl: null,
9090
userAgent: `core:${coreVersion}`,
91+
remoteMediaOptions: { receiveAudio: true, receiveVideo: true },
9192
},
9293
},
9394
});
@@ -109,6 +110,46 @@ describe("actions", () => {
109110
});
110111
});
111112
});
113+
114+
describe("when remoteMediaOptions is set", () => {
115+
it("initializes the RtcManagerDispatcher with that feature", () => {
116+
const store = createStore({
117+
withSignalConnection: true,
118+
initialState: {
119+
app: {
120+
displayName: null,
121+
externalId: null,
122+
ignoreBreakoutGroups: false,
123+
isActive: false,
124+
isAssistant: false,
125+
isAudioRecorder: false,
126+
isDialIn: false,
127+
isNodeSdk: false,
128+
roomName: null,
129+
roomUrl: null,
130+
userAgent: `core:${coreVersion}`,
131+
remoteMediaOptions: { receiveAudio: true, receiveVideo: false },
132+
},
133+
},
134+
});
135+
const before = store.getState().rtcConnection;
136+
137+
store.dispatch(doConnectRtc());
138+
139+
const after = store.getState().rtcConnection;
140+
141+
expect(RtcManagerDispatcher).toHaveBeenCalledTimes(1);
142+
expect(RtcManagerDispatcher).toHaveBeenCalledWith(
143+
expect.objectContaining({
144+
features: expect.objectContaining({ shouldReceiveMedia: { audio: true, video: false } }),
145+
}),
146+
);
147+
expect(diff(before, after)).toEqual({
148+
dispatcherCreated: true,
149+
rtcManagerDispatcher: expect.any(RtcManagerDispatcher),
150+
});
151+
});
152+
});
112153
});
113154

114155
it("doDisconnectRtc", () => {
@@ -164,7 +205,12 @@ describe("actions", () => {
164205
store.dispatch(doRtcManagerInitialize());
165206

166207
expect(mockRtcManager.addNewStream).toHaveBeenCalledTimes(1);
167-
expect(mockRtcManager.addNewStream).toHaveBeenCalledWith(CAMERA_STREAM_ID, store.getState().localMedia.stream, true, true);
208+
expect(mockRtcManager.addNewStream).toHaveBeenCalledWith(
209+
CAMERA_STREAM_ID,
210+
store.getState().localMedia.stream,
211+
true,
212+
true,
213+
);
168214
expect(store.getState().rtcConnection.rtcManagerInitialized).toBe(true);
169215
});
170216
});

0 commit comments

Comments
 (0)