From 3905f08e9f00ff649d7e049e9585b59a89964ce3 Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Tue, 10 Dec 2024 20:31:12 +0530 Subject: [PATCH 1/2] fix: use retry for decode error --- .../src/audio-sink-manager/AudioSinkManager.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts b/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts index e61f53a60f..9359b0b88e 100644 --- a/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts +++ b/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts @@ -9,6 +9,7 @@ import { HMSRemoteAudioTrack } from '../media/tracks'; import { HMSRemotePeer } from '../sdk/models/peer'; import { Store } from '../sdk/store'; import HMSLogger from '../utils/logger'; +import { sleep } from '../utils/timer-utils'; /** * Following are the errors thrown when autoplay is blocked in different browsers @@ -137,11 +138,15 @@ export class AudioSinkManager { ); this.eventBus.analytics.publish(AnalyticsEventFactory.audioPlaybackError(ex)); if (audioEl?.error?.code === MediaError.MEDIA_ERR_DECODE) { - await track.setVolume(0); - await track.setVolume(this.volume); - this.eventBus.analytics.publish( - AnalyticsEventFactory.audioRecovered('Audio recovered after media decode error'), - ); + // try to wait for main execution to complete first + this.removeAudioElement(audioEl, track); + await sleep(500); + await this.handleTrackAdd({ track, peer, callListener: false }); + if (!this.state.autoplayFailed) { + this.eventBus.analytics.publish( + AnalyticsEventFactory.audioRecovered('Audio recovered after media decode error'), + ); + } } }; track.setAudioElement(audioEl); From e15ad22c7b35bdc6dcf556974a0f260db7882a9f Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Tue, 10 Dec 2024 20:32:55 +0530 Subject: [PATCH 2/2] fix: use retry for decode error --- packages/hms-video-store/src/device-manager/DeviceManager.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/hms-video-store/src/device-manager/DeviceManager.ts b/packages/hms-video-store/src/device-manager/DeviceManager.ts index 60939a00f2..3898560b06 100644 --- a/packages/hms-video-store/src/device-manager/DeviceManager.ts +++ b/packages/hms-video-store/src/device-manager/DeviceManager.ts @@ -483,7 +483,8 @@ export class DeviceManager implements HMSDeviceManager { */ // eslint-disable-next-line complexity public autoSelectAudioOutput = async () => { - if ('ondevicechange' in navigator.mediaDevices || !this.audioInputChanged) { + // do this only after join so the earpiece would be selected at the right time + if ('ondevicechange' in navigator.mediaDevices || !this.store.getLocalPeer()?.joinedAt) { return; } const { bluetoothDevice, earpiece, speakerPhone, wired } = this.categorizeAudioInputDevices();