stormcloud-video-player 0.8.15 → 0.8.16

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.
@@ -3607,7 +3607,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3607
3607
  _this.showAds = true;
3608
3608
  _this.resetGamNoFillCounter();
3609
3609
  if (_this.inAdBreak && _this.expectedAdBreakDurationMs != null && _this.adStopTimerId == null) {
3610
- _this.scheduleAdStopCountdown(_this.getRemainingAdMs());
3610
+ _this.scheduleAdStopAtBreakBoundary();
3611
3611
  if (_this.config.debugAdTiming) {
3612
3612
  console.log("[StormcloudVideoPlayer] Starting ad break timer on content_pause (first ad starting)");
3613
3613
  }
@@ -4262,12 +4262,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4262
4262
  if (marker.durationSeconds != null) {
4263
4263
  var newDurationMs = marker.durationSeconds * 1e3;
4264
4264
  if (this.expectedAdBreakDurationMs == null || newDurationMs > this.expectedAdBreakDurationMs) {
4265
- this.expectedAdBreakDurationMs = newDurationMs;
4266
- var elapsedMs = this.currentAdBreakStartWallClockMs != null ? Date.now() - this.currentAdBreakStartWallClockMs : 0;
4267
- var remainingMs = Math.max(0, newDurationMs - elapsedMs);
4268
- this.scheduleAdStopCountdown(remainingMs);
4265
+ this.setAdBreakDurationBoundary(newDurationMs);
4266
+ this.scheduleAdStopAtBreakBoundary();
4269
4267
  if (this.config.debugAdTiming) {
4270
- console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(newDurationMs, "ms, remaining: ").concat(remainingMs, "ms"));
4268
+ console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(newDurationMs, "ms, remaining: ").concat(this.getWallClockRemainingAdMs(), "ms"));
4271
4269
  }
4272
4270
  }
4273
4271
  }
@@ -4341,13 +4339,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4341
4339
  }
4342
4340
  if (marker.type === "progress" && this.inAdBreak) {
4343
4341
  if (marker.durationSeconds != null) {
4344
- this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
4345
- }
4346
- if (this.expectedAdBreakDurationMs != null && this.currentAdBreakStartWallClockMs != null) {
4347
- var elapsedMs1 = Date.now() - this.currentAdBreakStartWallClockMs;
4348
- var remainingMs1 = Math.max(0, this.expectedAdBreakDurationMs - elapsedMs1);
4349
- this.scheduleAdStopCountdown(remainingMs1);
4342
+ this.setAdBreakDurationBoundary(marker.durationSeconds * 1e3);
4350
4343
  }
4344
+ this.scheduleAdStopAtBreakBoundary();
4351
4345
  if (!this.adPlayer.isAdPlaying() && this.activeAdRequestToken === null && this.adRequestQueue.length > 0 && this.hasTimeToStartAnotherAd()) {
4352
4346
  this.tryNextAvailableAdWithRateLimit();
4353
4347
  }
@@ -4371,15 +4365,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4371
4365
  activeAdRequest: this.activeAdRequestToken !== null
4372
4366
  });
4373
4367
  }
4374
- if (adPlaying || remaining > 1e3 && hasQueuedAds) {
4375
- if (this.config.debugAdTiming) {
4376
- console.log("[StormcloudVideoPlayer] Ignoring premature SCTE-35 end marker - ads still active");
4377
- }
4378
- return;
4379
- }
4380
- this.inAdBreak = false;
4381
- this.expectedAdBreakDurationMs = void 0;
4382
- this.currentAdBreakStartWallClockMs = void 0;
4368
+ this.scteAdBreakEndWallClockMs = Date.now();
4383
4369
  this.clearAdStartTimer();
4384
4370
  this.clearAdStopTimer();
4385
4371
  if (adPlaying) {
@@ -4396,14 +4382,48 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4396
4382
  this.inAdBreak = true;
4397
4383
  this.activeScte35BreakKey = cueKey !== null && cueKey !== void 0 ? cueKey : this.pendingScte35CueKey;
4398
4384
  this.scheduledScte35BreakKey = void 0;
4399
- this.expectedAdBreakDurationMs = durationMs;
4400
- this.currentAdBreakStartWallClockMs = Date.now();
4385
+ this.currentAdBreakStartWallClockMs = this.resolveScteBreakStartWallClockMs(marker);
4386
+ this.setAdBreakDurationBoundary(durationMs);
4401
4387
  this.handleAdStart(marker);
4402
- if (this.expectedAdBreakDurationMs != null) {
4403
- this.scheduleAdStopCountdown(this.expectedAdBreakDurationMs);
4388
+ this.scheduleAdStopAtBreakBoundary();
4389
+ }
4390
+ },
4391
+ {
4392
+ key: "resolveScteBreakStartWallClockMs",
4393
+ value: function resolveScteBreakStartWallClockMs(marker) {
4394
+ var nowWallClockMs = Date.now();
4395
+ if (typeof marker.ptsSeconds !== "number") {
4396
+ return nowWallClockMs;
4397
+ }
4398
+ var nowMs = this.video.currentTime * 1e3;
4399
+ var estimatedCurrentPtsMs = nowMs - this.ptsDriftEmaMs;
4400
+ var deltaMs = marker.ptsSeconds * 1e3 - estimatedCurrentPtsMs;
4401
+ if (!Number.isFinite(deltaMs)) {
4402
+ return nowWallClockMs;
4403
+ }
4404
+ return nowWallClockMs + Math.floor(deltaMs);
4405
+ }
4406
+ },
4407
+ {
4408
+ key: "setAdBreakDurationBoundary",
4409
+ value: function setAdBreakDurationBoundary(durationMs) {
4410
+ this.expectedAdBreakDurationMs = durationMs;
4411
+ if (durationMs != null && this.currentAdBreakStartWallClockMs != null) {
4412
+ this.scteAdBreakEndWallClockMs = this.currentAdBreakStartWallClockMs + durationMs;
4413
+ } else {
4414
+ this.scteAdBreakEndWallClockMs = void 0;
4404
4415
  }
4405
4416
  }
4406
4417
  },
4418
+ {
4419
+ key: "scheduleAdStopAtBreakBoundary",
4420
+ value: function scheduleAdStopAtBreakBoundary() {
4421
+ if (this.expectedAdBreakDurationMs == null) {
4422
+ return;
4423
+ }
4424
+ this.scheduleAdStopCountdown(this.getWallClockRemainingAdMs());
4425
+ }
4426
+ },
4407
4427
  {
4408
4428
  key: "parseCueOutDuration",
4409
4429
  value: function parseCueOutDuration(value) {
@@ -6051,7 +6071,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6051
6071
  currentVolume = this.video.volume;
6052
6072
  this.adPlayer.updateOriginalMutedState(currentMuted, currentVolume);
6053
6073
  this.inAdBreak = true;
6054
- this.currentAdBreakStartWallClockMs = Date.now();
6055
6074
  this.adBreakPlayedDurationMs = 0;
6056
6075
  this.currentAdIndex = 0;
6057
6076
  this.totalAdsInBreak = 0;
@@ -6157,7 +6176,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6157
6176
  _state.sent();
6158
6177
  this.markAdStarted();
6159
6178
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6160
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
6179
+ this.scheduleAdStopAtBreakBoundary();
6161
6180
  }
6162
6181
  adVolume = currentMuted ? 0 : currentVolume;
6163
6182
  this.adPlayer.setAdVolume(adVolume);
@@ -6217,7 +6236,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6217
6236
  _state.sent();
6218
6237
  this.markAdStarted();
6219
6238
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6220
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
6239
+ this.scheduleAdStopAtBreakBoundary();
6221
6240
  }
6222
6241
  adVolume1 = currentMuted ? 0 : currentVolume;
6223
6242
  this.adPlayer.setAdVolume(adVolume1);
@@ -6290,7 +6309,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6290
6309
  _state.sent();
6291
6310
  this.markAdStarted();
6292
6311
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6293
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
6312
+ this.scheduleAdStopAtBreakBoundary();
6294
6313
  }
6295
6314
  adVolume2 = currentMuted ? 0 : currentVolume;
6296
6315
  this.adPlayer.setAdVolume(adVolume2);
@@ -6673,7 +6692,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6673
6692
  _state.sent();
6674
6693
  this.markAdStarted();
6675
6694
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6676
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
6695
+ this.scheduleAdStopAtBreakBoundary();
6677
6696
  }
6678
6697
  this.adPlayer.setAdVolume(this.getAdAudioVolume());
6679
6698
  this.consecutiveFailures = 0;
@@ -7201,19 +7220,15 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7201
7220
  {
7202
7221
  key: "ensureAdStoppedByTimer",
7203
7222
  value: function ensureAdStoppedByTimer() {
7204
- var _this_config_adBreakCheckIntervalMs, _this_expectedAdBreakDurationMs;
7223
+ var _this_config_adBreakCheckIntervalMs, _this_getAdBreakEndWallClockMs;
7205
7224
  if (!this.inAdBreak) return;
7206
7225
  this.adStopTimerId = void 0;
7207
7226
  var adPlaying = this.adPlayer.isAdPlaying();
7208
7227
  var checkIntervalMs = Math.max(250, Math.floor((_this_config_adBreakCheckIntervalMs = this.config.adBreakCheckIntervalMs) !== null && _this_config_adBreakCheckIntervalMs !== void 0 ? _this_config_adBreakCheckIntervalMs : 1e3));
7209
7228
  var maxExtensionMsConfig = this.config.maxAdBreakExtensionMs;
7210
7229
  var maxExtensionMs = typeof maxExtensionMsConfig === "number" && maxExtensionMsConfig > 0 ? maxExtensionMsConfig : 0;
7211
- var elapsedSinceStartMs = 0;
7212
- if (this.currentAdBreakStartWallClockMs != null) {
7213
- elapsedSinceStartMs = Date.now() - this.currentAdBreakStartWallClockMs;
7214
- }
7215
- var expectedDurationMs = (_this_expectedAdBreakDurationMs = this.expectedAdBreakDurationMs) !== null && _this_expectedAdBreakDurationMs !== void 0 ? _this_expectedAdBreakDurationMs : 0;
7216
- var overrunMs = Math.max(0, elapsedSinceStartMs - expectedDurationMs);
7230
+ var endWallClockMs = (_this_getAdBreakEndWallClockMs = this.getAdBreakEndWallClockMs()) !== null && _this_getAdBreakEndWallClockMs !== void 0 ? _this_getAdBreakEndWallClockMs : Date.now();
7231
+ var overrunMs = Math.max(0, Date.now() - endWallClockMs);
7217
7232
  var shouldExtendAdBreak = adPlaying && overrunMs < maxExtensionMs;
7218
7233
  if (shouldExtendAdBreak) {
7219
7234
  this.scheduleAdStopCountdown(checkIntervalMs);
@@ -7489,7 +7504,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7489
7504
  _state.sent();
7490
7505
  this.markAdStarted();
7491
7506
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
7492
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
7507
+ this.scheduleAdStopAtBreakBoundary();
7493
7508
  }
7494
7509
  this.adPlayer.setAdVolume(this.getAdAudioVolume());
7495
7510
  this.consecutiveFailures = 0;
@@ -7541,7 +7556,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7541
7556
  _state.sent();
7542
7557
  this.markAdStarted();
7543
7558
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
7544
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
7559
+ this.scheduleAdStopAtBreakBoundary();
7545
7560
  }
7546
7561
  this.adPlayer.setAdVolume(this.getAdAudioVolume());
7547
7562
  return [
@@ -7687,6 +7702,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7687
7702
  this.scheduledScte35BreakKey = void 0;
7688
7703
  this.expectedAdBreakDurationMs = void 0;
7689
7704
  this.currentAdBreakStartWallClockMs = void 0;
7705
+ this.scteAdBreakEndWallClockMs = void 0;
7690
7706
  this.clearAdStartTimer();
7691
7707
  this.clearAdStopTimer();
7692
7708
  this.adPodQueue = [];
@@ -7874,11 +7890,23 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7874
7890
  {
7875
7891
  key: "getWallClockRemainingAdMs",
7876
7892
  value: function getWallClockRemainingAdMs() {
7893
+ var endWallClockMs = this.getAdBreakEndWallClockMs();
7894
+ if (endWallClockMs != null) {
7895
+ return Math.max(0, endWallClockMs - Date.now());
7896
+ }
7897
+ return 0;
7898
+ }
7899
+ },
7900
+ {
7901
+ key: "getAdBreakEndWallClockMs",
7902
+ value: function getAdBreakEndWallClockMs() {
7903
+ if (this.scteAdBreakEndWallClockMs != null) {
7904
+ return this.scteAdBreakEndWallClockMs;
7905
+ }
7877
7906
  if (this.expectedAdBreakDurationMs == null || this.currentAdBreakStartWallClockMs == null) {
7878
- return 0;
7907
+ return void 0;
7879
7908
  }
7880
- var elapsed = Date.now() - this.currentAdBreakStartWallClockMs;
7881
- return Math.max(0, this.expectedAdBreakDurationMs - elapsed);
7909
+ return this.currentAdBreakStartWallClockMs + this.expectedAdBreakDurationMs;
7882
7910
  }
7883
7911
  },
7884
7912
  {