default to jsmpeg if webrtc times out

This commit is contained in:
Josh Hawkins 2024-06-04 09:56:58 -05:00
parent 1b9e539903
commit fbf1b5fd55
3 changed files with 40 additions and 17 deletions

View File

@ -138,6 +138,7 @@ export default function LivePlayer({
iOSCompatFullScreen={iOSCompatFullScreen} iOSCompatFullScreen={iOSCompatFullScreen}
onPlaying={() => setLiveReady(true)} onPlaying={() => setLiveReady(true)}
pip={pip} pip={pip}
onError={onError}
/> />
); );
} else if (liveMode == "mse") { } else if (liveMode == "mse") {

View File

@ -316,24 +316,22 @@ function MSEPlayer({
if (isSafari || isIOS) { if (isSafari || isIOS) {
onPlaying?.(); onPlaying?.();
} }
return onError != undefined if (onError != undefined) {
? () => { if (videoRef.current?.paused) {
if (videoRef.current?.paused) { return;
return; }
}
if (bufferTimeout) { if (bufferTimeout) {
clearTimeout(bufferTimeout); clearTimeout(bufferTimeout);
setBufferTimeout(undefined); setBufferTimeout(undefined);
} }
setBufferTimeout( setBufferTimeout(
setTimeout(() => { setTimeout(() => {
onError("stalled"); onError("stalled");
}, 3000), }, 3000),
); );
} }
: undefined;
}} }}
onError={(e) => { onError={(e) => {
if ( if (
@ -349,6 +347,8 @@ function MSEPlayer({
(isSafari || isIOS) (isSafari || isIOS)
) { ) {
onError?.("mse-decode"); onError?.("mse-decode");
clearTimeout(bufferTimeout);
setBufferTimeout(undefined);
} }
if (wsRef.current) { if (wsRef.current) {

View File

@ -36,6 +36,7 @@ export default function WebRtcPlayer({
const pcRef = useRef<RTCPeerConnection | undefined>(); const pcRef = useRef<RTCPeerConnection | undefined>();
const videoRef = useRef<HTMLVideoElement | null>(null); const videoRef = useRef<HTMLVideoElement | null>(null);
const [bufferTimeout, setBufferTimeout] = useState<NodeJS.Timeout>(); const [bufferTimeout, setBufferTimeout] = useState<NodeJS.Timeout>();
const videoLoadTimeoutRef = useRef<NodeJS.Timeout>();
const PeerConnection = useCallback( const PeerConnection = useCallback(
async (media: string) => { async (media: string) => {
@ -193,6 +194,27 @@ export default function WebRtcPlayer({
videoRef.current.requestPictureInPicture(); videoRef.current.requestPictureInPicture();
}, [pip, videoRef]); }, [pip, videoRef]);
useEffect(() => {
videoLoadTimeoutRef.current = setTimeout(() => {
onError?.("stalled");
}, 5000);
return () => {
if (videoLoadTimeoutRef.current) {
clearTimeout(videoLoadTimeoutRef.current);
}
};
// we know that these deps are correct
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const handleLoadedData = () => {
if (videoLoadTimeoutRef.current) {
clearTimeout(videoLoadTimeoutRef.current);
}
onPlaying?.();
};
return ( return (
<video <video
ref={videoRef} ref={videoRef}
@ -201,7 +223,7 @@ export default function WebRtcPlayer({
autoPlay autoPlay
playsInline playsInline
muted={!audioEnabled} muted={!audioEnabled}
onLoadedData={onPlaying} onLoadedData={handleLoadedData}
onProgress={ onProgress={
onError != undefined onError != undefined
? () => { ? () => {