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}
onPlaying={() => setLiveReady(true)}
pip={pip}
onError={onError}
/>
);
} else if (liveMode == "mse") {

View File

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

View File

@ -36,6 +36,7 @@ export default function WebRtcPlayer({
const pcRef = useRef<RTCPeerConnection | undefined>();
const videoRef = useRef<HTMLVideoElement | null>(null);
const [bufferTimeout, setBufferTimeout] = useState<NodeJS.Timeout>();
const videoLoadTimeoutRef = useRef<NodeJS.Timeout>();
const PeerConnection = useCallback(
async (media: string) => {
@ -193,6 +194,27 @@ export default function WebRtcPlayer({
videoRef.current.requestPictureInPicture();
}, [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 (
<video
ref={videoRef}
@ -201,7 +223,7 @@ export default function WebRtcPlayer({
autoPlay
playsInline
muted={!audioEnabled}
onLoadedData={onPlaying}
onLoadedData={handleLoadedData}
onProgress={
onError != undefined
? () => {