bim
timfa Tim Falken · pushed by timfa
Authored 2026-05-25 · 5 months ago
- Hash
b942d6359e295871e9634a482629c7fc4dceb4dd- Parent
0f3aa256
3 files changed
+193
−13
@@ -182,7 +182,7 @@
182
182
## public/shared-video-player.js
183
183
- applyDefaultTextTrackPrefs() - Writes the default Video.js caption override settings (transparent background, uniform edge style) so all streamed players start from the same text-track baseline.
184
184
- bindTrackPrefs(player, prefs, savePrefs) - Restores subtitle/audio track selections by track name and persists later track changes; shared by the authenticated player and the share page so both resolve track matches the same way.
185
- bindImageSubtitleOverlay(player, videojs, prefs, session, opts) - Adds the shared IM button/menu/overlay for bitmap subtitle tracks, restores saved image-subtitle selections, fetches rendered frames through a caller-supplied request builder, keeps a separate rolling lookahead-prefetch worker alive across timeupdates (including gaps where no subtitle is currently visible), extends prefetch target to at least the latest buffered video end (not only fixed lookahead seconds), coalesces overlapping current-frame refreshes into a single in-flight fetch (only force-refresh paths abort/restart), applies per-request timeouts (`currentRequestTimeoutMs`, `prefetchRequestTimeoutMs`) so hung subtitle frame requests cannot stall updates indefinitely, paces prefetch polling (`prefetchRequestIntervalMs`) to reduce request bursts, logs current and prefetch subtitle request/send/receive/not-available timing to the browser console and optional batch sink, renders seek-bar bracket markers for last requested point (`]`) and last received/ready point (`[`), advances markers even when responses are 204/no-frame, and disables the track after the first hard failure.
185
- bindImageSubtitleOverlay(player, videojs, prefs, session, opts) - Adds the shared IM button/menu/overlay for bitmap subtitle tracks, restores saved image-subtitle selections, fetches rendered frames through a caller-supplied request builder, keeps a separate rolling lookahead-prefetch worker alive across timeupdates (including gaps where no subtitle is currently visible), extends prefetch target to at least the latest buffered video end (not only fixed lookahead seconds), coalesces overlapping current-frame refreshes into a single in-flight fetch (only force-refresh paths abort/restart), applies per-request timeouts (`currentRequestTimeoutMs`, `prefetchRequestTimeoutMs`) so hung subtitle frame requests cannot stall updates indefinitely, paces prefetch polling (`prefetchRequestIntervalMs`) to reduce request bursts, logs current and prefetch subtitle request/send/receive/not-available timing to the browser console and optional batch sink, updates seek-bar bracket markers only after responses resolve (no in-flight jump-back flicker), shows a merged `[]` marker when requested and received positions match, advances markers even when responses are 204/no-frame, and disables the track after the first hard failure.
186
186
- configureVideoJsBuffering(videojs, opts) - Applies the long forward-buffer settings used for file playback when VHS exposes those knobs.
187
187
- ensureVideoPlaybackUi(player, durationSeconds) - Forces file streams into VOD UI mode, normalises the reported duration, stops live-tracker state, and hides the live badge when present.
188
188
@@ -182,7 +182,7 @@182
## public/shared-video-player.js
182
## public/shared-video-player.js
183
- applyDefaultTextTrackPrefs() - Writes the default Video.js caption override settings (transparent background, uniform edge style) so all streamed players start from the same text-track baseline.
183
- applyDefaultTextTrackPrefs() - Writes the default Video.js caption override settings (transparent background, uniform edge style) so all streamed players start from the same text-track baseline.
184
- bindTrackPrefs(player, prefs, savePrefs) - Restores subtitle/audio track selections by track name and persists later track changes; shared by the authenticated player and the share page so both resolve track matches the same way.
184
- bindTrackPrefs(player, prefs, savePrefs) - Restores subtitle/audio track selections by track name and persists later track changes; shared by the authenticated player and the share page so both resolve track matches the same way.
185
- bindImageSubtitleOverlay(player, videojs, prefs, session, opts) - Adds the shared IM button/menu/overlay for bitmap subtitle tracks, restores saved image-subtitle selections, fetches rendered frames through a caller-supplied request builder, keeps a separate rolling lookahead-prefetch worker alive across timeupdates (including gaps where no subtitle is currently visible), extends prefetch target to at least the latest buffered video end (not only fixed lookahead seconds), coalesces overlapping current-frame refreshes into a single in-flight fetch (only force-refresh paths abort/restart), applies per-request timeouts (`currentRequestTimeoutMs`, `prefetchRequestTimeoutMs`) so hung subtitle frame requests cannot stall updates indefinitely, paces prefetch polling (`prefetchRequestIntervalMs`) to reduce request bursts, logs current and prefetch subtitle request/send/receive/not-available timing to the browser console and optional batch sink, renders seek-bar bracket markers for last requested point (`]`) and last received/ready point (`[`), advances markers even when responses are 204/no-frame, and disables the track after the first hard failure.
185
- bindImageSubtitleOverlay(player, videojs, prefs, session, opts) - Adds the shared IM button/menu/overlay for bitmap subtitle tracks, restores saved image-subtitle selections, fetches rendered frames through a caller-supplied request builder, keeps a separate rolling lookahead-prefetch worker alive across timeupdates (including gaps where no subtitle is currently visible), extends prefetch target to at least the latest buffered video end (not only fixed lookahead seconds), coalesces overlapping current-frame refreshes into a single in-flight fetch (only force-refresh paths abort/restart), applies per-request timeouts (`currentRequestTimeoutMs`, `prefetchRequestTimeoutMs`) so hung subtitle frame requests cannot stall updates indefinitely, paces prefetch polling (`prefetchRequestIntervalMs`) to reduce request bursts, logs current and prefetch subtitle request/send/receive/not-available timing to the browser console and optional batch sink, updates seek-bar bracket markers only after responses resolve (no in-flight jump-back flicker), shows a merged `[]` marker when requested and received positions match, advances markers even when responses are 204/no-frame, and disables the track after the first hard failure.
186
- configureVideoJsBuffering(videojs, opts) - Applies the long forward-buffer settings used for file playback when VHS exposes those knobs.
186
- configureVideoJsBuffering(videojs, opts) - Applies the long forward-buffer settings used for file playback when VHS exposes those knobs.
187
- ensureVideoPlaybackUi(player, durationSeconds) - Forces file streams into VOD UI mode, normalises the reported duration, stops live-tracker state, and hides the live badge when present.
187
- ensureVideoPlaybackUi(player, durationSeconds) - Forces file streams into VOD UI mode, normalises the reported duration, stops live-tracker state, and hides the live badge when present.
188
188
@@ -304,6 +304,7 @@
304
304
let seekMarkerContainerEl = null;
305
305
let seekMarkerRequestedEl = null;
306
306
let seekMarkerReceivedEl = null;
307
let seekMarkerCombinedEl = null;
307
308
let lastRequestedCaptionStartTimeSeconds = null;
308
309
let lastReceivedCaptionStartTimeSeconds = null;
309
310
let subtitleLogSequence = 0;
@@ -468,31 +469,56 @@
468
469
469
470
const updateSeekBarMarkers = () =>
470
471
{
471
if (!seekMarkerRequestedEl || !seekMarkerReceivedEl) return;
472
if (!seekMarkerRequestedEl || !seekMarkerReceivedEl || !seekMarkerCombinedEl) return;
472
473
473
474
const duration = Number(player.duration && player.duration());
474
475
if (!Number.isFinite(duration) || duration <= 0)
475
476
{
476
477
seekMarkerRequestedEl.style.display = 'none';
477
478
seekMarkerReceivedEl.style.display = 'none';
479
seekMarkerCombinedEl.style.display = 'none';
478
480
return;
479
481
}
480
482
481
const applyMarker = (markerEl, markerTimeSeconds) =>
483
const getMarkerRatio = (markerTimeSeconds) =>
482
484
{
483
485
if (!Number.isFinite(markerTimeSeconds) || markerTimeSeconds < 0)
486
{
487
return null;
488
}
489
490
return Math.max(0, Math.min(1, markerTimeSeconds / duration));
491
};
492
493
const applyMarker = (markerEl, ratio) =>
494
{
495
if (!Number.isFinite(ratio))
484
496
{
485
497
markerEl.style.display = 'none';
486
498
return;
487
499
}
488
500
489
const ratio = Math.max(0, Math.min(1, markerTimeSeconds / duration));
490
501
markerEl.style.display = 'block';
491
502
markerEl.style.left = `${(ratio * 100).toFixed(4)}%`;
492
503
};
493
504
494
applyMarker(seekMarkerRequestedEl, lastRequestedCaptionStartTimeSeconds);
495
applyMarker(seekMarkerReceivedEl, lastReceivedCaptionStartTimeSeconds);
505
const requestedRatio = getMarkerRatio(lastRequestedCaptionStartTimeSeconds);
506
const receivedRatio = getMarkerRatio(lastReceivedCaptionStartTimeSeconds);
507
const shouldCombine = Number.isFinite(requestedRatio)
508
&& Number.isFinite(receivedRatio)
509
&& Math.abs(requestedRatio - receivedRatio) <= 1e-6;
510
511
if (shouldCombine)
512
{
513
applyMarker(seekMarkerCombinedEl, requestedRatio);
514
seekMarkerRequestedEl.style.display = 'none';
515
seekMarkerReceivedEl.style.display = 'none';
516
return;
517
}
518
519
seekMarkerCombinedEl.style.display = 'none';
520
applyMarker(seekMarkerRequestedEl, requestedRatio);
521
applyMarker(seekMarkerReceivedEl, receivedRatio);
496
522
};
497
523
498
524
const ensureSeekBarMarkers = () =>
@@ -540,17 +566,39 @@
540
566
markerEl.style.fontWeight = '700';
541
567
markerEl.style.lineHeight = '10px';
542
568
markerEl.style.textAlign = 'center';
543
markerEl.style.textShadow = '-1px 0 #000, 0 1px #000, 1px 0 #000, 0 -1px #000';
544
569
markerEl.style.display = 'none';
545
570
markerEl.textContent = direction === 'left' ? '[' : ']';
546
571
markerEl.setAttribute('aria-hidden', 'true');
547
572
return markerEl;
548
573
};
549
574
575
const buildCombinedMarker = () =>
576
{
577
const markerEl = document.createElement('span');
578
markerEl.className = 'vjs-image-subtitle-seek-marker vjs-image-subtitle-seek-marker-combined';
579
markerEl.style.position = 'absolute';
580
markerEl.style.top = '50%';
581
markerEl.style.width = '16px';
582
markerEl.style.height = '10px';
583
markerEl.style.transform = 'translate(-50%, -50%)';
584
markerEl.style.color = '#fff';
585
markerEl.style.fontFamily = 'monospace';
586
markerEl.style.fontSize = '12px';
587
markerEl.style.fontWeight = '700';
588
markerEl.style.lineHeight = '10px';
589
markerEl.style.textAlign = 'center';
590
markerEl.style.display = 'none';
591
markerEl.textContent = '[]';
592
markerEl.setAttribute('aria-hidden', 'true');
593
return markerEl;
594
};
595
550
596
seekMarkerReceivedEl = buildBracketMarker('left');
551
597
seekMarkerRequestedEl = buildBracketMarker('right');
598
seekMarkerCombinedEl = buildCombinedMarker();
552
599
seekMarkerContainerEl.appendChild(seekMarkerReceivedEl);
553
600
seekMarkerContainerEl.appendChild(seekMarkerRequestedEl);
601
seekMarkerContainerEl.appendChild(seekMarkerCombinedEl);
554
602
555
603
seekBarEl.appendChild(seekMarkerContainerEl);
556
604
updateSeekBarMarkers();
@@ -733,8 +781,6 @@
733
781
requestedAtMs: prefetchRequestStartedAtMs,
734
782
requestedVideoTimeSeconds: roundLogNumber(nextTime),
735
783
});
736
setSeekMarkerTime('requested', nextTime);
737
updateSeekBarMarkers();
738
784
739
785
let prefetchTimedOut = false;
740
786
const timeoutId = armRequestTimeout(controller, prefetchRequestTimeoutMs, () =>
@@ -771,6 +817,7 @@
771
817
sentToHeadersReceivedMs: diffMilliseconds(responseMeta.responseHeadersReceivedAtMs, responseMeta.serverResponseSentAtMs),
772
818
});
773
819
820
setSeekMarkerTime('requested', nextTime);
774
821
const receivedMarkerTime = Number.isFinite(responseMeta.shouldShowAtVideoTimeSeconds)
775
822
? responseMeta.shouldShowAtVideoTimeSeconds
776
823
: nextTime;
@@ -898,8 +945,6 @@
898
945
requestedAtMs: requestStartedAtMs,
899
946
requestedVideoTimeSeconds: roundLogNumber(currentTime),
900
947
});
901
setSeekMarkerTime('requested', currentTime);
902
updateSeekBarMarkers();
903
948
904
949
currentFramePromise = (async () =>
905
950
{
@@ -937,6 +982,7 @@
937
982
sentToHeadersReceivedMs: diffMilliseconds(responseMeta.responseHeadersReceivedAtMs, responseMeta.serverResponseSentAtMs),
938
983
});
939
984
985
setSeekMarkerTime('requested', currentTime);
940
986
const receivedMarkerTime = Number.isFinite(responseMeta.shouldShowAtVideoTimeSeconds)
941
987
? responseMeta.shouldShowAtVideoTimeSeconds
942
988
: currentTime;
@@ -1074,6 +1120,7 @@
1074
1120
seekMarkerContainerEl = null;
1075
1121
seekMarkerRequestedEl = null;
1076
1122
seekMarkerReceivedEl = null;
1123
seekMarkerCombinedEl = null;
1077
1124
if (overlayEl) overlayEl.remove();
1078
1125
if (menuEl) menuEl.remove();
1079
1126
player.imageSubtitleOverlayController = null;
@@ -304,6 +304,7 @@304
let seekMarkerContainerEl = null;304
let seekMarkerContainerEl = null;305
let seekMarkerRequestedEl = null;305
let seekMarkerRequestedEl = null;306
let seekMarkerReceivedEl = null;306
let seekMarkerReceivedEl = null;307
let seekMarkerCombinedEl = null;307
let lastRequestedCaptionStartTimeSeconds = null;308
let lastRequestedCaptionStartTimeSeconds = null;308
let lastReceivedCaptionStartTimeSeconds = null;309
let lastReceivedCaptionStartTimeSeconds = null;309
let subtitleLogSequence = 0;310
let subtitleLogSequence = 0;@@ -468,31 +469,56 @@468
469
469
const updateSeekBarMarkers = () =>470
const updateSeekBarMarkers = () =>470
{471
{471
if (!seekMarkerRequestedEl || !seekMarkerReceivedEl) return;472
if (!seekMarkerRequestedEl || !seekMarkerReceivedEl || !seekMarkerCombinedEl) return;472
473
473
const duration = Number(player.duration && player.duration());474
const duration = Number(player.duration && player.duration());474
if (!Number.isFinite(duration) || duration <= 0)475
if (!Number.isFinite(duration) || duration <= 0)475
{476
{476
seekMarkerRequestedEl.style.display = 'none';477
seekMarkerRequestedEl.style.display = 'none';477
seekMarkerReceivedEl.style.display = 'none';478
seekMarkerReceivedEl.style.display = 'none';479
seekMarkerCombinedEl.style.display = 'none';478
return;480
return;479
}481
}480
482
481
const applyMarker = (markerEl, markerTimeSeconds) =>483
const getMarkerRatio = (markerTimeSeconds) =>482
{484
{483
if (!Number.isFinite(markerTimeSeconds) || markerTimeSeconds < 0)485
if (!Number.isFinite(markerTimeSeconds) || markerTimeSeconds < 0)486
{487
return null;488
}489
490
return Math.max(0, Math.min(1, markerTimeSeconds / duration));491
};492
493
const applyMarker = (markerEl, ratio) =>494
{495
if (!Number.isFinite(ratio))484
{496
{485
markerEl.style.display = 'none';497
markerEl.style.display = 'none';486
return;498
return;487
}499
}488
500
489
const ratio = Math.max(0, Math.min(1, markerTimeSeconds / duration));490
markerEl.style.display = 'block';501
markerEl.style.display = 'block';491
markerEl.style.left = `${(ratio * 100).toFixed(4)}%`;502
markerEl.style.left = `${(ratio * 100).toFixed(4)}%`;492
};503
};493
504
494
applyMarker(seekMarkerRequestedEl, lastRequestedCaptionStartTimeSeconds);505
const requestedRatio = getMarkerRatio(lastRequestedCaptionStartTimeSeconds);495
applyMarker(seekMarkerReceivedEl, lastReceivedCaptionStartTimeSeconds);506
const receivedRatio = getMarkerRatio(lastReceivedCaptionStartTimeSeconds);507
const shouldCombine = Number.isFinite(requestedRatio)508
&& Number.isFinite(receivedRatio)509
&& Math.abs(requestedRatio - receivedRatio) <= 1e-6;510
511
if (shouldCombine)512
{513
applyMarker(seekMarkerCombinedEl, requestedRatio);514
seekMarkerRequestedEl.style.display = 'none';515
seekMarkerReceivedEl.style.display = 'none';516
return;517
}518
519
seekMarkerCombinedEl.style.display = 'none';520
applyMarker(seekMarkerRequestedEl, requestedRatio);521
applyMarker(seekMarkerReceivedEl, receivedRatio);496
};522
};497
523
498
const ensureSeekBarMarkers = () =>524
const ensureSeekBarMarkers = () =>@@ -540,17 +566,39 @@540
markerEl.style.fontWeight = '700';566
markerEl.style.fontWeight = '700';541
markerEl.style.lineHeight = '10px';567
markerEl.style.lineHeight = '10px';542
markerEl.style.textAlign = 'center';568
markerEl.style.textAlign = 'center';543
markerEl.style.textShadow = '-1px 0 #000, 0 1px #000, 1px 0 #000, 0 -1px #000';544
markerEl.style.display = 'none';569
markerEl.style.display = 'none';545
markerEl.textContent = direction === 'left' ? '[' : ']';570
markerEl.textContent = direction === 'left' ? '[' : ']';546
markerEl.setAttribute('aria-hidden', 'true');571
markerEl.setAttribute('aria-hidden', 'true');547
return markerEl;572
return markerEl;548
};573
};549
574
575
const buildCombinedMarker = () =>576
{577
const markerEl = document.createElement('span');578
markerEl.className = 'vjs-image-subtitle-seek-marker vjs-image-subtitle-seek-marker-combined';579
markerEl.style.position = 'absolute';580
markerEl.style.top = '50%';581
markerEl.style.width = '16px';582
markerEl.style.height = '10px';583
markerEl.style.transform = 'translate(-50%, -50%)';584
markerEl.style.color = '#fff';585
markerEl.style.fontFamily = 'monospace';586
markerEl.style.fontSize = '12px';587
markerEl.style.fontWeight = '700';588
markerEl.style.lineHeight = '10px';589
markerEl.style.textAlign = 'center';590
markerEl.style.display = 'none';591
markerEl.textContent = '[]';592
markerEl.setAttribute('aria-hidden', 'true');593
return markerEl;594
};595
550
seekMarkerReceivedEl = buildBracketMarker('left');596
seekMarkerReceivedEl = buildBracketMarker('left');551
seekMarkerRequestedEl = buildBracketMarker('right');597
seekMarkerRequestedEl = buildBracketMarker('right');598
seekMarkerCombinedEl = buildCombinedMarker();552
seekMarkerContainerEl.appendChild(seekMarkerReceivedEl);599
seekMarkerContainerEl.appendChild(seekMarkerReceivedEl);553
seekMarkerContainerEl.appendChild(seekMarkerRequestedEl);600
seekMarkerContainerEl.appendChild(seekMarkerRequestedEl);601
seekMarkerContainerEl.appendChild(seekMarkerCombinedEl);554
602
555
seekBarEl.appendChild(seekMarkerContainerEl);603
seekBarEl.appendChild(seekMarkerContainerEl);556
updateSeekBarMarkers();604
updateSeekBarMarkers();@@ -733,8 +781,6 @@733
requestedAtMs: prefetchRequestStartedAtMs,781
requestedAtMs: prefetchRequestStartedAtMs,734
requestedVideoTimeSeconds: roundLogNumber(nextTime),782
requestedVideoTimeSeconds: roundLogNumber(nextTime),735
});783
});736
setSeekMarkerTime('requested', nextTime);737
updateSeekBarMarkers();738
784
739
let prefetchTimedOut = false;785
let prefetchTimedOut = false;740
const timeoutId = armRequestTimeout(controller, prefetchRequestTimeoutMs, () =>786
const timeoutId = armRequestTimeout(controller, prefetchRequestTimeoutMs, () =>@@ -771,6 +817,7 @@771
sentToHeadersReceivedMs: diffMilliseconds(responseMeta.responseHeadersReceivedAtMs, responseMeta.serverResponseSentAtMs),817
sentToHeadersReceivedMs: diffMilliseconds(responseMeta.responseHeadersReceivedAtMs, responseMeta.serverResponseSentAtMs),772
});818
});773
819
820
setSeekMarkerTime('requested', nextTime);774
const receivedMarkerTime = Number.isFinite(responseMeta.shouldShowAtVideoTimeSeconds)821
const receivedMarkerTime = Number.isFinite(responseMeta.shouldShowAtVideoTimeSeconds)775
? responseMeta.shouldShowAtVideoTimeSeconds822
? responseMeta.shouldShowAtVideoTimeSeconds776
: nextTime;823
: nextTime;@@ -898,8 +945,6 @@898
requestedAtMs: requestStartedAtMs,945
requestedAtMs: requestStartedAtMs,899
requestedVideoTimeSeconds: roundLogNumber(currentTime),946
requestedVideoTimeSeconds: roundLogNumber(currentTime),900
});947
});901
setSeekMarkerTime('requested', currentTime);902
updateSeekBarMarkers();903
948
904
currentFramePromise = (async () =>949
currentFramePromise = (async () =>905
{950
{@@ -937,6 +982,7 @@937
sentToHeadersReceivedMs: diffMilliseconds(responseMeta.responseHeadersReceivedAtMs, responseMeta.serverResponseSentAtMs),982
sentToHeadersReceivedMs: diffMilliseconds(responseMeta.responseHeadersReceivedAtMs, responseMeta.serverResponseSentAtMs),938
});983
});939
984
985
setSeekMarkerTime('requested', currentTime);940
const receivedMarkerTime = Number.isFinite(responseMeta.shouldShowAtVideoTimeSeconds)986
const receivedMarkerTime = Number.isFinite(responseMeta.shouldShowAtVideoTimeSeconds)941
? responseMeta.shouldShowAtVideoTimeSeconds987
? responseMeta.shouldShowAtVideoTimeSeconds942
: currentTime;988
: currentTime;@@ -1074,6 +1120,7 @@1074
seekMarkerContainerEl = null;1120
seekMarkerContainerEl = null;1075
seekMarkerRequestedEl = null;1121
seekMarkerRequestedEl = null;1076
seekMarkerReceivedEl = null;1122
seekMarkerReceivedEl = null;1123
seekMarkerCombinedEl = null;1077
if (overlayEl) overlayEl.remove();1124
if (overlayEl) overlayEl.remove();1078
if (menuEl) menuEl.remove();1125
if (menuEl) menuEl.remove();1079
player.imageSubtitleOverlayController = null;1126
player.imageSubtitleOverlayController = null;@@ -535,10 +535,12 @@ describe('shared image subtitle prefetching', () =>
535
535
536
536
const requestedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-right');
537
537
const receivedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-left');
538
const combinedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-combined');
538
539
expect(requestedMarker).toBeTruthy();
539
540
expect(receivedMarker).toBeTruthy();
540
expect(requestedMarker.style.left).toBe('40.0000%');
541
expect(receivedMarker.style.left).toBe('40.0000%');
541
expect(combinedMarker).toBeTruthy();
542
expect(combinedMarker.style.display).toBe('block');
543
expect(combinedMarker.style.left).toBe('40.0000%');
542
544
expect(requestedMarker.textContent).toBe(']');
543
545
expect(receivedMarker.textContent).toBe('[');
544
546
@@ -547,6 +549,137 @@ describe('shared image subtitle prefetching', () =>
547
549
window.close();
548
550
});
549
551
552
test('keeps existing marker positions while the next request is still in flight', async () =>
553
{
554
const window = createWindow();
555
const helper = loadSharedVideoPlayer(window);
556
const { player, videojs } = buildPlayerHarness(window);
557
let pendingResolve = null;
558
559
player.duration(10);
560
window.fetch = jest.fn((url) =>
561
{
562
const parsed = new URL(url, 'http://localhost/');
563
const timeSeconds = Number(parsed.searchParams.get('timeSeconds'));
564
565
if (timeSeconds === 0)
566
{
567
return Promise.resolve(new Response('png-data', {
568
status: 200,
569
headers: {
570
'Content-Type': 'image/png',
571
'X-Subtitle-Frame-Status': 'ok',
572
'X-Subtitle-Frame-Start-Time': '2',
573
'X-Subtitle-Frame-End-Time': '3',
574
'X-Subtitle-Frame-Width': '320',
575
'X-Subtitle-Frame-Height': '180',
576
'X-Subtitle-Frame-Canvas-Width': '640',
577
'X-Subtitle-Frame-Canvas-Height': '360',
578
},
579
}));
580
}
581
582
return new Promise((resolve) =>
583
{
584
pendingResolve = resolve;
585
});
586
});
587
588
const controller = helper.bindImageSubtitleOverlay(player, videojs, {}, {
589
imageSubtitleTracks: [{ label: 'PGS English', streamIndex: 0, default: true }],
590
}, {
591
lookaheadSeconds: 0,
592
buildFrameRequest: ({ currentTime, streamIndex }) => ({
593
url: `/subtitle-frame?streamIndex=${streamIndex}&timeSeconds=${currentTime}`,
594
}),
595
});
596
597
await flushAsyncWork(window, 8);
598
599
const requestedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-right');
600
const receivedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-left');
601
const combinedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-combined');
602
expect(requestedMarker).toBeTruthy();
603
expect(receivedMarker).toBeTruthy();
604
expect(combinedMarker).toBeTruthy();
605
expect(requestedMarker.style.left).toBe('0.0000%');
606
expect(receivedMarker.style.left).toBe('20.0000%');
607
608
player.setCurrentTime(1.5);
609
player.trigger('timeupdate');
610
await flushAsyncWork(window, 2);
611
612
expect(requestedMarker.style.left).toBe('0.0000%');
613
expect(receivedMarker.style.left).toBe('20.0000%');
614
615
pendingResolve(new Response(null, {
616
status: 204,
617
headers: {
618
'X-Subtitle-Frame-Status': 'none',
619
},
620
}));
621
622
await flushAsyncWork(window, 8);
623
expect(combinedMarker.style.display).toBe('block');
624
expect(combinedMarker.style.left).toBe('15.0000%');
625
626
controller.detach();
627
await flushAsyncWork(window, 2);
628
window.close();
629
});
630
631
test('renders a combined marker when requested and received times are identical', async () =>
632
{
633
const window = createWindow();
634
const helper = loadSharedVideoPlayer(window);
635
const { player, videojs } = buildPlayerHarness(window);
636
637
player.duration(10);
638
window.fetch = jest.fn(async () =>
639
{
640
return new Response('png-data', {
641
status: 200,
642
headers: {
643
'Content-Type': 'image/png',
644
'X-Subtitle-Frame-Status': 'ok',
645
'X-Subtitle-Frame-Start-Time': '0',
646
'X-Subtitle-Frame-End-Time': '1',
647
'X-Subtitle-Frame-Width': '320',
648
'X-Subtitle-Frame-Height': '180',
649
'X-Subtitle-Frame-Canvas-Width': '640',
650
'X-Subtitle-Frame-Canvas-Height': '360',
651
},
652
});
653
});
654
655
const controller = helper.bindImageSubtitleOverlay(player, videojs, {}, {
656
imageSubtitleTracks: [{ label: 'PGS English', streamIndex: 0, default: true }],
657
}, {
658
lookaheadSeconds: 0,
659
buildFrameRequest: ({ currentTime, streamIndex }) => ({
660
url: `/subtitle-frame?streamIndex=${streamIndex}&timeSeconds=${currentTime}`,
661
}),
662
});
663
664
await flushAsyncWork(window, 8);
665
666
const requestedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-right');
667
const receivedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-left');
668
const combinedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-combined');
669
expect(requestedMarker).toBeTruthy();
670
expect(receivedMarker).toBeTruthy();
671
expect(combinedMarker).toBeTruthy();
672
expect(combinedMarker.style.display).toBe('block');
673
expect(combinedMarker.style.left).toBe('0.0000%');
674
expect(combinedMarker.textContent).toBe('[]');
675
expect(requestedMarker.style.display).toBe('none');
676
expect(receivedMarker.style.display).toBe('none');
677
678
controller.detach();
679
await flushAsyncWork(window, 2);
680
window.close();
681
});
682
550
683
test('recovers when a current subtitle request hangs and times out', async () =>
551
684
{
552
685
const window = createWindow();
@@ -535,10 +535,12 @@ describe('shared image subtitle prefetching', () =>535
535
536
const requestedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-right');536
const requestedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-right');537
const receivedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-left');537
const receivedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-left');538
const combinedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-combined');538
expect(requestedMarker).toBeTruthy();539
expect(requestedMarker).toBeTruthy();539
expect(receivedMarker).toBeTruthy();540
expect(receivedMarker).toBeTruthy();540
expect(requestedMarker.style.left).toBe('40.0000%');541
expect(combinedMarker).toBeTruthy();541
expect(receivedMarker.style.left).toBe('40.0000%');542
expect(combinedMarker.style.display).toBe('block');543
expect(combinedMarker.style.left).toBe('40.0000%');542
expect(requestedMarker.textContent).toBe(']');544
expect(requestedMarker.textContent).toBe(']');543
expect(receivedMarker.textContent).toBe('[');545
expect(receivedMarker.textContent).toBe('[');544
546
@@ -547,6 +549,137 @@ describe('shared image subtitle prefetching', () =>547
window.close();549
window.close();548
});550
});549
551
552
test('keeps existing marker positions while the next request is still in flight', async () =>553
{554
const window = createWindow();555
const helper = loadSharedVideoPlayer(window);556
const { player, videojs } = buildPlayerHarness(window);557
let pendingResolve = null;558
559
player.duration(10);560
window.fetch = jest.fn((url) =>561
{562
const parsed = new URL(url, 'http://localhost/');563
const timeSeconds = Number(parsed.searchParams.get('timeSeconds'));564
565
if (timeSeconds === 0)566
{567
return Promise.resolve(new Response('png-data', {568
status: 200,569
headers: {570
'Content-Type': 'image/png',571
'X-Subtitle-Frame-Status': 'ok',572
'X-Subtitle-Frame-Start-Time': '2',573
'X-Subtitle-Frame-End-Time': '3',574
'X-Subtitle-Frame-Width': '320',575
'X-Subtitle-Frame-Height': '180',576
'X-Subtitle-Frame-Canvas-Width': '640',577
'X-Subtitle-Frame-Canvas-Height': '360',578
},579
}));580
}581
582
return new Promise((resolve) =>583
{584
pendingResolve = resolve;585
});586
});587
588
const controller = helper.bindImageSubtitleOverlay(player, videojs, {}, {589
imageSubtitleTracks: [{ label: 'PGS English', streamIndex: 0, default: true }],590
}, {591
lookaheadSeconds: 0,592
buildFrameRequest: ({ currentTime, streamIndex }) => ({593
url: `/subtitle-frame?streamIndex=${streamIndex}&timeSeconds=${currentTime}`,594
}),595
});596
597
await flushAsyncWork(window, 8);598
599
const requestedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-right');600
const receivedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-left');601
const combinedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-combined');602
expect(requestedMarker).toBeTruthy();603
expect(receivedMarker).toBeTruthy();604
expect(combinedMarker).toBeTruthy();605
expect(requestedMarker.style.left).toBe('0.0000%');606
expect(receivedMarker.style.left).toBe('20.0000%');607
608
player.setCurrentTime(1.5);609
player.trigger('timeupdate');610
await flushAsyncWork(window, 2);611
612
expect(requestedMarker.style.left).toBe('0.0000%');613
expect(receivedMarker.style.left).toBe('20.0000%');614
615
pendingResolve(new Response(null, {616
status: 204,617
headers: {618
'X-Subtitle-Frame-Status': 'none',619
},620
}));621
622
await flushAsyncWork(window, 8);623
expect(combinedMarker.style.display).toBe('block');624
expect(combinedMarker.style.left).toBe('15.0000%');625
626
controller.detach();627
await flushAsyncWork(window, 2);628
window.close();629
});630
631
test('renders a combined marker when requested and received times are identical', async () =>632
{633
const window = createWindow();634
const helper = loadSharedVideoPlayer(window);635
const { player, videojs } = buildPlayerHarness(window);636
637
player.duration(10);638
window.fetch = jest.fn(async () =>639
{640
return new Response('png-data', {641
status: 200,642
headers: {643
'Content-Type': 'image/png',644
'X-Subtitle-Frame-Status': 'ok',645
'X-Subtitle-Frame-Start-Time': '0',646
'X-Subtitle-Frame-End-Time': '1',647
'X-Subtitle-Frame-Width': '320',648
'X-Subtitle-Frame-Height': '180',649
'X-Subtitle-Frame-Canvas-Width': '640',650
'X-Subtitle-Frame-Canvas-Height': '360',651
},652
});653
});654
655
const controller = helper.bindImageSubtitleOverlay(player, videojs, {}, {656
imageSubtitleTracks: [{ label: 'PGS English', streamIndex: 0, default: true }],657
}, {658
lookaheadSeconds: 0,659
buildFrameRequest: ({ currentTime, streamIndex }) => ({660
url: `/subtitle-frame?streamIndex=${streamIndex}&timeSeconds=${currentTime}`,661
}),662
});663
664
await flushAsyncWork(window, 8);665
666
const requestedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-right');667
const receivedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-left');668
const combinedMarker = player.el().querySelector('.vjs-image-subtitle-seek-marker-combined');669
expect(requestedMarker).toBeTruthy();670
expect(receivedMarker).toBeTruthy();671
expect(combinedMarker).toBeTruthy();672
expect(combinedMarker.style.display).toBe('block');673
expect(combinedMarker.style.left).toBe('0.0000%');674
expect(combinedMarker.textContent).toBe('[]');675
expect(requestedMarker.style.display).toBe('none');676
expect(receivedMarker.style.display).toBe('none');677
678
controller.detach();679
await flushAsyncWork(window, 2);680
window.close();681
});682
550
test('recovers when a current subtitle request hangs and times out', async () =>683
test('recovers when a current subtitle request hangs and times out', async () =>551
{684
{552
const window = createWindow();685
const window = createWindow();