hls.js 1.6.0-beta.1.0.canary.10818 → 1.6.0-beta.1.0.canary.10821

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -70,7 +70,7 @@
70
70
  "@babel/preset-env": "7.26.0",
71
71
  "@babel/preset-typescript": "7.26.0",
72
72
  "@babel/register": "7.25.9",
73
- "@microsoft/api-documenter": "7.26.0",
73
+ "@microsoft/api-documenter": "7.26.1",
74
74
  "@microsoft/api-extractor": "7.48.0",
75
75
  "@rollup/plugin-alias": "5.1.1",
76
76
  "@rollup/plugin-babel": "6.0.4",
@@ -130,5 +130,5 @@
130
130
  "url-toolkit": "2.2.5",
131
131
  "wrangler": "3.91.0"
132
132
  },
133
- "version": "1.6.0-beta.1.0.canary.10818"
133
+ "version": "1.6.0-beta.1.0.canary.10821"
134
134
  }
@@ -106,12 +106,13 @@ class ID3TrackController implements ComponentAPI {
106
106
  this.media = null;
107
107
  this.dateRangeCuesAppended = {};
108
108
  // @ts-ignore
109
- this.hls = null;
109
+ this.hls = this.onEventCueEnter = null;
110
110
  }
111
111
 
112
112
  private _registerListeners() {
113
113
  const { hls } = this;
114
114
  hls.on(Events.MEDIA_ATTACHING, this.onMediaAttaching, this);
115
+ hls.on(Events.MEDIA_ATTACHED, this.onMediaAttached, this);
115
116
  hls.on(Events.MEDIA_DETACHING, this.onMediaDetaching, this);
116
117
  hls.on(Events.MANIFEST_LOADING, this.onManifestLoading, this);
117
118
  hls.on(Events.FRAG_PARSING_METADATA, this.onFragParsingMetadata, this);
@@ -123,6 +124,7 @@ class ID3TrackController implements ComponentAPI {
123
124
  private _unregisterListeners() {
124
125
  const { hls } = this;
125
126
  hls.off(Events.MEDIA_ATTACHING, this.onMediaAttaching, this);
127
+ hls.off(Events.MEDIA_ATTACHED, this.onMediaAttached, this);
126
128
  hls.off(Events.MEDIA_DETACHING, this.onMediaDetaching, this);
127
129
  hls.off(Events.MANIFEST_LOADING, this.onManifestLoading, this);
128
130
  hls.off(Events.FRAG_PARSING_METADATA, this.onFragParsingMetadata, this);
@@ -131,6 +133,13 @@ class ID3TrackController implements ComponentAPI {
131
133
  hls.off(Events.LEVEL_PTS_UPDATED, this.onLevelPtsUpdated, this);
132
134
  }
133
135
 
136
+ private onEventCueEnter = () => {
137
+ if (!this.hls) {
138
+ return;
139
+ }
140
+ this.hls.trigger(Events.EVENT_CUE_ENTER, {});
141
+ };
142
+
134
143
  // Add ID3 metatadata text track.
135
144
  private onMediaAttaching(
136
145
  event: Events.MEDIA_ATTACHING,
@@ -142,6 +151,13 @@ class ID3TrackController implements ComponentAPI {
142
151
  }
143
152
  }
144
153
 
154
+ private onMediaAttached() {
155
+ const details = this.hls.latestLevelDetails;
156
+ if (details) {
157
+ this.updateDateRangeCues(details);
158
+ }
159
+ }
160
+
145
161
  private onMediaDetaching(
146
162
  event: Events.MEDIA_DETACHING,
147
163
  data: MediaDetachingData,
@@ -153,7 +169,7 @@ class ID3TrackController implements ComponentAPI {
153
169
  }
154
170
  if (this.id3Track) {
155
171
  if (this.removeCues) {
156
- clearCurrentCues(this.id3Track);
172
+ clearCurrentCues(this.id3Track, this.onEventCueEnter);
157
173
  }
158
174
  this.id3Track = null;
159
175
  }
@@ -349,7 +365,9 @@ class ID3TrackController implements ComponentAPI {
349
365
  delete dateRangeCuesAppended[id];
350
366
  Object.keys(cues).forEach((key) => {
351
367
  try {
352
- id3Track.removeCue(cues[key]);
368
+ const cue = cues[key];
369
+ cue.removeEventListener('enter', this.onEventCueEnter);
370
+ id3Track.removeCue(cue);
353
371
  } catch (e) {
354
372
  /* no-op */
355
373
  }
@@ -429,17 +447,26 @@ class ID3TrackController implements ComponentAPI {
429
447
  if (isSCTE35Attribute(key)) {
430
448
  data = hexToArrayBuffer(data);
431
449
  }
450
+ const payload: any = { key, data };
432
451
  const cue = createCueWithDataFields(
433
452
  Cue,
434
453
  startTime,
435
454
  endTime,
436
- { key, data },
455
+ payload,
437
456
  MetadataSchema.dateRange,
438
457
  );
439
458
  if (cue) {
440
459
  cue.id = id;
441
460
  this.id3Track.addCue(cue);
442
461
  cues[key] = cue;
462
+ if (
463
+ __USE_INTERSTITALS__ &&
464
+ this.hls.config.interstitialsController
465
+ ) {
466
+ if (key === 'X-ASSET-LIST' || key === 'X-ASSET-URL') {
467
+ cue.addEventListener('enter', this.onEventCueEnter);
468
+ }
469
+ }
443
470
  }
444
471
  }
445
472
  }
@@ -135,6 +135,7 @@ export default class InterstitialsController
135
135
  hls.on(Events.AUDIO_TRACK_UPDATED, this.onAudioTrackUpdated, this);
136
136
  hls.on(Events.SUBTITLE_TRACK_SWITCH, this.onSubtitleTrackSwitch, this);
137
137
  hls.on(Events.SUBTITLE_TRACK_UPDATED, this.onSubtitleTrackUpdated, this);
138
+ hls.on(Events.EVENT_CUE_ENTER, this.onInterstitialCueEnter, this);
138
139
  hls.on(Events.ASSET_LIST_LOADED, this.onAssetListLoaded, this);
139
140
  hls.on(Events.BUFFER_APPENDED, this.onBufferAppended, this);
140
141
  hls.on(Events.BUFFER_FLUSHED, this.onBufferFlushed, this);
@@ -158,6 +159,7 @@ export default class InterstitialsController
158
159
  hls.off(Events.AUDIO_TRACK_UPDATED, this.onAudioTrackUpdated, this);
159
160
  hls.off(Events.SUBTITLE_TRACK_SWITCH, this.onSubtitleTrackSwitch, this);
160
161
  hls.off(Events.SUBTITLE_TRACK_UPDATED, this.onSubtitleTrackUpdated, this);
162
+ hls.off(Events.EVENT_CUE_ENTER, this.onInterstitialCueEnter, this);
161
163
  hls.off(Events.ASSET_LIST_LOADED, this.onAssetListLoaded, this);
162
164
  hls.off(Events.BUFFER_CODECS, this.onBufferCodecs, this);
163
165
  hls.off(Events.BUFFER_APPENDED, this.onBufferAppended, this);
@@ -822,6 +824,10 @@ MediaSource ${JSON.stringify(attachMediaSourceData)} from ${logFromSource}`,
822
824
  }
823
825
  };
824
826
 
827
+ private onInterstitialCueEnter() {
828
+ this.onTimeupdate();
829
+ }
830
+
825
831
  private onTimeupdate = () => {
826
832
  const currentTime = this.currentTime;
827
833
  if (currentTime === undefined || this.playbackDisabled) {
package/src/events.ts CHANGED
@@ -216,6 +216,8 @@ export enum Events {
216
216
  INTERSTITIALS_PRIMARY_RESUMED = 'hlsInterstitialsPrimaryResumed',
217
217
  // Interstitial players dispatch this event when playout limit is reached
218
218
  PLAYOUT_LIMIT_REACHED = 'hlsPlayoutLimitReached',
219
+ // Event DateRange cue "enter" event dispatched
220
+ EVENT_CUE_ENTER = 'hlsEventCueEnter',
219
221
  }
220
222
 
221
223
  /**
@@ -490,6 +492,7 @@ export interface HlsListeners {
490
492
  event: Events.PLAYOUT_LIMIT_REACHED,
491
493
  data: {},
492
494
  ) => void;
495
+ [Events.EVENT_CUE_ENTER]: (event: Events.EVENT_CUE_ENTER, data: {}) => void;
493
496
  }
494
497
  export interface HlsEventEmitter {
495
498
  on<E extends keyof HlsListeners, Context = undefined>(
@@ -49,7 +49,7 @@ export function addCueToTrack(track: TextTrack, cue: VTTCue) {
49
49
  }
50
50
  }
51
51
 
52
- export function clearCurrentCues(track: TextTrack) {
52
+ export function clearCurrentCues(track: TextTrack, enterHandler?: () => void) {
53
53
  // When track.mode is disabled, track.cues will be null.
54
54
  // To guarantee the removal of cues, we need to temporarily
55
55
  // change the mode to hidden
@@ -59,6 +59,9 @@ export function clearCurrentCues(track: TextTrack) {
59
59
  }
60
60
  if (track.cues) {
61
61
  for (let i = track.cues.length; i--; ) {
62
+ if (enterHandler) {
63
+ track.cues[i].removeEventListener('enter', enterHandler);
64
+ }
62
65
  track.removeCue(track.cues[i]);
63
66
  }
64
67
  }