livedesk 0.1.367 → 0.1.369

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.
@@ -2,23 +2,46 @@ import { Mode4AtlasSession } from './mode4-atlas.js';
2
2
  import { randomUUID } from 'node:crypto';
3
3
 
4
4
  export function buildMode4AtlasSessionKey(config = {}) {
5
- const monitorSelections = Object.fromEntries(
6
- Object.entries(config.monitorSelections || {})
7
- .sort(([left], [right]) => left.localeCompare(right))
8
- .map(([deviceId, monitorIndex]) => [deviceId, Number(monitorIndex || 0)])
9
- );
10
5
  return JSON.stringify({
11
6
  deviceIds: Array.isArray(config.deviceIds) ? config.deviceIds : [],
12
- inputDeviceIds: Array.isArray(config.inputDeviceIds) ? config.inputDeviceIds : [],
13
7
  width: Number(config.width || 1920),
14
8
  height: Number(config.height || 1080),
15
9
  tileWidth: Number(config.tileWidth || 320),
16
10
  tileHeight: Number(config.tileHeight || 180),
17
- fps: Number(config.fps || 20),
18
- monitorSelections
11
+ fps: Number(config.fps || 20)
19
12
  });
20
13
  }
21
14
 
15
+ export function planMode4AtlasInputTransitions(previous = {}, next = {}) {
16
+ const previousIds = new Set(Array.isArray(previous.inputDeviceIds) ? previous.inputDeviceIds : []);
17
+ const nextIds = new Set(Array.isArray(next.inputDeviceIds) ? next.inputDeviceIds : []);
18
+ const previousMonitorSelections = previous.monitorSelections || {};
19
+ const nextMonitorSelections = next.monitorSelections || {};
20
+ const captureSizeChanged = previousIds.size > 0
21
+ && (Number(previous.tileWidth || 0) !== Number(next.tileWidth || 0)
22
+ || Number(previous.tileHeight || 0) !== Number(next.tileHeight || 0));
23
+ const stop = [...previousIds].filter(deviceId => !nextIds.has(deviceId));
24
+ const start = [];
25
+ const restart = [];
26
+ const unchanged = [];
27
+
28
+ for (const deviceId of nextIds) {
29
+ if (!previousIds.has(deviceId)) {
30
+ start.push(deviceId);
31
+ continue;
32
+ }
33
+ const previousMonitorIndex = Number(previousMonitorSelections[deviceId] || 0);
34
+ const nextMonitorIndex = Number(nextMonitorSelections[deviceId] || 0);
35
+ if (captureSizeChanged || previousMonitorIndex !== nextMonitorIndex) {
36
+ restart.push(deviceId);
37
+ } else {
38
+ unchanged.push(deviceId);
39
+ }
40
+ }
41
+
42
+ return { stop, start, restart, unchanged };
43
+ }
44
+
22
45
  export class Mode4AtlasPool {
23
46
  constructor(options = {}) {
24
47
  this.createSession = typeof options.createSession === 'function'
@@ -107,7 +107,11 @@ export class Mode4AtlasSession {
107
107
  const frame = frameEvent?.frame || {};
108
108
  const deviceId = String(frameEvent?.deviceId || frame.deviceId || '').trim();
109
109
  const mode = String(frame.frameMode || frame.mode || '').toLowerCase();
110
- if (!this.inputDeviceSet.has(deviceId) || mode !== 'mode2-lzo' || !Buffer.isBuffer(frameEvent?.payload)) return;
110
+ const streamPurpose = String(frame.streamPurpose || '').trim().toLowerCase();
111
+ if (!this.inputDeviceSet.has(deviceId)
112
+ || mode !== 'mode2-lzo'
113
+ || streamPurpose !== 'atlas'
114
+ || !Buffer.isBuffer(frameEvent?.payload)) return;
111
115
  this.pendingFrames.set(deviceId, {
112
116
  type: 'frame',
113
117
  deviceId,