@livedesk/hub 0.1.37 → 0.1.38

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livedesk/hub",
3
- "version": "0.1.37",
3
+ "version": "0.1.38",
4
4
  "description": "LiveDesk local Hub API and browser frame bridge",
5
5
  "type": "module",
6
6
  "main": "src/server.js",
package/src/remote-hub.js CHANGED
@@ -1119,9 +1119,19 @@ function getAccountRouteEndpointReason(endpoint, context = {}) {
1119
1119
  return 'ok';
1120
1120
  }
1121
1121
 
1122
- function safeText(value, maxLength = 1000) {
1123
- return String(value ?? '').replace(/\0/g, '').trim().slice(0, maxLength);
1124
- }
1122
+ function safeText(value, maxLength = 1000) {
1123
+ return String(value ?? '').replace(/\0/g, '').trim().slice(0, maxLength);
1124
+ }
1125
+
1126
+ function normalizeRemoteKeyboardKey(value) {
1127
+ const raw = String(value ?? '').replace(/\0/g, '');
1128
+ return raw === ' ' ? ' ' : safeString(raw, 80);
1129
+ }
1130
+
1131
+ function normalizeRemoteKeyboardText(value) {
1132
+ const raw = String(value ?? '').replace(/\0/g, '');
1133
+ return raw === ' ' ? ' ' : safeText(raw, 256);
1134
+ }
1125
1135
 
1126
1136
  function safeTaskData(value) {
1127
1137
  if (value === undefined || value === null) return undefined;
@@ -1202,14 +1212,14 @@ function readRawRemoteInputMonitorIndex(input) {
1202
1212
  return undefined;
1203
1213
  }
1204
1214
 
1205
- function normalizeRemoteInputEvent(value = {}) {
1215
+ function normalizeRemoteInputEvent(value = {}) {
1206
1216
  const input = value && typeof value === 'object' ? value : {};
1207
1217
  const type = safeString(input.type || input.Type, 48);
1208
1218
  const normalizedX = Number(input.normalizedX ?? input.NormalizedX);
1209
1219
  const normalizedY = Number(input.normalizedY ?? input.NormalizedY);
1210
1220
  const deltaX = Number(input.deltaX ?? input.DeltaX);
1211
1221
  const deltaY = Number(input.deltaY ?? input.DeltaY);
1212
- const keyCode = Number(input.keyCode ?? input.KeyCode);
1222
+ const keyCode = Number(input.keyCode ?? input.KeyCode);
1213
1223
  const location = Number(input.location ?? input.Location);
1214
1224
  const monitorIndex = parseExactLiveStreamMonitorIndex(readRawRemoteInputMonitorIndex(input));
1215
1225
  const inputSeq = Number(input.inputSeq ?? input.InputSeq);
@@ -1217,13 +1227,18 @@ function normalizeRemoteInputEvent(value = {}) {
1217
1227
  const hubReceivedAtEpochMs = Number(input.hubReceivedAtEpochMs ?? input.HubReceivedAtEpochMs);
1218
1228
  const captureGeneration = Number(input.captureGeneration ?? input.CaptureGeneration);
1219
1229
  const rawPressedCodes = input.pressedCodes ?? input.PressedCodes;
1220
- const pressedCodes = Array.isArray(rawPressedCodes)
1230
+ const pressedCodes = Array.isArray(rawPressedCodes)
1221
1231
  ? [...new Set(rawPressedCodes
1222
1232
  .map(code => safeString(code, 80))
1223
1233
  .filter(Boolean))]
1224
1234
  .slice(0, 64)
1225
- : null;
1226
- return {
1235
+ : null;
1236
+ const key = normalizeRemoteKeyboardKey(input.key ?? input.Key);
1237
+ let code = safeString(input.code ?? input.Code, 80);
1238
+ if ((!code || code === 'Unidentified') && (key === ' ' || key === 'Spacebar' || keyCode === 32)) {
1239
+ code = 'Space';
1240
+ }
1241
+ return {
1227
1242
  type,
1228
1243
  // A missing monitor is not equivalent to the primary display. Control
1229
1244
  // input must prove the exact monitor owned by its capture generation.
@@ -1233,11 +1248,11 @@ function normalizeRemoteInputEvent(value = {}) {
1233
1248
  button: safeString(input.button || input.Button, 24),
1234
1249
  deltaX: Number.isFinite(deltaX) ? Math.max(-4096, Math.min(4096, deltaX)) : 0,
1235
1250
  deltaY: Number.isFinite(deltaY) ? Math.max(-4096, Math.min(4096, deltaY)) : 0,
1236
- key: safeString(input.key || input.Key, 80),
1237
- code: safeString(input.code || input.Code, 80),
1251
+ key,
1252
+ code,
1238
1253
  keyCode: Number.isFinite(keyCode) ? Math.max(0, Math.min(65535, Math.trunc(keyCode))) : 0,
1239
1254
  location: Number.isFinite(location) ? Math.max(0, Math.min(255, Math.trunc(location))) : 0,
1240
- text: safeText(input.text || input.Text, 256),
1255
+ text: normalizeRemoteKeyboardText(input.text ?? input.Text),
1241
1256
  repeat: input.repeat === true || input.Repeat === true,
1242
1257
  pressedCodes,
1243
1258
  shiftKey: input.shiftKey === true || input.ShiftKey === true,
package/src/server.js CHANGED
@@ -2710,7 +2710,7 @@ function enqueueFramePacketForClient(ws, packetOwner, meta) {
2710
2710
  }
2711
2711
  // FRAME_LANE_GENERATION_CONTRACT_END
2712
2712
 
2713
- function updateFrameSubscription(ws, payload = {}) {
2713
+ function updateFrameSubscription(ws, payload = {}) {
2714
2714
  const previousDeviceIds = ws.liveDeskDeviceIds instanceof Set
2715
2715
  ? new Set(ws.liveDeskDeviceIds)
2716
2716
  : new Set();
@@ -2743,10 +2743,43 @@ function updateFrameSubscription(ws, payload = {}) {
2743
2743
  const targetIds = newlySubscribedIds.length > 0 ? newlySubscribedIds : deviceIds;
2744
2744
  for (const deviceId of targetIds.slice(0, 80)) {
2745
2745
  startFrameSubscriptionLive(ws, 'subscribe', deviceId, { reuseExisting: true });
2746
- }
2747
- }
2748
-
2749
- function startFrameSubscriptionLive(
2746
+ }
2747
+ }
2748
+
2749
+ function refreshFrameSubscriptionLive(ws, payload = {}) {
2750
+ if (!ws || ws.readyState !== 1) {
2751
+ return;
2752
+ }
2753
+ const requestedIds = normalizeDeviceIds(payload.deviceIds ?? payload.devices ?? payload.deviceId);
2754
+ const subscribedIds = [...(ws.liveDeskDeviceIds || [])];
2755
+ const targetIds = requestedIds.length > 0
2756
+ ? requestedIds.filter(deviceId => ws.liveDeskDeviceIds?.has?.(deviceId))
2757
+ : subscribedIds;
2758
+ if (targetIds.length === 0) {
2759
+ return;
2760
+ }
2761
+ ws.liveDeskAutoStart = /^(1|true|yes|on|live)$/i.test(String(
2762
+ payload.autoStartLive ?? payload.startLive ?? ws.liveDeskAutoStart ?? ''
2763
+ ));
2764
+ ws.liveDeskLiveOptions = normalizeLiveOptions({
2765
+ ...(ws.liveDeskLiveOptions || {}),
2766
+ ...payload,
2767
+ forceRestart: false,
2768
+ reuseExisting: true,
2769
+ monitorSelections: {
2770
+ ...(ws.liveDeskLiveOptions?.monitorSelections || {}),
2771
+ ...(payload.monitorSelections || {})
2772
+ }
2773
+ });
2774
+ for (const deviceId of targetIds.slice(0, 80)) {
2775
+ startFrameSubscriptionLive(ws, 'watchdog', deviceId, {
2776
+ ...ws.liveDeskLiveOptions,
2777
+ reuseExisting: true
2778
+ });
2779
+ }
2780
+ }
2781
+
2782
+ function startFrameSubscriptionLive(
2750
2783
  ws,
2751
2784
  reason = 'subscribe',
2752
2785
  onlyDeviceId = '',
@@ -5494,9 +5527,11 @@ frameWss.on('connection', (ws, req) => {
5494
5527
  ws.on('message', data => {
5495
5528
  try {
5496
5529
  const payload = JSON.parse(Buffer.isBuffer(data) ? data.toString('utf8') : String(data || ''));
5497
- if (payload?.type === 'subscribe') {
5498
- updateFrameSubscription(ws, payload);
5499
- } else if (payload?.type === 'restart-live') {
5530
+ if (payload?.type === 'subscribe') {
5531
+ updateFrameSubscription(ws, payload);
5532
+ } else if (payload?.type === 'refresh-live') {
5533
+ refreshFrameSubscriptionLive(ws, payload);
5534
+ } else if (payload?.type === 'restart-live') {
5500
5535
  restartFrameSubscriptionLive(ws, payload);
5501
5536
  }
5502
5537
  } catch {