| 1234567891011121314151617181920212223242526 |
- import test from 'node:test'
- import assert from 'node:assert/strict'
- import { createVideoLiveSession } from '../../src/modules/cockpit/services/videoLiveSession.js'
- // 后端 CockpitVideoService.preparedResult 只回 sessionId/status/mode/media,
- // 不含 deviceCode。真实链路必须能接受这个契约,不能误判成"设备不匹配"。
- const prepared = (code) => ({ deviceCode: code, sessionId: 'session-x', sessionToken: 'owner-x', mode: 'LIVE', status: 'PREPARED' })
- const liveWithoutDeviceCode = { sessionId: 'session-x', status: 'ACTIVE', mode: 'LIVE',
- media: { native: true, url: 'https://media.invalid/live.mp4' } }
- test('the real prepared-live payload without deviceCode still starts one active video', async () => {
- const updates = [], releases = []
- const live = createVideoLiveSession({
- prepare: async (code) => prepared(code),
- start: async () => liveWithoutDeviceCode,
- status: async () => liveWithoutDeviceCode,
- heartbeat: async () => {},
- stop: async (session) => { releases.push(session.sessionId); return { sessionId: session.sessionId, status: 'STOPPED' } },
- }, (patch) => updates.push(patch))
- try {
- await live.start('CAM/契约')
- assert.ok(updates.some((patch) => patch.media?.url === 'https://media.invalid/live.mp4'),
- '真实后端不回 deviceCode 时也必须进入播放,而不是被判为设备不匹配')
- assert.deepEqual(releases, [], '正常启动不得触发释放')
- } finally { await live.dispose() }
- })
|