This commit is contained in:
Nicolas Mowen 2024-07-23 08:34:38 -06:00 committed by GitHub
parent 524f03a650
commit 47aecff567
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 39 additions and 5 deletions

View File

@ -11,16 +11,18 @@ type LivePlayerProps = {
className?: string; className?: string;
birdseyeConfig: BirdseyeConfig; birdseyeConfig: BirdseyeConfig;
liveMode: LivePlayerMode; liveMode: LivePlayerMode;
onClick?: () => void; pip?: boolean;
containerRef: React.MutableRefObject<HTMLDivElement | null>; containerRef: React.MutableRefObject<HTMLDivElement | null>;
onClick?: () => void;
}; };
export default function BirdseyeLivePlayer({ export default function BirdseyeLivePlayer({
className, className,
birdseyeConfig, birdseyeConfig,
liveMode, liveMode,
onClick, pip,
containerRef, containerRef,
onClick,
}: LivePlayerProps) { }: LivePlayerProps) {
let player; let player;
if (liveMode == "webrtc") { if (liveMode == "webrtc") {
@ -28,6 +30,7 @@ export default function BirdseyeLivePlayer({
<WebRtcPlayer <WebRtcPlayer
className={`size-full rounded-lg md:rounded-2xl`} className={`size-full rounded-lg md:rounded-2xl`}
camera="birdseye" camera="birdseye"
pip={pip}
/> />
); );
} else if (liveMode == "mse") { } else if (liveMode == "mse") {
@ -36,6 +39,7 @@ export default function BirdseyeLivePlayer({
<MSEPlayer <MSEPlayer
className={`size-full rounded-lg md:rounded-2xl`} className={`size-full rounded-lg md:rounded-2xl`}
camera="birdseye" camera="birdseye"
pip={pip}
/> />
); );
} else { } else {

View File

@ -5,15 +5,18 @@ import { Button } from "@/components/ui/button";
import { TooltipProvider } from "@/components/ui/tooltip"; import { TooltipProvider } from "@/components/ui/tooltip";
import { useResizeObserver } from "@/hooks/resize-observer"; import { useResizeObserver } from "@/hooks/resize-observer";
import { FrigateConfig } from "@/types/frigateConfig"; import { FrigateConfig } from "@/types/frigateConfig";
import { useMemo, useRef } from "react"; import { useEffect, useMemo, useRef, useState } from "react";
import { import {
isDesktop, isDesktop,
isFirefox,
isIOS,
isMobile, isMobile,
isSafari, isSafari,
useMobileOrientation, useMobileOrientation,
} from "react-device-detect"; } from "react-device-detect";
import { FaCompress, FaExpand } from "react-icons/fa"; import { FaCompress, FaExpand } from "react-icons/fa";
import { IoMdArrowBack } from "react-icons/io"; import { IoMdArrowBack } from "react-icons/io";
import { LuPictureInPicture } from "react-icons/lu";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch"; import { TransformWrapper, TransformComponent } from "react-zoom-pan-pinch";
import useSWR from "swr"; import useSWR from "swr";
@ -35,8 +38,17 @@ export default function LiveBirdseyeView({
const [{ width: windowWidth, height: windowHeight }] = const [{ width: windowWidth, height: windowHeight }] =
useResizeObserver(window); useResizeObserver(window);
// pip state
useEffect(() => {
setPip(document.pictureInPictureElement != null);
// we know that these deps are correct
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [document.pictureInPictureElement]);
// playback state // playback state
const [pip, setPip] = useState(false);
const cameraAspectRatio = useMemo(() => { const cameraAspectRatio = useMemo(() => {
if (!config) { if (!config) {
return 16 / 9; return 16 / 9;
@ -151,6 +163,23 @@ export default function LiveBirdseyeView({
title={fullscreen ? "Close" : "Fullscreen"} title={fullscreen ? "Close" : "Fullscreen"}
onClick={toggleFullscreen} onClick={toggleFullscreen}
/> />
{!isIOS && !isFirefox && config.birdseye.restream && (
<CameraFeatureToggle
className="p-2 md:p-0"
variant={fullscreen ? "overlay" : "primary"}
Icon={LuPictureInPicture}
isActive={pip}
title={pip ? "Close" : "Picture in Picture"}
onClick={() => {
if (!pip) {
setPip(true);
} else {
document.exitPictureInPicture();
setPip(false);
}
}}
/>
)}
</div> </div>
</TooltipProvider> </TooltipProvider>
</div> </div>
@ -177,6 +206,7 @@ export default function LiveBirdseyeView({
birdseyeConfig={config.birdseye} birdseyeConfig={config.birdseye}
liveMode={preferredLiveMode} liveMode={preferredLiveMode}
containerRef={containerRef} containerRef={containerRef}
pip={pip}
/> />
</div> </div>
</TransformComponent> </TransformComponent>

View File

@ -372,7 +372,7 @@ export default function LiveCameraView({
onClick={toggleFullscreen} onClick={toggleFullscreen}
/> />
)} )}
{!isIOS && !isFirefox && ( {!isIOS && !isFirefox && preferredLiveMode != "jsmpeg" && (
<CameraFeatureToggle <CameraFeatureToggle
className="p-2 md:p-0" className="p-2 md:p-0"
variant={fullscreen ? "overlay" : "primary"} variant={fullscreen ? "overlay" : "primary"}
@ -452,8 +452,8 @@ export default function LiveCameraView({
iOSCompatFullScreen={isIOS} iOSCompatFullScreen={isIOS}
preferredLiveMode={preferredLiveMode} preferredLiveMode={preferredLiveMode}
pip={pip} pip={pip}
setFullResolution={setFullResolution}
containerRef={containerRef} containerRef={containerRef}
setFullResolution={setFullResolution}
onError={handleError} onError={handleError}
/> />
</div> </div>