stormcloud-video-player 0.3.64 → 0.3.65

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.
@@ -3915,7 +3915,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3915
3915
  _this.showAds = true;
3916
3916
  _this.resetGamNoFillCounter();
3917
3917
  if (_this.inAdBreak && _this.expectedAdBreakDurationMs != null && _this.adStopTimerId == null) {
3918
- _this.scheduleAdStopCountdown(_this.getRemainingAdMs());
3918
+ _this.scheduleAdStopAtBreakBoundary();
3919
3919
  if (_this.config.debugAdTiming) {
3920
3920
  console.log("[StormcloudVideoPlayer] Starting ad break timer on content_pause (first ad starting)");
3921
3921
  }
@@ -4559,12 +4559,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4559
4559
  if (marker.durationSeconds != null) {
4560
4560
  var newDurationMs = marker.durationSeconds * 1e3;
4561
4561
  if (this.expectedAdBreakDurationMs == null || newDurationMs > this.expectedAdBreakDurationMs) {
4562
- this.expectedAdBreakDurationMs = newDurationMs;
4563
- var elapsedMs = this.currentAdBreakStartWallClockMs != null ? Date.now() - this.currentAdBreakStartWallClockMs : 0;
4564
- var remainingMs = Math.max(0, newDurationMs - elapsedMs);
4565
- this.scheduleAdStopCountdown(remainingMs);
4562
+ this.setAdBreakDurationBoundary(newDurationMs);
4563
+ this.scheduleAdStopAtBreakBoundary();
4566
4564
  if (this.config.debugAdTiming) {
4567
- console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(newDurationMs, "ms, remaining: ").concat(remainingMs, "ms"));
4565
+ console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(newDurationMs, "ms, remaining: ").concat(this.getRemainingAdMs(), "ms"));
4568
4566
  }
4569
4567
  }
4570
4568
  }
@@ -4638,13 +4636,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4638
4636
  }
4639
4637
  if (marker.type === "progress" && this.inAdBreak) {
4640
4638
  if (marker.durationSeconds != null) {
4641
- this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
4642
- }
4643
- if (this.expectedAdBreakDurationMs != null && this.currentAdBreakStartWallClockMs != null) {
4644
- var elapsedMs1 = Date.now() - this.currentAdBreakStartWallClockMs;
4645
- var remainingMs1 = Math.max(0, this.expectedAdBreakDurationMs - elapsedMs1);
4646
- this.scheduleAdStopCountdown(remainingMs1);
4639
+ this.setAdBreakDurationBoundary(marker.durationSeconds * 1e3);
4647
4640
  }
4641
+ this.scheduleAdStopAtBreakBoundary();
4648
4642
  if (!this.ima.isAdPlaying() && this.activeAdRequestToken === null && this.adRequestQueue.length > 0) {
4649
4643
  this.tryNextAvailableAdWithRateLimit();
4650
4644
  }
@@ -4669,15 +4663,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4669
4663
  activeAdRequest: this.activeAdRequestToken !== null
4670
4664
  });
4671
4665
  }
4672
- if (adPlaying || remaining > 1e3 && hasQueuedAds) {
4673
- if (this.config.debugAdTiming) {
4674
- console.log("[StormcloudVideoPlayer] Ignoring premature SCTE-35 end marker - ads still active");
4675
- }
4676
- return;
4677
- }
4678
- this.inAdBreak = false;
4679
- this.expectedAdBreakDurationMs = void 0;
4680
- this.currentAdBreakStartWallClockMs = void 0;
4666
+ this.scteAdBreakEndWallClockMs = Date.now();
4681
4667
  this.clearAdStartTimer();
4682
4668
  this.clearAdStopTimer();
4683
4669
  if (adPlaying) {
@@ -4701,12 +4687,46 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4701
4687
  this.inAdBreak = true;
4702
4688
  this.activeScte35BreakKey = cueKey !== null && cueKey !== void 0 ? cueKey : this.pendingScte35CueKey;
4703
4689
  this.scheduledScte35BreakKey = void 0;
4704
- this.expectedAdBreakDurationMs = durationMs;
4705
- this.currentAdBreakStartWallClockMs = Date.now();
4690
+ this.currentAdBreakStartWallClockMs = this.resolveScteBreakStartWallClockMs(marker);
4691
+ this.setAdBreakDurationBoundary(durationMs);
4706
4692
  this.handleAdStart(marker);
4707
- if (this.expectedAdBreakDurationMs != null) {
4708
- this.scheduleAdStopCountdown(this.expectedAdBreakDurationMs);
4693
+ this.scheduleAdStopAtBreakBoundary();
4694
+ }
4695
+ },
4696
+ {
4697
+ key: "resolveScteBreakStartWallClockMs",
4698
+ value: function resolveScteBreakStartWallClockMs(marker) {
4699
+ var nowWallClockMs = Date.now();
4700
+ if (typeof marker.ptsSeconds !== "number") {
4701
+ return nowWallClockMs;
4709
4702
  }
4703
+ var nowMs = this.video.currentTime * 1e3;
4704
+ var estimatedCurrentPtsMs = nowMs - this.ptsDriftEmaMs;
4705
+ var deltaMs = marker.ptsSeconds * 1e3 - estimatedCurrentPtsMs;
4706
+ if (!Number.isFinite(deltaMs)) {
4707
+ return nowWallClockMs;
4708
+ }
4709
+ return nowWallClockMs + Math.floor(deltaMs);
4710
+ }
4711
+ },
4712
+ {
4713
+ key: "setAdBreakDurationBoundary",
4714
+ value: function setAdBreakDurationBoundary(durationMs) {
4715
+ this.expectedAdBreakDurationMs = durationMs;
4716
+ if (durationMs != null && this.currentAdBreakStartWallClockMs != null) {
4717
+ this.scteAdBreakEndWallClockMs = this.currentAdBreakStartWallClockMs + durationMs;
4718
+ } else {
4719
+ this.scteAdBreakEndWallClockMs = void 0;
4720
+ }
4721
+ }
4722
+ },
4723
+ {
4724
+ key: "scheduleAdStopAtBreakBoundary",
4725
+ value: function scheduleAdStopAtBreakBoundary() {
4726
+ if (this.expectedAdBreakDurationMs == null) {
4727
+ return;
4728
+ }
4729
+ this.scheduleAdStopCountdown(this.getRemainingAdMs());
4710
4730
  }
4711
4731
  },
4712
4732
  {
@@ -6334,7 +6354,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6334
6354
  }
6335
6355
  }
6336
6356
  this.inAdBreak = true;
6337
- this.currentAdBreakStartWallClockMs = Date.now();
6338
6357
  this.currentAdIndex = 0;
6339
6358
  this.totalAdsInBreak = 1;
6340
6359
  this.adPodQueue = [];
@@ -6421,7 +6440,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6421
6440
  case 2:
6422
6441
  _state.sent();
6423
6442
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6424
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
6443
+ this.scheduleAdStopAtBreakBoundary();
6425
6444
  }
6426
6445
  adVolume = currentMuted ? 0 : currentVolume;
6427
6446
  this.ima.setAdVolume(adVolume);
@@ -6464,7 +6483,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6464
6483
  case 6:
6465
6484
  _state.sent();
6466
6485
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6467
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
6486
+ this.scheduleAdStopAtBreakBoundary();
6468
6487
  }
6469
6488
  adVolume1 = currentMuted ? 0 : currentVolume;
6470
6489
  this.ima.setAdVolume(adVolume1);
@@ -6519,7 +6538,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6519
6538
  case 10:
6520
6539
  _state.sent();
6521
6540
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6522
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
6541
+ this.scheduleAdStopAtBreakBoundary();
6523
6542
  }
6524
6543
  adVolume2 = currentMuted ? 0 : currentVolume;
6525
6544
  this.ima.setAdVolume(adVolume2);
@@ -6871,7 +6890,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6871
6890
  case 2:
6872
6891
  _state.sent();
6873
6892
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6874
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
6893
+ this.scheduleAdStopAtBreakBoundary();
6875
6894
  }
6876
6895
  currentMuted = this.video.muted;
6877
6896
  currentVolume = this.video.volume;
@@ -7371,21 +7390,16 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7371
7390
  {
7372
7391
  key: "ensureAdStoppedByTimer",
7373
7392
  value: function ensureAdStoppedByTimer() {
7374
- var _this_config_adBreakCheckIntervalMs, _this_expectedAdBreakDurationMs;
7393
+ var _this_config_adBreakCheckIntervalMs, _this_getAdBreakEndWallClockMs;
7375
7394
  if (!this.inAdBreak) return;
7376
7395
  this.adStopTimerId = void 0;
7377
7396
  var adPlaying = this.ima.isAdPlaying();
7378
- var pendingAds = this.adPodQueue.length > 0;
7379
7397
  var checkIntervalMs = Math.max(250, Math.floor((_this_config_adBreakCheckIntervalMs = this.config.adBreakCheckIntervalMs) !== null && _this_config_adBreakCheckIntervalMs !== void 0 ? _this_config_adBreakCheckIntervalMs : 1e3));
7380
7398
  var maxExtensionMsConfig = this.config.maxAdBreakExtensionMs;
7381
- var maxExtensionMs = typeof maxExtensionMsConfig === "number" && maxExtensionMsConfig > 0 ? maxExtensionMsConfig : 6e4;
7382
- var elapsedSinceStartMs = 0;
7383
- if (this.currentAdBreakStartWallClockMs != null) {
7384
- elapsedSinceStartMs = Date.now() - this.currentAdBreakStartWallClockMs;
7385
- }
7386
- var expectedDurationMs = (_this_expectedAdBreakDurationMs = this.expectedAdBreakDurationMs) !== null && _this_expectedAdBreakDurationMs !== void 0 ? _this_expectedAdBreakDurationMs : 0;
7387
- var overrunMs = Math.max(0, elapsedSinceStartMs - expectedDurationMs);
7388
- var shouldExtendAdBreak = (adPlaying || pendingAds || this.showAds) && overrunMs < maxExtensionMs;
7399
+ var maxExtensionMs = typeof maxExtensionMsConfig === "number" && maxExtensionMsConfig > 0 ? maxExtensionMsConfig : 0;
7400
+ var endWallClockMs = (_this_getAdBreakEndWallClockMs = this.getAdBreakEndWallClockMs()) !== null && _this_getAdBreakEndWallClockMs !== void 0 ? _this_getAdBreakEndWallClockMs : Date.now();
7401
+ var overrunMs = Math.max(0, Date.now() - endWallClockMs);
7402
+ var shouldExtendAdBreak = adPlaying && overrunMs < maxExtensionMs;
7389
7403
  if (shouldExtendAdBreak) {
7390
7404
  this.scheduleAdStopCountdown(checkIntervalMs);
7391
7405
  return;
@@ -7651,7 +7665,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7651
7665
  case 5:
7652
7666
  _state.sent();
7653
7667
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
7654
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
7668
+ this.scheduleAdStopAtBreakBoundary();
7655
7669
  }
7656
7670
  currentMuted = this.video.muted;
7657
7671
  currentVolume = this.video.volume;
@@ -7701,7 +7715,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7701
7715
  case 8:
7702
7716
  _state.sent();
7703
7717
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
7704
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
7718
+ this.scheduleAdStopAtBreakBoundary();
7705
7719
  }
7706
7720
  currentMuted1 = this.video.muted;
7707
7721
  currentVolume1 = this.video.volume;
@@ -7846,6 +7860,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7846
7860
  this.scheduledScte35BreakKey = void 0;
7847
7861
  this.expectedAdBreakDurationMs = void 0;
7848
7862
  this.currentAdBreakStartWallClockMs = void 0;
7863
+ this.scteAdBreakEndWallClockMs = void 0;
7849
7864
  this.clearAdStartTimer();
7850
7865
  this.clearAdStopTimer();
7851
7866
  this.adPodQueue = [];
@@ -8035,9 +8050,21 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8035
8050
  {
8036
8051
  key: "getRemainingAdMs",
8037
8052
  value: function getRemainingAdMs() {
8038
- if (this.expectedAdBreakDurationMs == null || this.currentAdBreakStartWallClockMs == null) return 0;
8039
- var elapsed = Date.now() - this.currentAdBreakStartWallClockMs;
8040
- return Math.max(0, this.expectedAdBreakDurationMs - elapsed);
8053
+ var endWallClockMs = this.getAdBreakEndWallClockMs();
8054
+ if (endWallClockMs != null) {
8055
+ return Math.max(0, endWallClockMs - Date.now());
8056
+ }
8057
+ return 0;
8058
+ }
8059
+ },
8060
+ {
8061
+ key: "getAdBreakEndWallClockMs",
8062
+ value: function getAdBreakEndWallClockMs() {
8063
+ if (this.scteAdBreakEndWallClockMs != null) {
8064
+ return this.scteAdBreakEndWallClockMs;
8065
+ }
8066
+ if (this.expectedAdBreakDurationMs == null || this.currentAdBreakStartWallClockMs == null) return void 0;
8067
+ return this.currentAdBreakStartWallClockMs + this.expectedAdBreakDurationMs;
8041
8068
  }
8042
8069
  },
8043
8070
  {