stormcloud-video-player 0.5.21 → 0.5.23

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.
package/lib/index.cjs CHANGED
@@ -1048,6 +1048,106 @@ function createEmptyTrackingState() {
1048
1048
  complete: false
1049
1049
  };
1050
1050
  }
1051
+ function firePixelWithRetry(url) {
1052
+ var retries = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 2, delayMs = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 500, logPrefix = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "[VastParser]";
1053
+ return _async_to_generator(function() {
1054
+ var _loop, attempt, _ret;
1055
+ return _ts_generator(this, function(_state) {
1056
+ switch(_state.label){
1057
+ case 0:
1058
+ _loop = function(attempt) {
1059
+ var unused;
1060
+ return _ts_generator(this, function(_state) {
1061
+ switch(_state.label){
1062
+ case 0:
1063
+ _state.trys.push([
1064
+ 0,
1065
+ 2,
1066
+ ,
1067
+ 6
1068
+ ]);
1069
+ return [
1070
+ 4,
1071
+ fetch(url, {
1072
+ method: "GET",
1073
+ mode: "no-cors",
1074
+ cache: "no-cache",
1075
+ keepalive: true
1076
+ })
1077
+ ];
1078
+ case 1:
1079
+ _state.sent();
1080
+ return [
1081
+ 2,
1082
+ {
1083
+ v: void void 0
1084
+ }
1085
+ ];
1086
+ case 2:
1087
+ unused = _state.sent();
1088
+ if (!(attempt < retries)) return [
1089
+ 3,
1090
+ 4
1091
+ ];
1092
+ return [
1093
+ 4,
1094
+ new Promise(function(r) {
1095
+ return setTimeout(r, delayMs * Math.pow(2, attempt));
1096
+ })
1097
+ ];
1098
+ case 3:
1099
+ _state.sent();
1100
+ return [
1101
+ 3,
1102
+ 5
1103
+ ];
1104
+ case 4:
1105
+ console.warn("".concat(logPrefix, " Tracking pixel failed after ").concat(retries + 1, " attempts: ").concat(url));
1106
+ _state.label = 5;
1107
+ case 5:
1108
+ return [
1109
+ 3,
1110
+ 6
1111
+ ];
1112
+ case 6:
1113
+ return [
1114
+ 2
1115
+ ];
1116
+ }
1117
+ });
1118
+ };
1119
+ attempt = 0;
1120
+ _state.label = 1;
1121
+ case 1:
1122
+ if (!(attempt <= retries)) return [
1123
+ 3,
1124
+ 4
1125
+ ];
1126
+ return [
1127
+ 5,
1128
+ _ts_values(_loop(attempt))
1129
+ ];
1130
+ case 2:
1131
+ _ret = _state.sent();
1132
+ if (_type_of(_ret) === "object") return [
1133
+ 2,
1134
+ _ret.v
1135
+ ];
1136
+ _state.label = 3;
1137
+ case 3:
1138
+ attempt++;
1139
+ return [
1140
+ 3,
1141
+ 1
1142
+ ];
1143
+ case 4:
1144
+ return [
1145
+ 2
1146
+ ];
1147
+ }
1148
+ });
1149
+ })();
1150
+ }
1051
1151
  function fireTrackingPixels(urls, sessionId) {
1052
1152
  var logPrefix = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "[VastParser]";
1053
1153
  if (!urls || urls.length === 0) return;
@@ -1057,9 +1157,13 @@ function fireTrackingPixels(urls, sessionId) {
1057
1157
  if (sessionId) {
1058
1158
  trackingUrl = "".concat(trackingUrl).concat(trackingUrl.includes("?") ? "&" : "?", "session_id=").concat(sessionId);
1059
1159
  }
1060
- var img = new Image(1, 1);
1061
- img.onerror = function() {};
1062
- img.src = trackingUrl;
1160
+ if (typeof fetch !== "undefined") {
1161
+ firePixelWithRetry(trackingUrl, 2, 500, logPrefix).catch(function() {});
1162
+ } else {
1163
+ var img = new Image(1, 1);
1164
+ img.onerror = function() {};
1165
+ img.src = trackingUrl;
1166
+ }
1063
1167
  console.log("".concat(logPrefix, " Fired tracking pixel: ").concat(trackingUrl));
1064
1168
  } catch (error) {
1065
1169
  console.warn("".concat(logPrefix, " Error firing tracking pixel:"), error);
@@ -3225,13 +3329,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3225
3329
  }
3226
3330
  }
3227
3331
  _this.adLayer.setAdVolume(_this.adLayer.getOriginalMutedState() ? 1 : _this.adLayer.getOriginalVolume());
3228
- if (_this.isShowingPlaceholder) {
3229
- if (_this.config.debugAdTiming) {
3230
- console.log("[StormcloudVideoPlayer] Hiding placeholder - new ads starting");
3231
- }
3232
- _this.hidePlaceholderLayer();
3233
- _this.adLayer.hidePlaceholder();
3234
- _this.isShowingPlaceholder = false;
3332
+ _this.stopFillerBreakTimer();
3333
+ _this.hidePlaceholderLayer();
3334
+ _this.isShowingPlaceholder = false;
3335
+ if (_this.config.debugAdTiming) {
3336
+ console.log("[StormcloudVideoPlayer] Hiding placeholder - new ads starting");
3235
3337
  }
3236
3338
  });
3237
3339
  this.adLayer.on("content_resume", function() {
@@ -3282,90 +3384,80 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3282
3384
  }
3283
3385
  },
3284
3386
  {
3285
- key: "ensurePlaceholderContainer",
3286
- value: function ensurePlaceholderContainer() {
3287
- if (this.placeholderContainer) {
3288
- return;
3289
- }
3290
- var container = document.createElement("div");
3291
- container.style.position = "absolute";
3292
- container.style.left = "0";
3293
- container.style.top = "0";
3294
- container.style.right = "0";
3295
- container.style.bottom = "0";
3296
- container.style.display = "none";
3297
- container.style.alignItems = "center";
3298
- container.style.justifyContent = "center";
3299
- container.style.pointerEvents = "none";
3300
- container.style.zIndex = "5";
3301
- container.style.backgroundColor = "#000";
3302
- container.style.transition = "opacity 0.3s ease-in-out";
3303
- container.style.opacity = "0";
3304
- if (!this.video.parentElement) {
3305
- if (this.config.debugAdTiming) {
3306
- console.warn("[StormcloudVideoPlayer] Video element has no parent for placeholder container");
3307
- }
3308
- return;
3309
- }
3310
- this.video.parentElement.appendChild(container);
3311
- this.placeholderContainer = container;
3387
+ key: "ensureFillerVideo",
3388
+ value: function ensureFillerVideo() {
3389
+ if (this.fillerVideo) return;
3390
+ if (!this.video.parentElement) return;
3391
+ var filler = document.createElement("video");
3392
+ filler.src = "https://f000.backblazeb2.com/file/AdStormAds/384/Sonifi_Filler.mp4";
3393
+ filler.loop = true;
3394
+ filler.muted = false;
3395
+ filler.playsInline = true;
3396
+ filler.style.position = "absolute";
3397
+ filler.style.left = "0";
3398
+ filler.style.top = "0";
3399
+ filler.style.width = "100%";
3400
+ filler.style.height = "100%";
3401
+ filler.style.objectFit = "cover";
3402
+ filler.style.zIndex = "20";
3403
+ filler.style.display = "none";
3404
+ filler.preload = "auto";
3405
+ this.video.parentElement.appendChild(filler);
3406
+ this.fillerVideo = filler;
3312
3407
  }
3313
3408
  },
3314
3409
  {
3315
3410
  key: "showPlaceholderLayer",
3316
3411
  value: function showPlaceholderLayer() {
3317
3412
  var _this = this;
3318
- this.ensurePlaceholderContainer();
3319
- if (!this.placeholderContainer) {
3320
- return;
3321
- }
3413
+ this.ensureFillerVideo();
3414
+ if (!this.fillerVideo) return;
3322
3415
  if (!this.video.muted) {
3323
3416
  this.video.muted = true;
3324
3417
  this.video.volume = 0;
3325
- if (this.config.debugAdTiming) {
3326
- console.log("[StormcloudVideoPlayer] Muted video when showing placeholder");
3327
- }
3328
- }
3329
- var wasHidden = this.placeholderContainer.style.display === "none" || this.placeholderContainer.style.opacity === "0";
3330
- if (wasHidden) {
3331
- this.placeholderContainer.style.transition = "none";
3332
- } else {
3333
- this.placeholderContainer.style.transition = "opacity 0.3s ease-in-out";
3334
- }
3335
- this.placeholderContainer.style.backgroundColor = "#000";
3336
- this.placeholderContainer.style.display = "flex";
3337
- this.placeholderContainer.offsetHeight;
3338
- this.placeholderContainer.style.opacity = "1";
3339
- this.placeholderContainer.style.pointerEvents = "auto";
3340
- if (wasHidden) {
3341
- requestAnimationFrame(function() {
3342
- if (_this.placeholderContainer) {
3343
- _this.placeholderContainer.style.transition = "opacity 0.3s ease-in-out";
3344
- }
3345
- });
3346
3418
  }
3419
+ this.fillerVideo.style.display = "block";
3420
+ this.fillerVideo.play().catch(function() {
3421
+ if (_this.fillerVideo) {
3422
+ _this.fillerVideo.style.display = "none";
3423
+ }
3424
+ });
3347
3425
  if (this.config.debugAdTiming) {
3348
- console.log("[StormcloudVideoPlayer] Showing placeholder layer");
3426
+ console.log("[StormcloudVideoPlayer] Showing filler video layer");
3349
3427
  }
3350
3428
  }
3351
3429
  },
3352
3430
  {
3353
3431
  key: "hidePlaceholderLayer",
3354
3432
  value: function hidePlaceholderLayer() {
3355
- var _this = this;
3356
- if (!this.placeholderContainer) {
3357
- return;
3358
- }
3359
- this.placeholderContainer.style.opacity = "0";
3360
- setTimeout(function() {
3361
- if (_this.placeholderContainer) {
3362
- _this.placeholderContainer.style.display = "none";
3363
- _this.placeholderContainer.style.pointerEvents = "none";
3364
- _this.placeholderContainer.style.backgroundColor = "#000";
3365
- }
3366
- }, 300);
3433
+ if (!this.fillerVideo) return;
3434
+ this.fillerVideo.style.display = "none";
3435
+ this.fillerVideo.pause();
3436
+ this.fillerVideo.currentTime = 0;
3367
3437
  if (this.config.debugAdTiming) {
3368
- console.log("[StormcloudVideoPlayer] Hiding placeholder layer");
3438
+ console.log("[StormcloudVideoPlayer] Hiding filler video layer");
3439
+ }
3440
+ }
3441
+ },
3442
+ {
3443
+ key: "startFillerBreakTimer",
3444
+ value: function startFillerBreakTimer(durationMs) {
3445
+ var _this = this;
3446
+ this.stopFillerBreakTimer();
3447
+ this.showPlaceholderLayer();
3448
+ this.fillerBreakTimerId = setTimeout(function() {
3449
+ _this.fillerBreakTimerId = void 0;
3450
+ _this.hidePlaceholderLayer();
3451
+ if (_this.inAdBreak) _this.handleAdPodComplete();
3452
+ }, durationMs);
3453
+ }
3454
+ },
3455
+ {
3456
+ key: "stopFillerBreakTimer",
3457
+ value: function stopFillerBreakTimer() {
3458
+ if (this.fillerBreakTimerId !== void 0) {
3459
+ clearTimeout(this.fillerBreakTimerId);
3460
+ this.fillerBreakTimerId = void 0;
3369
3461
  }
3370
3462
  }
3371
3463
  },
@@ -3378,6 +3470,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3378
3470
  this.video.autoplay = !!this.config.autoplay;
3379
3471
  this.video.muted = !!this.config.muted;
3380
3472
  this.adLayer.initialize();
3473
+ this.ensureFillerVideo();
3381
3474
  this.adLayer.updateOriginalMutedState(this.video.muted, this.video.volume);
3382
3475
  this.attachAdLayerEventListeners();
3383
3476
  this.timeUpdateHandler = function() {
@@ -4297,7 +4390,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4297
4390
  this.totalAdsInBreak = 1;
4298
4391
  this.adPodQueue = [];
4299
4392
  this.showAds = true;
4300
- this.showPlaceholderLayer();
4393
+ if (adBreakDurationMs != null) {
4394
+ this.startFillerBreakTimer(adBreakDurationMs);
4395
+ } else {
4396
+ this.showPlaceholderLayer();
4397
+ }
4301
4398
  this.adLayer.showPlaceholder();
4302
4399
  if (this.expectedAdBreakDurationMs == null && adBreakDurationMs != null) {
4303
4400
  this.expectedAdBreakDurationMs = adBreakDurationMs;
@@ -4399,7 +4496,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4399
4496
  key: "stopContinuousFetching",
4400
4497
  value: function stopContinuousFetching() {
4401
4498
  this.continuousFetchingActive = false;
4402
- this.hidePlaceholderLayer();
4403
4499
  if (this.config.debugAdTiming) {
4404
4500
  console.log("[CONTINUOUS-FETCH] \uD83D\uDED1 Stopping continuous ad fetching");
4405
4501
  }
@@ -4590,13 +4686,23 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4590
4686
  key: "showPlaceholderAndWaitForAds",
4591
4687
  value: function showPlaceholderAndWaitForAds() {
4592
4688
  return _async_to_generator(function() {
4593
- var remaining, waitTime, checkInterval, maxChecks, i, bids, unused;
4689
+ var remaining, waitTime, stillRemaining2, checkInterval, maxChecks, i, bids, unused, stillRemaining;
4594
4690
  return _ts_generator(this, function(_state) {
4595
4691
  switch(_state.label){
4596
4692
  case 0:
4597
4693
  remaining = this.getRemainingAdMs();
4598
4694
  waitTime = Math.min(this.maxPlaceholderDurationMs, remaining);
4599
4695
  if (this.consecutiveFailures >= this.maxConsecutiveFailures) {
4696
+ stillRemaining2 = this.getRemainingAdMs();
4697
+ if (stillRemaining2 >= 1e3) {
4698
+ if (this.config.debugAdTiming) {
4699
+ console.log("[CONTINUOUS-FETCH] \uD83D\uDED1 Max failures reached but break still active — resetting and continuing filler");
4700
+ }
4701
+ this.consecutiveFailures = 0;
4702
+ return [
4703
+ 2
4704
+ ];
4705
+ }
4600
4706
  if (this.config.debugAdTiming) {
4601
4707
  console.log("[CONTINUOUS-FETCH] \uD83D\uDED1 Skipping placeholder - too many consecutive failures");
4602
4708
  }
@@ -4615,6 +4721,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4615
4721
  console.log("[CONTINUOUS-FETCH] ⬛ Showing placeholder for ".concat(waitTime, "ms while waiting for ad response"));
4616
4722
  }
4617
4723
  this.isShowingPlaceholder = true;
4724
+ this.showPlaceholderLayer();
4618
4725
  this.adLayer.showPlaceholder();
4619
4726
  checkInterval = 300;
4620
4727
  maxChecks = Math.floor(waitTime / checkInterval);
@@ -4638,8 +4745,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4638
4745
  ];
4639
4746
  if (this.consecutiveFailures >= this.maxConsecutiveFailures) {
4640
4747
  if (this.config.debugAdTiming) {
4641
- console.log("[CONTINUOUS-FETCH] \uD83D\uDED1 Too many failures during placeholder wait");
4748
+ console.log("[CONTINUOUS-FETCH] \uD83D\uDED1 Too many failures during placeholder wait — resetting and continuing filler");
4642
4749
  }
4750
+ this.consecutiveFailures = 0;
4643
4751
  return [
4644
4752
  3,
4645
4753
  10
@@ -4706,6 +4814,18 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4706
4814
  1
4707
4815
  ];
4708
4816
  case 10:
4817
+ stillRemaining = this.getRemainingAdMs();
4818
+ if (stillRemaining >= 1e3) {
4819
+ if (this.config.debugAdTiming) {
4820
+ console.log("[CONTINUOUS-FETCH] ⏰ Placeholder slot expired, ".concat(stillRemaining, "ms still remaining — continuing filler"));
4821
+ }
4822
+ this.isShowingPlaceholder = false;
4823
+ this.adLayer.hidePlaceholder();
4824
+ this.consecutiveFailures = 0;
4825
+ return [
4826
+ 2
4827
+ ];
4828
+ }
4709
4829
  if (this.config.debugAdTiming) {
4710
4830
  console.log("[CONTINUOUS-FETCH] \u23F0 Placeholder timeout, ending ad break");
4711
4831
  }
@@ -4829,6 +4949,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4829
4949
  this.activeAdRequestToken = null;
4830
4950
  this.isInAdTransition = false;
4831
4951
  this.stopContinuousFetching();
4952
+ this.stopFillerBreakTimer();
4953
+ this.hidePlaceholderLayer();
4832
4954
  this.clearPendingAdBreak();
4833
4955
  this.pendingNextAdBids = null;
4834
4956
  if (this.isShowingPlaceholder) {
@@ -5237,16 +5359,18 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5237
5359
  value: function destroy() {
5238
5360
  var _this_hls, _this_adLayer;
5239
5361
  this.stopContinuousFetching();
5362
+ this.stopFillerBreakTimer();
5240
5363
  this.clearAdStartTimer();
5241
5364
  this.clearAdStopTimer();
5242
5365
  this.clearAdFailsafeTimer();
5243
5366
  this.clearAdRequestWatchdog();
5244
5367
  this.clearPendingAdBreak();
5245
- if (this.placeholderContainer) {
5246
- if (this.placeholderContainer.parentElement) {
5247
- this.placeholderContainer.parentElement.removeChild(this.placeholderContainer);
5368
+ if (this.fillerVideo) {
5369
+ this.fillerVideo.pause();
5370
+ if (this.fillerVideo.parentElement) {
5371
+ this.fillerVideo.parentElement.removeChild(this.fillerVideo);
5248
5372
  }
5249
- this.placeholderContainer = void 0;
5373
+ this.fillerVideo = void 0;
5250
5374
  }
5251
5375
  if (this.timeUpdateHandler) {
5252
5376
  this.video.removeEventListener("timeupdate", this.timeUpdateHandler);