stormcloud-video-player 0.8.29 → 0.8.31

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.
Files changed (42) hide show
  1. package/dist/stormcloud-vp.min.js +2 -2
  2. package/lib/index.cjs +293 -1219
  3. package/lib/index.cjs.map +1 -1
  4. package/lib/index.d.cts +0 -3
  5. package/lib/index.d.ts +0 -3
  6. package/lib/index.js +292 -1219
  7. package/lib/index.js.map +1 -1
  8. package/lib/player/AdBreakOrchestrator.cjs +57 -490
  9. package/lib/player/AdBreakOrchestrator.cjs.map +1 -1
  10. package/lib/player/AdBreakOrchestrator.d.cts +8 -7
  11. package/lib/player/AdConfigManager.cjs +12 -53
  12. package/lib/player/AdConfigManager.cjs.map +1 -1
  13. package/lib/player/AdConfigManager.d.cts +4 -5
  14. package/lib/player/AdTimingService.d.cts +1 -1
  15. package/lib/player/HlsEngine.d.cts +1 -1
  16. package/lib/player/PlayerControls.d.cts +1 -1
  17. package/lib/player/Scte35CueManager.d.cts +1 -1
  18. package/lib/player/Scte35Parser.d.cts +1 -1
  19. package/lib/player/StormcloudVideoPlayer.cjs +293 -1219
  20. package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
  21. package/lib/player/StormcloudVideoPlayer.d.cts +1 -3
  22. package/lib/player/playerTypes.d.cts +1 -1
  23. package/lib/players/HlsPlayer.cjs +293 -1219
  24. package/lib/players/HlsPlayer.cjs.map +1 -1
  25. package/lib/players/HlsPlayer.d.cts +1 -1
  26. package/lib/players/index.cjs +293 -1219
  27. package/lib/players/index.cjs.map +1 -1
  28. package/lib/sdk/hlsAdPlayer.cjs +49 -8
  29. package/lib/sdk/hlsAdPlayer.cjs.map +1 -1
  30. package/lib/sdk/hlsAdPlayer.d.cts +1 -1
  31. package/lib/{types-Xgz2_W1C.d.cts → types-CSHvCbhZ.d.cts} +0 -1
  32. package/lib/ui/StormcloudVideoPlayer.cjs +293 -1219
  33. package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
  34. package/lib/ui/StormcloudVideoPlayer.d.cts +1 -1
  35. package/lib/utils/tracking.d.cts +1 -1
  36. package/lib/utils/vastMacros.cjs +10 -15
  37. package/lib/utils/vastMacros.cjs.map +1 -1
  38. package/lib/utils/vastMacros.d.cts +0 -1
  39. package/package.json +1 -1
  40. package/lib/player/AdPreloadPool.cjs +0 -673
  41. package/lib/player/AdPreloadPool.cjs.map +0 -1
  42. package/lib/player/AdPreloadPool.d.cts +0 -37
package/lib/index.cjs CHANGED
@@ -963,24 +963,65 @@ function createHlsAdPlayer(contentVideo, options) {
963
963
  }
964
964
  }
965
965
  function fetchVastXml(vastTagUrl) {
966
+ var credentials = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "include";
966
967
  return _async_to_generator(function() {
967
- var response;
968
+ var requestVast, response, error;
968
969
  return _ts_generator(this, function(_state) {
969
970
  switch(_state.label){
970
971
  case 0:
971
- return [
972
- 4,
973
- fetch(vastTagUrl, {
972
+ requestVast = function requestVast(creds) {
973
+ return fetch(vastTagUrl, {
974
974
  mode: "cors",
975
- credentials: "include",
975
+ credentials: creds,
976
976
  headers: {
977
977
  "Accept": "application/xml, text/xml, */*"
978
978
  },
979
979
  referrerPolicy: "no-referrer-when-downgrade"
980
- })
981
- ];
980
+ });
981
+ };
982
+ _state.label = 1;
982
983
  case 1:
984
+ _state.trys.push([
985
+ 1,
986
+ 3,
987
+ ,
988
+ 7
989
+ ]);
990
+ return [
991
+ 4,
992
+ requestVast(credentials)
993
+ ];
994
+ case 2:
983
995
  response = _state.sent();
996
+ return [
997
+ 3,
998
+ 7
999
+ ];
1000
+ case 3:
1001
+ error = _state.sent();
1002
+ if (!(credentials !== "omit")) return [
1003
+ 3,
1004
+ 5
1005
+ ];
1006
+ console.warn('[HlsAdPlayer] VAST fetch failed with credentials="'.concat(credentials, '", retrying without credentials:'), error);
1007
+ return [
1008
+ 4,
1009
+ requestVast("omit")
1010
+ ];
1011
+ case 4:
1012
+ response = _state.sent();
1013
+ return [
1014
+ 3,
1015
+ 6
1016
+ ];
1017
+ case 5:
1018
+ throw error;
1019
+ case 6:
1020
+ return [
1021
+ 3,
1022
+ 7
1023
+ ];
1024
+ case 7:
984
1025
  if (!response.ok) {
985
1026
  throw new Error("Failed to fetch VAST: ".concat(response.statusText));
986
1027
  }
@@ -1002,7 +1043,7 @@ function createHlsAdPlayer(contentVideo, options) {
1002
1043
  depth = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : 0, accumulatedTracking = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : createEmptyTrackingUrls();
1003
1044
  return [
1004
1045
  4,
1005
- fetchVastXml(vastTagUrl)
1046
+ fetchVastXml(vastTagUrl, depth === 0 ? "include" : "omit")
1006
1047
  ];
1007
1048
  case 1:
1008
1049
  vastXml = _state.sent();
@@ -3678,21 +3719,16 @@ function applyVastMacros(baseUrl, ctx) {
3678
3719
  if (ctx.pod != null) {
3679
3720
  params.set("pod", String(ctx.pod));
3680
3721
  }
3681
- var optimizedPodMode = ctx.podMaxAds != null || ctx.podMinDurationMs != null || ctx.podMaxDurationMs != null;
3682
- if (optimizedPodMode) {
3683
- params.delete("ppos");
3684
- params.delete("lip");
3685
- if (ctx.podMinDurationMs != null) {
3686
- params.set("pmnd", String(Math.max(0, Math.round(ctx.podMinDurationMs))));
3687
- }
3688
- if (ctx.podMaxDurationMs != null) {
3689
- params.set("pmxd", String(Math.max(0, Math.round(ctx.podMaxDurationMs))));
3690
- }
3691
- if (ctx.podMaxAds != null) {
3692
- params.set("pmad", String(Math.max(1, Math.round(ctx.podMaxAds))));
3693
- }
3694
- } else if (ctx.adPosition != null) {
3695
- params.set("ppos", String(ctx.adPosition));
3722
+ params.delete("ppos");
3723
+ params.delete("lip");
3724
+ if (ctx.podMinDurationMs != null) {
3725
+ params.set("pmnd", String(Math.max(0, Math.round(ctx.podMinDurationMs))));
3726
+ }
3727
+ if (ctx.podMaxDurationMs != null) {
3728
+ params.set("pmxd", String(Math.max(0, Math.round(ctx.podMaxDurationMs))));
3729
+ }
3730
+ if (ctx.podMaxAds != null) {
3731
+ params.set("pmad", String(Math.max(1, Math.round(ctx.podMaxAds))));
3696
3732
  }
3697
3733
  var requestUrl = ctx.contentUrl || ctx.pageUrl;
3698
3734
  if (requestUrl) {
@@ -5055,9 +5091,9 @@ var AdConfigManager = /*#__PURE__*/ function() {
5055
5091
  this.consentSignals = {};
5056
5092
  this.podCounter = 0;
5057
5093
  this.podAssignedByPrefetch = false;
5058
- this.adRequestPositionInBreak = 0;
5059
5094
  this.lastHeartbeatTime = 0;
5060
5095
  this.defaultPodMaxAds = 6;
5096
+ this.defaultPodMaxDurationMs = 12e4;
5061
5097
  this.config = config;
5062
5098
  this.video = video;
5063
5099
  }
@@ -5475,48 +5511,12 @@ var AdConfigManager = /*#__PURE__*/ function() {
5475
5511
  key: "beginNewAdPod",
5476
5512
  value: function beginNewAdPod() {
5477
5513
  this.podCounter++;
5478
- this.adRequestPositionInBreak = 0;
5479
- }
5480
- },
5481
- {
5482
- key: "generateVastUrlsWithCorrelators",
5483
- value: function generateVastUrlsWithCorrelators(baseUrl, count, adPlayer, palNonce, inAdBreak) {
5484
- var urls = [];
5485
- for(var i = 0; i < count; i++){
5486
- this.adRequestPositionInBreak++;
5487
- var adWillPlayMuted = inAdBreak ? adPlayer.getOriginalMutedState() : this.video.muted;
5488
- var envSignals = resolveVastEnvironmentSignals(!!this.config.ctvAdRequest);
5489
- var urlWithMacros = applyVastMacros(baseUrl, {
5490
- correlator: this.viewCorrelator,
5491
- streamCorrelator: this.streamCorrelator,
5492
- pod: this.podCounter > 0 ? this.podCounter : void 0,
5493
- adPosition: this.adRequestPositionInBreak,
5494
- isCtv: envSignals.isCtv,
5495
- contentUrl: envSignals.contentUrl,
5496
- pageUrl: !envSignals.isCtv && typeof window !== "undefined" ? window.location.href : void 0,
5497
- adWillPlayMuted: adWillPlayMuted,
5498
- adWillAutoPlay: !!this.config.autoplay,
5499
- appId: envSignals.appId,
5500
- appName: envSignals.appName,
5501
- sessionId: envSignals.sessionId,
5502
- deviceId: envSignals.deviceId,
5503
- deviceIdType: envSignals.deviceIdType,
5504
- limitAdTracking: envSignals.limitAdTracking,
5505
- deviceTypeHint: envSignals.deviceTypeHint,
5506
- adTest: this.config.adTest,
5507
- consent: this.consentSignals
5508
- });
5509
- var finalUrl = palNonce.injectNonce(urlWithMacros);
5510
- console.log("[StormcloudVideoPlayer] Resolved ad request URL (pod=".concat(this.podCounter, ", pos=").concat(this.adRequestPositionInBreak, "):"), finalUrl);
5511
- urls.push(finalUrl);
5512
- }
5513
- return urls;
5514
5514
  }
5515
5515
  },
5516
5516
  {
5517
5517
  key: "resolvePodParams",
5518
5518
  value: function resolvePodParams(breakDurationMs) {
5519
- var maxDurationMs = breakDurationMs != null && breakDurationMs > 0 ? breakDurationMs : this.config.podMaxDurationMs;
5519
+ var maxDurationMs = breakDurationMs != null && breakDurationMs > 0 ? breakDurationMs : this.config.podMaxDurationMs != null && this.config.podMaxDurationMs > 0 ? this.config.podMaxDurationMs : this.defaultPodMaxDurationMs;
5520
5520
  var maxAds = this.config.podMaxAds && this.config.podMaxAds > 0 ? this.config.podMaxAds : this.apiNumberAds && this.apiNumberAds > 0 ? this.apiNumberAds : this.defaultPodMaxAds;
5521
5521
  var minDurationMs = this.config.podExactDuration && maxDurationMs != null ? maxDurationMs : 0;
5522
5522
  return {
@@ -6169,611 +6169,155 @@ var AdTimingService = /*#__PURE__*/ function() {
6169
6169
  ]);
6170
6170
  return AdTimingService;
6171
6171
  }();
6172
- // src/player/AdPreloadPool.ts
6173
- var AdPreloadPool = /*#__PURE__*/ function() {
6174
- function AdPreloadPool(deps) {
6175
- _class_call_check(this, AdPreloadPool);
6176
- this.pool = [];
6177
- this.maxPoolSize = 2;
6178
- this.poolActive = false;
6179
- this.loopRunning = false;
6180
- this.deps = deps;
6181
- }
6182
- _create_class(AdPreloadPool, [
6183
- {
6184
- key: "active",
6185
- get: function get() {
6186
- return this.poolActive;
6187
- },
6188
- set: function set(value) {
6189
- this.poolActive = value;
6190
- }
6191
- },
6172
+ // src/player/PlaceholderLayer.ts
6173
+ var PlaceholderLayer = /*#__PURE__*/ function() {
6174
+ function PlaceholderLayer(video, debug) {
6175
+ _class_call_check(this, PlaceholderLayer);
6176
+ this.video = video;
6177
+ this.debug = debug;
6178
+ }
6179
+ _create_class(PlaceholderLayer, [
6192
6180
  {
6193
- key: "isLoopRunning",
6194
- get: function get() {
6195
- return this.loopRunning;
6181
+ key: "ensureContainer",
6182
+ value: function ensureContainer() {
6183
+ if (this.container) {
6184
+ return;
6185
+ }
6186
+ var el = document.createElement("div");
6187
+ el.style.position = "absolute";
6188
+ el.style.left = "0";
6189
+ el.style.top = "0";
6190
+ el.style.right = "0";
6191
+ el.style.bottom = "0";
6192
+ el.style.display = "none";
6193
+ el.style.alignItems = "center";
6194
+ el.style.justifyContent = "center";
6195
+ el.style.pointerEvents = "none";
6196
+ el.style.zIndex = "5";
6197
+ el.style.backgroundColor = "#000";
6198
+ el.style.transition = "opacity 0.3s ease-in-out";
6199
+ el.style.opacity = "0";
6200
+ if (!this.video.parentElement) {
6201
+ if (this.debug) {
6202
+ console.warn("[StormcloudVideoPlayer] Video element has no parent for placeholder container");
6203
+ }
6204
+ return;
6205
+ }
6206
+ this.video.parentElement.appendChild(el);
6207
+ this.container = el;
6196
6208
  }
6197
6209
  },
6198
6210
  {
6199
- key: "startPreloadPool",
6200
- value: function startPreloadPool(baseVastUrl, initialUrls) {
6201
- var startLoopImmediately = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
6202
- if (this.poolActive) {
6203
- if (this.deps.debug) {
6204
- console.log("[PRELOAD-POOL] Already active, skipping duplicate start");
6205
- }
6211
+ key: "show",
6212
+ value: function show() {
6213
+ var _this = this;
6214
+ this.ensureContainer();
6215
+ if (!this.container) {
6206
6216
  return;
6207
6217
  }
6208
- this.poolActive = true;
6209
- if (this.deps.debug) {
6210
- console.log("[PRELOAD-POOL] Starting preload pool EARLY (target size: ".concat(this.maxPoolSize, ")"));
6211
- console.log("[PRELOAD-POOL] Ad break hasn't started yet, but preloading ads in advance");
6212
- }
6213
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
6214
- try {
6215
- for(var _iterator = initialUrls[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
6216
- var url = _step.value;
6217
- if (this.pool.length < this.maxPoolSize) {
6218
- this.preloadAdIntoPool(url);
6219
- }
6218
+ if (!this.video.muted) {
6219
+ this.video.muted = true;
6220
+ if (this.debug) {
6221
+ console.log("[StormcloudVideoPlayer] Muted video when showing placeholder");
6220
6222
  }
6221
- } catch (err) {
6222
- _didIteratorError = true;
6223
- _iteratorError = err;
6224
- } finally{
6225
- try {
6226
- if (!_iteratorNormalCompletion && _iterator.return != null) {
6227
- _iterator.return();
6228
- }
6229
- } finally{
6230
- if (_didIteratorError) {
6231
- throw _iteratorError;
6223
+ }
6224
+ var wasHidden = this.container.style.display === "none" || this.container.style.opacity === "0";
6225
+ if (wasHidden) {
6226
+ this.container.style.transition = "none";
6227
+ } else {
6228
+ this.container.style.transition = "opacity 0.3s ease-in-out";
6229
+ }
6230
+ this.container.style.backgroundColor = "#000";
6231
+ this.container.style.display = "flex";
6232
+ this.container.offsetHeight;
6233
+ this.container.style.opacity = "1";
6234
+ this.container.style.pointerEvents = "auto";
6235
+ if (wasHidden) {
6236
+ requestAnimationFrame(function() {
6237
+ if (_this.container) {
6238
+ _this.container.style.transition = "opacity 0.3s ease-in-out";
6232
6239
  }
6240
+ });
6241
+ }
6242
+ if (this.debug) {
6243
+ console.log("[StormcloudVideoPlayer] Showing placeholder layer (between content and ad layer)");
6244
+ }
6245
+ }
6246
+ },
6247
+ {
6248
+ key: "hide",
6249
+ value: function hide() {
6250
+ var _this = this;
6251
+ if (!this.container) {
6252
+ return;
6253
+ }
6254
+ this.container.style.opacity = "0";
6255
+ setTimeout(function() {
6256
+ if (_this.container) {
6257
+ _this.container.style.display = "none";
6258
+ _this.container.style.pointerEvents = "none";
6259
+ _this.container.style.backgroundColor = "#000";
6233
6260
  }
6261
+ }, 300);
6262
+ if (this.debug) {
6263
+ console.log("[StormcloudVideoPlayer] Hiding placeholder layer");
6234
6264
  }
6235
- if (startLoopImmediately) {
6236
- this.preloadPoolLoop(baseVastUrl);
6237
- } else if (this.deps.debug) {
6238
- console.log("[PRELOAD-POOL] Pre-break mode: preloaded once, waiting for SCTE start to continue fetching");
6265
+ }
6266
+ },
6267
+ {
6268
+ key: "destroy",
6269
+ value: function destroy() {
6270
+ if (this.container) {
6271
+ if (this.container.parentElement) {
6272
+ this.container.parentElement.removeChild(this.container);
6273
+ }
6274
+ this.container = void 0;
6239
6275
  }
6240
6276
  }
6277
+ }
6278
+ ]);
6279
+ return PlaceholderLayer;
6280
+ }();
6281
+ // src/player/HlsEngine.ts
6282
+ var import_hls2 = __toESM(require("hls.js"), 1);
6283
+ var HlsEngine = /*#__PURE__*/ function() {
6284
+ function HlsEngine(config, video, cueManager, timing, callbacks) {
6285
+ _class_call_check(this, HlsEngine);
6286
+ this.isLiveStream = false;
6287
+ this.nativeHlsMode = false;
6288
+ this.videoSrcProtection = null;
6289
+ this.bufferedSegmentsCount = 0;
6290
+ this.shouldAutoplayAfterBuffering = false;
6291
+ this.hasInitialBufferCompleted = false;
6292
+ this.config = config;
6293
+ this.video = video;
6294
+ this.cueManager = cueManager;
6295
+ this.timing = timing;
6296
+ this.callbacks = callbacks;
6297
+ }
6298
+ _create_class(HlsEngine, [
6299
+ {
6300
+ key: "debug",
6301
+ get: function get() {
6302
+ return !!this.config.debugAdTiming;
6303
+ }
6241
6304
  },
6242
6305
  {
6243
- key: "preloadAdIntoPool",
6244
- value: function preloadAdIntoPool(vastUrl) {
6245
- return _async_to_generator(function() {
6246
- var _this, timing, epoch, loadPromise;
6247
- return _ts_generator(this, function(_state) {
6248
- _this = this;
6249
- timing = this.deps.timing;
6250
- if (timing.isGamInCooldown()) {
6251
- if (this.deps.debug) {
6252
- console.log("[CIRCUIT-BREAKER] GAM in cooldown, skipping preload");
6253
- }
6254
- return [
6255
- 2
6256
- ];
6257
- }
6258
- if (this.pool.some(function(entry) {
6259
- return entry.vastUrl === vastUrl;
6260
- }) || timing.failedVastUrls.has(vastUrl) || timing.isUrlInCooldown(vastUrl)) {
6261
- return [
6262
- 2
6263
- ];
6264
- }
6265
- if (this.pool.length >= this.maxPoolSize) {
6266
- return [
6267
- 2
6268
- ];
6269
- }
6270
- if (this.deps.debug) {
6271
- console.log("[PRELOAD-POOL] Preloading ad into pool: ".concat(vastUrl));
6272
- }
6273
- epoch = timing.adBreakEpoch;
6274
- loadPromise = function() {
6275
- return _async_to_generator(function() {
6276
- var _this, hasAdError, adErrorPayload, errorListenerCleanup, _preloadAd_getLoadedAdDuration, continueLiveStreamDuringAds, preloadAd, errorListener, isNoFill, poolEntry, loadedDuration, lateErrorListener, _poolEntry_durationSeconds, error;
6277
- return _ts_generator(this, function(_state) {
6278
- switch(_state.label){
6279
- case 0:
6280
- _this = this;
6281
- hasAdError = false;
6282
- adErrorPayload = null;
6283
- errorListenerCleanup = null;
6284
- _state.label = 1;
6285
- case 1:
6286
- _state.trys.push([
6287
- 1,
6288
- 5,
6289
- ,
6290
- 6
6291
- ]);
6292
- continueLiveStreamDuringAds = this.deps.shouldContinueLiveStreamDuringAds();
6293
- preloadAd = this.deps.createAdPlayer(continueLiveStreamDuringAds);
6294
- preloadAd.initialize();
6295
- errorListener = function errorListener(payload) {
6296
- hasAdError = true;
6297
- adErrorPayload = payload;
6298
- };
6299
- preloadAd.on("ad_error", errorListener);
6300
- errorListenerCleanup = function errorListenerCleanup() {
6301
- return preloadAd.off("ad_error", errorListener);
6302
- };
6303
- return [
6304
- 4,
6305
- timing.enforceGlobalRateLimit()
6306
- ];
6307
- case 2:
6308
- _state.sent();
6309
- return [
6310
- 4,
6311
- preloadAd.requestAds(vastUrl)
6312
- ];
6313
- case 3:
6314
- _state.sent();
6315
- preloadAd.pause();
6316
- return [
6317
- 4,
6318
- new Promise(function(resolve) {
6319
- return setTimeout(resolve, 1500);
6320
- })
6321
- ];
6322
- case 4:
6323
- _state.sent();
6324
- preloadAd.pause();
6325
- if (hasAdError) {
6326
- isNoFill = (adErrorPayload === null || adErrorPayload === void 0 ? void 0 : adErrorPayload.isNoFill) || (adErrorPayload === null || adErrorPayload === void 0 ? void 0 : adErrorPayload.code) === 303 || (adErrorPayload === null || adErrorPayload === void 0 ? void 0 : adErrorPayload.vastErrorCode) === 303;
6327
- if (errorListenerCleanup) {
6328
- errorListenerCleanup();
6329
- }
6330
- preloadAd.destroy();
6331
- timing.recordGamNoFill();
6332
- if (isNoFill) {
6333
- if (this.deps.debug) {
6334
- console.log("[PRELOAD-POOL] Ad preload returned no-fill: ".concat(vastUrl));
6335
- }
6336
- timing.temporaryFailureUrls.set(vastUrl, Date.now());
6337
- } else {
6338
- if (this.deps.debug) {
6339
- console.log("[PRELOAD-POOL] Ad preload failed with error: ".concat(vastUrl), adErrorPayload);
6340
- }
6341
- if (adErrorPayload && !timing.isTemporaryAdError(adErrorPayload)) {
6342
- timing.failedVastUrls.add(vastUrl);
6343
- } else {
6344
- timing.temporaryFailureUrls.set(vastUrl, Date.now());
6345
- }
6346
- }
6347
- return [
6348
- 2
6349
- ];
6350
- }
6351
- if (!this.poolActive || epoch !== timing.adBreakEpoch) {
6352
- if (this.deps.debug) {
6353
- console.log("[PRELOAD-POOL] Discarding preloaded ad - break ended during fetch");
6354
- }
6355
- if (errorListenerCleanup) {
6356
- errorListenerCleanup();
6357
- }
6358
- try {
6359
- preloadAd.destroy();
6360
- } catch (unused) {}
6361
- return [
6362
- 2
6363
- ];
6364
- }
6365
- poolEntry = {
6366
- vastUrl: vastUrl,
6367
- adController: preloadAd,
6368
- loadedAt: Date.now(),
6369
- isReady: true,
6370
- loadPromise: Promise.resolve()
6371
- };
6372
- loadedDuration = (_preloadAd_getLoadedAdDuration = preloadAd.getLoadedAdDuration) === null || _preloadAd_getLoadedAdDuration === void 0 ? void 0 : _preloadAd_getLoadedAdDuration.call(preloadAd);
6373
- if (loadedDuration != null && loadedDuration > 0) {
6374
- poolEntry.durationSeconds = loadedDuration;
6375
- }
6376
- lateErrorListener = function lateErrorListener(payload) {
6377
- var index = _this.pool.findIndex(function(entry) {
6378
- return entry.vastUrl === vastUrl;
6379
- });
6380
- if (index >= 0) {
6381
- _this.pool.splice(index, 1);
6382
- if (_this.deps.debug) {
6383
- console.log("[PRELOAD-POOL] Late error detected, removed from pool: ".concat(vastUrl), payload);
6384
- }
6385
- try {
6386
- preloadAd.destroy();
6387
- } catch (unused) {}
6388
- }
6389
- };
6390
- preloadAd.on("ad_error", lateErrorListener);
6391
- this.pool.push(poolEntry);
6392
- if (this.deps.debug) {
6393
- ;
6394
- console.log("[PRELOAD-POOL] Ad preloaded (no errors detected within timeout) (pool size: ".concat(this.pool.length, "/").concat(this.maxPoolSize, ", duration=").concat((_poolEntry_durationSeconds = poolEntry.durationSeconds) !== null && _poolEntry_durationSeconds !== void 0 ? _poolEntry_durationSeconds : "?", "s)"));
6395
- }
6396
- if (errorListenerCleanup) {
6397
- errorListenerCleanup();
6398
- }
6399
- return [
6400
- 3,
6401
- 6
6402
- ];
6403
- case 5:
6404
- error = _state.sent();
6405
- if (errorListenerCleanup) {
6406
- errorListenerCleanup();
6407
- }
6408
- timing.recordGamNoFill();
6409
- if (this.deps.debug) {
6410
- console.warn("[PRELOAD-POOL] Failed to preload ad: ".concat(vastUrl), error);
6411
- }
6412
- if (_instanceof(error, Error) && !timing.isTemporaryAdError(error)) {
6413
- timing.failedVastUrls.add(vastUrl);
6414
- } else if (_instanceof(error, Error) && timing.isTemporaryAdError(error)) {
6415
- timing.temporaryFailureUrls.set(vastUrl, Date.now());
6416
- }
6417
- return [
6418
- 3,
6419
- 6
6420
- ];
6421
- case 6:
6422
- return [
6423
- 2
6424
- ];
6425
- }
6426
- });
6427
- }).call(_this);
6428
- }();
6429
- loadPromise.catch(function() {});
6430
- return [
6431
- 2
6432
- ];
6433
- });
6434
- }).call(this);
6306
+ key: "shouldUseNativeHls",
6307
+ value: function shouldUseNativeHls(getStreamType) {
6308
+ var streamType = getStreamType();
6309
+ if (streamType === "other") {
6310
+ return true;
6311
+ }
6312
+ var canNative = this.video.canPlayType("application/vnd.apple.mpegurl");
6313
+ return !!(this.config.allowNativeHls && canNative);
6435
6314
  }
6436
6315
  },
6437
6316
  {
6438
- key: "preloadPoolLoop",
6439
- value: function preloadPoolLoop(baseVastUrl) {
6317
+ key: "setupNativeHls",
6318
+ value: function setupNativeHls() {
6440
6319
  return _async_to_generator(function() {
6441
- var epoch, newUrls, newUrl;
6442
- return _ts_generator(this, function(_state) {
6443
- switch(_state.label){
6444
- case 0:
6445
- if (this.loopRunning) {
6446
- return [
6447
- 2
6448
- ];
6449
- }
6450
- this.loopRunning = true;
6451
- epoch = this.deps.timing.adBreakEpoch;
6452
- if (this.deps.debug) {
6453
- console.log("[PRELOAD-POOL] Starting continuous preload loop");
6454
- }
6455
- _state.label = 1;
6456
- case 1:
6457
- if (!(this.poolActive && epoch === this.deps.timing.adBreakEpoch)) return [
6458
- 3,
6459
- 10
6460
- ];
6461
- if (this.deps.timing.isGamInCooldown()) {
6462
- if (this.deps.debug) {
6463
- console.log("[CIRCUIT-BREAKER] GAM in cooldown, stopping preload pool loop");
6464
- }
6465
- return [
6466
- 3,
6467
- 10
6468
- ];
6469
- }
6470
- if (!(!this.deps.isInAdBreak() && this.pool.length >= this.maxPoolSize)) return [
6471
- 3,
6472
- 3
6473
- ];
6474
- return [
6475
- 4,
6476
- new Promise(function(resolve) {
6477
- return setTimeout(resolve, 2e3);
6478
- })
6479
- ];
6480
- case 2:
6481
- _state.sent();
6482
- return [
6483
- 3,
6484
- 1
6485
- ];
6486
- case 3:
6487
- if (!this.deps.isInAdBreak() && this.deps.getPendingAdBreak() === null) {
6488
- if (this.deps.debug) {
6489
- console.log("[PRELOAD-POOL] Ad break cancelled, stopping preload pool");
6490
- }
6491
- return [
6492
- 3,
6493
- 10
6494
- ];
6495
- }
6496
- _state.label = 4;
6497
- case 4:
6498
- if (!(this.pool.length < this.maxPoolSize)) return [
6499
- 3,
6500
- 8
6501
- ];
6502
- if (!this.poolActive || epoch !== this.deps.timing.adBreakEpoch || this.deps.timing.isGamInCooldown()) {
6503
- return [
6504
- 3,
6505
- 8
6506
- ];
6507
- }
6508
- if (this.deps.isInAdBreak() && !this.deps.timing.hasTimeToStartAnotherAd()) {
6509
- if (this.deps.debug) {
6510
- console.log("[PRELOAD-POOL] Not enough ad break time left, stopping preload");
6511
- }
6512
- return [
6513
- 3,
6514
- 8
6515
- ];
6516
- }
6517
- newUrls = this.deps.generateVastUrlsWithCorrelators(baseVastUrl, 1);
6518
- newUrl = newUrls[0];
6519
- if (!(newUrl && !this.deps.timing.failedVastUrls.has(newUrl) && !this.deps.timing.isUrlInCooldown(newUrl))) return [
6520
- 3,
6521
- 6
6522
- ];
6523
- return [
6524
- 4,
6525
- this.preloadAdIntoPool(newUrl)
6526
- ];
6527
- case 5:
6528
- _state.sent();
6529
- _state.label = 6;
6530
- case 6:
6531
- return [
6532
- 4,
6533
- new Promise(function(resolve) {
6534
- return setTimeout(resolve, 1e3);
6535
- })
6536
- ];
6537
- case 7:
6538
- _state.sent();
6539
- return [
6540
- 3,
6541
- 4
6542
- ];
6543
- case 8:
6544
- return [
6545
- 4,
6546
- new Promise(function(resolve) {
6547
- return setTimeout(resolve, 2e3);
6548
- })
6549
- ];
6550
- case 9:
6551
- _state.sent();
6552
- return [
6553
- 3,
6554
- 1
6555
- ];
6556
- case 10:
6557
- this.loopRunning = false;
6558
- if (this.deps.debug) {
6559
- console.log("[PRELOAD-POOL] Preload loop ended");
6560
- }
6561
- return [
6562
- 2
6563
- ];
6564
- }
6565
- });
6566
- }).call(this);
6567
- }
6568
- },
6569
- {
6570
- key: "getPreloadedAd",
6571
- value: function getPreloadedAd() {
6572
- if (this.pool.length === 0) {
6573
- return null;
6574
- }
6575
- var entry = this.pool.shift();
6576
- if (!entry || !entry.isReady) {
6577
- return null;
6578
- }
6579
- if (this.deps.debug) {
6580
- console.log("[PRELOAD-POOL] Using preloaded ad from pool (".concat(this.pool.length, " remaining)"));
6581
- }
6582
- return {
6583
- vastUrl: entry.vastUrl,
6584
- adController: entry.adController
6585
- };
6586
- }
6587
- },
6588
- {
6589
- key: "stop",
6590
- value: function stop() {
6591
- this.poolActive = false;
6592
- this.loopRunning = false;
6593
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
6594
- try {
6595
- for(var _iterator = this.pool[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
6596
- var entry = _step.value;
6597
- try {
6598
- entry.adController.destroy();
6599
- } catch (error) {
6600
- if (this.deps.debug) {
6601
- console.warn("[PRELOAD-POOL] Error destroying preloaded controller:", error);
6602
- }
6603
- }
6604
- }
6605
- } catch (err) {
6606
- _didIteratorError = true;
6607
- _iteratorError = err;
6608
- } finally{
6609
- try {
6610
- if (!_iteratorNormalCompletion && _iterator.return != null) {
6611
- _iterator.return();
6612
- }
6613
- } finally{
6614
- if (_didIteratorError) {
6615
- throw _iteratorError;
6616
- }
6617
- }
6618
- }
6619
- this.pool = [];
6620
- if (this.deps.debug) {
6621
- console.log("[PRELOAD-POOL] Preload pool stopped and cleaned up");
6622
- }
6623
- }
6624
- }
6625
- ]);
6626
- return AdPreloadPool;
6627
- }();
6628
- // src/player/PlaceholderLayer.ts
6629
- var PlaceholderLayer = /*#__PURE__*/ function() {
6630
- function PlaceholderLayer(video, debug) {
6631
- _class_call_check(this, PlaceholderLayer);
6632
- this.video = video;
6633
- this.debug = debug;
6634
- }
6635
- _create_class(PlaceholderLayer, [
6636
- {
6637
- key: "ensureContainer",
6638
- value: function ensureContainer() {
6639
- if (this.container) {
6640
- return;
6641
- }
6642
- var el = document.createElement("div");
6643
- el.style.position = "absolute";
6644
- el.style.left = "0";
6645
- el.style.top = "0";
6646
- el.style.right = "0";
6647
- el.style.bottom = "0";
6648
- el.style.display = "none";
6649
- el.style.alignItems = "center";
6650
- el.style.justifyContent = "center";
6651
- el.style.pointerEvents = "none";
6652
- el.style.zIndex = "5";
6653
- el.style.backgroundColor = "#000";
6654
- el.style.transition = "opacity 0.3s ease-in-out";
6655
- el.style.opacity = "0";
6656
- if (!this.video.parentElement) {
6657
- if (this.debug) {
6658
- console.warn("[StormcloudVideoPlayer] Video element has no parent for placeholder container");
6659
- }
6660
- return;
6661
- }
6662
- this.video.parentElement.appendChild(el);
6663
- this.container = el;
6664
- }
6665
- },
6666
- {
6667
- key: "show",
6668
- value: function show() {
6669
- var _this = this;
6670
- this.ensureContainer();
6671
- if (!this.container) {
6672
- return;
6673
- }
6674
- if (!this.video.muted) {
6675
- this.video.muted = true;
6676
- if (this.debug) {
6677
- console.log("[StormcloudVideoPlayer] Muted video when showing placeholder");
6678
- }
6679
- }
6680
- var wasHidden = this.container.style.display === "none" || this.container.style.opacity === "0";
6681
- if (wasHidden) {
6682
- this.container.style.transition = "none";
6683
- } else {
6684
- this.container.style.transition = "opacity 0.3s ease-in-out";
6685
- }
6686
- this.container.style.backgroundColor = "#000";
6687
- this.container.style.display = "flex";
6688
- this.container.offsetHeight;
6689
- this.container.style.opacity = "1";
6690
- this.container.style.pointerEvents = "auto";
6691
- if (wasHidden) {
6692
- requestAnimationFrame(function() {
6693
- if (_this.container) {
6694
- _this.container.style.transition = "opacity 0.3s ease-in-out";
6695
- }
6696
- });
6697
- }
6698
- if (this.debug) {
6699
- console.log("[StormcloudVideoPlayer] Showing placeholder layer (between content and ad layer)");
6700
- }
6701
- }
6702
- },
6703
- {
6704
- key: "hide",
6705
- value: function hide() {
6706
- var _this = this;
6707
- if (!this.container) {
6708
- return;
6709
- }
6710
- this.container.style.opacity = "0";
6711
- setTimeout(function() {
6712
- if (_this.container) {
6713
- _this.container.style.display = "none";
6714
- _this.container.style.pointerEvents = "none";
6715
- _this.container.style.backgroundColor = "#000";
6716
- }
6717
- }, 300);
6718
- if (this.debug) {
6719
- console.log("[StormcloudVideoPlayer] Hiding placeholder layer");
6720
- }
6721
- }
6722
- },
6723
- {
6724
- key: "destroy",
6725
- value: function destroy() {
6726
- if (this.container) {
6727
- if (this.container.parentElement) {
6728
- this.container.parentElement.removeChild(this.container);
6729
- }
6730
- this.container = void 0;
6731
- }
6732
- }
6733
- }
6734
- ]);
6735
- return PlaceholderLayer;
6736
- }();
6737
- // src/player/HlsEngine.ts
6738
- var import_hls2 = __toESM(require("hls.js"), 1);
6739
- var HlsEngine = /*#__PURE__*/ function() {
6740
- function HlsEngine(config, video, cueManager, timing, callbacks) {
6741
- _class_call_check(this, HlsEngine);
6742
- this.isLiveStream = false;
6743
- this.nativeHlsMode = false;
6744
- this.videoSrcProtection = null;
6745
- this.bufferedSegmentsCount = 0;
6746
- this.shouldAutoplayAfterBuffering = false;
6747
- this.hasInitialBufferCompleted = false;
6748
- this.config = config;
6749
- this.video = video;
6750
- this.cueManager = cueManager;
6751
- this.timing = timing;
6752
- this.callbacks = callbacks;
6753
- }
6754
- _create_class(HlsEngine, [
6755
- {
6756
- key: "debug",
6757
- get: function get() {
6758
- return !!this.config.debugAdTiming;
6759
- }
6760
- },
6761
- {
6762
- key: "shouldUseNativeHls",
6763
- value: function shouldUseNativeHls(getStreamType) {
6764
- var streamType = getStreamType();
6765
- if (streamType === "other") {
6766
- return true;
6767
- }
6768
- var canNative = this.video.canPlayType("application/vnd.apple.mpegurl");
6769
- return !!(this.config.allowNativeHls && canNative);
6770
- }
6771
- },
6772
- {
6773
- key: "setupNativeHls",
6774
- value: function setupNativeHls() {
6775
- return _async_to_generator(function() {
6776
- var _this_config_isLiveStream, _this_config_lowLatencyMode, adBehavior, _this_video_play;
6320
+ var _this_config_isLiveStream, _this_config_lowLatencyMode, adBehavior, _this_video_play;
6777
6321
  return _ts_generator(this, function(_state) {
6778
6322
  switch(_state.label){
6779
6323
  case 0:
@@ -7346,7 +6890,7 @@ function resizePlayer(video, adPlayer, debug) {
7346
6890
  }
7347
6891
  // src/player/AdBreakOrchestrator.ts
7348
6892
  var AdBreakOrchestrator = /*#__PURE__*/ function() {
7349
- function AdBreakOrchestrator(host, timing, preloadPool, adConfig, cueManager, placeholder) {
6893
+ function AdBreakOrchestrator(host, timing, adConfig, cueManager, placeholder) {
7350
6894
  _class_call_check(this, AdBreakOrchestrator);
7351
6895
  this.inAdBreak = false;
7352
6896
  this.showAds = false;
@@ -7360,7 +6904,6 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
7360
6904
  this.pendingAdBreak = null;
7361
6905
  this.host = host;
7362
6906
  this.timing = timing;
7363
- this.preloadPool = preloadPool;
7364
6907
  this.adConfig = adConfig;
7365
6908
  this.cueManager = cueManager;
7366
6909
  this.placeholder = placeholder;
@@ -7379,23 +6922,19 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
7379
6922
  }
7380
6923
  },
7381
6924
  {
7382
- key: "optimizedPodsEnabled",
7383
- get: // ───────────────────────────────────────────────────────────────
6925
+ // ───────────────────────────────────────────────────────────────
7384
6926
  // IMA event listeners
7385
6927
  // ───────────────────────────────────────────────────────────────
7386
- function get() {
7387
- return this.host.config.optimizedPods !== false;
7388
- }
7389
- },
7390
- {
7391
- key: "nextAdRequestUrl",
6928
+ /**
6929
+ * Produces the next pod ad-request URL for the current break. Every request
6930
+ * (initial and continuous-fetch top-up) carries pod macros (pmad/pmnd/pmxd,
6931
+ * no ppos); pmxd tracks the remaining break time so top-up pods only ask for
6932
+ * what still fits.
6933
+ */ key: "nextAdRequestUrl",
7392
6934
  value: function nextAdRequestUrl(baseVastUrl) {
7393
- if (this.optimizedPodsEnabled) {
7394
- var remaining = Math.min(this.timing.getWallClockRemainingAdMs(), this.timing.getDurationBudgetRemainingMs());
7395
- var breakDurationMs = remaining > 0 ? remaining : void 0;
7396
- return this.host.generatePodVastUrl(baseVastUrl, breakDurationMs);
7397
- }
7398
- return this.host.generateVastUrls(baseVastUrl, 1)[0];
6935
+ var remaining = Math.min(this.timing.getWallClockRemainingAdMs(), this.timing.getDurationBudgetRemainingMs());
6936
+ var breakDurationMs = remaining > 0 ? remaining : void 0;
6937
+ return this.host.generatePodVastUrl(baseVastUrl, breakDurationMs);
7399
6938
  }
7400
6939
  },
7401
6940
  {
@@ -7567,340 +7106,76 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
7567
7106
  // ───────────────────────────────────────────────────────────────
7568
7107
  function handleAdStart(_marker) {
7569
7108
  return _async_to_generator(function() {
7570
- var scheduled, tags, baseVastUrl, adBreakDurationMs, mode, currentMuted, currentVolume, podPlayed, firstAdUrl, usePreloadedAd, preloadedController, preloaded, adPlayer, preservedMuted, preservedVolume, adVolume, adPlayer1, adVolume1, error, fallbackPreloaded, ap, adVolume2, fallbackError;
7109
+ var scheduled, tags, baseVastUrl, adBreakDurationMs, mode, currentMuted, currentVolume, podPlayed;
7571
7110
  return _ts_generator(this, function(_state) {
7572
7111
  switch(_state.label){
7573
7112
  case 0:
7574
7113
  scheduled = this.adConfig.findCurrentOrNextBreak(this.host.video.currentTime * 1e3);
7575
7114
  if (scheduled) {
7576
- this.adConfig.consumedVmapBreakIds.add(this.adConfig.getAdBreakKey(scheduled));
7577
- }
7578
- tags = this.adConfig.selectVastTagsForBreak(scheduled);
7579
- if (tags && tags.length > 0 && tags[0]) {
7580
- baseVastUrl = tags[0];
7581
- } else if (this.adConfig.apiVastTagUrl) {
7582
- baseVastUrl = this.adConfig.apiVastTagUrl;
7583
- } else {
7584
- this.clearPendingAdBreak();
7585
- return [
7586
- 2
7587
- ];
7588
- }
7589
- adBreakDurationMs = _marker.durationSeconds != null ? _marker.durationSeconds * 1e3 : scheduled === null || scheduled === void 0 ? void 0 : scheduled.durationMs;
7590
- if (this.debug) {
7591
- mode = this.host.config.isLiveStream ? "LIVE" : "VOD";
7592
- console.log("[CONTINUOUS-FETCH] ".concat(mode, " MODE: Target duration=").concat(adBreakDurationMs, "ms"));
7593
- }
7594
- this.timing.failedVastUrls.clear();
7595
- this.timing.temporaryFailureUrls.clear();
7596
- this.timing.consecutiveFailures = 0;
7597
- this.continuousFetchingActive = true;
7598
- this.isShowingPlaceholder = false;
7599
- this.timing.totalAdRequestsInBreak = 0;
7600
- if (this.adConfig.podAssignedByPrefetch) {
7601
- this.adConfig.podAssignedByPrefetch = false;
7602
- } else {
7603
- this.adConfig.beginNewAdPod();
7604
- }
7605
- currentMuted = this.host.video.muted;
7606
- currentVolume = this.host.video.volume;
7607
- this.host.getAdPlayer().updateOriginalMutedState(currentMuted, currentVolume);
7608
- this.inAdBreak = true;
7609
- this.timing.adBreakPlayedDurationMs = 0;
7610
- this.timing.currentAdIndex = 0;
7611
- this.timing.totalAdsInBreak = 0;
7612
- this.adPodQueue = [];
7613
- this.showAds = false;
7614
- if (this.timing.expectedAdBreakDurationMs == null && adBreakDurationMs != null) {
7615
- this.timing.expectedAdBreakDurationMs = adBreakDurationMs;
7616
- }
7617
- if (!this.optimizedPodsEnabled) return [
7618
- 3,
7619
- 2
7620
- ];
7621
- return [
7622
- 4,
7623
- this.startOptimizedPod(baseVastUrl, adBreakDurationMs, currentMuted, currentVolume)
7624
- ];
7625
- case 1:
7626
- podPlayed = _state.sent();
7627
- if (podPlayed) {
7628
- return [
7629
- 2
7630
- ];
7631
- }
7632
- if (this.debug) {
7633
- console.log("[POD] Optimized pod unavailable, falling back to sequential single-ad path");
7634
- }
7635
- _state.label = 2;
7636
- case 2:
7637
- usePreloadedAd = false;
7638
- preloaded = this.preloadPool.getPreloadedAd();
7639
- if (preloaded) {
7640
- firstAdUrl = preloaded.vastUrl;
7641
- preloadedController = preloaded.adController;
7642
- usePreloadedAd = true;
7643
- sendAdLoadedTracking(this.host.config.licenseKey, {
7644
- source: "hls",
7645
- vastUrl: firstAdUrl,
7646
- timestamp: /* @__PURE__ */ new Date().toISOString()
7647
- }, this.analyticsContext).catch(function() {});
7648
- if (this.debug) {
7649
- console.log("[CONTINUOUS-FETCH] Using preloaded ad from pool (preloaded in advance, ready immediately!)");
7650
- }
7651
- } else if (this.pendingAdBreak && this.pendingAdBreak.vastUrls.length > 0) {
7652
- this.adRequestQueue = _to_consumable_array(this.pendingAdBreak.vastUrls);
7653
- firstAdUrl = this.adRequestQueue.shift();
7654
- if (this.debug) {
7655
- console.log("[CONTINUOUS-FETCH] Pool empty, using prefetched URLs (".concat(this.adRequestQueue.length + 1, " available)"));
7656
- }
7657
- this.clearPendingAdBreak();
7658
- } else {
7659
- if (this.debug) {
7660
- console.log("[CONTINUOUS-FETCH] Generating new ad URLs...");
7661
- }
7662
- firstAdUrl = this.nextAdRequestUrl(baseVastUrl);
7663
- this.adRequestQueue = [];
7664
- }
7665
- if (!firstAdUrl) {
7666
- if (this.debug) {
7667
- console.warn("[CONTINUOUS-FETCH] Failed to get first ad URL");
7668
- }
7669
- this.handleAdPodComplete();
7670
- return [
7671
- 2
7672
- ];
7673
- }
7674
- if (this.debug) {
7675
- console.log("[CONTINUOUS-FETCH] First VAST URL:", firstAdUrl);
7676
- }
7677
- _state.label = 3;
7678
- case 3:
7679
- _state.trys.push([
7680
- 3,
7681
- 14,
7682
- ,
7683
- 22
7684
- ]);
7685
- if (!(usePreloadedAd && preloadedController)) return [
7686
- 3,
7687
- 7
7688
- ];
7689
- if (!!this.timing.ensureLoadedAdFitsBudget(preloadedController)) return [
7690
- 3,
7691
- 5
7692
- ];
7693
- this.timing.rejectLoadedAdForDuration(preloadedController);
7694
- this.startContinuousFetching(baseVastUrl);
7695
- return [
7696
- 4,
7697
- this.tryNextAvailableAdWithRateLimit()
7698
- ];
7699
- case 4:
7700
- _state.sent();
7701
- return [
7702
- 2
7703
- ];
7704
- case 5:
7705
- adPlayer = this.host.getAdPlayer();
7706
- preservedMuted = adPlayer.getOriginalMutedState();
7707
- preservedVolume = adPlayer.getOriginalVolume();
7708
- adPlayer.destroy();
7709
- this.host.video.muted = true;
7710
- this.host.setAdPlayer(preloadedController);
7711
- preloadedController.updateOriginalMutedState(preservedMuted, preservedVolume);
7712
- this.attachImaEventListeners();
7713
- if (this.debug) {
7714
- console.log("[CONTINUOUS-FETCH] Using preloaded ad, resuming and starting playback immediately (no request delay!)");
7715
- }
7716
- preloadedController.resume();
7717
- this.timing.consecutiveFailures = 0;
7718
- this.startContinuousFetching(baseVastUrl);
7719
- if (!this.optimizedPodsEnabled) {
7720
- if (!this.preloadPool.active) {
7721
- this.preloadPool.active = true;
7722
- }
7723
- if (!this.preloadPool.isLoopRunning) {
7724
- this.preloadPool.preloadPoolLoop(baseVastUrl);
7725
- }
7726
- }
7727
- return [
7728
- 4,
7729
- preloadedController.play()
7730
- ];
7731
- case 6:
7732
- _state.sent();
7733
- this.timing.markAdStarted();
7734
- if (this.timing.expectedAdBreakDurationMs != null && this.timing.getAdBreakEndWallClockMs() == null) {
7735
- this.timing.scheduleAdStopAtBreakBoundary();
7736
- }
7737
- adVolume = currentMuted ? 0 : currentVolume;
7738
- preloadedController.setAdVolume(adVolume);
7739
- return [
7740
- 3,
7741
- 13
7742
- ];
7743
- case 7:
7744
- adPlayer1 = this.host.getAdPlayer();
7745
- return [
7746
- 4,
7747
- this.timing.enforceGlobalRateLimit()
7748
- ];
7749
- case 8:
7750
- _state.sent();
7751
- this.timing.lastAdRequestTime = Date.now();
7752
- return [
7753
- 4,
7754
- adPlayer1.requestAds(firstAdUrl)
7755
- ];
7756
- case 9:
7757
- _state.sent();
7758
- sendAdLoadedTracking(this.host.config.licenseKey, {
7759
- source: "hls",
7760
- vastUrl: firstAdUrl,
7761
- timestamp: /* @__PURE__ */ new Date().toISOString()
7762
- }, this.analyticsContext).catch(function() {});
7763
- if (this.debug) {
7764
- console.log("[CONTINUOUS-FETCH] First ad request successful, starting playback");
7765
- }
7766
- if (!!this.timing.ensureLoadedAdFitsBudget(adPlayer1)) return [
7767
- 3,
7768
- 11
7769
- ];
7770
- this.timing.rejectLoadedAdForDuration(adPlayer1);
7771
- this.recreateAdController();
7772
- this.startContinuousFetching(baseVastUrl);
7773
- return [
7774
- 4,
7775
- this.tryNextAvailableAdWithRateLimit()
7776
- ];
7777
- case 10:
7778
- _state.sent();
7779
- return [
7780
- 2
7781
- ];
7782
- case 11:
7783
- this.timing.consecutiveFailures = 0;
7784
- this.startContinuousFetching(baseVastUrl);
7785
- if (!this.optimizedPodsEnabled && !this.preloadPool.active) {
7786
- this.preloadPool.startPreloadPool(baseVastUrl, []);
7787
- }
7788
- return [
7789
- 4,
7790
- adPlayer1.play()
7791
- ];
7792
- case 12:
7793
- _state.sent();
7794
- this.timing.markAdStarted();
7795
- if (this.timing.expectedAdBreakDurationMs != null && this.timing.getAdBreakEndWallClockMs() == null) {
7796
- this.timing.scheduleAdStopAtBreakBoundary();
7797
- }
7798
- adVolume1 = currentMuted ? 0 : currentVolume;
7799
- adPlayer1.setAdVolume(adVolume1);
7800
- _state.label = 13;
7801
- case 13:
7802
- return [
7803
- 3,
7804
- 22
7805
- ];
7806
- case 14:
7807
- error = _state.sent();
7808
- if (this.debug) {
7809
- console.warn("[CONTINUOUS-FETCH] First ad request failed:", error);
7115
+ this.adConfig.consumedVmapBreakIds.add(this.adConfig.getAdBreakKey(scheduled));
7810
7116
  }
7811
- if (!!usePreloadedAd) return [
7812
- 3,
7813
- 20
7814
- ];
7815
- fallbackPreloaded = this.preloadPool.getPreloadedAd();
7816
- if (!fallbackPreloaded) return [
7817
- 3,
7818
- 20
7819
- ];
7117
+ tags = this.adConfig.selectVastTagsForBreak(scheduled);
7118
+ if (tags && tags.length > 0 && tags[0]) {
7119
+ baseVastUrl = tags[0];
7120
+ } else if (this.adConfig.apiVastTagUrl) {
7121
+ baseVastUrl = this.adConfig.apiVastTagUrl;
7122
+ } else {
7123
+ this.clearPendingAdBreak();
7124
+ return [
7125
+ 2
7126
+ ];
7127
+ }
7128
+ adBreakDurationMs = _marker.durationSeconds != null ? _marker.durationSeconds * 1e3 : scheduled === null || scheduled === void 0 ? void 0 : scheduled.durationMs;
7820
7129
  if (this.debug) {
7821
- console.log("[CONTINUOUS-FETCH] First ad failed, using preloaded fallback");
7130
+ mode = this.host.config.isLiveStream ? "LIVE" : "VOD";
7131
+ console.log("[CONTINUOUS-FETCH] ".concat(mode, " MODE: Target duration=").concat(adBreakDurationMs, "ms"));
7822
7132
  }
7823
- _state.label = 15;
7824
- case 15:
7825
- _state.trys.push([
7826
- 15,
7827
- 19,
7828
- ,
7829
- 20
7830
- ]);
7831
- if (!!this.timing.ensureLoadedAdFitsBudget(fallbackPreloaded.adController)) return [
7832
- 3,
7833
- 17
7834
- ];
7835
- this.timing.rejectLoadedAdForDuration(fallbackPreloaded.adController);
7836
- this.startContinuousFetching(baseVastUrl);
7837
- return [
7838
- 4,
7839
- this.tryNextAvailableAdWithRateLimit()
7840
- ];
7841
- case 16:
7842
- _state.sent();
7843
- return [
7844
- 2
7845
- ];
7846
- case 17:
7847
- this.swapToPreloadedAdPlayer(fallbackPreloaded.adController);
7133
+ this.timing.failedVastUrls.clear();
7134
+ this.timing.temporaryFailureUrls.clear();
7848
7135
  this.timing.consecutiveFailures = 0;
7849
- this.startContinuousFetching(baseVastUrl);
7850
- if (!this.optimizedPodsEnabled && !this.preloadPool.active) {
7851
- this.preloadPool.active = true;
7852
- this.preloadPool.preloadPoolLoop(baseVastUrl);
7136
+ this.continuousFetchingActive = true;
7137
+ this.isShowingPlaceholder = false;
7138
+ this.timing.totalAdRequestsInBreak = 0;
7139
+ if (this.adConfig.podAssignedByPrefetch) {
7140
+ this.adConfig.podAssignedByPrefetch = false;
7141
+ } else {
7142
+ this.adConfig.beginNewAdPod();
7853
7143
  }
7854
- ap = this.host.getAdPlayer();
7855
- return [
7856
- 4,
7857
- ap.play()
7858
- ];
7859
- case 18:
7860
- _state.sent();
7861
- this.timing.markAdStarted();
7862
- if (this.timing.expectedAdBreakDurationMs != null && this.timing.getAdBreakEndWallClockMs() == null) {
7863
- this.timing.scheduleAdStopAtBreakBoundary();
7144
+ currentMuted = this.host.video.muted;
7145
+ currentVolume = this.host.video.volume;
7146
+ this.host.getAdPlayer().updateOriginalMutedState(currentMuted, currentVolume);
7147
+ this.inAdBreak = true;
7148
+ this.timing.adBreakPlayedDurationMs = 0;
7149
+ this.timing.currentAdIndex = 0;
7150
+ this.timing.totalAdsInBreak = 0;
7151
+ this.adPodQueue = [];
7152
+ this.showAds = false;
7153
+ if (this.timing.expectedAdBreakDurationMs == null && adBreakDurationMs != null) {
7154
+ this.timing.expectedAdBreakDurationMs = adBreakDurationMs;
7864
7155
  }
7865
- adVolume2 = currentMuted ? 0 : currentVolume;
7866
- ap.setAdVolume(adVolume2);
7867
7156
  return [
7868
- 2
7157
+ 4,
7158
+ this.startOptimizedPod(baseVastUrl, adBreakDurationMs, currentMuted, currentVolume)
7869
7159
  ];
7870
- case 19:
7871
- fallbackError = _state.sent();
7872
- if (this.debug) {
7873
- console.warn("[CONTINUOUS-FETCH] Preloaded fallback also failed:", fallbackError);
7874
- }
7875
- return [
7160
+ case 1:
7161
+ podPlayed = _state.sent();
7162
+ if (!!podPlayed) return [
7876
7163
  3,
7877
- 20
7164
+ 3
7878
7165
  ];
7879
- case 20:
7880
- if (this.timing.isTemporaryAdError(error)) {
7881
- this.timing.temporaryFailureUrls.set(firstAdUrl, Date.now());
7882
- if (this.debug) {
7883
- console.log("[CONTINUOUS-FETCH] First ad had temporary error (no-fill) - will try alternatives");
7884
- }
7885
- } else {
7886
- this.timing.failedVastUrls.add(firstAdUrl);
7887
- if (this.debug) {
7888
- console.log("[CONTINUOUS-FETCH] First ad had permanent error - URL blacklisted");
7889
- }
7166
+ if (this.debug) {
7167
+ console.log("[POD] Initial pod request did not fill; attempting top-up pod request");
7890
7168
  }
7891
- this.timing.consecutiveFailures++;
7169
+ this.continuousFetchingActive = true;
7892
7170
  this.startContinuousFetching(baseVastUrl);
7893
7171
  return [
7894
7172
  4,
7895
7173
  this.tryNextAvailableAdWithRateLimit()
7896
7174
  ];
7897
- case 21:
7175
+ case 2:
7898
7176
  _state.sent();
7899
- return [
7900
- 3,
7901
- 22
7902
- ];
7903
- case 22:
7177
+ _state.label = 3;
7178
+ case 3:
7904
7179
  return [
7905
7180
  2
7906
7181
  ];
@@ -7974,7 +7249,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
7974
7249
  ];
7975
7250
  }
7976
7251
  if (this.debug) {
7977
- console.log(podCount === 1 ? "[POD] Response contained a single ad; playing it and enabling sequential top-up" : "[POD] Optimized pod returned ".concat(podCount, " ads; playing pod in one controller"));
7252
+ console.log(podCount === 1 ? "[POD] Response contained a single ad; playing it and enabling pod top-up" : "[POD] Optimized pod returned ".concat(podCount, " ads; playing pod in one controller"));
7978
7253
  }
7979
7254
  sendAdLoadedTracking(this.host.config.licenseKey, {
7980
7255
  source: "hls",
@@ -7994,10 +7269,8 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
7994
7269
  }
7995
7270
  adPlayer.setAdVolume(currentMuted ? 0 : currentVolume);
7996
7271
  this.timing.consecutiveFailures = 0;
7997
- if (podCount === 1) {
7998
- this.continuousFetchingActive = true;
7999
- this.startContinuousFetching(baseVastUrl);
8000
- }
7272
+ this.continuousFetchingActive = true;
7273
+ this.startContinuousFetching(baseVastUrl);
8001
7274
  return [
8002
7275
  2,
8003
7276
  true
@@ -8030,20 +7303,6 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8030
7303
  }).call(this);
8031
7304
  }
8032
7305
  },
8033
- {
8034
- key: "swapToPreloadedAdPlayer",
8035
- value: function swapToPreloadedAdPlayer(preloadedController) {
8036
- var adPlayer = this.host.getAdPlayer();
8037
- var preservedMuted = adPlayer.getOriginalMutedState();
8038
- var preservedVolume = adPlayer.getOriginalVolume();
8039
- adPlayer.destroy();
8040
- this.host.video.muted = true;
8041
- this.host.setAdPlayer(preloadedController);
8042
- this.attachImaEventListeners();
8043
- preloadedController.updateOriginalMutedState(preservedMuted, preservedVolume);
8044
- preloadedController.resume();
8045
- }
8046
- },
8047
7306
  {
8048
7307
  // ───────────────────────────────────────────────────────────────
8049
7308
  // Continuous fetching
@@ -8294,7 +7553,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8294
7553
  value: function tryNextAvailableAd() {
8295
7554
  var retryCount = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
8296
7555
  return _async_to_generator(function() {
8297
- var remaining, preloaded, ap, error, nextAdUrl, error1, errorMessage, maxRetries;
7556
+ var remaining, nextAdUrl, error, errorMessage, maxRetries;
8298
7557
  return _ts_generator(this, function(_state) {
8299
7558
  switch(_state.label){
8300
7559
  case 0:
@@ -8332,132 +7591,71 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8332
7591
  ];
8333
7592
  }
8334
7593
  this.timing.cleanupTemporaryFailures();
8335
- preloaded = this.preloadPool.getPreloadedAd();
8336
- if (!preloaded) return [
8337
- 3,
8338
- 6
8339
- ];
8340
- if (this.debug) {
8341
- console.log("[CONTINUOUS-FETCH] Using preloaded ad from pool");
8342
- }
8343
- sendAdLoadedTracking(this.host.config.licenseKey, {
8344
- source: "hls",
8345
- vastUrl: preloaded.vastUrl,
8346
- timestamp: /* @__PURE__ */ new Date().toISOString()
8347
- }, this.analyticsContext).catch(function() {});
8348
7594
  _state.label = 1;
8349
7595
  case 1:
8350
- _state.trys.push([
8351
- 1,
8352
- 5,
8353
- ,
8354
- 6
8355
- ]);
8356
- if (!!this.timing.ensureLoadedAdFitsBudget(preloaded.adController)) return [
8357
- 3,
8358
- 3
8359
- ];
8360
- this.timing.rejectLoadedAdForDuration(preloaded.adController);
8361
- return [
8362
- 4,
8363
- this.tryNextAvailableAdWithRateLimit()
8364
- ];
8365
- case 2:
8366
- _state.sent();
8367
- return [
8368
- 2
8369
- ];
8370
- case 3:
8371
- this.swapToPreloadedAdPlayer(preloaded.adController);
8372
- ap = this.host.getAdPlayer();
8373
- return [
8374
- 4,
8375
- ap.play()
8376
- ];
8377
- case 4:
8378
- _state.sent();
8379
- this.timing.markAdStarted();
8380
- if (this.timing.expectedAdBreakDurationMs != null && this.timing.getAdBreakEndWallClockMs() == null) {
8381
- this.timing.scheduleAdStopAtBreakBoundary();
8382
- }
8383
- ap.setAdVolume(getAdAudioVolume(ap));
8384
- this.timing.consecutiveFailures = 0;
8385
- return [
8386
- 2
8387
- ];
8388
- case 5:
8389
- error = _state.sent();
8390
- if (this.debug) {
8391
- console.warn("[CONTINUOUS-FETCH] Preloaded ad failed to play:", error);
8392
- }
8393
- return [
8394
- 3,
8395
- 6
8396
- ];
8397
- case 6:
8398
7596
  if (!(this.adRequestQueue.length > 0)) return [
8399
7597
  3,
8400
- 14
7598
+ 9
8401
7599
  ];
8402
7600
  nextAdUrl = this.adRequestQueue.shift();
8403
7601
  if (!nextAdUrl) return [
8404
7602
  3,
8405
- 6
7603
+ 1
8406
7604
  ];
8407
7605
  if (this.timing.failedVastUrls.has(nextAdUrl)) {
8408
7606
  if (this.debug) console.log("[CONTINUOUS-FETCH] Skipping permanently-failed URL, trying next...");
8409
7607
  return [
8410
7608
  3,
8411
- 6
7609
+ 1
8412
7610
  ];
8413
7611
  }
8414
7612
  if (this.timing.isUrlInCooldown(nextAdUrl)) {
8415
7613
  if (this.debug) console.log("[CONTINUOUS-FETCH] Skipping URL in cooldown (recent no-fill), trying next...");
8416
7614
  return [
8417
7615
  3,
8418
- 6
7616
+ 1
8419
7617
  ];
8420
7618
  }
8421
7619
  if (this.debug) {
8422
7620
  console.log("[CONTINUOUS-FETCH] Requesting next ad via HLS ad player (".concat(this.timing.currentAdIndex + 1, ", ").concat(this.adRequestQueue.length, " remaining in queue)"));
8423
7621
  }
8424
- _state.label = 7;
8425
- case 7:
7622
+ _state.label = 2;
7623
+ case 2:
8426
7624
  _state.trys.push([
8427
- 7,
8428
- 9,
7625
+ 2,
7626
+ 4,
8429
7627
  ,
8430
- 13
7628
+ 8
8431
7629
  ]);
8432
7630
  return [
8433
7631
  4,
8434
7632
  this.playSingleAd(nextAdUrl)
8435
7633
  ];
8436
- case 8:
7634
+ case 3:
8437
7635
  _state.sent();
8438
7636
  this.timing.consecutiveFailures = 0;
8439
7637
  return [
8440
7638
  3,
8441
- 13
7639
+ 8
8442
7640
  ];
8443
- case 9:
8444
- error1 = _state.sent();
8445
- errorMessage = error1.message;
7641
+ case 4:
7642
+ error = _state.sent();
7643
+ errorMessage = error.message;
8446
7644
  if (this.debug) console.log("[CONTINUOUS-FETCH] Ad request failed:", errorMessage);
8447
7645
  if (!errorMessage.includes("ad_duration_exceeds_budget")) return [
8448
7646
  3,
8449
- 11
7647
+ 6
8450
7648
  ];
8451
7649
  return [
8452
7650
  4,
8453
7651
  this.tryNextAvailableAdWithRateLimit()
8454
7652
  ];
8455
- case 10:
7653
+ case 5:
8456
7654
  _state.sent();
8457
7655
  return [
8458
7656
  2
8459
7657
  ];
8460
- case 11:
7658
+ case 6:
8461
7659
  if (!errorMessage.includes("permanently failed") && !errorMessage.includes("in cooldown")) {
8462
7660
  this.timing.consecutiveFailures++;
8463
7661
  }
@@ -8465,21 +7663,21 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8465
7663
  4,
8466
7664
  this.tryNextAvailableAdWithRateLimit()
8467
7665
  ];
8468
- case 12:
7666
+ case 7:
8469
7667
  _state.sent();
8470
7668
  return [
8471
7669
  3,
8472
- 13
7670
+ 8
8473
7671
  ];
8474
- case 13:
7672
+ case 8:
8475
7673
  return [
8476
7674
  2
8477
7675
  ];
8478
- case 14:
7676
+ case 9:
8479
7677
  maxRetries = 3;
8480
7678
  if (!(this.continuousFetchingActive && retryCount < maxRetries && remaining > 2e3)) return [
8481
7679
  3,
8482
- 17
7680
+ 12
8483
7681
  ];
8484
7682
  if (this.debug) {
8485
7683
  console.log("[CONTINUOUS-FETCH] Queue empty, waiting for URLs... (".concat(retryCount + 1, "/").concat(maxRetries, ")"));
@@ -8490,18 +7688,18 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8490
7688
  return setTimeout(resolve, 500);
8491
7689
  })
8492
7690
  ];
8493
- case 15:
7691
+ case 10:
8494
7692
  _state.sent();
8495
7693
  return [
8496
7694
  4,
8497
7695
  this.tryNextAvailableAd(retryCount + 1)
8498
7696
  ];
8499
- case 16:
7697
+ case 11:
8500
7698
  _state.sent();
8501
7699
  return [
8502
7700
  2
8503
7701
  ];
8504
- case 17:
7702
+ case 12:
8505
7703
  if (!this.isShowingPlaceholder && remaining > 1e3) {
8506
7704
  this.showPlaceholderAndWaitForAds();
8507
7705
  } else {
@@ -8523,7 +7721,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8523
7721
  // ───────────────────────────────────────────────────────────────
8524
7722
  function playSingleAd(vastTagUrl) {
8525
7723
  return _async_to_generator(function() {
8526
- var adPlayer, requestToken, ap, playError, preloadedFallback, fbAp, fallbackError, error, errorMessage, preloadedFallback1, fbAp1, fallbackError1;
7724
+ var adPlayer, requestToken, ap, playError, error, errorMessage;
8527
7725
  return _ts_generator(this, function(_state) {
8528
7726
  switch(_state.label){
8529
7727
  case 0:
@@ -8555,9 +7753,9 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8555
7753
  case 1:
8556
7754
  _state.trys.push([
8557
7755
  1,
8558
- 12,
7756
+ 8,
8559
7757
  ,
8560
- 17
7758
+ 9
8561
7759
  ]);
8562
7760
  return [
8563
7761
  4,
@@ -8593,7 +7791,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8593
7791
  4,
8594
7792
  6,
8595
7793
  ,
8596
- 11
7794
+ 7
8597
7795
  ]);
8598
7796
  this.timing.startAdFailsafeTimer(requestToken);
8599
7797
  return [
@@ -8611,55 +7809,11 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8611
7809
  this.timing.temporaryFailureUrls.delete(vastTagUrl);
8612
7810
  return [
8613
7811
  3,
8614
- 11
7812
+ 7
8615
7813
  ];
8616
7814
  case 6:
8617
7815
  playError = _state.sent();
8618
7816
  if (this.debug) console.error("[AD-ERROR] Failed to play ad:", playError);
8619
- preloadedFallback = this.preloadPool.getPreloadedAd();
8620
- if (!preloadedFallback) return [
8621
- 3,
8622
- 10
8623
- ];
8624
- if (this.debug) console.log("[AD-ERROR] Play failed, trying preloaded fallback ad");
8625
- _state.label = 7;
8626
- case 7:
8627
- _state.trys.push([
8628
- 7,
8629
- 9,
8630
- ,
8631
- 10
8632
- ]);
8633
- if (!this.timing.ensureLoadedAdFitsBudget(preloadedFallback.adController)) {
8634
- this.timing.rejectLoadedAdForDuration(preloadedFallback.adController);
8635
- throw playError;
8636
- }
8637
- this.timing.clearAdFailsafeTimer();
8638
- this.swapToPreloadedAdPlayer(preloadedFallback.adController);
8639
- this.timing.consecutiveFailures = 0;
8640
- fbAp = this.host.getAdPlayer();
8641
- return [
8642
- 4,
8643
- fbAp.play()
8644
- ];
8645
- case 8:
8646
- _state.sent();
8647
- this.timing.markAdStarted();
8648
- if (this.timing.expectedAdBreakDurationMs != null && this.timing.getAdBreakEndWallClockMs() == null) {
8649
- this.timing.scheduleAdStopAtBreakBoundary();
8650
- }
8651
- fbAp.setAdVolume(getAdAudioVolume(fbAp));
8652
- return [
8653
- 2
8654
- ];
8655
- case 9:
8656
- fallbackError = _state.sent();
8657
- if (this.debug) console.warn("[AD-ERROR] Preloaded fallback also failed:", fallbackError);
8658
- return [
8659
- 3,
8660
- 10
8661
- ];
8662
- case 10:
8663
7817
  if (this.timing.isTemporaryAdError(playError)) {
8664
7818
  this.timing.temporaryFailureUrls.set(vastTagUrl, Date.now());
8665
7819
  if (this.debug) console.log("[AD-ERROR] Temporary play error - URL can be retried after cooldown");
@@ -8672,57 +7826,15 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8672
7826
  this.timing.activeAdRequestToken = null;
8673
7827
  }
8674
7828
  throw playError;
8675
- case 11:
7829
+ case 7:
8676
7830
  return [
8677
7831
  3,
8678
- 17
7832
+ 9
8679
7833
  ];
8680
- case 12:
7834
+ case 8:
8681
7835
  error = _state.sent();
8682
7836
  errorMessage = (error === null || error === void 0 ? void 0 : error.message) || "";
8683
7837
  if (this.debug) console.error("[AD-ERROR] Ad request failed:", errorMessage);
8684
- preloadedFallback1 = this.preloadPool.getPreloadedAd();
8685
- if (!preloadedFallback1) return [
8686
- 3,
8687
- 16
8688
- ];
8689
- if (this.debug) console.log("[AD-ERROR] Request failed, trying preloaded fallback ad");
8690
- _state.label = 13;
8691
- case 13:
8692
- _state.trys.push([
8693
- 13,
8694
- 15,
8695
- ,
8696
- 16
8697
- ]);
8698
- if (!this.timing.ensureLoadedAdFitsBudget(preloadedFallback1.adController)) {
8699
- this.timing.rejectLoadedAdForDuration(preloadedFallback1.adController);
8700
- throw error;
8701
- }
8702
- this.timing.clearAdRequestWatchdog();
8703
- this.timing.clearAdFailsafeTimer();
8704
- this.swapToPreloadedAdPlayer(preloadedFallback1.adController);
8705
- this.timing.consecutiveFailures = 0;
8706
- fbAp1 = this.host.getAdPlayer();
8707
- return [
8708
- 4,
8709
- fbAp1.play()
8710
- ];
8711
- case 14:
8712
- _state.sent();
8713
- this.timing.markAdStarted();
8714
- fbAp1.setAdVolume(getAdAudioVolume(fbAp1));
8715
- return [
8716
- 2
8717
- ];
8718
- case 15:
8719
- fallbackError1 = _state.sent();
8720
- if (this.debug) console.warn("[AD-ERROR] Preloaded fallback also failed:", fallbackError1);
8721
- return [
8722
- 3,
8723
- 16
8724
- ];
8725
- case 16:
8726
7838
  if (this.timing.isTemporaryAdError(error)) {
8727
7839
  this.timing.temporaryFailureUrls.set(vastTagUrl, Date.now());
8728
7840
  if (this.debug) console.log("[AD-ERROR] Temporary error (no-fill/timeout) - URL can be retried after cooldown");
@@ -8736,7 +7848,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8736
7848
  this.timing.activeAdRequestToken = null;
8737
7849
  }
8738
7850
  throw error;
8739
- case 17:
7851
+ case 9:
8740
7852
  return [
8741
7853
  2
8742
7854
  ];
@@ -8926,7 +8038,6 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8926
8038
  }
8927
8039
  this.timing.resetForBreakEnd();
8928
8040
  this.stopContinuousFetching();
8929
- this.preloadPool.stop();
8930
8041
  this.clearPendingAdBreak();
8931
8042
  if (this.isShowingPlaceholder) {
8932
8043
  this.host.getAdPlayer().hidePlaceholder();
@@ -9036,25 +8147,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
9036
8147
  return _this.adBreak.handleAdFailure();
9037
8148
  }
9038
8149
  });
9039
- this.preloadPool = new AdPreloadPool({
9040
- debug: !!this.config.debugAdTiming,
9041
- createAdPlayer: function createAdPlayer(c) {
9042
- return _this.createAdPlayer(c);
9043
- },
9044
- shouldContinueLiveStreamDuringAds: function shouldContinueLiveStreamDuringAds() {
9045
- return _this.shouldContinueLiveStreamDuringAds();
9046
- },
9047
- timing: this.timing,
9048
- generateVastUrlsWithCorrelators: function generateVastUrlsWithCorrelators(base, count) {
9049
- return _this.generateVastUrls(base, count);
9050
- },
9051
- isInAdBreak: function isInAdBreak() {
9052
- return _this.adBreak.inAdBreak;
9053
- },
9054
- getPendingAdBreak: function getPendingAdBreak() {
9055
- return _this.adBreak.pendingAdBreak;
9056
- }
9057
- });
9058
8150
  this.placeholder = new PlaceholderLayer(this.video, !!this.config.debugAdTiming);
9059
8151
  this.hlsEngine = new HlsEngine(this.config, this.video, this.cueManager, this.timing, {
9060
8152
  onManifestParsed: function onManifestParsed(isLive) {
@@ -9101,13 +8193,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
9101
8193
  getLiveSyncPosition: function getLiveSyncPosition() {
9102
8194
  return _this.hlsEngine.getLiveSyncPosition();
9103
8195
  },
9104
- generateVastUrls: function generateVastUrls(base, count) {
9105
- return _this.generateVastUrls(base, count);
9106
- },
9107
8196
  generatePodVastUrl: function generatePodVastUrl(base, breakDurationMs) {
9108
8197
  return _this.generatePodVastUrl(base, breakDurationMs);
9109
8198
  }
9110
- }, this.timing, this.preloadPool, this.adConfig, this.cueManager, this.placeholder);
8199
+ }, this.timing, this.adConfig, this.cueManager, this.placeholder);
9111
8200
  }
9112
8201
  _create_class(StormcloudVideoPlayer, [
9113
8202
  {
@@ -9132,12 +8221,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
9132
8221
  } : {}));
9133
8222
  }
9134
8223
  },
9135
- {
9136
- key: "generateVastUrls",
9137
- value: function generateVastUrls(baseUrl, count) {
9138
- return this.adConfig.generateVastUrlsWithCorrelators(baseUrl, count, this.adPlayer, this.palNonce, this.adBreak.inAdBreak);
9139
- }
9140
- },
9141
8224
  {
9142
8225
  key: "generatePodVastUrl",
9143
8226
  value: function generatePodVastUrl(baseUrl, breakDurationMs) {
@@ -9533,11 +8616,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
9533
8616
  }
9534
8617
  this.adConfig.beginNewAdPod();
9535
8618
  this.adConfig.podAssignedByPrefetch = true;
9536
- var optimizedPods = this.config.optimizedPods !== false;
9537
8619
  var breakDurationMs = marker.durationSeconds != null ? marker.durationSeconds * 1e3 : void 0;
9538
- var generatedUrls = optimizedPods ? [
8620
+ var generatedUrls = [
9539
8621
  this.generatePodVastUrl(baseVastUrl, breakDurationMs)
9540
- ] : this.generateVastUrls(baseVastUrl, 1);
8622
+ ];
9541
8623
  this.adBreak.pendingAdBreak = _object_spread_props(_object_spread({
9542
8624
  marker: marker
9543
8625
  }, fragmentSn !== void 0 ? {
@@ -9559,15 +8641,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
9559
8641
  }, detectPayload), buildAnalyticsContext(this.config)).catch(function() {});
9560
8642
  if (this.debug) {
9561
8643
  console.log("[PREFETCH] Starting ad prefetch for upcoming ad break");
9562
- console.log("[PREFETCH] Pre-generated ".concat(generatedUrls.length, " ").concat(optimizedPods ? "pod" : "VAST", " URL(s)"));
9563
- }
9564
- if (optimizedPods) {
9565
- if (this.debug) {
9566
- console.log("[PREFETCH] Optimized pods enabled - skipping single-ad preload pool");
9567
- }
9568
- return;
8644
+ console.log("[PREFETCH] Pre-generated pod request URL");
9569
8645
  }
9570
- this.preloadPool.startPreloadPool(baseVastUrl, generatedUrls.slice(0, 1), false);
9571
8646
  }
9572
8647
  },
9573
8648
  {
@@ -9806,7 +8881,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
9806
8881
  value: function destroy() {
9807
8882
  var _this_adPlayer;
9808
8883
  this.adBreak.stopContinuousFetching();
9809
- this.preloadPool.stop();
9810
8884
  this.timing.destroy();
9811
8885
  this.adBreak.clearPendingAdBreak();
9812
8886
  this.placeholder.destroy();