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

View File

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