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.
@@ -9,6 +9,7 @@ declare class StormcloudVideoPlayer {
9
9
  private inAdBreak;
10
10
  private currentAdBreakStartWallClockMs;
11
11
  private expectedAdBreakDurationMs;
12
+ private scteAdBreakEndWallClockMs;
12
13
  private adStopTimerId;
13
14
  private adStartTimerId;
14
15
  private adFailsafeTimerId;
@@ -115,6 +116,9 @@ declare class StormcloudVideoPlayer {
115
116
  private activatePendingScte35CuesForFragment;
116
117
  private onScte35Marker;
117
118
  private startScte35AdBreak;
119
+ private resolveScteBreakStartWallClockMs;
120
+ private setAdBreakDurationBoundary;
121
+ private scheduleAdStopAtBreakBoundary;
118
122
  private parseCueOutDuration;
119
123
  private parseCueOutCont;
120
124
  private parseAttributeList;
@@ -198,6 +202,7 @@ declare class StormcloudVideoPlayer {
198
202
  private selectVastTagsForBreak;
199
203
  private logAdState;
200
204
  private getWallClockRemainingAdMs;
205
+ private getAdBreakEndWallClockMs;
201
206
  private getDurationBudgetRemainingMs;
202
207
  private getLoadedAdDurationMs;
203
208
  private adFitsRemainingBudget;
@@ -3571,7 +3571,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3571
3571
  _this.showAds = true;
3572
3572
  _this.resetGamNoFillCounter();
3573
3573
  if (_this.inAdBreak && _this.expectedAdBreakDurationMs != null && _this.adStopTimerId == null) {
3574
- _this.scheduleAdStopCountdown(_this.getRemainingAdMs());
3574
+ _this.scheduleAdStopAtBreakBoundary();
3575
3575
  if (_this.config.debugAdTiming) {
3576
3576
  console.log("[StormcloudVideoPlayer] Starting ad break timer on content_pause (first ad starting)");
3577
3577
  }
@@ -4226,12 +4226,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4226
4226
  if (marker.durationSeconds != null) {
4227
4227
  var newDurationMs = marker.durationSeconds * 1e3;
4228
4228
  if (this.expectedAdBreakDurationMs == null || newDurationMs > this.expectedAdBreakDurationMs) {
4229
- this.expectedAdBreakDurationMs = newDurationMs;
4230
- var elapsedMs = this.currentAdBreakStartWallClockMs != null ? Date.now() - this.currentAdBreakStartWallClockMs : 0;
4231
- var remainingMs = Math.max(0, newDurationMs - elapsedMs);
4232
- this.scheduleAdStopCountdown(remainingMs);
4229
+ this.setAdBreakDurationBoundary(newDurationMs);
4230
+ this.scheduleAdStopAtBreakBoundary();
4233
4231
  if (this.config.debugAdTiming) {
4234
- console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(newDurationMs, "ms, remaining: ").concat(remainingMs, "ms"));
4232
+ console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(newDurationMs, "ms, remaining: ").concat(this.getWallClockRemainingAdMs(), "ms"));
4235
4233
  }
4236
4234
  }
4237
4235
  }
@@ -4305,13 +4303,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4305
4303
  }
4306
4304
  if (marker.type === "progress" && this.inAdBreak) {
4307
4305
  if (marker.durationSeconds != null) {
4308
- this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
4309
- }
4310
- if (this.expectedAdBreakDurationMs != null && this.currentAdBreakStartWallClockMs != null) {
4311
- var elapsedMs1 = Date.now() - this.currentAdBreakStartWallClockMs;
4312
- var remainingMs1 = Math.max(0, this.expectedAdBreakDurationMs - elapsedMs1);
4313
- this.scheduleAdStopCountdown(remainingMs1);
4306
+ this.setAdBreakDurationBoundary(marker.durationSeconds * 1e3);
4314
4307
  }
4308
+ this.scheduleAdStopAtBreakBoundary();
4315
4309
  if (!this.adPlayer.isAdPlaying() && this.activeAdRequestToken === null && this.adRequestQueue.length > 0 && this.hasTimeToStartAnotherAd()) {
4316
4310
  this.tryNextAvailableAdWithRateLimit();
4317
4311
  }
@@ -4335,15 +4329,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4335
4329
  activeAdRequest: this.activeAdRequestToken !== null
4336
4330
  });
4337
4331
  }
4338
- if (adPlaying || remaining > 1e3 && hasQueuedAds) {
4339
- if (this.config.debugAdTiming) {
4340
- console.log("[StormcloudVideoPlayer] Ignoring premature SCTE-35 end marker - ads still active");
4341
- }
4342
- return;
4343
- }
4344
- this.inAdBreak = false;
4345
- this.expectedAdBreakDurationMs = void 0;
4346
- this.currentAdBreakStartWallClockMs = void 0;
4332
+ this.scteAdBreakEndWallClockMs = Date.now();
4347
4333
  this.clearAdStartTimer();
4348
4334
  this.clearAdStopTimer();
4349
4335
  if (adPlaying) {
@@ -4360,14 +4346,48 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4360
4346
  this.inAdBreak = true;
4361
4347
  this.activeScte35BreakKey = cueKey !== null && cueKey !== void 0 ? cueKey : this.pendingScte35CueKey;
4362
4348
  this.scheduledScte35BreakKey = void 0;
4363
- this.expectedAdBreakDurationMs = durationMs;
4364
- this.currentAdBreakStartWallClockMs = Date.now();
4349
+ this.currentAdBreakStartWallClockMs = this.resolveScteBreakStartWallClockMs(marker);
4350
+ this.setAdBreakDurationBoundary(durationMs);
4365
4351
  this.handleAdStart(marker);
4366
- if (this.expectedAdBreakDurationMs != null) {
4367
- this.scheduleAdStopCountdown(this.expectedAdBreakDurationMs);
4352
+ this.scheduleAdStopAtBreakBoundary();
4353
+ }
4354
+ },
4355
+ {
4356
+ key: "resolveScteBreakStartWallClockMs",
4357
+ value: function resolveScteBreakStartWallClockMs(marker) {
4358
+ var nowWallClockMs = Date.now();
4359
+ if (typeof marker.ptsSeconds !== "number") {
4360
+ return nowWallClockMs;
4361
+ }
4362
+ var nowMs = this.video.currentTime * 1e3;
4363
+ var estimatedCurrentPtsMs = nowMs - this.ptsDriftEmaMs;
4364
+ var deltaMs = marker.ptsSeconds * 1e3 - estimatedCurrentPtsMs;
4365
+ if (!Number.isFinite(deltaMs)) {
4366
+ return nowWallClockMs;
4367
+ }
4368
+ return nowWallClockMs + Math.floor(deltaMs);
4369
+ }
4370
+ },
4371
+ {
4372
+ key: "setAdBreakDurationBoundary",
4373
+ value: function setAdBreakDurationBoundary(durationMs) {
4374
+ this.expectedAdBreakDurationMs = durationMs;
4375
+ if (durationMs != null && this.currentAdBreakStartWallClockMs != null) {
4376
+ this.scteAdBreakEndWallClockMs = this.currentAdBreakStartWallClockMs + durationMs;
4377
+ } else {
4378
+ this.scteAdBreakEndWallClockMs = void 0;
4368
4379
  }
4369
4380
  }
4370
4381
  },
4382
+ {
4383
+ key: "scheduleAdStopAtBreakBoundary",
4384
+ value: function scheduleAdStopAtBreakBoundary() {
4385
+ if (this.expectedAdBreakDurationMs == null) {
4386
+ return;
4387
+ }
4388
+ this.scheduleAdStopCountdown(this.getWallClockRemainingAdMs());
4389
+ }
4390
+ },
4371
4391
  {
4372
4392
  key: "parseCueOutDuration",
4373
4393
  value: function parseCueOutDuration(value) {
@@ -6015,7 +6035,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6015
6035
  currentVolume = this.video.volume;
6016
6036
  this.adPlayer.updateOriginalMutedState(currentMuted, currentVolume);
6017
6037
  this.inAdBreak = true;
6018
- this.currentAdBreakStartWallClockMs = Date.now();
6019
6038
  this.adBreakPlayedDurationMs = 0;
6020
6039
  this.currentAdIndex = 0;
6021
6040
  this.totalAdsInBreak = 0;
@@ -6121,7 +6140,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6121
6140
  _state.sent();
6122
6141
  this.markAdStarted();
6123
6142
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6124
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
6143
+ this.scheduleAdStopAtBreakBoundary();
6125
6144
  }
6126
6145
  adVolume = currentMuted ? 0 : currentVolume;
6127
6146
  this.adPlayer.setAdVolume(adVolume);
@@ -6181,7 +6200,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6181
6200
  _state.sent();
6182
6201
  this.markAdStarted();
6183
6202
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6184
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
6203
+ this.scheduleAdStopAtBreakBoundary();
6185
6204
  }
6186
6205
  adVolume1 = currentMuted ? 0 : currentVolume;
6187
6206
  this.adPlayer.setAdVolume(adVolume1);
@@ -6254,7 +6273,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6254
6273
  _state.sent();
6255
6274
  this.markAdStarted();
6256
6275
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6257
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
6276
+ this.scheduleAdStopAtBreakBoundary();
6258
6277
  }
6259
6278
  adVolume2 = currentMuted ? 0 : currentVolume;
6260
6279
  this.adPlayer.setAdVolume(adVolume2);
@@ -6637,7 +6656,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6637
6656
  _state.sent();
6638
6657
  this.markAdStarted();
6639
6658
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6640
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
6659
+ this.scheduleAdStopAtBreakBoundary();
6641
6660
  }
6642
6661
  this.adPlayer.setAdVolume(this.getAdAudioVolume());
6643
6662
  this.consecutiveFailures = 0;
@@ -7165,19 +7184,15 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7165
7184
  {
7166
7185
  key: "ensureAdStoppedByTimer",
7167
7186
  value: function ensureAdStoppedByTimer() {
7168
- var _this_config_adBreakCheckIntervalMs, _this_expectedAdBreakDurationMs;
7187
+ var _this_config_adBreakCheckIntervalMs, _this_getAdBreakEndWallClockMs;
7169
7188
  if (!this.inAdBreak) return;
7170
7189
  this.adStopTimerId = void 0;
7171
7190
  var adPlaying = this.adPlayer.isAdPlaying();
7172
7191
  var checkIntervalMs = Math.max(250, Math.floor((_this_config_adBreakCheckIntervalMs = this.config.adBreakCheckIntervalMs) !== null && _this_config_adBreakCheckIntervalMs !== void 0 ? _this_config_adBreakCheckIntervalMs : 1e3));
7173
7192
  var maxExtensionMsConfig = this.config.maxAdBreakExtensionMs;
7174
7193
  var maxExtensionMs = typeof maxExtensionMsConfig === "number" && maxExtensionMsConfig > 0 ? maxExtensionMsConfig : 0;
7175
- var elapsedSinceStartMs = 0;
7176
- if (this.currentAdBreakStartWallClockMs != null) {
7177
- elapsedSinceStartMs = Date.now() - this.currentAdBreakStartWallClockMs;
7178
- }
7179
- var expectedDurationMs = (_this_expectedAdBreakDurationMs = this.expectedAdBreakDurationMs) !== null && _this_expectedAdBreakDurationMs !== void 0 ? _this_expectedAdBreakDurationMs : 0;
7180
- var overrunMs = Math.max(0, elapsedSinceStartMs - expectedDurationMs);
7194
+ var endWallClockMs = (_this_getAdBreakEndWallClockMs = this.getAdBreakEndWallClockMs()) !== null && _this_getAdBreakEndWallClockMs !== void 0 ? _this_getAdBreakEndWallClockMs : Date.now();
7195
+ var overrunMs = Math.max(0, Date.now() - endWallClockMs);
7181
7196
  var shouldExtendAdBreak = adPlaying && overrunMs < maxExtensionMs;
7182
7197
  if (shouldExtendAdBreak) {
7183
7198
  this.scheduleAdStopCountdown(checkIntervalMs);
@@ -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
  this.consecutiveFailures = 0;
@@ -7505,7 +7520,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7505
7520
  _state.sent();
7506
7521
  this.markAdStarted();
7507
7522
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
7508
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
7523
+ this.scheduleAdStopAtBreakBoundary();
7509
7524
  }
7510
7525
  this.adPlayer.setAdVolume(this.getAdAudioVolume());
7511
7526
  return [
@@ -7651,6 +7666,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7651
7666
  this.scheduledScte35BreakKey = void 0;
7652
7667
  this.expectedAdBreakDurationMs = void 0;
7653
7668
  this.currentAdBreakStartWallClockMs = void 0;
7669
+ this.scteAdBreakEndWallClockMs = void 0;
7654
7670
  this.clearAdStartTimer();
7655
7671
  this.clearAdStopTimer();
7656
7672
  this.adPodQueue = [];
@@ -7838,11 +7854,23 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7838
7854
  {
7839
7855
  key: "getWallClockRemainingAdMs",
7840
7856
  value: function getWallClockRemainingAdMs() {
7857
+ var endWallClockMs = this.getAdBreakEndWallClockMs();
7858
+ if (endWallClockMs != null) {
7859
+ return Math.max(0, endWallClockMs - Date.now());
7860
+ }
7861
+ return 0;
7862
+ }
7863
+ },
7864
+ {
7865
+ key: "getAdBreakEndWallClockMs",
7866
+ value: function getAdBreakEndWallClockMs() {
7867
+ if (this.scteAdBreakEndWallClockMs != null) {
7868
+ return this.scteAdBreakEndWallClockMs;
7869
+ }
7841
7870
  if (this.expectedAdBreakDurationMs == null || this.currentAdBreakStartWallClockMs == null) {
7842
- return 0;
7871
+ return void 0;
7843
7872
  }
7844
- var elapsed = Date.now() - this.currentAdBreakStartWallClockMs;
7845
- return Math.max(0, this.expectedAdBreakDurationMs - elapsed);
7873
+ return this.currentAdBreakStartWallClockMs + this.expectedAdBreakDurationMs;
7846
7874
  }
7847
7875
  },
7848
7876
  {