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.
@@ -3730,7 +3730,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3730
3730
  _this.adLayer.showPlaceholder();
3731
3731
  }
3732
3732
  if (_this.inAdBreak && _this.expectedAdBreakDurationMs != null && _this.adStopTimerId == null) {
3733
- _this.scheduleAdStopCountdown(_this.getRemainingAdMs());
3733
+ _this.scheduleAdStopAtBreakBoundary();
3734
3734
  if (_this.config.debugAdTiming) {
3735
3735
  console.log("[StormcloudVideoPlayer] Starting ad break timer on content_pause (first ad starting)");
3736
3736
  }
@@ -4164,12 +4164,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4164
4164
  if (marker.durationSeconds != null) {
4165
4165
  var newDurationMs = marker.durationSeconds * 1e3;
4166
4166
  if (this.expectedAdBreakDurationMs == null || newDurationMs > this.expectedAdBreakDurationMs) {
4167
- this.expectedAdBreakDurationMs = newDurationMs;
4168
- var elapsedMs = this.currentAdBreakStartWallClockMs != null ? Date.now() - this.currentAdBreakStartWallClockMs : 0;
4169
- var remainingMs = Math.max(0, newDurationMs - elapsedMs);
4170
- this.scheduleAdStopCountdown(remainingMs);
4167
+ this.setAdBreakDurationBoundary(newDurationMs);
4168
+ this.scheduleAdStopAtBreakBoundary();
4171
4169
  if (this.config.debugAdTiming) {
4172
- console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(newDurationMs, "ms, remaining: ").concat(remainingMs, "ms"));
4170
+ console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(newDurationMs, "ms, remaining: ").concat(this.getRemainingAdMs(), "ms"));
4173
4171
  }
4174
4172
  }
4175
4173
  }
@@ -4177,8 +4175,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4177
4175
  }
4178
4176
  this.inAdBreak = true;
4179
4177
  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;
4180
- this.expectedAdBreakDurationMs = durationMs;
4181
- this.currentAdBreakStartWallClockMs = Date.now();
4178
+ this.currentAdBreakStartWallClockMs = this.resolveScteBreakStartWallClockMs(marker);
4179
+ this.setAdBreakDurationBoundary(durationMs);
4182
4180
  if (this.config.licenseKey) {
4183
4181
  var _this_pendingAdBreak1;
4184
4182
  var adDetectInfo = _object_spread({
@@ -4242,20 +4240,14 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4242
4240
  this.clearAdStartTimer();
4243
4241
  this.handleAdStart(marker);
4244
4242
  }
4245
- if (this.expectedAdBreakDurationMs != null) {
4246
- this.scheduleAdStopCountdown(this.expectedAdBreakDurationMs);
4247
- }
4243
+ this.scheduleAdStopAtBreakBoundary();
4248
4244
  return;
4249
4245
  }
4250
4246
  if (marker.type === "progress" && this.inAdBreak) {
4251
4247
  if (marker.durationSeconds != null) {
4252
- this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
4253
- }
4254
- if (this.expectedAdBreakDurationMs != null && this.currentAdBreakStartWallClockMs != null) {
4255
- var elapsedMs1 = Date.now() - this.currentAdBreakStartWallClockMs;
4256
- var remainingMs1 = Math.max(0, this.expectedAdBreakDurationMs - elapsedMs1);
4257
- this.scheduleAdStopCountdown(remainingMs1);
4248
+ this.setAdBreakDurationBoundary(marker.durationSeconds * 1e3);
4258
4249
  }
4250
+ this.scheduleAdStopAtBreakBoundary();
4259
4251
  if (!this.adLayer.isAdPlaying() && this.pendingNextAdBids != null && this.pendingNextAdBids.length > 0) {
4260
4252
  var bids = this.pendingNextAdBids;
4261
4253
  this.pendingNextAdBids = null;
@@ -4286,15 +4278,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4286
4278
  }
4287
4279
  return;
4288
4280
  }
4289
- if (adPlaying || remaining > 500) {
4290
- if (this.config.debugAdTiming) {
4291
- console.log("[StormcloudVideoPlayer] Ignoring premature SCTE-35 end marker - ads still active or time remaining");
4292
- }
4293
- return;
4294
- }
4295
- this.inAdBreak = false;
4296
- this.expectedAdBreakDurationMs = void 0;
4297
- this.currentAdBreakStartWallClockMs = void 0;
4281
+ this.scteAdBreakEndWallClockMs = Date.now();
4298
4282
  this.clearAdStartTimer();
4299
4283
  this.clearAdStopTimer();
4300
4284
  if (adPlaying) {
@@ -4305,6 +4289,42 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4305
4289
  }
4306
4290
  }
4307
4291
  },
4292
+ {
4293
+ key: "resolveScteBreakStartWallClockMs",
4294
+ value: function resolveScteBreakStartWallClockMs(marker) {
4295
+ var nowWallClockMs = Date.now();
4296
+ if (typeof marker.ptsSeconds !== "number") {
4297
+ return nowWallClockMs;
4298
+ }
4299
+ var nowMs = this.video.currentTime * 1e3;
4300
+ var estimatedCurrentPtsMs = nowMs - this.ptsDriftEmaMs;
4301
+ var deltaMs = marker.ptsSeconds * 1e3 - estimatedCurrentPtsMs;
4302
+ if (!Number.isFinite(deltaMs)) {
4303
+ return nowWallClockMs;
4304
+ }
4305
+ return nowWallClockMs + Math.floor(deltaMs);
4306
+ }
4307
+ },
4308
+ {
4309
+ key: "setAdBreakDurationBoundary",
4310
+ value: function setAdBreakDurationBoundary(durationMs) {
4311
+ this.expectedAdBreakDurationMs = durationMs;
4312
+ if (durationMs != null && this.currentAdBreakStartWallClockMs != null) {
4313
+ this.scteAdBreakEndWallClockMs = this.currentAdBreakStartWallClockMs + durationMs;
4314
+ } else {
4315
+ this.scteAdBreakEndWallClockMs = void 0;
4316
+ }
4317
+ }
4318
+ },
4319
+ {
4320
+ key: "scheduleAdStopAtBreakBoundary",
4321
+ value: function scheduleAdStopAtBreakBoundary() {
4322
+ if (this.expectedAdBreakDurationMs == null) {
4323
+ return;
4324
+ }
4325
+ this.scheduleAdStopCountdown(this.getRemainingAdMs());
4326
+ }
4327
+ },
4308
4328
  {
4309
4329
  key: "parseCueOutDuration",
4310
4330
  value: function parseCueOutDuration(value) {
@@ -4940,7 +4960,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4940
4960
  case 9:
4941
4961
  _state.sent();
4942
4962
  if (_this.expectedAdBreakDurationMs != null && _this.adStopTimerId == null) {
4943
- _this.scheduleAdStopCountdown(_this.getRemainingAdMs());
4963
+ _this.scheduleAdStopAtBreakBoundary();
4944
4964
  }
4945
4965
  _this.adLayer.setAdVolume(_this.adLayer.getOriginalMutedState() ? 1 : _this.adLayer.getOriginalVolume());
4946
4966
  return [
@@ -5045,7 +5065,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5045
5065
  case 19:
5046
5066
  _state.sent();
5047
5067
  if (_this.expectedAdBreakDurationMs != null && _this.adStopTimerId == null) {
5048
- _this.scheduleAdStopCountdown(_this.getRemainingAdMs());
5068
+ _this.scheduleAdStopAtBreakBoundary();
5049
5069
  }
5050
5070
  _this.adLayer.setAdVolume(_this.adLayer.getOriginalMutedState() ? 1 : _this.adLayer.getOriginalVolume());
5051
5071
  _state.label = 20;
@@ -5128,7 +5148,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5128
5148
  key: "handleAdStart",
5129
5149
  value: function handleAdStart(_marker) {
5130
5150
  return _async_to_generator(function() {
5131
- var _this_savedMutedStateBeforeScte, adBreakDurationMs, mode, state, adBreakToken, adVolume, token, remaining, err;
5151
+ var _this_savedMutedStateBeforeScte, adBreakDurationMs, mode, state, fillerRemainingMs, adBreakToken, adVolume, token, remaining, err;
5132
5152
  return _ts_generator(this, function(_state) {
5133
5153
  switch(_state.label){
5134
5154
  case 0:
@@ -5162,20 +5182,21 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5162
5182
  }
5163
5183
  }
5164
5184
  this.inAdBreak = true;
5165
- this.currentAdBreakStartWallClockMs = Date.now();
5166
5185
  this.currentAdIndex = 0;
5167
5186
  this.totalAdsInBreak = Math.max(1, this.preloadedTokens.length);
5168
5187
  this.adPodQueue = [];
5169
5188
  if (!this.config.disableFiller) this.showAds = true;
5170
- if (adBreakDurationMs != null) {
5171
- this.startFillerBreakTimer(adBreakDurationMs);
5189
+ if (this.expectedAdBreakDurationMs == null && adBreakDurationMs != null) {
5190
+ this.currentAdBreakStartWallClockMs = Date.now();
5191
+ this.setAdBreakDurationBoundary(adBreakDurationMs);
5192
+ }
5193
+ fillerRemainingMs = this.getRemainingAdMs();
5194
+ if (this.expectedAdBreakDurationMs != null && fillerRemainingMs > 0) {
5195
+ this.startFillerBreakTimer(fillerRemainingMs);
5172
5196
  } else if (!this.config.disableFiller && this.preloadedTokens.length === 0) {
5173
5197
  this.showPlaceholderLayer();
5174
5198
  }
5175
5199
  if (!this.config.disableFiller) this.adLayer.showPlaceholder();
5176
- if (this.expectedAdBreakDurationMs == null && adBreakDurationMs != null) {
5177
- this.expectedAdBreakDurationMs = adBreakDurationMs;
5178
- }
5179
5200
  this.clearPendingAdBreak();
5180
5201
  adBreakToken = Date.now();
5181
5202
  this.activeAdRequestToken = adBreakToken;
@@ -5212,7 +5233,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5212
5233
  case 2:
5213
5234
  _state.sent();
5214
5235
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
5215
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
5236
+ this.scheduleAdStopAtBreakBoundary();
5216
5237
  }
5217
5238
  this.adLayer.setAdVolume(adVolume);
5218
5239
  return [
@@ -5398,7 +5419,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5398
5419
  case 4:
5399
5420
  _state.sent();
5400
5421
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
5401
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
5422
+ this.scheduleAdStopAtBreakBoundary();
5402
5423
  }
5403
5424
  this.adLayer.setAdVolume(this.adLayer.getOriginalMutedState() ? 1 : this.adLayer.getOriginalVolume());
5404
5425
  _state.label = 5;
@@ -5640,21 +5661,16 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5640
5661
  {
5641
5662
  key: "ensureAdStoppedByTimer",
5642
5663
  value: function ensureAdStoppedByTimer() {
5643
- var _this_config_adBreakCheckIntervalMs, _this_expectedAdBreakDurationMs;
5664
+ var _this_config_adBreakCheckIntervalMs, _this_getAdBreakEndWallClockMs;
5644
5665
  if (!this.inAdBreak) return;
5645
5666
  this.adStopTimerId = void 0;
5646
5667
  var adPlaying = this.adLayer.isAdPlaying();
5647
- var pendingAds = this.adPodQueue.length > 0;
5648
5668
  var checkIntervalMs = Math.max(250, Math.floor((_this_config_adBreakCheckIntervalMs = this.config.adBreakCheckIntervalMs) !== null && _this_config_adBreakCheckIntervalMs !== void 0 ? _this_config_adBreakCheckIntervalMs : 1e3));
5649
5669
  var maxExtensionMsConfig = this.config.maxAdBreakExtensionMs;
5650
- var maxExtensionMs = typeof maxExtensionMsConfig === "number" && maxExtensionMsConfig > 0 ? maxExtensionMsConfig : 6e4;
5651
- var elapsedSinceStartMs = 0;
5652
- if (this.currentAdBreakStartWallClockMs != null) {
5653
- elapsedSinceStartMs = Date.now() - this.currentAdBreakStartWallClockMs;
5654
- }
5655
- var expectedDurationMs = (_this_expectedAdBreakDurationMs = this.expectedAdBreakDurationMs) !== null && _this_expectedAdBreakDurationMs !== void 0 ? _this_expectedAdBreakDurationMs : 0;
5656
- var overrunMs = Math.max(0, elapsedSinceStartMs - expectedDurationMs);
5657
- var shouldExtendAdBreak = (adPlaying || pendingAds || this.showAds) && overrunMs < maxExtensionMs;
5670
+ var maxExtensionMs = typeof maxExtensionMsConfig === "number" && maxExtensionMsConfig > 0 ? maxExtensionMsConfig : 0;
5671
+ var endWallClockMs = (_this_getAdBreakEndWallClockMs = this.getAdBreakEndWallClockMs()) !== null && _this_getAdBreakEndWallClockMs !== void 0 ? _this_getAdBreakEndWallClockMs : Date.now();
5672
+ var overrunMs = Math.max(0, Date.now() - endWallClockMs);
5673
+ var shouldExtendAdBreak = adPlaying && overrunMs < maxExtensionMs;
5658
5674
  if (shouldExtendAdBreak) {
5659
5675
  this.scheduleAdStopCountdown(checkIntervalMs);
5660
5676
  return;
@@ -5728,6 +5744,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5728
5744
  this.inAdBreak = false;
5729
5745
  this.expectedAdBreakDurationMs = void 0;
5730
5746
  this.currentAdBreakStartWallClockMs = void 0;
5747
+ this.scteAdBreakEndWallClockMs = void 0;
5731
5748
  this.clearAdStartTimer();
5732
5749
  this.clearAdStopTimer();
5733
5750
  this.adPodQueue = [];
@@ -5989,10 +6006,25 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5989
6006
  {
5990
6007
  key: "getRemainingAdMs",
5991
6008
  value: function getRemainingAdMs() {
6009
+ var endWallClockMs = this.getAdBreakEndWallClockMs();
6010
+ if (endWallClockMs != null) {
6011
+ return Math.max(0, endWallClockMs - Date.now());
6012
+ }
5992
6013
  if (this.currentAdBreakStartWallClockMs == null) return 0;
5993
6014
  if (this.expectedAdBreakDurationMs == null) return Number.MAX_SAFE_INTEGER;
5994
- var elapsed = Date.now() - this.currentAdBreakStartWallClockMs;
5995
- return Math.max(0, this.expectedAdBreakDurationMs - elapsed);
6015
+ return 0;
6016
+ }
6017
+ },
6018
+ {
6019
+ key: "getAdBreakEndWallClockMs",
6020
+ value: function getAdBreakEndWallClockMs() {
6021
+ if (this.scteAdBreakEndWallClockMs != null) {
6022
+ return this.scteAdBreakEndWallClockMs;
6023
+ }
6024
+ if (this.expectedAdBreakDurationMs == null || this.currentAdBreakStartWallClockMs == null) {
6025
+ return void 0;
6026
+ }
6027
+ return this.currentAdBreakStartWallClockMs + this.expectedAdBreakDurationMs;
5996
6028
  }
5997
6029
  },
5998
6030
  {