livedesk 0.1.103 → 0.1.105

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.
package/hub/src/server.js CHANGED
@@ -21,6 +21,7 @@ const webIndexPath = resolve(webDistPath, 'index.html');
21
21
  const packageInfo = JSON.parse(readFileSync(resolve(__dirname, '..', 'package.json'), 'utf8'));
22
22
  const httpHost = process.env.LIVEDESK_HUB_HTTP_HOST || '0.0.0.0';
23
23
  const httpPort = Number(process.env.LIVEDESK_HUB_HTTP_PORT || process.env.PORT || 5179);
24
+ const frameBackpressureBytes = readPositiveIntegerEnv('LIVEDESK_FRAME_WS_BACKPRESSURE_BYTES', 512 * 1024);
24
25
  const frameClients = new Set();
25
26
  const inputClients = new Set();
26
27
  const audioClients = new Set();
@@ -28,6 +29,11 @@ let frameClientSeq = 0;
28
29
  let inputClientSeq = 0;
29
30
  let audioClientSeq = 0;
30
31
 
32
+ function readPositiveIntegerEnv(name, fallback) {
33
+ const value = Number(process.env[name]);
34
+ return Number.isFinite(value) && value > 0 ? Math.round(value) : fallback;
35
+ }
36
+
31
37
  function handleRemoteHubEvent(type, event) {
32
38
  if (type !== 'RemoteDeviceConnected') {
33
39
  return;
@@ -178,6 +184,8 @@ function normalizeLiveOptions(payload = {}) {
178
184
  quality: clampNumber(payload.quality, 20, 95, 45),
179
185
  monitorIndex: normalizeMonitorIndex(payload.monitorIndex ?? payload.screenIndex ?? payload.displayIndex),
180
186
  monitorSelections: normalizeMonitorSelections(payload.monitorSelections),
187
+ forceRestart: /^(1|true|yes|on)$/i.test(String(payload.forceRestart ?? '')),
188
+ reuseExisting: /^(1|true|yes|on)$/i.test(String(payload.reuseExisting ?? '')),
181
189
  mode,
182
190
  frameMode: mode
183
191
  };
@@ -277,7 +285,8 @@ function startFrameSubscriptionLive(ws, reason = 'subscribe', onlyDeviceId = '',
277
285
  const result = remoteHub.startLiveStream(deviceId, {
278
286
  ...liveOptions,
279
287
  monitorIndex,
280
- reuseExisting: liveOptions.reuseExisting === true || reason === 'subscribe' || reason === 'watchdog',
288
+ reuseExisting: liveOptions.forceRestart !== true
289
+ && (liveOptions.reuseExisting === true || reason === 'subscribe' || reason === 'watchdog'),
281
290
  silentReuse: reason === 'watchdog' && liveOptions.forceRestart !== true
282
291
  });
283
292
  if (result?.ok) {
@@ -410,6 +419,10 @@ function broadcastRemoteBinaryFrame(frameEvent) {
410
419
  if (!deviceId || frameClients.size === 0) {
411
420
  return;
412
421
  }
422
+ const frame = frameEvent.frame || {};
423
+ const isH264 = String(frame.codec || frame.mimeType || frame.format || '').toLowerCase().includes('h264')
424
+ || String(frame.frameMode || frame.mode || '').toLowerCase() === 'mode3-h264-hw';
425
+ const isKeyFrame = frame.isKeyFrame === true || String(frame.chunkType || '').toLowerCase() === 'key';
413
426
  const packet = buildRemoteFrameBinaryPacket(frameEvent);
414
427
  if (!packet) {
415
428
  return;
@@ -421,9 +434,16 @@ function broadcastRemoteBinaryFrame(frameEvent) {
421
434
  if (client.liveDeskDeviceIds?.size > 0 && !client.liveDeskDeviceIds.has(deviceId)) {
422
435
  continue;
423
436
  }
424
- if (client.bufferedAmount > 8 * 1024 * 1024) {
437
+ if (client.bufferedAmount > frameBackpressureBytes) {
438
+ client.liveDeskFrameBackpressured = true;
439
+ client.liveDeskFrameBackpressureDrops = Number(client.liveDeskFrameBackpressureDrops || 0) + 1;
440
+ continue;
441
+ }
442
+ if (client.liveDeskFrameBackpressured && isH264 && !isKeyFrame) {
443
+ client.liveDeskFrameBackpressureDrops = Number(client.liveDeskFrameBackpressureDrops || 0) + 1;
425
444
  continue;
426
445
  }
446
+ client.liveDeskFrameBackpressured = false;
427
447
  safeWebSocketSend(client, packet, { binary: true });
428
448
  }
429
449
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "livedesk",
3
- "version": "0.1.103",
3
+ "version": "0.1.105",
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.75",
33
+ "@livedesk/client": "0.1.76",
34
34
  "cors": "^2.8.5",
35
35
  "express": "^4.21.2",
36
36
  "ws": "^8.18.3"