stormcloud-video-player 0.6.13 → 0.6.14

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.
@@ -3818,7 +3818,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3818
3818
  _this.adLayer.showPlaceholder();
3819
3819
  }
3820
3820
  if (_this.inAdBreak && _this.expectedAdBreakDurationMs != null && _this.adStopTimerId == null) {
3821
- _this.scheduleAdStopCountdown(_this.getRemainingAdMs());
3821
+ _this.scheduleAdStopAtBreakBoundary();
3822
3822
  if (_this.config.debugAdTiming) {
3823
3823
  console.log("[StormcloudVideoPlayer] Starting ad break timer on content_pause (first ad starting)");
3824
3824
  }
@@ -4252,12 +4252,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4252
4252
  if (marker.durationSeconds != null) {
4253
4253
  var newDurationMs = marker.durationSeconds * 1e3;
4254
4254
  if (this.expectedAdBreakDurationMs == null || newDurationMs > this.expectedAdBreakDurationMs) {
4255
- this.expectedAdBreakDurationMs = newDurationMs;
4256
- var elapsedMs = this.currentAdBreakStartWallClockMs != null ? Date.now() - this.currentAdBreakStartWallClockMs : 0;
4257
- var remainingMs = Math.max(0, newDurationMs - elapsedMs);
4258
- this.scheduleAdStopCountdown(remainingMs);
4255
+ this.setAdBreakDurationBoundary(newDurationMs);
4256
+ this.scheduleAdStopAtBreakBoundary();
4259
4257
  if (this.config.debugAdTiming) {
4260
- console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(newDurationMs, "ms, remaining: ").concat(remainingMs, "ms"));
4258
+ console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(newDurationMs, "ms, remaining: ").concat(this.getRemainingAdMs(), "ms"));
4261
4259
  }
4262
4260
  }
4263
4261
  }
@@ -4265,8 +4263,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4265
4263
  }
4266
4264
  this.inAdBreak = true;
4267
4265
  var durationMs = marker.durationSeconds != null ? marker.durationSeconds * 1e3 : ((_this_pendingAdBreak = this.pendingAdBreak) === null || _this_pendingAdBreak === void 0 ? void 0 : _this_pendingAdBreak.marker.durationSeconds) != null ? this.pendingAdBreak.marker.durationSeconds * 1e3 : void 0;
4268
- this.expectedAdBreakDurationMs = durationMs;
4269
- this.currentAdBreakStartWallClockMs = Date.now();
4266
+ this.currentAdBreakStartWallClockMs = this.resolveScteBreakStartWallClockMs(marker);
4267
+ this.setAdBreakDurationBoundary(durationMs);
4270
4268
  if (this.config.licenseKey) {
4271
4269
  var _this_pendingAdBreak1;
4272
4270
  var adDetectInfo = _object_spread({
@@ -4330,20 +4328,14 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4330
4328
  this.clearAdStartTimer();
4331
4329
  this.handleAdStart(marker);
4332
4330
  }
4333
- if (this.expectedAdBreakDurationMs != null) {
4334
- this.scheduleAdStopCountdown(this.expectedAdBreakDurationMs);
4335
- }
4331
+ this.scheduleAdStopAtBreakBoundary();
4336
4332
  return;
4337
4333
  }
4338
4334
  if (marker.type === "progress" && this.inAdBreak) {
4339
4335
  if (marker.durationSeconds != null) {
4340
- this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
4341
- }
4342
- if (this.expectedAdBreakDurationMs != null && this.currentAdBreakStartWallClockMs != null) {
4343
- var elapsedMs1 = Date.now() - this.currentAdBreakStartWallClockMs;
4344
- var remainingMs1 = Math.max(0, this.expectedAdBreakDurationMs - elapsedMs1);
4345
- this.scheduleAdStopCountdown(remainingMs1);
4336
+ this.setAdBreakDurationBoundary(marker.durationSeconds * 1e3);
4346
4337
  }
4338
+ this.scheduleAdStopAtBreakBoundary();
4347
4339
  if (!this.adLayer.isAdPlaying() && this.pendingNextAdBids != null && this.pendingNextAdBids.length > 0) {
4348
4340
  var bids = this.pendingNextAdBids;
4349
4341
  this.pendingNextAdBids = null;
@@ -4374,15 +4366,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4374
4366
  }
4375
4367
  return;
4376
4368
  }
4377
- if (adPlaying || remaining > 500) {
4378
- if (this.config.debugAdTiming) {
4379
- console.log("[StormcloudVideoPlayer] Ignoring premature SCTE-35 end marker - ads still active or time remaining");
4380
- }
4381
- return;
4382
- }
4383
- this.inAdBreak = false;
4384
- this.expectedAdBreakDurationMs = void 0;
4385
- this.currentAdBreakStartWallClockMs = void 0;
4369
+ this.scteAdBreakEndWallClockMs = Date.now();
4386
4370
  this.clearAdStartTimer();
4387
4371
  this.clearAdStopTimer();
4388
4372
  if (adPlaying) {
@@ -4393,6 +4377,42 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4393
4377
  }
4394
4378
  }
4395
4379
  },
4380
+ {
4381
+ key: "resolveScteBreakStartWallClockMs",
4382
+ value: function resolveScteBreakStartWallClockMs(marker) {
4383
+ var nowWallClockMs = Date.now();
4384
+ if (typeof marker.ptsSeconds !== "number") {
4385
+ return nowWallClockMs;
4386
+ }
4387
+ var nowMs = this.video.currentTime * 1e3;
4388
+ var estimatedCurrentPtsMs = nowMs - this.ptsDriftEmaMs;
4389
+ var deltaMs = marker.ptsSeconds * 1e3 - estimatedCurrentPtsMs;
4390
+ if (!Number.isFinite(deltaMs)) {
4391
+ return nowWallClockMs;
4392
+ }
4393
+ return nowWallClockMs + Math.floor(deltaMs);
4394
+ }
4395
+ },
4396
+ {
4397
+ key: "setAdBreakDurationBoundary",
4398
+ value: function setAdBreakDurationBoundary(durationMs) {
4399
+ this.expectedAdBreakDurationMs = durationMs;
4400
+ if (durationMs != null && this.currentAdBreakStartWallClockMs != null) {
4401
+ this.scteAdBreakEndWallClockMs = this.currentAdBreakStartWallClockMs + durationMs;
4402
+ } else {
4403
+ this.scteAdBreakEndWallClockMs = void 0;
4404
+ }
4405
+ }
4406
+ },
4407
+ {
4408
+ key: "scheduleAdStopAtBreakBoundary",
4409
+ value: function scheduleAdStopAtBreakBoundary() {
4410
+ if (this.expectedAdBreakDurationMs == null) {
4411
+ return;
4412
+ }
4413
+ this.scheduleAdStopCountdown(this.getRemainingAdMs());
4414
+ }
4415
+ },
4396
4416
  {
4397
4417
  key: "parseCueOutDuration",
4398
4418
  value: function parseCueOutDuration(value) {
@@ -5028,7 +5048,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5028
5048
  case 9:
5029
5049
  _state.sent();
5030
5050
  if (_this.expectedAdBreakDurationMs != null && _this.adStopTimerId == null) {
5031
- _this.scheduleAdStopCountdown(_this.getRemainingAdMs());
5051
+ _this.scheduleAdStopAtBreakBoundary();
5032
5052
  }
5033
5053
  _this.adLayer.setAdVolume(_this.adLayer.getOriginalMutedState() ? 1 : _this.adLayer.getOriginalVolume());
5034
5054
  return [
@@ -5133,7 +5153,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5133
5153
  case 19:
5134
5154
  _state.sent();
5135
5155
  if (_this.expectedAdBreakDurationMs != null && _this.adStopTimerId == null) {
5136
- _this.scheduleAdStopCountdown(_this.getRemainingAdMs());
5156
+ _this.scheduleAdStopAtBreakBoundary();
5137
5157
  }
5138
5158
  _this.adLayer.setAdVolume(_this.adLayer.getOriginalMutedState() ? 1 : _this.adLayer.getOriginalVolume());
5139
5159
  _state.label = 20;
@@ -5216,7 +5236,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5216
5236
  key: "handleAdStart",
5217
5237
  value: function handleAdStart(_marker) {
5218
5238
  return _async_to_generator(function() {
5219
- var _this_savedMutedStateBeforeScte, adBreakDurationMs, mode, state, adBreakToken, adVolume, token, remaining, err;
5239
+ var _this_savedMutedStateBeforeScte, adBreakDurationMs, mode, state, fillerRemainingMs, adBreakToken, adVolume, token, remaining, err;
5220
5240
  return _ts_generator(this, function(_state) {
5221
5241
  switch(_state.label){
5222
5242
  case 0:
@@ -5250,20 +5270,21 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5250
5270
  }
5251
5271
  }
5252
5272
  this.inAdBreak = true;
5253
- this.currentAdBreakStartWallClockMs = Date.now();
5254
5273
  this.currentAdIndex = 0;
5255
5274
  this.totalAdsInBreak = Math.max(1, this.preloadedTokens.length);
5256
5275
  this.adPodQueue = [];
5257
5276
  if (!this.config.disableFiller) this.showAds = true;
5258
- if (adBreakDurationMs != null) {
5259
- this.startFillerBreakTimer(adBreakDurationMs);
5277
+ if (this.expectedAdBreakDurationMs == null && adBreakDurationMs != null) {
5278
+ this.currentAdBreakStartWallClockMs = Date.now();
5279
+ this.setAdBreakDurationBoundary(adBreakDurationMs);
5280
+ }
5281
+ fillerRemainingMs = this.getRemainingAdMs();
5282
+ if (this.expectedAdBreakDurationMs != null && fillerRemainingMs > 0) {
5283
+ this.startFillerBreakTimer(fillerRemainingMs);
5260
5284
  } else if (!this.config.disableFiller && this.preloadedTokens.length === 0) {
5261
5285
  this.showPlaceholderLayer();
5262
5286
  }
5263
5287
  if (!this.config.disableFiller) this.adLayer.showPlaceholder();
5264
- if (this.expectedAdBreakDurationMs == null && adBreakDurationMs != null) {
5265
- this.expectedAdBreakDurationMs = adBreakDurationMs;
5266
- }
5267
5288
  this.clearPendingAdBreak();
5268
5289
  adBreakToken = Date.now();
5269
5290
  this.activeAdRequestToken = adBreakToken;
@@ -5300,7 +5321,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5300
5321
  case 2:
5301
5322
  _state.sent();
5302
5323
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
5303
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
5324
+ this.scheduleAdStopAtBreakBoundary();
5304
5325
  }
5305
5326
  this.adLayer.setAdVolume(adVolume);
5306
5327
  return [
@@ -5486,7 +5507,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5486
5507
  case 4:
5487
5508
  _state.sent();
5488
5509
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
5489
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
5510
+ this.scheduleAdStopAtBreakBoundary();
5490
5511
  }
5491
5512
  this.adLayer.setAdVolume(this.adLayer.getOriginalMutedState() ? 1 : this.adLayer.getOriginalVolume());
5492
5513
  _state.label = 5;
@@ -5728,21 +5749,16 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5728
5749
  {
5729
5750
  key: "ensureAdStoppedByTimer",
5730
5751
  value: function ensureAdStoppedByTimer() {
5731
- var _this_config_adBreakCheckIntervalMs, _this_expectedAdBreakDurationMs;
5752
+ var _this_config_adBreakCheckIntervalMs, _this_getAdBreakEndWallClockMs;
5732
5753
  if (!this.inAdBreak) return;
5733
5754
  this.adStopTimerId = void 0;
5734
5755
  var adPlaying = this.adLayer.isAdPlaying();
5735
- var pendingAds = this.adPodQueue.length > 0;
5736
5756
  var checkIntervalMs = Math.max(250, Math.floor((_this_config_adBreakCheckIntervalMs = this.config.adBreakCheckIntervalMs) !== null && _this_config_adBreakCheckIntervalMs !== void 0 ? _this_config_adBreakCheckIntervalMs : 1e3));
5737
5757
  var maxExtensionMsConfig = this.config.maxAdBreakExtensionMs;
5738
- var maxExtensionMs = typeof maxExtensionMsConfig === "number" && maxExtensionMsConfig > 0 ? maxExtensionMsConfig : 6e4;
5739
- var elapsedSinceStartMs = 0;
5740
- if (this.currentAdBreakStartWallClockMs != null) {
5741
- elapsedSinceStartMs = Date.now() - this.currentAdBreakStartWallClockMs;
5742
- }
5743
- var expectedDurationMs = (_this_expectedAdBreakDurationMs = this.expectedAdBreakDurationMs) !== null && _this_expectedAdBreakDurationMs !== void 0 ? _this_expectedAdBreakDurationMs : 0;
5744
- var overrunMs = Math.max(0, elapsedSinceStartMs - expectedDurationMs);
5745
- var shouldExtendAdBreak = (adPlaying || pendingAds || this.showAds) && overrunMs < maxExtensionMs;
5758
+ var maxExtensionMs = typeof maxExtensionMsConfig === "number" && maxExtensionMsConfig > 0 ? maxExtensionMsConfig : 0;
5759
+ var endWallClockMs = (_this_getAdBreakEndWallClockMs = this.getAdBreakEndWallClockMs()) !== null && _this_getAdBreakEndWallClockMs !== void 0 ? _this_getAdBreakEndWallClockMs : Date.now();
5760
+ var overrunMs = Math.max(0, Date.now() - endWallClockMs);
5761
+ var shouldExtendAdBreak = adPlaying && overrunMs < maxExtensionMs;
5746
5762
  if (shouldExtendAdBreak) {
5747
5763
  this.scheduleAdStopCountdown(checkIntervalMs);
5748
5764
  return;
@@ -5816,6 +5832,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5816
5832
  this.inAdBreak = false;
5817
5833
  this.expectedAdBreakDurationMs = void 0;
5818
5834
  this.currentAdBreakStartWallClockMs = void 0;
5835
+ this.scteAdBreakEndWallClockMs = void 0;
5819
5836
  this.clearAdStartTimer();
5820
5837
  this.clearAdStopTimer();
5821
5838
  this.adPodQueue = [];
@@ -6077,10 +6094,25 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6077
6094
  {
6078
6095
  key: "getRemainingAdMs",
6079
6096
  value: function getRemainingAdMs() {
6097
+ var endWallClockMs = this.getAdBreakEndWallClockMs();
6098
+ if (endWallClockMs != null) {
6099
+ return Math.max(0, endWallClockMs - Date.now());
6100
+ }
6080
6101
  if (this.currentAdBreakStartWallClockMs == null) return 0;
6081
6102
  if (this.expectedAdBreakDurationMs == null) return Number.MAX_SAFE_INTEGER;
6082
- var elapsed = Date.now() - this.currentAdBreakStartWallClockMs;
6083
- return Math.max(0, this.expectedAdBreakDurationMs - elapsed);
6103
+ return 0;
6104
+ }
6105
+ },
6106
+ {
6107
+ key: "getAdBreakEndWallClockMs",
6108
+ value: function getAdBreakEndWallClockMs() {
6109
+ if (this.scteAdBreakEndWallClockMs != null) {
6110
+ return this.scteAdBreakEndWallClockMs;
6111
+ }
6112
+ if (this.expectedAdBreakDurationMs == null || this.currentAdBreakStartWallClockMs == null) {
6113
+ return void 0;
6114
+ }
6115
+ return this.currentAdBreakStartWallClockMs + this.expectedAdBreakDurationMs;
6084
6116
  }
6085
6117
  },
6086
6118
  {