livedesk 0.1.67 → 0.1.68

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 +65 -32
  2. package/package.json +2 -2
package/hub/src/server.js CHANGED
@@ -28,6 +28,23 @@ let frameClientSeq = 0;
28
28
  let inputClientSeq = 0;
29
29
  let audioClientSeq = 0;
30
30
 
31
+ function handleRemoteHubEvent(type, event) {
32
+ if (type !== 'RemoteDeviceConnected') {
33
+ return;
34
+ }
35
+ const deviceId = String(event?.deviceId || event?.device?.deviceId || '').trim();
36
+ if (!deviceId) {
37
+ return;
38
+ }
39
+ for (const ws of frameClients) {
40
+ if (ws.readyState === 1
41
+ && ws.liveDeskAutoStart
42
+ && ws.liveDeskDeviceIds?.has(deviceId)) {
43
+ startFrameSubscriptionLive(ws, 'device-reconnected', deviceId);
44
+ }
45
+ }
46
+ }
47
+
31
48
  const remoteHub = createRemoteHub({
32
49
  managerPackage: '@livedesk/hub',
33
50
  managerVersion: packageInfo.version,
@@ -38,6 +55,7 @@ const remoteHub = createRemoteHub({
38
55
  },
39
56
  logEvent: (_scope, message) => console.log(`[LiveDesk Hub] ${message}`),
40
57
  logWarn: (_scope, message) => console.warn(`[LiveDesk Hub] ${message}`),
58
+ emitEvent: handleRemoteHubEvent,
41
59
  emitFrame: broadcastRemoteBinaryFrame,
42
60
  emitAudio: broadcastRemoteBinaryAudio
43
61
  });
@@ -185,41 +203,56 @@ function updateFrameSubscription(ws, payload = {}) {
185
203
  autoStartLive: ws.liveDeskAutoStart
186
204
  });
187
205
 
188
- if (ws.liveDeskAutoStart && deviceIds.length > 0) {
189
- const lookup = new Map(remoteHub.listDevices({ includeDataUrl: false }).map(device => [device.deviceId, device]));
190
- const started = [];
191
- const skipped = [];
192
- for (const deviceId of deviceIds.slice(0, 80)) {
193
- const device = lookup.get(deviceId);
194
- const liveCapable = device?.liveStreamEnabled === true
195
- || device?.liveStreamCapable === true
196
- || device?.capabilities?.liveStream === true
197
- || device?.capabilities?.stream === true
198
- || device?.capabilities?.screenStream === true;
199
- if (!device?.connected || !liveCapable) {
200
- skipped.push({ deviceId, reason: device?.connected ? 'live-unavailable' : 'not-connected' });
201
- continue;
202
- }
203
- const monitorIndex = Object.prototype.hasOwnProperty.call(ws.liveDeskLiveOptions.monitorSelections || {}, deviceId)
204
- ? ws.liveDeskLiveOptions.monitorSelections[deviceId]
205
- : ws.liveDeskLiveOptions.monitorIndex;
206
- const result = remoteHub.startLiveStream(deviceId, {
207
- ...ws.liveDeskLiveOptions,
208
- monitorIndex
209
- });
210
- if (result?.ok) {
211
- started.push({ deviceId, streamId: result.streamId, fps: result.fps });
212
- } else {
213
- skipped.push({ deviceId, reason: result?.error || 'start-failed' });
214
- }
206
+ startFrameSubscriptionLive(ws, 'subscribe');
207
+ }
208
+
209
+ function startFrameSubscriptionLive(ws, reason = 'subscribe', onlyDeviceId = '') {
210
+ const subscribedIds = [...(ws.liveDeskDeviceIds || [])];
211
+ if (!ws.liveDeskAutoStart || subscribedIds.length === 0) {
212
+ return;
213
+ }
214
+
215
+ const targetIds = onlyDeviceId
216
+ ? subscribedIds.filter(deviceId => deviceId === onlyDeviceId)
217
+ : subscribedIds;
218
+ if (targetIds.length === 0) {
219
+ return;
220
+ }
221
+
222
+ const lookup = new Map(remoteHub.listDevices({ includeDataUrl: false }).map(device => [device.deviceId, device]));
223
+ const started = [];
224
+ const skipped = [];
225
+ for (const deviceId of targetIds.slice(0, 80)) {
226
+ const device = lookup.get(deviceId);
227
+ const liveCapable = device?.liveStreamEnabled === true
228
+ || device?.liveStreamCapable === true
229
+ || device?.capabilities?.liveStream === true
230
+ || device?.capabilities?.stream === true
231
+ || device?.capabilities?.screenStream === true;
232
+ if (!device?.connected || !liveCapable) {
233
+ skipped.push({ deviceId, reason: device?.connected ? 'live-unavailable' : 'not-connected' });
234
+ continue;
215
235
  }
216
- sendJson(ws, {
217
- type: 'RemoteFrameLiveAutoStart',
218
- timestamp: new Date().toISOString(),
219
- started,
220
- skipped: skipped.slice(0, 24)
236
+ const monitorIndex = Object.prototype.hasOwnProperty.call(ws.liveDeskLiveOptions.monitorSelections || {}, deviceId)
237
+ ? ws.liveDeskLiveOptions.monitorSelections[deviceId]
238
+ : ws.liveDeskLiveOptions.monitorIndex;
239
+ const result = remoteHub.startLiveStream(deviceId, {
240
+ ...ws.liveDeskLiveOptions,
241
+ monitorIndex
221
242
  });
243
+ if (result?.ok) {
244
+ started.push({ deviceId, streamId: result.streamId, fps: result.fps, reused: result.reused === true });
245
+ } else {
246
+ skipped.push({ deviceId, reason: result?.error || 'start-failed' });
247
+ }
222
248
  }
249
+ sendJson(ws, {
250
+ type: 'RemoteFrameLiveAutoStart',
251
+ timestamp: new Date().toISOString(),
252
+ reason,
253
+ started,
254
+ skipped: skipped.slice(0, 24)
255
+ });
223
256
  }
224
257
 
225
258
  function updateAudioSubscription(ws, payload = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "livedesk",
3
- "version": "0.1.67",
3
+ "version": "0.1.68",
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.50",
33
+ "@livedesk/client": "0.1.51",
34
34
  "cors": "^2.8.5",
35
35
  "express": "^4.21.2",
36
36
  "ws": "^8.18.3"