livedesk 0.1.104 → 0.1.106
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;
|
|
@@ -413,6 +419,10 @@ function broadcastRemoteBinaryFrame(frameEvent) {
|
|
|
413
419
|
if (!deviceId || frameClients.size === 0) {
|
|
414
420
|
return;
|
|
415
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';
|
|
416
426
|
const packet = buildRemoteFrameBinaryPacket(frameEvent);
|
|
417
427
|
if (!packet) {
|
|
418
428
|
return;
|
|
@@ -424,9 +434,16 @@ function broadcastRemoteBinaryFrame(frameEvent) {
|
|
|
424
434
|
if (client.liveDeskDeviceIds?.size > 0 && !client.liveDeskDeviceIds.has(deviceId)) {
|
|
425
435
|
continue;
|
|
426
436
|
}
|
|
427
|
-
if (client.bufferedAmount >
|
|
437
|
+
if (client.bufferedAmount > frameBackpressureBytes) {
|
|
438
|
+
client.liveDeskFrameBackpressured = true;
|
|
439
|
+
client.liveDeskFrameBackpressureDrops = Number(client.liveDeskFrameBackpressureDrops || 0) + 1;
|
|
428
440
|
continue;
|
|
429
441
|
}
|
|
442
|
+
if (client.liveDeskFrameBackpressured && isH264 && !isKeyFrame) {
|
|
443
|
+
client.liveDeskFrameBackpressureDrops = Number(client.liveDeskFrameBackpressureDrops || 0) + 1;
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
client.liveDeskFrameBackpressured = false;
|
|
430
447
|
safeWebSocketSend(client, packet, { binary: true });
|
|
431
448
|
}
|
|
432
449
|
}
|
|
@@ -845,6 +862,11 @@ inputWss.on('connection', ws => {
|
|
|
845
862
|
const deviceId = String(payload?.deviceId || '').trim();
|
|
846
863
|
const input = payload?.input && typeof payload.input === 'object' ? payload.input : payload;
|
|
847
864
|
const result = remoteHub.sendInputControl(deviceId, input);
|
|
865
|
+
const fireAndForget = payload?.fireAndForget === true
|
|
866
|
+
|| String(input?.type || '').toLowerCase() === 'pointermove';
|
|
867
|
+
if (fireAndForget && result?.ok) {
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
848
870
|
sendJson(ws, {
|
|
849
871
|
type: result?.ok ? 'RemoteInputQueued' : 'RemoteInputError',
|
|
850
872
|
requestId: payload?.requestId || '',
|