Live video on the AT Protocol
79
fork

Configure Feed

Select the types of activity you want to include in your feed.

at eli/docker-linting 83 lines 2.7 kB view raw
1import { useCallback, useEffect, useRef } from "react"; 2import { TamaguiElement, View } from "tamagui"; 3import Controls from "./controls"; 4import PlayerLoading from "./player-loading"; 5import { PlayerProps } from "./props"; 6import Video from "./video"; 7import VideoRetry from "./video-retry"; 8 9export default function Fullscreen(props: PlayerProps) { 10 const divRef = useRef<TamaguiElement>(null); 11 const videoRef = useRef<HTMLVideoElement | null>(null); 12 const videoCallback = useCallback((node: HTMLVideoElement | null) => { 13 videoRef.current = node; 14 if (typeof props.videoRef === "function") { 15 props.videoRef(node); 16 } else if (props.videoRef) { 17 props.videoRef.current = node; 18 } 19 }, []); 20 21 const setFullscreen = (on: boolean) => { 22 if (!divRef.current) { 23 return; 24 } 25 (async () => { 26 if (on && !document.fullscreenElement) { 27 try { 28 const div = divRef.current as HTMLDivElement; 29 if (typeof div.requestFullscreen === "function") { 30 await div.requestFullscreen(); 31 } else if (videoRef.current) { 32 if ( 33 typeof (videoRef.current as any).webkitEnterFullscreen === 34 "function" 35 ) { 36 await (videoRef.current as any).webkitEnterFullscreen(); 37 } else if ( 38 typeof videoRef.current.requestFullscreen === "function" 39 ) { 40 await videoRef.current.requestFullscreen(); 41 } 42 } 43 props.setFullscreen(true); 44 } catch (e) { 45 console.error("fullscreen failed", e.message); 46 } 47 } 48 if (!on) { 49 if (document.fullscreenElement) { 50 try { 51 await document.exitFullscreen(); 52 } catch (e) { 53 console.error("fullscreen exit failed", e.message); 54 } 55 } 56 props.setFullscreen(false); 57 } 58 })(); 59 }; 60 61 useEffect(() => { 62 const listener = () => { 63 console.log("fullscreenchange", document.fullscreenElement); 64 props.setFullscreen(!!document.fullscreenElement); 65 }; 66 document.body.addEventListener("fullscreenchange", listener); 67 document.body.addEventListener("webkitfullscreenchange", listener); 68 return () => { 69 document.body.removeEventListener("fullscreenchange", listener); 70 document.body.removeEventListener("webkitfullscreenchange", listener); 71 }; 72 }, []); 73 74 return ( 75 <View flex={1} ref={divRef}> 76 <PlayerLoading {...props}></PlayerLoading> 77 <Controls {...props} setFullscreen={setFullscreen} videoRef={videoRef} /> 78 <VideoRetry {...props}> 79 <Video {...props} videoRef={videoCallback} /> 80 </VideoRetry> 81 </View> 82 ); 83}