mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-08 20:25:26 +03:00
Use webrtc for safari
This commit is contained in:
parent
2806d1b027
commit
51ca862683
@ -87,6 +87,7 @@ export default function LivePlayer({
|
|||||||
<WebRtcPlayer
|
<WebRtcPlayer
|
||||||
className={`rounded-2xl h-full ${liveReady ? "" : "hidden"}`}
|
className={`rounded-2xl h-full ${liveReady ? "" : "hidden"}`}
|
||||||
camera={cameraConfig.live.stream_name}
|
camera={cameraConfig.live.stream_name}
|
||||||
|
playbackEnabled={cameraActive}
|
||||||
onPlaying={() => setLiveReady(true)}
|
onPlaying={() => setLiveReady(true)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -4,16 +4,21 @@ import { useCallback, useEffect, useRef } from "react";
|
|||||||
type WebRtcPlayerProps = {
|
type WebRtcPlayerProps = {
|
||||||
className?: string;
|
className?: string;
|
||||||
camera: string;
|
camera: string;
|
||||||
|
playbackEnabled?: boolean;
|
||||||
onPlaying?: () => void;
|
onPlaying?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function WebRtcPlayer({
|
export default function WebRtcPlayer({
|
||||||
className,
|
className,
|
||||||
camera,
|
camera,
|
||||||
|
playbackEnabled = true,
|
||||||
onPlaying,
|
onPlaying,
|
||||||
}: WebRtcPlayerProps) {
|
}: WebRtcPlayerProps) {
|
||||||
|
// camera states
|
||||||
|
|
||||||
const pcRef = useRef<RTCPeerConnection | undefined>();
|
const pcRef = useRef<RTCPeerConnection | undefined>();
|
||||||
const videoRef = useRef<HTMLVideoElement | null>(null);
|
const videoRef = useRef<HTMLVideoElement | null>(null);
|
||||||
|
|
||||||
const PeerConnection = useCallback(
|
const PeerConnection = useCallback(
|
||||||
async (media: string) => {
|
async (media: string) => {
|
||||||
if (!videoRef.current) {
|
if (!videoRef.current) {
|
||||||
@ -129,6 +134,10 @@ export default function WebRtcPlayer({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!playbackEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const url = `${baseUrl.replace(
|
const url = `${baseUrl.replace(
|
||||||
/^http/,
|
/^http/,
|
||||||
"ws"
|
"ws"
|
||||||
@ -143,10 +152,9 @@ export default function WebRtcPlayer({
|
|||||||
pcRef.current = undefined;
|
pcRef.current = undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [camera, connect, PeerConnection, pcRef, videoRef]);
|
}, [camera, connect, PeerConnection, pcRef, videoRef, playbackEnabled]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
|
||||||
<video
|
<video
|
||||||
ref={videoRef}
|
ref={videoRef}
|
||||||
className={className}
|
className={className}
|
||||||
@ -155,6 +163,5 @@ export default function WebRtcPlayer({
|
|||||||
muted
|
muted
|
||||||
onLoadedData={onPlaying}
|
onLoadedData={onPlaying}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
|
|||||||
import { TooltipProvider } from "@/components/ui/tooltip";
|
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||||
import { Event as FrigateEvent } from "@/types/event";
|
import { Event as FrigateEvent } from "@/types/event";
|
||||||
import { FrigateConfig } from "@/types/frigateConfig";
|
import { FrigateConfig } from "@/types/frigateConfig";
|
||||||
|
import { isSafari } from "@/utils/browserUtil";
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
|
||||||
@ -64,6 +65,7 @@ function Live() {
|
|||||||
.sort((aConf, bConf) => aConf.ui.order - bConf.ui.order);
|
.sort((aConf, bConf) => aConf.ui.order - bConf.ui.order);
|
||||||
}, [config]);
|
}, [config]);
|
||||||
|
|
||||||
|
const safari = isSafari();
|
||||||
const [windowVisible, setWindowVisible] = useState(true);
|
const [windowVisible, setWindowVisible] = useState(true);
|
||||||
const visibilityListener = useCallback(() => {
|
const visibilityListener = useCallback(() => {
|
||||||
setWindowVisible(document.visibilityState == "visible");
|
setWindowVisible(document.visibilityState == "visible");
|
||||||
@ -109,7 +111,7 @@ function Live() {
|
|||||||
className={`mb-2 md:mb-0 rounded-2xl bg-black ${grow}`}
|
className={`mb-2 md:mb-0 rounded-2xl bg-black ${grow}`}
|
||||||
windowVisible={windowVisible}
|
windowVisible={windowVisible}
|
||||||
cameraConfig={camera}
|
cameraConfig={camera}
|
||||||
preferredLiveMode="mse"
|
preferredLiveMode={safari ? "webrtc" : "mse"}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user