Only close MSE websocket when it's already open (#12078)

This commit is contained in:
Josh Hawkins 2024-06-20 06:03:14 -06:00 committed by GitHub
parent 5c33cdba4e
commit 9f81ce2876
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -117,12 +117,12 @@ function MSEPlayer({
}, [wsURL]); }, [wsURL]);
const onDisconnect = useCallback(() => { const onDisconnect = useCallback(() => {
setWsState(WebSocket.CLOSED); if (wsRef.current && wsState == WebSocket.OPEN) {
if (wsRef.current) { setWsState(WebSocket.CLOSED);
wsRef.current.close(); wsRef.current.close();
wsRef.current = null; wsRef.current = null;
} }
}, []); }, [wsState]);
const onOpen = () => { const onOpen = () => {
setWsState(WebSocket.OPEN); setWsState(WebSocket.OPEN);