mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
Fix two way talk starting webrtc session (#10422)
* Fix two way talk starting webrtc session * Remove logs
This commit is contained in:
parent
79ca599ace
commit
52ce6190ae
@ -46,7 +46,7 @@ function MSEPlayer({
|
||||
const msRef = useRef<MediaSource | null>(null);
|
||||
|
||||
const wsURL = useMemo(() => {
|
||||
return `${baseUrl.replace(/^http/, "ws")}live/webrtc/api/ws?src=${camera}`;
|
||||
return `${baseUrl.replace(/^http/, "ws")}live/mse/api/ws?src=${camera}`;
|
||||
}, [camera]);
|
||||
|
||||
const play = () => {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { baseUrl } from "@/api/baseUrl";
|
||||
import { useCallback, useEffect, useRef } from "react";
|
||||
import { useCallback, useEffect, useMemo, useRef } from "react";
|
||||
|
||||
type WebRtcPlayerProps = {
|
||||
className?: string;
|
||||
@ -18,6 +18,12 @@ export default function WebRtcPlayer({
|
||||
microphoneEnabled = false,
|
||||
onPlaying,
|
||||
}: WebRtcPlayerProps) {
|
||||
// metadata
|
||||
|
||||
const wsURL = useMemo(() => {
|
||||
return `${baseUrl.replace(/^http/, "ws")}live/webrtc/api/ws?src=${camera}`;
|
||||
}, [camera]);
|
||||
|
||||
// camera states
|
||||
|
||||
const pcRef = useRef<RTCPeerConnection | undefined>();
|
||||
@ -89,12 +95,13 @@ export default function WebRtcPlayer({
|
||||
}
|
||||
|
||||
const connect = useCallback(
|
||||
async (ws: WebSocket, aPc: Promise<RTCPeerConnection | undefined>) => {
|
||||
async (aPc: Promise<RTCPeerConnection | undefined>) => {
|
||||
if (!aPc) {
|
||||
return;
|
||||
}
|
||||
|
||||
pcRef.current = await aPc;
|
||||
const ws = new WebSocket(wsURL);
|
||||
|
||||
ws.addEventListener("open", () => {
|
||||
pcRef.current?.addEventListener("icecandidate", (ev) => {
|
||||
@ -130,7 +137,7 @@ export default function WebRtcPlayer({
|
||||
}
|
||||
});
|
||||
},
|
||||
[],
|
||||
[wsURL],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@ -142,15 +149,10 @@ export default function WebRtcPlayer({
|
||||
return;
|
||||
}
|
||||
|
||||
const url = `${baseUrl.replace(
|
||||
/^http/,
|
||||
"ws",
|
||||
)}live/webrtc/api/ws?src=${camera}`;
|
||||
const ws = new WebSocket(url);
|
||||
const aPc = PeerConnection(
|
||||
microphoneEnabled ? "video+audio+microphone" : "video+audio",
|
||||
);
|
||||
connect(ws, aPc);
|
||||
connect(aPc);
|
||||
|
||||
return () => {
|
||||
if (pcRef.current) {
|
||||
|
@ -129,6 +129,14 @@ export default function LiveCameraView({ camera }: LiveCameraViewProps) {
|
||||
}
|
||||
}, [camera, fullscreen, isPortrait]);
|
||||
|
||||
const preferredLiveMode = useMemo(() => {
|
||||
if (isSafari || mic) {
|
||||
return "webrtc";
|
||||
}
|
||||
|
||||
return "mse";
|
||||
}, [mic]);
|
||||
|
||||
const windowAspectRatio = useMemo(() => {
|
||||
return windowWidth / windowHeight;
|
||||
}, [windowWidth, windowHeight]);
|
||||
@ -263,7 +271,7 @@ export default function LiveCameraView({ camera }: LiveCameraViewProps) {
|
||||
cameraConfig={camera}
|
||||
playAudio={audio}
|
||||
micEnabled={mic}
|
||||
preferredLiveMode={isSafari || mic ? "webrtc" : "mse"}
|
||||
preferredLiveMode={preferredLiveMode}
|
||||
/>
|
||||
</div>
|
||||
{camera.onvif.host != "" && <PtzControlPanel camera={camera.name} />}
|
||||
|
Loading…
Reference in New Issue
Block a user