Skip to content

Commit 4f0b151

Browse files
authored
fix: improve WebSocket close handling in VideoPlayer component (#128)
1 parent 67473e1 commit 4f0b151

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

  • web_ui/src/pages/Instant/components/VideoPlayer

web_ui/src/pages/Instant/components/VideoPlayer/index.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,16 @@ const VideoPlayer = ({ codec = 'avc1.42E01E', poster, style, cameraId, channel,
205205
onPlay && onPlay()
206206
}
207207
// connection closed handling
208-
wsRef.current.onclose = () => {
208+
wsRef.current.onclose = (event) => {
209209
console.log('video player: WebSocket connection closed')
210210
if (!error) {
211211
setError(t('instant.deviceList.deviceConnectClosed'))
212212
// message.error(t('instant.deviceList.deviceConnectClosed'))
213213
}
214-
onPlay && onPlay()
214+
const { reason = '' } = event;
215+
if (reason !== 'close_by_user') {
216+
onPlay && onPlay()
217+
}
215218
}
216219

217220
decoderRef.current = new window.VideoDecoder({
@@ -280,7 +283,7 @@ const VideoPlayer = ({ codec = 'avc1.42E01E', poster, style, cameraId, channel,
280283
return () => {
281284
if (wsRef.current) {
282285
try {
283-
wsRef.current.close && wsRef.current.close();
286+
wsRef.current.close && wsRef.current.close(1000, 'close_by_user');
284287
} catch (e) {
285288
console.error('Close WebSocket exception:', e);
286289
}

0 commit comments

Comments
 (0)