mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Add micropohone button for two way talk (#10408)
This commit is contained in:
parent
9e10b914c9
commit
92255f771b
@ -20,6 +20,7 @@ type LivePlayerProps = {
|
|||||||
showStillWithoutActivity?: boolean;
|
showStillWithoutActivity?: boolean;
|
||||||
windowVisible?: boolean;
|
windowVisible?: boolean;
|
||||||
playAudio?: boolean;
|
playAudio?: boolean;
|
||||||
|
micEnabled?: boolean; // only webrtc supports mic
|
||||||
onClick?: () => void;
|
onClick?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -30,6 +31,7 @@ export default function LivePlayer({
|
|||||||
showStillWithoutActivity = true,
|
showStillWithoutActivity = true,
|
||||||
windowVisible = true,
|
windowVisible = true,
|
||||||
playAudio = false,
|
playAudio = false,
|
||||||
|
micEnabled = false,
|
||||||
onClick,
|
onClick,
|
||||||
}: LivePlayerProps) {
|
}: LivePlayerProps) {
|
||||||
// camera activity
|
// camera activity
|
||||||
@ -97,6 +99,7 @@ export default function LivePlayer({
|
|||||||
camera={cameraConfig.live.stream_name}
|
camera={cameraConfig.live.stream_name}
|
||||||
playbackEnabled={cameraActive}
|
playbackEnabled={cameraActive}
|
||||||
audioEnabled={playAudio}
|
audioEnabled={playAudio}
|
||||||
|
microphoneEnabled={micEnabled}
|
||||||
onPlaying={() => setLiveReady(true)}
|
onPlaying={() => setLiveReady(true)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -6,6 +6,7 @@ type WebRtcPlayerProps = {
|
|||||||
camera: string;
|
camera: string;
|
||||||
playbackEnabled?: boolean;
|
playbackEnabled?: boolean;
|
||||||
audioEnabled?: boolean;
|
audioEnabled?: boolean;
|
||||||
|
microphoneEnabled?: boolean;
|
||||||
onPlaying?: () => void;
|
onPlaying?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -14,6 +15,7 @@ export default function WebRtcPlayer({
|
|||||||
camera,
|
camera,
|
||||||
playbackEnabled = true,
|
playbackEnabled = true,
|
||||||
audioEnabled = false,
|
audioEnabled = false,
|
||||||
|
microphoneEnabled = false,
|
||||||
onPlaying,
|
onPlaying,
|
||||||
}: WebRtcPlayerProps) {
|
}: WebRtcPlayerProps) {
|
||||||
// camera states
|
// camera states
|
||||||
@ -145,7 +147,9 @@ export default function WebRtcPlayer({
|
|||||||
"ws",
|
"ws",
|
||||||
)}live/webrtc/api/ws?src=${camera}`;
|
)}live/webrtc/api/ws?src=${camera}`;
|
||||||
const ws = new WebSocket(url);
|
const ws = new WebSocket(url);
|
||||||
const aPc = PeerConnection("video+audio");
|
const aPc = PeerConnection(
|
||||||
|
microphoneEnabled ? "video+audio+microphone" : "video+audio",
|
||||||
|
);
|
||||||
connect(ws, aPc);
|
connect(ws, aPc);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
@ -154,7 +158,15 @@ export default function WebRtcPlayer({
|
|||||||
pcRef.current = undefined;
|
pcRef.current = undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [camera, connect, PeerConnection, pcRef, videoRef, playbackEnabled]);
|
}, [
|
||||||
|
camera,
|
||||||
|
connect,
|
||||||
|
PeerConnection,
|
||||||
|
pcRef,
|
||||||
|
videoRef,
|
||||||
|
playbackEnabled,
|
||||||
|
microphoneEnabled,
|
||||||
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<video
|
<video
|
||||||
|
@ -40,6 +40,8 @@ import {
|
|||||||
FaAngleUp,
|
FaAngleUp,
|
||||||
FaCompress,
|
FaCompress,
|
||||||
FaExpand,
|
FaExpand,
|
||||||
|
FaMicrophone,
|
||||||
|
FaMicrophoneSlash,
|
||||||
} from "react-icons/fa";
|
} from "react-icons/fa";
|
||||||
import { GiSpeaker, GiSpeakerOff } from "react-icons/gi";
|
import { GiSpeaker, GiSpeakerOff } from "react-icons/gi";
|
||||||
import { IoMdArrowBack } from "react-icons/io";
|
import { IoMdArrowBack } from "react-icons/io";
|
||||||
@ -98,6 +100,7 @@ export default function LiveCameraView({ camera }: LiveCameraViewProps) {
|
|||||||
// playback state
|
// playback state
|
||||||
|
|
||||||
const [audio, setAudio] = useState(false);
|
const [audio, setAudio] = useState(false);
|
||||||
|
const [mic, setMic] = useState(false);
|
||||||
const [fullscreen, setFullscreen] = useState(false);
|
const [fullscreen, setFullscreen] = useState(false);
|
||||||
|
|
||||||
const growClassName = useMemo(() => {
|
const growClassName = useMemo(() => {
|
||||||
@ -190,6 +193,16 @@ export default function LiveCameraView({ camera }: LiveCameraViewProps) {
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
{window.isSecureContext && (
|
||||||
|
<CameraFeatureToggle
|
||||||
|
className="p-2 md:p-0"
|
||||||
|
variant={fullscreen ? "overlay" : "primary"}
|
||||||
|
Icon={mic ? FaMicrophone : FaMicrophoneSlash}
|
||||||
|
isActive={mic}
|
||||||
|
title={`${mic ? "Disable" : "Enable"} Two Way Talk`}
|
||||||
|
onClick={() => setMic(!mic)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<CameraFeatureToggle
|
<CameraFeatureToggle
|
||||||
className="p-2 md:p-0"
|
className="p-2 md:p-0"
|
||||||
variant={fullscreen ? "overlay" : "primary"}
|
variant={fullscreen ? "overlay" : "primary"}
|
||||||
@ -249,7 +262,8 @@ export default function LiveCameraView({ camera }: LiveCameraViewProps) {
|
|||||||
showStillWithoutActivity={false}
|
showStillWithoutActivity={false}
|
||||||
cameraConfig={camera}
|
cameraConfig={camera}
|
||||||
playAudio={audio}
|
playAudio={audio}
|
||||||
preferredLiveMode={isSafari ? "webrtc" : "mse"}
|
micEnabled={mic}
|
||||||
|
preferredLiveMode={isSafari || mic ? "webrtc" : "mse"}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{camera.onvif.host != "" && <PtzControlPanel camera={camera.name} />}
|
{camera.onvif.host != "" && <PtzControlPanel camera={camera.name} />}
|
||||||
@ -410,7 +424,10 @@ function PtzControlPanel({ camera }: { camera: string }) {
|
|||||||
<DropdownMenuContent>
|
<DropdownMenuContent>
|
||||||
{ptz?.presets.map((preset) => {
|
{ptz?.presets.map((preset) => {
|
||||||
return (
|
return (
|
||||||
<DropdownMenuItem onSelect={() => sendPtz(`preset_${preset}`)}>
|
<DropdownMenuItem
|
||||||
|
key={preset}
|
||||||
|
onSelect={() => sendPtz(`preset_${preset}`)}
|
||||||
|
>
|
||||||
{preset}
|
{preset}
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user