Skip to content

Commit

Permalink
fix: added error logs when failing to initialize audio sink
Browse files Browse the repository at this point in the history
  • Loading branch information
ygit committed Dec 11, 2024
1 parent 580d445 commit fbdec62
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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 @@ -82,6 +81,7 @@ export class AudioSinkManager {

init(elementId?: string) {
if (this.state.initialized || this.audioSink) {
HMSLogger.e(this.TAG, 'audio sink already initialized', this.audioSink);
return;
}
this.state.initialized = true;
Expand Down Expand Up @@ -144,20 +144,24 @@ export class AudioSinkManager {
audioEl.onerror = async () => {
HMSLogger.e(this.TAG, 'error on audio element', audioEl.error);
const ex = ErrorFactory.TracksErrors.AudioPlaybackError(
`Audio playback error for track - ${track.trackId} code - ${audioEl?.error?.code}`,
`Audio playback error for track - ${track.trackId} code - ${audioEl?.error?.code} ${audioEl?.error} ${track}`,
);
this.eventBus.analytics.publish(AnalyticsEventFactory.audioPlaybackError(ex));
if (audioEl?.error?.code === MediaError.MEDIA_ERR_DECODE) {
this.removeAudioElement(audioEl, track);
await sleep(500);
// await sleep(500);
await this.handleTrackAdd({ track, peer, callListener: false });
}
};
track.setAudioElement(audioEl);
track.setVolume(this.volume);
HMSLogger.d(this.TAG, 'Audio track added', `${track}`);
this.init(); // call to create sink element if not already created
this.audioSink?.append(audioEl);
if (this.audioSink) {
this.audioSink.append(audioEl);
} else {
HMSLogger.e(this.TAG, 'audio sink not initialized', this.audioSink);
}
this.outputDevice && (await track.setOutputDevice(this.outputDevice));
audioEl.srcObject = new MediaStream([track.nativeTrack]);
callListener && this.listener?.onTrackUpdate(HMSTrackUpdate.TRACK_ADDED, track, peer);
Expand Down Expand Up @@ -262,6 +266,8 @@ export class AudioSinkManager {
audioEl.srcObject = null;
audioEl.remove();
track.setAudioElement(null);
} else {
HMSLogger.e(this.TAG, 'Audio element not found', `${track}`);
}
};

Expand Down

0 comments on commit fbdec62

Please sign in to comment.