From 92255f771b0c47c4ffa6bac4e6446f341473c891 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Tue, 12 Mar 2024 17:19:02 -0600 Subject: [PATCH] Add micropohone button for two way talk (#10408) --- web/src/components/player/LivePlayer.tsx | 3 +++ web/src/components/player/WebRTCPlayer.tsx | 16 ++++++++++++++-- web/src/views/live/LiveCameraView.tsx | 21 +++++++++++++++++++-- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/web/src/components/player/LivePlayer.tsx b/web/src/components/player/LivePlayer.tsx index 2978717b7..30c1d5b5c 100644 --- a/web/src/components/player/LivePlayer.tsx +++ b/web/src/components/player/LivePlayer.tsx @@ -20,6 +20,7 @@ type LivePlayerProps = { showStillWithoutActivity?: boolean; windowVisible?: boolean; playAudio?: boolean; + micEnabled?: boolean; // only webrtc supports mic onClick?: () => void; }; @@ -30,6 +31,7 @@ export default function LivePlayer({ showStillWithoutActivity = true, windowVisible = true, playAudio = false, + micEnabled = false, onClick, }: LivePlayerProps) { // camera activity @@ -97,6 +99,7 @@ export default function LivePlayer({ camera={cameraConfig.live.stream_name} playbackEnabled={cameraActive} audioEnabled={playAudio} + microphoneEnabled={micEnabled} onPlaying={() => setLiveReady(true)} /> ); diff --git a/web/src/components/player/WebRTCPlayer.tsx b/web/src/components/player/WebRTCPlayer.tsx index d964b3460..f7d6c85c0 100644 --- a/web/src/components/player/WebRTCPlayer.tsx +++ b/web/src/components/player/WebRTCPlayer.tsx @@ -6,6 +6,7 @@ type WebRtcPlayerProps = { camera: string; playbackEnabled?: boolean; audioEnabled?: boolean; + microphoneEnabled?: boolean; onPlaying?: () => void; }; @@ -14,6 +15,7 @@ export default function WebRtcPlayer({ camera, playbackEnabled = true, audioEnabled = false, + microphoneEnabled = false, onPlaying, }: WebRtcPlayerProps) { // camera states @@ -145,7 +147,9 @@ export default function WebRtcPlayer({ "ws", )}live/webrtc/api/ws?src=${camera}`; const ws = new WebSocket(url); - const aPc = PeerConnection("video+audio"); + const aPc = PeerConnection( + microphoneEnabled ? "video+audio+microphone" : "video+audio", + ); connect(ws, aPc); return () => { @@ -154,7 +158,15 @@ export default function WebRtcPlayer({ pcRef.current = undefined; } }; - }, [camera, connect, PeerConnection, pcRef, videoRef, playbackEnabled]); + }, [ + camera, + connect, + PeerConnection, + pcRef, + videoRef, + playbackEnabled, + microphoneEnabled, + ]); return (