diff --git a/packages/hms-video-store/src/device-manager/DeviceManager.ts b/packages/hms-video-store/src/device-manager/DeviceManager.ts index 8fedbc647c..60939a00f2 100644 --- a/packages/hms-video-store/src/device-manager/DeviceManager.ts +++ b/packages/hms-video-store/src/device-manager/DeviceManager.ts @@ -106,7 +106,6 @@ export class DeviceManager implements HMSDeviceManager { // do it only on initial load. if (!force) { await this.updateToActualDefaultDevice(); - await this.autoSelectAudioOutput(); this.startPollingForDevices(); } this.logDevices('Init'); @@ -134,12 +133,12 @@ export class DeviceManager implements HMSDeviceManager { } cleanup() { - this.initialized = false; - this.earpieceSelected = false; if (this.timer) { clearTimeout(this.timer); this.timer = null; } + this.initialized = false; + this.earpieceSelected = false; this.audioInput = []; this.audioOutput = []; this.videoInput = []; @@ -483,8 +482,8 @@ export class DeviceManager implements HMSDeviceManager { * Mweb is not able to play via call channel by default, this is to switch from media channel to call channel */ // eslint-disable-next-line complexity - private autoSelectAudioOutput = async () => { - if ('ondevicechange' in navigator.mediaDevices) { + public autoSelectAudioOutput = async () => { + if ('ondevicechange' in navigator.mediaDevices || !this.audioInputChanged) { return; } const { bluetoothDevice, earpiece, speakerPhone, wired } = this.categorizeAudioInputDevices(); diff --git a/packages/hms-video-store/src/sdk/index.ts b/packages/hms-video-store/src/sdk/index.ts index 50bd36b0eb..c74c5c2e8e 100644 --- a/packages/hms-video-store/src/sdk/index.ts +++ b/packages/hms-video-store/src/sdk/index.ts @@ -666,6 +666,7 @@ export class HMSSdk implements HMSInterface { await this.notifyJoin(); this.sdkState.isJoinInProgress = false; await this.publish(config.settings, previewRole); + await this.deviceManager.autoSelectAudioOutput(); } catch (error) { this.analyticsTimer.end(TimedEvent.JOIN); this.sdkState.isJoinInProgress = false;