@gcorevideo/player 2.28.28 → 2.28.29

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/dist/core.js CHANGED
@@ -12862,6 +12862,8 @@ class DashPlayback extends BasePlayback {
12862
12862
  startChangeQuality = false;
12863
12863
  manifestInfo = null;
12864
12864
  _timeUpdateTimer = null;
12865
+ oncueenter = null;
12866
+ oncueexit = null;
12865
12867
  get name() {
12866
12868
  return 'dash';
12867
12869
  }
@@ -12904,6 +12906,7 @@ class DashPlayback extends BasePlayback {
12904
12906
  }
12905
12907
  }
12906
12908
  get _startTime() {
12909
+ // TODO review
12907
12910
  if (this._playbackType === Playback.LIVE &&
12908
12911
  this._playlistType !== 'EVENT') {
12909
12912
  return this._extrapolatedStartTime;
@@ -12958,12 +12961,12 @@ class DashPlayback extends BasePlayback {
12958
12961
  streaming: {
12959
12962
  text: {
12960
12963
  defaultEnabled: false,
12964
+ dispatchForManualRendering: true,
12961
12965
  },
12962
12966
  },
12963
12967
  }, this.options.dash);
12964
12968
  this._dash.updateSettings(settings);
12965
12969
  }
12966
- assert.ok(this.el instanceof HTMLMediaElement, 'el must be an HTMLMediaElement');
12967
12970
  this._dash.attachView(this.el);
12968
12971
  this._dash.setAutoPlay(false);
12969
12972
  this._dash.attachSource(this.options.src);
@@ -13007,6 +13010,19 @@ class DashPlayback extends BasePlayback {
13007
13010
  this.trigger(Events$1.PLAYBACK_AUDIO_CHANGED, toClapprTrack$1(e.newMediaInfo));
13008
13011
  }
13009
13012
  });
13013
+ this._dash.on(_.events.CUE_ENTER, (e) => {
13014
+ this.oncueenter?.({
13015
+ end: e.end,
13016
+ id: e.id,
13017
+ start: e.start,
13018
+ text: e.text,
13019
+ });
13020
+ });
13021
+ this._dash.on(_.events.CUE_EXIT, (e) => {
13022
+ this.oncueexit?.({
13023
+ id: e.id,
13024
+ });
13025
+ });
13010
13026
  }
13011
13027
  render() {
13012
13028
  this._ready();
@@ -13095,8 +13111,7 @@ class DashPlayback extends BasePlayback {
13095
13111
  this.trigger(Events$1.PLAYBACK_SETTINGSUPDATE);
13096
13112
  }
13097
13113
  _onPlaybackError = (event) => {
13098
- // TODO
13099
- trace(`${T$3} _onPlaybackError`, { event });
13114
+ trace(`${T$3} _onPlaybackError`, { type: event.type, code: event.error.code, message: event.error.message });
13100
13115
  };
13101
13116
  _onDASHJSSError = (event) => {
13102
13117
  this._stopTimeUpdateTimer();
@@ -13215,7 +13230,14 @@ class DashPlayback extends BasePlayback {
13215
13230
  this._dash.off(_.events.ERROR, this._onDASHJSSError);
13216
13231
  this._dash.off(_.events.PLAYBACK_ERROR, this._onPlaybackError);
13217
13232
  this._dash.off(_.events.MANIFEST_LOADED, this.getDuration);
13233
+ const tracks = this._dash.getTracksFor('text');
13234
+ tracks.forEach(track => {
13235
+ if (track.id) {
13236
+ this._dash.removeExternalSubtitleById(track.id);
13237
+ }
13238
+ });
13218
13239
  this._dash.reset();
13240
+ this._dash.destroy();
13219
13241
  this._dash = null;
13220
13242
  }
13221
13243
  }
@@ -13233,8 +13255,6 @@ class DashPlayback extends BasePlayback {
13233
13255
  }
13234
13256
  }
13235
13257
  _fillLevels(levels) {
13236
- // TOOD check that levels[i].index === i
13237
- trace(`${T$3} _fillLevels`, { levels });
13238
13258
  this._levels = levels.map((level) => {
13239
13259
  return {
13240
13260
  level: level.index,
@@ -13311,6 +13331,31 @@ class DashPlayback extends BasePlayback {
13311
13331
  super._handleTextTrackChange();
13312
13332
  this._dash?.setTextTrack(this.closedCaptionsTrackId);
13313
13333
  }
13334
+ setTextTrack(id) {
13335
+ this._dash?.setTextTrack(id);
13336
+ }
13337
+ /**
13338
+ * @override
13339
+ */
13340
+ get closedCaptionsTracks() {
13341
+ const tt = this.getTextTracks();
13342
+ return tt;
13343
+ }
13344
+ getTextTracks() {
13345
+ return this._dash?.getTracksFor('text').map((t, index) => ({
13346
+ id: index,
13347
+ name: getTextTrackLabel(t) || "",
13348
+ track: {
13349
+ id: index,
13350
+ label: getTextTrackLabel(t) || "",
13351
+ language: t.lang,
13352
+ mode: "hidden",
13353
+ },
13354
+ })) || [];
13355
+ }
13356
+ }
13357
+ function getTextTrackLabel(t) {
13358
+ return t.labels.find((l) => !l.lang || l.lang === t.lang)?.text;
13314
13359
  }
13315
13360
  DashPlayback.canPlay = function (resource, mimeType) {
13316
13361
  if (!isDashSource(resource, mimeType)) {
@@ -49965,11 +50010,9 @@ const CLAPPR_VERSION = '0.13.0';
49965
50010
  const { now } = Utils;
49966
50011
  const AUTO = -1;
49967
50012
  const DEFAULT_RECOVER_ATTEMPTS = 16;
49968
- Events$1.register('PLAYBACK_FRAGMENT_CHANGED');
49969
50013
  Events$1.register('PLAYBACK_FRAGMENT_PARSING_METADATA');
49970
50014
  const T$2 = 'playback.hls';
49971
50015
  class HlsPlayback extends BasePlayback {
49972
- _ccIsSetup = false;
49973
50016
  _ccTracksUpdated = false;
49974
50017
  _currentFragment = null;
49975
50018
  _currentLevel = null;
@@ -49993,6 +50036,10 @@ class HlsPlayback extends BasePlayback {
49993
50036
  _recoveredDecodingError = false;
49994
50037
  _segmentTargetDuration = null;
49995
50038
  _timeUpdateTimer = null;
50039
+ oncueenter = null;
50040
+ oncueexit = null;
50041
+ cues = []; // TODO check the list size and use BST if needed
50042
+ currentCueId = null;
49996
50043
  /**
49997
50044
  * @internal
49998
50045
  */
@@ -50187,7 +50234,7 @@ class HlsPlayback extends BasePlayback {
50187
50234
  return;
50188
50235
  }
50189
50236
  this._manifestParsed = false;
50190
- this._ccIsSetup = false;
50237
+ // this._ccIsSetup = false
50191
50238
  this._ccTracksUpdated = false;
50192
50239
  this._setInitialState();
50193
50240
  this._hls.destroy();
@@ -50198,6 +50245,7 @@ class HlsPlayback extends BasePlayback {
50198
50245
  maxBufferLength: 2,
50199
50246
  maxMaxBufferLength: 4,
50200
50247
  autoStartLoad: false,
50248
+ renderTextTracksNatively: false,
50201
50249
  }, this.options.playback.hlsjsConfig);
50202
50250
  this._hls = new Hls(config);
50203
50251
  }
@@ -50211,7 +50259,7 @@ class HlsPlayback extends BasePlayback {
50211
50259
  if (!this._hls) {
50212
50260
  return;
50213
50261
  }
50214
- this._hls.once(Hls.Events.MEDIA_ATTACHED, () => {
50262
+ this._hls.once(Events.MEDIA_ATTACHED, () => {
50215
50263
  assert.ok(this._hls, 'HLS.js is not initialized');
50216
50264
  this.options.hlsPlayback.preload && this._hls.loadSource(this.options.src);
50217
50265
  });
@@ -50226,25 +50274,29 @@ class HlsPlayback extends BasePlayback {
50226
50274
  this.el.removeEventListener('playing', onPlaying);
50227
50275
  };
50228
50276
  this.el.addEventListener('playing', onPlaying);
50229
- this._hls.on(Hls.Events.MANIFEST_PARSED, () => {
50277
+ this._hls.on(Events.MANIFEST_PARSED, () => {
50230
50278
  this._manifestParsed = true;
50231
- this._hls.startLoad(-1);
50279
+ this.reload();
50232
50280
  });
50233
- this._hls.on(Hls.Events.LEVEL_LOADED, (evt, data) => {
50281
+ this._hls.on(Events.LEVEL_LOADED, (evt, data) => {
50234
50282
  this._updatePlaybackType(evt, data);
50235
50283
  });
50236
- this._hls.on(Hls.Events.LEVEL_UPDATED, (evt, data) => this._onLevelUpdated(evt, data));
50237
- this._hls.on(Hls.Events.LEVEL_SWITCHING, (evt, data) => this._onLevelSwitch(evt, data));
50238
- this._hls.on(Hls.Events.LEVEL_SWITCHED, (evt, data) => this._onLevelSwitched(evt, data));
50239
- this._hls.on(Hls.Events.FRAG_CHANGED, (evt, data) => this._onFragmentChanged(evt, data));
50240
- this._hls.on(Hls.Events.FRAG_LOADED, (evt, data) => this._onFragmentLoaded(evt, data));
50241
- this._hls.on(Hls.Events.FRAG_PARSING_METADATA, (evt, data) => this._onFragmentParsingMetadata(evt, data));
50242
- this._hls.on(Hls.Events.ERROR, (evt, data) => this._onHLSJSError(evt, data));
50243
- // this._hls.on(HLSJS.Events.SUBTITLE_TRACK_LOADED, () =>
50244
- // this._onSubtitleLoaded(),
50245
- // )
50284
+ this._hls.on(Events.LEVEL_UPDATED, (evt, data) => this._onLevelUpdated(evt, data));
50285
+ this._hls.on(Events.LEVEL_SWITCHING, (evt, data) => this._onLevelSwitch(evt, data));
50286
+ this._hls.on(Events.LEVEL_SWITCHED, (evt, data) => this._onLevelSwitched(evt, data));
50287
+ this._hls.on(Events.ERROR, (evt, data) => this._onHLSJSError(evt, data));
50246
50288
  this._hls.on(Events.AUDIO_TRACKS_UPDATED, (evt, data) => this._onAudioTracksUpdated(evt, data));
50247
50289
  this._hls.on(Events.AUDIO_TRACK_SWITCHED, (evt, data) => this._onAudioTrackSwitched(evt, data));
50290
+ this._hls.on(Events.CUES_PARSED, (evt, data) => {
50291
+ data.cues?.forEach((cue) => {
50292
+ this.cues.push({
50293
+ id: cue.id,
50294
+ start: cue.startTime,
50295
+ end: cue.endTime,
50296
+ text: cue.text,
50297
+ });
50298
+ });
50299
+ });
50248
50300
  this.bindCustomListeners();
50249
50301
  }
50250
50302
  bindCustomListeners() {
@@ -50263,13 +50315,6 @@ class HlsPlayback extends BasePlayback {
50263
50315
  requestedEventName && this._hls.off(requestedEventName, item.callback);
50264
50316
  });
50265
50317
  }
50266
- _onFragmentParsingMetadata(evt, data) {
50267
- // @ts-ignore
50268
- this.trigger(Events$1.Custom.PLAYBACK_FRAGMENT_PARSING_METADATA, {
50269
- evt,
50270
- data,
50271
- });
50272
- }
50273
50318
  render() {
50274
50319
  this._ready();
50275
50320
  return super.render();
@@ -50351,6 +50396,7 @@ class HlsPlayback extends BasePlayback {
50351
50396
  this.dvrEnabled && this._updateDvr(time < this.getDuration() - 3);
50352
50397
  time += this._startTime;
50353
50398
  this.el.currentTime = time;
50399
+ this.triggerCues();
50354
50400
  }
50355
50401
  seekToLivePoint() {
50356
50402
  this.seek(this.getDuration());
@@ -50399,20 +50445,20 @@ class HlsPlayback extends BasePlayback {
50399
50445
  if (this._recoverAttemptsRemaining > 0) {
50400
50446
  this._recoverAttemptsRemaining -= 1;
50401
50447
  switch (data.type) {
50402
- case Hls.ErrorTypes.NETWORK_ERROR:
50448
+ case ErrorTypes.NETWORK_ERROR:
50403
50449
  switch (data.details) {
50404
50450
  // The following network errors cannot be recovered with HLS.startLoad()
50405
50451
  // For more details, see https://github.com/video-dev/hls.js/blob/master/doc/design.md#error-detection-and-handling
50406
50452
  // For "level load" fatal errors, see https://github.com/video-dev/hls.js/issues/1138
50407
50453
  // TODO test handling of these errors
50408
- case Hls.ErrorDetails.MANIFEST_LOAD_ERROR:
50409
- case Hls.ErrorDetails.MANIFEST_LOAD_TIMEOUT:
50410
- case Hls.ErrorDetails.MANIFEST_PARSING_ERROR:
50454
+ case ErrorDetails.MANIFEST_LOAD_ERROR:
50455
+ case ErrorDetails.MANIFEST_LOAD_TIMEOUT:
50456
+ case ErrorDetails.MANIFEST_PARSING_ERROR:
50411
50457
  // TODO sort out the errors below, perhaps some of them are recoverable
50412
- case Hls.ErrorDetails.LEVEL_LOAD_ERROR:
50413
- case Hls.ErrorDetails.LEVEL_LOAD_TIMEOUT:
50414
- case Hls.ErrorDetails.FRAG_LOAD_ERROR:
50415
- case Hls.ErrorDetails.FRAG_LOAD_TIMEOUT:
50458
+ case ErrorDetails.LEVEL_LOAD_ERROR:
50459
+ case ErrorDetails.LEVEL_LOAD_TIMEOUT:
50460
+ case ErrorDetails.FRAG_LOAD_ERROR:
50461
+ case ErrorDetails.FRAG_LOAD_TIMEOUT:
50416
50462
  Log.error('hlsjs: unrecoverable network fatal error.', {
50417
50463
  evt,
50418
50464
  data,
@@ -50429,11 +50475,11 @@ class HlsPlayback extends BasePlayback {
50429
50475
  details: data.details,
50430
50476
  });
50431
50477
  error.level = PlayerError.Levels.WARN;
50432
- this._hls?.startLoad();
50478
+ this.reload();
50433
50479
  break;
50434
50480
  }
50435
50481
  break;
50436
- case Hls.ErrorTypes.MEDIA_ERROR:
50482
+ case ErrorTypes.MEDIA_ERROR:
50437
50483
  Log.warn('hlsjs: trying to recover from media error.', {
50438
50484
  evt,
50439
50485
  data,
@@ -50474,9 +50520,14 @@ class HlsPlayback extends BasePlayback {
50474
50520
  });
50475
50521
  }
50476
50522
  }
50523
+ reload() {
50524
+ this.cues = [];
50525
+ this.currentCueId = null;
50526
+ this._hls?.startLoad(-1);
50527
+ }
50477
50528
  _keyIsDenied(data) {
50478
- return (data.type === Hls.ErrorTypes.NETWORK_ERROR &&
50479
- data.details === Hls.ErrorDetails.KEY_LOAD_ERROR &&
50529
+ return (data.type === ErrorTypes.NETWORK_ERROR &&
50530
+ data.details === ErrorDetails.KEY_LOAD_ERROR &&
50480
50531
  data.response &&
50481
50532
  data.response.code &&
50482
50533
  data.response.code >= 400);
@@ -50494,6 +50545,7 @@ class HlsPlayback extends BasePlayback {
50494
50545
  }
50495
50546
  this._lastTimeUpdate = update;
50496
50547
  this.trigger(Events$1.PLAYBACK_TIMEUPDATE, update, this.name);
50548
+ this.triggerCues();
50497
50549
  }
50498
50550
  _onDurationChange() {
50499
50551
  const duration = this.getDuration();
@@ -50532,6 +50584,20 @@ class HlsPlayback extends BasePlayback {
50532
50584
  };
50533
50585
  this.trigger(Events$1.PLAYBACK_PROGRESS, progress, buffered);
50534
50586
  }
50587
+ triggerCues() {
50588
+ const currentTime = this.getCurrentTime();
50589
+ // const cues = Object.values(this.cues)
50590
+ // TODO build a search tree
50591
+ const cue = this.cues.find((cue) => currentTime >= cue.start && currentTime <= cue.end);
50592
+ if (cue) {
50593
+ this.currentCueId = cue.id;
50594
+ this.oncueenter?.(cue);
50595
+ }
50596
+ else if (this.currentCueId) {
50597
+ this.oncueexit?.({ id: this.currentCueId });
50598
+ this.currentCueId = null;
50599
+ }
50600
+ }
50535
50601
  load(url) {
50536
50602
  this._stopTimeUpdateTimer();
50537
50603
  this.options.src = url;
@@ -50723,26 +50789,6 @@ class HlsPlayback extends BasePlayback {
50723
50789
  durationChanged && this._onDurationChange();
50724
50790
  startTimeChanged && this._onProgress();
50725
50791
  }
50726
- _onFragmentChanged(evt, data) {
50727
- this._currentFragment = data.frag;
50728
- // @ts-ignore
50729
- this.trigger(Events$1.Custom.PLAYBACK_FRAGMENT_CHANGED, data);
50730
- }
50731
- _onFragmentLoaded(evt, data) {
50732
- this.trigger(Events$1.PLAYBACK_FRAGMENT_LOADED, data);
50733
- }
50734
- // _onSubtitleLoaded() {
50735
- // trace(`${T} _onSubtitleLoaded`)
50736
- // // This event may be triggered multiple times
50737
- // // Setup CC only once (disable CC by default)
50738
- // if (!this._ccIsSetup) {
50739
- // this.trigger(Events.PLAYBACK_SUBTITLE_AVAILABLE)
50740
- // const trackId =
50741
- // this._playbackType === Playback.LIVE ? -1 : this.closedCaptionsTrackId
50742
- // this.closedCaptionsTrackId = trackId
50743
- // this._ccIsSetup = true
50744
- // }
50745
- // }
50746
50792
  _onLevelSwitch(evt, data) {
50747
50793
  if (!this.levels.length) {
50748
50794
  this._fillLevels();
@@ -50814,6 +50860,26 @@ class HlsPlayback extends BasePlayback {
50814
50860
  const track = this._hls.audioTracks[data.id];
50815
50861
  this.trigger(Events$1.PLAYBACK_AUDIO_CHANGED, toClapprTrack(track));
50816
50862
  }
50863
+ setTextTrack(id) {
50864
+ this._hls.subtitleTrack = id;
50865
+ }
50866
+ /**
50867
+ * @override
50868
+ */
50869
+ get closedCaptionsTracks() {
50870
+ return this.getTextTracks();
50871
+ }
50872
+ getTextTracks() {
50873
+ return this._hls?.subtitleTracks.map((t) => ({
50874
+ id: t.id,
50875
+ name: t.name,
50876
+ track: {
50877
+ id: t.id,
50878
+ label: t.name,
50879
+ language: t.lang,
50880
+ },
50881
+ })) || [];
50882
+ }
50817
50883
  }
50818
50884
  HlsPlayback.canPlay = function (resource, mimeType) {
50819
50885
  if (!isHlsSource(resource, mimeType)) {
@@ -51415,7 +51481,7 @@ class Player {
51415
51481
  }
51416
51482
  }
51417
51483
 
51418
- var version$1 = "2.28.28";
51484
+ var version$1 = "2.28.29";
51419
51485
 
51420
51486
  var packages = {
51421
51487
  "node_modules/@clappr/core": {