Fix mobile username matching and expose VOD subtitles
This commit is contained in:
@ -6,6 +6,8 @@ class CaptionTracks {
|
||||
this.hls = null;
|
||||
this.probe = null;
|
||||
this.remoteTracks = [];
|
||||
this.timeOffset = 0;
|
||||
this.remoteCueTimes = new WeakMap();
|
||||
this.hlsTracks = new Map();
|
||||
this.retired = new Set();
|
||||
this.generation = 0;
|
||||
@ -48,6 +50,7 @@ class CaptionTracks {
|
||||
this.generation++;
|
||||
this.hls = null;
|
||||
this.probe = null;
|
||||
this.timeOffset = 0;
|
||||
this.retireNativeTracks();
|
||||
this.onChange();
|
||||
}
|
||||
@ -56,6 +59,24 @@ class CaptionTracks {
|
||||
this.probe = { subtitles: info?.subtitles || [], url };
|
||||
}
|
||||
|
||||
setTimeOffset(offset) {
|
||||
this.timeOffset = Number.isFinite(Number(offset)) ? Math.max(0, Number(offset)) : 0;
|
||||
for (const element of this.remoteTracks) this.alignRemoteCues(element);
|
||||
}
|
||||
|
||||
alignRemoteCues(element) {
|
||||
const track = element.track, mode = track.mode;
|
||||
if (!track.cues?.length) return;
|
||||
track.mode = 'hidden';
|
||||
for (const cue of Array.from(track.cues || [])) {
|
||||
if (!this.remoteCueTimes.has(cue)) this.remoteCueTimes.set(cue, { start: cue.startTime, end: cue.endTime });
|
||||
const original = this.remoteCueTimes.get(cue);
|
||||
cue.startTime = Math.max(0, original.start - this.timeOffset);
|
||||
cue.endTime = Math.max(0, original.end - this.timeOffset);
|
||||
}
|
||||
track.mode = mode;
|
||||
}
|
||||
|
||||
prepareMediaRecovery() {
|
||||
const tracks = Array.from(this.hlsTracks, ([key, entry]) => ({ key, entry,
|
||||
cues: Array.from(entry.element.track.cues || []), mode: entry.element.track.mode }));
|
||||
@ -97,6 +118,9 @@ class CaptionTracks {
|
||||
element.label = subtitle.title || subtitle.language || 'Subtitles';
|
||||
element.srclang = subtitle.language || '';
|
||||
element.src = `/api/subtitle?url=${encodeURIComponent(this.probe.url)}&index=${subtitle.index}`;
|
||||
element.addEventListener('load', () => {
|
||||
if (this.remoteTracks.includes(element)) this.alignRemoteCues(element);
|
||||
});
|
||||
this.remoteTracks.push(element);
|
||||
this.video.appendChild(element);
|
||||
}
|
||||
@ -251,6 +275,8 @@ class CaptionTracks {
|
||||
if (this.generation !== generation) return;
|
||||
this.off();
|
||||
track.mode = 'showing';
|
||||
const remote = this.remoteTracks.find(element => element.track === track);
|
||||
if (remote) this.alignRemoteCues(remote);
|
||||
} });
|
||||
}
|
||||
const counts = new Map();
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/** Metadata probes belong to the active playback, and share an ordered lease across replacements. */
|
||||
class PlaybackProbe {
|
||||
constructor(fetchImpl = fetch) {
|
||||
this.fetch = fetchImpl;
|
||||
this.fetch = (url, options) => fetchImpl(url, options);
|
||||
this.sequence = 0;
|
||||
this.leaseId = Array.from(globalThis.crypto.getRandomValues(new Uint8Array(16)),
|
||||
byte => byte.toString(16).padStart(2, '0')).join('');
|
||||
|
||||
Reference in New Issue
Block a user