From 9cacb05b9f5a39213e6cf4d0e33696a515b38a6e Mon Sep 17 00:00:00 2001 From: davidliu Date: Wed, 21 Oct 2026 18:32:57 +0900 Subject: [PATCH] Ignore signal messages received after the WebSocket is closed on React Native --- .changeset/short-toys-push.md | 5 +++++ src/api/WebSocketStream.ts | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changeset/short-toys-push.md diff --git a/.changeset/short-toys-push.md b/.changeset/short-toys-push.md new file mode 100644 index 0000000000..07b12efbd5 --- /dev/null +++ b/.changeset/short-toys-push.md @@ -0,0 +1,5 @@ +--- +'livekit-client': patch +--- + +Ignore signal messages received after the WebSocket is closed on React Native diff --git a/src/api/WebSocketStream.ts b/src/api/WebSocketStream.ts index acab4330b6..6a88b43fba 100644 --- a/src/api/WebSocketStream.ts +++ b/src/api/WebSocketStream.ts @@ -67,7 +67,12 @@ export class WebSocketStream({ start(controller) { - ws.onmessage = ({ data }) => controller.enqueue(data); + ws.onmessage = ({ data }) => { + // workaround for RN behavior, browsers drop these messages already + if (ws.readyState === WebSocket.OPEN) { + controller.enqueue(data); + } + }; ws.onerror = (e) => controller.error(ConnectionError.websocket(getErrorDescription(e, 'websocket'))); ws.onclose = (ev) => {