livedesk 0.1.85 → 0.1.86

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.
@@ -4008,6 +4008,7 @@ export function createRemoteHub(options = {}) {
4008
4008
  const { fps, maxWidth, maxHeight, quality, monitorIndex, transfer } = normalized;
4009
4009
  const commandId = safeString(options.commandId, 128) || crypto.randomUUID();
4010
4010
  if (device.activeLiveStream?.streamId === streamId
4011
+ && options.forceRestart !== true
4011
4012
  && liveStreamMatchesOptions(device.activeLiveStream, normalized)
4012
4013
  && liveStreamIsReusable(device.activeLiveStream)) {
4013
4014
  if (options.silentReuse !== true) {
@@ -4030,6 +4031,16 @@ export function createRemoteHub(options = {}) {
4030
4031
  reused: true
4031
4032
  };
4032
4033
  }
4034
+ if (options.forceRestart === true && device.activeLiveStream?.streamId === streamId) {
4035
+ emitRemoteEvent('RemoteLiveStreamForcedRestart', device, {
4036
+ streamId,
4037
+ fps,
4038
+ mode: transfer.mode,
4039
+ frameMode: transfer.frameMode,
4040
+ monitorIndex,
4041
+ reason: safeString(options.restartReason || 'browser-stale', 128)
4042
+ });
4043
+ }
4033
4044
  if (device.activeLiveStream?.streamId === streamId
4034
4045
  && liveStreamMatchesOptions(device.activeLiveStream, normalized)
4035
4046
  && device.activeLiveStream.open === true
package/hub/src/server.js CHANGED
@@ -207,7 +207,7 @@ function updateFrameSubscription(ws, payload = {}) {
207
207
  startFrameSubscriptionLive(ws, 'subscribe');
208
208
  }
209
209
 
210
- function startFrameSubscriptionLive(ws, reason = 'subscribe', onlyDeviceId = '') {
210
+ function startFrameSubscriptionLive(ws, reason = 'subscribe', onlyDeviceId = '', overrideLiveOptions = null) {
211
211
  const subscribedIds = [...(ws.liveDeskDeviceIds || [])];
212
212
  if (!ws.liveDeskAutoStart || subscribedIds.length === 0) {
213
213
  return;
@@ -220,6 +220,9 @@ function startFrameSubscriptionLive(ws, reason = 'subscribe', onlyDeviceId = '')
220
220
  return;
221
221
  }
222
222
 
223
+ const liveOptions = overrideLiveOptions && typeof overrideLiveOptions === 'object'
224
+ ? { ...ws.liveDeskLiveOptions, ...overrideLiveOptions }
225
+ : ws.liveDeskLiveOptions;
223
226
  const lookup = new Map(remoteHub.listDevices({ includeDataUrl: false }).map(device => [device.deviceId, device]));
224
227
  const started = [];
225
228
  const skipped = [];
@@ -234,13 +237,13 @@ function startFrameSubscriptionLive(ws, reason = 'subscribe', onlyDeviceId = '')
234
237
  skipped.push({ deviceId, reason: device?.connected ? 'live-unavailable' : 'not-connected' });
235
238
  continue;
236
239
  }
237
- const monitorIndex = Object.prototype.hasOwnProperty.call(ws.liveDeskLiveOptions.monitorSelections || {}, deviceId)
238
- ? ws.liveDeskLiveOptions.monitorSelections[deviceId]
239
- : ws.liveDeskLiveOptions.monitorIndex;
240
+ const monitorIndex = Object.prototype.hasOwnProperty.call(liveOptions.monitorSelections || {}, deviceId)
241
+ ? liveOptions.monitorSelections[deviceId]
242
+ : liveOptions.monitorIndex;
240
243
  const result = remoteHub.startLiveStream(deviceId, {
241
- ...ws.liveDeskLiveOptions,
244
+ ...liveOptions,
242
245
  monitorIndex,
243
- silentReuse: reason === 'watchdog'
246
+ silentReuse: reason === 'watchdog' && liveOptions.forceRestart !== true
244
247
  });
245
248
  if (result?.ok) {
246
249
  started.push({ deviceId, streamId: result.streamId, fps: result.fps, reused: result.reused === true });
@@ -260,6 +263,29 @@ function startFrameSubscriptionLive(ws, reason = 'subscribe', onlyDeviceId = '')
260
263
  });
261
264
  }
262
265
 
266
+ function restartFrameSubscriptionLive(ws, payload = {}) {
267
+ const requestedIds = normalizeDeviceIds(payload.deviceIds ?? payload.devices ?? payload.deviceId);
268
+ const targetIds = requestedIds.length > 0
269
+ ? requestedIds
270
+ : [...(ws.liveDeskDeviceIds || [])];
271
+ if (targetIds.length === 0) {
272
+ sendJson(ws, { type: 'RemoteFrameSubscriptionError', error: 'restart-device-missing' });
273
+ return;
274
+ }
275
+ const restartOptions = {
276
+ ...normalizeLiveOptions({
277
+ ...ws.liveDeskLiveOptions,
278
+ ...payload
279
+ }),
280
+ forceRestart: true,
281
+ restartToken: String(payload.restartToken || `${Date.now()}`).slice(0, 128),
282
+ restartReason: String(payload.restartReason || payload.reason || 'browser-stale').slice(0, 128)
283
+ };
284
+ for (const deviceId of targetIds.slice(0, 16)) {
285
+ startFrameSubscriptionLive(ws, restartOptions.restartReason, deviceId, restartOptions);
286
+ }
287
+ }
288
+
263
289
  function updateAudioSubscription(ws, payload = {}) {
264
290
  const deviceIds = normalizeDeviceIds(payload.deviceIds ?? payload.devices ?? payload.deviceId);
265
291
  ws.liveDeskAudioDeviceIds = new Set(deviceIds);
@@ -728,6 +754,8 @@ frameWss.on('connection', (ws, req) => {
728
754
  const payload = JSON.parse(Buffer.isBuffer(data) ? data.toString('utf8') : String(data || ''));
729
755
  if (payload?.type === 'subscribe') {
730
756
  updateFrameSubscription(ws, payload);
757
+ } else if (payload?.type === 'restart-live') {
758
+ restartFrameSubscriptionLive(ws, payload);
731
759
  }
732
760
  } catch {
733
761
  sendJson(ws, { type: 'RemoteFrameSubscriptionError', error: 'invalid-message' });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "livedesk",
3
- "version": "0.1.85",
3
+ "version": "0.1.86",
4
4
  "description": "LiveDesk Hub and client launcher",
5
5
  "type": "module",
6
6
  "bin": {