Refine player control-plane flow
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const vm = require('node:vm');
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
|
||||
function loadScript(scriptPath, sandbox) {
|
||||
const source = fs.readFileSync(scriptPath, 'utf8');
|
||||
vm.runInNewContext(source, sandbox, { filename: scriptPath });
|
||||
}
|
||||
|
||||
test('webpage preloading only targets the next slide', () => {
|
||||
const sandbox = {
|
||||
window: null,
|
||||
Date,
|
||||
Array,
|
||||
Number,
|
||||
String,
|
||||
Boolean,
|
||||
Object,
|
||||
Math,
|
||||
console,
|
||||
escapeHtml(value) {
|
||||
return String(value || '');
|
||||
},
|
||||
currentPlaylistSignature: 'signature',
|
||||
slides: [],
|
||||
index: 0,
|
||||
activeSlidesCacheKey: '',
|
||||
activeSlidesCacheValue: [],
|
||||
renderCacheViewportKey: '',
|
||||
preloadSignature: '',
|
||||
preloadContainer: null
|
||||
};
|
||||
sandbox.window = sandbox;
|
||||
|
||||
loadScript(path.join(__dirname, '..', 'src', 'player', 'public', 'js', 'player-page-playlist.js'), sandbox);
|
||||
|
||||
const current = { id: 1 };
|
||||
const next = { id: 2 };
|
||||
const later = { id: 3 };
|
||||
|
||||
assert.equal(sandbox.getWebpagePreloadSlides([current, next, later], 0).map((slide) => slide.id).join(','), '2');
|
||||
assert.equal(sandbox.getWebpagePreloadSlides([current, next, later], 1).map((slide) => slide.id).join(','), '3');
|
||||
assert.equal(sandbox.getWebpagePreloadSlides([current, next, later], 2).map((slide) => slide.id).join(','), '');
|
||||
});
|
||||
|
||||
test('rtmp warmups only target the next slide', () => {
|
||||
const sandbox = {
|
||||
window: null,
|
||||
Date,
|
||||
Array,
|
||||
Number,
|
||||
String,
|
||||
Boolean,
|
||||
Object,
|
||||
Math,
|
||||
console,
|
||||
fetch() {
|
||||
throw new Error('not expected');
|
||||
},
|
||||
currentPlaylistSkipUnavailableRtmp: false,
|
||||
videoRegionRenderVersion: 0,
|
||||
slideMarkupCache: Object.create(null),
|
||||
slides: [],
|
||||
index: 0,
|
||||
setTimeout,
|
||||
clearTimeout,
|
||||
document: {
|
||||
createElement() {
|
||||
return {
|
||||
className: '',
|
||||
setAttribute() {},
|
||||
appendChild() {},
|
||||
parentNode: null,
|
||||
addEventListener() {}
|
||||
};
|
||||
},
|
||||
body: {
|
||||
appendChild() {}
|
||||
}
|
||||
},
|
||||
pulsePlayerRegionTypes: {
|
||||
register() {}
|
||||
}
|
||||
};
|
||||
sandbox.window = sandbox;
|
||||
|
||||
loadScript(path.join(__dirname, '..', 'src', 'player', 'regions', 'rtmp.js'), sandbox);
|
||||
|
||||
const current = { id: 1 };
|
||||
const next = { id: 2 };
|
||||
const later = { id: 3 };
|
||||
|
||||
assert.equal(sandbox.getRtmpWarmupSlides([current, next, later], 0).map((slide) => slide.id).join(','), '2');
|
||||
assert.equal(sandbox.getRtmpWarmupSlides([current, next, later], 1).map((slide) => slide.id).join(','), '3');
|
||||
assert.equal(sandbox.getRtmpWarmupSlides([current, next, later], 2).map((slide) => slide.id).join(','), '');
|
||||
});
|
||||
Reference in New Issue
Block a user