mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-22 11:12:18 +00:00
71 lines
1.9 KiB
JavaScript
71 lines
1.9 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { attachCctvVideo } from './videoPlayback.js';
|
|
function video() {
|
|
const v = new EventTarget();
|
|
Object.assign(v, {
|
|
src: '',
|
|
pause() {},
|
|
load() {},
|
|
removeAttribute() {},
|
|
play: () => Promise.resolve(),
|
|
});
|
|
return v;
|
|
}
|
|
test('switch during lazy import never starts the stale decoder', async () => {
|
|
let resolve;
|
|
let constructed = 0;
|
|
class Hls {
|
|
constructor() {
|
|
constructed++;
|
|
}
|
|
static isSupported() {
|
|
return true;
|
|
}
|
|
}
|
|
const source = video();
|
|
const playback = attachCctvVideo(source, '/api/cctv/media/a', 'hls', {
|
|
loadHls: () =>
|
|
new Promise((r) => {
|
|
resolve = r;
|
|
}),
|
|
});
|
|
playback.dispose();
|
|
resolve({ default: Hls });
|
|
await playback.ready;
|
|
assert.equal(constructed, 0);
|
|
assert.equal(source.src, '');
|
|
});
|
|
test('missing decoder uses honest failure fallback once', async () => {
|
|
let failures = 0;
|
|
const playback = attachCctvVideo(video(), '/api/cctv/media/a', 'hls', {
|
|
loadHls: async () => {
|
|
throw new Error('unavailable');
|
|
},
|
|
onFailure: () => failures++,
|
|
});
|
|
await playback.ready;
|
|
playback.dispose();
|
|
assert.equal(failures, 1);
|
|
});
|
|
|
|
test('native HLS releases its client lease without response-header access', async () => {
|
|
const source = video();
|
|
source.canPlayType = () => 'probably';
|
|
const releases = [];
|
|
const playback = attachCctvVideo(source, '/api/cctv/media/a', 'hls', {
|
|
loadHls: async () => ({ default: { isSupported: () => false } }),
|
|
fetchImpl: async (url, init) => {
|
|
releases.push({ url, init });
|
|
},
|
|
});
|
|
await playback.ready;
|
|
assert.match(source.src, /\/api\/cctv\/media\/a\?lease=[a-f0-9-]{36}$/);
|
|
const requested = source.src;
|
|
playback.dispose();
|
|
playback.dispose();
|
|
assert.equal(releases.length, 1);
|
|
assert.equal(releases[0].url, requested);
|
|
assert.equal(releases[0].init.method, 'DELETE');
|
|
});
|