stormcloud-video-player 0.8.14 → 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.
@@ -2695,6 +2695,7 @@ function logBrowserInfo() {
2695
2695
  // src/utils/ctvVastSignals.ts
2696
2696
  var AIRY_ANDROID_APP_ID = "com.freeairytv.android";
2697
2697
  var AIRY_APP_NAME = "AiryTV Movies & TV";
2698
+ var AIRY_DEFAULT_CONTENT_URL = "https://live.airy.tv";
2698
2699
  var CTV_SESSION_STORAGE_KEY = "stormcloud.ctv.sid";
2699
2700
  var DEVICE_ID_STORAGE_KEYS = [
2700
2701
  "rdid",
@@ -2712,8 +2713,9 @@ function resolveCtvVastSignals() {
2712
2713
  var bridgeSignals = readNativeBridgeSignals();
2713
2714
  var deviceId = bridgeSignals.deviceId || readStoredDeviceId();
2714
2715
  var deviceIdType = bridgeSignals.deviceIdType || readStoredString("deviceIdType") || inferDeviceIdType();
2716
+ var contentUrl = bridgeSignals.contentUrl || readStoredString("contentUrl") || AIRY_DEFAULT_CONTENT_URL;
2715
2717
  return _object_spread_props(_object_spread({
2716
- contentUrl: "https://".concat(AIRY_ANDROID_APP_ID, ".example.com"),
2718
+ contentUrl: contentUrl,
2717
2719
  appId: AIRY_ANDROID_APP_ID,
2718
2720
  appName: AIRY_APP_NAME,
2719
2721
  sessionId: getOrCreateCtvSessionId()
@@ -2764,6 +2766,12 @@ function readNativeBridgeSignals() {
2764
2766
  try {
2765
2767
  for(var _iterator = candidates[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2766
2768
  var source = _step.value;
2769
+ var contentUrl = readBridgeValue(source, [
2770
+ "contentUrl",
2771
+ "url",
2772
+ "videoUrl",
2773
+ "canonicalUrl"
2774
+ ]) || void 0;
2767
2775
  var deviceId = readBridgeValue(source, [
2768
2776
  "rdid",
2769
2777
  "ifa",
@@ -2771,7 +2779,7 @@ function readNativeBridgeSignals() {
2771
2779
  "adId",
2772
2780
  "deviceId"
2773
2781
  ]) || void 0;
2774
- if (!deviceId) continue;
2782
+ if (!contentUrl && !deviceId) continue;
2775
2783
  var deviceIdType = readBridgeValue(source, [
2776
2784
  "idtype",
2777
2785
  "deviceIdType",
@@ -2783,11 +2791,13 @@ function readNativeBridgeSignals() {
2783
2791
  "limitedAdTracking",
2784
2792
  "lat"
2785
2793
  ]);
2786
- return _object_spread({
2794
+ return _object_spread({}, contentUrl ? {
2795
+ contentUrl: contentUrl
2796
+ } : {}, deviceId ? {
2787
2797
  deviceId: deviceId
2788
- }, deviceIdType ? {
2798
+ } : {}, deviceId && deviceIdType ? {
2789
2799
  deviceIdType: deviceIdType
2790
- } : {}, limitAdTracking != null ? {
2800
+ } : {}, deviceId && limitAdTracking != null ? {
2791
2801
  limitAdTracking: limitAdTracking
2792
2802
  } : {});
2793
2803
  }
@@ -3547,7 +3557,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3547
3557
  _this.showAds = true;
3548
3558
  _this.resetGamNoFillCounter();
3549
3559
  if (_this.inAdBreak && _this.expectedAdBreakDurationMs != null && _this.adStopTimerId == null) {
3550
- _this.scheduleAdStopCountdown(_this.getRemainingAdMs());
3560
+ _this.scheduleAdStopAtBreakBoundary();
3551
3561
  if (_this.config.debugAdTiming) {
3552
3562
  console.log("[StormcloudVideoPlayer] Starting ad break timer on content_pause (first ad starting)");
3553
3563
  }
@@ -4202,12 +4212,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4202
4212
  if (marker.durationSeconds != null) {
4203
4213
  var newDurationMs = marker.durationSeconds * 1e3;
4204
4214
  if (this.expectedAdBreakDurationMs == null || newDurationMs > this.expectedAdBreakDurationMs) {
4205
- this.expectedAdBreakDurationMs = newDurationMs;
4206
- var elapsedMs = this.currentAdBreakStartWallClockMs != null ? Date.now() - this.currentAdBreakStartWallClockMs : 0;
4207
- var remainingMs = Math.max(0, newDurationMs - elapsedMs);
4208
- this.scheduleAdStopCountdown(remainingMs);
4215
+ this.setAdBreakDurationBoundary(newDurationMs);
4216
+ this.scheduleAdStopAtBreakBoundary();
4209
4217
  if (this.config.debugAdTiming) {
4210
- console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(newDurationMs, "ms, remaining: ").concat(remainingMs, "ms"));
4218
+ console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(newDurationMs, "ms, remaining: ").concat(this.getWallClockRemainingAdMs(), "ms"));
4211
4219
  }
4212
4220
  }
4213
4221
  }
@@ -4281,13 +4289,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4281
4289
  }
4282
4290
  if (marker.type === "progress" && this.inAdBreak) {
4283
4291
  if (marker.durationSeconds != null) {
4284
- this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
4285
- }
4286
- if (this.expectedAdBreakDurationMs != null && this.currentAdBreakStartWallClockMs != null) {
4287
- var elapsedMs1 = Date.now() - this.currentAdBreakStartWallClockMs;
4288
- var remainingMs1 = Math.max(0, this.expectedAdBreakDurationMs - elapsedMs1);
4289
- this.scheduleAdStopCountdown(remainingMs1);
4292
+ this.setAdBreakDurationBoundary(marker.durationSeconds * 1e3);
4290
4293
  }
4294
+ this.scheduleAdStopAtBreakBoundary();
4291
4295
  if (!this.adPlayer.isAdPlaying() && this.activeAdRequestToken === null && this.adRequestQueue.length > 0 && this.hasTimeToStartAnotherAd()) {
4292
4296
  this.tryNextAvailableAdWithRateLimit();
4293
4297
  }
@@ -4311,15 +4315,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4311
4315
  activeAdRequest: this.activeAdRequestToken !== null
4312
4316
  });
4313
4317
  }
4314
- if (adPlaying || remaining > 1e3 && hasQueuedAds) {
4315
- if (this.config.debugAdTiming) {
4316
- console.log("[StormcloudVideoPlayer] Ignoring premature SCTE-35 end marker - ads still active");
4317
- }
4318
- return;
4319
- }
4320
- this.inAdBreak = false;
4321
- this.expectedAdBreakDurationMs = void 0;
4322
- this.currentAdBreakStartWallClockMs = void 0;
4318
+ this.scteAdBreakEndWallClockMs = Date.now();
4323
4319
  this.clearAdStartTimer();
4324
4320
  this.clearAdStopTimer();
4325
4321
  if (adPlaying) {
@@ -4336,12 +4332,46 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4336
4332
  this.inAdBreak = true;
4337
4333
  this.activeScte35BreakKey = cueKey !== null && cueKey !== void 0 ? cueKey : this.pendingScte35CueKey;
4338
4334
  this.scheduledScte35BreakKey = void 0;
4339
- this.expectedAdBreakDurationMs = durationMs;
4340
- this.currentAdBreakStartWallClockMs = Date.now();
4335
+ this.currentAdBreakStartWallClockMs = this.resolveScteBreakStartWallClockMs(marker);
4336
+ this.setAdBreakDurationBoundary(durationMs);
4341
4337
  this.handleAdStart(marker);
4342
- if (this.expectedAdBreakDurationMs != null) {
4343
- this.scheduleAdStopCountdown(this.expectedAdBreakDurationMs);
4338
+ this.scheduleAdStopAtBreakBoundary();
4339
+ }
4340
+ },
4341
+ {
4342
+ key: "resolveScteBreakStartWallClockMs",
4343
+ value: function resolveScteBreakStartWallClockMs(marker) {
4344
+ var nowWallClockMs = Date.now();
4345
+ if (typeof marker.ptsSeconds !== "number") {
4346
+ return nowWallClockMs;
4347
+ }
4348
+ var nowMs = this.video.currentTime * 1e3;
4349
+ var estimatedCurrentPtsMs = nowMs - this.ptsDriftEmaMs;
4350
+ var deltaMs = marker.ptsSeconds * 1e3 - estimatedCurrentPtsMs;
4351
+ if (!Number.isFinite(deltaMs)) {
4352
+ return nowWallClockMs;
4353
+ }
4354
+ return nowWallClockMs + Math.floor(deltaMs);
4355
+ }
4356
+ },
4357
+ {
4358
+ key: "setAdBreakDurationBoundary",
4359
+ value: function setAdBreakDurationBoundary(durationMs) {
4360
+ this.expectedAdBreakDurationMs = durationMs;
4361
+ if (durationMs != null && this.currentAdBreakStartWallClockMs != null) {
4362
+ this.scteAdBreakEndWallClockMs = this.currentAdBreakStartWallClockMs + durationMs;
4363
+ } else {
4364
+ this.scteAdBreakEndWallClockMs = void 0;
4365
+ }
4366
+ }
4367
+ },
4368
+ {
4369
+ key: "scheduleAdStopAtBreakBoundary",
4370
+ value: function scheduleAdStopAtBreakBoundary() {
4371
+ if (this.expectedAdBreakDurationMs == null) {
4372
+ return;
4344
4373
  }
4374
+ this.scheduleAdStopCountdown(this.getWallClockRemainingAdMs());
4345
4375
  }
4346
4376
  },
4347
4377
  {
@@ -5991,7 +6021,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5991
6021
  currentVolume = this.video.volume;
5992
6022
  this.adPlayer.updateOriginalMutedState(currentMuted, currentVolume);
5993
6023
  this.inAdBreak = true;
5994
- this.currentAdBreakStartWallClockMs = Date.now();
5995
6024
  this.adBreakPlayedDurationMs = 0;
5996
6025
  this.currentAdIndex = 0;
5997
6026
  this.totalAdsInBreak = 0;
@@ -6097,7 +6126,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6097
6126
  _state.sent();
6098
6127
  this.markAdStarted();
6099
6128
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6100
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
6129
+ this.scheduleAdStopAtBreakBoundary();
6101
6130
  }
6102
6131
  adVolume = currentMuted ? 0 : currentVolume;
6103
6132
  this.adPlayer.setAdVolume(adVolume);
@@ -6157,7 +6186,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6157
6186
  _state.sent();
6158
6187
  this.markAdStarted();
6159
6188
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6160
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
6189
+ this.scheduleAdStopAtBreakBoundary();
6161
6190
  }
6162
6191
  adVolume1 = currentMuted ? 0 : currentVolume;
6163
6192
  this.adPlayer.setAdVolume(adVolume1);
@@ -6230,7 +6259,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6230
6259
  _state.sent();
6231
6260
  this.markAdStarted();
6232
6261
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6233
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
6262
+ this.scheduleAdStopAtBreakBoundary();
6234
6263
  }
6235
6264
  adVolume2 = currentMuted ? 0 : currentVolume;
6236
6265
  this.adPlayer.setAdVolume(adVolume2);
@@ -6613,7 +6642,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6613
6642
  _state.sent();
6614
6643
  this.markAdStarted();
6615
6644
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
6616
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
6645
+ this.scheduleAdStopAtBreakBoundary();
6617
6646
  }
6618
6647
  this.adPlayer.setAdVolume(this.getAdAudioVolume());
6619
6648
  this.consecutiveFailures = 0;
@@ -7141,19 +7170,15 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7141
7170
  {
7142
7171
  key: "ensureAdStoppedByTimer",
7143
7172
  value: function ensureAdStoppedByTimer() {
7144
- var _this_config_adBreakCheckIntervalMs, _this_expectedAdBreakDurationMs;
7173
+ var _this_config_adBreakCheckIntervalMs, _this_getAdBreakEndWallClockMs;
7145
7174
  if (!this.inAdBreak) return;
7146
7175
  this.adStopTimerId = void 0;
7147
7176
  var adPlaying = this.adPlayer.isAdPlaying();
7148
7177
  var checkIntervalMs = Math.max(250, Math.floor((_this_config_adBreakCheckIntervalMs = this.config.adBreakCheckIntervalMs) !== null && _this_config_adBreakCheckIntervalMs !== void 0 ? _this_config_adBreakCheckIntervalMs : 1e3));
7149
7178
  var maxExtensionMsConfig = this.config.maxAdBreakExtensionMs;
7150
7179
  var maxExtensionMs = typeof maxExtensionMsConfig === "number" && maxExtensionMsConfig > 0 ? maxExtensionMsConfig : 0;
7151
- var elapsedSinceStartMs = 0;
7152
- if (this.currentAdBreakStartWallClockMs != null) {
7153
- elapsedSinceStartMs = Date.now() - this.currentAdBreakStartWallClockMs;
7154
- }
7155
- var expectedDurationMs = (_this_expectedAdBreakDurationMs = this.expectedAdBreakDurationMs) !== null && _this_expectedAdBreakDurationMs !== void 0 ? _this_expectedAdBreakDurationMs : 0;
7156
- var overrunMs = Math.max(0, elapsedSinceStartMs - expectedDurationMs);
7180
+ var endWallClockMs = (_this_getAdBreakEndWallClockMs = this.getAdBreakEndWallClockMs()) !== null && _this_getAdBreakEndWallClockMs !== void 0 ? _this_getAdBreakEndWallClockMs : Date.now();
7181
+ var overrunMs = Math.max(0, Date.now() - endWallClockMs);
7157
7182
  var shouldExtendAdBreak = adPlaying && overrunMs < maxExtensionMs;
7158
7183
  if (shouldExtendAdBreak) {
7159
7184
  this.scheduleAdStopCountdown(checkIntervalMs);
@@ -7429,7 +7454,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7429
7454
  _state.sent();
7430
7455
  this.markAdStarted();
7431
7456
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
7432
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
7457
+ this.scheduleAdStopAtBreakBoundary();
7433
7458
  }
7434
7459
  this.adPlayer.setAdVolume(this.getAdAudioVolume());
7435
7460
  this.consecutiveFailures = 0;
@@ -7481,7 +7506,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7481
7506
  _state.sent();
7482
7507
  this.markAdStarted();
7483
7508
  if (this.expectedAdBreakDurationMs != null && this.adStopTimerId == null) {
7484
- this.scheduleAdStopCountdown(this.getRemainingAdMs());
7509
+ this.scheduleAdStopAtBreakBoundary();
7485
7510
  }
7486
7511
  this.adPlayer.setAdVolume(this.getAdAudioVolume());
7487
7512
  return [
@@ -7627,6 +7652,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7627
7652
  this.scheduledScte35BreakKey = void 0;
7628
7653
  this.expectedAdBreakDurationMs = void 0;
7629
7654
  this.currentAdBreakStartWallClockMs = void 0;
7655
+ this.scteAdBreakEndWallClockMs = void 0;
7630
7656
  this.clearAdStartTimer();
7631
7657
  this.clearAdStopTimer();
7632
7658
  this.adPodQueue = [];
@@ -7814,11 +7840,23 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7814
7840
  {
7815
7841
  key: "getWallClockRemainingAdMs",
7816
7842
  value: function getWallClockRemainingAdMs() {
7843
+ var endWallClockMs = this.getAdBreakEndWallClockMs();
7844
+ if (endWallClockMs != null) {
7845
+ return Math.max(0, endWallClockMs - Date.now());
7846
+ }
7847
+ return 0;
7848
+ }
7849
+ },
7850
+ {
7851
+ key: "getAdBreakEndWallClockMs",
7852
+ value: function getAdBreakEndWallClockMs() {
7853
+ if (this.scteAdBreakEndWallClockMs != null) {
7854
+ return this.scteAdBreakEndWallClockMs;
7855
+ }
7817
7856
  if (this.expectedAdBreakDurationMs == null || this.currentAdBreakStartWallClockMs == null) {
7818
- return 0;
7857
+ return void 0;
7819
7858
  }
7820
- var elapsed = Date.now() - this.currentAdBreakStartWallClockMs;
7821
- return Math.max(0, this.expectedAdBreakDurationMs - elapsed);
7859
+ return this.currentAdBreakStartWallClockMs + this.expectedAdBreakDurationMs;
7822
7860
  }
7823
7861
  },
7824
7862
  {