Skip to content

Commit

Permalink
fix: add to paused tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
raviteja83 committed May 21, 2024
1 parent 6903b7d commit f57c04b
Showing 1 changed file with 15 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 { isMobile } from '../internal';
import { HMSRemoteAudioTrack } from '../media/tracks';
import { HMSRemotePeer } from '../sdk/models/peer';
import { Store } from '../sdk/store';
Expand Down Expand Up @@ -40,6 +41,7 @@ export class AudioSinkManager {
private state = { ...INITIAL_STATE };
private listener?: HMSUpdateListener;
private timer: ReturnType<typeof setInterval> | null = null;
private autoUnpauseTimer: ReturnType<typeof setInterval> | null = null;
private earpieceSelected = false;

constructor(private store: Store, private deviceManager: DeviceManager, private eventBus: EventBus) {
Expand All @@ -48,6 +50,7 @@ export class AudioSinkManager {
this.eventBus.audioTrackUpdate.subscribe(this.handleTrackUpdate);
this.eventBus.deviceChange.subscribe(this.handleAudioDeviceChange);
this.startPollingForDevices();
this.startPollingToCheckPausedAudio();
}

setListener(listener?: HMSUpdateListener) {
Expand Down Expand Up @@ -99,6 +102,10 @@ export class AudioSinkManager {
clearInterval(this.timer);
this.timer = null;
}
if (this.autoUnpauseTimer) {
clearInterval(this.autoUnpauseTimer);
this.autoUnpauseTimer = null;
}
this.eventBus.audioTrackAdded.unsubscribe(this.handleTrackAdd);
this.eventBus.audioTrackRemoved.unsubscribe(this.handleTrackRemove);
this.eventBus.audioTrackUpdate.unsubscribe(this.handleTrackUpdate);
Expand Down Expand Up @@ -265,6 +272,14 @@ export class AudioSinkManager {
}
};

private startPollingToCheckPausedAudio = () => {
if (isMobile()) {
this.autoUnpauseTimer = setInterval(() => {
this.unpauseAudioTracks();
}, 5000);
}
};

private startPollingForDevices = () => {
// device change supported, no polling needed
if ('ondevicechange' in navigator.mediaDevices) {
Expand Down

0 comments on commit f57c04b

Please sign in to comment.