From f92a23fd74e1342de2650558d57a1e1bc2ece57b Mon Sep 17 00:00:00 2001 From: Scott Lamb Date: Mon, 29 Mar 2021 11:49:33 -0700 Subject: [PATCH] fix Multiview to work in Safari and Firefox LiveCamera itself still doesn't work in Safari, but small steps. --- ui/src/Live/LiveCamera.tsx | 110 ++++++++++++++++++---------- ui/src/Live/Multiview.tsx | 143 ++++++++++++++++++++----------------- ui/src/Live/index.tsx | 4 +- 3 files changed, 151 insertions(+), 106 deletions(-) diff --git a/ui/src/Live/LiveCamera.tsx b/ui/src/Live/LiveCamera.tsx index d59c562..5d56c80 100644 --- a/ui/src/Live/LiveCamera.tsx +++ b/ui/src/Live/LiveCamera.tsx @@ -11,7 +11,8 @@ import CircularProgress from "@material-ui/core/CircularProgress"; import Alert from "@material-ui/core/Alert"; interface LiveCameraProps { - camera: Camera; + camera: Camera | null; + chooser: JSX.Element; } interface BufferStateClosed { @@ -274,11 +275,15 @@ class LiveCameraDriver { /** * A live view of a camera. + * + * The caller is currently expected to put this into a 16x9 block. + * * Note there's a significant setup cost to creating a LiveCamera, so the parent * should use React's key attribute to avoid unnecessarily mounting * and unmounting a camera. + * */ -const LiveCamera = ({ camera }: LiveCameraProps) => { +const LiveCamera = ({ camera, chooser }: LiveCameraProps) => { const videoRef = React.useRef(null); const [playbackState, setPlaybackState] = React.useState({ state: "normal", @@ -287,6 +292,10 @@ const LiveCamera = ({ camera }: LiveCameraProps) => { // Load the camera driver. const [driver, setDriver] = React.useState(null); React.useEffect(() => { + if (camera === null) { + setDriver(null); + return; + } const d = new LiveCameraDriver(camera, setPlaybackState, videoRef); setDriver(d); return () => { @@ -308,43 +317,10 @@ const LiveCamera = ({ camera }: LiveCameraProps) => { return () => clearTimeout(timerId); }, [playbackState]); - if (driver === null) { - return ; - } - return ( - - {showProgress && ( -
- -
- )} - {playbackState.state === "error" && ( -
- {playbackState.message} -
- )} + const videoElement = + driver === null ? ( +