Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persisting audio & video device selection across local peer's role change #3377

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/hms-video-store/src/device-manager/DeviceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export class DeviceManager implements HMSDeviceManager {
hasWebcamPermission = false;
hasMicrophonePermission = false;

currentSelection: SelectedDevices = {
raviteja83 marked this conversation as resolved.
Show resolved Hide resolved
audioInput: undefined,
videoInput: undefined,
audioOutput: undefined,
};

private readonly TAG = '[Device Manager]:';
private initialized = false;
private videoInputChanged = false;
Expand Down
45 changes: 40 additions & 5 deletions packages/hms-video-store/src/sdk/RoleChangeManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Store } from './store';
import { DeviceManager } from '../device-manager';
import { HMSRole } from '../interfaces';
import { DeviceType, HMSRole } from '../interfaces';
import InitialSettings from '../interfaces/settings';
import { SimulcastLayers } from '../interfaces/simulcast-layers';
import { HMSPeerUpdate, HMSTrackUpdate, HMSUpdateListener } from '../interfaces/update-listener';
Expand Down Expand Up @@ -144,14 +144,49 @@ export default class RoleChangeManager {
}

private getSettings(): InitialSettings {
const initialSettings = this.store.getConfig()?.settings;
const { isAudioMuted, isVideoMuted } = this.getMutedStatus();
const { audioInputDeviceId, audioOutputDeviceId } = this.getAudioDeviceSettings();
const videoDeviceId = this.getVideoInputDeviceId();
return {
isAudioMuted: isAudioMuted,
isVideoMuted: isVideoMuted,
audioInputDeviceId: audioInputDeviceId,
audioOutputDeviceId: audioOutputDeviceId,
videoDeviceId: videoDeviceId,
};
}

private getMutedStatus(): { isAudioMuted: boolean; isVideoMuted: boolean } {
const initialSettings = this.store.getConfig()?.settings;
return {
isAudioMuted: initialSettings?.isAudioMuted ?? true,
isVideoMuted: initialSettings?.isVideoMuted ?? true,
audioInputDeviceId: initialSettings?.audioInputDeviceId || 'default',
audioOutputDeviceId: initialSettings?.audioOutputDeviceId || 'default',
videoDeviceId: initialSettings?.videoDeviceId || 'default',
};
}

private getAudioDeviceSettings(): { audioInputDeviceId: string; audioOutputDeviceId: string } {
const initialSettings = this.store.getConfig()?.settings;
const audioInputDeviceId =
this.deviceManager.currentSelection[DeviceType.audioInput]?.deviceId ||
initialSettings?.audioInputDeviceId ||
'default';
const audioOutputDeviceId =
this.deviceManager.currentSelection[DeviceType.audioOutput]?.deviceId ||
initialSettings?.audioOutputDeviceId ||
'default';

return {
audioInputDeviceId,
audioOutputDeviceId,
};
}

private getVideoInputDeviceId(): string {
const initialSettings = this.store.getConfig()?.settings;
return (
this.deviceManager.currentSelection[DeviceType.videoInput]?.deviceId ||
initialSettings?.videoDeviceId ||
'default'
);
}
}
1 change: 1 addition & 0 deletions packages/hms-video-store/src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,7 @@ export class HMSSdk implements HMSInterface {
}

private handleLocalRoleUpdate = async ({ oldRole, newRole }: { oldRole: HMSRole; newRole: HMSRole }) => {
this.deviceManager.currentSelection = this.deviceManager.getCurrentSelection();
raviteja83 marked this conversation as resolved.
Show resolved Hide resolved
await this.transport.handleLocalRoleUpdate({ oldRole, newRole });
await this.roleChangeManager?.handleLocalPeerRoleUpdate({ oldRole, newRole });
await this.interactivityCenter.whiteboard.handleLocalRoleUpdate();
Expand Down