Skip to content

Commit

Permalink
fix: resume audio context on unblock autoplay
Browse files Browse the repository at this point in the history
  • Loading branch information
raviteja83 committed Dec 23, 2024
1 parent f961cb9 commit 6c676ec
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ErrorFactory } from '../error/ErrorFactory';
import { HMSAction } from '../error/HMSAction';
import { EventBus } from '../events/EventBus';
import { HMSDeviceChangeEvent, HMSTrackUpdate, HMSUpdateListener } from '../interfaces';
import { HMSAudioContextHandler } from '../internal';
import { HMSRemoteAudioTrack } from '../media/tracks';
import { HMSRemotePeer } from '../sdk/models/peer';
import { Store } from '../sdk/store';
Expand Down Expand Up @@ -74,6 +75,7 @@ export class AudioSinkManager {
if (this.autoPausedTracks.size > 0) {
await this.unpauseAudioTracks();
}
await HMSAudioContextHandler.resumeContext();
}

init(elementId?: string) {
Expand Down
4 changes: 4 additions & 0 deletions packages/hms-video-store/src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,10 @@ export class HMSSdk implements HMSInterface {
this.sdkState.isJoinInProgress = false;
await this.publish(config.settings, previewRole);
await this.deviceManager.autoSelectAudioOutput();
// Throw autoplay error even if audio context is suspended as it will be used in Audio Plugins which can lead to no audio
if (HMSAudioContextHandler.getAudioContext().state === 'suspended') {
this.listener?.onError(ErrorFactory.TracksErrors.AutoplayBlocked(HMSAction.JOIN));
}
} catch (error) {
this.analyticsTimer.end(TimedEvent.JOIN);
this.sdkState.isJoinInProgress = false;
Expand Down

0 comments on commit 6c676ec

Please sign in to comment.