From 4e164542c05f9dc6dec8ebc6e3b52ba6199cd1c0 Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Wed, 24 Jul 2024 19:16:36 +0530 Subject: [PATCH 01/28] feat: handling interruption events --- .../src/analytics/AnalyticsEventFactory.ts | 23 +++++++++++++++++++ .../src/media/tracks/HMSLocalAudioTrack.ts | 10 ++++++++ .../src/media/tracks/HMSLocalVideoTrack.ts | 10 ++++++++ 3 files changed, 43 insertions(+) diff --git a/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts b/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts index e387fa4991..a9f295fe36 100644 --- a/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts +++ b/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts @@ -7,6 +7,7 @@ import { HMSException } from '../error/HMSException'; import { DeviceMap, SelectedDevices } from '../interfaces'; import { HMSTrackSettings } from '../media/settings/HMSTrackSettings'; import { HMSRemoteVideoTrack } from '../media/tracks/HMSRemoteVideoTrack'; +import { HMSTrackType } from '../schema'; export default class AnalyticsEventFactory { private static KEY_REQUESTED_AT = 'requested_at'; @@ -256,6 +257,28 @@ export default class AnalyticsEventFactory { level: AnalyticsEventLevel.INFO, }); } + + static interrupionStart(type: HMSTrackType, deviceInfo: Partial) { + return new AnalyticsEvent({ + name: 'interruption.start', + level: AnalyticsEventLevel.INFO, + properties: { + type, + ...deviceInfo, + }, + }); + } + + static interrupionStop(type: HMSTrackType, deviceInfo: Partial) { + return new AnalyticsEvent({ + name: 'interruption.stop', + level: AnalyticsEventLevel.INFO, + properties: { + type, + ...deviceInfo, + }, + }); + } private static eventNameFor(name: string, ok: boolean) { const suffix = ok ? 'success' : 'failed'; return `${name}.${suffix}`; diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts index 2e3883660c..6bc01930bd 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts @@ -76,6 +76,16 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { private handleVisibilityChange = async () => { if (document.visibilityState === 'visible') { await this.replaceTrackWith(this.settings); + // stopped + AnalyticsEventFactory.interrupionStop(this.type, { + deviceId: this.settings.deviceId, + groupId: this.nativeTrack.getSettings().groupId, + }); + } else { + AnalyticsEventFactory.interrupionStart(this.type, { + deviceId: this.settings.deviceId, + groupId: this.nativeTrack.getSettings().groupId, + }); } }; diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index 0a19048514..1c8962fa1e 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -499,9 +499,19 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { this.enabledStateBeforeBackground = this.enabled; this.nativeTrack.enabled = false; this.replaceSenderTrack(this.nativeTrack); + // started interruption + AnalyticsEventFactory.interrupionStart(this.type, { + deviceId: this.settings.deviceId, + groupId: this.nativeTrack.getSettings().groupId, + }); } else { this.nativeTrack.enabled = this.enabledStateBeforeBackground; this.replaceSenderTrack(this.processedTrack || this.nativeTrack); + // stopped + AnalyticsEventFactory.interrupionStop(this.type, { + deviceId: this.settings.deviceId, + groupId: this.nativeTrack.getSettings().groupId, + }); } this.eventBus.localVideoEnabled.publish({ enabled: this.nativeTrack.enabled, track: this }); }; From a1fb3abd5847c6ae8deb7b761369ad50766c7653 Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Wed, 24 Jul 2024 19:36:43 +0530 Subject: [PATCH 02/28] fix: added audio disabling for mweb --- .../hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts | 6 +++--- .../hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts index 6bc01930bd..0f53fccb11 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts @@ -9,7 +9,7 @@ import { HMSAudioPlugin, HMSPluginSupportResult } from '../../plugins'; import { HMSAudioPluginsManager } from '../../plugins/audio'; import Room from '../../sdk/models/HMSRoom'; import HMSLogger from '../../utils/logger'; -import { isBrowser, isIOS } from '../../utils/support'; +import { isBrowser, isMobile } from '../../utils/support'; import { getAudioTrack, isEmptyTrack } from '../../utils/track'; import { TrackAudioLevelMonitor } from '../../utils/track-audio-level-monitor'; import { HMSAudioTrackSettings, HMSAudioTrackSettingsBuilder } from '../settings'; @@ -60,7 +60,7 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { } this.pluginsManager = new HMSAudioPluginsManager(this, eventBus, room); this.setFirstTrackId(track.id); - if (isIOS() && isBrowser) { + if (isMobile() && isBrowser) { document.addEventListener('visibilitychange', this.handleVisibilityChange); } } @@ -240,7 +240,7 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { this.processedTrack?.stop(); this.isPublished = false; this.destroyAudioLevelMonitor(); - if (isIOS() && isBrowser) { + if (isMobile() && isBrowser) { document.removeEventListener('visibilitychange', this.handleVisibilityChange); } } diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index 1c8962fa1e..395dd32985 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -499,6 +499,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { this.enabledStateBeforeBackground = this.enabled; this.nativeTrack.enabled = false; this.replaceSenderTrack(this.nativeTrack); + console.log('video invisible'); // started interruption AnalyticsEventFactory.interrupionStart(this.type, { deviceId: this.settings.deviceId, @@ -507,6 +508,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { } else { this.nativeTrack.enabled = this.enabledStateBeforeBackground; this.replaceSenderTrack(this.processedTrack || this.nativeTrack); + console.log('video visible'); // stopped AnalyticsEventFactory.interrupionStop(this.type, { deviceId: this.settings.deviceId, From e682d46be9a952c4e3112e5ad582a04c34014143 Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Wed, 24 Jul 2024 19:37:08 +0530 Subject: [PATCH 03/28] fix: remove load --- packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index 395dd32985..1c8962fa1e 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -499,7 +499,6 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { this.enabledStateBeforeBackground = this.enabled; this.nativeTrack.enabled = false; this.replaceSenderTrack(this.nativeTrack); - console.log('video invisible'); // started interruption AnalyticsEventFactory.interrupionStart(this.type, { deviceId: this.settings.deviceId, @@ -508,7 +507,6 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { } else { this.nativeTrack.enabled = this.enabledStateBeforeBackground; this.replaceSenderTrack(this.processedTrack || this.nativeTrack); - console.log('video visible'); // stopped AnalyticsEventFactory.interrupionStop(this.type, { deviceId: this.settings.deviceId, From 11fe2141928e574ecc75a22a3ac1b86e3d3e9288 Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Thu, 25 Jul 2024 10:47:26 +0530 Subject: [PATCH 04/28] fix: cleanup --- .../src/analytics/AnalyticsEventFactory.ts | 24 +++++++++---------- .../src/media/tracks/HMSLocalAudioTrack.ts | 13 ++++------ .../src/media/tracks/HMSLocalVideoTrack.ts | 14 ++++------- .../src/media/tracks/HMSTrack.ts | 12 +++++++++- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts b/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts index a9f295fe36..3dfd3af8ae 100644 --- a/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts +++ b/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts @@ -258,18 +258,17 @@ export default class AnalyticsEventFactory { }); } - static interrupionStart(type: HMSTrackType, deviceInfo: Partial) { - return new AnalyticsEvent({ - name: 'interruption.start', - level: AnalyticsEventLevel.INFO, - properties: { - type, - ...deviceInfo, - }, - }); - } - - static interrupionStop(type: HMSTrackType, deviceInfo: Partial) { + static interrupion(started: boolean, type: HMSTrackType, deviceInfo: Partial) { + if (started) { + return new AnalyticsEvent({ + name: 'interruption.start', + level: AnalyticsEventLevel.INFO, + properties: { + type, + ...deviceInfo, + }, + }); + } return new AnalyticsEvent({ name: 'interruption.stop', level: AnalyticsEventLevel.INFO, @@ -279,6 +278,7 @@ export default class AnalyticsEventFactory { }, }); } + private static eventNameFor(name: string, ok: boolean) { const suffix = ok ? 'success' : 'failed'; return `${name}.${suffix}`; diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts index 0f53fccb11..06dc0ddc78 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts @@ -76,16 +76,11 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { private handleVisibilityChange = async () => { if (document.visibilityState === 'visible') { await this.replaceTrackWith(this.settings); - // stopped - AnalyticsEventFactory.interrupionStop(this.type, { - deviceId: this.settings.deviceId, - groupId: this.nativeTrack.getSettings().groupId, - }); + // stopped interruption event + this.sendInterruptionEvent(false); } else { - AnalyticsEventFactory.interrupionStart(this.type, { - deviceId: this.settings.deviceId, - groupId: this.nativeTrack.getSettings().groupId, - }); + // started interruption event + this.sendInterruptionEvent(true); } }; diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index 1c8962fa1e..06429b6487 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -499,19 +499,13 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { this.enabledStateBeforeBackground = this.enabled; this.nativeTrack.enabled = false; this.replaceSenderTrack(this.nativeTrack); - // started interruption - AnalyticsEventFactory.interrupionStart(this.type, { - deviceId: this.settings.deviceId, - groupId: this.nativeTrack.getSettings().groupId, - }); + // started interruption event + this.sendInterruptionEvent(true); } else { this.nativeTrack.enabled = this.enabledStateBeforeBackground; this.replaceSenderTrack(this.processedTrack || this.nativeTrack); - // stopped - AnalyticsEventFactory.interrupionStop(this.type, { - deviceId: this.settings.deviceId, - groupId: this.nativeTrack.getSettings().groupId, - }); + // stopped interruption event + this.sendInterruptionEvent(false); } this.eventBus.localVideoEnabled.publish({ enabled: this.nativeTrack.enabled, track: this }); }; diff --git a/packages/hms-video-store/src/media/tracks/HMSTrack.ts b/packages/hms-video-store/src/media/tracks/HMSTrack.ts index b3c5574bb1..2c59758236 100644 --- a/packages/hms-video-store/src/media/tracks/HMSTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSTrack.ts @@ -1,4 +1,5 @@ import { HMSTrackType } from './HMSTrackType'; +import AnalyticsEventFactory from '../../analytics/AnalyticsEventFactory'; import { stringifyMediaStreamTrack } from '../../utils/json'; import HMSLogger from '../../utils/logger'; import { HMSMediaStream } from '../streams'; @@ -84,7 +85,16 @@ export abstract class HMSTrack { protected setFirstTrackId(trackId: string) { this.firstTrackId = trackId; } - + /** + * @internal + * It will send event to analytics when interruption start/stop + */ + protected sendInterruptionEvent(started: boolean) { + AnalyticsEventFactory.interrupion(started, this.type, { + deviceId: this.nativeTrack.getSettings().deviceId, + groupId: this.nativeTrack.getSettings().groupId, + }); + } /** * @internal * take care of - From 2a927b6ecc0e36641e7963e459b69ec0a72ffd32 Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Thu, 25 Jul 2024 16:33:57 +0530 Subject: [PATCH 05/28] fix: testing --- examples/prebuilt-react-integration/index.html | 2 +- .../src/analytics/AnalyticsEventFactory.ts | 12 +----------- .../src/audio-sink-manager/AudioSinkManager.ts | 13 +++++++++++++ .../src/media/tracks/HMSLocalAudioTrack.ts | 11 +++++------ .../src/media/tracks/HMSLocalVideoTrack.ts | 1 + .../hms-video-store/src/media/tracks/HMSTrack.ts | 4 +++- .../src/plugins/audio/HMSAudioPluginsManager.ts | 12 ++++++++++++ 7 files changed, 36 insertions(+), 19 deletions(-) diff --git a/examples/prebuilt-react-integration/index.html b/examples/prebuilt-react-integration/index.html index 895cbcd8ce..aee5d151bb 100644 --- a/examples/prebuilt-react-integration/index.html +++ b/examples/prebuilt-react-integration/index.html @@ -1,4 +1,4 @@ - + diff --git a/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts b/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts index 3dfd3af8ae..6b40afc38d 100644 --- a/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts +++ b/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts @@ -259,18 +259,8 @@ export default class AnalyticsEventFactory { } static interrupion(started: boolean, type: HMSTrackType, deviceInfo: Partial) { - if (started) { - return new AnalyticsEvent({ - name: 'interruption.start', - level: AnalyticsEventLevel.INFO, - properties: { - type, - ...deviceInfo, - }, - }); - } return new AnalyticsEvent({ - name: 'interruption.stop', + name: `${started ? 'interruption.start' : 'interruption.stop'}`, level: AnalyticsEventLevel.INFO, properties: { type, 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 6d1e667888..93997911f0 100644 --- a/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts +++ b/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts @@ -120,9 +120,20 @@ export class AudioSinkManager { const audioTrack = this.store.getTrackById(event.target.id); if (audioTrack) { this.autoPausedTracks.add(audioTrack as HMSRemoteAudioTrack); + // started interruption event + // audioTrack.sendInterruptionEvent(true); } }; + private handleAudioPlay = async (event: any) => { + // this means the audio replayed because of external factors(headset removal, incoming phone call) + HMSLogger.d(this.TAG, 'Audio Play', event.target.id); + const audioTrack = this.store.getTrackById(event.target.id); + if (audioTrack) { + // stopped interruption event + // audioTrack.sendInterruptionEvent(false); + } + }; private handleTrackUpdate = ({ track }: { track: HMSRemoteAudioTrack; enabled: boolean }) => { HMSLogger.d(this.TAG, 'Track updated', `${track}`); }; @@ -140,6 +151,7 @@ export class AudioSinkManager { audioEl.style.display = 'none'; audioEl.id = track.trackId; audioEl.addEventListener('pause', this.handleAudioPaused); + audioEl.addEventListener('play', this.handleAudioPlay); audioEl.onerror = async () => { HMSLogger.e(this.TAG, 'error on audio element', audioEl.error); @@ -259,6 +271,7 @@ export class AudioSinkManager { if (audioEl) { HMSLogger.d(this.TAG, 'removing audio element', `${track}`); audioEl.removeEventListener('pause', this.handleAudioPaused); + audioEl.removeEventListener('play', this.handleAudioPlay); audioEl.srcObject = null; audioEl.remove(); track.setAudioElement(null); diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts index 06dc0ddc78..0881373e2f 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts @@ -9,7 +9,7 @@ import { HMSAudioPlugin, HMSPluginSupportResult } from '../../plugins'; import { HMSAudioPluginsManager } from '../../plugins/audio'; import Room from '../../sdk/models/HMSRoom'; import HMSLogger from '../../utils/logger'; -import { isBrowser, isMobile } from '../../utils/support'; +import { isBrowser, isIOS } from '../../utils/support'; import { getAudioTrack, isEmptyTrack } from '../../utils/track'; import { TrackAudioLevelMonitor } from '../../utils/track-audio-level-monitor'; import { HMSAudioTrackSettings, HMSAudioTrackSettingsBuilder } from '../settings'; @@ -60,7 +60,7 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { } this.pluginsManager = new HMSAudioPluginsManager(this, eventBus, room); this.setFirstTrackId(track.id); - if (isMobile() && isBrowser) { + if (isIOS() && isBrowser) { document.addEventListener('visibilitychange', this.handleVisibilityChange); } } @@ -76,11 +76,10 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { private handleVisibilityChange = async () => { if (document.visibilityState === 'visible') { await this.replaceTrackWith(this.settings); - // stopped interruption event - this.sendInterruptionEvent(false); + // this.sendInterruptionEvent(false); } else { // started interruption event - this.sendInterruptionEvent(true); + // this.sendInterruptionEvent(true); } }; @@ -235,7 +234,7 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { this.processedTrack?.stop(); this.isPublished = false; this.destroyAudioLevelMonitor(); - if (isMobile() && isBrowser) { + if (isIOS() && isBrowser) { document.removeEventListener('visibilitychange', this.handleVisibilityChange); } } diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index 06429b6487..e6c12e9f47 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -495,6 +495,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { }; private handleVisibilityChange = async () => { + console.log('interruption> here ', document.visibilityState); if (document.visibilityState === 'hidden' && this.source === 'regular') { this.enabledStateBeforeBackground = this.enabled; this.nativeTrack.enabled = false; diff --git a/packages/hms-video-store/src/media/tracks/HMSTrack.ts b/packages/hms-video-store/src/media/tracks/HMSTrack.ts index 2c59758236..6aa355c8f3 100644 --- a/packages/hms-video-store/src/media/tracks/HMSTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSTrack.ts @@ -89,7 +89,9 @@ export abstract class HMSTrack { * @internal * It will send event to analytics when interruption start/stop */ - protected sendInterruptionEvent(started: boolean) { + sendInterruptionEvent(started: boolean) { + // @ts-ignore + console.log('interruption started ', started, this.type); AnalyticsEventFactory.interrupion(started, this.type, { deviceId: this.nativeTrack.getSettings().deviceId, groupId: this.nativeTrack.getSettings().groupId, diff --git a/packages/hms-video-store/src/plugins/audio/HMSAudioPluginsManager.ts b/packages/hms-video-store/src/plugins/audio/HMSAudioPluginsManager.ts index 649d556e75..61846130ae 100644 --- a/packages/hms-video-store/src/plugins/audio/HMSAudioPluginsManager.ts +++ b/packages/hms-video-store/src/plugins/audio/HMSAudioPluginsManager.ts @@ -200,6 +200,7 @@ export class HMSAudioPluginsManager { //Keeping it separate since we are initializing context only once async closeContext() { + this.audioContext?.removeEventListener('statechange', this.handleAudioContextState); this.audioContext?.close(); this.audioContext = undefined; } @@ -282,9 +283,19 @@ export class HMSAudioPluginsManager { plugin.stop(); this.analytics.removed(name); } + private handleAudioContextState() { + console.log('interruption> context state ', this.audioContext); + if (this.audioContext?.state === 'suspended') { + this.hmsTrack.sendInterruptionEvent(true); + } else if (this.audioContext?.state === 'running') { + this.hmsTrack.sendInterruptionEvent(false); + } + } private createAudioContext() { + console.log('interruption> here context'); if (!this.audioContext) { + console.log('interruption> present context'); if (checkBrowserSupport()) { /** Not setting default sample rate for firefox since connecting @@ -295,6 +306,7 @@ export class HMSAudioPluginsManager { } else { this.audioContext = new AudioContext({ sampleRate: DEFAULT_SAMPLE_RATE }); } + this.audioContext.addEventListener('statechange', this.handleAudioContextState); } } } From 5fc0f4390fdeb7867b29db847d7e6eae2916096f Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Thu, 25 Jul 2024 21:12:25 +0530 Subject: [PATCH 06/28] fix: testing audio context state --- .../src/plugins/audio/HMSAudioPluginsManager.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/hms-video-store/src/plugins/audio/HMSAudioPluginsManager.ts b/packages/hms-video-store/src/plugins/audio/HMSAudioPluginsManager.ts index 61846130ae..3967c5dd35 100644 --- a/packages/hms-video-store/src/plugins/audio/HMSAudioPluginsManager.ts +++ b/packages/hms-video-store/src/plugins/audio/HMSAudioPluginsManager.ts @@ -283,12 +283,12 @@ export class HMSAudioPluginsManager { plugin.stop(); this.analytics.removed(name); } - private handleAudioContextState() { - console.log('interruption> context state ', this.audioContext); - - if (this.audioContext?.state === 'suspended') { + private handleAudioContextState(ev: Event) { + const context = ev.currentTarget as AudioContext; + console.log('interruption> context state ', this.audioContext, context); + if (context?.state === 'suspended') { this.hmsTrack.sendInterruptionEvent(true); - } else if (this.audioContext?.state === 'running') { + } else if (context.state === 'running') { this.hmsTrack.sendInterruptionEvent(false); } } From 0856aee0c446197dfc261d141a4a6dc9d91a1f41 Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Fri, 26 Jul 2024 11:18:38 +0530 Subject: [PATCH 07/28] fix: updated to sinek manager --- .../src/analytics/AnalyticsEventFactory.ts | 3 +-- .../src/audio-sink-manager/AudioSinkManager.ts | 6 ++---- .../src/media/tracks/HMSLocalAudioTrack.ts | 4 ++-- .../src/media/tracks/HMSLocalVideoTrack.ts | 1 - .../hms-video-store/src/media/tracks/HMSTrack.ts | 6 ++---- .../src/plugins/audio/HMSAudioPluginsManager.ts | 14 +------------- 6 files changed, 8 insertions(+), 26 deletions(-) diff --git a/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts b/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts index 6b40afc38d..41bb17e6cd 100644 --- a/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts +++ b/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts @@ -7,7 +7,6 @@ import { HMSException } from '../error/HMSException'; import { DeviceMap, SelectedDevices } from '../interfaces'; import { HMSTrackSettings } from '../media/settings/HMSTrackSettings'; import { HMSRemoteVideoTrack } from '../media/tracks/HMSRemoteVideoTrack'; -import { HMSTrackType } from '../schema'; export default class AnalyticsEventFactory { private static KEY_REQUESTED_AT = 'requested_at'; @@ -258,7 +257,7 @@ export default class AnalyticsEventFactory { }); } - static interrupion(started: boolean, type: HMSTrackType, deviceInfo: Partial) { + static interrupion(started: boolean, type: string, deviceInfo: Partial) { return new AnalyticsEvent({ name: `${started ? 'interruption.start' : 'interruption.stop'}`, level: AnalyticsEventLevel.INFO, 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 93997911f0..1d1c7edf91 100644 --- a/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts +++ b/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts @@ -116,22 +116,20 @@ export class AudioSinkManager { private handleAudioPaused = async (event: any) => { // this means the audio paused because of external factors(headset removal, incoming phone call) - HMSLogger.d(this.TAG, 'Audio Paused', event.target.id); const audioTrack = this.store.getTrackById(event.target.id); if (audioTrack) { this.autoPausedTracks.add(audioTrack as HMSRemoteAudioTrack); // started interruption event - // audioTrack.sendInterruptionEvent(true); + audioTrack.sendInterruptionEvent(true, true); } }; private handleAudioPlay = async (event: any) => { // this means the audio replayed because of external factors(headset removal, incoming phone call) - HMSLogger.d(this.TAG, 'Audio Play', event.target.id); const audioTrack = this.store.getTrackById(event.target.id); if (audioTrack) { // stopped interruption event - // audioTrack.sendInterruptionEvent(false); + audioTrack.sendInterruptionEvent(false, true); } }; private handleTrackUpdate = ({ track }: { track: HMSRemoteAudioTrack; enabled: boolean }) => { diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts index 0881373e2f..0460713517 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts @@ -76,10 +76,10 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { private handleVisibilityChange = async () => { if (document.visibilityState === 'visible') { await this.replaceTrackWith(this.settings); - // this.sendInterruptionEvent(false); + this.sendInterruptionEvent(false); } else { // started interruption event - // this.sendInterruptionEvent(true); + this.sendInterruptionEvent(true); } }; diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index e6c12e9f47..06429b6487 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -495,7 +495,6 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { }; private handleVisibilityChange = async () => { - console.log('interruption> here ', document.visibilityState); if (document.visibilityState === 'hidden' && this.source === 'regular') { this.enabledStateBeforeBackground = this.enabled; this.nativeTrack.enabled = false; diff --git a/packages/hms-video-store/src/media/tracks/HMSTrack.ts b/packages/hms-video-store/src/media/tracks/HMSTrack.ts index 6aa355c8f3..cd34ddc4a2 100644 --- a/packages/hms-video-store/src/media/tracks/HMSTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSTrack.ts @@ -89,10 +89,8 @@ export abstract class HMSTrack { * @internal * It will send event to analytics when interruption start/stop */ - sendInterruptionEvent(started: boolean) { - // @ts-ignore - console.log('interruption started ', started, this.type); - AnalyticsEventFactory.interrupion(started, this.type, { + sendInterruptionEvent(started: boolean, isRemoteAudio = false) { + AnalyticsEventFactory.interrupion(started, isRemoteAudio ? 'remote.audio' : this.type, { deviceId: this.nativeTrack.getSettings().deviceId, groupId: this.nativeTrack.getSettings().groupId, }); diff --git a/packages/hms-video-store/src/plugins/audio/HMSAudioPluginsManager.ts b/packages/hms-video-store/src/plugins/audio/HMSAudioPluginsManager.ts index 3967c5dd35..649d556e75 100644 --- a/packages/hms-video-store/src/plugins/audio/HMSAudioPluginsManager.ts +++ b/packages/hms-video-store/src/plugins/audio/HMSAudioPluginsManager.ts @@ -200,7 +200,6 @@ export class HMSAudioPluginsManager { //Keeping it separate since we are initializing context only once async closeContext() { - this.audioContext?.removeEventListener('statechange', this.handleAudioContextState); this.audioContext?.close(); this.audioContext = undefined; } @@ -283,19 +282,9 @@ export class HMSAudioPluginsManager { plugin.stop(); this.analytics.removed(name); } - private handleAudioContextState(ev: Event) { - const context = ev.currentTarget as AudioContext; - console.log('interruption> context state ', this.audioContext, context); - if (context?.state === 'suspended') { - this.hmsTrack.sendInterruptionEvent(true); - } else if (context.state === 'running') { - this.hmsTrack.sendInterruptionEvent(false); - } - } + private createAudioContext() { - console.log('interruption> here context'); if (!this.audioContext) { - console.log('interruption> present context'); if (checkBrowserSupport()) { /** Not setting default sample rate for firefox since connecting @@ -306,7 +295,6 @@ export class HMSAudioPluginsManager { } else { this.audioContext = new AudioContext({ sampleRate: DEFAULT_SAMPLE_RATE }); } - this.audioContext.addEventListener('statechange', this.handleAudioContextState); } } } From 1a3ff2d19ce2e46e14c520d8a9ce2a15d652da70 Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Fri, 26 Jul 2024 11:31:28 +0530 Subject: [PATCH 08/28] fix: added log --- packages/hms-video-store/src/media/tracks/HMSTrack.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/hms-video-store/src/media/tracks/HMSTrack.ts b/packages/hms-video-store/src/media/tracks/HMSTrack.ts index cd34ddc4a2..20c74e64f6 100644 --- a/packages/hms-video-store/src/media/tracks/HMSTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSTrack.ts @@ -90,6 +90,7 @@ export abstract class HMSTrack { * It will send event to analytics when interruption start/stop */ sendInterruptionEvent(started: boolean, isRemoteAudio = false) { + console.log('interruption> event ', isRemoteAudio, this.type, started); AnalyticsEventFactory.interrupion(started, isRemoteAudio ? 'remote.audio' : this.type, { deviceId: this.nativeTrack.getSettings().deviceId, groupId: this.nativeTrack.getSettings().groupId, From d6f7650dbd8179bb03540cb111fd27302b8237d2 Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Fri, 26 Jul 2024 13:33:58 +0530 Subject: [PATCH 09/28] fix: added logs --- .../src/media/tracks/HMSLocalAudioTrack.ts | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts index 0460713517..8da9185079 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts @@ -9,7 +9,6 @@ import { HMSAudioPlugin, HMSPluginSupportResult } from '../../plugins'; import { HMSAudioPluginsManager } from '../../plugins/audio'; import Room from '../../sdk/models/HMSRoom'; import HMSLogger from '../../utils/logger'; -import { isBrowser, isIOS } from '../../utils/support'; import { getAudioTrack, isEmptyTrack } from '../../utils/track'; import { TrackAudioLevelMonitor } from '../../utils/track-audio-level-monitor'; import { HMSAudioTrackSettings, HMSAudioTrackSettingsBuilder } from '../settings'; @@ -41,6 +40,12 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { */ isPublished = false; + /** + * mark true when interrupted + * @internal + */ + isInterrupted = false; + constructor( stream: HMSLocalStream, track: MediaStreamTrack, @@ -60,9 +65,7 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { } this.pluginsManager = new HMSAudioPluginsManager(this, eventBus, room); this.setFirstTrackId(track.id); - if (isIOS() && isBrowser) { - document.addEventListener('visibilitychange', this.handleVisibilityChange); - } + document.addEventListener('visibilitychange', this.handleVisibilityChange); } getManuallySelectedDeviceId() { @@ -74,12 +77,21 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { } private handleVisibilityChange = async () => { - if (document.visibilityState === 'visible') { + console.log( + 'interruption> audio visible ', + this.nativeTrack.readyState, + this.nativeTrack.muted, + document.visibilityState, + this.isInterrupted, + ); + if (this.nativeTrack.readyState !== 'ended' && !this.nativeTrack.muted && document.visibilityState !== 'visible') { + this.sendInterruptionEvent(true); + this.isInterrupted = true; + } + if (document.visibilityState === 'visible' && this.isInterrupted) { await this.replaceTrackWith(this.settings); this.sendInterruptionEvent(false); - } else { - // started interruption event - this.sendInterruptionEvent(true); + this.isInterrupted = false; } }; @@ -234,9 +246,7 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { this.processedTrack?.stop(); this.isPublished = false; this.destroyAudioLevelMonitor(); - if (isIOS() && isBrowser) { - document.removeEventListener('visibilitychange', this.handleVisibilityChange); - } + document.removeEventListener('visibilitychange', this.handleVisibilityChange); } /** From 45fe4773668e819c5dc592bcba9bac77cb3b0539 Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Mon, 29 Jul 2024 12:44:32 +0530 Subject: [PATCH 10/28] fix: interruption eventing testing --- .../audio-sink-manager/AudioSinkManager.ts | 15 ++++----------- .../src/media/tracks/HMSLocalAudioTrack.ts | 19 +++++++++++-------- .../src/media/tracks/HMSLocalVideoTrack.ts | 13 +++++++++++-- .../src/media/tracks/HMSTrack.ts | 3 ++- 4 files changed, 28 insertions(+), 22 deletions(-) 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 1d1c7edf91..177aee0b45 100644 --- a/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts +++ b/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts @@ -120,18 +120,13 @@ export class AudioSinkManager { if (audioTrack) { this.autoPausedTracks.add(audioTrack as HMSRemoteAudioTrack); // started interruption event - audioTrack.sendInterruptionEvent(true, true); + audioTrack.sendInterruptionEvent({ + started: true, + isRemoteAudio: true, + }); } }; - private handleAudioPlay = async (event: any) => { - // this means the audio replayed because of external factors(headset removal, incoming phone call) - const audioTrack = this.store.getTrackById(event.target.id); - if (audioTrack) { - // stopped interruption event - audioTrack.sendInterruptionEvent(false, true); - } - }; private handleTrackUpdate = ({ track }: { track: HMSRemoteAudioTrack; enabled: boolean }) => { HMSLogger.d(this.TAG, 'Track updated', `${track}`); }; @@ -149,7 +144,6 @@ export class AudioSinkManager { audioEl.style.display = 'none'; audioEl.id = track.trackId; audioEl.addEventListener('pause', this.handleAudioPaused); - audioEl.addEventListener('play', this.handleAudioPlay); audioEl.onerror = async () => { HMSLogger.e(this.TAG, 'error on audio element', audioEl.error); @@ -269,7 +263,6 @@ export class AudioSinkManager { if (audioEl) { HMSLogger.d(this.TAG, 'removing audio element', `${track}`); audioEl.removeEventListener('pause', this.handleAudioPaused); - audioEl.removeEventListener('play', this.handleAudioPlay); audioEl.srcObject = null; audioEl.remove(); track.setAudioElement(null); diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts index 8da9185079..4bf606dba5 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts @@ -78,19 +78,22 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { private handleVisibilityChange = async () => { console.log( - 'interruption> audio visible ', - this.nativeTrack.readyState, - this.nativeTrack.muted, - document.visibilityState, - this.isInterrupted, + `interruption> video visible readyState=> ${this.nativeTrack.readyState}, + muted=> ${this.nativeTrack.muted}, + visiblity=> ${document.visibilityState}, + isInterrupted=> ${this.isInterrupted}`, ); - if (this.nativeTrack.readyState !== 'ended' && !this.nativeTrack.muted && document.visibilityState !== 'visible') { - this.sendInterruptionEvent(true); + if (this.nativeTrack.readyState === 'ended' && this.nativeTrack.muted && document.visibilityState !== 'visible') { + this.sendInterruptionEvent({ + started: true, + }); this.isInterrupted = true; } if (document.visibilityState === 'visible' && this.isInterrupted) { await this.replaceTrackWith(this.settings); - this.sendInterruptionEvent(false); + this.sendInterruptionEvent({ + started: false, + }); this.isInterrupted = false; } }; diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index 06429b6487..6ef1e3f0af 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -495,17 +495,26 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { }; private handleVisibilityChange = async () => { + console.log( + `interruption> video visible readyState=> ${this.nativeTrack.readyState}, + muted=> ${this.nativeTrack.muted}, + visiblity=> ${document.visibilityState},`, + ); if (document.visibilityState === 'hidden' && this.source === 'regular') { this.enabledStateBeforeBackground = this.enabled; this.nativeTrack.enabled = false; this.replaceSenderTrack(this.nativeTrack); // started interruption event - this.sendInterruptionEvent(true); + this.sendInterruptionEvent({ + started: true, + }); } else { this.nativeTrack.enabled = this.enabledStateBeforeBackground; this.replaceSenderTrack(this.processedTrack || this.nativeTrack); // stopped interruption event - this.sendInterruptionEvent(false); + this.sendInterruptionEvent({ + started: false, + }); } this.eventBus.localVideoEnabled.publish({ enabled: this.nativeTrack.enabled, track: this }); }; diff --git a/packages/hms-video-store/src/media/tracks/HMSTrack.ts b/packages/hms-video-store/src/media/tracks/HMSTrack.ts index 20c74e64f6..3db10a9eca 100644 --- a/packages/hms-video-store/src/media/tracks/HMSTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSTrack.ts @@ -89,8 +89,9 @@ export abstract class HMSTrack { * @internal * It will send event to analytics when interruption start/stop */ - sendInterruptionEvent(started: boolean, isRemoteAudio = false) { + sendInterruptionEvent({ started, isRemoteAudio = false }: { started: boolean; isRemoteAudio?: boolean }) { console.log('interruption> event ', isRemoteAudio, this.type, started); + // TODO send it interruption AnalyticsEventFactory.interrupion(started, isRemoteAudio ? 'remote.audio' : this.type, { deviceId: this.nativeTrack.getSettings().deviceId, groupId: this.nativeTrack.getSettings().groupId, From 0123bbade030ae208571642e2fade106f6e58bf7 Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Mon, 29 Jul 2024 13:21:22 +0530 Subject: [PATCH 11/28] fix: remove logs --- .../audio-sink-manager/AudioSinkManager.ts | 10 +++++---- .../src/media/tracks/HMSLocalAudioTrack.ts | 22 +++++++++---------- .../src/media/tracks/HMSLocalVideoTrack.ts | 21 +++++++++--------- .../src/media/tracks/HMSTrack.ts | 4 +--- 4 files changed, 27 insertions(+), 30 deletions(-) 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 177aee0b45..b935202821 100644 --- a/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts +++ b/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts @@ -120,10 +120,12 @@ export class AudioSinkManager { if (audioTrack) { this.autoPausedTracks.add(audioTrack as HMSRemoteAudioTrack); // started interruption event - audioTrack.sendInterruptionEvent({ - started: true, - isRemoteAudio: true, - }); + this.eventBus.analytics.publish( + audioTrack.sendInterruptionEvent({ + started: true, + isRemoteAudio: true, + }), + ); } }; diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts index 4bf606dba5..3eb3fe616c 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts @@ -77,23 +77,21 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { } private handleVisibilityChange = async () => { - console.log( - `interruption> video visible readyState=> ${this.nativeTrack.readyState}, - muted=> ${this.nativeTrack.muted}, - visiblity=> ${document.visibilityState}, - isInterrupted=> ${this.isInterrupted}`, - ); if (this.nativeTrack.readyState === 'ended' && this.nativeTrack.muted && document.visibilityState !== 'visible') { - this.sendInterruptionEvent({ - started: true, - }); + this.eventBus.analytics.publish( + this.sendInterruptionEvent({ + started: true, + }), + ); this.isInterrupted = true; } if (document.visibilityState === 'visible' && this.isInterrupted) { await this.replaceTrackWith(this.settings); - this.sendInterruptionEvent({ - started: false, - }); + this.eventBus.analytics.publish( + this.sendInterruptionEvent({ + started: false, + }), + ); this.isInterrupted = false; } }; diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index 6ef1e3f0af..c09adc4fdd 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -495,26 +495,25 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { }; private handleVisibilityChange = async () => { - console.log( - `interruption> video visible readyState=> ${this.nativeTrack.readyState}, - muted=> ${this.nativeTrack.muted}, - visiblity=> ${document.visibilityState},`, - ); if (document.visibilityState === 'hidden' && this.source === 'regular') { this.enabledStateBeforeBackground = this.enabled; this.nativeTrack.enabled = false; this.replaceSenderTrack(this.nativeTrack); // started interruption event - this.sendInterruptionEvent({ - started: true, - }); + this.eventBus.analytics.publish( + this.sendInterruptionEvent({ + started: true, + }), + ); } else { this.nativeTrack.enabled = this.enabledStateBeforeBackground; this.replaceSenderTrack(this.processedTrack || this.nativeTrack); // stopped interruption event - this.sendInterruptionEvent({ - started: false, - }); + this.eventBus.analytics.publish( + this.sendInterruptionEvent({ + started: false, + }), + ); } this.eventBus.localVideoEnabled.publish({ enabled: this.nativeTrack.enabled, track: this }); }; diff --git a/packages/hms-video-store/src/media/tracks/HMSTrack.ts b/packages/hms-video-store/src/media/tracks/HMSTrack.ts index 3db10a9eca..829dc13a0a 100644 --- a/packages/hms-video-store/src/media/tracks/HMSTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSTrack.ts @@ -90,9 +90,7 @@ export abstract class HMSTrack { * It will send event to analytics when interruption start/stop */ sendInterruptionEvent({ started, isRemoteAudio = false }: { started: boolean; isRemoteAudio?: boolean }) { - console.log('interruption> event ', isRemoteAudio, this.type, started); - // TODO send it interruption - AnalyticsEventFactory.interrupion(started, isRemoteAudio ? 'remote.audio' : this.type, { + return AnalyticsEventFactory.interrupion(started, isRemoteAudio ? 'remote.audio' : this.type, { deviceId: this.nativeTrack.getSettings().deviceId, groupId: this.nativeTrack.getSettings().groupId, }); From 03738b861c68a5140f6ff65eb65d03a352ca499d Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Mon, 29 Jul 2024 16:05:14 +0530 Subject: [PATCH 12/28] fix: remote audio --- .../src/audio-sink-manager/AudioSinkManager.ts | 7 ------- 1 file changed, 7 deletions(-) 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 b935202821..c8238e9fb3 100644 --- a/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts +++ b/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts @@ -119,13 +119,6 @@ export class AudioSinkManager { const audioTrack = this.store.getTrackById(event.target.id); if (audioTrack) { this.autoPausedTracks.add(audioTrack as HMSRemoteAudioTrack); - // started interruption event - this.eventBus.analytics.publish( - audioTrack.sendInterruptionEvent({ - started: true, - isRemoteAudio: true, - }), - ); } }; From fa37aacc0e384dc075ac1e8acef295f710a1ab21 Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Mon, 29 Jul 2024 16:06:57 +0530 Subject: [PATCH 13/28] fix: wrong line removed --- .../hms-video-store/src/audio-sink-manager/AudioSinkManager.ts | 1 + 1 file changed, 1 insertion(+) 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 c8238e9fb3..6d1e667888 100644 --- a/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts +++ b/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts @@ -116,6 +116,7 @@ export class AudioSinkManager { private handleAudioPaused = async (event: any) => { // this means the audio paused because of external factors(headset removal, incoming phone call) + HMSLogger.d(this.TAG, 'Audio Paused', event.target.id); const audioTrack = this.store.getTrackById(event.target.id); if (audioTrack) { this.autoPausedTracks.add(audioTrack as HMSRemoteAudioTrack); From e09d5b9f6b41bd9dfdf0e0ad535d3bb98f41dfd1 Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Mon, 29 Jul 2024 16:08:04 +0530 Subject: [PATCH 14/28] fix: type --- packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts b/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts index 41bb17e6cd..d7f4200922 100644 --- a/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts +++ b/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts @@ -257,7 +257,7 @@ export default class AnalyticsEventFactory { }); } - static interrupion(started: boolean, type: string, deviceInfo: Partial) { + static interruption(started: boolean, type: string, deviceInfo: Partial) { return new AnalyticsEvent({ name: `${started ? 'interruption.start' : 'interruption.stop'}`, level: AnalyticsEventLevel.INFO, From 0cab8627c80cf81a1161b7d2de3a59cd50f95a36 Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Mon, 29 Jul 2024 16:15:16 +0530 Subject: [PATCH 15/28] fix: remove local screenshare video check --- .../hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts | 2 +- .../hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts index 3eb3fe616c..cdc7ff030d 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts @@ -77,7 +77,7 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { } private handleVisibilityChange = async () => { - if (this.nativeTrack.readyState === 'ended' && this.nativeTrack.muted && document.visibilityState !== 'visible') { + if ((this.nativeTrack.readyState === 'ended' || this.nativeTrack.muted) && document.visibilityState !== 'visible') { this.eventBus.analytics.publish( this.sendInterruptionEvent({ started: true, diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index c09adc4fdd..66bcd5d19d 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -495,7 +495,10 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { }; private handleVisibilityChange = async () => { - if (document.visibilityState === 'hidden' && this.source === 'regular') { + if (this.source !== 'regular') { + return; + } + if (document.visibilityState === 'hidden') { this.enabledStateBeforeBackground = this.enabled; this.nativeTrack.enabled = false; this.replaceSenderTrack(this.nativeTrack); From 4b9c215661770518e6f945dee3b7e251b2fb9712 Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Mon, 29 Jul 2024 16:19:16 +0530 Subject: [PATCH 16/28] fix: remove extra variable --- .../src/media/tracks/HMSLocalAudioTrack.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts index cdc7ff030d..1c58eff236 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts @@ -40,12 +40,6 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { */ isPublished = false; - /** - * mark true when interrupted - * @internal - */ - isInterrupted = false; - constructor( stream: HMSLocalStream, track: MediaStreamTrack, @@ -75,7 +69,7 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { resetManuallySelectedDeviceId() { this.manuallySelectedDeviceId = undefined; } - + // eslint-disable-next-line complexity private handleVisibilityChange = async () => { if ((this.nativeTrack.readyState === 'ended' || this.nativeTrack.muted) && document.visibilityState !== 'visible') { this.eventBus.analytics.publish( @@ -83,16 +77,14 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { started: true, }), ); - this.isInterrupted = true; } - if (document.visibilityState === 'visible' && this.isInterrupted) { + if (document.visibilityState === 'visible' && (this.nativeTrack.readyState === 'ended' || this.nativeTrack.muted)) { await this.replaceTrackWith(this.settings); this.eventBus.analytics.publish( this.sendInterruptionEvent({ started: false, }), ); - this.isInterrupted = false; } }; From f45b31b3022e1692cbd6b3e7039e1454c4e137cb Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Mon, 29 Jul 2024 16:36:14 +0530 Subject: [PATCH 17/28] fix: unsaved file --- packages/hms-video-store/src/media/tracks/HMSTrack.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSTrack.ts b/packages/hms-video-store/src/media/tracks/HMSTrack.ts index 829dc13a0a..470a3eae88 100644 --- a/packages/hms-video-store/src/media/tracks/HMSTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSTrack.ts @@ -90,7 +90,7 @@ export abstract class HMSTrack { * It will send event to analytics when interruption start/stop */ sendInterruptionEvent({ started, isRemoteAudio = false }: { started: boolean; isRemoteAudio?: boolean }) { - return AnalyticsEventFactory.interrupion(started, isRemoteAudio ? 'remote.audio' : this.type, { + return AnalyticsEventFactory.interruption(started, isRemoteAudio ? 'remote.audio' : this.type, { deviceId: this.nativeTrack.getSettings().deviceId, groupId: this.nativeTrack.getSettings().groupId, }); From 8f4ed01eea3728e060b1f057e856f2c4802316c2 Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Mon, 29 Jul 2024 16:45:36 +0530 Subject: [PATCH 18/28] fix: complexity --- .../src/media/tracks/HMSLocalAudioTrack.ts | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts index 1c58eff236..f556e0b5a3 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts @@ -69,22 +69,27 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { resetManuallySelectedDeviceId() { this.manuallySelectedDeviceId = undefined; } - // eslint-disable-next-line complexity + + private isTrackNotPublishing = () => { + return this.nativeTrack.readyState === 'ended' || this.nativeTrack.muted; + }; + private handleVisibilityChange = async () => { - if ((this.nativeTrack.readyState === 'ended' || this.nativeTrack.muted) && document.visibilityState !== 'visible') { - this.eventBus.analytics.publish( - this.sendInterruptionEvent({ - started: true, - }), - ); - } - if (document.visibilityState === 'visible' && (this.nativeTrack.readyState === 'ended' || this.nativeTrack.muted)) { - await this.replaceTrackWith(this.settings); - this.eventBus.analytics.publish( - this.sendInterruptionEvent({ - started: false, - }), - ); + if (!this.isTrackNotPublishing()) { + if (document.visibilityState !== 'visible') { + this.eventBus.analytics.publish( + this.sendInterruptionEvent({ + started: true, + }), + ); + } else { + await this.replaceTrackWith(this.settings); + this.eventBus.analytics.publish( + this.sendInterruptionEvent({ + started: false, + }), + ); + } } }; From 7496816e61ab132cca12062959b73bb113141b7c Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Mon, 29 Jul 2024 16:47:21 +0530 Subject: [PATCH 19/28] fix: add source check in audio --- .../hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts index f556e0b5a3..d77d7fb884 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts @@ -75,6 +75,9 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { }; private handleVisibilityChange = async () => { + if (this.source !== 'regular') { + return; + } if (!this.isTrackNotPublishing()) { if (document.visibilityState !== 'visible') { this.eventBus.analytics.publish( From 4a0cdccbefa9ee135f8dfd043f231ab8c288dc43 Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Mon, 29 Jul 2024 16:53:21 +0530 Subject: [PATCH 20/28] fix: check --- packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts index d77d7fb884..965a873d1a 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts @@ -78,7 +78,7 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { if (this.source !== 'regular') { return; } - if (!this.isTrackNotPublishing()) { + if (this.isTrackNotPublishing()) { if (document.visibilityState !== 'visible') { this.eventBus.analytics.publish( this.sendInterruptionEvent({ From 1026377fe1a4269ecfbfa6ba9033265c6e435752 Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Mon, 29 Jul 2024 16:54:12 +0530 Subject: [PATCH 21/28] fix: check --- .../src/media/tracks/HMSLocalAudioTrack.ts | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts index 965a873d1a..94d51b3573 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts @@ -75,24 +75,22 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { }; private handleVisibilityChange = async () => { - if (this.source !== 'regular') { + if (this.source !== 'regular' || !this.isTrackNotPublishing()) { return; } - if (this.isTrackNotPublishing()) { - if (document.visibilityState !== 'visible') { - this.eventBus.analytics.publish( - this.sendInterruptionEvent({ - started: true, - }), - ); - } else { - await this.replaceTrackWith(this.settings); - this.eventBus.analytics.publish( - this.sendInterruptionEvent({ - started: false, - }), - ); - } + if (document.visibilityState !== 'visible') { + this.eventBus.analytics.publish( + this.sendInterruptionEvent({ + started: true, + }), + ); + } else { + await this.replaceTrackWith(this.settings); + this.eventBus.analytics.publish( + this.sendInterruptionEvent({ + started: false, + }), + ); } }; From 0c736d437e79d0f4abb4465f783272742ac16d75 Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Mon, 29 Jul 2024 17:05:07 +0530 Subject: [PATCH 22/28] fix: add log --- packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts index 94d51b3573..9deb0fce3b 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts @@ -85,6 +85,7 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { }), ); } else { + HMSLogger.d(this.TAG, 'On visibile replacing track as it is not publishing'); await this.replaceTrackWith(this.settings); this.eventBus.analytics.publish( this.sendInterruptionEvent({ From 4f4f76d2376f99fce05cf4d1ba9e78fbd901c60e Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Mon, 29 Jul 2024 17:26:45 +0530 Subject: [PATCH 23/28] fix: check with replace sender track --- .../hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index 66bcd5d19d..cab324e3e0 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -501,7 +501,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { if (document.visibilityState === 'hidden') { this.enabledStateBeforeBackground = this.enabled; this.nativeTrack.enabled = false; - this.replaceSenderTrack(this.nativeTrack); + // this.replaceSenderTrack(this.nativeTrack); // started interruption event this.eventBus.analytics.publish( this.sendInterruptionEvent({ @@ -510,7 +510,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { ); } else { this.nativeTrack.enabled = this.enabledStateBeforeBackground; - this.replaceSenderTrack(this.processedTrack || this.nativeTrack); + // this.replaceSenderTrack(this.processedTrack || this.nativeTrack); // stopped interruption event this.eventBus.analytics.publish( this.sendInterruptionEvent({ From 4b70e07192237872fdab44d54a2c406a2277fcdb Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Mon, 29 Jul 2024 18:12:52 +0530 Subject: [PATCH 24/28] fix: revert replace sender --- .../hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index cab324e3e0..66bcd5d19d 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -501,7 +501,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { if (document.visibilityState === 'hidden') { this.enabledStateBeforeBackground = this.enabled; this.nativeTrack.enabled = false; - // this.replaceSenderTrack(this.nativeTrack); + this.replaceSenderTrack(this.nativeTrack); // started interruption event this.eventBus.analytics.publish( this.sendInterruptionEvent({ @@ -510,7 +510,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { ); } else { this.nativeTrack.enabled = this.enabledStateBeforeBackground; - // this.replaceSenderTrack(this.processedTrack || this.nativeTrack); + this.replaceSenderTrack(this.processedTrack || this.nativeTrack); // stopped interruption event this.eventBus.analytics.publish( this.sendInterruptionEvent({ From b8e349d5f2d1ffcb0bb131faa32ed3970a16bfdc Mon Sep 17 00:00:00 2001 From: amar-1995 Date: Mon, 29 Jul 2024 19:14:17 +0530 Subject: [PATCH 25/28] fix: remove replace track --- .../hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index 66bcd5d19d..cab324e3e0 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -501,7 +501,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { if (document.visibilityState === 'hidden') { this.enabledStateBeforeBackground = this.enabled; this.nativeTrack.enabled = false; - this.replaceSenderTrack(this.nativeTrack); + // this.replaceSenderTrack(this.nativeTrack); // started interruption event this.eventBus.analytics.publish( this.sendInterruptionEvent({ @@ -510,7 +510,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { ); } else { this.nativeTrack.enabled = this.enabledStateBeforeBackground; - this.replaceSenderTrack(this.processedTrack || this.nativeTrack); + // this.replaceSenderTrack(this.processedTrack || this.nativeTrack); // stopped interruption event this.eventBus.analytics.publish( this.sendInterruptionEvent({ From 8b0920337a040c78419ac7ab7b52c121d683904b Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Mon, 29 Jul 2024 19:45:46 +0530 Subject: [PATCH 26/28] fix: local video not publishing --- .../hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index cab324e3e0..cff87f640c 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -509,8 +509,13 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { }), ); } else { + if (this.nativeTrack.muted || this.nativeTrack.readyState === 'ended') { + const track = await this.replaceTrackWith(this.settings); + this.nativeTrack?.stop(); + this.nativeTrack = track; + } this.nativeTrack.enabled = this.enabledStateBeforeBackground; - // this.replaceSenderTrack(this.processedTrack || this.nativeTrack); + await this.replaceSender(this.nativeTrack, this.enabledStateBeforeBackground); // stopped interruption event this.eventBus.analytics.publish( this.sendInterruptionEvent({ From 249a564cda4112bd409dadf6c8a2bacf9fc6bc60 Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Mon, 29 Jul 2024 21:44:36 +0530 Subject: [PATCH 27/28] fix: complexity --- .../src/media/tracks/HMSLocalAudioTrack.ts | 10 +++-- .../src/media/tracks/HMSLocalVideoTrack.ts | 41 +++++++++---------- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts index 9deb0fce3b..c0e6a99fc6 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts @@ -59,7 +59,9 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { } this.pluginsManager = new HMSAudioPluginsManager(this, eventBus, room); this.setFirstTrackId(track.id); - document.addEventListener('visibilitychange', this.handleVisibilityChange); + if (source === 'regular') { + document.addEventListener('visibilitychange', this.handleVisibilityChange); + } } getManuallySelectedDeviceId() { @@ -75,10 +77,12 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { }; private handleVisibilityChange = async () => { - if (this.source !== 'regular' || !this.isTrackNotPublishing()) { + // track state is fine do nothing + if (!this.isTrackNotPublishing()) { + HMSLogger.d(this.TAG, `visibiltiy: ${document.visibilityState}`, `${this}`); return; } - if (document.visibilityState !== 'visible') { + if (document.visibilityState === 'hidden') { this.eventBus.analytics.publish( this.sendInterruptionEvent({ started: true, diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index cff87f640c..73dc740f5b 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -84,7 +84,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { this.pluginsManager = new HMSVideoPluginsManager(this, eventBus); this.mediaStreamPluginsManager = new HMSMediaStreamPluginsManager(eventBus, room); this.setFirstTrackId(this.trackId); - if (isBrowser && isMobile()) { + if (isBrowser && source === 'regular') { document.addEventListener('visibilitychange', this.handleVisibilityChange); } } @@ -495,33 +495,32 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { }; private handleVisibilityChange = async () => { - if (this.source !== 'regular') { - return; - } if (document.visibilityState === 'hidden') { - this.enabledStateBeforeBackground = this.enabled; - this.nativeTrack.enabled = false; - // this.replaceSenderTrack(this.nativeTrack); - // started interruption event - this.eventBus.analytics.publish( - this.sendInterruptionEvent({ - started: true, - }), - ); + if (isMobile()) { + this.enabledStateBeforeBackground = this.enabled; + this.nativeTrack.enabled = false; + HMSLogger.d(this.TAG, 'visibility hidden muting track'); + this.replaceSenderTrack(this.nativeTrack); + // started interruption event + this.eventBus.analytics.publish( + this.sendInterruptionEvent({ + started: true, + }), + ); + } } else { if (this.nativeTrack.muted || this.nativeTrack.readyState === 'ended') { + HMSLogger.d(this.TAG, 'visibility visible, restarting track', `${this}`); const track = await this.replaceTrackWith(this.settings); this.nativeTrack?.stop(); this.nativeTrack = track; } - this.nativeTrack.enabled = this.enabledStateBeforeBackground; - await this.replaceSender(this.nativeTrack, this.enabledStateBeforeBackground); - // stopped interruption event - this.eventBus.analytics.publish( - this.sendInterruptionEvent({ - started: false, - }), - ); + if (isMobile()) { + this.nativeTrack.enabled = this.enabledStateBeforeBackground; + await this.replaceSender(this.nativeTrack, this.enabledStateBeforeBackground); + } else { + await this.replaceSender(this.nativeTrack, this.enabled); + } } this.eventBus.localVideoEnabled.publish({ enabled: this.nativeTrack.enabled, track: this }); }; From 281aa5075fe6615c487dc602fd60d22b31ad77b0 Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Tue, 30 Jul 2024 12:04:34 +0530 Subject: [PATCH 28/28] fix: render sinks after track replace --- packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index 73dc740f5b..758881a3d0 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -521,6 +521,8 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { } else { await this.replaceSender(this.nativeTrack, this.enabled); } + await this.processPlugins(); + this.videoHandler.updateSinks(); } this.eventBus.localVideoEnabled.publish({ enabled: this.nativeTrack.enabled, track: this }); };