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.
@@ -866,6 +866,106 @@ function createEmptyTrackingState() {
866
866
  complete: false
867
867
  };
868
868
  }
869
+ function firePixelWithRetry(url) {
870
+ 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]";
871
+ return _async_to_generator(function() {
872
+ var _loop, attempt, _ret;
873
+ return _ts_generator(this, function(_state) {
874
+ switch(_state.label){
875
+ case 0:
876
+ _loop = function(attempt) {
877
+ var unused;
878
+ return _ts_generator(this, function(_state) {
879
+ switch(_state.label){
880
+ case 0:
881
+ _state.trys.push([
882
+ 0,
883
+ 2,
884
+ ,
885
+ 6
886
+ ]);
887
+ return [
888
+ 4,
889
+ fetch(url, {
890
+ method: "GET",
891
+ mode: "no-cors",
892
+ cache: "no-cache",
893
+ keepalive: true
894
+ })
895
+ ];
896
+ case 1:
897
+ _state.sent();
898
+ return [
899
+ 2,
900
+ {
901
+ v: void void 0
902
+ }
903
+ ];
904
+ case 2:
905
+ unused = _state.sent();
906
+ if (!(attempt < retries)) return [
907
+ 3,
908
+ 4
909
+ ];
910
+ return [
911
+ 4,
912
+ new Promise(function(r) {
913
+ return setTimeout(r, delayMs * Math.pow(2, attempt));
914
+ })
915
+ ];
916
+ case 3:
917
+ _state.sent();
918
+ return [
919
+ 3,
920
+ 5
921
+ ];
922
+ case 4:
923
+ console.warn("".concat(logPrefix, " Tracking pixel failed after ").concat(retries + 1, " attempts: ").concat(url));
924
+ _state.label = 5;
925
+ case 5:
926
+ return [
927
+ 3,
928
+ 6
929
+ ];
930
+ case 6:
931
+ return [
932
+ 2
933
+ ];
934
+ }
935
+ });
936
+ };
937
+ attempt = 0;
938
+ _state.label = 1;
939
+ case 1:
940
+ if (!(attempt <= retries)) return [
941
+ 3,
942
+ 4
943
+ ];
944
+ return [
945
+ 5,
946
+ _ts_values(_loop(attempt))
947
+ ];
948
+ case 2:
949
+ _ret = _state.sent();
950
+ if (_type_of(_ret) === "object") return [
951
+ 2,
952
+ _ret.v
953
+ ];
954
+ _state.label = 3;
955
+ case 3:
956
+ attempt++;
957
+ return [
958
+ 3,
959
+ 1
960
+ ];
961
+ case 4:
962
+ return [
963
+ 2
964
+ ];
965
+ }
966
+ });
967
+ })();
968
+ }
869
969
  function fireTrackingPixels(urls, sessionId) {
870
970
  var logPrefix = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "[VastParser]";
871
971
  if (!urls || urls.length === 0) return;
@@ -875,9 +975,13 @@ function fireTrackingPixels(urls, sessionId) {
875
975
  if (sessionId) {
876
976
  trackingUrl = "".concat(trackingUrl).concat(trackingUrl.includes("?") ? "&" : "?", "session_id=").concat(sessionId);
877
977
  }
878
- var img = new Image(1, 1);
879
- img.onerror = function() {};
880
- img.src = trackingUrl;
978
+ if (typeof fetch !== "undefined") {
979
+ firePixelWithRetry(trackingUrl, 2, 500, logPrefix).catch(function() {});
980
+ } else {
981
+ var img = new Image(1, 1);
982
+ img.onerror = function() {};
983
+ img.src = trackingUrl;
984
+ }
881
985
  console.log("".concat(logPrefix, " Fired tracking pixel: ").concat(trackingUrl));
882
986
  } catch (error) {
883
987
  console.warn("".concat(logPrefix, " Error firing tracking pixel:"), error);
@@ -3018,13 +3122,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3018
3122
  }
3019
3123
  }
3020
3124
  _this.adLayer.setAdVolume(_this.adLayer.getOriginalMutedState() ? 1 : _this.adLayer.getOriginalVolume());
3021
- if (_this.isShowingPlaceholder) {
3022
- if (_this.config.debugAdTiming) {
3023
- console.log("[StormcloudVideoPlayer] Hiding placeholder - new ads starting");
3024
- }
3025
- _this.hidePlaceholderLayer();
3026
- _this.adLayer.hidePlaceholder();
3027
- _this.isShowingPlaceholder = false;
3125
+ _this.stopFillerBreakTimer();
3126
+ _this.hidePlaceholderLayer();
3127
+ _this.isShowingPlaceholder = false;
3128
+ if (_this.config.debugAdTiming) {
3129
+ console.log("[StormcloudVideoPlayer] Hiding placeholder - new ads starting");
3028
3130
  }
3029
3131
  });
3030
3132
  this.adLayer.on("content_resume", function() {
@@ -3075,90 +3177,80 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3075
3177
  }
3076
3178
  },
3077
3179
  {
3078
- key: "ensurePlaceholderContainer",
3079
- value: function ensurePlaceholderContainer() {
3080
- if (this.placeholderContainer) {
3081
- return;
3082
- }
3083
- var container = document.createElement("div");
3084
- container.style.position = "absolute";
3085
- container.style.left = "0";
3086
- container.style.top = "0";
3087
- container.style.right = "0";
3088
- container.style.bottom = "0";
3089
- container.style.display = "none";
3090
- container.style.alignItems = "center";
3091
- container.style.justifyContent = "center";
3092
- container.style.pointerEvents = "none";
3093
- container.style.zIndex = "5";
3094
- container.style.backgroundColor = "#000";
3095
- container.style.transition = "opacity 0.3s ease-in-out";
3096
- container.style.opacity = "0";
3097
- if (!this.video.parentElement) {
3098
- if (this.config.debugAdTiming) {
3099
- console.warn("[StormcloudVideoPlayer] Video element has no parent for placeholder container");
3100
- }
3101
- return;
3102
- }
3103
- this.video.parentElement.appendChild(container);
3104
- this.placeholderContainer = container;
3180
+ key: "ensureFillerVideo",
3181
+ value: function ensureFillerVideo() {
3182
+ if (this.fillerVideo) return;
3183
+ if (!this.video.parentElement) return;
3184
+ var filler = document.createElement("video");
3185
+ filler.src = "https://f000.backblazeb2.com/file/AdStormAds/384/Sonifi_Filler.mp4";
3186
+ filler.loop = true;
3187
+ filler.muted = false;
3188
+ filler.playsInline = true;
3189
+ filler.style.position = "absolute";
3190
+ filler.style.left = "0";
3191
+ filler.style.top = "0";
3192
+ filler.style.width = "100%";
3193
+ filler.style.height = "100%";
3194
+ filler.style.objectFit = "cover";
3195
+ filler.style.zIndex = "20";
3196
+ filler.style.display = "none";
3197
+ filler.preload = "auto";
3198
+ this.video.parentElement.appendChild(filler);
3199
+ this.fillerVideo = filler;
3105
3200
  }
3106
3201
  },
3107
3202
  {
3108
3203
  key: "showPlaceholderLayer",
3109
3204
  value: function showPlaceholderLayer() {
3110
3205
  var _this = this;
3111
- this.ensurePlaceholderContainer();
3112
- if (!this.placeholderContainer) {
3113
- return;
3114
- }
3206
+ this.ensureFillerVideo();
3207
+ if (!this.fillerVideo) return;
3115
3208
  if (!this.video.muted) {
3116
3209
  this.video.muted = true;
3117
3210
  this.video.volume = 0;
3118
- if (this.config.debugAdTiming) {
3119
- console.log("[StormcloudVideoPlayer] Muted video when showing placeholder");
3120
- }
3121
- }
3122
- var wasHidden = this.placeholderContainer.style.display === "none" || this.placeholderContainer.style.opacity === "0";
3123
- if (wasHidden) {
3124
- this.placeholderContainer.style.transition = "none";
3125
- } else {
3126
- this.placeholderContainer.style.transition = "opacity 0.3s ease-in-out";
3127
- }
3128
- this.placeholderContainer.style.backgroundColor = "#000";
3129
- this.placeholderContainer.style.display = "flex";
3130
- this.placeholderContainer.offsetHeight;
3131
- this.placeholderContainer.style.opacity = "1";
3132
- this.placeholderContainer.style.pointerEvents = "auto";
3133
- if (wasHidden) {
3134
- requestAnimationFrame(function() {
3135
- if (_this.placeholderContainer) {
3136
- _this.placeholderContainer.style.transition = "opacity 0.3s ease-in-out";
3137
- }
3138
- });
3139
3211
  }
3212
+ this.fillerVideo.style.display = "block";
3213
+ this.fillerVideo.play().catch(function() {
3214
+ if (_this.fillerVideo) {
3215
+ _this.fillerVideo.style.display = "none";
3216
+ }
3217
+ });
3140
3218
  if (this.config.debugAdTiming) {
3141
- console.log("[StormcloudVideoPlayer] Showing placeholder layer");
3219
+ console.log("[StormcloudVideoPlayer] Showing filler video layer");
3142
3220
  }
3143
3221
  }
3144
3222
  },
3145
3223
  {
3146
3224
  key: "hidePlaceholderLayer",
3147
3225
  value: function hidePlaceholderLayer() {
3148
- var _this = this;
3149
- if (!this.placeholderContainer) {
3150
- return;
3151
- }
3152
- this.placeholderContainer.style.opacity = "0";
3153
- setTimeout(function() {
3154
- if (_this.placeholderContainer) {
3155
- _this.placeholderContainer.style.display = "none";
3156
- _this.placeholderContainer.style.pointerEvents = "none";
3157
- _this.placeholderContainer.style.backgroundColor = "#000";
3158
- }
3159
- }, 300);
3226
+ if (!this.fillerVideo) return;
3227
+ this.fillerVideo.style.display = "none";
3228
+ this.fillerVideo.pause();
3229
+ this.fillerVideo.currentTime = 0;
3160
3230
  if (this.config.debugAdTiming) {
3161
- console.log("[StormcloudVideoPlayer] Hiding placeholder layer");
3231
+ console.log("[StormcloudVideoPlayer] Hiding filler video layer");
3232
+ }
3233
+ }
3234
+ },
3235
+ {
3236
+ key: "startFillerBreakTimer",
3237
+ value: function startFillerBreakTimer(durationMs) {
3238
+ var _this = this;
3239
+ this.stopFillerBreakTimer();
3240
+ this.showPlaceholderLayer();
3241
+ this.fillerBreakTimerId = setTimeout(function() {
3242
+ _this.fillerBreakTimerId = void 0;
3243
+ _this.hidePlaceholderLayer();
3244
+ if (_this.inAdBreak) _this.handleAdPodComplete();
3245
+ }, durationMs);
3246
+ }
3247
+ },
3248
+ {
3249
+ key: "stopFillerBreakTimer",
3250
+ value: function stopFillerBreakTimer() {
3251
+ if (this.fillerBreakTimerId !== void 0) {
3252
+ clearTimeout(this.fillerBreakTimerId);
3253
+ this.fillerBreakTimerId = void 0;
3162
3254
  }
3163
3255
  }
3164
3256
  },
@@ -3171,6 +3263,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3171
3263
  this.video.autoplay = !!this.config.autoplay;
3172
3264
  this.video.muted = !!this.config.muted;
3173
3265
  this.adLayer.initialize();
3266
+ this.ensureFillerVideo();
3174
3267
  this.adLayer.updateOriginalMutedState(this.video.muted, this.video.volume);
3175
3268
  this.attachAdLayerEventListeners();
3176
3269
  this.timeUpdateHandler = function() {
@@ -4090,7 +4183,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4090
4183
  this.totalAdsInBreak = 1;
4091
4184
  this.adPodQueue = [];
4092
4185
  this.showAds = true;
4093
- this.showPlaceholderLayer();
4186
+ if (adBreakDurationMs != null) {
4187
+ this.startFillerBreakTimer(adBreakDurationMs);
4188
+ } else {
4189
+ this.showPlaceholderLayer();
4190
+ }
4094
4191
  this.adLayer.showPlaceholder();
4095
4192
  if (this.expectedAdBreakDurationMs == null && adBreakDurationMs != null) {
4096
4193
  this.expectedAdBreakDurationMs = adBreakDurationMs;
@@ -4192,7 +4289,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4192
4289
  key: "stopContinuousFetching",
4193
4290
  value: function stopContinuousFetching() {
4194
4291
  this.continuousFetchingActive = false;
4195
- this.hidePlaceholderLayer();
4196
4292
  if (this.config.debugAdTiming) {
4197
4293
  console.log("[CONTINUOUS-FETCH] \uD83D\uDED1 Stopping continuous ad fetching");
4198
4294
  }
@@ -4383,13 +4479,23 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4383
4479
  key: "showPlaceholderAndWaitForAds",
4384
4480
  value: function showPlaceholderAndWaitForAds() {
4385
4481
  return _async_to_generator(function() {
4386
- var remaining, waitTime, checkInterval, maxChecks, i, bids, unused;
4482
+ var remaining, waitTime, stillRemaining2, checkInterval, maxChecks, i, bids, unused, stillRemaining;
4387
4483
  return _ts_generator(this, function(_state) {
4388
4484
  switch(_state.label){
4389
4485
  case 0:
4390
4486
  remaining = this.getRemainingAdMs();
4391
4487
  waitTime = Math.min(this.maxPlaceholderDurationMs, remaining);
4392
4488
  if (this.consecutiveFailures >= this.maxConsecutiveFailures) {
4489
+ stillRemaining2 = this.getRemainingAdMs();
4490
+ if (stillRemaining2 >= 1e3) {
4491
+ if (this.config.debugAdTiming) {
4492
+ console.log("[CONTINUOUS-FETCH] \uD83D\uDED1 Max failures reached but break still active — resetting and continuing filler");
4493
+ }
4494
+ this.consecutiveFailures = 0;
4495
+ return [
4496
+ 2
4497
+ ];
4498
+ }
4393
4499
  if (this.config.debugAdTiming) {
4394
4500
  console.log("[CONTINUOUS-FETCH] \uD83D\uDED1 Skipping placeholder - too many consecutive failures");
4395
4501
  }
@@ -4408,6 +4514,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4408
4514
  console.log("[CONTINUOUS-FETCH] ⬛ Showing placeholder for ".concat(waitTime, "ms while waiting for ad response"));
4409
4515
  }
4410
4516
  this.isShowingPlaceholder = true;
4517
+ this.showPlaceholderLayer();
4411
4518
  this.adLayer.showPlaceholder();
4412
4519
  checkInterval = 300;
4413
4520
  maxChecks = Math.floor(waitTime / checkInterval);
@@ -4431,8 +4538,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4431
4538
  ];
4432
4539
  if (this.consecutiveFailures >= this.maxConsecutiveFailures) {
4433
4540
  if (this.config.debugAdTiming) {
4434
- console.log("[CONTINUOUS-FETCH] \uD83D\uDED1 Too many failures during placeholder wait");
4541
+ console.log("[CONTINUOUS-FETCH] \uD83D\uDED1 Too many failures during placeholder wait — resetting and continuing filler");
4435
4542
  }
4543
+ this.consecutiveFailures = 0;
4436
4544
  return [
4437
4545
  3,
4438
4546
  10
@@ -4499,6 +4607,18 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4499
4607
  1
4500
4608
  ];
4501
4609
  case 10:
4610
+ stillRemaining = this.getRemainingAdMs();
4611
+ if (stillRemaining >= 1e3) {
4612
+ if (this.config.debugAdTiming) {
4613
+ console.log("[CONTINUOUS-FETCH] ⏰ Placeholder slot expired, ".concat(stillRemaining, "ms still remaining — continuing filler"));
4614
+ }
4615
+ this.isShowingPlaceholder = false;
4616
+ this.adLayer.hidePlaceholder();
4617
+ this.consecutiveFailures = 0;
4618
+ return [
4619
+ 2
4620
+ ];
4621
+ }
4502
4622
  if (this.config.debugAdTiming) {
4503
4623
  console.log("[CONTINUOUS-FETCH] \u23F0 Placeholder timeout, ending ad break");
4504
4624
  }
@@ -4622,6 +4742,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4622
4742
  this.activeAdRequestToken = null;
4623
4743
  this.isInAdTransition = false;
4624
4744
  this.stopContinuousFetching();
4745
+ this.stopFillerBreakTimer();
4746
+ this.hidePlaceholderLayer();
4625
4747
  this.clearPendingAdBreak();
4626
4748
  this.pendingNextAdBids = null;
4627
4749
  if (this.isShowingPlaceholder) {
@@ -5030,16 +5152,18 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5030
5152
  value: function destroy() {
5031
5153
  var _this_hls, _this_adLayer;
5032
5154
  this.stopContinuousFetching();
5155
+ this.stopFillerBreakTimer();
5033
5156
  this.clearAdStartTimer();
5034
5157
  this.clearAdStopTimer();
5035
5158
  this.clearAdFailsafeTimer();
5036
5159
  this.clearAdRequestWatchdog();
5037
5160
  this.clearPendingAdBreak();
5038
- if (this.placeholderContainer) {
5039
- if (this.placeholderContainer.parentElement) {
5040
- this.placeholderContainer.parentElement.removeChild(this.placeholderContainer);
5161
+ if (this.fillerVideo) {
5162
+ this.fillerVideo.pause();
5163
+ if (this.fillerVideo.parentElement) {
5164
+ this.fillerVideo.parentElement.removeChild(this.fillerVideo);
5041
5165
  }
5042
- this.placeholderContainer = void 0;
5166
+ this.fillerVideo = void 0;
5043
5167
  }
5044
5168
  if (this.timeUpdateHandler) {
5045
5169
  this.video.removeEventListener("timeupdate", this.timeUpdateHandler);