fixed API and stopping delay

This commit is contained in:
Marco Mooren
2026-05-27 12:54:56 +02:00
parent 470d4e8e76
commit 7b8d78ddaf
22 changed files with 495 additions and 98 deletions

View File

@@ -21,7 +21,15 @@ export function connectWs(onMessage, opts = {}) {
}
open();
return {
send(msg) { if (ws?.readyState === WebSocket.OPEN) ws.send(JSON.stringify(msg)); },
// Returns true when the message was actually queued on a live socket,
// false when the socket is closing/reconnecting. Callers that need to
// surface a transport failure (transport buttons) inspect the result;
// fire-and-forget callers can ignore it.
send(msg) {
if (ws?.readyState !== WebSocket.OPEN) return false;
ws.send(JSON.stringify(msg));
return true;
},
close() { closed = true; ws?.close(); },
get readyState() { return ws?.readyState; }
};