Improve thumbnails and live player (#9828)

* Don't show gif until event is over and fix aspect

* Be more efficient about updating events

* ensure previews are sorted

* Don't show live view when window is not visible

* Move debug camera to separate view

* Improve jpg loading

* Ensure still is updated on player live finish

* Don't reload when window not visible

* Only disconnect instead of full remove

* Use start time instead of event over to determine gif
This commit is contained in:
Nicolas Mowen
2024-02-12 18:28:36 -07:00
committed by GitHub
parent f54cb21bd0
commit 63bc1b1582
8 changed files with 298 additions and 167 deletions

View File

@@ -4,10 +4,16 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
type MSEPlayerProps = {
camera: string;
className?: string;
playbackEnabled?: boolean;
onPlaying?: () => void;
};
function MSEPlayer({ camera, className, onPlaying }: MSEPlayerProps) {
function MSEPlayer({
camera,
className,
playbackEnabled = true,
onPlaying,
}: MSEPlayerProps) {
let connectTS: number = 0;
const RECONNECT_TIMEOUT: number = 30000;
@@ -203,6 +209,10 @@ function MSEPlayer({ camera, className, onPlaying }: MSEPlayerProps) {
};
useEffect(() => {
if (!playbackEnabled) {
return;
}
// iOS 17.1+ uses ManagedMediaSource
const MediaSourceConstructor =
"ManagedMediaSource" in window ? window.ManagedMediaSource : MediaSource;
@@ -236,18 +246,12 @@ function MSEPlayer({ camera, className, onPlaying }: MSEPlayerProps) {
observer.observe(videoRef.current!);
}
return () => {
onDisconnect();
};
}, [onDisconnect, onConnect]);
useEffect(() => {
onConnect();
return () => {
onDisconnect();
};
}, [wsURL]);
}, [playbackEnabled, onDisconnect, onConnect]);
return (
<video