From ba6fa9b16b4d809aa25395f17119a16ab11f72fd Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Tue, 12 Mar 2024 17:26:43 +0530 Subject: [PATCH] feat: add polling --- examples/prebuilt-react-integration/src/App.jsx | 11 +---------- .../src/audio-sink-manager/AudioSinkManager.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/examples/prebuilt-react-integration/src/App.jsx b/examples/prebuilt-react-integration/src/App.jsx index 14ef416ff4..e49ddcb9b1 100644 --- a/examples/prebuilt-react-integration/src/App.jsx +++ b/examples/prebuilt-react-integration/src/App.jsx @@ -4,14 +4,5 @@ import { getRoomCodeFromUrl } from './utils'; export default function App() { const roomCode = getRoomCodeFromUrl(); - return + return ; } 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 6bbbd1df07..e4764736f3 100644 --- a/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts +++ b/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts @@ -47,6 +47,7 @@ export class AudioSinkManager { this.eventBus.audioTrackRemoved.subscribe(this.handleTrackRemove); this.eventBus.audioTrackUpdate.subscribe(this.handleTrackUpdate); this.eventBus.deviceChange.subscribe(this.handleAudioDeviceChange); + this.startPollingForDevices(); } setListener(listener?: HMSUpdateListener) { @@ -266,6 +267,19 @@ export class AudioSinkManager { } }; + private startPollingForDevices = () => { + // device change supported, no polling needed + if ('ondevicechange' in navigator.mediaDevices) { + return; + } + this.timer = setInterval(() => { + (async () => { + await this.deviceManager.init(true, false); + await this.autoSelectAudioOutput(); + })(); + }, 5000); + }; + /** * Mweb is not able to play via call channel by default, this is to switch from media channel to call channel */