@gcorevideo/player 2.16.17 → 2.18.0

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.
Files changed (91) hide show
  1. package/README.md +68 -19
  2. package/dist/index.js +272 -125
  3. package/dist/player.d.ts +230 -73
  4. package/docs/api/index.md +1 -1
  5. package/docs/api/player.containersize.md +19 -0
  6. package/docs/api/player.dashsettings.md +2 -0
  7. package/docs/api/player.errorlevel.md +1 -0
  8. package/docs/api/player.langtag.md +6 -0
  9. package/docs/api/player.md +59 -24
  10. package/docs/api/player.mediatransport.md +1 -0
  11. package/docs/api/player.playbackerror.code.md +2 -0
  12. package/docs/api/player.playbackerror.description.md +2 -0
  13. package/docs/api/player.playbackerror.level.md +2 -0
  14. package/docs/api/player.playbackerror.md +43 -4
  15. package/docs/api/player.playbackerror.message.md +2 -0
  16. package/docs/api/player.playbackerror.origin.md +21 -0
  17. package/docs/api/player.playbackerror.scope.md +16 -0
  18. package/docs/api/player.playbackerrorcode.md +8 -7
  19. package/docs/api/player.playbackmodule.md +1 -0
  20. package/docs/api/player.player.attachto.md +26 -0
  21. package/docs/api/player.player.configure.md +6 -2
  22. package/docs/api/player.player.destroy.md +1 -1
  23. package/docs/api/player.player.getcurrenttime.md +6 -2
  24. package/docs/api/player.player.getduration.md +4 -0
  25. package/docs/api/player.player.getvolume.md +22 -0
  26. package/docs/api/player.player.isdvrenabled.md +20 -0
  27. package/docs/api/player.player.isdvrinuse.md +24 -0
  28. package/docs/api/player.player.isplaying.md +20 -0
  29. package/docs/api/player.player.md +76 -8
  30. package/docs/api/player.player.mute.md +1 -1
  31. package/docs/api/player.player.off.md +5 -5
  32. package/docs/api/player.player.on.md +5 -5
  33. package/docs/api/player.player.registerplugin.md +14 -1
  34. package/docs/api/player.player.resize.md +6 -5
  35. package/docs/api/player.player.seek.md +1 -1
  36. package/docs/api/player.player.setvolume.md +56 -0
  37. package/docs/api/player.player.unmute.md +1 -1
  38. package/docs/api/player.player.unregisterplugin.md +2 -2
  39. package/docs/api/player.playercomponenttype.md +16 -0
  40. package/docs/api/player.playerdebugsettings.md +1 -1
  41. package/docs/api/player.playerdebugtag.md +1 -0
  42. package/docs/api/player.playerevent.md +96 -0
  43. package/docs/api/player.playereventhandler.md +3 -2
  44. package/docs/api/player.playereventparams.md +20 -0
  45. package/docs/api/player.playermediasourcedesc.md +1 -1
  46. package/docs/api/player.playermediasourcedesc.mimetype.md +1 -1
  47. package/docs/api/player.qualitylevel.bitrate.md +16 -0
  48. package/docs/api/player.qualitylevel.height.md +16 -0
  49. package/docs/api/player.qualitylevel.level.md +16 -0
  50. package/docs/api/player.qualitylevel.md +104 -7
  51. package/docs/api/player.qualitylevel.width.md +16 -0
  52. package/docs/api/player.timeposition.current.md +16 -0
  53. package/docs/api/player.timeposition.md +65 -7
  54. package/docs/api/player.timeposition.total.md +16 -0
  55. package/docs/api/player.timevalue.md +1 -1
  56. package/docs/api/player.translationsettings.md +7 -1
  57. package/docs/api/player.transportpreference.md +1 -0
  58. package/lib/Player.d.ts +107 -26
  59. package/lib/Player.d.ts.map +1 -1
  60. package/lib/Player.js +161 -77
  61. package/lib/index.d.ts +2 -3
  62. package/lib/index.d.ts.map +1 -1
  63. package/lib/index.js +2 -3
  64. package/lib/internal.types.d.ts +3 -5
  65. package/lib/internal.types.d.ts.map +1 -1
  66. package/lib/playback/dash-playback/DashPlayback.d.ts +2 -0
  67. package/lib/playback/dash-playback/DashPlayback.d.ts.map +1 -1
  68. package/lib/playback/dash-playback/DashPlayback.js +37 -25
  69. package/lib/playback/hls-playback/HlsPlayback.d.ts +3 -0
  70. package/lib/playback/hls-playback/HlsPlayback.d.ts.map +1 -1
  71. package/lib/playback/hls-playback/HlsPlayback.js +33 -18
  72. package/lib/playback.types.d.ts +65 -6
  73. package/lib/playback.types.d.ts.map +1 -1
  74. package/lib/playback.types.js +10 -0
  75. package/lib/types.d.ts +54 -5
  76. package/lib/types.d.ts.map +1 -1
  77. package/lib/types.js +31 -2
  78. package/package.json +1 -1
  79. package/rollup.config.js +1 -1
  80. package/src/Player.ts +202 -91
  81. package/src/__tests__/Player.test.ts +9 -3
  82. package/src/index.ts +2 -3
  83. package/src/internal.types.ts +3 -2
  84. package/src/playback/dash-playback/DashPlayback.ts +64 -35
  85. package/src/playback/hls-playback/HlsPlayback.ts +46 -22
  86. package/src/playback.types.ts +65 -5
  87. package/src/types.ts +56 -6
  88. package/src/utils/__tests__/mediaSources.test.ts +8 -2
  89. package/temp/player.api.json +771 -106
  90. package/tsconfig.tsbuildinfo +1 -1
  91. package/dist/DashPlayback-BRJzl8D8.js +0 -901
package/dist/index.js CHANGED
@@ -12215,6 +12215,20 @@ function EventLite() {
12215
12215
  */
12216
12216
  var PlayerEvent;
12217
12217
  (function (PlayerEvent) {
12218
+ /**
12219
+ * Playback has reached the end of the media.
12220
+ */
12221
+ PlayerEvent["Ended"] = "ended";
12222
+ /**
12223
+ * An error occurred.
12224
+ * Parameters: {@link PlaybackError}
12225
+ */
12226
+ PlayerEvent["Error"] = "error";
12227
+ /**
12228
+ * The player has switched to or from the fullscreen mode.
12229
+ * Parameters:`boolean` isFullscreen
12230
+ */
12231
+ PlayerEvent["Fullscreen"] = "fullscreen";
12218
12232
  /**
12219
12233
  * The player is ready to use.
12220
12234
  */
@@ -12227,14 +12241,29 @@ var PlayerEvent;
12227
12241
  * Playback has been paused.
12228
12242
  */
12229
12243
  PlayerEvent["Pause"] = "pause";
12244
+ /**
12245
+ * The player's container has been resized.
12246
+ * Parameters: {@link ContainerSize}
12247
+ */
12248
+ PlayerEvent["Resize"] = "resize";
12249
+ /**
12250
+ * The player is seeking to a new position.
12251
+ */
12252
+ PlayerEvent["Seek"] = "seek";
12230
12253
  /**
12231
12254
  * Playback has been stopped.
12232
12255
  */
12233
12256
  PlayerEvent["Stop"] = "stop";
12234
12257
  /**
12235
- * Playback has reached the end of the media.
12258
+ * The current playback time has changed.
12259
+ * Parameters: {@link TimePosition}
12236
12260
  */
12237
- PlayerEvent["Ended"] = "ended";
12261
+ PlayerEvent["TimeUpdate"] = "timeupdate";
12262
+ /**
12263
+ * The volume has changed.
12264
+ * Parameters: `number` volume in the range 0..1
12265
+ */
12266
+ PlayerEvent["VolumeUpdate"] = "volumeupdate";
12238
12267
  })(PlayerEvent || (PlayerEvent = {}));
12239
12268
 
12240
12269
  // TODO rewrite using the Playback classes and canPlay static methods
@@ -12273,9 +12302,6 @@ function buildMediaSourcesList(sources, priorityTransport = 'dash') {
12273
12302
  }, [[], []]);
12274
12303
  return preferred.concat(rest);
12275
12304
  }
12276
- function unwrapSource(s) {
12277
- return typeof s === 'string' ? s : s.source;
12278
- }
12279
12305
  function wrapSource(s) {
12280
12306
  return typeof s === 'string' ? { source: s, mimeType: guessMimeType(s) } : s;
12281
12307
  }
@@ -12323,12 +12349,22 @@ var dash_all_minExports = requireDash_all_min();
12323
12349
  const DASHJS = /*@__PURE__*/getDefaultExportFromCjs$1(dash_all_minExports);
12324
12350
 
12325
12351
  /**
12352
+ * Codes of errors occurring within the playback component.
12326
12353
  * @beta
12327
12354
  */
12328
12355
  var PlaybackErrorCode;
12329
12356
  (function (PlaybackErrorCode) {
12357
+ /**
12358
+ * An unknown or uncategorised error.
12359
+ */
12330
12360
  PlaybackErrorCode[PlaybackErrorCode["Generic"] = 0] = "Generic";
12361
+ /**
12362
+ * The media source is not available. Typically a network error.
12363
+ */
12331
12364
  PlaybackErrorCode[PlaybackErrorCode["MediaSourceUnavailable"] = 1] = "MediaSourceUnavailable";
12365
+ /**
12366
+ * The media source is not accessible due to some protection policy.
12367
+ */
12332
12368
  PlaybackErrorCode[PlaybackErrorCode["MediaSourceAccessDenied"] = 3] = "MediaSourceAccessDenied";
12333
12369
  })(PlaybackErrorCode || (PlaybackErrorCode = {}));
12334
12370
 
@@ -12397,13 +12433,15 @@ class DashPlayback extends HTML5Video {
12397
12433
  this.trigger(Events$1.PLAYBACK_LEVEL_SWITCH_START);
12398
12434
  assert.ok(this._dash, 'An instance of dashjs MediaPlayer is required to switch levels');
12399
12435
  const dash = this._dash;
12400
- // TODO use $.extend
12401
- const settings = this.options.dash ? structuredClone(this.options.dash) : {};
12402
- settings.streaming = settings.streaming || {};
12403
- settings.streaming.abr = settings.streaming.abr || {};
12404
- settings.streaming.abr.autoSwitchBitrate =
12405
- settings.streaming.abr.autoSwitchBitrate || {};
12406
- settings.streaming.abr.autoSwitchBitrate.video = id === -1;
12436
+ const settings = $.extend(true, {}, this.options.dash, {
12437
+ streaming: {
12438
+ abr: {
12439
+ autoSwitchBitrate: {
12440
+ video: id === -1,
12441
+ },
12442
+ },
12443
+ },
12444
+ });
12407
12445
  dash.updateSettings(settings);
12408
12446
  if (id !== -1) {
12409
12447
  this._dash.setQualityFor('video', id);
@@ -12471,16 +12509,14 @@ class DashPlayback extends HTML5Video {
12471
12509
  this._dash.initialize();
12472
12510
  if (this.options.dash) {
12473
12511
  // TODO use $.extend
12474
- const settings = structuredClone(this.options.dash);
12475
- if (!settings.streaming) {
12476
- settings.streaming = {};
12477
- }
12478
- if (!settings.streaming.text) {
12479
- settings.streaming.text = {
12480
- defaultEnabled: false,
12481
- };
12482
- }
12483
- this._dash.updateSettings(this.options.dash);
12512
+ const settings = $.extend({}, this.options.dash, {
12513
+ streaming: {
12514
+ text: {
12515
+ defaultEnabled: false,
12516
+ },
12517
+ },
12518
+ });
12519
+ this._dash.updateSettings(settings);
12484
12520
  }
12485
12521
  this._dash.attachView(this.el);
12486
12522
  this._dash.setAutoPlay(false);
@@ -12492,13 +12528,14 @@ class DashPlayback extends HTML5Video {
12492
12528
  this._updatePlaybackType();
12493
12529
  this._fillLevels(bitrates);
12494
12530
  dash.on(DASHJS.MediaPlayer.events.QUALITY_CHANGE_REQUESTED, (evt) => {
12495
- // TODO
12496
- assert.ok(this._levels, 'An array of levels is required to change quality');
12497
- const newLevel = this._levels.find((level) => level.level === evt.newQuality); // TODO or simply this._levels[evt.newQuality]?
12498
- assert.ok(newLevel, 'A valid level is required to change quality');
12531
+ const newLevel = this.getLevel(evt.newQuality);
12499
12532
  this.onLevelSwitch(newLevel);
12500
12533
  });
12501
12534
  });
12535
+ this._dash.on(DASHJS.MediaPlayer.events.QUALITY_CHANGE_RENDERED, (evt) => {
12536
+ const currentLevel = this.getLevel(evt.newQuality);
12537
+ this.onLevelSwitchEnd(currentLevel);
12538
+ });
12502
12539
  this._dash.on(DASHJS.MediaPlayer.events.METRIC_ADDED, (e) => {
12503
12540
  // Listen for the first manifest request in order to update player UI
12504
12541
  if (e.metric === 'DVRInfo') {
@@ -12642,7 +12679,11 @@ class DashPlayback extends HTML5Video {
12642
12679
  };
12643
12680
  triggerError(error) {
12644
12681
  trace(`${T$2} triggerError`, { error });
12645
- this.trigger(Events$1.PLAYBACK_ERROR, error);
12682
+ this.trigger(Events$1.PLAYBACK_ERROR, {
12683
+ ...error,
12684
+ origin: this.name,
12685
+ scope: DashPlayback.type,
12686
+ });
12646
12687
  // only reset the dash player in 10ms async, so that the rest of the
12647
12688
  // calling function finishes
12648
12689
  setTimeout(() => {
@@ -12757,8 +12798,10 @@ class DashPlayback extends HTML5Video {
12757
12798
  onLevelSwitch(currentLevel) {
12758
12799
  // TODO check the two below
12759
12800
  this.trigger(Events$1.PLAYBACK_LEVEL_SWITCH, currentLevel);
12801
+ }
12802
+ onLevelSwitchEnd(currentLevel) {
12760
12803
  this.trigger(Events$1.PLAYBACK_LEVEL_SWITCH_END);
12761
- const isHD = (currentLevel.height >= 720 || (currentLevel.bitrate / 1000) >= 2000);
12804
+ const isHD = currentLevel.height >= 720 || currentLevel.bitrate / 1000 >= 2000;
12762
12805
  this.trigger(Events$1.PLAYBACK_HIGHDEFINITIONUPDATE, isHD);
12763
12806
  this.trigger(Events$1.PLAYBACK_BITRATE, currentLevel);
12764
12807
  }
@@ -12768,6 +12811,11 @@ class DashPlayback extends HTML5Video {
12768
12811
  isSeekEnabled() {
12769
12812
  return this._playbackType === Playback.VOD || this.dvrEnabled;
12770
12813
  }
12814
+ getLevel(quality) {
12815
+ const ret = this.levels.find((level) => level.level === quality);
12816
+ assert.ok(ret, 'Invalid quality level');
12817
+ return ret;
12818
+ }
12771
12819
  }
12772
12820
  DashPlayback.canPlay = function (resource, mimeType) {
12773
12821
  if (!isDashSource(resource, mimeType)) {
@@ -41700,6 +41748,7 @@ class HlsPlayback extends HTML5Video {
41700
41748
  this._hls.on(Hls.Events.LEVEL_LOADED, (evt, data) => this._updatePlaybackType(evt, data));
41701
41749
  this._hls.on(Hls.Events.LEVEL_UPDATED, (evt, data) => this._onLevelUpdated(evt, data));
41702
41750
  this._hls.on(Hls.Events.LEVEL_SWITCHING, (evt, data) => this._onLevelSwitch(evt, data));
41751
+ this._hls.on(Hls.Events.LEVEL_SWITCHED, (evt, data) => this._onLevelSwitched(evt, data));
41703
41752
  this._hls.on(Hls.Events.FRAG_CHANGED, (evt, data) => this._onFragmentChanged(evt, data));
41704
41753
  this._hls.on(Hls.Events.FRAG_LOADED, (evt, data) => this._onFragmentLoaded(evt, data));
41705
41754
  this._hls.on(Hls.Events.FRAG_PARSING_METADATA, (evt, data) => this._onFragmentParsingMetadata(evt, data));
@@ -41757,7 +41806,10 @@ class HlsPlayback extends HTML5Video {
41757
41806
  }
41758
41807
  else {
41759
41808
  Log.error('hlsjs: failed to recover', { evt, data });
41760
- trace(`${T$1} _recover failed to recover`, { type: data.type, details: data.details });
41809
+ trace(`${T$1} _recover failed to recover`, {
41810
+ type: data.type,
41811
+ details: data.details,
41812
+ });
41761
41813
  error.level = PlayerError.Levels.FATAL;
41762
41814
  this.triggerError(error);
41763
41815
  }
@@ -41840,12 +41892,18 @@ class HlsPlayback extends HTML5Video {
41840
41892
  this.trigger(Events$1.PLAYBACK_SETTINGSUPDATE);
41841
41893
  }
41842
41894
  _onHLSJSError(evt, data) {
41843
- trace(`${T$1} _onHLSJSError`, { fatal: data.fatal, type: data.type, details: data.details });
41895
+ trace(`${T$1} _onHLSJSError`, {
41896
+ fatal: data.fatal,
41897
+ type: data.type,
41898
+ details: data.details,
41899
+ });
41844
41900
  const error = {
41845
41901
  code: PlaybackErrorCode.Generic,
41846
41902
  description: `${this.name} error: type: ${data.type}, details: ${data.details} fatal: ${data.fatal}`,
41847
41903
  level: data.fatal ? PlayerError.Levels.FATAL : PlayerError.Levels.WARN,
41848
41904
  message: `${this.name} error: type: ${data.type}, details: ${data.details}`,
41905
+ origin: this.name,
41906
+ scope: HlsPlayback.type,
41849
41907
  };
41850
41908
  if (data.response) {
41851
41909
  error.description += `, response: ${JSON.stringify(data.response)}`;
@@ -41925,7 +41983,10 @@ class HlsPlayback extends HTML5Video {
41925
41983
  return;
41926
41984
  }
41927
41985
  Log.warn('hlsjs: non-fatal error occurred', { evt, data });
41928
- trace(`${T$1} _onHLSJSError non-fatal error occurred`, { type: data.type, details: data.details });
41986
+ trace(`${T$1} _onHLSJSError non-fatal error occurred`, {
41987
+ type: data.type,
41988
+ details: data.details,
41989
+ });
41929
41990
  }
41930
41991
  }
41931
41992
  _keyIsDenied(data) {
@@ -42198,22 +42259,24 @@ class HlsPlayback extends HTML5Video {
42198
42259
  if (!this.levels.length) {
42199
42260
  this._fillLevels();
42200
42261
  }
42201
- this.trigger(Events$1.PLAYBACK_LEVEL_SWITCH_END);
42202
42262
  this.trigger(Events$1.PLAYBACK_LEVEL_SWITCH, data);
42203
- assert(this._hls, 'Hls.js instance is not available');
42204
- const currentLevel = this._hls.levels[data.level];
42205
- if (currentLevel) {
42206
- // TODO should highDefinition be private and maybe have a read only accessor if it's used somewhere
42207
- this.highDefinition =
42208
- currentLevel.height >= 720 || currentLevel.bitrate / 1000 >= 2000;
42209
- this.trigger(Events$1.PLAYBACK_HIGHDEFINITIONUPDATE, this.highDefinition);
42210
- this.trigger(Events$1.PLAYBACK_BITRATE, {
42211
- height: currentLevel.height,
42212
- width: currentLevel.width,
42213
- bitrate: currentLevel.bitrate,
42214
- level: data.level,
42215
- });
42216
- }
42263
+ }
42264
+ _onLevelSwitched(evt, data) {
42265
+ // @ts-ignore
42266
+ const currentLevel = this._hls.levels[data.level]; // TODO or find by .id == level?
42267
+ assert.ok(currentLevel, 'Invalid quality level');
42268
+ this._currentLevel = data.level;
42269
+ // TODO should highDefinition be private and maybe have a read only accessor if it's used somewhere
42270
+ this.highDefinition =
42271
+ currentLevel.height >= 720 || currentLevel.bitrate / 1000 >= 2000;
42272
+ this.trigger(Events$1.PLAYBACK_HIGHDEFINITIONUPDATE, this.highDefinition);
42273
+ this.trigger(Events$1.PLAYBACK_BITRATE, {
42274
+ height: currentLevel.height,
42275
+ width: currentLevel.width,
42276
+ bitrate: currentLevel.bitrate,
42277
+ level: data.level,
42278
+ });
42279
+ this.trigger(Events$1.PLAYBACK_LEVEL_SWITCH_END);
42217
42280
  }
42218
42281
  get dvrEnabled() {
42219
42282
  // enabled when:
@@ -42261,11 +42324,11 @@ const DEFAULT_OPTIONS = {
42261
42324
  };
42262
42325
  /**
42263
42326
  * The main component to use in the application code.
42327
+ * @beta
42264
42328
  * @remarks
42265
42329
  * The Player object provides very basic API to control playback.
42266
42330
  * To build a sophisticated UI, use the plugins framework to tap into the Clappr core.
42267
42331
  * {@link https://github.com/clappr/clappr/wiki/Architecture}
42268
- * @beta
42269
42332
  */
42270
42333
  class Player {
42271
42334
  config = DEFAULT_OPTIONS;
@@ -42283,16 +42346,16 @@ class Player {
42283
42346
  }
42284
42347
  /**
42285
42348
  * Adds a listener to a player event
42286
- * @param event - See {@link PlayerEvent}
42287
- * @param handler - See {@link PlayerEventHandler}
42349
+ * @param event - event type, see {@link PlayerEvent}
42350
+ * @param handler - a callback function to handle the event
42288
42351
  */
42289
42352
  on(event, handler) {
42290
42353
  this.emitter.on(event, handler);
42291
42354
  }
42292
42355
  /**
42293
- * Removes a listener from a player event
42356
+ * Removes a previously added event listener
42294
42357
  * @param event - See {@link PlayerEvent}
42295
- * @param handler - See {@link PlayerEventHandler}
42358
+ * @param handler - a callback attached earlier to that event type
42296
42359
  */
42297
42360
  off(event, handler) {
42298
42361
  this.emitter.off(event, handler);
@@ -42300,10 +42363,12 @@ class Player {
42300
42363
  /**
42301
42364
  * Configures the player.
42302
42365
  *
42303
- * Can be called multiple times. Each consequent call extends the previous configuration.
42304
- * After a reconfiguration, if something significant has changed, the must be reinitialized (i.e, a `.destroy()` followed by an `.init()` call).
42305
- *
42306
42366
  * @param config - complete or partial configuration
42367
+ * @remarks
42368
+ * Can be called multiple times.
42369
+ * Each consequent call extends the previous configuration with only the new keys overridden.
42370
+ *
42371
+ * After a reconfiguration, if something significant has changed, it might make sense reinitialize the player (i.e, a `.destroy()` followed by an `.init()` call).
42307
42372
  */
42308
42373
  configure(config) {
42309
42374
  this.setConfig(config);
@@ -42311,6 +42376,29 @@ class Player {
42311
42376
  /**
42312
42377
  * Initializes the player at the given container element.
42313
42378
  * @param playerElement - DOM element to host the player
42379
+ * @remarks
42380
+ * The player will be initialized and attached to the given element.
42381
+ *
42382
+ * All the core plugins will be initialized at this point.
42383
+ *
42384
+ * If no sources were configured, it will trigger an error.
42385
+ *
42386
+ * The player container will be initialized and then all the registered UI plugins.
42387
+ *
42388
+ * If the `autoPlay` option is set, then it will trigger playback immediately.
42389
+ *
42390
+ * It is an error to call this method twice. If you need to attache player to another DOM element,
42391
+ * first call {@link Player.destroy} and then {@link Player.attachTo}.
42392
+ *
42393
+ * @example
42394
+ * ```ts
42395
+ * const player = new Player({
42396
+ * sources: [{ source: 'https://example.com/a.mpd', mimeType: 'application/dash+xml' }],
42397
+ * })
42398
+ * document.addEventListener('DOMContentLoaded', () => {
42399
+ * player.attachTo(document.getElementById('video-container'))
42400
+ * })
42401
+ * ```
42314
42402
  */
42315
42403
  attachTo(playerElement) {
42316
42404
  assert.ok(!this.player, 'Player already initialized');
@@ -42331,7 +42419,7 @@ class Player {
42331
42419
  return this.initPlayer(coreOpts);
42332
42420
  }
42333
42421
  /**
42334
- * Destroys the player, releasing all resources and removing any DOM elements added.
42422
+ * Destroys the player, releasing all resources and unmounting its UI from the DOM.
42335
42423
  */
42336
42424
  destroy() {
42337
42425
  trace(`${T} destroy`, {
@@ -42349,8 +42437,11 @@ class Player {
42349
42437
  }
42350
42438
  }
42351
42439
  /**
42352
- * Current playback time in seconds, if appropriate.
42353
- * @returns For live streams, it returns the current time of the current segment.
42440
+ * Current playback (time since the beginning of the stream), if appropriate.
42441
+ *
42442
+ * @returns Time in seconds
42443
+ * @remarks
42444
+ * For live streams, it returns the current time within the current segment.
42354
42445
  */
42355
42446
  getCurrentTime() {
42356
42447
  if (!this.player) {
@@ -42360,7 +42451,10 @@ class Player {
42360
42451
  }
42361
42452
  /**
42362
42453
  * Duration of the current media in seconds, if appropriate.
42363
- * @returns For live streams, it returns the duration of the current segment.
42454
+ *
42455
+ * @returns Time in seconds
42456
+ * @remarks
42457
+ * For live streams, it returns the duration of the current segment.
42364
42458
  */
42365
42459
  getDuration() {
42366
42460
  if (!this.player) {
@@ -42369,13 +42463,33 @@ class Player {
42369
42463
  return this.player.getDuration();
42370
42464
  }
42371
42465
  /**
42372
- * Mutes the player.
42466
+ * Indicates whether DVR is enabled.
42467
+ */
42468
+ isDvrEnabled() {
42469
+ return this.player?.isDvrEnabled() ?? false;
42470
+ }
42471
+ /**
42472
+ * Indicates whether DVR is in use.
42473
+ * @remarks
42474
+ * DVR mode, if it is enabled, is triggered we a user seeks behind the live edge.
42475
+ */
42476
+ isDvrInUse() {
42477
+ return this.player?.isDvrInUse() ?? false;
42478
+ }
42479
+ /**
42480
+ * Indicates the playing state.
42481
+ */
42482
+ isPlaying() {
42483
+ return this.player?.isPlaying() ?? false;
42484
+ }
42485
+ /**
42486
+ * Mutes the sound of the video.
42373
42487
  */
42374
42488
  mute() {
42375
42489
  this.player?.mute();
42376
42490
  }
42377
42491
  /**
42378
- * Unmutes the player.
42492
+ * Unmutes the video sound.
42379
42493
  */
42380
42494
  unmute() {
42381
42495
  this.player?.unmute();
@@ -42395,17 +42509,38 @@ class Player {
42395
42509
  /**
42396
42510
  * Resizes the player container element and everything within it.
42397
42511
  * @param newSize - new size of the player
42512
+ * @remarks
42513
+ * Use this method when the player itself does not detect properly the change in size of its container element.
42514
+ * It can be a case for orientation change on some mobile devices.
42398
42515
  */
42399
42516
  resize(newSize) {
42400
42517
  this.player?.resize(newSize);
42401
42518
  }
42402
42519
  /**
42403
42520
  * Seeks to the given time.
42404
- * @param time - time to seek to in seconds
42521
+ * @param time - time to seek to in seconds (since the beginning of the stream)
42405
42522
  */
42406
42523
  seek(time) {
42407
42524
  this.player?.seek(time);
42408
42525
  }
42526
+ /**
42527
+ * Gets the current volume of the media content being played.
42528
+ * @returns a number between 0 and 1
42529
+ */
42530
+ getVolume() {
42531
+ // This method is provided by the MediaControl plugin
42532
+ // @ts-ignore
42533
+ return this.player?.getVolume?.() || 0;
42534
+ }
42535
+ /**
42536
+ * Sets the current volume of the media content being played.
42537
+ * @param volume - a number between 0 and 1
42538
+ */
42539
+ setVolume(volume) {
42540
+ // This method is provided by the MediaControl plugin
42541
+ // @ts-ignore
42542
+ this.player?.setVolume?.(volume);
42543
+ }
42409
42544
  /**
42410
42545
  * Stops playback.
42411
42546
  */
@@ -42414,14 +42549,27 @@ class Player {
42414
42549
  }
42415
42550
  /**
42416
42551
  * Registers a plugin.
42417
- * @param plugin - plugin to register
42552
+ * @param plugin - a plugin class
42553
+ * @remarks
42554
+ * Use this method to extend the player with custom behavior.
42555
+ * The plugin class must inherit from one of the Clappr UIPlugin, UIContainerPlugin or CorePlugin classes.
42556
+ * A core plugin will be initialized and attached to the player when the player is initialized.
42557
+ * A UI plugin will be initialized and attached to the player container is initialized.
42558
+ *
42559
+ * @see {@link https://github.com/clappr/clappr/wiki/Architecture}
42560
+ * @example
42561
+ * ```ts
42562
+ * import MyPlugin from './MyPlugin.js'
42563
+ *
42564
+ * Player.registerPlugin(MyPlugin)
42565
+ * ```
42418
42566
  */
42419
42567
  static registerPlugin(plugin) {
42420
42568
  Loader.registerPlugin(plugin);
42421
42569
  }
42422
42570
  /**
42423
- * Unregisters a plugin.
42424
- * @param plugin - plugin to unregister
42571
+ * Unregisters a plugin registered earlier with {@link Player.registerPlugin}.
42572
+ * @param plugin - a plugin class
42425
42573
  */
42426
42574
  static unregisterPlugin(plugin) {
42427
42575
  Loader.unregisterPlugin(plugin);
@@ -42459,32 +42607,7 @@ class Player {
42459
42607
  const player = this.player;
42460
42608
  this.bindContainerEventListeners(player);
42461
42609
  player.core.on(Events$1.CORE_ACTIVE_CONTAINER_CHANGED, () => this.bindContainerEventListeners(player), null);
42462
- player.core.on(Events$1.CORE_SCREEN_ORIENTATION_CHANGED, ({ orientation }) => {
42463
- trace(`${T} CORE_SCREEN_ORIENTATION_CHANGED`, {
42464
- orientation,
42465
- rootNode: {
42466
- width: this.rootNode?.clientWidth,
42467
- height: this.rootNode?.clientHeight,
42468
- },
42469
- });
42470
- if (Browser.isiOS && this.rootNode) {
42471
- player.core.resize({
42472
- width: this.rootNode.clientWidth,
42473
- height: this.rootNode.clientHeight,
42474
- });
42475
- }
42476
- }, null);
42477
- player.core.on(Events$1.CORE_RESIZE, ({ width, height }) => {
42478
- trace(`${T} CORE_RESIZE`, {
42479
- width,
42480
- height,
42481
- });
42482
- }, null);
42483
- player.core.on(Events$1.CORE_FULLSCREEN, (isFullscreen) => {
42484
- trace(`${T} CORE_FULLSCREEN`, {
42485
- isFullscreen,
42486
- });
42487
- }, null);
42610
+ this.bindSizeManagementListeners(player);
42488
42611
  if (this.config.autoPlay) {
42489
42612
  setTimeout(() => {
42490
42613
  trace(`${T} autoPlay`, {
@@ -42502,6 +42625,15 @@ class Player {
42502
42625
  reportError(e);
42503
42626
  }
42504
42627
  }
42628
+ safeTriggerEvent(event, ...args) {
42629
+ try {
42630
+ this.emitter.emit(event, ...args);
42631
+ }
42632
+ catch (e) {
42633
+ reportError(e);
42634
+ }
42635
+ }
42636
+ // TODO test
42505
42637
  events = {
42506
42638
  onReady: () => {
42507
42639
  trace(`${T} onReady`, {
@@ -42518,42 +42650,29 @@ class Player {
42518
42650
  // TODO ensure that CORE_ACTIVE_CONTAINER_CHANGED does not get caught before onReady
42519
42651
  setTimeout(() => this.tuneIn(), 0);
42520
42652
  },
42521
- onResize: (newSize) => {
42522
- trace(`${T} onResize`, {
42523
- newSize,
42524
- });
42525
- },
42526
42653
  onPlay: () => {
42527
- try {
42528
- this.emitter.emit(PlayerEvent.Play);
42529
- }
42530
- catch (e) {
42531
- reportError(e);
42532
- }
42654
+ this.safeTriggerEvent(PlayerEvent.Play);
42533
42655
  },
42534
42656
  onPause: () => {
42535
- try {
42536
- this.emitter.emit(PlayerEvent.Pause);
42537
- }
42538
- catch (e) {
42539
- reportError(e);
42540
- }
42657
+ this.safeTriggerEvent(PlayerEvent.Pause);
42541
42658
  },
42542
42659
  onEnded: () => {
42543
- try {
42544
- this.emitter.emit(PlayerEvent.Ended);
42545
- }
42546
- catch (e) {
42547
- reportError(e);
42548
- }
42660
+ this.safeTriggerEvent(PlayerEvent.Ended);
42661
+ },
42662
+ onSeek: (time) => {
42663
+ this.safeTriggerEvent(PlayerEvent.Seek, time);
42549
42664
  },
42550
42665
  onStop: () => {
42551
- try {
42552
- this.emitter.emit(PlayerEvent.Stop);
42553
- }
42554
- catch (e) {
42555
- reportError(e);
42556
- }
42666
+ this.safeTriggerEvent(PlayerEvent.Stop);
42667
+ },
42668
+ onVolumeUpdate: (volume) => {
42669
+ this.safeTriggerEvent(PlayerEvent.VolumeUpdate, volume);
42670
+ },
42671
+ onTimeUpdate: (time) => {
42672
+ this.safeTriggerEvent(PlayerEvent.TimeUpdate, time);
42673
+ },
42674
+ onError: (error) => {
42675
+ this.safeTriggerEvent(PlayerEvent.Error, error);
42557
42676
  },
42558
42677
  };
42559
42678
  buildCoreOptions(rootNode) {
@@ -42581,6 +42700,7 @@ class Player {
42581
42700
  mute: this.config.mute,
42582
42701
  crossOrigin: 'anonymous', // TODO
42583
42702
  hlsjsConfig: {
42703
+ // TODO
42584
42704
  debug: this.config.debug === 'all' || this.config.debug === 'hls',
42585
42705
  },
42586
42706
  },
@@ -42589,7 +42709,7 @@ class Player {
42589
42709
  width: rootNode.clientWidth,
42590
42710
  source: source ? source.source : undefined,
42591
42711
  mimeType: source ? source.mimeType : undefined,
42592
- sources, // prevent Clappr from loading all sources simultaneously
42712
+ sources,
42593
42713
  strings: this.config.strings,
42594
42714
  };
42595
42715
  return coreOptions;
@@ -42603,9 +42723,6 @@ class Player {
42603
42723
  this.config.sources.map((s) => wrapSource(s)), this.config.priorityTransport);
42604
42724
  }
42605
42725
  bindContainerEventListeners(player) {
42606
- trace(`${T} bindContainerEventListeners`, {
42607
- activePlayback: player.core.activePlayback?.name,
42608
- });
42609
42726
  if (Browser.isiOS && player.core.activePlayback) {
42610
42727
  player.core.activePlayback.$el.on('webkitendfullscreen', () => {
42611
42728
  try {
@@ -42617,9 +42734,39 @@ class Player {
42617
42734
  });
42618
42735
  }
42619
42736
  }
42737
+ bindSizeManagementListeners(player) {
42738
+ player.core.on(Events$1.CORE_SCREEN_ORIENTATION_CHANGED, ({ orientation }) => {
42739
+ trace(`${T} on CORE_SCREEN_ORIENTATION_CHANGED`, {
42740
+ orientation,
42741
+ rootNode: {
42742
+ width: this.rootNode?.clientWidth,
42743
+ height: this.rootNode?.clientHeight,
42744
+ },
42745
+ });
42746
+ if (Browser.isiOS && this.rootNode) {
42747
+ player.core.resize({
42748
+ width: this.rootNode.clientWidth,
42749
+ height: this.rootNode.clientHeight,
42750
+ });
42751
+ }
42752
+ }, null);
42753
+ player.core.on(Events$1.CORE_RESIZE, ({ width, height }) => {
42754
+ trace(`${T} on CORE_RESIZE`, {
42755
+ width,
42756
+ height,
42757
+ });
42758
+ this.safeTriggerEvent(PlayerEvent.Resize, { width, height });
42759
+ }, null);
42760
+ player.core.on(Events$1.CORE_FULLSCREEN, (isFullscreen) => {
42761
+ trace(`${T} CORE_FULLSCREEN`, {
42762
+ isFullscreen,
42763
+ });
42764
+ this.safeTriggerEvent(PlayerEvent.Fullscreen, isFullscreen);
42765
+ }, null);
42766
+ }
42620
42767
  }
42621
42768
 
42622
- var version$1 = "2.16.17";
42769
+ var version$1 = "2.18.0";
42623
42770
 
42624
42771
  var packages = {
42625
42772
  "node_modules/@clappr/core": {
@@ -42643,4 +42790,4 @@ function version() {
42643
42790
  };
42644
42791
  }
42645
42792
 
42646
- export { LogTracer, Logger, PlaybackErrorCode, Player, PlayerEvent, SentryTracer, buildMediaSourcesList, isDashSource, isHlsSource, reportError, setTracer, trace, unwrapSource, version, wrapSource };
42793
+ export { LogTracer, Logger, PlaybackErrorCode, Player, PlayerEvent, SentryTracer, reportError, setTracer, trace, version };