|
|
@@ -0,0 +1,32 @@
|
|
|
+import test from 'node:test'
|
|
|
+import assert from 'node:assert/strict'
|
|
|
+import { createVideoLiveSession } from '../../src/modules/cockpit/services/videoLiveSession.js'
|
|
|
+
|
|
|
+const data = (code) => ({ deviceCode: code, sessionId: `session-${code}`, sessionToken: `owner-${code}`, mode: 'LIVE', media: { native: true, url: `https://media.invalid/${code}.mp4` } })
|
|
|
+
|
|
|
+test('simultaneous open commands never create a video for a superseded device', async () => {
|
|
|
+ const requests = [], updates = []
|
|
|
+ const live = createVideoLiveSession({
|
|
|
+ start: async (code) => { requests.push(code); return data(code) },
|
|
|
+ heartbeat: async () => {}, stop: async () => {},
|
|
|
+ }, (patch) => updates.push(patch))
|
|
|
+ try {
|
|
|
+ await Promise.all([live.start('A'), live.start('B')])
|
|
|
+ assert.deepEqual(requests, ['B'])
|
|
|
+ assert.equal(updates.some((patch) => patch.media?.url.endsWith('/A.mp4')), false)
|
|
|
+ } finally { await live.dispose() }
|
|
|
+})
|
|
|
+
|
|
|
+test('closing in the same turn cancels an open before it can start server media', async () => {
|
|
|
+ const requests = []
|
|
|
+ const live = createVideoLiveSession({
|
|
|
+ start: async (code) => { requests.push(code); return data(code) },
|
|
|
+ heartbeat: async () => {}, stop: async () => {},
|
|
|
+ }, () => {})
|
|
|
+ try {
|
|
|
+ const opening = live.start('A')
|
|
|
+ await live.stop()
|
|
|
+ await opening
|
|
|
+ assert.deepEqual(requests, [])
|
|
|
+ } finally { await live.dispose() }
|
|
|
+})
|