Fall back to REST polling when the WebSocket cannot connect
On some mobile networks/browsers the wss:// upgrade is blocked even though the page loads (the server side is verified working: a browser-style handshake gets 101). After three socket failures the header now shows "polling (5s)" instead of a misleading perpetual "reconnecting", since the 5s REST poll keeps all data correct. The socket error handler also surfaces the browser's message.
This commit is contained in:
1 parent
07c17fbd2c
commit
bf7eda3f6a
2 files changed
+16
-4
No files matched your search
+6
-1
@@ -58,7 +58,12 @@ export function openSocket({ onMessage, onOpen, onClose, onError }) {
|
||||
onError?.(event.code, event.reason)
|
||||
schedule()
|
||||
}
|
||||
socket.onerror = () => socket.close()
|
||||
socket.onerror = (event) => {
|
||||
// The browser hides details here; surface what it does give us.
|
||||
const detail = event?.message || 'connection error'
|
||||
onError?.(0, detail)
|
||||
socket.close()
|
||||
}
|
||||
}
|
||||
connect()
|
||||
|
||||
|
||||
Reference in new issue
Block a user