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.
@@ -3519,7 +3519,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3519
3519
  _this.showAds = true;
3520
3520
  _this.resetGamNoFillCounter();
3521
3521
  if (_this.inAdBreak && _this.expectedAdBreakDurationMs != null && _this.adStopTimerId == null) {
3522
- _this.scheduleAdStopCountdown(_this.getRemainingAdMs());
3522
+ _this.scheduleAdStopAtBreakBoundary();
3523
3523
  if (_this.config.debugAdTiming) {
3524
3524
  console.log("[StormcloudVideoPlayer] Starting ad break timer on content_pause (first ad starting)");
3525
3525
  }
@@ -4174,12 +4174,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4174
4174
  if (marker.durationSeconds != null) {
4175
4175
  var newDurationMs = marker.durationSeconds * 1e3;
4176
4176
  if (this.expectedAdBreakDurationMs == null || newDurationMs > this.expectedAdBreakDurationMs) {
4177
- this.expectedAdBreakDurationMs = newDurationMs;
4178
- var elapsedMs = this.currentAdBreakStartWallClockMs != null ? Date.now() - this.currentAdBreakStartWallClockMs : 0;
4179
- var remainingMs = Math.max(0, newDurationMs - elapsedMs);
4180
- this.scheduleAdStopCountdown(remainingMs);
4177
+ this.setAdBreakDurationBoundary(newDurationMs);
4178
+ this.scheduleAdStopAtBreakBoundary();
4181
4179
  if (this.config.debugAdTiming) {
4182
- console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(newDurationMs, "ms, remaining: ").concat(remainingMs, "ms"));
4180
+ console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(newDurationMs, "ms, remaining: ").concat(this.getWallClockRemainingAdMs(), "ms"));
4183
4181
  }
4184
4182
  }
4185
4183
  }
@@ -4253,13 +4251,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4253
4251
  }
4254
4252
  if (marker.type === "progress" && this.inAdBreak) {
4255
4253
  if (marker.durationSeconds != null) {
4256
- this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
4257
- }
4258
- if (this.expectedAdBreakDurationMs != null && this.currentAdBreakStartWallClockMs != null) {
4259
- var elapsedMs1 = Date.now() - this.currentAdBreakStartWallClockMs;
4260
- var remainingMs1 = Math.max(0, this.expectedAdBreakDurationMs - elapsedMs1);
4261
- this.scheduleAdStopCountdown(remainingMs1);
4254
+ this.setAdBreakDurationBoundary(marker.durationSeconds * 1e3);
4262
4255
  }
4256
+ this.scheduleAdStopAtBreakBoundary();
4263
4257
  if (!this.adPlayer.isAdPlaying() && this.activeAdRequestToken === null && this.adRequestQueue.length > 0 && this.hasTimeToStartAnotherAd()) {
4264
4258
  this.tryNextAvailableAdWithRateLimit();
4265
4259
  }
@@ -4283,15 +4277,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4283
4277
  activeAdRequest: this.activeAdRequestToken !== null
4284
4278
  });
4285
4279
  }
4286
- if (adPlaying || remaining > 1e3 && hasQueuedAds) {
4287
- if (this.config.debugAdTiming) {
4288
- console.log("[StormcloudVideoPlayer] Ignoring premature SCTE-35 end marker - ads still active");
4289
- }
4290
- return;
4291
- }
4292
- this.inAdBreak = false;
4293
- this.expectedAdBreakDurationMs = void 0;
4294
- this.currentAdBreakStartWallClockMs = void 0;
4280
+ this.scteAdBreakEndWallClockMs = Date.now();
4295
4281
  this.clearAdStartTimer();
4296
4282
  this.clearAdStopTimer();
4297
4283
  if (adPlaying) {
@@ -4308,14 +4294,48 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4308
4294
  this.inAdBreak = true;
4309
4295
  this.activeScte35BreakKey = cueKey !== null && cueKey !== void 0 ? cueKey : this.pendingScte35CueKey;
4310
4296
  this.scheduledScte35BreakKey = void 0;
4311
- this.expectedAdBreakDurationMs = durationMs;
4312
- this.currentAdBreakStartWallClockMs = Date.now();
4297
+ this.currentAdBreakStartWallClockMs = this.resolveScteBreakStartWallClockMs(marker);
4298
+ this.setAdBreakDurationBoundary(durationMs);
4313
4299
  this.handleAdStart(marker);
4314
- if (this.expectedAdBreakDurationMs != null) {
4315
- this.scheduleAdStopCountdown(this.expectedAdBreakDurationMs);
4300
+ this.scheduleAdStopAtBreakBoundary();
4301
+ }
4302
+ },
4303
+ {
4304
+ key: "resolveScteBreakStartWallClockMs",
4305
+ value: function resolveScteBreakStartWallClockMs(marker) {
4306
+ var nowWallClockMs = Date.now();
4307
+ if (typeof marker.ptsSeconds !== "number") {
4308
+ return nowWallClockMs;
4309
+ }
4310
+ var nowMs = this.video.currentTime * 1e3;
4311
+ var estimatedCurrentPtsMs = nowMs - this.ptsDriftEmaMs;
4312
+ var deltaMs = marker.ptsSeconds * 1e3 - estimatedCurrentPtsMs;
4313
+ if (!Number.isFinite(deltaMs)) {
4314
+ return nowWallClockMs;
4315
+ }
4316
+ return nowWallClockMs + Math.floor(deltaMs);
4317
+ }
4318
+ },
4319
+ {
4320
+ key: "setAdBreakDurationBoundary",
4321
+ value: function setAdBreakDurationBoundary(durationMs) {
4322
+ this.expectedAdBreakDurationMs = durationMs;
4323
+ if (durationMs != null && this.currentAdBreakStartWallClockMs != null) {
4324
+ this.scteAdBreakEndWallClockMs = this.currentAdBreakStartWallClockMs + durationMs;
4325
+ } else {
4326
+ this.scteAdBreakEndWallClockMs = void 0;
4316
4327
  }
4317
4328
  }
4318
4329
  },
4330
+ {
4331
+ key: "scheduleAdStopAtBreakBoundary",
4332
+ value: function scheduleAdStopAtBreakBoundary() {
4333
+ if (this.expectedAdBreakDurationMs == null) {
4334
+ return;
4335
+ }
4336
+ this.scheduleAdStopCountdown(this.getWallClockRemainingAdMs());
4337
+ }
4338
+ },
4319
4339
  {
4320
4340
  key: "parseCueOutDuration",
4321
4341
  value: function parseCueOutDuration(value) {
@@ -5963,7 +5983,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5963
5983
  currentVolume = this.video.volume;
5964
5984
  this.adPlayer.updateOriginalMutedState(currentMuted, currentVolume);
5965
5985
  this.inAdBreak = true;
5966
- this.currentAdBreakStartWallClockMs = Date.now();
5967
5986
  this.adBreakPlayedDurationMs = 0;
5968
5987
  this.currentAdIndex = 0;
5969
5988
  this.totalAdsInBreak = 0;
@@ -6069,7 +6088,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6069
6088
  _state.sent();
6070
6089
  this.markAdStarted();
6071
6090
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6072
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
6091
+ this.scheduleAdStopAtBreakBoundary();
6073
6092
  }
6074
6093
  adVolume = currentMuted ? 0 : currentVolume;
6075
6094
  this.adPlayer.setAdVolume(adVolume);
@@ -6129,7 +6148,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6129
6148
  _state.sent();
6130
6149
  this.markAdStarted();
6131
6150
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6132
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
6151
+ this.scheduleAdStopAtBreakBoundary();
6133
6152
  }
6134
6153
  adVolume1 = currentMuted ? 0 : currentVolume;
6135
6154
  this.adPlayer.setAdVolume(adVolume1);
@@ -6202,7 +6221,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6202
6221
  _state.sent();
6203
6222
  this.markAdStarted();
6204
6223
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6205
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
6224
+ this.scheduleAdStopAtBreakBoundary();
6206
6225
  }
6207
6226
  adVolume2 = currentMuted ? 0 : currentVolume;
6208
6227
  this.adPlayer.setAdVolume(adVolume2);
@@ -6585,7 +6604,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6585
6604
  _state.sent();
6586
6605
  this.markAdStarted();
6587
6606
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6588
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
6607
+ this.scheduleAdStopAtBreakBoundary();
6589
6608
  }
6590
6609
  this.adPlayer.setAdVolume(this.getAdAudioVolume());
6591
6610
  this.consecutiveFailures = 0;
@@ -7113,19 +7132,15 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7113
7132
  {
7114
7133
  key: "ensureAdStoppedByTimer",
7115
7134
  value: function ensureAdStoppedByTimer() {
7116
- var _this_config_adBreakCheckIntervalMs, _this_expectedAdBreakDurationMs;
7135
+ var _this_config_adBreakCheckIntervalMs, _this_getAdBreakEndWallClockMs;
7117
7136
  if (!this.inAdBreak) return;
7118
7137
  this.adStopTimerId = void 0;
7119
7138
  var adPlaying = this.adPlayer.isAdPlaying();
7120
7139
  var checkIntervalMs = Math.max(250, Math.floor((_this_config_adBreakCheckIntervalMs = this.config.adBreakCheckIntervalMs) !== null && _this_config_adBreakCheckIntervalMs !== void 0 ? _this_config_adBreakCheckIntervalMs : 1e3));
7121
7140
  var maxExtensionMsConfig = this.config.maxAdBreakExtensionMs;
7122
7141
  var maxExtensionMs = typeof maxExtensionMsConfig === "number" && maxExtensionMsConfig > 0 ? maxExtensionMsConfig : 0;
7123
- var elapsedSinceStartMs = 0;
7124
- if (this.currentAdBreakStartWallClockMs != null) {
7125
- elapsedSinceStartMs = Date.now() - this.currentAdBreakStartWallClockMs;
7126
- }
7127
- var expectedDurationMs = (_this_expectedAdBreakDurationMs = this.expectedAdBreakDurationMs) !== null && _this_expectedAdBreakDurationMs !== void 0 ? _this_expectedAdBreakDurationMs : 0;
7128
- var overrunMs = Math.max(0, elapsedSinceStartMs - expectedDurationMs);
7142
+ var endWallClockMs = (_this_getAdBreakEndWallClockMs = this.getAdBreakEndWallClockMs()) !== null && _this_getAdBreakEndWallClockMs !== void 0 ? _this_getAdBreakEndWallClockMs : Date.now();
7143
+ var overrunMs = Math.max(0, Date.now() - endWallClockMs);
7129
7144
  var shouldExtendAdBreak = adPlaying && overrunMs < maxExtensionMs;
7130
7145
  if (shouldExtendAdBreak) {
7131
7146
  this.scheduleAdStopCountdown(checkIntervalMs);
@@ -7401,7 +7416,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7401
7416
  _state.sent();
7402
7417
  this.markAdStarted();
7403
7418
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
7404
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
7419
+ this.scheduleAdStopAtBreakBoundary();
7405
7420
  }
7406
7421
  this.adPlayer.setAdVolume(this.getAdAudioVolume());
7407
7422
  this.consecutiveFailures = 0;
@@ -7453,7 +7468,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7453
7468
  _state.sent();
7454
7469
  this.markAdStarted();
7455
7470
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
7456
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
7471
+ this.scheduleAdStopAtBreakBoundary();
7457
7472
  }
7458
7473
  this.adPlayer.setAdVolume(this.getAdAudioVolume());
7459
7474
  return [
@@ -7599,6 +7614,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7599
7614
  this.scheduledScte35BreakKey = void 0;
7600
7615
  this.expectedAdBreakDurationMs = void 0;
7601
7616
  this.currentAdBreakStartWallClockMs = void 0;
7617
+ this.scteAdBreakEndWallClockMs = void 0;
7602
7618
  this.clearAdStartTimer();
7603
7619
  this.clearAdStopTimer();
7604
7620
  this.adPodQueue = [];
@@ -7786,11 +7802,23 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7786
7802
  {
7787
7803
  key: "getWallClockRemainingAdMs",
7788
7804
  value: function getWallClockRemainingAdMs() {
7805
+ var endWallClockMs = this.getAdBreakEndWallClockMs();
7806
+ if (endWallClockMs != null) {
7807
+ return Math.max(0, endWallClockMs - Date.now());
7808
+ }
7809
+ return 0;
7810
+ }
7811
+ },
7812
+ {
7813
+ key: "getAdBreakEndWallClockMs",
7814
+ value: function getAdBreakEndWallClockMs() {
7815
+ if (this.scteAdBreakEndWallClockMs != null) {
7816
+ return this.scteAdBreakEndWallClockMs;
7817
+ }
7789
7818
  if (this.expectedAdBreakDurationMs == null || this.currentAdBreakStartWallClockMs == null) {
7790
- return 0;
7819
+ return void 0;
7791
7820
  }
7792
- var elapsed = Date.now() - this.currentAdBreakStartWallClockMs;
7793
- return Math.max(0, this.expectedAdBreakDurationMs - elapsed);
7821
+ return this.currentAdBreakStartWallClockMs + this.expectedAdBreakDurationMs;
7794
7822
  }
7795
7823
  },
7796
7824
  {