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.
@@ -904,6 +904,106 @@ function createEmptyTrackingState() {
904
904
  complete: false
905
905
  };
906
906
  }
907
+ function firePixelWithRetry(url) {
908
+ 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]";
909
+ return _async_to_generator(function() {
910
+ var _loop, attempt, _ret;
911
+ return _ts_generator(this, function(_state) {
912
+ switch(_state.label){
913
+ case 0:
914
+ _loop = function(attempt) {
915
+ var unused;
916
+ return _ts_generator(this, function(_state) {
917
+ switch(_state.label){
918
+ case 0:
919
+ _state.trys.push([
920
+ 0,
921
+ 2,
922
+ ,
923
+ 6
924
+ ]);
925
+ return [
926
+ 4,
927
+ fetch(url, {
928
+ method: "GET",
929
+ mode: "no-cors",
930
+ cache: "no-cache",
931
+ keepalive: true
932
+ })
933
+ ];
934
+ case 1:
935
+ _state.sent();
936
+ return [
937
+ 2,
938
+ {
939
+ v: void void 0
940
+ }
941
+ ];
942
+ case 2:
943
+ unused = _state.sent();
944
+ if (!(attempt < retries)) return [
945
+ 3,
946
+ 4
947
+ ];
948
+ return [
949
+ 4,
950
+ new Promise(function(r) {
951
+ return setTimeout(r, delayMs * Math.pow(2, attempt));
952
+ })
953
+ ];
954
+ case 3:
955
+ _state.sent();
956
+ return [
957
+ 3,
958
+ 5
959
+ ];
960
+ case 4:
961
+ console.warn("".concat(logPrefix, " Tracking pixel failed after ").concat(retries + 1, " attempts: ").concat(url));
962
+ _state.label = 5;
963
+ case 5:
964
+ return [
965
+ 3,
966
+ 6
967
+ ];
968
+ case 6:
969
+ return [
970
+ 2
971
+ ];
972
+ }
973
+ });
974
+ };
975
+ attempt = 0;
976
+ _state.label = 1;
977
+ case 1:
978
+ if (!(attempt <= retries)) return [
979
+ 3,
980
+ 4
981
+ ];
982
+ return [
983
+ 5,
984
+ _ts_values(_loop(attempt))
985
+ ];
986
+ case 2:
987
+ _ret = _state.sent();
988
+ if (_type_of(_ret) === "object") return [
989
+ 2,
990
+ _ret.v
991
+ ];
992
+ _state.label = 3;
993
+ case 3:
994
+ attempt++;
995
+ return [
996
+ 3,
997
+ 1
998
+ ];
999
+ case 4:
1000
+ return [
1001
+ 2
1002
+ ];
1003
+ }
1004
+ });
1005
+ })();
1006
+ }
907
1007
  function fireTrackingPixels(urls, sessionId) {
908
1008
  var logPrefix = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "[VastParser]";
909
1009
  if (!urls || urls.length === 0) return;
@@ -913,9 +1013,13 @@ function fireTrackingPixels(urls, sessionId) {
913
1013
  if (sessionId) {
914
1014
  trackingUrl = "".concat(trackingUrl).concat(trackingUrl.includes("?") ? "&" : "?", "session_id=").concat(sessionId);
915
1015
  }
916
- var img = new Image(1, 1);
917
- img.onerror = function() {};
918
- img.src = trackingUrl;
1016
+ if (typeof fetch !== "undefined") {
1017
+ firePixelWithRetry(trackingUrl, 2, 500, logPrefix).catch(function() {});
1018
+ } else {
1019
+ var img = new Image(1, 1);
1020
+ img.onerror = function() {};
1021
+ img.src = trackingUrl;
1022
+ }
919
1023
  console.log("".concat(logPrefix, " Fired tracking pixel: ").concat(trackingUrl));
920
1024
  } catch (error) {
921
1025
  console.warn("".concat(logPrefix, " Error firing tracking pixel:"), error);
@@ -3056,13 +3160,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3056
3160
  }
3057
3161
  }
3058
3162
  _this.adLayer.setAdVolume(_this.adLayer.getOriginalMutedState() ? 1 : _this.adLayer.getOriginalVolume());
3059
- if (_this.isShowingPlaceholder) {
3060
- if (_this.config.debugAdTiming) {
3061
- console.log("[StormcloudVideoPlayer] Hiding placeholder - new ads starting");
3062
- }
3063
- _this.hidePlaceholderLayer();
3064
- _this.adLayer.hidePlaceholder();
3065
- _this.isShowingPlaceholder = false;
3163
+ _this.stopFillerBreakTimer();
3164
+ _this.hidePlaceholderLayer();
3165
+ _this.isShowingPlaceholder = false;
3166
+ if (_this.config.debugAdTiming) {
3167
+ console.log("[StormcloudVideoPlayer] Hiding placeholder - new ads starting");
3066
3168
  }
3067
3169
  });
3068
3170
  this.adLayer.on("content_resume", function() {
@@ -3113,90 +3215,80 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3113
3215
  }
3114
3216
  },
3115
3217
  {
3116
- key: "ensurePlaceholderContainer",
3117
- value: function ensurePlaceholderContainer() {
3118
- if (this.placeholderContainer) {
3119
- return;
3120
- }
3121
- var container = document.createElement("div");
3122
- container.style.position = "absolute";
3123
- container.style.left = "0";
3124
- container.style.top = "0";
3125
- container.style.right = "0";
3126
- container.style.bottom = "0";
3127
- container.style.display = "none";
3128
- container.style.alignItems = "center";
3129
- container.style.justifyContent = "center";
3130
- container.style.pointerEvents = "none";
3131
- container.style.zIndex = "5";
3132
- container.style.backgroundColor = "#000";
3133
- container.style.transition = "opacity 0.3s ease-in-out";
3134
- container.style.opacity = "0";
3135
- if (!this.video.parentElement) {
3136
- if (this.config.debugAdTiming) {
3137
- console.warn("[StormcloudVideoPlayer] Video element has no parent for placeholder container");
3138
- }
3139
- return;
3140
- }
3141
- this.video.parentElement.appendChild(container);
3142
- this.placeholderContainer = container;
3218
+ key: "ensureFillerVideo",
3219
+ value: function ensureFillerVideo() {
3220
+ if (this.fillerVideo) return;
3221
+ if (!this.video.parentElement) return;
3222
+ var filler = document.createElement("video");
3223
+ filler.src = "https://f000.backblazeb2.com/file/AdStormAds/384/Sonifi_Filler.mp4";
3224
+ filler.loop = true;
3225
+ filler.muted = false;
3226
+ filler.playsInline = true;
3227
+ filler.style.position = "absolute";
3228
+ filler.style.left = "0";
3229
+ filler.style.top = "0";
3230
+ filler.style.width = "100%";
3231
+ filler.style.height = "100%";
3232
+ filler.style.objectFit = "cover";
3233
+ filler.style.zIndex = "20";
3234
+ filler.style.display = "none";
3235
+ filler.preload = "auto";
3236
+ this.video.parentElement.appendChild(filler);
3237
+ this.fillerVideo = filler;
3143
3238
  }
3144
3239
  },
3145
3240
  {
3146
3241
  key: "showPlaceholderLayer",
3147
3242
  value: function showPlaceholderLayer() {
3148
3243
  var _this = this;
3149
- this.ensurePlaceholderContainer();
3150
- if (!this.placeholderContainer) {
3151
- return;
3152
- }
3244
+ this.ensureFillerVideo();
3245
+ if (!this.fillerVideo) return;
3153
3246
  if (!this.video.muted) {
3154
3247
  this.video.muted = true;
3155
3248
  this.video.volume = 0;
3156
- if (this.config.debugAdTiming) {
3157
- console.log("[StormcloudVideoPlayer] Muted video when showing placeholder");
3158
- }
3159
- }
3160
- var wasHidden = this.placeholderContainer.style.display === "none" || this.placeholderContainer.style.opacity === "0";
3161
- if (wasHidden) {
3162
- this.placeholderContainer.style.transition = "none";
3163
- } else {
3164
- this.placeholderContainer.style.transition = "opacity 0.3s ease-in-out";
3165
- }
3166
- this.placeholderContainer.style.backgroundColor = "#000";
3167
- this.placeholderContainer.style.display = "flex";
3168
- this.placeholderContainer.offsetHeight;
3169
- this.placeholderContainer.style.opacity = "1";
3170
- this.placeholderContainer.style.pointerEvents = "auto";
3171
- if (wasHidden) {
3172
- requestAnimationFrame(function() {
3173
- if (_this.placeholderContainer) {
3174
- _this.placeholderContainer.style.transition = "opacity 0.3s ease-in-out";
3175
- }
3176
- });
3177
3249
  }
3250
+ this.fillerVideo.style.display = "block";
3251
+ this.fillerVideo.play().catch(function() {
3252
+ if (_this.fillerVideo) {
3253
+ _this.fillerVideo.style.display = "none";
3254
+ }
3255
+ });
3178
3256
  if (this.config.debugAdTiming) {
3179
- console.log("[StormcloudVideoPlayer] Showing placeholder layer");
3257
+ console.log("[StormcloudVideoPlayer] Showing filler video layer");
3180
3258
  }
3181
3259
  }
3182
3260
  },
3183
3261
  {
3184
3262
  key: "hidePlaceholderLayer",
3185
3263
  value: function hidePlaceholderLayer() {
3186
- var _this = this;
3187
- if (!this.placeholderContainer) {
3188
- return;
3189
- }
3190
- this.placeholderContainer.style.opacity = "0";
3191
- setTimeout(function() {
3192
- if (_this.placeholderContainer) {
3193
- _this.placeholderContainer.style.display = "none";
3194
- _this.placeholderContainer.style.pointerEvents = "none";
3195
- _this.placeholderContainer.style.backgroundColor = "#000";
3196
- }
3197
- }, 300);
3264
+ if (!this.fillerVideo) return;
3265
+ this.fillerVideo.style.display = "none";
3266
+ this.fillerVideo.pause();
3267
+ this.fillerVideo.currentTime = 0;
3198
3268
  if (this.config.debugAdTiming) {
3199
- console.log("[StormcloudVideoPlayer] Hiding placeholder layer");
3269
+ console.log("[StormcloudVideoPlayer] Hiding filler video layer");
3270
+ }
3271
+ }
3272
+ },
3273
+ {
3274
+ key: "startFillerBreakTimer",
3275
+ value: function startFillerBreakTimer(durationMs) {
3276
+ var _this = this;
3277
+ this.stopFillerBreakTimer();
3278
+ this.showPlaceholderLayer();
3279
+ this.fillerBreakTimerId = setTimeout(function() {
3280
+ _this.fillerBreakTimerId = void 0;
3281
+ _this.hidePlaceholderLayer();
3282
+ if (_this.inAdBreak) _this.handleAdPodComplete();
3283
+ }, durationMs);
3284
+ }
3285
+ },
3286
+ {
3287
+ key: "stopFillerBreakTimer",
3288
+ value: function stopFillerBreakTimer() {
3289
+ if (this.fillerBreakTimerId !== void 0) {
3290
+ clearTimeout(this.fillerBreakTimerId);
3291
+ this.fillerBreakTimerId = void 0;
3200
3292
  }
3201
3293
  }
3202
3294
  },
@@ -3209,6 +3301,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3209
3301
  this.video.autoplay = !!this.config.autoplay;
3210
3302
  this.video.muted = !!this.config.muted;
3211
3303
  this.adLayer.initialize();
3304
+ this.ensureFillerVideo();
3212
3305
  this.adLayer.updateOriginalMutedState(this.video.muted, this.video.volume);
3213
3306
  this.attachAdLayerEventListeners();
3214
3307
  this.timeUpdateHandler = function() {
@@ -4128,7 +4221,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4128
4221
  this.totalAdsInBreak = 1;
4129
4222
  this.adPodQueue = [];
4130
4223
  this.showAds = true;
4131
- this.showPlaceholderLayer();
4224
+ if (adBreakDurationMs != null) {
4225
+ this.startFillerBreakTimer(adBreakDurationMs);
4226
+ } else {
4227
+ this.showPlaceholderLayer();
4228
+ }
4132
4229
  this.adLayer.showPlaceholder();
4133
4230
  if (this.expectedAdBreakDurationMs == null && adBreakDurationMs != null) {
4134
4231
  this.expectedAdBreakDurationMs = adBreakDurationMs;
@@ -4230,7 +4327,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4230
4327
  key: "stopContinuousFetching",
4231
4328
  value: function stopContinuousFetching() {
4232
4329
  this.continuousFetchingActive = false;
4233
- this.hidePlaceholderLayer();
4234
4330
  if (this.config.debugAdTiming) {
4235
4331
  console.log("[CONTINUOUS-FETCH] \uD83D\uDED1 Stopping continuous ad fetching");
4236
4332
  }
@@ -4421,13 +4517,23 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4421
4517
  key: "showPlaceholderAndWaitForAds",
4422
4518
  value: function showPlaceholderAndWaitForAds() {
4423
4519
  return _async_to_generator(function() {
4424
- var remaining, waitTime, checkInterval, maxChecks, i, bids, unused;
4520
+ var remaining, waitTime, stillRemaining2, checkInterval, maxChecks, i, bids, unused, stillRemaining;
4425
4521
  return _ts_generator(this, function(_state) {
4426
4522
  switch(_state.label){
4427
4523
  case 0:
4428
4524
  remaining = this.getRemainingAdMs();
4429
4525
  waitTime = Math.min(this.maxPlaceholderDurationMs, remaining);
4430
4526
  if (this.consecutiveFailures >= this.maxConsecutiveFailures) {
4527
+ stillRemaining2 = this.getRemainingAdMs();
4528
+ if (stillRemaining2 >= 1e3) {
4529
+ if (this.config.debugAdTiming) {
4530
+ console.log("[CONTINUOUS-FETCH] \uD83D\uDED1 Max failures reached but break still active — resetting and continuing filler");
4531
+ }
4532
+ this.consecutiveFailures = 0;
4533
+ return [
4534
+ 2
4535
+ ];
4536
+ }
4431
4537
  if (this.config.debugAdTiming) {
4432
4538
  console.log("[CONTINUOUS-FETCH] \uD83D\uDED1 Skipping placeholder - too many consecutive failures");
4433
4539
  }
@@ -4446,6 +4552,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4446
4552
  console.log("[CONTINUOUS-FETCH] ⬛ Showing placeholder for ".concat(waitTime, "ms while waiting for ad response"));
4447
4553
  }
4448
4554
  this.isShowingPlaceholder = true;
4555
+ this.showPlaceholderLayer();
4449
4556
  this.adLayer.showPlaceholder();
4450
4557
  checkInterval = 300;
4451
4558
  maxChecks = Math.floor(waitTime / checkInterval);
@@ -4469,8 +4576,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4469
4576
  ];
4470
4577
  if (this.consecutiveFailures >= this.maxConsecutiveFailures) {
4471
4578
  if (this.config.debugAdTiming) {
4472
- console.log("[CONTINUOUS-FETCH] \uD83D\uDED1 Too many failures during placeholder wait");
4579
+ console.log("[CONTINUOUS-FETCH] \uD83D\uDED1 Too many failures during placeholder wait — resetting and continuing filler");
4473
4580
  }
4581
+ this.consecutiveFailures = 0;
4474
4582
  return [
4475
4583
  3,
4476
4584
  10
@@ -4537,6 +4645,18 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4537
4645
  1
4538
4646
  ];
4539
4647
  case 10:
4648
+ stillRemaining = this.getRemainingAdMs();
4649
+ if (stillRemaining >= 1e3) {
4650
+ if (this.config.debugAdTiming) {
4651
+ console.log("[CONTINUOUS-FETCH] ⏰ Placeholder slot expired, ".concat(stillRemaining, "ms still remaining — continuing filler"));
4652
+ }
4653
+ this.isShowingPlaceholder = false;
4654
+ this.adLayer.hidePlaceholder();
4655
+ this.consecutiveFailures = 0;
4656
+ return [
4657
+ 2
4658
+ ];
4659
+ }
4540
4660
  if (this.config.debugAdTiming) {
4541
4661
  console.log("[CONTINUOUS-FETCH] \u23F0 Placeholder timeout, ending ad break");
4542
4662
  }
@@ -4660,6 +4780,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4660
4780
  this.activeAdRequestToken = null;
4661
4781
  this.isInAdTransition = false;
4662
4782
  this.stopContinuousFetching();
4783
+ this.stopFillerBreakTimer();
4784
+ this.hidePlaceholderLayer();
4663
4785
  this.clearPendingAdBreak();
4664
4786
  this.pendingNextAdBids = null;
4665
4787
  if (this.isShowingPlaceholder) {
@@ -5068,16 +5190,18 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5068
5190
  value: function destroy() {
5069
5191
  var _this_hls, _this_adLayer;
5070
5192
  this.stopContinuousFetching();
5193
+ this.stopFillerBreakTimer();
5071
5194
  this.clearAdStartTimer();
5072
5195
  this.clearAdStopTimer();
5073
5196
  this.clearAdFailsafeTimer();
5074
5197
  this.clearAdRequestWatchdog();
5075
5198
  this.clearPendingAdBreak();
5076
- if (this.placeholderContainer) {
5077
- if (this.placeholderContainer.parentElement) {
5078
- this.placeholderContainer.parentElement.removeChild(this.placeholderContainer);
5199
+ if (this.fillerVideo) {
5200
+ this.fillerVideo.pause();
5201
+ if (this.fillerVideo.parentElement) {
5202
+ this.fillerVideo.parentElement.removeChild(this.fillerVideo);
5079
5203
  }
5080
- this.placeholderContainer = void 0;
5204
+ this.fillerVideo = void 0;
5081
5205
  }
5082
5206
  if (this.timeUpdateHandler) {
5083
5207
  this.video.removeEventListener("timeupdate", this.timeUpdateHandler);