mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
fix(cctv): key-gate Ottawa, opt-in Québec video, keep shared slots
Review fixes for #1506. - Ottawa: use the documented camera list and the city's Traffic Camera Images API. The pack is skipped with no request unless OTTAWA_CAMERA_CERTIFICATE is set; the certificate is added only at fetch time inside the pinned /opendata/ path, and each camera is fetched at most once a minute through the shared frame cache. - Québec 511 video is opt-in (CCTV_QUEBEC_VIDEO_ENABLED=1) and loads only after the viewer presses Play; selection, auto-hop, scenes and voice no longer contact Québec 511. Credit splits locations (MTQ, CC BY 4.0) from video (Québec 511). Interrupted play() is no longer reported as an unavailable source; the per-frame listener runs only while a Québec camera is selected and the canvas rect is cached. - Catalog cap: reserved Québec and World slots come only from capacity above the 4,000 shared slots, so a lower CCTV_MAX_SOURCES thins every pack instead of starving the existing ones. dev-fresh and .env.example default to 7,516. - Throttled frames (World, Ottawa): inside the refresh floor with no cached frame the proxy serves the placeholder, never Street View; a failed fetch backs off for a minute; the cache is bounded by bytes. - MJPEG first-frame extraction runs only for sources registered as MJPEG (Taiwan Highway Bureau), caps a frame at 2 MB, reads in linear time, accepts a CRLF preamble and a boundary that already starts with "--", and ends a part without Content-Length at the next delimiter. THB hosts are registered in the redirect pin list. - Tests: World loader policy, Québec loader and opt-in, proxy cooldown without Street View, Ottawa signing, cap reservations at 7,516, 4,000 and 48, overlay Play gate, refresh, visibility and teardown. Guard tests check the 4,000 shared slots again. - Remove the unused standalone Québec preview module and public page. - Docs: DATA_SOURCES, SECURITY, CURRENT-STATE, CCTV_INTEGRATION, README, .env.example, changelog fragment renamed to its full scope.
This commit is contained in:
1 parent
fa4ce4b2a5
commit
db8afbae81
43 files changed
+1327
-1110
No files matched your search
+115
-34
@@ -49,13 +49,29 @@ function setMedia(video, url) {
|
||||
video.load();
|
||||
}
|
||||
|
||||
/** Treat an interrupted play() (a pause or a new source) as no failure. */
|
||||
function onPlayFailure(mark) {
|
||||
return (error) => {
|
||||
if (error?.name !== 'AbortError') mark();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Québec 511 serves a new clip at the same URL every few minutes, so a refresh
|
||||
* adds a timestamp to get past the browser's media cache.
|
||||
*/
|
||||
function mediaRefreshUrl(value) {
|
||||
const url = new URL(value);
|
||||
url.searchParams.set('_', String(Date.now()));
|
||||
return url.href;
|
||||
}
|
||||
|
||||
/** Attach the active Québec source to a floating browser player and map preview. */
|
||||
/**
|
||||
* Attach the active Québec source to a floating browser player and map
|
||||
* preview. The browser contacts Québec 511 only after the viewer presses Play
|
||||
* for that camera; selecting it (by click, auto-hop, a scene or voice) only
|
||||
* shows its details and the play control.
|
||||
*/
|
||||
export function createQuebecCctvOverlay(viewer) {
|
||||
if (!viewer?.scene || typeof document === 'undefined') return null;
|
||||
|
||||
@@ -64,7 +80,7 @@ export function createQuebecCctvOverlay(viewer) {
|
||||
const panel = document.createElement('section');
|
||||
panel.className = 'qci-panel';
|
||||
panel.hidden = true;
|
||||
panel.setAttribute('role', 'dialog');
|
||||
panel.setAttribute('role', 'region');
|
||||
panel.setAttribute('aria-label', t('CCTV camera'));
|
||||
|
||||
const header = document.createElement('header');
|
||||
@@ -91,10 +107,14 @@ export function createQuebecCctvOverlay(viewer) {
|
||||
|
||||
const actions = document.createElement('div');
|
||||
actions.className = 'qci-actions';
|
||||
const play = document.createElement('button');
|
||||
play.type = 'button';
|
||||
play.className = 'qci-play';
|
||||
play.textContent = t('Play');
|
||||
const refresh = document.createElement('button');
|
||||
refresh.type = 'button';
|
||||
refresh.textContent = t('Refresh map still');
|
||||
actions.append(refresh);
|
||||
actions.append(play, refresh);
|
||||
const note = document.createElement('p');
|
||||
note.className = 'qci-note';
|
||||
const sourceLink = document.createElement('a');
|
||||
@@ -110,7 +130,7 @@ export function createQuebecCctvOverlay(viewer) {
|
||||
still.className = 'qci-marker-still';
|
||||
still.muted = true;
|
||||
still.playsInline = true;
|
||||
still.preload = 'auto';
|
||||
still.preload = 'none';
|
||||
still.setAttribute('aria-hidden', 'true');
|
||||
const markerLabel = document.createElement('span');
|
||||
markerLabel.className = 'qci-marker-label';
|
||||
@@ -121,7 +141,11 @@ export function createQuebecCctvOverlay(viewer) {
|
||||
let selectedPosition = null;
|
||||
let closedWindowCameraId = null;
|
||||
let selectedMediaUrl = '';
|
||||
/** Camera id the viewer pressed Play for; media loads only for this one. */
|
||||
let playingCameraId = null;
|
||||
let mediaRefreshTimer = 0;
|
||||
let removeRender = null;
|
||||
let canvasRect = null;
|
||||
let liveUnavailable = false;
|
||||
let stillUnavailable = false;
|
||||
|
||||
@@ -144,8 +168,18 @@ export function createQuebecCctvOverlay(viewer) {
|
||||
markerLabel.textContent = t('Source unavailable');
|
||||
}
|
||||
|
||||
function startRender() {
|
||||
if (!removeRender)
|
||||
removeRender = viewer.scene.postRender.addEventListener(updateMarker);
|
||||
}
|
||||
|
||||
function stopRender() {
|
||||
removeRender?.();
|
||||
removeRender = null;
|
||||
}
|
||||
|
||||
function stopMediaRefresh() {
|
||||
clearInterval(mediaRefreshTimer);
|
||||
window.clearInterval(mediaRefreshTimer);
|
||||
mediaRefreshTimer = 0;
|
||||
}
|
||||
|
||||
@@ -156,7 +190,7 @@ export function createQuebecCctvOverlay(viewer) {
|
||||
() => {
|
||||
if (document.hidden || closedWindowCameraId === selected?.id) return;
|
||||
setMedia(live, mediaRefreshUrl(selectedMediaUrl));
|
||||
void live.play().catch(markLiveUnavailable);
|
||||
void live.play().catch(onPlayFailure(markLiveUnavailable));
|
||||
refreshStill();
|
||||
},
|
||||
2 * 60 * 1000,
|
||||
@@ -164,10 +198,33 @@ export function createQuebecCctvOverlay(viewer) {
|
||||
}
|
||||
|
||||
function refreshStill() {
|
||||
if (!selectedMediaUrl) return;
|
||||
if (!selectedMediaUrl || playingCameraId !== selected?.id) return;
|
||||
setMedia(still, '');
|
||||
setMedia(still, mediaRefreshUrl(selectedMediaUrl));
|
||||
void still.play().catch(markStillUnavailable);
|
||||
void still.play().catch(onPlayFailure(markStillUnavailable));
|
||||
}
|
||||
|
||||
/** Load and play the selected camera's media: only from a Play click. */
|
||||
function startPlayback() {
|
||||
if (!selected || !selectedMediaUrl) return;
|
||||
playingCameraId = selected.id;
|
||||
liveUnavailable = false;
|
||||
stillUnavailable = false;
|
||||
play.hidden = true;
|
||||
refresh.hidden = false;
|
||||
live.hidden = false;
|
||||
still.hidden = false;
|
||||
marker.classList.remove('qci-marker-link-only');
|
||||
note.textContent = t(
|
||||
'The map still uses a separate request and may show a different moment.',
|
||||
);
|
||||
note.hidden = false;
|
||||
markerLabel.textContent = markerLabelText(selected, true);
|
||||
setMedia(live, selectedMediaUrl);
|
||||
setMedia(still, selectedMediaUrl);
|
||||
void live.play().catch(onPlayFailure(markLiveUnavailable));
|
||||
void still.play().catch(onPlayFailure(markStillUnavailable));
|
||||
startMediaRefresh();
|
||||
}
|
||||
|
||||
function setCamera(camera, { reselected = false } = {}) {
|
||||
@@ -176,9 +233,11 @@ export function createQuebecCctvOverlay(viewer) {
|
||||
selectedPosition = null;
|
||||
closedWindowCameraId = null;
|
||||
selectedMediaUrl = '';
|
||||
playingCameraId = null;
|
||||
liveUnavailable = false;
|
||||
stillUnavailable = false;
|
||||
stopMediaRefresh();
|
||||
stopRender();
|
||||
panel.hidden = true;
|
||||
marker.hidden = true;
|
||||
setMedia(live, '');
|
||||
@@ -189,6 +248,7 @@ export function createQuebecCctvOverlay(viewer) {
|
||||
const changed = selected?.id !== camera.id;
|
||||
if (changed || reselected) closedWindowCameraId = null;
|
||||
selected = camera;
|
||||
startRender();
|
||||
selectedPosition = Cesium.Cartesian3.fromDegrees(
|
||||
Number(camera.lon),
|
||||
Number(camera.lat),
|
||||
@@ -205,7 +265,9 @@ export function createQuebecCctvOverlay(viewer) {
|
||||
if (changed || mediaUrl !== selectedMediaUrl) {
|
||||
liveUnavailable = false;
|
||||
stillUnavailable = false;
|
||||
playingCameraId = null;
|
||||
}
|
||||
const playing = Boolean(mediaUrl) && playingCameraId === camera.id;
|
||||
title.textContent = camera.name || t('CCTV camera');
|
||||
coordinates.textContent = [
|
||||
`${Number(camera.lat).toFixed(5)}, ${Number(camera.lon).toFixed(5)}`,
|
||||
@@ -218,16 +280,19 @@ export function createQuebecCctvOverlay(viewer) {
|
||||
.join(' · ');
|
||||
credit.textContent = camera.credit || camera.provider || '';
|
||||
credit.hidden = !credit.textContent;
|
||||
live.hidden = !mediaUrl;
|
||||
refresh.hidden = !mediaUrl;
|
||||
live.hidden = !playing;
|
||||
play.hidden = !mediaUrl || playing;
|
||||
refresh.hidden = !playing;
|
||||
actions.hidden = !mediaUrl;
|
||||
note.hidden = !mediaUrl;
|
||||
note.textContent = mediaUrl
|
||||
? liveUnavailable
|
||||
? t('Source unavailable')
|
||||
: t(
|
||||
'The map still uses a separate request and may show a different moment.',
|
||||
)
|
||||
? !playing
|
||||
? t('Video plays from Québec 511, which sees your IP address.')
|
||||
: liveUnavailable
|
||||
? t('Source unavailable')
|
||||
: t(
|
||||
'The map still uses a separate request and may show a different moment.',
|
||||
)
|
||||
: sourceUrl
|
||||
? ''
|
||||
: t('Source unavailable');
|
||||
@@ -236,27 +301,24 @@ export function createQuebecCctvOverlay(viewer) {
|
||||
sourceLink.hidden = !sourceUrl;
|
||||
markerLabel.textContent = stillUnavailable
|
||||
? t('Source unavailable')
|
||||
: markerLabelText(camera, mediaUrl);
|
||||
marker.classList.toggle('qci-marker-link-only', !mediaUrl);
|
||||
still.hidden = !mediaUrl;
|
||||
: markerLabelText(camera, playing);
|
||||
marker.classList.toggle('qci-marker-link-only', !playing);
|
||||
still.hidden = !playing;
|
||||
panel.hidden = false;
|
||||
|
||||
if (changed || mediaUrl !== selectedMediaUrl) {
|
||||
selectedMediaUrl = mediaUrl;
|
||||
setMedia(live, mediaUrl);
|
||||
setMedia(still, mediaUrl);
|
||||
if (mediaUrl) {
|
||||
void live.play().catch(markLiveUnavailable);
|
||||
void still.play().catch(markStillUnavailable);
|
||||
startMediaRefresh();
|
||||
} else {
|
||||
stopMediaRefresh();
|
||||
}
|
||||
} else if (reselected && mediaUrl) {
|
||||
// A new camera never inherits playback: the browser stays off 511
|
||||
// until the viewer presses Play for it.
|
||||
stopMediaRefresh();
|
||||
setMedia(live, '');
|
||||
setMedia(still, '');
|
||||
} else if (reselected && playing) {
|
||||
if (live.error || live.networkState === 3 || live.readyState < 2) {
|
||||
setMedia(live, mediaRefreshUrl(mediaUrl));
|
||||
}
|
||||
if (live.paused) void live.play().catch(markLiveUnavailable);
|
||||
if (live.paused)
|
||||
void live.play().catch(onPlayFailure(markLiveUnavailable));
|
||||
startMediaRefresh();
|
||||
if (still.error || still.networkState === 3 || still.readyState < 2)
|
||||
refreshStill();
|
||||
@@ -280,7 +342,10 @@ export function createQuebecCctvOverlay(viewer) {
|
||||
point.y <= canvas.clientHeight;
|
||||
marker.hidden = !visible;
|
||||
if (!visible) return;
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
// Measured once per resize or scroll, not every frame, so the per-frame
|
||||
// style writes never force a layout.
|
||||
canvasRect ||= canvas.getBoundingClientRect();
|
||||
const rect = canvasRect;
|
||||
marker.style.left = `${rect.left + point.x}px`;
|
||||
marker.style.top = `${rect.top + point.y}px`;
|
||||
const distance = Cesium.Cartesian3.distance(
|
||||
@@ -320,6 +385,23 @@ export function createQuebecCctvOverlay(viewer) {
|
||||
{ signal },
|
||||
);
|
||||
refresh.addEventListener('click', refreshStill, { signal });
|
||||
play.addEventListener('click', startPlayback, { signal });
|
||||
const resetCanvasRect = () => {
|
||||
canvasRect = null;
|
||||
};
|
||||
window.addEventListener('resize', resetCanvasRect, { signal });
|
||||
window.addEventListener('scroll', resetCanvasRect, {
|
||||
signal,
|
||||
capture: true,
|
||||
passive: true,
|
||||
});
|
||||
panel.addEventListener(
|
||||
'keydown',
|
||||
(event) => {
|
||||
if (event.key === 'Escape') close.click();
|
||||
},
|
||||
{ signal },
|
||||
);
|
||||
close.addEventListener(
|
||||
'click',
|
||||
() => {
|
||||
@@ -359,25 +441,24 @@ export function createQuebecCctvOverlay(viewer) {
|
||||
document.addEventListener(
|
||||
'visibilitychange',
|
||||
() => {
|
||||
if (!selectedMediaUrl) return;
|
||||
if (!selectedMediaUrl || playingCameraId !== selected?.id) return;
|
||||
if (document.hidden) {
|
||||
live.pause();
|
||||
still.pause();
|
||||
} else if (closedWindowCameraId !== selected?.id) {
|
||||
void live.play().catch(markLiveUnavailable);
|
||||
void live.play().catch(onPlayFailure(markLiveUnavailable));
|
||||
refreshStill();
|
||||
}
|
||||
},
|
||||
{ signal },
|
||||
);
|
||||
|
||||
const removeRender = viewer.scene.postRender.addEventListener(updateMarker);
|
||||
return {
|
||||
setCamera,
|
||||
dispose() {
|
||||
controller.abort();
|
||||
stopMediaRefresh();
|
||||
removeRender();
|
||||
stopRender();
|
||||
setMedia(live, '');
|
||||
setMedia(still, '');
|
||||
panel.remove();
|
||||
|
||||
@@ -4,18 +4,48 @@ import { Window } from 'happy-dom';
|
||||
import * as Cesium from 'cesium';
|
||||
import { createQuebecCctvOverlay } from './quebecCctvOverlay.js';
|
||||
|
||||
test('routine same-camera updates keep Québec feed errors visible until recovery', async () => {
|
||||
const MEDIA_URL =
|
||||
'https://www.quebec511.info/Carte/Fenetres/camera.ashx?id=3735&format=mp4';
|
||||
|
||||
const CAMERA = Object.freeze({
|
||||
id: 'qc-511-3735',
|
||||
sourceKind: 'quebec-511-browser',
|
||||
name: 'Route 136 at rue Panet',
|
||||
lat: 45.51651,
|
||||
lon: -73.5502,
|
||||
positionSource: 'MTQ georeferenced point',
|
||||
browserMediaUrl: MEDIA_URL,
|
||||
sourceUrl:
|
||||
'https://www.quebec511.info/Carte/Fenetres/FenetreVideo.html?id=3735',
|
||||
});
|
||||
|
||||
/**
|
||||
* Mount the overlay in a happy-dom window with recorded media loads, timers
|
||||
* and postRender listeners. `play` decides what each play() returns.
|
||||
*/
|
||||
function mountOverlay(t, { play = () => Promise.resolve() } = {}) {
|
||||
const window = new Window({ url: 'http://localhost:4173/' });
|
||||
const previousWindow = globalThis.window;
|
||||
const previousDocument = globalThis.document;
|
||||
globalThis.window = window;
|
||||
globalThis.document = window.document;
|
||||
window.HTMLMediaElement.prototype.load = function () {};
|
||||
const loads = [];
|
||||
window.HTMLMediaElement.prototype.load = function () {
|
||||
if (this.getAttribute('src')) loads.push(this.getAttribute('src'));
|
||||
};
|
||||
window.HTMLMediaElement.prototype.play = function () {
|
||||
return Promise.resolve();
|
||||
return play(this);
|
||||
};
|
||||
window.HTMLMediaElement.prototype.pause = function () {};
|
||||
window.setInterval = () => 0;
|
||||
const intervals = new Map();
|
||||
let nextTimer = 1;
|
||||
window.setInterval = (fn) => {
|
||||
const id = nextTimer++;
|
||||
intervals.set(id, fn);
|
||||
return id;
|
||||
};
|
||||
window.clearInterval = (id) => intervals.delete(id);
|
||||
const renderListeners = new Set();
|
||||
const viewer = {
|
||||
camera: {
|
||||
positionWC: Cesium.Cartesian3.fromDegrees(-73.5502, 45.51651, 1000),
|
||||
@@ -23,49 +53,140 @@ test('routine same-camera updates keep Québec feed errors visible until recover
|
||||
scene: {
|
||||
canvas: { clientWidth: 800, clientHeight: 600 },
|
||||
cartesianToCanvasCoordinates: () => null,
|
||||
postRender: { addEventListener: () => () => {} },
|
||||
postRender: {
|
||||
addEventListener(fn) {
|
||||
renderListeners.add(fn);
|
||||
return () => renderListeners.delete(fn);
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
let overlay;
|
||||
|
||||
try {
|
||||
overlay = createQuebecCctvOverlay(viewer);
|
||||
const camera = {
|
||||
id: 'qc-511-3735',
|
||||
sourceKind: 'quebec-511-browser',
|
||||
name: 'Route 136 at rue Panet',
|
||||
lat: 45.51651,
|
||||
lon: -73.5502,
|
||||
positionSource: 'MTQ georeferenced point',
|
||||
browserMediaUrl:
|
||||
'https://www.quebec511.info/Carte/Fenetres/camera.ashx?id=3735&format=mp4',
|
||||
sourceUrl:
|
||||
'https://www.quebec511.info/Carte/Fenetres/FenetreVideo.html?id=3735',
|
||||
};
|
||||
overlay.setCamera(camera);
|
||||
const [live, still] = window.document.querySelectorAll('video');
|
||||
live.dispatchEvent(new window.Event('error'));
|
||||
still.dispatchEvent(new window.Event('error'));
|
||||
|
||||
overlay.setCamera({ ...camera });
|
||||
|
||||
assert.equal(window.document.querySelector('.qci-note').textContent, 'Source unavailable');
|
||||
assert.equal(window.document.querySelector('.qci-marker-label').textContent, 'Source unavailable');
|
||||
|
||||
live.dispatchEvent(new window.Event('loadeddata'));
|
||||
still.dispatchEvent(new window.Event('loadeddata'));
|
||||
assert.match(
|
||||
window.document.querySelector('.qci-note').textContent,
|
||||
/separate request/,
|
||||
);
|
||||
assert.match(
|
||||
window.document.querySelector('.qci-marker-label').textContent,
|
||||
/^PREVIEW ·/,
|
||||
);
|
||||
} finally {
|
||||
const overlay = createQuebecCctvOverlay(viewer);
|
||||
t.after(() => {
|
||||
overlay?.dispose();
|
||||
globalThis.window = previousWindow;
|
||||
globalThis.document = previousDocument;
|
||||
window.close();
|
||||
}
|
||||
});
|
||||
const [live, still] = window.document.querySelectorAll('video');
|
||||
return {
|
||||
window,
|
||||
overlay,
|
||||
loads,
|
||||
intervals,
|
||||
renderListeners,
|
||||
live,
|
||||
still,
|
||||
note: () => window.document.querySelector('.qci-note').textContent,
|
||||
label: () => window.document.querySelector('.qci-marker-label').textContent,
|
||||
playButton: () => window.document.querySelector('.qci-play'),
|
||||
};
|
||||
}
|
||||
|
||||
test('selecting a Québec camera contacts Québec 511 only after Play', (t) => {
|
||||
const ui = mountOverlay(t);
|
||||
assert.equal(ui.renderListeners.size, 0, 'no per-frame work before a camera');
|
||||
|
||||
ui.overlay.setCamera(CAMERA);
|
||||
assert.deepEqual(ui.loads, [], 'selection alone loads no 511 media');
|
||||
assert.equal(ui.intervals.size, 0, 'and starts no refresh timer');
|
||||
assert.equal(ui.playButton().hidden, false);
|
||||
assert.match(ui.note(), /sees your IP address/);
|
||||
assert.equal(ui.renderListeners.size, 1);
|
||||
|
||||
ui.playButton().click();
|
||||
assert.deepEqual(ui.loads, [MEDIA_URL, MEDIA_URL], 'live player and map still');
|
||||
assert.equal(ui.playButton().hidden, true);
|
||||
assert.equal(ui.intervals.size, 1);
|
||||
|
||||
// A different camera never inherits playback.
|
||||
ui.loads.length = 0;
|
||||
ui.overlay.setCamera({
|
||||
...CAMERA,
|
||||
id: 'qc-511-4103',
|
||||
browserMediaUrl: MEDIA_URL.replace('3735', '4103'),
|
||||
});
|
||||
assert.deepEqual(ui.loads, []);
|
||||
assert.equal(ui.intervals.size, 0);
|
||||
assert.equal(ui.playButton().hidden, false);
|
||||
|
||||
ui.overlay.setCamera(null);
|
||||
assert.equal(ui.renderListeners.size, 0, 'deselect drops the per-frame listener');
|
||||
});
|
||||
|
||||
test('a camera without browser media shows only its provider link', (t) => {
|
||||
const ui = mountOverlay(t);
|
||||
ui.overlay.setCamera({ ...CAMERA, browserMediaUrl: '' });
|
||||
assert.equal(ui.playButton().hidden, true);
|
||||
assert.deepEqual(ui.loads, []);
|
||||
const link = ui.window.document.querySelector('.qci-panel a');
|
||||
assert.equal(link.hidden, false);
|
||||
assert.equal(link.href, CAMERA.sourceUrl);
|
||||
});
|
||||
|
||||
test('routine same-camera updates keep Québec feed errors visible until recovery', (t) => {
|
||||
const ui = mountOverlay(t);
|
||||
ui.overlay.setCamera(CAMERA);
|
||||
ui.playButton().click();
|
||||
ui.live.dispatchEvent(new ui.window.Event('error'));
|
||||
ui.still.dispatchEvent(new ui.window.Event('error'));
|
||||
|
||||
ui.overlay.setCamera({ ...CAMERA });
|
||||
|
||||
assert.equal(ui.note(), 'Source unavailable');
|
||||
assert.equal(ui.label(), 'Source unavailable');
|
||||
|
||||
ui.live.dispatchEvent(new ui.window.Event('loadeddata'));
|
||||
ui.still.dispatchEvent(new ui.window.Event('loadeddata'));
|
||||
assert.match(ui.note(), /separate request/);
|
||||
assert.match(ui.label(), /^PREVIEW ·/);
|
||||
});
|
||||
|
||||
test('an interrupted play() is not reported as an unavailable source', async (t) => {
|
||||
const abort = () =>
|
||||
Promise.reject(new DOMException('interrupted by pause()', 'AbortError'));
|
||||
const ui = mountOverlay(t, { play: abort });
|
||||
ui.overlay.setCamera(CAMERA);
|
||||
ui.playButton().click();
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
assert.match(ui.note(), /separate request/);
|
||||
assert.match(ui.label(), /^PREVIEW ·/);
|
||||
});
|
||||
|
||||
test('a real play() failure is reported', async (t) => {
|
||||
const fail = () =>
|
||||
Promise.reject(new DOMException('no supported source', 'NotSupportedError'));
|
||||
const ui = mountOverlay(t, { play: fail });
|
||||
ui.overlay.setCamera(CAMERA);
|
||||
ui.playButton().click();
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
assert.equal(ui.note(), 'Source unavailable');
|
||||
});
|
||||
|
||||
test('the refresh timer reloads with a cache-buster, skips hidden tabs, and stops on dispose', (t) => {
|
||||
const ui = mountOverlay(t);
|
||||
ui.overlay.setCamera(CAMERA);
|
||||
ui.playButton().click();
|
||||
const [refresh] = ui.intervals.values();
|
||||
|
||||
ui.loads.length = 0;
|
||||
Object.defineProperty(ui.window.document, 'hidden', {
|
||||
configurable: true,
|
||||
get: () => true,
|
||||
});
|
||||
refresh();
|
||||
assert.deepEqual(ui.loads, [], 'a hidden tab does not refresh');
|
||||
|
||||
Object.defineProperty(ui.window.document, 'hidden', {
|
||||
configurable: true,
|
||||
get: () => false,
|
||||
});
|
||||
refresh();
|
||||
assert.equal(ui.loads.length, 2);
|
||||
for (const src of ui.loads) assert.match(src, /[?&]_=\d+$/);
|
||||
|
||||
ui.overlay.dispose();
|
||||
assert.equal(ui.intervals.size, 0);
|
||||
assert.equal(ui.renderListeners.size, 0);
|
||||
assert.equal(ui.window.document.querySelector('.qci-panel'), null);
|
||||
});
|
||||
Reference in new issue
Block a user