eb-player 2.0.7 → 2.0.9

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.
@@ -4,7 +4,7 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.EBPlayer = {}));
5
5
  })(this, (function (exports) { 'use strict';
6
6
 
7
- var __EB_PLAYER_VERSION__ = "2.0.7";
7
+ var __EB_PLAYER_VERSION__ = "2.0.9";
8
8
 
9
9
  /**
10
10
  * Finite State Machine for player playback state transitions.
@@ -4284,6 +4284,15 @@
4284
4284
  video.addEventListener('ended', () => {
4285
4285
  state.playbackState = 'ended';
4286
4286
  }, { signal });
4287
+ // Safety net: clear stale 'buffering' state when playback is clearly advancing.
4288
+ // In some edge cases (live stream segment boundaries), the browser fires 'waiting'
4289
+ // but never fires 'playing' even though video resumes from buffer. The timeupdate
4290
+ // event fires reliably while time advances, so we use it to recover.
4291
+ video.addEventListener('timeupdate', () => {
4292
+ if (state.playbackState === 'buffering' && !video.paused && video.readyState >= 3) {
4293
+ state.playbackState = 'playing';
4294
+ }
4295
+ }, { signal });
4287
4296
  }
4288
4297
  /**
4289
4298
  * Seek to a specific time. Default implementation sets video.currentTime.
@@ -5235,7 +5244,9 @@
5235
5244
  if (!hlsjsUrl) {
5236
5245
  throw new Error('HlsEngine: config.hlsjs URL is required');
5237
5246
  }
5238
- // Create token manager if a token URL is configured
5247
+ // Create token manager if a token URL is configured.
5248
+ // No initial fetchToken() here — updateUrlWithTokenParams() below handles it
5249
+ // and populates lastTokenResponse (used lazily by DRM licenseXhrSetup).
5239
5250
  if (config.token) {
5240
5251
  this.tokenManager = new CDNTokenManager({
5241
5252
  token: config.token,
@@ -5244,13 +5255,6 @@
5244
5255
  extraParamsCallback: (config.engineSettings.extraParamsCallback ?? config.extraParamsCallback),
5245
5256
  onCDNTokenError: config.engineSettings.onCDNTokenError
5246
5257
  });
5247
- // Fetch initial token
5248
- if (config.src) {
5249
- await this.tokenManager.fetchToken({ src: config.src });
5250
- }
5251
- // Guard: abort if detached during token fetch
5252
- if (this.detached)
5253
- return;
5254
5258
  }
5255
5259
  // console.info('HlsEngine: loading hls.js from', hlsjsUrl)
5256
5260
  const Hls = await loadScript(hlsjsUrl, 'Hls');
@@ -5333,7 +5337,6 @@
5333
5337
  // Create the driver (NEVER stored in state)
5334
5338
  const driver = new Hls(driverConfig);
5335
5339
  this.driver = driver;
5336
- this.resolveDriverReady();
5337
5340
  // Pitfall 4: apply discontinuity workaround BEFORE attachMedia/loadSource
5338
5341
  applyDiscontinuityWorkaround(driver, Hls.Events);
5339
5342
  // Wire retry handler
@@ -5356,8 +5359,27 @@
5356
5359
  }
5357
5360
  }
5358
5361
  driver.loadSource(src);
5362
+ // Resolve driverReady AFTER loadSource so consumers (P2P, snapshot handler)
5363
+ // don't start making token requests before the main engine's initial token
5364
+ // fetch completes and populates the cache.
5365
+ this.resolveDriverReady();
5359
5366
  // Register driver event handlers
5360
5367
  this.registerDriverEvents(Hls, state);
5368
+ // Pause/resume loading on video pause/play to stop manifest refreshes
5369
+ // (and thus CDN token requests) while the player is paused.
5370
+ // Only applies to live streams where hls.js continuously refreshes the manifest.
5371
+ const driverRef = driver;
5372
+ video.addEventListener('pause', () => {
5373
+ if (this.state?.isLive) {
5374
+ driverRef.stopLoad();
5375
+ }
5376
+ }, { signal });
5377
+ video.addEventListener('play', () => {
5378
+ if (this.state?.isLive) {
5379
+ // Defer startLoad to avoid re-entrancy (Pitfall 3)
5380
+ setTimeout(() => driverRef.startLoad(-1), 0);
5381
+ }
5382
+ }, { signal });
5361
5383
  // Start stall watchdog
5362
5384
  this.startWatchdog();
5363
5385
  }