Skip to content

Commit 4d1352d

Browse files
authored
fix: respect call type settings when applying persisted device preferеnces (#1879)
Before applying local preferences, we now check whether the appropriate device kind is enabled on the call type level. This is especially important for customers using default and audio-only call types in the same app. Although preferences can be kept under a different key depending on the call type, it is good to handle this in the hook itself, too.
1 parent dcb4f0a commit 4d1352d

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

packages/react-sdk/src/hooks/usePersistedDevicePreferences.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,11 @@ export const usePersistedDevicePreferences = (
7575
setApplyingState('applying');
7676

7777
(async () => {
78-
for (const [deviceKey, state, defaultMuted] of [
79-
['microphone', microphoneState, !settings.audio.mic_default_on],
80-
['camera', cameraState, !settings.video.camera_default_on],
81-
['speaker', speakerState, false],
78+
const { audio, video } = settings;
79+
for (const [deviceKey, state, defaultMuted, enabledInCallType] of [
80+
['microphone', microphoneState, !audio.mic_default_on, true],
81+
['camera', cameraState, !video.camera_default_on, video.enabled],
82+
['speaker', speakerState, false, true],
8283
] as const) {
8384
const preferences = parseLocalDevicePreferences(key);
8485
const preference = preferences[deviceKey];
@@ -91,8 +92,9 @@ export const usePersistedDevicePreferences = (
9192
manager,
9293
[preference].flat(),
9394
state.devices,
95+
enabledInCallType,
9496
)
95-
: applyMutedState(manager, defaultMuted);
97+
: applyMutedState(manager, defaultMuted, enabledInCallType);
9698

9799
await applyPromise.catch((err) => {
98100
console.warn(
@@ -327,6 +329,7 @@ const applyLocalDevicePreference = async (
327329
manager: DeviceManagerLike,
328330
preference: LocalDevicePreference[],
329331
devices: MediaDeviceInfo[],
332+
enabledInCallType: boolean,
330333
): Promise<void> => {
331334
let muted: boolean | undefined;
332335

@@ -352,12 +355,16 @@ const applyLocalDevicePreference = async (
352355
}
353356

354357
if (typeof muted === 'boolean') {
355-
await applyMutedState(manager, muted);
358+
await applyMutedState(manager, muted, enabledInCallType);
356359
}
357360
};
358361

359-
const applyMutedState = async (manager: DeviceManagerLike, muted: boolean) => {
360-
if (!manager.state.status) {
362+
const applyMutedState = async (
363+
manager: DeviceManagerLike,
364+
muted: boolean,
365+
enabledInCallType: boolean,
366+
) => {
367+
if (enabledInCallType && !manager.state.status) {
361368
await manager[muted ? 'disable' : 'enable']?.();
362369
}
363370
};

sample-apps/react/react-dogfood/components/Lobby.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@ export const Lobby = ({ onJoin, mode = 'regular' }: LobbyProps) => {
5353
useCallSession,
5454
useCallMembers,
5555
useCallCustomData,
56+
useCallSettings,
5657
} = useCallStateHooks();
5758
const { hasBrowserPermission: hasMicPermission } = useMicrophoneState();
5859
const { hasBrowserPermission: hasCameraPermission, isMute: isCameraMute } =
5960
useCameraState();
6061
const callSession = useCallSession();
6162
const members = useCallMembers();
63+
const settings = useCallSettings();
6264
const currentUser = useConnectedUser();
6365
const isProntoEnvironment = useIsProntoEnvironment();
6466
const isDemoEnvironment = useIsDemoEnvironment();
@@ -154,13 +156,15 @@ export const Lobby = ({ onJoin, mode = 'regular' }: LobbyProps) => {
154156
/>
155157
<div className="rd__lobby-media-toggle">
156158
<ToggleAudioPreviewButton Menu={null} />
157-
<ToggleVideoPreviewButton Menu={null} />
159+
{settings?.video.enabled && (
160+
<ToggleVideoPreviewButton Menu={null} />
161+
)}
158162
</div>
159163
</div>
160164
<div className="rd__lobby-controls">
161165
<div className="rd__lobby-media">
162166
<ToggleMicButton />
163-
<ToggleCameraButton />
167+
{settings?.video.enabled && <ToggleCameraButton />}
164168
</div>
165169

166170
<div className="rd__lobby-settings">

0 commit comments

Comments
 (0)