From 07a4de638f25201e0fcf2c3949c6eebaf07abebe Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 13 Feb 2023 15:20:48 +0000 Subject: [PATCH 1/2] Don't pause audio streams on media actions This adds handlers for the media actions to do nothing, otherwise they cause the audio element for a random participant to get paused. Fixes https://github.com/vector-im/element-call/issues/855 --- src/room/useGroupCall.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/room/useGroupCall.ts b/src/room/useGroupCall.ts index f2d7f27e..d0157ff7 100644 --- a/src/room/useGroupCall.ts +++ b/src/room/useGroupCall.ts @@ -158,6 +158,38 @@ export function useGroupCall(groupCall: GroupCall): UseGroupCallReturnType { [setState] ); + const doNothingMediaActionCallback = useCallback( + (details: MediaSessionActionDetails) => {}, + [] + ); + + useEffect(() => { + // disable the media action keys, otherwise audio elements get paused when + // the user presses media keys or unplugs headphones, etc. + // Note there are actions for muting / unmuting a microphone & hanging up + // which we could wire up. + const mediaActions: MediaSessionAction[] = [ + "play", + "pause", + "stop", + "nexttrack", + "previoustrack", + ]; + + for (const mediaAction of mediaActions) { + navigator.mediaSession.setActionHandler( + mediaAction, + doNothingMediaActionCallback + ); + } + + return () => { + for (const mediaAction of mediaActions) { + navigator.mediaSession.setActionHandler(mediaAction, null); + } + }; + }, [doNothingMediaEventCallback]); + useEffect(() => { function onGroupCallStateChanged() { updateState({ From 605dd44df0d33c30b0fcd060f564a5eacf4f1f07 Mon Sep 17 00:00:00 2001 From: David Baker Date: Mon, 13 Feb 2023 15:49:58 +0000 Subject: [PATCH 2/2] Rename other instance of variable --- src/room/useGroupCall.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/room/useGroupCall.ts b/src/room/useGroupCall.ts index d0157ff7..9d509872 100644 --- a/src/room/useGroupCall.ts +++ b/src/room/useGroupCall.ts @@ -188,7 +188,7 @@ export function useGroupCall(groupCall: GroupCall): UseGroupCallReturnType { navigator.mediaSession.setActionHandler(mediaAction, null); } }; - }, [doNothingMediaEventCallback]); + }, [doNothingMediaActionCallback]); useEffect(() => { function onGroupCallStateChanged() {