- Refactor duplicated video event listener boilerplate in wireVideoEvents() into onVideoEvent() helper (viewer.js: -57 lines) - Fix 3 ESLint no-unused-vars warnings (bare catch instead of unused _e) - Fix 1 additional no-unused-vars: unused 'data' param in MANIFEST_LOADED - Remove dead 'Hls.cast' entry from playerRank map (no strategy produces it) - Remove deprecated .eslintignore file (ESLint v9 uses flat config only) - Add __tests__/ to ESLint ignores in flat config Net: -20 lines (46 ins, 66 del). 83/83 tests pass, lint clean (0 warnings)
This commit is contained in:
1 parent
e11be9a20a
commit
ae8608148d
6 files changed
+21
-42
No files matched your search
+17
-36
@@ -320,7 +320,7 @@ function wireHlsEvents(hls, video, panel) {
|
||||
const HlsEvents = window.Hls.Events;
|
||||
|
||||
// --- Manifest lifecycle ---
|
||||
hls.on(HlsEvents.MANIFEST_LOADED, (_ev, data) => {
|
||||
hls.on(HlsEvents.MANIFEST_LOADED, () => {
|
||||
state.phase = 'loading';
|
||||
state.lastEvent = 'MANIFEST_LOADED';
|
||||
state.lastActivity = Date.now();
|
||||
@@ -524,35 +524,22 @@ function wireHlsEvents(hls, video, panel) {
|
||||
* These complement hls.js events by providing browser-level playback state.
|
||||
*/
|
||||
function wireVideoEvents(video) {
|
||||
video.addEventListener('playing', () => {
|
||||
const s = panelStates.get(video);
|
||||
if (s) {
|
||||
s.phase = 'playing';
|
||||
s.lastEvent = 'video.playing';
|
||||
// Helper: bind a video event that updates state and re-renders.
|
||||
// Skips the handler if the panel state has already been cleaned up.
|
||||
function onVideoEvent(eventName, updater) {
|
||||
video.addEventListener(eventName, () => {
|
||||
const s = panelStates.get(video);
|
||||
if (!s) return;
|
||||
updater(s);
|
||||
s.lastActivity = Date.now();
|
||||
renderPanelState(video, s._panel);
|
||||
}
|
||||
});
|
||||
if (s._panel) renderPanelState(video, s._panel);
|
||||
});
|
||||
}
|
||||
|
||||
video.addEventListener('waiting', () => {
|
||||
const s = panelStates.get(video);
|
||||
if (s) {
|
||||
s.phase = 'buffering';
|
||||
s.lastEvent = 'video.waiting';
|
||||
s.lastActivity = Date.now();
|
||||
renderPanelState(video, s._panel);
|
||||
}
|
||||
});
|
||||
|
||||
video.addEventListener('stalled', () => {
|
||||
const s = panelStates.get(video);
|
||||
if (s) {
|
||||
s.phase = 'buffering';
|
||||
s.lastEvent = 'video.stalled';
|
||||
s.lastActivity = Date.now();
|
||||
renderPanelState(video, s._panel);
|
||||
}
|
||||
});
|
||||
// Track playback phase transitions.
|
||||
onVideoEvent('playing', s => { s.phase = 'playing'; s.lastEvent = 'video.playing'; });
|
||||
onVideoEvent('waiting', s => { s.phase = 'buffering'; s.lastEvent = 'video.waiting'; });
|
||||
onVideoEvent('stalled', s => { s.phase = 'buffering'; s.lastEvent = 'video.stalled'; });
|
||||
|
||||
// Track actual playback position (fragments are delivered out of order but
|
||||
// the browser's timeupdate fires as they are played back sequentially).
|
||||
@@ -563,6 +550,7 @@ function wireVideoEvents(video) {
|
||||
s.duration = video.duration || 0;
|
||||
});
|
||||
|
||||
// Seek events — update activity marker, re-render.
|
||||
video.addEventListener('seeking', () => {
|
||||
const s = panelStates.get(video);
|
||||
if (s) {
|
||||
@@ -571,14 +559,7 @@ function wireVideoEvents(video) {
|
||||
}
|
||||
});
|
||||
|
||||
video.addEventListener('seeked', () => {
|
||||
const s = panelStates.get(video);
|
||||
if (s) {
|
||||
s.lastEvent = 'video.seeked';
|
||||
s.lastActivity = Date.now();
|
||||
renderPanelState(video, s._panel);
|
||||
}
|
||||
});
|
||||
onVideoEvent('seeked', s => { s.lastEvent = 'video.seeked'; });
|
||||
}
|
||||
|
||||
/* ======================================================================== */
|
||||
|
||||
Reference in new issue
Block a user