Skip to content

Commit

Permalink
fix: use retry for decode error
Browse files Browse the repository at this point in the history
  • Loading branch information
raviteja83 authored Dec 10, 2024
1 parent 9013a6a commit 7e19fbe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion packages/hms-video-store/src/device-manager/DeviceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 7e19fbe

Please sign in to comment.