@gcorevideo/player 2.30.1 → 2.30.2

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.
@@ -51401,7 +51401,7 @@ function insertStyle(css) {
51401
51401
 
51402
51402
  insertStyle("@import \"https://fonts.googleapis.com/css?family=Roboto\";\n:root {\n --theme-background-color: rgb(0 0 0 / 70%);\n --theme-text-color: rgb(255 255 255 / 100%);\n --theme-foreground-color: rgb(201 201 201 / 100%);\n --theme-hover-color: rgb(255 255 255 / 100%);\n}\n\n.gcore-skin-bg-color {\n background-color: var(--theme-background-color) !important;\n}\n\n.gcore-skin-text-color {\n color: var(--theme-text-color) !important;\n}\n\n.gcore-skin-text-color svg {\n fill: var(--theme-text-color) !important;\n}\n\n.gcore-skin-text-color svg path {\n fill: var(--theme-text-color) !important;\n}\n\n.gcore-skin-border-textarea-color {\n border-color: var(--theme-text-color) !important;\n}\n\n.gcore-skin-button-color {\n color: var(--theme-foreground-color) !important;\n}\n.gcore-skin-button-color svg {\n fill: var(--theme-foreground-color) !important;\n}\n.gcore-skin-button-color svg path {\n fill: var(--theme-foreground-color) !important;\n}\n.gcore-skin-button-color svg path.icon-hover {\n fill: var(--theme-foreground-color) !important;\n}\n.gcore-skin-button-color[data-fullscreen] svg {\n stroke: var(--theme-foreground-color) !important;\n}\n.gcore-skin-button-color[data-fullscreen] svg path {\n stroke: var(--theme-foreground-color) !important;\n}\n\n.gcore-skin-main-color {\n background-color: var(--theme-foreground-color);\n}\n\n.gcore-skin-border-color {\n border-color: var(--theme-foreground-color) !important;\n}\n\n.gcore-skin-button-color:hover {\n color: var(--theme-hover-color) !important;\n}\n\n.gcore-skin-button-color:hover svg {\n fill: var(--theme-hover-color) !important;\n}\n\n.gcore-skin-button-color:hover svg path {\n fill: var(--theme-hover-color) !important;\n}\n\n.gcore-skin-border-color:hover {\n border-color: var(--theme-hover-color) !important;\n}\n\n.gcore-skin-button-with-bg-color:hover svg path.icon-hover {\n fill: var(--theme-hover-color) !important;\n}\n\n.gcore-skin-active {\n color: var(--theme-hover-color) !important;\n}\n\n.gcore-skin-active svg {\n fill: var(--theme-hover-color) !important;\n}\n\n.gcore-skin-active svg path {\n fill: var(--theme-hover-color) !important;\n}\n\n* {\n -webkit-tap-highlight-color: transparent;\n -webkit-touch-callout: none;\n user-select: none;\n}\n\n.player-poster {\n background-size: contain !important;\n}\n\n.spinner-three-bounce > .gcore-skin-main-color {\n box-shadow: 4px 4px 9px 1px rgba(36, 61, 81, 0.51);\n}\n\n.gplayer-lite-btn {\n cursor: pointer;\n border: none;\n margin: 0;\n padding: 0;\n width: auto;\n overflow: visible;\n background: transparent;\n /* inherit font & color from ancestor */\n color: inherit;\n font: inherit;\n /* Normalize `line-height`. Cannot be changed from `normal` in Firefox 4+. */\n line-height: normal;\n /* Corrects font smoothing for webkit */\n -webkit-font-smoothing: inherit;\n -moz-osx-font-smoothing: inherit;\n /* Corrects inability to style clickable `input` types in iOS */\n appearance: none;\n /* Remove excess padding and border in Firefox 4+ */\n}\n.gplayer-lite-btn::-moz-focus-inner {\n border: 0;\n padding: 0;\n}");
51403
51403
 
51404
- const pluginHtml$4 = "<button class='gcore-skin-button-color media-control-dd' id=\"gplayer-audiotracks-button\" aria-haspopup=\"menu\" aria-expanded=\"false\">\n <span class=\"media-control-dd__text\" id=\"gplayer-audiotracks-button-text\"><%= title %></span>\n <span class=\"media-control-dd__arrow\"><%= icon %></span>\n</button>\n<ul class=\"gcore-skin-bg-color menu media-control-dd__popup\" id=\"gplayer-audiotracks-menu\" role=\"menu\">\n <% for (const track of tracks) { %>\n <li>\n <a href=\"#\" class=\"gcore-skin-text-color\" data-item=\"<%= track.id %>\" role=\"menuitemradio\" aria-checked=\"<%= track.id === current %>\">\n <%= track.label %>\n </a>\n </li>\n <% }; %>\n</ul>\n";
51404
+ const pluginHtml$4 = "<button class='gcore-skin-button-color media-control-dd' id=\"gplayer-audiotracks-button\" aria-haspopup=\"menu\" aria-expanded=\"false\">\n <span class=\"media-control-dd__text\" id=\"gplayer-audiotracks-button-text\"><%= title %></span>\n <span class=\"media-control-dd__arrow\"><%= icon %></span>\n</button>\n<ul class=\"gcore-skin-bg-color menu media-control-dd__popup\" id=\"gplayer-audiotracks-menu\" role=\"menu\">\n <% for (const track of tracks) { %>\n <li>\n <a href=\"#\" class=\"gcore-skin-text-color\" data-item=\"<%= track.id %>\" role=\"menuitemradio\" aria-checked=\"<%= track.id === current %>\">\n <%= track.label || track.language %>\n </a>\n </li>\n <% }; %>\n</ul>\n";
51405
51405
 
51406
51406
  const audioArrow = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg width=\"9px\" height=\"6px\" viewBox=\"0 0 9 6\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <!-- Generator: Sketch 49 (51002) - http://www.bohemiancoding.com/sketch -->\n <title>quality-arrow</title>\n <desc>Created with Sketch.</desc>\n <defs></defs>\n <g id=\"quality-arrow\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n <path\n d=\"M5.07079194,5.78553848 C4.91457318,5.94277844 4.70551573,6.00941824 4.50028717,5.99893557 C4.2950586,6.00941824 4.08676693,5.94277844 3.92978239,5.78553848 L0.221118462,1.2997069 C-0.0737061539,1.00469478 -0.0737061539,0.526236029 0.221118462,0.231972666 C0.515177299,-0.0630394586 1.23500883,0.00734414472 1.64852907,0.00734414472 L7.77475484,0.00734414472 C8.21201421,0.00734414472 8.48539703,-0.0630394586 8.77945587,0.231972666 C9.07351471,0.526236029 9.07351471,1.00469478 8.77945587,1.2997069 L5.07079194,5.78553848 Z\"\n fill=\"#FFFFFE\"></path>\n </g>\n</svg>\n";
51407
51407
 
@@ -53055,7 +53055,6 @@ function mergeElements(a, b) {
53055
53055
  }
53056
53056
 
53057
53057
  const VERSION$6 = '2.22.4';
53058
- // const T = 'plugins.audiotracks'
53059
53058
  /**
53060
53059
  * `PLUGIN` that makes possible to switch audio tracks via the media control UI.
53061
53060
  * @public
@@ -53070,6 +53069,7 @@ class AudioTracks extends UICorePlugin {
53070
53069
  currentTrack = null;
53071
53070
  open = false;
53072
53071
  tracks = [];
53072
+ autoUpdateTimerId = null;
53073
53073
  /**
53074
53074
  * @internal
53075
53075
  */
@@ -53130,19 +53130,18 @@ class AudioTracks extends UICorePlugin {
53130
53130
  onActiveContainerChanged() {
53131
53131
  this.currentTrack = null;
53132
53132
  this.listenTo(this.core.activeContainer, Events$1.CONTAINER_AUDIO_AVAILABLE, (tracks) => {
53133
+ const currentTrackId = this.core.activeContainer.currentAudioTrack?.id ??
53134
+ this.core.activePlayback?.currentAudioTrack?.id;
53133
53135
  this.currentTrack =
53134
- tracks.find((track) => track.kind === 'main') ?? null; // TODO test
53136
+ tracks.find((track) => track.id === currentTrackId) ??
53137
+ tracks.find((track) => track.kind === 'main') ??
53138
+ tracks[0] ??
53139
+ null;
53135
53140
  this.tracks = tracks;
53136
53141
  this.render();
53137
53142
  this.mount();
53138
53143
  });
53139
- this.listenTo(this.core.activeContainer, Events$1.CONTAINER_AUDIO_CHANGED, (track) => {
53140
- this.currentTrack = track;
53141
- this.highlightCurrentTrack();
53142
- this.buttonElement().removeClass('changing');
53143
- this.updateText();
53144
- });
53145
- // TODO test
53144
+ this.bindContainerAudioChanged();
53146
53145
  this.listenTo(this.core.activeContainer, Events$1.CONTAINER_CLICK, () => {
53147
53146
  this.hideMenu();
53148
53147
  });
@@ -53150,6 +53149,21 @@ class AudioTracks extends UICorePlugin {
53150
53149
  this.clickaway(null);
53151
53150
  });
53152
53151
  }
53152
+ bindContainerAudioChanged() {
53153
+ this.listenTo(this.core.activeContainer, Events$1.CONTAINER_AUDIO_CHANGED, (track) => {
53154
+ this.setCurrentTrack(track);
53155
+ });
53156
+ }
53157
+ setCurrentTrack(track) {
53158
+ if (this.autoUpdateTimerId) {
53159
+ clearTimeout(this.autoUpdateTimerId);
53160
+ this.autoUpdateTimerId = null;
53161
+ }
53162
+ this.currentTrack = track;
53163
+ this.highlightCurrentTrack();
53164
+ this.buttonElement().removeClass('changing');
53165
+ this.updateText();
53166
+ }
53153
53167
  shouldRender() {
53154
53168
  // Render is called from the parent class constructor so tracks aren't available
53155
53169
  // Only care if we have at least 2 to choose from
@@ -53182,7 +53196,7 @@ class AudioTracks extends UICorePlugin {
53182
53196
  selectAudioTrack(id) {
53183
53197
  this.startTrackSwitching();
53184
53198
  this.core.activeContainer.switchAudioTrack(id);
53185
- this.updateText();
53199
+ this.autoUpdateSelected(id);
53186
53200
  }
53187
53201
  hideMenu() {
53188
53202
  this.open = false;
@@ -53233,7 +53247,7 @@ class AudioTracks extends UICorePlugin {
53233
53247
  if (!this.currentTrack) {
53234
53248
  return;
53235
53249
  }
53236
- this.buttonElementText().text(this.currentTrack.label);
53250
+ this.buttonElementText().text(this.getTitle());
53237
53251
  }
53238
53252
  highlightCurrentTrack() {
53239
53253
  this.trackElement().removeClass('current');
@@ -53254,6 +53268,15 @@ class AudioTracks extends UICorePlugin {
53254
53268
  this.core.getPlugin('media_control')?.slot('audiotracks', this.$el);
53255
53269
  }
53256
53270
  }
53271
+ autoUpdateSelected(id) {
53272
+ if (this.autoUpdateTimerId) {
53273
+ clearTimeout(this.autoUpdateTimerId);
53274
+ }
53275
+ this.autoUpdateTimerId = setTimeout(() => {
53276
+ const track = this.tracks.find(t => t.id === id) ?? null;
53277
+ this.setCurrentTrack(track);
53278
+ }, 500);
53279
+ }
53257
53280
  clickaway = mediaControlClickaway(() => this.hideMenu());
53258
53281
  }
53259
53282
 
package/dist/index.js CHANGED
@@ -12922,7 +12922,7 @@ var PlaybackEvents;
12922
12922
  // https://github.com/clappr/clappr/blob/8752995ea439321ac7ca3cd35e8c64de7a3c3d17/LICENSE
12923
12923
  const AUTO$1 = -1;
12924
12924
  const { now: now$2 } = Utils;
12925
- const T$f = 'playback.dash';
12925
+ const T$g = 'playback.dash';
12926
12926
  class DashPlayback extends BasePlayback {
12927
12927
  _levels = [];
12928
12928
  _currentLevel = AUTO$1;
@@ -13199,7 +13199,7 @@ class DashPlayback extends BasePlayback {
13199
13199
  this.trigger(Events$1.PLAYBACK_SETTINGSUPDATE);
13200
13200
  }
13201
13201
  _onPlaybackError = (event) => {
13202
- trace(`${T$f} _onPlaybackError`, { type: event.type, code: event.error.code, message: event.error.message });
13202
+ trace(`${T$g} _onPlaybackError`, { type: event.type, code: event.error.code, message: event.error.message });
13203
13203
  };
13204
13204
  _onDASHJSSError = (event) => {
13205
13205
  this._stopTimeUpdateTimer();
@@ -50141,7 +50141,7 @@ const { now } = Utils;
50141
50141
  const AUTO = -1;
50142
50142
  const DEFAULT_RECOVER_ATTEMPTS = 16;
50143
50143
  Events$1.register('PLAYBACK_FRAGMENT_PARSING_METADATA');
50144
- const T$e = 'playback.hls';
50144
+ const T$f = 'playback.hls';
50145
50145
  class HlsPlayback extends BasePlayback {
50146
50146
  _currentFragment = null;
50147
50147
  _currentLevel = null;
@@ -50473,7 +50473,7 @@ class HlsPlayback extends BasePlayback {
50473
50473
  }
50474
50474
  else {
50475
50475
  Log.error('hlsjs: failed to recover', { evt, data });
50476
- trace(`${T$e} _recover failed to recover`, {
50476
+ trace(`${T$f} _recover failed to recover`, {
50477
50477
  type: data.type,
50478
50478
  details: data.details,
50479
50479
  });
@@ -50560,7 +50560,7 @@ class HlsPlayback extends BasePlayback {
50560
50560
  this.trigger(Events$1.PLAYBACK_SETTINGSUPDATE);
50561
50561
  }
50562
50562
  _onHLSJSError(evt, data) {
50563
- trace(`${T$e} _onHLSJSError`, {
50563
+ trace(`${T$f} _onHLSJSError`, {
50564
50564
  fatal: data.fatal,
50565
50565
  type: data.type,
50566
50566
  details: data.details,
@@ -50608,7 +50608,7 @@ class HlsPlayback extends BasePlayback {
50608
50608
  evt,
50609
50609
  data,
50610
50610
  });
50611
- trace(`${T$e} _onHLSJSError trying to recover from network error`, {
50611
+ trace(`${T$f} _onHLSJSError trying to recover from network error`, {
50612
50612
  details: data.details,
50613
50613
  });
50614
50614
  error.level = PlayerError.Levels.WARN;
@@ -50621,7 +50621,7 @@ class HlsPlayback extends BasePlayback {
50621
50621
  evt,
50622
50622
  data,
50623
50623
  });
50624
- trace(`${T$e} _onHLSJSError trying to recover from media error`, {
50624
+ trace(`${T$f} _onHLSJSError trying to recover from media error`, {
50625
50625
  details: data.details,
50626
50626
  });
50627
50627
  error.level = PlayerError.Levels.WARN;
@@ -50651,7 +50651,7 @@ class HlsPlayback extends BasePlayback {
50651
50651
  return;
50652
50652
  }
50653
50653
  Log.warn('hlsjs: non-fatal error occurred', { evt, data });
50654
- trace(`${T$e} _onHLSJSError non-fatal error occurred`, {
50654
+ trace(`${T$f} _onHLSJSError non-fatal error occurred`, {
50655
50655
  type: data.type,
50656
50656
  details: data.details,
50657
50657
  });
@@ -50984,7 +50984,7 @@ class HlsPlayback extends BasePlayback {
50984
50984
  this.trigger(Events$1.PLAYBACK_AUDIO_AVAILABLE, data.audioTracks.map(toClapprTrack));
50985
50985
  }
50986
50986
  _onAudioTrackSwitched(_, data) {
50987
- trace(`${T$e} onAudioTrackSwitched`);
50987
+ trace(`${T$f} onAudioTrackSwitched`);
50988
50988
  // @ts-ignore
50989
50989
  const track = this._hls.audioTracks[data.id];
50990
50990
  this.trigger(Events$1.PLAYBACK_AUDIO_CHANGED, toClapprTrack(track));
@@ -51032,7 +51032,7 @@ function toClapprTrack(t) {
51032
51032
  };
51033
51033
  }
51034
51034
 
51035
- const T$d = 'playback.html5_video';
51035
+ const T$e = 'playback.html5_video';
51036
51036
  const STALL_TIMEOUT = 15000;
51037
51037
  class HTML5Video extends BasePlayback {
51038
51038
  stallTimerId = null;
@@ -51133,7 +51133,7 @@ class HTML5Video extends BasePlayback {
51133
51133
  switchAudioTrack(id) {
51134
51134
  const tracks = this.el.audioTracks;
51135
51135
  const supported = !!tracks;
51136
- trace(`${T$d} switchAudioTrack`, {
51136
+ trace(`${T$e} switchAudioTrack`, {
51137
51137
  supported,
51138
51138
  });
51139
51139
  if (supported) {
@@ -51152,7 +51152,7 @@ function registerPlaybacks() {
51152
51152
  Loader.registerPlayback(DashPlayback);
51153
51153
  }
51154
51154
 
51155
- const T$c = 'gplayer';
51155
+ const T$d = 'gplayer';
51156
51156
  const DEFAULT_OPTIONS = {
51157
51157
  autoPlay: false,
51158
51158
  debug: 'none',
@@ -51499,7 +51499,7 @@ class Player {
51499
51499
  }
51500
51500
  }
51501
51501
  triggerAutoPlay() {
51502
- trace(`${T$c} triggerAutoPlay`);
51502
+ trace(`${T$d} triggerAutoPlay`);
51503
51503
  setTimeout(() => {
51504
51504
  this.player?.play({
51505
51505
  autoPlay: true,
@@ -51517,7 +51517,7 @@ class Player {
51517
51517
  // TODO test
51518
51518
  events = {
51519
51519
  onReady: () => {
51520
- trace(`${T$c} onReady`, {
51520
+ trace(`${T$d} onReady`, {
51521
51521
  ready: this.ready,
51522
51522
  });
51523
51523
  if (this.ready) {
@@ -51551,7 +51551,7 @@ class Player {
51551
51551
  buildCoreOptions(rootNode) {
51552
51552
  const sources = this.buildMediaSourcesList();
51553
51553
  const source = sources[0];
51554
- trace(`${T$c} buildCoreOptions`, {
51554
+ trace(`${T$d} buildCoreOptions`, {
51555
51555
  source,
51556
51556
  sources,
51557
51557
  });
@@ -51628,7 +51628,7 @@ class Player {
51628
51628
  }
51629
51629
  }
51630
51630
 
51631
- var version$1 = "2.30.1";
51631
+ var version$1 = "2.30.2";
51632
51632
 
51633
51633
  var packages = {
51634
51634
  "node_modules/@clappr/core": {
@@ -51652,7 +51652,7 @@ function version() {
51652
51652
  };
51653
51653
  }
51654
51654
 
51655
- const pluginHtml$6 = "<button class='gcore-skin-button-color media-control-dd' id=\"gplayer-audiotracks-button\" aria-haspopup=\"menu\" aria-expanded=\"false\">\n <span class=\"media-control-dd__text\" id=\"gplayer-audiotracks-button-text\"><%= title %></span>\n <span class=\"media-control-dd__arrow\"><%= icon %></span>\n</button>\n<ul class=\"gcore-skin-bg-color menu media-control-dd__popup\" id=\"gplayer-audiotracks-menu\" role=\"menu\">\n <% for (const track of tracks) { %>\n <li>\n <a href=\"#\" class=\"gcore-skin-text-color\" data-item=\"<%= track.id %>\" role=\"menuitemradio\" aria-checked=\"<%= track.id === current %>\">\n <%= track.label %>\n </a>\n </li>\n <% }; %>\n</ul>\n";
51655
+ const pluginHtml$6 = "<button class='gcore-skin-button-color media-control-dd' id=\"gplayer-audiotracks-button\" aria-haspopup=\"menu\" aria-expanded=\"false\">\n <span class=\"media-control-dd__text\" id=\"gplayer-audiotracks-button-text\"><%= title %></span>\n <span class=\"media-control-dd__arrow\"><%= icon %></span>\n</button>\n<ul class=\"gcore-skin-bg-color menu media-control-dd__popup\" id=\"gplayer-audiotracks-menu\" role=\"menu\">\n <% for (const track of tracks) { %>\n <li>\n <a href=\"#\" class=\"gcore-skin-text-color\" data-item=\"<%= track.id %>\" role=\"menuitemradio\" aria-checked=\"<%= track.id === current %>\">\n <%= track.label || track.language %>\n </a>\n </li>\n <% }; %>\n</ul>\n";
51656
51656
 
51657
51657
  const audioArrow = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<svg width=\"9px\" height=\"6px\" viewBox=\"0 0 9 6\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\"\n xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <!-- Generator: Sketch 49 (51002) - http://www.bohemiancoding.com/sketch -->\n <title>quality-arrow</title>\n <desc>Created with Sketch.</desc>\n <defs></defs>\n <g id=\"quality-arrow\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n <path\n d=\"M5.07079194,5.78553848 C4.91457318,5.94277844 4.70551573,6.00941824 4.50028717,5.99893557 C4.2950586,6.00941824 4.08676693,5.94277844 3.92978239,5.78553848 L0.221118462,1.2997069 C-0.0737061539,1.00469478 -0.0737061539,0.526236029 0.221118462,0.231972666 C0.515177299,-0.0630394586 1.23500883,0.00734414472 1.64852907,0.00734414472 L7.77475484,0.00734414472 C8.21201421,0.00734414472 8.48539703,-0.0630394586 8.77945587,0.231972666 C9.07351471,0.526236029 9.07351471,1.00469478 8.77945587,1.2997069 L5.07079194,5.78553848 Z\"\n fill=\"#FFFFFE\"></path>\n </g>\n</svg>\n";
51658
51658
 
@@ -52061,7 +52061,7 @@ const INITIAL_SETTINGS = {
52061
52061
  default: [],
52062
52062
  seekEnabled: false,
52063
52063
  };
52064
- const T$b = 'plugins.media_control';
52064
+ const T$c = 'plugins.media_control';
52065
52065
  /**
52066
52066
  * Extended events for the {@link MediaControl} plugin
52067
52067
  * @public
@@ -52354,7 +52354,7 @@ class MediaControl extends UICorePlugin {
52354
52354
  * Reenables the plugin disabled earlier with the {@link MediaControl.disable} method
52355
52355
  */
52356
52356
  enable() {
52357
- trace(`${T$b} enable`, {
52357
+ trace(`${T$c} enable`, {
52358
52358
  chromeless: this.options.chromeless,
52359
52359
  userDisabled: this.userDisabled,
52360
52360
  });
@@ -52511,7 +52511,7 @@ class MediaControl extends UICorePlugin {
52511
52511
  this.$el.removeClass('w370');
52512
52512
  this.$el.removeClass('w270');
52513
52513
  this.verticalVolume = false;
52514
- trace(`${T$b} playerResize`, {
52514
+ trace(`${T$c} playerResize`, {
52515
52515
  size,
52516
52516
  width: this.container.$el.width(),
52517
52517
  height: this.container.$el.height(),
@@ -53309,7 +53309,7 @@ function mergeElements(a, b) {
53309
53309
  }
53310
53310
 
53311
53311
  const VERSION$7 = '2.22.4';
53312
- // const T = 'plugins.audiotracks'
53312
+ const T$b = 'plugins.audiotracks';
53313
53313
  /**
53314
53314
  * `PLUGIN` that makes possible to switch audio tracks via the media control UI.
53315
53315
  * @public
@@ -53324,6 +53324,7 @@ class AudioTracks extends UICorePlugin {
53324
53324
  currentTrack = null;
53325
53325
  open = false;
53326
53326
  tracks = [];
53327
+ autoUpdateTimerId = null;
53327
53328
  /**
53328
53329
  * @internal
53329
53330
  */
@@ -53384,19 +53385,21 @@ class AudioTracks extends UICorePlugin {
53384
53385
  onActiveContainerChanged() {
53385
53386
  this.currentTrack = null;
53386
53387
  this.listenTo(this.core.activeContainer, Events$1.CONTAINER_AUDIO_AVAILABLE, (tracks) => {
53388
+ trace(`${T$b} on Events.CONTAINER_AUDIO_AVAILABLE`, {
53389
+ tracks,
53390
+ });
53391
+ const currentTrackId = this.core.activeContainer.currentAudioTrack?.id ??
53392
+ this.core.activePlayback?.currentAudioTrack?.id;
53387
53393
  this.currentTrack =
53388
- tracks.find((track) => track.kind === 'main') ?? null; // TODO test
53394
+ tracks.find((track) => track.id === currentTrackId) ??
53395
+ tracks.find((track) => track.kind === 'main') ??
53396
+ tracks[0] ??
53397
+ null;
53389
53398
  this.tracks = tracks;
53390
53399
  this.render();
53391
53400
  this.mount();
53392
53401
  });
53393
- this.listenTo(this.core.activeContainer, Events$1.CONTAINER_AUDIO_CHANGED, (track) => {
53394
- this.currentTrack = track;
53395
- this.highlightCurrentTrack();
53396
- this.buttonElement().removeClass('changing');
53397
- this.updateText();
53398
- });
53399
- // TODO test
53402
+ this.bindContainerAudioChanged();
53400
53403
  this.listenTo(this.core.activeContainer, Events$1.CONTAINER_CLICK, () => {
53401
53404
  this.hideMenu();
53402
53405
  });
@@ -53404,6 +53407,24 @@ class AudioTracks extends UICorePlugin {
53404
53407
  this.clickaway(null);
53405
53408
  });
53406
53409
  }
53410
+ bindContainerAudioChanged() {
53411
+ this.listenTo(this.core.activeContainer, Events$1.CONTAINER_AUDIO_CHANGED, (track) => {
53412
+ trace(`${T$b} on Events.CONTAINER_AUDIO_CHANGED`, {
53413
+ track,
53414
+ });
53415
+ this.setCurrentTrack(track);
53416
+ });
53417
+ }
53418
+ setCurrentTrack(track) {
53419
+ if (this.autoUpdateTimerId) {
53420
+ clearTimeout(this.autoUpdateTimerId);
53421
+ this.autoUpdateTimerId = null;
53422
+ }
53423
+ this.currentTrack = track;
53424
+ this.highlightCurrentTrack();
53425
+ this.buttonElement().removeClass('changing');
53426
+ this.updateText();
53427
+ }
53407
53428
  shouldRender() {
53408
53429
  // Render is called from the parent class constructor so tracks aren't available
53409
53430
  // Only care if we have at least 2 to choose from
@@ -53436,7 +53457,7 @@ class AudioTracks extends UICorePlugin {
53436
53457
  selectAudioTrack(id) {
53437
53458
  this.startTrackSwitching();
53438
53459
  this.core.activeContainer.switchAudioTrack(id);
53439
- this.updateText();
53460
+ this.autoUpdateSelected(id);
53440
53461
  }
53441
53462
  hideMenu() {
53442
53463
  this.open = false;
@@ -53487,7 +53508,7 @@ class AudioTracks extends UICorePlugin {
53487
53508
  if (!this.currentTrack) {
53488
53509
  return;
53489
53510
  }
53490
- this.buttonElementText().text(this.currentTrack.label);
53511
+ this.buttonElementText().text(this.getTitle());
53491
53512
  }
53492
53513
  highlightCurrentTrack() {
53493
53514
  this.trackElement().removeClass('current');
@@ -53508,6 +53529,15 @@ class AudioTracks extends UICorePlugin {
53508
53529
  this.core.getPlugin('media_control')?.slot('audiotracks', this.$el);
53509
53530
  }
53510
53531
  }
53532
+ autoUpdateSelected(id) {
53533
+ if (this.autoUpdateTimerId) {
53534
+ clearTimeout(this.autoUpdateTimerId);
53535
+ }
53536
+ this.autoUpdateTimerId = setTimeout(() => {
53537
+ const track = this.tracks.find(t => t.id === id) ?? null;
53538
+ this.setCurrentTrack(track);
53539
+ }, 500);
53540
+ }
53511
53541
  clickaway = mediaControlClickaway(() => this.hideMenu());
53512
53542
  }
53513
53543
 
@@ -13,6 +13,7 @@ export declare class AudioTracks extends UICorePlugin {
13
13
  private currentTrack;
14
14
  private open;
15
15
  private tracks;
16
+ private autoUpdateTimerId;
16
17
  /**
17
18
  * @internal
18
19
  */
@@ -47,6 +48,8 @@ export declare class AudioTracks extends UICorePlugin {
47
48
  bindEvents(): void;
48
49
  private onCoreReady;
49
50
  private onActiveContainerChanged;
51
+ private bindContainerAudioChanged;
52
+ private setCurrentTrack;
50
53
  private shouldRender;
51
54
  /**
52
55
  * @internal
@@ -65,6 +68,7 @@ export declare class AudioTracks extends UICorePlugin {
65
68
  private updateText;
66
69
  private highlightCurrentTrack;
67
70
  private mount;
71
+ private autoUpdateSelected;
68
72
  private clickaway;
69
73
  }
70
74
  //# sourceMappingURL=AudioTracks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AudioTracks.d.ts","sourceRoot":"","sources":["../../../src/plugins/audio-selector/AudioTracks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,YAAY,EAAY,MAAM,cAAc,CAAA;AAiB7D;;;;;;;;;GASG;AACH,qBAAa,WAAY,SAAQ,YAAY;IAC3C,OAAO,CAAC,YAAY,CAA0B;IAE9C,OAAO,CAAC,IAAI,CAAQ;IAEpB,OAAO,CAAC,MAAM,CAAmB;IAEjC;;OAEG;IACH,IAAI,IAAI,WAEP;IAED;;OAEG;IACH,IAAI,gBAAgB;;MAEnB;IAED;;OAEG;IACH,MAAM,KAAK,OAAO,WAEjB;IAED,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAuB;IAEvD;;OAEG;IACH,IAAa,UAAU;;MAItB;IAED;;OAEG;IACH,IAAa,MAAM;;;MAKlB;IAED;;OAEG;IACM,UAAU;IASnB,OAAO,CAAC,WAAW;IAoBnB,OAAO,CAAC,wBAAwB;IAgChC,OAAO,CAAC,YAAY;IAMpB;;OAEG;IACM,MAAM;IAgBf,OAAO,CAAC,aAAa;IAUrB,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,QAAQ;IAOhB,OAAO,CAAC,UAAU;IAkBlB,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,QAAQ;IAOhB,OAAO,CAAC,mBAAmB;IAI3B,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,qBAAqB;IAgB7B,OAAO,CAAC,KAAK;IAMb,OAAO,CAAC,SAAS,CAA+C;CACjE"}
1
+ {"version":3,"file":"AudioTracks.d.ts","sourceRoot":"","sources":["../../../src/plugins/audio-selector/AudioTracks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,YAAY,EAAY,MAAM,cAAc,CAAA;AAiB7D;;;;;;;;;GASG;AACH,qBAAa,WAAY,SAAQ,YAAY;IAC3C,OAAO,CAAC,YAAY,CAA0B;IAE9C,OAAO,CAAC,IAAI,CAAQ;IAEpB,OAAO,CAAC,MAAM,CAAmB;IAEjC,OAAO,CAAC,iBAAiB,CAA6C;IAEtE;;OAEG;IACH,IAAI,IAAI,WAEP;IAED;;OAEG;IACH,IAAI,gBAAgB;;MAEnB;IAED;;OAEG;IACH,MAAM,KAAK,OAAO,WAEjB;IAED,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAuB;IAEvD;;OAEG;IACH,IAAa,UAAU;;MAItB;IAED;;OAEG;IACH,IAAa,MAAM;;;MAKlB;IAED;;OAEG;IACM,UAAU;IASnB,OAAO,CAAC,WAAW;IAoBnB,OAAO,CAAC,wBAAwB;IA+BhC,OAAO,CAAC,yBAAyB;IAajC,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,YAAY;IAMpB;;OAEG;IACM,MAAM;IAgBf,OAAO,CAAC,aAAa;IAUrB,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,QAAQ;IAOhB,OAAO,CAAC,UAAU;IAkBlB,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,QAAQ;IAOhB,OAAO,CAAC,mBAAmB;IAI3B,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,qBAAqB;IAgB7B,OAAO,CAAC,KAAK;IAMb,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,SAAS,CAA+C;CACjE"}
@@ -1,13 +1,13 @@
1
1
  import { Events, UICorePlugin, template } from '@clappr/core';
2
2
  import assert from 'assert';
3
- // import { trace } from '@gcorevideo/utils'
3
+ import { trace } from '@gcorevideo/utils';
4
4
  import { CLAPPR_VERSION } from '../../build.js';
5
5
  import pluginHtml from '../../../assets/audio-tracks/template.ejs';
6
6
  import audioArrow from '../../../assets/icons/old/quality-arrow.svg';
7
7
  import { ExtendedEvents } from '../media-control/MediaControl.js';
8
8
  import { mediaControlClickaway } from '../../utils/clickaway.js';
9
9
  const VERSION = '2.22.4';
10
- // const T = 'plugins.audiotracks'
10
+ const T = 'plugins.audiotracks';
11
11
  /**
12
12
  * `PLUGIN` that makes possible to switch audio tracks via the media control UI.
13
13
  * @public
@@ -22,6 +22,7 @@ export class AudioTracks extends UICorePlugin {
22
22
  currentTrack = null;
23
23
  open = false;
24
24
  tracks = [];
25
+ autoUpdateTimerId = null;
25
26
  /**
26
27
  * @internal
27
28
  */
@@ -82,19 +83,21 @@ export class AudioTracks extends UICorePlugin {
82
83
  onActiveContainerChanged() {
83
84
  this.currentTrack = null;
84
85
  this.listenTo(this.core.activeContainer, Events.CONTAINER_AUDIO_AVAILABLE, (tracks) => {
86
+ trace(`${T} on Events.CONTAINER_AUDIO_AVAILABLE`, {
87
+ tracks,
88
+ });
89
+ const currentTrackId = this.core.activeContainer.currentAudioTrack?.id ??
90
+ this.core.activePlayback?.currentAudioTrack?.id;
85
91
  this.currentTrack =
86
- tracks.find((track) => track.kind === 'main') ?? null; // TODO test
92
+ tracks.find((track) => track.id === currentTrackId) ??
93
+ tracks.find((track) => track.kind === 'main') ??
94
+ tracks[0] ??
95
+ null;
87
96
  this.tracks = tracks;
88
97
  this.render();
89
98
  this.mount();
90
99
  });
91
- this.listenTo(this.core.activeContainer, Events.CONTAINER_AUDIO_CHANGED, (track) => {
92
- this.currentTrack = track;
93
- this.highlightCurrentTrack();
94
- this.buttonElement().removeClass('changing');
95
- this.updateText();
96
- });
97
- // TODO test
100
+ this.bindContainerAudioChanged();
98
101
  this.listenTo(this.core.activeContainer, Events.CONTAINER_CLICK, () => {
99
102
  this.hideMenu();
100
103
  });
@@ -102,6 +105,24 @@ export class AudioTracks extends UICorePlugin {
102
105
  this.clickaway(null);
103
106
  });
104
107
  }
108
+ bindContainerAudioChanged() {
109
+ this.listenTo(this.core.activeContainer, Events.CONTAINER_AUDIO_CHANGED, (track) => {
110
+ trace(`${T} on Events.CONTAINER_AUDIO_CHANGED`, {
111
+ track,
112
+ });
113
+ this.setCurrentTrack(track);
114
+ });
115
+ }
116
+ setCurrentTrack(track) {
117
+ if (this.autoUpdateTimerId) {
118
+ clearTimeout(this.autoUpdateTimerId);
119
+ this.autoUpdateTimerId = null;
120
+ }
121
+ this.currentTrack = track;
122
+ this.highlightCurrentTrack();
123
+ this.buttonElement().removeClass('changing');
124
+ this.updateText();
125
+ }
105
126
  shouldRender() {
106
127
  // Render is called from the parent class constructor so tracks aren't available
107
128
  // Only care if we have at least 2 to choose from
@@ -134,7 +155,7 @@ export class AudioTracks extends UICorePlugin {
134
155
  selectAudioTrack(id) {
135
156
  this.startTrackSwitching();
136
157
  this.core.activeContainer.switchAudioTrack(id);
137
- this.updateText();
158
+ this.autoUpdateSelected(id);
138
159
  }
139
160
  hideMenu() {
140
161
  this.open = false;
@@ -185,7 +206,7 @@ export class AudioTracks extends UICorePlugin {
185
206
  if (!this.currentTrack) {
186
207
  return;
187
208
  }
188
- this.buttonElementText().text(this.currentTrack.label);
209
+ this.buttonElementText().text(this.getTitle());
189
210
  }
190
211
  highlightCurrentTrack() {
191
212
  this.trackElement().removeClass('current');
@@ -206,5 +227,14 @@ export class AudioTracks extends UICorePlugin {
206
227
  this.core.getPlugin('media_control')?.slot('audiotracks', this.$el);
207
228
  }
208
229
  }
230
+ autoUpdateSelected(id) {
231
+ if (this.autoUpdateTimerId) {
232
+ clearTimeout(this.autoUpdateTimerId);
233
+ }
234
+ this.autoUpdateTimerId = setTimeout(() => {
235
+ const track = this.tracks.find(t => t.id === id) ?? null;
236
+ this.setCurrentTrack(track);
237
+ }, 500);
238
+ }
209
239
  clickaway = mediaControlClickaway(() => this.hideMenu());
210
240
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gcorevideo/player",
3
- "version": "2.30.1",
3
+ "version": "2.30.2",
4
4
  "description": "Gcore JavaScript video player",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -1,7 +1,7 @@
1
1
  import { Events, UICorePlugin, template } from '@clappr/core'
2
2
  import { AudioTrack } from '@clappr/core/types/base/playback/playback.js'
3
3
  import assert from 'assert'
4
- // import { trace } from '@gcorevideo/utils'
4
+ import { trace } from '@gcorevideo/utils'
5
5
 
6
6
  import { CLAPPR_VERSION } from '../../build.js'
7
7
 
@@ -13,7 +13,7 @@ import { mediaControlClickaway } from '../../utils/clickaway.js'
13
13
 
14
14
  const VERSION: string = '2.22.4'
15
15
 
16
- // const T = 'plugins.audiotracks'
16
+ const T = 'plugins.audiotracks'
17
17
 
18
18
  /**
19
19
  * `PLUGIN` that makes possible to switch audio tracks via the media control UI.
@@ -32,6 +32,8 @@ export class AudioTracks extends UICorePlugin {
32
32
 
33
33
  private tracks: AudioTrack[] = []
34
34
 
35
+ private autoUpdateTimerId: ReturnType<typeof setTimeout> | null = null
36
+
35
37
  /**
36
38
  * @internal
37
39
  */
@@ -112,24 +114,23 @@ export class AudioTracks extends UICorePlugin {
112
114
  this.core.activeContainer,
113
115
  Events.CONTAINER_AUDIO_AVAILABLE,
114
116
  (tracks: AudioTrack[]) => {
117
+ trace(`${T} on Events.CONTAINER_AUDIO_AVAILABLE`, {
118
+ tracks,
119
+ })
120
+ const currentTrackId =
121
+ this.core.activeContainer.currentAudioTrack?.id ??
122
+ this.core.activePlayback?.currentAudioTrack?.id
115
123
  this.currentTrack =
116
- tracks.find((track) => track.kind === 'main') ?? null // TODO test
124
+ tracks.find((track) => track.id === currentTrackId) ??
125
+ tracks.find((track) => track.kind === 'main') ??
126
+ tracks[0] ??
127
+ null
117
128
  this.tracks = tracks
118
129
  this.render()
119
130
  this.mount()
120
131
  },
121
132
  )
122
- this.listenTo(
123
- this.core.activeContainer,
124
- Events.CONTAINER_AUDIO_CHANGED,
125
- (track: AudioTrack) => {
126
- this.currentTrack = track
127
- this.highlightCurrentTrack()
128
- this.buttonElement().removeClass('changing')
129
- this.updateText()
130
- },
131
- )
132
- // TODO test
133
+ this.bindContainerAudioChanged()
133
134
  this.listenTo(this.core.activeContainer, Events.CONTAINER_CLICK, () => {
134
135
  this.hideMenu()
135
136
  })
@@ -138,6 +139,30 @@ export class AudioTracks extends UICorePlugin {
138
139
  })
139
140
  }
140
141
 
142
+ private bindContainerAudioChanged() {
143
+ this.listenTo(
144
+ this.core.activeContainer,
145
+ Events.CONTAINER_AUDIO_CHANGED,
146
+ (track: AudioTrack) => {
147
+ trace(`${T} on Events.CONTAINER_AUDIO_CHANGED`, {
148
+ track,
149
+ })
150
+ this.setCurrentTrack(track)
151
+ }
152
+ )
153
+ }
154
+
155
+ private setCurrentTrack(track: AudioTrack | null) {
156
+ if (this.autoUpdateTimerId) {
157
+ clearTimeout(this.autoUpdateTimerId)
158
+ this.autoUpdateTimerId = null
159
+ }
160
+ this.currentTrack = track
161
+ this.highlightCurrentTrack()
162
+ this.buttonElement().removeClass('changing')
163
+ this.updateText()
164
+ }
165
+
141
166
  private shouldRender() {
142
167
  // Render is called from the parent class constructor so tracks aren't available
143
168
  // Only care if we have at least 2 to choose from
@@ -176,7 +201,7 @@ export class AudioTracks extends UICorePlugin {
176
201
  private selectAudioTrack(id: string) {
177
202
  this.startTrackSwitching()
178
203
  this.core.activeContainer.switchAudioTrack(id)
179
- this.updateText()
204
+ this.autoUpdateSelected(id)
180
205
  }
181
206
 
182
207
  private hideMenu() {
@@ -241,7 +266,7 @@ export class AudioTracks extends UICorePlugin {
241
266
  if (!this.currentTrack) {
242
267
  return
243
268
  }
244
- this.buttonElementText().text(this.currentTrack.label)
269
+ this.buttonElementText().text(this.getTitle())
245
270
  }
246
271
 
247
272
  private highlightCurrentTrack() {
@@ -266,5 +291,15 @@ export class AudioTracks extends UICorePlugin {
266
291
  }
267
292
  }
268
293
 
294
+ private autoUpdateSelected(id: string) {
295
+ if (this.autoUpdateTimerId) {
296
+ clearTimeout(this.autoUpdateTimerId)
297
+ }
298
+ this.autoUpdateTimerId = setTimeout(() => {
299
+ const track = this.tracks.find(t => t.id === id) ?? null
300
+ this.setCurrentTrack(track)
301
+ }, 500)
302
+ }
303
+
269
304
  private clickaway = mediaControlClickaway(() => this.hideMenu())
270
305
  }