From dcefadbcc61cf03b2379dafa65dc8acc7d5a670b Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Thu, 10 Oct 2024 10:51:06 +0530 Subject: [PATCH 1/5] fix: listen to specific events --- .../components/Notifications/Notifications.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/roomkit-react/src/Prebuilt/components/Notifications/Notifications.tsx b/packages/roomkit-react/src/Prebuilt/components/Notifications/Notifications.tsx index 4d8df74fb2..54ea779d0d 100644 --- a/packages/roomkit-react/src/Prebuilt/components/Notifications/Notifications.tsx +++ b/packages/roomkit-react/src/Prebuilt/components/Notifications/Notifications.tsx @@ -43,7 +43,18 @@ const pollToastKey: Record = {}; export function Notifications() { const localPeerID = useHMSStore(selectLocalPeerID); - const notification = useHMSNotifications(); + const notification = useHMSNotifications([ + HMSNotificationTypes.NAME_UPDATED, + HMSNotificationTypes.ERROR, + HMSNotificationTypes.ROLE_UPDATED, + HMSNotificationTypes.CHANGE_TRACK_STATE_REQUEST, + HMSNotificationTypes.REMOVED_FROM_ROOM, + HMSNotificationTypes.ROOM_ENDED, + HMSNotificationTypes.DEVICE_CHANGE_UPDATE, + HMSNotificationTypes.POLL_STARTED, + HMSNotificationTypes.POLL_STOPPED, + HMSNotificationTypes.NEW_MESSAGE, + ]); const subscribedNotifications = useSubscribedNotifications() || {}; const roomState = useHMSStore(selectRoomState); const updateRoomLayoutForRole = useUpdateRoomLayout(); From 7759c2a561f8b2d6168e6f47532640d5080f1abf Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Thu, 10 Oct 2024 12:11:23 +0530 Subject: [PATCH 2/5] fix: add logs for no data --- packages/hms-video-store/src/sdk/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/hms-video-store/src/sdk/index.ts b/packages/hms-video-store/src/sdk/index.ts index dd0f751cbe..c7ff1f6f89 100644 --- a/packages/hms-video-store/src/sdk/index.ts +++ b/packages/hms-video-store/src/sdk/index.ts @@ -456,6 +456,7 @@ export class HMSSdk implements HMSInterface { const error = ErrorFactory.TracksErrors.NoDataInTrack( `${track.type} track has no data. muted: ${track.nativeTrack.muted}, readyState: ${track.nativeTrack.readyState}`, ); + HMSLogger.e(this.TAG, error); this.sendAnalyticsEvent( AnalyticsEventFactory.publish({ devices: this.deviceManager.getDevices(), @@ -1343,6 +1344,7 @@ export class HMSSdk implements HMSInterface { const error = ErrorFactory.TracksErrors.NoDataInTrack( `${track.type} track has no data. muted: ${track.nativeTrack.muted}, readyState: ${track.nativeTrack.readyState}`, ); + HMSLogger.e(this.TAG, error); this.sendAnalyticsEvent( AnalyticsEventFactory.publish({ devices: this.deviceManager.getDevices(), From 35a371454f3019fe76b328f815a9e68f203a6ea3 Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Thu, 10 Oct 2024 12:43:57 +0530 Subject: [PATCH 3/5] fix: handle local video not recovering after call --- .../src/audio-sink-manager/AudioSinkManager.ts | 2 ++ packages/hms-video-store/src/events/EventBus.ts | 1 + .../hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts | 6 ++++-- .../hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts | 6 ++++-- packages/hms-video-store/src/sdk/index.ts | 2 ++ packages/hms-video-store/src/utils/constants.ts | 1 + 6 files changed, 14 insertions(+), 4 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 51a4190313..9359b0b88e 100644 --- a/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts +++ b/packages/hms-video-store/src/audio-sink-manager/AudioSinkManager.ts @@ -46,6 +46,7 @@ export class AudioSinkManager { this.eventBus.audioTrackUpdate.subscribe(this.handleTrackUpdate); this.eventBus.deviceChange.subscribe(this.handleAudioDeviceChange); this.eventBus.localVideoUnmutedNatively.subscribe(this.unpauseAudioTracks); + this.eventBus.localAudioUnmutedNatively.subscribe(this.unpauseAudioTracks); } setListener(listener?: HMSUpdateListener) { @@ -98,6 +99,7 @@ export class AudioSinkManager { this.eventBus.audioTrackUpdate.unsubscribe(this.handleTrackUpdate); this.eventBus.deviceChange.unsubscribe(this.handleAudioDeviceChange); this.eventBus.localVideoUnmutedNatively.unsubscribe(this.unpauseAudioTracks); + this.eventBus.localAudioUnmutedNatively.unsubscribe(this.unpauseAudioTracks); this.autoPausedTracks = new Set(); this.state = { ...INITIAL_STATE }; } diff --git a/packages/hms-video-store/src/events/EventBus.ts b/packages/hms-video-store/src/events/EventBus.ts index 0bd6f2e263..096b4bba32 100644 --- a/packages/hms-video-store/src/events/EventBus.ts +++ b/packages/hms-video-store/src/events/EventBus.ts @@ -31,6 +31,7 @@ export class EventBus { this.eventEmitter, ); readonly localVideoUnmutedNatively = new HMSInternalEvent(HMSEvents.LOCAL_VIDEO_UNMUTED_NATIVELY, this.eventEmitter); + readonly localAudioUnmutedNatively = new HMSInternalEvent(HMSEvents.LOCAL_AUDIO_UNMUTED_NATIVELY, this.eventEmitter); /** * Emitter which processes raw RTC stats from rtcStatsUpdate and calls client callback diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts index d194ccca37..69fd62e186 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalAudioTrack.ts @@ -325,7 +325,7 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { }; /** @internal */ - handleTrackUnmute = () => { + handleTrackUnmute = async () => { HMSLogger.d(this.TAG, 'unmuted natively'); const reason = document.visibilityState === 'hidden' ? 'visibility-change' : 'incoming-call'; this.eventBus.analytics.publish( @@ -334,7 +334,9 @@ export class HMSLocalAudioTrack extends HMSAudioTrack { reason, }), ); - this.setEnabled(this.enabled); + await this.setEnabled(this.enabled); + // whatsapp call doesn't seem to send video unmute natively, so use audio unmute to play video + this.eventBus.localAudioUnmutedNatively.publish(); }; private replaceSenderTrack = async () => { diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index e798912e86..06c026ad9c 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -85,6 +85,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { this.pluginsManager = new HMSVideoPluginsManager(this, eventBus); this.mediaStreamPluginsManager = new HMSMediaStreamPluginsManager(eventBus, room); this.setFirstTrackId(this.trackId); + this.eventBus.localAudioUnmutedNatively.subscribe(this.handleTrackUnmute); if (isBrowser && source === 'regular' && isMobile()) { document.addEventListener('visibilitychange', this.handleVisibilityChange); } @@ -261,6 +262,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { * @internal */ async cleanup() { + this.eventBus.localAudioUnmutedNatively.unsubscribe(this.handleTrackUnmute); this.removeTrackEventListeners(this.nativeTrack); super.cleanup(); this.transceiver = undefined; @@ -534,7 +536,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { }; /** @internal */ - handleTrackUnmute = () => { + handleTrackUnmute = async () => { HMSLogger.d(this.TAG, 'unmuted natively'); this.eventBus.analytics.publish( this.sendInterruptionEvent({ @@ -545,7 +547,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { super.handleTrackUnmute(); this.eventBus.localVideoEnabled.publish({ enabled: this.enabled, track: this }); this.eventBus.localVideoUnmutedNatively.publish(); - this.setEnabled(this.enabled); + await this.setEnabled(this.enabled); }; /** diff --git a/packages/hms-video-store/src/sdk/index.ts b/packages/hms-video-store/src/sdk/index.ts index c7ff1f6f89..3cac0898a7 100644 --- a/packages/hms-video-store/src/sdk/index.ts +++ b/packages/hms-video-store/src/sdk/index.ts @@ -256,6 +256,7 @@ export class HMSSdk implements HMSInterface { this.eventBus.analytics.subscribe(this.sendAnalyticsEvent); this.eventBus.deviceChange.subscribe(this.handleDeviceChange); this.eventBus.localVideoUnmutedNatively.subscribe(this.unpauseRemoteVideoTracks); + this.eventBus.localAudioUnmutedNatively.subscribe(this.unpauseRemoteVideoTracks); this.eventBus.audioPluginFailed.subscribe(this.handleAudioPluginError); } @@ -672,6 +673,7 @@ export class HMSSdk implements HMSInterface { this.cleanDeviceManagers(); this.eventBus.analytics.unsubscribe(this.sendAnalyticsEvent); this.eventBus.localVideoUnmutedNatively.unsubscribe(this.unpauseRemoteVideoTracks); + this.eventBus.localAudioUnmutedNatively.unsubscribe(this.unpauseRemoteVideoTracks); this.analyticsTimer.cleanup(); DeviceStorageManager.cleanup(); this.playlistManager.cleanup(); diff --git a/packages/hms-video-store/src/utils/constants.ts b/packages/hms-video-store/src/utils/constants.ts index 5f237a85d3..0888adb791 100644 --- a/packages/hms-video-store/src/utils/constants.ts +++ b/packages/hms-video-store/src/utils/constants.ts @@ -40,6 +40,7 @@ export const HMSEvents = { LOCAL_AUDIO_ENABLED: 'local-audio-enabled', LOCAL_VIDEO_ENABLED: 'local-video-enabled', LOCAL_VIDEO_UNMUTED_NATIVELY: 'local-video-unmuted-natively', + LOCAL_AUDIO_UNMUTED_NATIVELY: 'local-audio-unmuted-natively', STATS_UPDATE: 'stats-update', // emitted by HMSWebrtcInternals RTC_STATS_UPDATE: 'rtc-stats-update', // emitted by RTCStatsMonitor TRACK_DEGRADED: 'track-degraded', From f6ed495a0473a4195d74faa5818917ed88aa4c6b Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Thu, 10 Oct 2024 13:07:19 +0530 Subject: [PATCH 4/5] fix: test, increase notification duration --- packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts | 2 +- .../src/Prebuilt/components/Notifications/Notifications.tsx | 1 + 2 files changed, 2 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 06c026ad9c..ac219a47cf 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -544,7 +544,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { reason: 'incoming-call', }), ); - super.handleTrackUnmute(); + this.handleTrackUnmute(); this.eventBus.localVideoEnabled.publish({ enabled: this.enabled, track: this }); this.eventBus.localVideoUnmutedNatively.publish(); await this.setEnabled(this.enabled); diff --git a/packages/roomkit-react/src/Prebuilt/components/Notifications/Notifications.tsx b/packages/roomkit-react/src/Prebuilt/components/Notifications/Notifications.tsx index 54ea779d0d..c9e9c529fc 100644 --- a/packages/roomkit-react/src/Prebuilt/components/Notifications/Notifications.tsx +++ b/packages/roomkit-react/src/Prebuilt/components/Notifications/Notifications.tsx @@ -120,6 +120,7 @@ export function Notifications() { if (!subscribedNotifications.ERROR) return; ToastManager.addToast({ title: `Error: ${notification.data?.message} - ${notification.data?.description}`, + duration: 8000, }); break; case HMSNotificationTypes.ROLE_UPDATED: { From fe92c47b84ab1b0354f0452910aeae89a225ce37 Mon Sep 17 00:00:00 2001 From: raviteja83 Date: Thu, 10 Oct 2024 13:12:44 +0530 Subject: [PATCH 5/5] fix: test --- .../hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts index ac219a47cf..0089b696b0 100644 --- a/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts +++ b/packages/hms-video-store/src/media/tracks/HMSLocalVideoTrack.ts @@ -516,12 +516,12 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { private addTrackEventListeners(track: MediaStreamTrack) { track.addEventListener('mute', this.handleTrackMute); - track.addEventListener('unmute', this.handleTrackUnmute); + track.addEventListener('unmute', this.handleTrackUnmuteNatively); } private removeTrackEventListeners(track: MediaStreamTrack) { track.removeEventListener('mute', this.handleTrackMute); - track.removeEventListener('unmute', this.handleTrackUnmute); + track.removeEventListener('unmute', this.handleTrackUnmuteNatively); } private handleTrackMute = () => { @@ -536,7 +536,7 @@ export class HMSLocalVideoTrack extends HMSVideoTrack { }; /** @internal */ - handleTrackUnmute = async () => { + handleTrackUnmuteNatively = async () => { HMSLogger.d(this.TAG, 'unmuted natively'); this.eventBus.analytics.publish( this.sendInterruptionEvent({