livedesk 0.1.99 → 0.1.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/hub/src/server.js +32 -4
  2. package/package.json +2 -2
package/hub/src/server.js CHANGED
@@ -188,8 +188,36 @@ function sendJson(ws, payload) {
188
188
  if (!ws || ws.readyState !== 1) {
189
189
  return false;
190
190
  }
191
- ws.send(JSON.stringify(payload));
192
- return true;
191
+ return safeWebSocketSend(ws, JSON.stringify(payload));
192
+ }
193
+
194
+ function forgetWebSocketClient(ws) {
195
+ frameClients.delete(ws);
196
+ audioClients.delete(ws);
197
+ inputClients.delete(ws);
198
+ try {
199
+ ws.terminate?.();
200
+ } catch {
201
+ // Ignore cleanup failures.
202
+ }
203
+ }
204
+
205
+ function safeWebSocketSend(ws, payload, options = undefined) {
206
+ if (!ws || ws.readyState !== 1) {
207
+ return false;
208
+ }
209
+
210
+ try {
211
+ ws.send(payload, options, err => {
212
+ if (err) {
213
+ forgetWebSocketClient(ws);
214
+ }
215
+ });
216
+ return true;
217
+ } catch {
218
+ forgetWebSocketClient(ws);
219
+ return false;
220
+ }
193
221
  }
194
222
 
195
223
  function updateFrameSubscription(ws, payload = {}) {
@@ -389,7 +417,7 @@ function broadcastRemoteBinaryFrame(frameEvent) {
389
417
  if (client.bufferedAmount > 8 * 1024 * 1024) {
390
418
  continue;
391
419
  }
392
- client.send(packet, { binary: true });
420
+ safeWebSocketSend(client, packet, { binary: true });
393
421
  }
394
422
  }
395
423
 
@@ -412,7 +440,7 @@ function broadcastRemoteBinaryAudio(audioEvent) {
412
440
  if (client.bufferedAmount > 2 * 1024 * 1024) {
413
441
  continue;
414
442
  }
415
- client.send(packet, { binary: true });
443
+ safeWebSocketSend(client, packet, { binary: true });
416
444
  }
417
445
  }
418
446
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "livedesk",
3
- "version": "0.1.99",
3
+ "version": "0.1.100",
4
4
  "description": "LiveDesk Hub and client launcher",
5
5
  "type": "module",
6
6
  "bin": {
@@ -30,7 +30,7 @@
30
30
  "node": ">=20"
31
31
  },
32
32
  "dependencies": {
33
- "@livedesk/client": "0.1.72",
33
+ "@livedesk/client": "0.1.73",
34
34
  "cors": "^2.8.5",
35
35
  "express": "^4.21.2",
36
36
  "ws": "^8.18.3"