stormcloud-video-player 0.8.65 → 0.8.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.cjs CHANGED
@@ -330,26 +330,6 @@ function _ts_generator(thisArg, body) {
330
330
  };
331
331
  }
332
332
  }
333
- function _ts_values(o) {
334
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
335
- if (m) {
336
- return m.call(o);
337
- }
338
- if (o && typeof o.length === "number") {
339
- return {
340
- next: function() {
341
- if (o && i >= o.length) {
342
- o = void 0;
343
- }
344
- return {
345
- value: o && o[i++],
346
- done: !o
347
- };
348
- }
349
- };
350
- }
351
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
352
- }
353
333
  function _type_of(obj) {
354
334
  "@swc/helpers - typeof";
355
335
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
@@ -991,6 +971,8 @@ function createHlsAdPlayer(contentVideo, options) {
991
971
  var pendingPlayPromise;
992
972
  var currentVastTagUrl;
993
973
  var funnelContext = {};
974
+ var mediaProbe;
975
+ var lastPodAdElementCount = 0;
994
976
  var mediaCandidates = [];
995
977
  var mediaCandidateIndex = 0;
996
978
  var mediaStartTimerId;
@@ -1108,6 +1090,7 @@ function createHlsAdPlayer(contentVideo, options) {
1108
1090
  stage: stage,
1109
1091
  breakId: funnelContext.breakId,
1110
1092
  requestId: funnelContext.requestId,
1093
+ controllerId: funnelContext.controllerId,
1111
1094
  visibilityState: typeof document !== "undefined" ? document.visibilityState : void 0,
1112
1095
  adId: currentAd === null || currentAd === void 0 ? void 0 : currentAd.id,
1113
1096
  podIndex: podIndex,
@@ -1297,7 +1280,6 @@ function createHlsAdPlayer(contentVideo, options) {
1297
1280
  });
1298
1281
  logFunnel("media_candidate", _object_spread_props(_object_spread({}, details), {
1299
1282
  reason: "accepted",
1300
- // Mixed-content media is often auto-upgraded, so it is kept as a last resort.
1301
1283
  why: insecure ? "insecure_http_deprioritized" : "playable",
1302
1284
  score: score
1303
1285
  }));
@@ -1325,6 +1307,145 @@ function createHlsAdPlayer(contentVideo, options) {
1325
1307
  var url = (mediaFile.url.toLowerCase().split("?")[0] || "").trim();
1326
1308
  return type.startsWith("audio/") || url.endsWith(".mp3") || url.endsWith(".aac") || url.endsWith(".m4a") || url.endsWith(".ogg") || url.endsWith(".oga") || url.endsWith(".opus") || url.endsWith(".wav") || url.endsWith(".weba");
1327
1309
  }
1310
+ function getMediaProbe() {
1311
+ if (adVideoElement) return adVideoElement;
1312
+ if (!mediaProbe && typeof document !== "undefined") {
1313
+ mediaProbe = document.createElement("video");
1314
+ }
1315
+ return mediaProbe;
1316
+ }
1317
+ function evaluateMediaFile(mf) {
1318
+ var _mf_textContent;
1319
+ var type = mf.getAttribute("type") || "";
1320
+ var url = ((_mf_textContent = mf.textContent) === null || _mf_textContent === void 0 ? void 0 : _mf_textContent.trim()) || "";
1321
+ var delivery = mf.getAttribute("delivery") || void 0;
1322
+ var codec = mf.getAttribute("codec") || void 0;
1323
+ if (!url) {
1324
+ return {
1325
+ category: "missing_media",
1326
+ whyRejected: "empty_url",
1327
+ canPlayType: ""
1328
+ };
1329
+ }
1330
+ var apiFramework = (mf.getAttribute("apiFramework") || "").toUpperCase();
1331
+ if (apiFramework === "VPAID") {
1332
+ return {
1333
+ category: "vpaid",
1334
+ whyRejected: "vpaid_not_supported",
1335
+ canPlayType: ""
1336
+ };
1337
+ }
1338
+ try {
1339
+ var protocol = new URL(url).protocol;
1340
+ if (protocol !== "https:" && protocol !== "http:") {
1341
+ return {
1342
+ category: "invalid_url",
1343
+ whyRejected: "protocol_".concat(protocol),
1344
+ canPlayType: ""
1345
+ };
1346
+ }
1347
+ } catch (unused) {
1348
+ return {
1349
+ category: "invalid_url",
1350
+ whyRejected: "unparseable_url",
1351
+ canPlayType: ""
1352
+ };
1353
+ }
1354
+ var bitrateAttr = mf.getAttribute("bitrate");
1355
+ var bitrateValue = bitrateAttr ? parseInt(bitrateAttr, 10) : void 0;
1356
+ var file = {
1357
+ url: url,
1358
+ type: type,
1359
+ width: parseInt(mf.getAttribute("width") || "1920", 10),
1360
+ height: parseInt(mf.getAttribute("height") || "1080", 10),
1361
+ bitrate: bitrateValue && bitrateValue > 0 ? bitrateValue : void 0,
1362
+ delivery: delivery,
1363
+ codec: codec
1364
+ };
1365
+ if (isAudioMediaFile(file)) {
1366
+ return {
1367
+ category: "audio_only",
1368
+ whyRejected: type.toLowerCase().startsWith("audio/") ? "audio_mime" : "audio_extension",
1369
+ canPlayType: ""
1370
+ };
1371
+ }
1372
+ var isHls = isHlsMediaFile(file);
1373
+ var hasExplicitDimensions = mf.getAttribute("width") != null && mf.getAttribute("height") != null;
1374
+ if (!isHls && hasExplicitDimensions && (file.width <= 1 || file.height <= 1)) {
1375
+ return {
1376
+ category: "audio_only",
1377
+ whyRejected: "zero_dimensions",
1378
+ canPlayType: ""
1379
+ };
1380
+ }
1381
+ var probe = getMediaProbe();
1382
+ if (isHls) {
1383
+ var _ref;
1384
+ var nativeHls = (_ref = probe === null || probe === void 0 ? void 0 : probe.canPlayType("application/vnd.apple.mpegurl")) !== null && _ref !== void 0 ? _ref : "";
1385
+ if (import_hls.default.isSupported()) {
1386
+ return {
1387
+ file: file,
1388
+ whyAccepted: "hls_js",
1389
+ canPlayType: nativeHls
1390
+ };
1391
+ }
1392
+ if (nativeHls !== "") {
1393
+ return {
1394
+ file: file,
1395
+ whyAccepted: "native_hls",
1396
+ canPlayType: nativeHls
1397
+ };
1398
+ }
1399
+ return {
1400
+ category: "unsupported_hls",
1401
+ whyRejected: "no_hls_support",
1402
+ canPlayType: nativeHls
1403
+ };
1404
+ }
1405
+ if (!isProgressiveMediaFile(file)) {
1406
+ return {
1407
+ category: "unsupported_mime",
1408
+ whyRejected: "not_a_video_mime",
1409
+ canPlayType: ""
1410
+ };
1411
+ }
1412
+ if (!probe) {
1413
+ return {
1414
+ file: file,
1415
+ whyAccepted: "no_probe_available",
1416
+ canPlayType: ""
1417
+ };
1418
+ }
1419
+ var baseType = type || "video/mp4";
1420
+ var canPlay2 = probe.canPlayType(baseType);
1421
+ if (canPlay2 === "") {
1422
+ return {
1423
+ category: "unsupported_mime",
1424
+ whyRejected: "canPlayType_empty",
1425
+ canPlayType: canPlay2
1426
+ };
1427
+ }
1428
+ if (codec) {
1429
+ var withCodec = probe.canPlayType("".concat(baseType, '; codecs="').concat(codec, '"'));
1430
+ if (withCodec === "") {
1431
+ return {
1432
+ category: "unsupported_codec",
1433
+ whyRejected: "codec_canPlayType_empty",
1434
+ canPlayType: withCodec
1435
+ };
1436
+ }
1437
+ return {
1438
+ file: file,
1439
+ whyAccepted: "canPlayType_".concat(withCodec),
1440
+ canPlayType: withCodec
1441
+ };
1442
+ }
1443
+ return {
1444
+ file: file,
1445
+ whyAccepted: "canPlayType_".concat(canPlay2),
1446
+ canPlayType: canPlay2
1447
+ };
1448
+ }
1328
1449
  function collectVideoMediaFiles(linear, verbose, stats) {
1329
1450
  var mediaFileElements = linear.querySelectorAll(":scope > MediaFiles > MediaFile");
1330
1451
  var mediaFiles = [];
@@ -1334,57 +1455,33 @@ function createHlsAdPlayer(contentVideo, options) {
1334
1455
  }
1335
1456
  mediaFileElements.forEach(function(mf, index) {
1336
1457
  var _mf_textContent;
1337
- var type = mf.getAttribute("type") || "";
1458
+ var result = evaluateMediaFile(mf);
1338
1459
  var url = ((_mf_textContent = mf.textContent) === null || _mf_textContent === void 0 ? void 0 : _mf_textContent.trim()) || "";
1339
- var width = mf.getAttribute("width") || "";
1340
- var height = mf.getAttribute("height") || "";
1341
- if (verbose) {
1342
- console.log("[HlsAdPlayer] MediaFile ".concat(index, ': type="').concat(type, '", url="').concat(url, '", width="').concat(width, '", height="').concat(height, '"'));
1343
- }
1344
- if (!url) {
1345
- if (verbose) {
1346
- console.warn("[HlsAdPlayer] MediaFile ".concat(index, " has empty URL"));
1347
- }
1348
- return;
1349
- }
1350
- var apiFramework = (mf.getAttribute("apiFramework") || "").toUpperCase();
1351
- if (apiFramework === "VPAID") {
1352
- if (stats) stats.vpaid++;
1353
- if (verbose) {
1354
- console.log("[HlsAdPlayer] MediaFile ".concat(index, " ignored (VPAID creatives are not supported)"));
1355
- }
1356
- return;
1357
- }
1358
- var bitrateAttr = mf.getAttribute("bitrate");
1359
- var bitrateValue = bitrateAttr ? parseInt(bitrateAttr, 10) : void 0;
1360
- var mediaFile = {
1361
- url: url,
1362
- type: type,
1363
- width: parseInt(width || "1920", 10),
1364
- height: parseInt(height || "1080", 10),
1365
- bitrate: bitrateValue && bitrateValue > 0 ? bitrateValue : void 0
1366
- };
1367
- if (isAudioMediaFile(mediaFile)) {
1368
- if (stats) stats.audio++;
1369
- console.warn("[HlsAdPlayer] MediaFile ".concat(index, ' skipped (audio-only, type="').concat(type, '") — audio ads are not played to avoid a black screen'));
1460
+ var accepted = "file" in result;
1461
+ logFunnel("mediafile_evaluated", {
1462
+ reason: accepted ? "accepted" : result.category,
1463
+ index: index,
1464
+ type: mf.getAttribute("type") || "",
1465
+ delivery: mf.getAttribute("delivery") || void 0,
1466
+ codec: mf.getAttribute("codec") || void 0,
1467
+ apiFramework: mf.getAttribute("apiFramework") || void 0,
1468
+ width: mf.getAttribute("width"),
1469
+ height: mf.getAttribute("height"),
1470
+ fileUrl: redactUrl(url),
1471
+ canPlayType: result.canPlayType,
1472
+ whyAccepted: accepted ? result.whyAccepted : void 0,
1473
+ whyRejected: accepted ? void 0 : result.whyRejected
1474
+ });
1475
+ if ("file" in result) {
1476
+ mediaFiles.push(result.file);
1370
1477
  return;
1371
1478
  }
1372
- var hasExplicitDimensions = mf.getAttribute("width") != null && mf.getAttribute("height") != null;
1373
- if (!isHlsMediaFile(mediaFile) && hasExplicitDimensions && (mediaFile.width <= 1 || mediaFile.height <= 1)) {
1374
- if (stats) stats.audio++;
1375
- console.warn("[HlsAdPlayer] MediaFile ".concat(index, " skipped (degenerate dimensions ").concat(mediaFile.width, "x").concat(mediaFile.height, ', type="').concat(type, '") — likely an audio-only placeholder rendition'));
1376
- return;
1479
+ if (stats) {
1480
+ var _stats_categories_result_category;
1481
+ stats.categories[result.category] = ((_stats_categories_result_category = stats.categories[result.category]) !== null && _stats_categories_result_category !== void 0 ? _stats_categories_result_category : 0) + 1;
1377
1482
  }
1378
- if (isHlsMediaFile(mediaFile) || isProgressiveMediaFile(mediaFile)) {
1379
- mediaFiles.push(mediaFile);
1380
- if (verbose) {
1381
- console.log("[HlsAdPlayer] Added ".concat(isHlsMediaFile(mediaFile) ? "HLS" : "progressive", " MediaFile: ").concat(url));
1382
- }
1383
- } else {
1384
- if (stats) stats.unsupported++;
1385
- if (verbose) {
1386
- console.log("[HlsAdPlayer] MediaFile ".concat(index, ' ignored (type="').concat(type, '" is not supported)'));
1387
- }
1483
+ if (result.category === "audio_only") {
1484
+ console.warn("[HlsAdPlayer] MediaFile ".concat(index, " skipped (audio-only: ").concat(result.whyRejected, ', type="').concat(mf.getAttribute("type") || "", '") — audio-only ads are not played on video inventory'));
1388
1485
  }
1389
1486
  });
1390
1487
  return mediaFiles;
@@ -1606,7 +1703,7 @@ function createHlsAdPlayer(contentVideo, options) {
1606
1703
  if (adElement.getAttribute("conditionalAd") === "true") {
1607
1704
  console.warn("[HlsAdPlayer] Skipping conditional <Ad> (VPAID-only)");
1608
1705
  logFunnel("vast_no_supported_media", {
1609
- reason: "vpaid_only",
1706
+ reason: "vpaid",
1610
1707
  conditionalAd: true
1611
1708
  });
1612
1709
  return {
@@ -1619,9 +1716,7 @@ function createHlsAdPlayer(contentVideo, options) {
1619
1716
  var mediaFiles = [];
1620
1717
  var rejectStats = {
1621
1718
  total: 0,
1622
- vpaid: 0,
1623
- audio: 0,
1624
- unsupported: 0
1719
+ categories: {}
1625
1720
  };
1626
1721
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1627
1722
  try {
@@ -1650,10 +1745,39 @@ function createHlsAdPlayer(contentVideo, options) {
1650
1745
  }
1651
1746
  if (!linear) {
1652
1747
  console.warn("[HlsAdPlayer] No supported linear media files in <Ad>");
1653
- var reason = rejectStats.total === 0 ? "no_mediafiles" : rejectStats.vpaid > 0 ? "vpaid_only" : rejectStats.audio > 0 ? "audio_only" : "unsupported_type";
1654
- logFunnel("vast_no_supported_media", _object_spread({
1655
- reason: reason
1656
- }, rejectStats));
1748
+ var reason = "missing_media";
1749
+ var top = 0;
1750
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
1751
+ try {
1752
+ for(var _iterator1 = Object.keys(rejectStats.categories)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
1753
+ var category = _step1.value;
1754
+ var _rejectStats_categories_category;
1755
+ var count = (_rejectStats_categories_category = rejectStats.categories[category]) !== null && _rejectStats_categories_category !== void 0 ? _rejectStats_categories_category : 0;
1756
+ if (count > top) {
1757
+ top = count;
1758
+ reason = category;
1759
+ }
1760
+ }
1761
+ } catch (err) {
1762
+ _didIteratorError1 = true;
1763
+ _iteratorError1 = err;
1764
+ } finally{
1765
+ try {
1766
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
1767
+ _iterator1.return();
1768
+ }
1769
+ } finally{
1770
+ if (_didIteratorError1) {
1771
+ throw _iteratorError1;
1772
+ }
1773
+ }
1774
+ }
1775
+ if (rejectStats.total > 0 && top === 0) reason = "other";
1776
+ logFunnel("vast_no_supported_media", {
1777
+ reason: reason,
1778
+ mediaFileCount: rejectStats.total,
1779
+ rejectedByCategory: rejectStats.categories
1780
+ });
1657
1781
  return {
1658
1782
  type: "empty",
1659
1783
  errorUrls: errorUrls,
@@ -1683,9 +1807,9 @@ function createHlsAdPlayer(contentVideo, options) {
1683
1807
  }
1684
1808
  }
1685
1809
  function fetchVastXml(vastTagUrl) {
1686
- var credentials = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "include";
1810
+ var credentials = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "include", kind = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "gam";
1687
1811
  return _async_to_generator(function() {
1688
- var controller, timeoutId, requestVast, response, error, error1;
1812
+ var controller, timeoutId, startedAt, attempt, requestVast, response, error, error1;
1689
1813
  return _ts_generator(this, function(_state) {
1690
1814
  switch(_state.label){
1691
1815
  case 0:
@@ -1697,17 +1821,51 @@ function createHlsAdPlayer(contentVideo, options) {
1697
1821
  timeoutId = controller ? setTimeout(function() {
1698
1822
  return controller.abort();
1699
1823
  }, VAST_REQUEST_TIMEOUT_MS) : void 0;
1824
+ startedAt = Date.now();
1825
+ attempt = 0;
1700
1826
  requestVast = function requestVast(creds) {
1701
- return fetch(vastTagUrl, _object_spread({
1702
- mode: "cors",
1703
- credentials: creds,
1704
- headers: {
1705
- "Accept": "application/xml, text/xml, */*"
1706
- },
1707
- referrerPolicy: "no-referrer-when-downgrade"
1708
- }, controller ? {
1709
- signal: controller.signal
1710
- } : {}));
1827
+ return _async_to_generator(function() {
1828
+ var response;
1829
+ return _ts_generator(this, function(_state) {
1830
+ switch(_state.label){
1831
+ case 0:
1832
+ attempt++;
1833
+ if (kind === "gam") {
1834
+ logFunnel("gam_http_request_sent", {
1835
+ attempt: attempt,
1836
+ credentials: creds
1837
+ });
1838
+ }
1839
+ return [
1840
+ 4,
1841
+ fetch(vastTagUrl, _object_spread({
1842
+ mode: "cors",
1843
+ credentials: creds,
1844
+ headers: {
1845
+ "Accept": "application/xml, text/xml, */*"
1846
+ },
1847
+ referrerPolicy: "no-referrer-when-downgrade"
1848
+ }, controller ? {
1849
+ signal: controller.signal
1850
+ } : {}))
1851
+ ];
1852
+ case 1:
1853
+ response = _state.sent();
1854
+ if (kind === "gam") {
1855
+ logFunnel("gam_response_received", {
1856
+ attempt: attempt,
1857
+ httpStatus: response.status,
1858
+ ok: response.ok,
1859
+ elapsedMs: Date.now() - startedAt
1860
+ });
1861
+ }
1862
+ return [
1863
+ 2,
1864
+ response
1865
+ ];
1866
+ }
1867
+ });
1868
+ })();
1711
1869
  };
1712
1870
  _state.label = 1;
1713
1871
  case 1:
@@ -1764,7 +1922,7 @@ function createHlsAdPlayer(contentVideo, options) {
1764
1922
  ];
1765
1923
  case 8:
1766
1924
  if (!response.ok) {
1767
- throw new Error("Failed to fetch VAST: ".concat(response.statusText));
1925
+ throw new Error("Failed to fetch VAST: HTTP ".concat(response.status, " ").concat(response.statusText));
1768
1926
  }
1769
1927
  return [
1770
1928
  4,
@@ -1779,7 +1937,7 @@ function createHlsAdPlayer(contentVideo, options) {
1779
1937
  error1 = _state.sent();
1780
1938
  if (controller === null || controller === void 0 ? void 0 : controller.signal.aborted) {
1781
1939
  if (pendingRequestAbortReason) {
1782
- throw new Error("".concat(pendingRequestAbortReason, " (timeout): ").concat(vastTagUrl));
1940
+ throw new Error("".concat(pendingRequestAbortReason, ": ").concat(vastTagUrl));
1783
1941
  }
1784
1942
  throw new Error("VAST request timeout after ".concat(VAST_REQUEST_TIMEOUT_MS, "ms: ").concat(vastTagUrl));
1785
1943
  }
@@ -1823,7 +1981,7 @@ function createHlsAdPlayer(contentVideo, options) {
1823
1981
  ]);
1824
1982
  return [
1825
1983
  4,
1826
- fetchVastXml(vastTagUrl, depth === 0 ? "include" : "omit")
1984
+ fetchVastXml(vastTagUrl, depth === 0 ? "include" : "omit", depth === 0 ? "gam" : "wrapper")
1827
1985
  ];
1828
1986
  case 2:
1829
1987
  vastXml = _state.sent();
@@ -1908,10 +2066,11 @@ function createHlsAdPlayer(contentVideo, options) {
1908
2066
  }
1909
2067
  function fetchAndParsePod(vastTagUrl) {
1910
2068
  return _async_to_generator(function() {
1911
- var _root_getAttribute, vastXml, trimmedXml, xmlDoc, root, adElements, _root_getAttribute1, _empty_errorUrls, empty, _empty_errorCode, resolveAd, podElements, buffet, resolveAll, ads, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, ad, err, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, ad1, err;
2069
+ var _root_getAttribute, _root_getAttribute1, vastXml, trimmedXml, xmlDoc, root, adElements, _root_getAttribute2, _empty_errorUrls, empty, _empty_errorCode, resolveAd, podElements, buffet, resolveAll, ads, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, ad, err, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, ad1, err;
1912
2070
  return _ts_generator(this, function(_state) {
1913
2071
  switch(_state.label){
1914
2072
  case 0:
2073
+ lastPodAdElementCount = 0;
1915
2074
  return [
1916
2075
  4,
1917
2076
  fetchVastXml(vastTagUrl)
@@ -1926,6 +2085,10 @@ function createHlsAdPlayer(contentVideo, options) {
1926
2085
  trimmedXml = vastXml.trim();
1927
2086
  if (trimmedXml.length === 0) {
1928
2087
  console.warn("[HlsAdPlayer] Pod VAST response body is empty (no fill)");
2088
+ logFunnel("vast_parsed", {
2089
+ adElementCount: 0,
2090
+ reason: "empty_body"
2091
+ });
1929
2092
  return [
1930
2093
  2,
1931
2094
  []
@@ -1934,6 +2097,10 @@ function createHlsAdPlayer(contentVideo, options) {
1934
2097
  xmlDoc = parseXml(vastXml);
1935
2098
  if (!xmlDoc) {
1936
2099
  console.error("[HlsAdPlayer] Pod VAST XML content (first 2000 chars):", vastXml.substring(0, 2e3));
2100
+ logFunnel("vast_parsed", {
2101
+ adElementCount: 0,
2102
+ reason: "xml_parse_error"
2103
+ });
1937
2104
  return [
1938
2105
  2,
1939
2106
  []
@@ -1941,10 +2108,21 @@ function createHlsAdPlayer(contentVideo, options) {
1941
2108
  }
1942
2109
  root = xmlDoc.documentElement;
1943
2110
  adElements = Array.from(root.querySelectorAll(":scope > Ad"));
2111
+ logFunnel("vast_parsed", {
2112
+ reason: adElements.length > 0 ? "has_ads" : "no_ads",
2113
+ vastVersion: (_root_getAttribute = root.getAttribute("version")) !== null && _root_getAttribute !== void 0 ? _root_getAttribute : void 0,
2114
+ adElementCount: adElements.length,
2115
+ inlineCount: adElements.filter(function(el) {
2116
+ return el.querySelector(":scope > InLine");
2117
+ }).length,
2118
+ wrapperCount: adElements.filter(function(el) {
2119
+ return el.querySelector(":scope > Wrapper");
2120
+ }).length
2121
+ });
1944
2122
  if (adElements.length === 0) {
1945
2123
  ;
1946
2124
  ;
1947
- console.warn("[HlsAdPlayer] No <Ad> elements in VAST ".concat((_root_getAttribute1 = root.getAttribute("version")) !== null && _root_getAttribute1 !== void 0 ? _root_getAttribute1 : "", " pod response (no fill)"));
2125
+ console.warn("[HlsAdPlayer] No <Ad> elements in VAST ".concat((_root_getAttribute2 = root.getAttribute("version")) !== null && _root_getAttribute2 !== void 0 ? _root_getAttribute2 : "", " pod response (no fill)"));
1948
2126
  empty = emptyVastResult(root);
1949
2127
  if (empty.type === "empty" && ((_empty_errorUrls = empty.errorUrls) === null || _empty_errorUrls === void 0 ? void 0 : _empty_errorUrls.length)) {
1950
2128
  ;
@@ -1962,10 +2140,15 @@ function createHlsAdPlayer(contentVideo, options) {
1962
2140
  var _parsed_errorUrls, parsed, _parsed_errorCode;
1963
2141
  return _ts_generator(this, function(_state) {
1964
2142
  parsed = parseAdElement(adElement);
1965
- if (parsed.type === "inline") return [
1966
- 2,
1967
- parsed.ad
1968
- ];
2143
+ if (parsed.type === "inline") {
2144
+ logFunnel("inline_resolved", {
2145
+ depth: 0
2146
+ });
2147
+ return [
2148
+ 2,
2149
+ parsed.ad
2150
+ ];
2151
+ }
1969
2152
  if (parsed.type === "wrapper") {
1970
2153
  return [
1971
2154
  2,
@@ -2143,7 +2326,8 @@ function createHlsAdPlayer(contentVideo, options) {
2143
2326
  7
2144
2327
  ];
2145
2328
  case 21:
2146
- console.log("[HlsAdPlayer] Parsed ".concat(ads.length, " ad(s) from VAST ").concat((_root_getAttribute = root.getAttribute("version")) !== null && _root_getAttribute !== void 0 ? _root_getAttribute : "", " pod response"));
2329
+ console.log("[HlsAdPlayer] Parsed ".concat(ads.length, " ad(s) from VAST ").concat((_root_getAttribute1 = root.getAttribute("version")) !== null && _root_getAttribute1 !== void 0 ? _root_getAttribute1 : "", " pod response"));
2330
+ lastPodAdElementCount = adElements.length;
2147
2331
  return [
2148
2332
  2,
2149
2333
  ads
@@ -3213,6 +3397,17 @@ function createHlsAdPlayer(contentVideo, options) {
3213
3397
  if (!ads.length && pendingRequestAbortReason) {
3214
3398
  throw new Error(pendingRequestAbortReason);
3215
3399
  }
3400
+ if (!ads.length && lastPodAdElementCount > 0) {
3401
+ console.warn("[HlsAdPlayer] VAST response had ads but none were playable");
3402
+ logFunnel("vast_fill_rejected", {
3403
+ adElementCount: lastPodAdElementCount
3404
+ });
3405
+ emit("ad_error");
3406
+ return [
3407
+ 2,
3408
+ Promise.reject(new Error("VAST fill rejected: no playable ad in response"))
3409
+ ];
3410
+ }
3216
3411
  if (!ads.length) {
3217
3412
  console.warn("[HlsAdPlayer] No ads available from VAST response");
3218
3413
  logFunnel("no_fill");
@@ -5652,6 +5847,21 @@ function normalizeVastTagUrl(raw) {
5652
5847
  return raw;
5653
5848
  }
5654
5849
  }
5850
+ var GAM_AD_HOSTS = /* @__PURE__ */ new Set([
5851
+ "pubads.g.doubleclick.net",
5852
+ "securepubads.g.doubleclick.net"
5853
+ ]);
5854
+ function ensureVideoAdType(rawUrl) {
5855
+ try {
5856
+ var url = new URL(rawUrl);
5857
+ if (!GAM_AD_HOSTS.has(url.hostname)) return rawUrl;
5858
+ if (url.searchParams.has("ad_type")) return rawUrl;
5859
+ url.searchParams.set("ad_type", "video");
5860
+ return url.toString();
5861
+ } catch (unused) {
5862
+ return rawUrl;
5863
+ }
5864
+ }
5655
5865
  function applyVastMacros(baseUrl, ctx) {
5656
5866
  var expandedUrl = expandInlineMacroPlaceholders(baseUrl, ctx);
5657
5867
  var url;
@@ -7362,7 +7572,7 @@ var AdConfigManager = /*#__PURE__*/ function() {
7362
7572
  } : {}), {
7363
7573
  consent: this.consentSignals
7364
7574
  }));
7365
- var finalUrl = palNonce.injectNonce(urlWithMacros);
7575
+ var finalUrl = palNonce.injectNonce(ensureVideoAdType(urlWithMacros));
7366
7576
  console.log("[StormcloudVideoPlayer] Resolved optimized-pod request URL (pod=".concat(this.podCounter, ", pmad=").concat(podParams.maxAds, ", pmnd=").concat(podParams.minDurationMs, ", pmxd=").concat((_podParams_maxDurationMs = podParams.maxDurationMs) !== null && _podParams_maxDurationMs !== void 0 ? _podParams_maxDurationMs : "?", "):"), finalUrl);
7367
7577
  return finalUrl;
7368
7578
  }
@@ -8851,6 +9061,18 @@ function resizePlayer(video, adPlayer, debug) {
8851
9061
  }
8852
9062
  }
8853
9063
  // src/player/AdBreakOrchestrator.ts
9064
+ var REQUEST_FAILURE_STAGES = /* @__PURE__ */ new Set([
9065
+ "no_fill",
9066
+ "vast_fill_rejected",
9067
+ "request_failed",
9068
+ "media_unsupported",
9069
+ "play_failed",
9070
+ "play_resolved_but_never_started",
9071
+ "hls_fatal",
9072
+ "media_error",
9073
+ "stall",
9074
+ "decode_failure"
9075
+ ]);
8854
9076
  var AdBreakOrchestrator = /*#__PURE__*/ function() {
8855
9077
  function AdBreakOrchestrator(host, timing, adConfig, cueManager, placeholder) {
8856
9078
  _class_call_check(this, AdBreakOrchestrator);
@@ -8858,15 +9080,17 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8858
9080
  this.showAds = false;
8859
9081
  this.isShowingPlaceholder = false;
8860
9082
  this.adDetectSentForCurrentBreak = false;
8861
- this.continuousFetchingActive = false;
8862
- this.continuousFetchLoopRunning = false;
9083
+ this.slotState = "IDLE";
9084
+ this.unusableResponsesInBreak = 0;
9085
+ this.controllerGeneration = 0;
9086
+ this.requestDiagnostics = /* @__PURE__ */ new Map();
8863
9087
  this.breakFunnel = {};
8864
9088
  this.controllerCallInFlight = false;
8865
9089
  this.playbackStartedForCurrentRequest = false;
8866
9090
  this.opportunityEpoch = -1;
8867
- this.adRequestQueue = [];
8868
9091
  this.adPodQueue = [];
8869
- this.maxPlaceholderDurationMs = 5e3;
9092
+ this.defaultMinRemainingMsToRequestAd = 1e4;
9093
+ this.defaultMaxNoFillsPerBreak = 2;
8870
9094
  this.pendingAdBreak = null;
8871
9095
  this.host = host;
8872
9096
  this.timing = timing;
@@ -8902,7 +9126,23 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8902
9126
  key: "attachImaEventListeners",
8903
9127
  value: function attachImaEventListeners() {
8904
9128
  var _this = this;
8905
- var adPlayer = this.host.getAdPlayer();
9129
+ var controller = this.host.getAdPlayer();
9130
+ var generation = this.controllerGeneration;
9131
+ var adPlayer = {
9132
+ on: function on(event, handler) {
9133
+ controller.on(event, function(payload) {
9134
+ if (generation !== _this.controllerGeneration) {
9135
+ _this.logOrchestratorFunnel("stale_callback_ignored", {
9136
+ event: event,
9137
+ staleControllerId: generation,
9138
+ currentControllerId: _this.controllerGeneration
9139
+ });
9140
+ return;
9141
+ }
9142
+ handler(payload);
9143
+ });
9144
+ }
9145
+ };
8906
9146
  adPlayer.on("pod_ad_started", function(payload) {
8907
9147
  _this.timing.notePodAdStarted();
8908
9148
  if (_this.debug) {
@@ -8918,19 +9158,29 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8918
9158
  });
8919
9159
  adPlayer.on("ad_funnel", function(payload) {
8920
9160
  if (!(payload === null || payload === void 0 ? void 0 : payload.stage)) return;
8921
- _this.countFunnelStage(payload.stage);
9161
+ var stage = payload.stage;
9162
+ _this.countFunnelStage(stage);
8922
9163
  if (payload.reason) {
8923
- _this.countFunnelStage("".concat(payload.stage, ":").concat(payload.reason));
9164
+ _this.countFunnelStage("".concat(stage, ":").concat(payload.reason));
8924
9165
  }
8925
- if (payload.stage === "impression_fired" && payload.pixelCount != null) {
9166
+ if (stage === "impression_fired" && payload.pixelCount != null) {
8926
9167
  _this.countFunnelStage("impression_urls", payload.pixelCount);
8927
9168
  }
8928
9169
  if (payload.visibilityState === "hidden") {
8929
9170
  _this.countFunnelStage("while_hidden");
8930
9171
  }
9172
+ if (stage === "gam_http_request_sent") {
9173
+ if (payload.attempt === 1) {
9174
+ _this.timing.noteAdRequestSent();
9175
+ } else {
9176
+ _this.countFunnelStage("gam_http_request_retry");
9177
+ }
9178
+ }
9179
+ _this.recordRequestDiagnostic(payload);
8931
9180
  });
8932
9181
  adPlayer.on("ad_impression", function() {
8933
9182
  _this.timing.consecutiveFailures = 0;
9183
+ _this.setSlotState("PLAYING", "impression");
8934
9184
  if (!_this.playbackStartedForCurrentRequest) {
8935
9185
  _this.playbackStartedForCurrentRequest = true;
8936
9186
  _this.timing.markAdStarted();
@@ -8949,16 +9199,11 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8949
9199
  var remaining = _this.timing.getRemainingAdMs();
8950
9200
  _this.timing.consecutiveFailures = 0;
8951
9201
  if (_this.debug) {
8952
- console.log("[StormcloudVideoPlayer] all_ads_completed event received - remaining=".concat(remaining, "ms, queued ads=").concat(_this.adRequestQueue.length), _this.adRequestQueue.length > 0 ? {
8953
- queuedUrls: _to_consumable_array(_this.adRequestQueue)
8954
- } : {});
9202
+ console.log("[StormcloudVideoPlayer] all_ads_completed event received - remaining=".concat(remaining, "ms"));
8955
9203
  }
8956
9204
  if (_this.inAdBreak) {
8957
- if (_this.timing.hasTimeToStartAnotherAd()) {
8958
- _this.tryNextAvailableAdWithRateLimit();
8959
- } else {
8960
- _this.handleAdPodComplete();
8961
- }
9205
+ _this.setSlotState("NEEDS_NEXT_AD", "all_ads_completed");
9206
+ _this.requestNextAd("all_ads_completed");
8962
9207
  }
8963
9208
  });
8964
9209
  adPlayer.on("ad_error", function(errorPayload) {
@@ -8979,10 +9224,9 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8979
9224
  }
8980
9225
  console.error("[AD-ERROR]", errorMessage, errorPayload || "");
8981
9226
  if (_this.controllerCallInFlight) {
8982
- _this.timing.recordGamNoFill();
8983
9227
  return;
8984
9228
  }
8985
- _this.handleAdFailure();
9229
+ _this.handleAdFailure("ad_error");
8986
9230
  });
8987
9231
  adPlayer.on("content_pause", function() {
8988
9232
  _this.timing.clearAdFailsafeTimer();
@@ -9021,26 +9265,32 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9021
9265
  }
9022
9266
  _this.timing.consecutiveFailures = 0;
9023
9267
  _this.timing.recordPlayedAdDuration(_this.host.getAdPlayer());
9024
- var remaining = _this.timing.getRemainingAdMs();
9025
9268
  if (_this.debug) {
9026
- console.log("[CONTINUOUS-FETCH] content_resume event: remaining=".concat(remaining, "ms, queued ads=").concat(_this.adRequestQueue.length), _this.adRequestQueue.length > 0 ? {
9027
- queuedUrls: _to_consumable_array(_this.adRequestQueue)
9028
- } : {});
9029
- }
9030
- if (_this.timing.hasTimeToStartAnotherAd()) {
9031
- _this.tryNextAvailableAdWithRateLimit();
9032
- } else {
9033
- _this.handleAdPodComplete();
9269
+ console.log("[AdBreak] content_resume: remaining=".concat(_this.timing.getRemainingAdMs(), "ms"));
9034
9270
  }
9271
+ _this.setSlotState("NEEDS_NEXT_AD", "ad_complete");
9272
+ _this.requestNextAd("ad_complete");
9035
9273
  });
9036
9274
  }
9037
9275
  },
9038
9276
  {
9039
9277
  key: "recreateAdController",
9040
- value: function recreateAdController() {
9041
- if (this.debug) {
9042
- console.log("[StormcloudVideoPlayer] Recreating AdController for new ad");
9278
+ value: function recreateAdController(reason) {
9279
+ if (reason === "new_request" && (this.slotState === "REQUESTING" || this.slotState === "READY")) {
9280
+ console.warn("[AD-CONTROLLER] destroy during active request", {
9281
+ controllerId: this.controllerGeneration,
9282
+ requestId: this.currentRequestId,
9283
+ state: this.slotState,
9284
+ reason: reason
9285
+ });
9043
9286
  }
9287
+ console.log("[AD-CONTROLLER] destroy", {
9288
+ controllerId: this.controllerGeneration,
9289
+ requestId: this.currentRequestId,
9290
+ state: this.slotState,
9291
+ reason: reason
9292
+ });
9293
+ this.countFunnelStage("controller_destroy:".concat(reason));
9044
9294
  var shouldShowPlaceholder = this.inAdBreak && this.showAds;
9045
9295
  var adPlayer = this.host.getAdPlayer();
9046
9296
  if (shouldShowPlaceholder && adPlayer) {
@@ -9067,9 +9317,16 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9067
9317
  var continueLiveStreamDuringAds = this.host.shouldContinueLiveStreamDuringAds();
9068
9318
  var newAdPlayer = this.host.createAdPlayer(continueLiveStreamDuringAds);
9069
9319
  this.host.setAdPlayer(newAdPlayer);
9320
+ this.controllerGeneration++;
9070
9321
  newAdPlayer.initialize();
9071
9322
  newAdPlayer.updateOriginalMutedState(preservedMutedState, preservedVolumeState);
9072
9323
  this.attachImaEventListeners();
9324
+ if (this.debug) {
9325
+ console.log("[AD-CONTROLLER] create", {
9326
+ controllerId: this.controllerGeneration,
9327
+ reason: reason
9328
+ });
9329
+ }
9073
9330
  if (shouldShowPlaceholder) {
9074
9331
  this.placeholder.show();
9075
9332
  newAdPlayer.showPlaceholder();
@@ -9090,32 +9347,57 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9090
9347
  }
9091
9348
  },
9092
9349
  {
9093
- key: "handleAdStart",
9094
- value: // ───────────────────────────────────────────────────────────────
9350
+ // ───────────────────────────────────────────────────────────────
9095
9351
  // Ad break start
9096
9352
  // ───────────────────────────────────────────────────────────────
9097
- function handleAdStart(_marker) {
9353
+ key: "isBreakActive",
9354
+ value: function isBreakActive() {
9355
+ return this.slotState !== "IDLE";
9356
+ }
9357
+ },
9358
+ {
9359
+ key: "getSlotState",
9360
+ value: function getSlotState() {
9361
+ return this.slotState;
9362
+ }
9363
+ },
9364
+ {
9365
+ key: "beginVmapBreak",
9366
+ value: function beginVmapBreak(breakKey) {
9367
+ this.breakSource = "vmap";
9368
+ this.followUpBaseVastUrl = void 0;
9369
+ this.unusableResponsesInBreak = 0;
9370
+ this.timing.totalAdRequestsInBreak = 0;
9371
+ this.setSlotState("NEEDS_NEXT_AD", "vmap_break_start");
9372
+ this.noteOpportunity("vmap", breakKey);
9373
+ }
9374
+ },
9375
+ {
9376
+ key: "handleAdStart",
9377
+ value: function handleAdStart(marker) {
9098
9378
  return _async_to_generator(function() {
9099
- var scheduled, tags, baseVastUrl, adBreakDurationMs, mode, currentMuted, currentVolume, podPlayed;
9379
+ var baseVastUrl, adBreakDurationMs, mode, currentMuted, currentVolume, epoch, podPlayed;
9100
9380
  return _ts_generator(this, function(_state) {
9101
9381
  switch(_state.label){
9102
9382
  case 0:
9103
- scheduled = this.adConfig.findCurrentOrNextBreak(this.host.video.currentTime * 1e3);
9104
- if (scheduled) {
9105
- this.adConfig.consumedVmapBreakIds.add(this.adConfig.getAdBreakKey(scheduled));
9383
+ if (this.slotState !== "IDLE") {
9384
+ this.logOrchestratorFunnel("duplicate_break_start", {
9385
+ source: "scte35",
9386
+ state: this.slotState
9387
+ });
9388
+ return [
9389
+ 2
9390
+ ];
9106
9391
  }
9107
- tags = this.adConfig.selectVastTagsForBreak(scheduled);
9108
- if (tags && tags.length > 0 && tags[0]) {
9109
- baseVastUrl = tags[0];
9110
- } else if (this.adConfig.apiVastTagUrl) {
9111
- baseVastUrl = this.adConfig.apiVastTagUrl;
9112
- } else {
9392
+ baseVastUrl = this.adConfig.apiVastTagUrl;
9393
+ if (!baseVastUrl) {
9394
+ console.warn("[AdBreak] SCTE-35 break started but no direct VAST tag is configured");
9113
9395
  this.clearPendingAdBreak();
9114
9396
  return [
9115
9397
  2
9116
9398
  ];
9117
9399
  }
9118
- adBreakDurationMs = _marker.durationSeconds != null ? _marker.durationSeconds * 1e3 : scheduled === null || scheduled === void 0 ? void 0 : scheduled.durationMs;
9400
+ adBreakDurationMs = marker.durationSeconds != null ? marker.durationSeconds * 1e3 : this.timing.expectedAdBreakDurationMs;
9119
9401
  if (this.debug) {
9120
9402
  mode = this.host.config.isLiveStream ? "LIVE" : "VOD";
9121
9403
  console.log("[CONTINUOUS-FETCH] ".concat(mode, " MODE: Target duration=").concat(adBreakDurationMs, "ms"));
@@ -9123,9 +9405,12 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9123
9405
  this.timing.failedVastUrls.clear();
9124
9406
  this.timing.temporaryFailureUrls.clear();
9125
9407
  this.timing.consecutiveFailures = 0;
9126
- this.continuousFetchingActive = true;
9127
9408
  this.isShowingPlaceholder = false;
9128
9409
  this.timing.totalAdRequestsInBreak = 0;
9410
+ this.breakSource = "scte35";
9411
+ this.followUpBaseVastUrl = baseVastUrl;
9412
+ this.unusableResponsesInBreak = 0;
9413
+ this.setSlotState("NEEDS_NEXT_AD", "scte35_break_start");
9129
9414
  if (this.adConfig.podAssignedByPrefetch) {
9130
9415
  this.adConfig.podAssignedByPrefetch = false;
9131
9416
  } else {
@@ -9144,29 +9429,17 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9144
9429
  this.timing.expectedAdBreakDurationMs = adBreakDurationMs;
9145
9430
  }
9146
9431
  this.noteOpportunity("scte35", this.cueManager.activeScte35BreakKey);
9432
+ epoch = this.timing.adBreakEpoch;
9147
9433
  return [
9148
9434
  4,
9149
9435
  this.startOptimizedPod(baseVastUrl, adBreakDurationMs)
9150
9436
  ];
9151
9437
  case 1:
9152
9438
  podPlayed = _state.sent();
9153
- if (!!podPlayed) return [
9154
- 3,
9155
- 3
9156
- ];
9157
- if (this.debug) {
9158
- console.log("[POD] Initial pod request did not fill; attempting top-up pod request");
9439
+ if (!podPlayed && this.inAdBreak && epoch === this.timing.adBreakEpoch) {
9440
+ this.setSlotState("NEEDS_NEXT_AD", "initial_request_failed");
9441
+ this.requestNextAd("initial_request_failed");
9159
9442
  }
9160
- this.continuousFetchingActive = true;
9161
- this.startContinuousFetching(baseVastUrl);
9162
- return [
9163
- 4,
9164
- this.tryNextAvailableAdWithRateLimit()
9165
- ];
9166
- case 2:
9167
- _state.sent();
9168
- _state.label = 3;
9169
- case 3:
9170
9443
  return [
9171
9444
  2
9172
9445
  ];
@@ -9182,10 +9455,11 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9182
9455
  // ───────────────────────────────────────────────────────────────
9183
9456
  function startOptimizedPod(baseVastUrl, breakDurationMs) {
9184
9457
  return _async_to_generator(function() {
9185
- var podUrl, adPlayer, requestToken, _ref, _adPlayer_getPodAdCount, podCount, error;
9458
+ var podUrl, prefetched, epoch, generation, adPlayer, requestToken, _ref, _adPlayer_getPodAdCount, podCount, error;
9186
9459
  return _ts_generator(this, function(_state) {
9187
9460
  switch(_state.label){
9188
9461
  case 0:
9462
+ prefetched = !!(this.pendingAdBreak && this.pendingAdBreak.vastUrls.length > 0);
9189
9463
  if (this.pendingAdBreak && this.pendingAdBreak.vastUrls.length > 0) {
9190
9464
  podUrl = this.pendingAdBreak.vastUrls[0];
9191
9465
  this.clearPendingAdBreak();
@@ -9198,12 +9472,16 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9198
9472
  false
9199
9473
  ];
9200
9474
  }
9201
- this.continuousFetchingActive = false;
9202
- this.recreateAdController();
9475
+ this.noteVastUrlGenerated(podUrl, prefetched ? "prefetch" : "break_start");
9476
+ epoch = this.timing.adBreakEpoch;
9477
+ this.recreateAdController("new_request");
9478
+ generation = this.controllerGeneration;
9203
9479
  adPlayer = this.host.getAdPlayer();
9204
9480
  requestToken = ++this.timing.adRequestTokenCounter;
9205
9481
  this.timing.activeAdRequestToken = requestToken;
9206
9482
  this.currentVastUrl = podUrl;
9483
+ this.setSlotState("REQUESTING", "initial_pod");
9484
+ this.beginFunnelRequest(adPlayer, requestToken, "initial_pod");
9207
9485
  _state.label = 1;
9208
9486
  case 1:
9209
9487
  _state.trys.push([
@@ -9218,9 +9496,11 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9218
9496
  ];
9219
9497
  case 2:
9220
9498
  _state.sent();
9499
+ if (this.isStale(epoch, generation)) return [
9500
+ 2,
9501
+ true
9502
+ ];
9221
9503
  this.timing.startAdRequestWatchdog(requestToken);
9222
- this.timing.noteAdRequestSent();
9223
- this.beginFunnelRequest(adPlayer, requestToken);
9224
9504
  return [
9225
9505
  4,
9226
9506
  this.callController(function() {
@@ -9230,7 +9510,10 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9230
9510
  case 3:
9231
9511
  _state.sent();
9232
9512
  this.timing.clearAdRequestWatchdog();
9233
- if (this.timing.activeAdRequestToken !== requestToken) {
9513
+ if (this.isStale(epoch, generation)) {
9514
+ this.logOrchestratorFunnel("stale_request_result_ignored", {
9515
+ requestId: requestToken
9516
+ });
9234
9517
  return [
9235
9518
  2,
9236
9519
  true
@@ -9238,11 +9521,16 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9238
9521
  }
9239
9522
  podCount = (_ref = (_adPlayer_getPodAdCount = adPlayer.getPodAdCount) === null || _adPlayer_getPodAdCount === void 0 ? void 0 : _adPlayer_getPodAdCount.call(adPlayer)) !== null && _ref !== void 0 ? _ref : 1;
9240
9523
  if (podCount < 1) {
9524
+ if (this.timing.activeAdRequestToken === requestToken) {
9525
+ this.timing.activeAdRequestToken = null;
9526
+ }
9527
+ this.recordRequestFailure(new Error("No ads available"), podUrl);
9241
9528
  return [
9242
9529
  2,
9243
9530
  false
9244
9531
  ];
9245
9532
  }
9533
+ this.setSlotState("READY", "vast_ready");
9246
9534
  if (this.debug) {
9247
9535
  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"));
9248
9536
  }
@@ -9260,12 +9548,14 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9260
9548
  ];
9261
9549
  case 4:
9262
9550
  _state.sent();
9551
+ if (this.isStale(epoch, generation)) return [
9552
+ 2,
9553
+ true
9554
+ ];
9263
9555
  if (this.timing.expectedAdBreakDurationMs != null && this.timing.getAdBreakEndWallClockMs() == null) {
9264
9556
  this.timing.scheduleAdStopAtBreakBoundary();
9265
9557
  }
9266
9558
  adPlayer.setAdVolume(getAdAudioVolume(adPlayer));
9267
- this.continuousFetchingActive = true;
9268
- this.startContinuousFetching(baseVastUrl);
9269
9559
  return [
9270
9560
  2,
9271
9561
  true
@@ -9277,14 +9567,20 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9277
9567
  if (this.timing.activeAdRequestToken === requestToken) {
9278
9568
  this.timing.activeAdRequestToken = null;
9279
9569
  }
9570
+ if (this.isStale(epoch, generation)) {
9571
+ this.logOrchestratorFunnel("stale_request_result_ignored", {
9572
+ requestId: requestToken,
9573
+ errorMessage: error === null || error === void 0 ? void 0 : error.message
9574
+ });
9575
+ return [
9576
+ 2,
9577
+ true
9578
+ ];
9579
+ }
9280
9580
  if (this.debug) {
9281
9581
  console.warn("[POD] Optimized pod request/play failed:", error);
9282
9582
  }
9283
- if (this.timing.isTemporaryAdError(error)) {
9284
- this.timing.temporaryFailureUrls.set(podUrl, Date.now());
9285
- }
9286
- this.continuousFetchingActive = true;
9287
- this.recreateAdController();
9583
+ this.recordRequestFailure(error, podUrl);
9288
9584
  return [
9289
9585
  2,
9290
9586
  false
@@ -9300,168 +9596,204 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9300
9596
  },
9301
9597
  {
9302
9598
  // ───────────────────────────────────────────────────────────────
9303
- // Continuous fetching
9599
+ // Next-ad scheduling (single flight)
9304
9600
  // ───────────────────────────────────────────────────────────────
9305
- key: "startContinuousFetching",
9306
- value: function startContinuousFetching(baseVastUrl) {
9307
- if (!this.continuousFetchingActive) {
9601
+ key: "setSlotState",
9602
+ value: function setSlotState(next, reason) {
9603
+ if (this.slotState === next) return;
9604
+ var previous = this.slotState;
9605
+ this.slotState = next;
9606
+ if (this.debug) {
9607
+ console.log("[AdBreak][STATE] ".concat(previous, " -> ").concat(next), {
9608
+ reason: reason,
9609
+ breakId: this.timing.adBreakEpoch,
9610
+ requestId: this.currentRequestId,
9611
+ controllerId: this.controllerGeneration
9612
+ });
9613
+ }
9614
+ }
9615
+ },
9616
+ {
9617
+ key: "isStale",
9618
+ value: function isStale(epoch, generation) {
9619
+ return !this.inAdBreak || epoch !== this.timing.adBreakEpoch || generation !== this.controllerGeneration;
9620
+ }
9621
+ },
9622
+ {
9623
+ key: "getMinRemainingMsToRequestAd",
9624
+ value: function getMinRemainingMsToRequestAd() {
9625
+ var configured = this.host.config.minRemainingMsToRequestAd;
9626
+ var floor = this.timing.getMinRemainingMsToStartAd();
9627
+ if (typeof configured === "number" && configured >= 0) {
9628
+ return Math.max(configured, floor);
9629
+ }
9630
+ return Math.max(this.defaultMinRemainingMsToRequestAd, floor);
9631
+ }
9632
+ },
9633
+ {
9634
+ key: "getMaxNoFillsPerBreak",
9635
+ value: function getMaxNoFillsPerBreak() {
9636
+ var configured = this.host.config.maxNoFillsPerBreak;
9637
+ return typeof configured === "number" && configured > 0 ? configured : this.defaultMaxNoFillsPerBreak;
9638
+ }
9639
+ },
9640
+ {
9641
+ key: "isBreakTimeBounded",
9642
+ value: function isBreakTimeBounded() {
9643
+ return this.breakSource === "scte35" || this.timing.expectedAdBreakDurationMs != null;
9644
+ }
9645
+ },
9646
+ {
9647
+ key: "getStopRequestingReason",
9648
+ value: function getStopRequestingReason(remainingMs) {
9649
+ if (this.breakSource === "vmap") {
9650
+ if (this.adPodQueue.length === 0) return "vmap_queue_empty";
9651
+ } else if (this.breakSource !== "scte35" || !this.followUpBaseVastUrl) {
9652
+ return "no_follow_up_source";
9653
+ }
9654
+ if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
9655
+ return "max_consecutive_failures";
9656
+ }
9657
+ if (this.unusableResponsesInBreak >= this.getMaxNoFillsPerBreak()) {
9658
+ return "unusable_response_limit";
9659
+ }
9660
+ if (this.timing.totalAdRequestsInBreak >= this.timing.maxTotalAdRequestsPerBreak) {
9661
+ return "request_cap";
9662
+ }
9663
+ if (this.timing.isGamInCooldown()) {
9664
+ return "gam_cooldown";
9665
+ }
9666
+ if (this.isBreakTimeBounded() && remainingMs < this.getMinRemainingMsToRequestAd()) {
9667
+ return "insufficient_break_time";
9668
+ }
9669
+ return void 0;
9670
+ }
9671
+ },
9672
+ {
9673
+ key: "getNextRequestDelayMs",
9674
+ value: function getNextRequestDelayMs() {
9675
+ var failures = this.timing.consecutiveFailures;
9676
+ var backoff = failures > 0 ? Math.min(this.timing.backoffBaseMs * Math.pow(2, failures), this.timing.maxBackoffMs) : 0;
9677
+ var minInterval = this.timing.minAdRequestIntervalMs + backoff;
9678
+ var sinceLast = Date.now() - this.timing.lastAdRequestTime;
9679
+ return Math.max(0, minInterval - sinceLast);
9680
+ }
9681
+ },
9682
+ {
9683
+ key: "requestNextAd",
9684
+ value: function requestNextAd(trigger) {
9685
+ var _this = this;
9686
+ if (!this.inAdBreak) return;
9687
+ if (this.slotState !== "NEEDS_NEXT_AD") {
9688
+ this.logOrchestratorFunnel("request_suppressed", {
9689
+ trigger: trigger,
9690
+ state: this.slotState,
9691
+ why: "slot_busy"
9692
+ });
9308
9693
  return;
9309
9694
  }
9310
- if (this.continuousFetchLoopRunning) {
9311
- if (this.debug) {
9312
- console.log("[CONTINUOUS-FETCH] Fetch loop already running, skipping duplicate start");
9313
- }
9695
+ if (this.nextAdTimerId != null) {
9696
+ this.logOrchestratorFunnel("request_suppressed", {
9697
+ trigger: trigger,
9698
+ state: this.slotState,
9699
+ why: "request_already_scheduled"
9700
+ });
9314
9701
  return;
9315
9702
  }
9316
- if (this.debug) {
9317
- console.log("[CONTINUOUS-FETCH] Starting continuous ad fetching loop");
9703
+ var remainingMs = this.timing.getRemainingAdMs();
9704
+ var stopReason = this.getStopRequestingReason(remainingMs);
9705
+ if (stopReason) {
9706
+ this.logOrchestratorFunnel("next_ad_decision", {
9707
+ trigger: trigger,
9708
+ decision: "end_break",
9709
+ reason: stopReason,
9710
+ remainingMs: remainingMs,
9711
+ requestsSent: this.timing.totalAdRequestsInBreak,
9712
+ unusableResponses: this.unusableResponsesInBreak,
9713
+ consecutiveFailures: this.timing.consecutiveFailures
9714
+ });
9715
+ this.handleAdPodComplete(stopReason);
9716
+ return;
9717
+ }
9718
+ var waitMs = this.getNextRequestDelayMs();
9719
+ if (waitMs > 0 && this.isBreakTimeBounded() && remainingMs - waitMs < this.getMinRemainingMsToRequestAd()) {
9720
+ this.logOrchestratorFunnel("next_ad_decision", {
9721
+ trigger: trigger,
9722
+ decision: "end_break",
9723
+ reason: "insufficient_break_time_after_backoff",
9724
+ remainingMs: remainingMs,
9725
+ waitMs: waitMs
9726
+ });
9727
+ this.handleAdPodComplete("insufficient_break_time_after_backoff");
9728
+ return;
9729
+ }
9730
+ this.logOrchestratorFunnel("next_ad_decision", {
9731
+ trigger: trigger,
9732
+ decision: waitMs > 0 ? "request_after_delay" : "request_now",
9733
+ waitMs: waitMs,
9734
+ remainingMs: remainingMs,
9735
+ consecutiveFailures: this.timing.consecutiveFailures
9736
+ });
9737
+ if (waitMs > 0) {
9738
+ if (!this.isShowingPlaceholder) {
9739
+ this.isShowingPlaceholder = true;
9740
+ this.host.getAdPlayer().showPlaceholder();
9741
+ }
9742
+ var epoch = this.timing.adBreakEpoch;
9743
+ this.nextAdTimerId = window.setTimeout(function() {
9744
+ _this.nextAdTimerId = void 0;
9745
+ if (!_this.inAdBreak || epoch !== _this.timing.adBreakEpoch) return;
9746
+ _this.requestNextAd("".concat(trigger, ":after_delay"));
9747
+ }, waitMs);
9748
+ return;
9318
9749
  }
9319
- this.continuousFetchLoopRunning = true;
9320
- this.continuousFetchLoop(baseVastUrl);
9750
+ void this.requestFollowUpAd(trigger);
9321
9751
  }
9322
9752
  },
9323
9753
  {
9324
- key: "continuousFetchLoop",
9325
- value: function continuousFetchLoop(baseVastUrl) {
9754
+ key: "requestFollowUpAd",
9755
+ value: function requestFollowUpAd(trigger) {
9326
9756
  return _async_to_generator(function() {
9327
- var _this, _loop, epoch, _ret;
9757
+ var url, epoch, unused;
9328
9758
  return _ts_generator(this, function(_state) {
9329
9759
  switch(_state.label){
9330
9760
  case 0:
9331
- _loop = function() {
9332
- var remaining, maxQueueSize, newAdUrl, queuedUrlsPreview, generationDelay;
9333
- return _ts_generator(this, function(_state) {
9334
- switch(_state.label){
9335
- case 0:
9336
- remaining = Math.min(_this.timing.getWallClockRemainingAdMs(), _this.timing.getDurationBudgetRemainingMs());
9337
- if (remaining <= _this.timing.getMinRemainingMsToStartAd()) {
9338
- if (_this.debug) {
9339
- console.log("[CONTINUOUS-FETCH] Not enough ad break time left (wall=".concat(_this.timing.getWallClockRemainingAdMs(), "ms, budget=").concat(_this.timing.getDurationBudgetRemainingMs(), "ms), stopping URL generation"));
9340
- }
9341
- return [
9342
- 2,
9343
- "break"
9344
- ];
9345
- }
9346
- if (_this.timing.isGamInCooldown()) {
9347
- if (_this.debug) {
9348
- console.log("[CIRCUIT-BREAKER] GAM in cooldown, stopping URL generation");
9349
- }
9350
- return [
9351
- 2,
9352
- "break"
9353
- ];
9354
- }
9355
- if (_this.timing.consecutiveFailures >= _this.timing.maxConsecutiveFailures) {
9356
- if (_this.debug) {
9357
- console.log("[CONTINUOUS-FETCH] Too many consecutive failures (".concat(_this.timing.consecutiveFailures, "), stopping URL generation"));
9358
- }
9359
- return [
9360
- 2,
9361
- "break"
9362
- ];
9363
- }
9364
- if (_this.timing.totalAdRequestsInBreak >= _this.timing.maxTotalAdRequestsPerBreak) {
9365
- if (_this.debug) {
9366
- console.log("[CONTINUOUS-FETCH] Maximum ad requests reached (".concat(_this.timing.maxTotalAdRequestsPerBreak, "), stopping"));
9367
- }
9368
- return [
9369
- 2,
9370
- "break"
9371
- ];
9372
- }
9373
- maxQueueSize = 5;
9374
- if (!(_this.adRequestQueue.length >= maxQueueSize)) return [
9375
- 3,
9376
- 2
9377
- ];
9378
- if (_this.debug) {
9379
- console.log("[CONTINUOUS-FETCH] URL queue full (".concat(_this.adRequestQueue.length, "), waiting..."));
9380
- }
9381
- return [
9382
- 4,
9383
- new Promise(function(resolve) {
9384
- return setTimeout(resolve, 1e3);
9385
- })
9386
- ];
9387
- case 1:
9388
- _state.sent();
9389
- return [
9390
- 2,
9391
- "continue"
9392
- ];
9393
- case 2:
9394
- newAdUrl = _this.nextAdRequestUrl(baseVastUrl);
9395
- if (!(!newAdUrl || _this.timing.failedVastUrls.has(newAdUrl) || _this.timing.isUrlInCooldown(newAdUrl))) return [
9396
- 3,
9397
- 4
9398
- ];
9399
- return [
9400
- 4,
9401
- new Promise(function(resolve) {
9402
- return setTimeout(resolve, 500);
9403
- })
9404
- ];
9405
- case 3:
9406
- _state.sent();
9407
- return [
9408
- 2,
9409
- "continue"
9410
- ];
9411
- case 4:
9412
- if (_this.debug) {
9413
- queuedUrlsPreview = _to_consumable_array(_this.adRequestQueue).concat([
9414
- newAdUrl
9415
- ]);
9416
- console.log("[CONTINUOUS-FETCH] Queued VAST URL (queue size: ".concat(queuedUrlsPreview.length, ")"), {
9417
- queuedUrls: queuedUrlsPreview
9418
- });
9419
- }
9420
- _this.adRequestQueue.push(newAdUrl);
9421
- generationDelay = _this.timing.consecutiveFailures > 0 ? Math.min(1e3 * Math.pow(2, _this.timing.consecutiveFailures), 5e3) : 500;
9422
- return [
9423
- 4,
9424
- new Promise(function(resolve) {
9425
- return setTimeout(resolve, generationDelay);
9426
- })
9427
- ];
9428
- case 5:
9429
- _state.sent();
9430
- return [
9431
- 2
9432
- ];
9433
- }
9434
- });
9435
- };
9761
+ if (this.breakSource === "vmap") {
9762
+ url = this.adPodQueue.shift();
9763
+ } else if (this.followUpBaseVastUrl) {
9764
+ url = this.nextAdRequestUrl(this.followUpBaseVastUrl);
9765
+ }
9766
+ if (!url) return [
9767
+ 2
9768
+ ];
9769
+ this.noteVastUrlGenerated(ensureVideoAdType(url), trigger);
9436
9770
  epoch = this.timing.adBreakEpoch;
9437
9771
  _state.label = 1;
9438
9772
  case 1:
9439
- if (!(this.continuousFetchingActive && this.inAdBreak && epoch === this.timing.adBreakEpoch)) return [
9440
- 3,
9441
- 3
9442
- ];
9443
- _this = this;
9773
+ _state.trys.push([
9774
+ 1,
9775
+ 3,
9776
+ ,
9777
+ 4
9778
+ ]);
9444
9779
  return [
9445
- 5,
9446
- _ts_values(_loop())
9780
+ 4,
9781
+ this.playSingleAd(url, trigger)
9447
9782
  ];
9448
9783
  case 2:
9449
- _ret = _state.sent();
9450
- if (_ret === "break") return [
9784
+ _state.sent();
9785
+ return [
9451
9786
  3,
9452
- 3
9787
+ 4
9453
9788
  ];
9789
+ case 3:
9790
+ unused = _state.sent();
9791
+ this.continueAfterRequestFailure(epoch);
9454
9792
  return [
9455
9793
  3,
9456
- 1
9794
+ 4
9457
9795
  ];
9458
- case 3:
9459
- this.continuousFetchLoopRunning = false;
9460
- if (this.debug) {
9461
- console.log("[CONTINUOUS-FETCH] URL generation loop ended (queued: ".concat(this.adRequestQueue.length, ")"), this.adRequestQueue.length > 0 ? {
9462
- queuedUrls: _to_consumable_array(this.adRequestQueue)
9463
- } : {});
9464
- }
9796
+ case 4:
9465
9797
  return [
9466
9798
  2
9467
9799
  ];
@@ -9471,242 +9803,158 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9471
9803
  }
9472
9804
  },
9473
9805
  {
9474
- key: "stopContinuousFetching",
9475
- value: function stopContinuousFetching() {
9476
- this.continuousFetchingActive = false;
9477
- this.continuousFetchLoopRunning = false;
9478
- this.placeholder.hide();
9479
- if (this.debug) {
9480
- console.log("[CONTINUOUS-FETCH] Stopping continuous ad fetching");
9806
+ key: "continueAfterRequestFailure",
9807
+ value: function continueAfterRequestFailure() {
9808
+ var epoch = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.timing.adBreakEpoch;
9809
+ if (!this.inAdBreak || epoch !== this.timing.adBreakEpoch) return;
9810
+ this.setSlotState("NEEDS_NEXT_AD", "request_failed");
9811
+ this.requestNextAd("after_failure");
9812
+ }
9813
+ },
9814
+ {
9815
+ key: "cancelScheduledRequest",
9816
+ value: function cancelScheduledRequest() {
9817
+ if (this.nextAdTimerId != null) {
9818
+ clearTimeout(this.nextAdTimerId);
9819
+ this.nextAdTimerId = void 0;
9481
9820
  }
9482
9821
  }
9483
9822
  },
9484
9823
  {
9485
- key: "tryNextAvailableAdWithRateLimit",
9486
- value: // ───────────────────────────────────────────────────────────────
9487
- // Ad iteration
9824
+ key: "noteVastUrlGenerated",
9825
+ value: function noteVastUrlGenerated(url, source) {
9826
+ var _ref, _ref1, _ref2, _ref3, _ref4;
9827
+ var params;
9828
+ try {
9829
+ params = new URL(url).searchParams;
9830
+ } catch (unused) {}
9831
+ var adType = (_ref = params === null || params === void 0 ? void 0 : params.get("ad_type")) !== null && _ref !== void 0 ? _ref : void 0;
9832
+ this.logOrchestratorFunnel("vast_url_generated", {
9833
+ source: source,
9834
+ pod: (_ref1 = params === null || params === void 0 ? void 0 : params.get("pod")) !== null && _ref1 !== void 0 ? _ref1 : void 0,
9835
+ pmad: (_ref2 = params === null || params === void 0 ? void 0 : params.get("pmad")) !== null && _ref2 !== void 0 ? _ref2 : void 0,
9836
+ pmnd: (_ref3 = params === null || params === void 0 ? void 0 : params.get("pmnd")) !== null && _ref3 !== void 0 ? _ref3 : void 0,
9837
+ pmxd: (_ref4 = params === null || params === void 0 ? void 0 : params.get("pmxd")) !== null && _ref4 !== void 0 ? _ref4 : void 0,
9838
+ adType: adType
9839
+ });
9840
+ if (adType === "audio" || adType === "audio_video") {
9841
+ console.warn("[AdBreak] VAST tag requests ad_type=".concat(adType, "; GAM may return audio-only creatives, which this video player rejects"));
9842
+ this.countFunnelStage("tag_allows_audio");
9843
+ }
9844
+ }
9845
+ },
9846
+ {
9847
+ key: "recordRequestFailure",
9848
+ value: function recordRequestFailure(error, vastTagUrl) {
9849
+ var _diag_vastAdCount;
9850
+ var diag = this.currentRequestId != null ? this.requestDiagnostics.get(this.currentRequestId) : void 0;
9851
+ var message = (error === null || error === void 0 ? void 0 : error.message) || "";
9852
+ var outcome;
9853
+ if (message.includes("ad_duration_exceeds_budget")) {
9854
+ outcome = "discarded_budget";
9855
+ } else if (message.includes("VAST fill rejected")) {
9856
+ outcome = "fill_rejected";
9857
+ } else if (/no ads available|no fill|nofill/i.test(message)) {
9858
+ outcome = "no_fill";
9859
+ } else if (/timeout/i.test(message)) {
9860
+ outcome = "request_timeout";
9861
+ } else if (/destroyed|aborted/i.test(message)) {
9862
+ outcome = "request_aborted";
9863
+ } else if (diag && ((_diag_vastAdCount = diag.vastAdCount) !== null && _diag_vastAdCount !== void 0 ? _diag_vastAdCount : 0) > 0 && !diag.impressionFired) {
9864
+ outcome = "playback_failed";
9865
+ } else {
9866
+ outcome = "request_failed";
9867
+ }
9868
+ this.timing.consecutiveFailures++;
9869
+ if (outcome === "no_fill" || outcome === "fill_rejected" || outcome === "discarded_budget") {
9870
+ this.unusableResponsesInBreak++;
9871
+ }
9872
+ if (outcome === "no_fill") {
9873
+ this.timing.recordGamNoFill();
9874
+ }
9875
+ if (diag && !diag.failureReason) {
9876
+ diag.failureReason = "".concat(outcome, ": ").concat(message);
9877
+ }
9878
+ if (this.timing.isTemporaryAdError(error)) {
9879
+ this.timing.temporaryFailureUrls.set(vastTagUrl, Date.now());
9880
+ } else if (outcome !== "discarded_budget") {
9881
+ this.timing.failedVastUrls.add(vastTagUrl);
9882
+ }
9883
+ this.countFunnelStage("request_outcome:".concat(outcome));
9884
+ this.logOrchestratorFunnel("request_outcome", {
9885
+ outcome: outcome,
9886
+ errorMessage: message,
9887
+ consecutiveFailures: this.timing.consecutiveFailures,
9888
+ unusableResponsesInBreak: this.unusableResponsesInBreak
9889
+ });
9890
+ }
9891
+ },
9892
+ {
9488
9893
  // ───────────────────────────────────────────────────────────────
9489
- function tryNextAvailableAdWithRateLimit() {
9490
- return _async_to_generator(function() {
9491
- var epoch, backoffMultiplier, backoffDelay, effectiveMinInterval, timeSinceLastRequest, waitTime;
9492
- return _ts_generator(this, function(_state) {
9493
- switch(_state.label){
9494
- case 0:
9495
- if (!this.inAdBreak) {
9496
- return [
9497
- 2
9498
- ];
9499
- }
9500
- epoch = this.timing.adBreakEpoch;
9501
- if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
9502
- if (this.debug) {
9503
- console.log("[CONTINUOUS-FETCH] Too many consecutive failures (".concat(this.timing.consecutiveFailures, "), ending ad break gracefully"));
9504
- }
9505
- this.handleAdPodComplete();
9506
- return [
9507
- 2
9508
- ];
9509
- }
9510
- backoffMultiplier = Math.pow(2, this.timing.consecutiveFailures);
9511
- backoffDelay = Math.min(this.timing.backoffBaseMs * backoffMultiplier, this.timing.maxBackoffMs);
9512
- effectiveMinInterval = this.timing.minAdRequestIntervalMs + (this.timing.consecutiveFailures > 0 ? backoffDelay : 0);
9513
- timeSinceLastRequest = Date.now() - this.timing.lastAdRequestTime;
9514
- if (!(timeSinceLastRequest < effectiveMinInterval)) return [
9515
- 3,
9516
- 2
9517
- ];
9518
- waitTime = effectiveMinInterval - timeSinceLastRequest;
9519
- if (this.debug) {
9520
- console.log("[CONTINUOUS-FETCH] Rate limiting: waiting ".concat(waitTime, "ms before next request (backoff: ").concat(this.timing.consecutiveFailures, " failures)"));
9521
- }
9522
- return [
9523
- 4,
9524
- new Promise(function(resolve) {
9525
- return setTimeout(resolve, waitTime);
9526
- })
9527
- ];
9528
- case 1:
9529
- _state.sent();
9530
- _state.label = 2;
9531
- case 2:
9532
- if (!this.inAdBreak || epoch !== this.timing.adBreakEpoch) {
9533
- return [
9534
- 2
9535
- ];
9536
- }
9537
- return [
9538
- 2,
9539
- this.tryNextAvailableAd(0)
9540
- ];
9894
+ // Per-request diagnostics
9895
+ // ───────────────────────────────────────────────────────────────
9896
+ key: "recordRequestDiagnostic",
9897
+ value: function recordRequestDiagnostic(payload) {
9898
+ var requestId = payload.requestId;
9899
+ if (typeof requestId !== "number") return;
9900
+ var diag = this.requestDiagnostics.get(requestId);
9901
+ if (!diag) return;
9902
+ switch(payload.stage){
9903
+ case "gam_http_request_sent":
9904
+ diag.gamRequestSent++;
9905
+ break;
9906
+ case "gam_response_received":
9907
+ diag.vastHttpStatus = payload.httpStatus;
9908
+ break;
9909
+ case "vast_parsed":
9910
+ diag.vastAdCount = payload.adElementCount;
9911
+ break;
9912
+ case "wrapper_fetch":
9913
+ case "inline_resolved":
9914
+ if (typeof payload.depth === "number") {
9915
+ diag.wrapperDepth = Math.max(diag.wrapperDepth, payload.depth);
9541
9916
  }
9542
- });
9543
- }).call(this);
9917
+ if (payload.stage === "inline_resolved") diag.inlineResolved = true;
9918
+ break;
9919
+ case "mediafile_evaluated":
9920
+ diag.mediaCandidateCount++;
9921
+ if (payload.whyAccepted) diag.supportedMediaCount++;
9922
+ break;
9923
+ case "playing":
9924
+ diag.playStarted = true;
9925
+ break;
9926
+ case "impression_fired":
9927
+ diag.impressionFired = true;
9928
+ break;
9929
+ default:
9930
+ if (REQUEST_FAILURE_STAGES.has(payload.stage) && !diag.failureReason) {
9931
+ diag.failureReason = payload.reason ? "".concat(payload.stage, ":").concat(payload.reason) : payload.stage;
9932
+ }
9933
+ }
9544
9934
  }
9545
9935
  },
9546
9936
  {
9547
- key: "tryNextAvailableAd",
9548
- value: function tryNextAvailableAd() {
9549
- var retryCount = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
9550
- return _async_to_generator(function() {
9551
- var remaining, nextAdUrl, error, errorMessage, maxRetries;
9552
- return _ts_generator(this, function(_state) {
9553
- switch(_state.label){
9554
- case 0:
9555
- if (!this.inAdBreak) {
9556
- return [
9557
- 2
9558
- ];
9559
- }
9560
- remaining = this.timing.getRemainingAdMs();
9561
- if (!this.timing.hasTimeToStartAnotherAd()) {
9562
- if (this.debug) {
9563
- console.log("[CONTINUOUS-FETCH] Not enough time remaining (".concat(remaining, "ms) to start another ad, ending ad break"));
9564
- }
9565
- this.handleAdPodComplete();
9566
- return [
9567
- 2
9568
- ];
9569
- }
9570
- if (this.timing.isGamInCooldown()) {
9571
- if (this.debug) {
9572
- console.log("[CIRCUIT-BREAKER] GAM in cooldown, ending ad break gracefully");
9573
- }
9574
- this.handleAdPodComplete();
9575
- return [
9576
- 2
9577
- ];
9578
- }
9579
- if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
9580
- if (this.debug) {
9581
- console.log("[CONTINUOUS-FETCH] Too many consecutive failures (".concat(this.timing.consecutiveFailures, "), ending ad break"));
9582
- }
9583
- this.handleAdPodComplete();
9584
- return [
9585
- 2
9586
- ];
9587
- }
9588
- this.timing.cleanupTemporaryFailures();
9589
- _state.label = 1;
9590
- case 1:
9591
- if (!(this.adRequestQueue.length > 0)) return [
9592
- 3,
9593
- 9
9594
- ];
9595
- nextAdUrl = this.adRequestQueue.shift();
9596
- if (!nextAdUrl) return [
9597
- 3,
9598
- 1
9599
- ];
9600
- if (this.timing.failedVastUrls.has(nextAdUrl)) {
9601
- if (this.debug) console.log("[CONTINUOUS-FETCH] Skipping permanently-failed URL, trying next...");
9602
- return [
9603
- 3,
9604
- 1
9605
- ];
9606
- }
9607
- if (this.timing.isUrlInCooldown(nextAdUrl)) {
9608
- if (this.debug) console.log("[CONTINUOUS-FETCH] Skipping URL in cooldown (recent no-fill), trying next...");
9609
- return [
9610
- 3,
9611
- 1
9612
- ];
9613
- }
9614
- if (this.debug) {
9615
- console.log("[CONTINUOUS-FETCH] Requesting next ad via HLS ad player (".concat(this.timing.currentAdIndex + 1, ", ").concat(this.adRequestQueue.length, " remaining in queue)"));
9616
- }
9617
- _state.label = 2;
9618
- case 2:
9619
- _state.trys.push([
9620
- 2,
9621
- 4,
9622
- ,
9623
- 8
9624
- ]);
9625
- return [
9626
- 4,
9627
- this.playSingleAd(nextAdUrl)
9628
- ];
9629
- case 3:
9630
- _state.sent();
9631
- return [
9632
- 3,
9633
- 8
9634
- ];
9635
- case 4:
9636
- error = _state.sent();
9637
- errorMessage = error.message;
9638
- if (this.debug) console.log("[CONTINUOUS-FETCH] Ad request failed:", errorMessage);
9639
- if (!errorMessage.includes("ad_duration_exceeds_budget")) return [
9640
- 3,
9641
- 6
9642
- ];
9643
- this.timing.consecutiveFailures++;
9644
- return [
9645
- 4,
9646
- this.tryNextAvailableAdWithRateLimit()
9647
- ];
9648
- case 5:
9649
- _state.sent();
9650
- return [
9651
- 2
9652
- ];
9653
- case 6:
9654
- if (!errorMessage.includes("permanently failed") && !errorMessage.includes("in cooldown")) {
9655
- this.timing.consecutiveFailures++;
9656
- }
9657
- return [
9658
- 4,
9659
- this.tryNextAvailableAdWithRateLimit()
9660
- ];
9661
- case 7:
9662
- _state.sent();
9663
- return [
9664
- 3,
9665
- 8
9666
- ];
9667
- case 8:
9668
- return [
9669
- 2
9670
- ];
9671
- case 9:
9672
- maxRetries = 3;
9673
- if (!(this.continuousFetchingActive && retryCount < maxRetries && remaining > 2e3)) return [
9674
- 3,
9675
- 12
9676
- ];
9677
- if (this.debug) {
9678
- console.log("[CONTINUOUS-FETCH] Queue empty, waiting for URLs... (".concat(retryCount + 1, "/").concat(maxRetries, ")"));
9679
- }
9680
- return [
9681
- 4,
9682
- new Promise(function(resolve) {
9683
- return setTimeout(resolve, 500);
9684
- })
9685
- ];
9686
- case 10:
9687
- _state.sent();
9688
- return [
9689
- 4,
9690
- this.tryNextAvailableAd(retryCount + 1)
9691
- ];
9692
- case 11:
9693
- _state.sent();
9694
- return [
9695
- 2
9696
- ];
9697
- case 12:
9698
- if (!this.isShowingPlaceholder && remaining > 1e3) {
9699
- this.showPlaceholderAndWaitForAds();
9700
- } else {
9701
- if (this.debug) console.log("[CONTINUOUS-FETCH] No more ads available, ending ad break");
9702
- this.handleAdPodComplete();
9703
- }
9704
- return [
9705
- 2
9706
- ];
9707
- }
9708
- });
9709
- }).call(this);
9937
+ key: "finalizeRequestDiagnostics",
9938
+ value: function finalizeRequestDiagnostics(requestId, endReason) {
9939
+ var _diag_vastAdCount;
9940
+ if (requestId == null) return;
9941
+ var diag = this.requestDiagnostics.get(requestId);
9942
+ if (!diag) return;
9943
+ this.requestDiagnostics.delete(requestId);
9944
+ if (!diag.impressionFired && !diag.failureReason && endReason) {
9945
+ diag.failureReason = endReason;
9946
+ }
9947
+ var gamReturnedAdWithoutImpression = ((_diag_vastAdCount = diag.vastAdCount) !== null && _diag_vastAdCount !== void 0 ? _diag_vastAdCount : 0) > 0 && !diag.impressionFired;
9948
+ if (gamReturnedAdWithoutImpression) {
9949
+ this.countFunnelStage("gam_ad_without_impression");
9950
+ }
9951
+ var startedAt = diag.startedAt, fields = _object_without_properties(diag, [
9952
+ "startedAt"
9953
+ ]);
9954
+ console.log("[AdBreak][REQUEST] summary", _object_spread_props(_object_spread({}, fields), {
9955
+ durationMs: Date.now() - startedAt,
9956
+ gamReturnedAdWithoutImpression: gamReturnedAdWithoutImpression
9957
+ }));
9710
9958
  }
9711
9959
  },
9712
9960
  {
@@ -9714,7 +9962,8 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9714
9962
  // Single ad playback
9715
9963
  // ───────────────────────────────────────────────────────────────
9716
9964
  key: "withCurrentPodBudget",
9717
- value: function withCurrentPodBudget(vastTagUrl) {
9965
+ value: function withCurrentPodBudget(rawVastTagUrl) {
9966
+ var vastTagUrl = ensureVideoAdType(rawVastTagUrl);
9718
9967
  var remaining = Math.min(this.timing.getWallClockRemainingAdMs(), this.timing.getDurationBudgetRemainingMs());
9719
9968
  if (!(remaining > 0)) return vastTagUrl;
9720
9969
  try {
@@ -9773,18 +10022,34 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9773
10022
  },
9774
10023
  {
9775
10024
  key: "beginFunnelRequest",
9776
- value: function beginFunnelRequest(adPlayer, requestToken) {
10025
+ value: function beginFunnelRequest(adPlayer, requestToken, trigger) {
9777
10026
  var _adPlayer_setFunnelContext;
9778
10027
  if (this.controllerCallInFlight) {
9779
10028
  this.logOrchestratorFunnel("duplicate_request_detected", {
9780
10029
  newRequestId: requestToken
9781
10030
  });
9782
10031
  }
10032
+ this.finalizeRequestDiagnostics(this.currentRequestId);
9783
10033
  this.currentRequestId = requestToken;
9784
10034
  this.requestStartedAt = Date.now();
10035
+ this.requestDiagnostics.set(requestToken, {
10036
+ breakId: this.timing.adBreakEpoch,
10037
+ requestId: requestToken,
10038
+ controllerId: this.controllerGeneration,
10039
+ trigger: trigger,
10040
+ gamRequestSent: 0,
10041
+ wrapperDepth: 0,
10042
+ inlineResolved: false,
10043
+ mediaCandidateCount: 0,
10044
+ supportedMediaCount: 0,
10045
+ playStarted: false,
10046
+ impressionFired: false,
10047
+ startedAt: Date.now()
10048
+ });
9785
10049
  (_adPlayer_setFunnelContext = adPlayer.setFunnelContext) === null || _adPlayer_setFunnelContext === void 0 ? void 0 : _adPlayer_setFunnelContext.call(adPlayer, {
9786
10050
  breakId: this.timing.adBreakEpoch,
9787
- requestId: requestToken
10051
+ requestId: requestToken,
10052
+ controllerId: this.controllerGeneration
9788
10053
  });
9789
10054
  }
9790
10055
  },
@@ -9815,7 +10080,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9815
10080
  adPlayer.abortPendingRequest("VAST request aborted after request watchdog timeout");
9816
10081
  return;
9817
10082
  }
9818
- this.handleAdFailure();
10083
+ this.handleAdFailure("request_watchdog_timeout");
9819
10084
  }
9820
10085
  },
9821
10086
  {
@@ -9861,21 +10126,30 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9861
10126
  {
9862
10127
  key: "playSingleAd",
9863
10128
  value: function playSingleAd(vastTagUrl) {
10129
+ var trigger = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "vmap";
9864
10130
  return _async_to_generator(function() {
9865
- var adPlayer, requestToken, ap, requestUrl, _ap_getLoadedAdDuration, adDurationS, remainingMs, playError, error, errorMessage;
10131
+ var epoch, generation, requestToken, ap, requestUrl, _ap_getLoadedAdDuration, adDurationS, remainingMs, error;
9866
10132
  return _ts_generator(this, function(_state) {
9867
10133
  switch(_state.label){
9868
10134
  case 0:
9869
- adPlayer = this.host.getAdPlayer();
9870
- if (adPlayer.isAdPlaying()) return [
9871
- 2
9872
- ];
10135
+ if (this.slotState === "REQUESTING" || this.slotState === "READY" || this.slotState === "PLAYING" || this.slotState === "ENDING") {
10136
+ this.logOrchestratorFunnel("request_suppressed", {
10137
+ trigger: trigger,
10138
+ state: this.slotState,
10139
+ why: "request_in_flight"
10140
+ });
10141
+ return [
10142
+ 2
10143
+ ];
10144
+ }
9873
10145
  if (this.timing.failedVastUrls.has(vastTagUrl)) {
9874
10146
  if (this.debug) console.warn("[AD-ERROR] Skipping permanently-failed VAST URL:", vastTagUrl);
10147
+ this.timing.consecutiveFailures++;
9875
10148
  throw new Error("VAST URL permanently failed");
9876
10149
  }
9877
10150
  if (this.timing.isUrlInCooldown(vastTagUrl)) {
9878
10151
  if (this.debug) console.warn("[AD-ERROR] Skipping URL in cooldown (recent no-fill):", vastTagUrl);
10152
+ this.timing.consecutiveFailures++;
9879
10153
  throw new Error("VAST URL in cooldown after no-fill");
9880
10154
  }
9881
10155
  if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
@@ -9886,16 +10160,23 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9886
10160
  if (this.debug) console.warn("[CIRCUIT-BREAKER] GAM in cooldown, skipping ad request");
9887
10161
  throw new Error("GAM in cooldown");
9888
10162
  }
9889
- this.recreateAdController();
10163
+ epoch = this.timing.adBreakEpoch;
10164
+ this.recreateAdController("new_request");
10165
+ generation = this.controllerGeneration;
9890
10166
  requestToken = ++this.timing.adRequestTokenCounter;
9891
10167
  this.timing.activeAdRequestToken = requestToken;
10168
+ ap = this.host.getAdPlayer();
10169
+ requestUrl = this.withCurrentPodBudget(vastTagUrl);
10170
+ this.currentVastUrl = requestUrl;
10171
+ this.setSlotState("REQUESTING", trigger);
10172
+ this.beginFunnelRequest(ap, requestToken, trigger);
9892
10173
  _state.label = 1;
9893
10174
  case 1:
9894
10175
  _state.trys.push([
9895
10176
  1,
9896
- 8,
10177
+ 5,
9897
10178
  ,
9898
- 9
10179
+ 6
9899
10180
  ]);
9900
10181
  return [
9901
10182
  4,
@@ -9903,12 +10184,10 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9903
10184
  ];
9904
10185
  case 2:
9905
10186
  _state.sent();
10187
+ if (this.isStale(epoch, generation)) return [
10188
+ 2
10189
+ ];
9906
10190
  this.timing.startAdRequestWatchdog(requestToken);
9907
- this.timing.noteAdRequestSent();
9908
- ap = this.host.getAdPlayer();
9909
- requestUrl = this.withCurrentPodBudget(vastTagUrl);
9910
- this.currentVastUrl = requestUrl;
9911
- this.beginFunnelRequest(ap, requestToken);
9912
10191
  return [
9913
10192
  4,
9914
10193
  this.callController(function() {
@@ -9917,36 +10196,31 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9917
10196
  ];
9918
10197
  case 3:
9919
10198
  _state.sent();
10199
+ this.timing.clearAdRequestWatchdog();
10200
+ if (this.isStale(epoch, generation)) {
10201
+ this.logOrchestratorFunnel("stale_request_result_ignored", {
10202
+ requestId: requestToken
10203
+ });
10204
+ return [
10205
+ 2
10206
+ ];
10207
+ }
9920
10208
  sendAdLoadedTracking(this.host.config.licenseKey, {
9921
10209
  source: "hls",
9922
10210
  vastUrl: requestUrl,
9923
10211
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
9924
10212
  }, this.analyticsContext).catch(function() {});
9925
- this.timing.clearAdRequestWatchdog();
9926
- if (this.timing.activeAdRequestToken !== requestToken) return [
9927
- 2
9928
- ];
9929
10213
  if (!this.timing.ensureLoadedAdFitsBudget(ap)) {
9930
10214
  ;
9931
10215
  adDurationS = (_ap_getLoadedAdDuration = ap.getLoadedAdDuration) === null || _ap_getLoadedAdDuration === void 0 ? void 0 : _ap_getLoadedAdDuration.call(ap);
9932
10216
  remainingMs = Math.min(this.timing.getWallClockRemainingAdMs(), this.timing.getDurationBudgetRemainingMs());
9933
10217
  this.logOrchestratorFunnel("discarded_budget", {
9934
- vastUrl: requestUrl,
9935
10218
  adDurationMs: adDurationS != null ? adDurationS * 1e3 : void 0,
9936
10219
  remainingMs: remainingMs
9937
10220
  });
9938
- this.timing.rejectLoadedAdForDuration(ap);
9939
- this.recreateAdController();
9940
10221
  throw new Error("ad_duration_exceeds_budget");
9941
10222
  }
9942
- _state.label = 4;
9943
- case 4:
9944
- _state.trys.push([
9945
- 4,
9946
- 6,
9947
- ,
9948
- 7
9949
- ]);
10223
+ this.setSlotState("READY", "vast_ready");
9950
10224
  this.timing.startAdFailsafeTimer(requestToken);
9951
10225
  return [
9952
10226
  4,
@@ -9954,8 +10228,11 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9954
10228
  return ap.play();
9955
10229
  })
9956
10230
  ];
9957
- case 5:
10231
+ case 4:
9958
10232
  _state.sent();
10233
+ if (this.isStale(epoch, generation)) return [
10234
+ 2
10235
+ ];
9959
10236
  if (this.timing.expectedAdBreakDurationMs != null && this.timing.getAdBreakEndWallClockMs() == null) {
9960
10237
  this.timing.scheduleAdStopAtBreakBoundary();
9961
10238
  }
@@ -9963,216 +10240,31 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9963
10240
  this.timing.temporaryFailureUrls.delete(vastTagUrl);
9964
10241
  return [
9965
10242
  3,
9966
- 7
9967
- ];
9968
- case 6:
9969
- playError = _state.sent();
9970
- if (this.debug) console.error("[AD-ERROR] Failed to play ad:", playError);
9971
- if (this.timing.isTemporaryAdError(playError)) {
9972
- this.timing.temporaryFailureUrls.set(vastTagUrl, Date.now());
9973
- if (this.debug) console.log("[AD-ERROR] Temporary play error - URL can be retried after cooldown");
9974
- } else {
9975
- this.timing.failedVastUrls.add(vastTagUrl);
9976
- if (this.debug) console.log("[AD-ERROR] Permanent play error - URL blacklisted");
9977
- }
9978
- this.timing.clearAdFailsafeTimer();
9979
- if (this.timing.activeAdRequestToken === requestToken) {
9980
- this.timing.activeAdRequestToken = null;
9981
- }
9982
- throw playError;
9983
- case 7:
9984
- return [
9985
- 3,
9986
- 9
10243
+ 6
9987
10244
  ];
9988
- case 8:
10245
+ case 5:
9989
10246
  error = _state.sent();
9990
- errorMessage = (error === null || error === void 0 ? void 0 : error.message) || "";
9991
- if (this.debug) console.error("[AD-ERROR] Ad request failed:", errorMessage);
9992
- if (this.timing.isTemporaryAdError(error)) {
9993
- this.timing.temporaryFailureUrls.set(vastTagUrl, Date.now());
9994
- if (this.debug) console.log("[AD-ERROR] Temporary error (no-fill/timeout) - URL can be retried after cooldown");
9995
- } else {
9996
- this.timing.failedVastUrls.add(vastTagUrl);
9997
- if (this.debug) console.log("[AD-ERROR] Permanent error - URL blacklisted:", errorMessage);
9998
- }
9999
10247
  this.timing.clearAdRequestWatchdog();
10000
10248
  this.timing.clearAdFailsafeTimer();
10001
10249
  if (this.timing.activeAdRequestToken === requestToken) {
10002
10250
  this.timing.activeAdRequestToken = null;
10003
10251
  }
10004
- throw error;
10005
- case 9:
10006
- return [
10007
- 2
10008
- ];
10009
- }
10010
- });
10011
- }).call(this);
10012
- }
10013
- },
10014
- {
10015
- key: "showPlaceholderAndWaitForAds",
10016
- value: // ───────────────────────────────────────────────────────────────
10017
- // Placeholder wait
10018
- // ───────────────────────────────────────────────────────────────
10019
- function showPlaceholderAndWaitForAds() {
10020
- return _async_to_generator(function() {
10021
- var remaining, waitTime, checkInterval, maxChecks, i, nextAdUrl, error, errorMessage;
10022
- return _ts_generator(this, function(_state) {
10023
- switch(_state.label){
10024
- case 0:
10025
- remaining = this.timing.getRemainingAdMs();
10026
- waitTime = Math.min(this.maxPlaceholderDurationMs, remaining);
10027
- if (this.timing.isGamInCooldown()) {
10028
- if (this.debug) console.log("[CIRCUIT-BREAKER] GAM in cooldown, skipping placeholder wait");
10029
- this.handleAdPodComplete();
10030
- return [
10031
- 2
10032
- ];
10033
- }
10034
- if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
10035
- if (this.debug) console.log("[CONTINUOUS-FETCH] Skipping placeholder - too many consecutive failures");
10036
- this.handleAdPodComplete();
10037
- return [
10038
- 2
10039
- ];
10040
- }
10041
- if (waitTime < 1e3) {
10042
- this.handleAdPodComplete();
10252
+ if (this.isStale(epoch, generation)) {
10253
+ this.logOrchestratorFunnel("stale_request_result_ignored", {
10254
+ requestId: requestToken,
10255
+ errorMessage: error === null || error === void 0 ? void 0 : error.message
10256
+ });
10043
10257
  return [
10044
10258
  2
10045
10259
  ];
10046
10260
  }
10047
- if (this.debug) {
10048
- console.log("[CONTINUOUS-FETCH] Showing placeholder for ".concat(waitTime, "ms while waiting for ad URLs"));
10261
+ if (this.debug) console.error("[AD-ERROR] Ad request failed:", error === null || error === void 0 ? void 0 : error.message);
10262
+ this.recordRequestFailure(error, vastTagUrl);
10263
+ if ((error === null || error === void 0 ? void 0 : error.message) === "ad_duration_exceeds_budget") {
10264
+ this.recreateAdController("discarded_budget");
10049
10265
  }
10050
- this.isShowingPlaceholder = true;
10051
- this.host.getAdPlayer().showPlaceholder();
10052
- checkInterval = 300;
10053
- maxChecks = Math.floor(waitTime / checkInterval);
10054
- i = 0;
10055
- _state.label = 1;
10056
- case 1:
10057
- if (!(i < maxChecks)) return [
10058
- 3,
10059
- 12
10060
- ];
10061
- return [
10062
- 4,
10063
- new Promise(function(resolve) {
10064
- return setTimeout(resolve, checkInterval);
10065
- })
10066
- ];
10067
- case 2:
10068
- _state.sent();
10069
- if (!this.inAdBreak) return [
10070
- 2
10071
- ];
10072
- if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
10073
- if (this.debug) console.log("[CONTINUOUS-FETCH] Too many failures during placeholder wait");
10074
- return [
10075
- 3,
10076
- 12
10077
- ];
10078
- }
10079
- if (!this.timing.hasTimeToStartAnotherAd()) {
10080
- if (this.debug) console.log("[CONTINUOUS-FETCH] Not enough time remaining during placeholder wait, ending ad break");
10081
- return [
10082
- 3,
10083
- 12
10084
- ];
10085
- }
10086
- _state.label = 3;
10087
- case 3:
10088
- if (!(this.adRequestQueue.length > 0)) return [
10089
- 3,
10090
- 11
10091
- ];
10092
- if (!this.timing.hasTimeToStartAnotherAd()) return [
10093
- 3,
10094
- 11
10095
- ];
10096
- nextAdUrl = this.adRequestQueue.shift();
10097
- if (!nextAdUrl) return [
10098
- 3,
10099
- 3
10100
- ];
10101
- if (this.timing.failedVastUrls.has(nextAdUrl)) return [
10102
- 3,
10103
- 3
10104
- ];
10105
- if (this.timing.isUrlInCooldown(nextAdUrl)) return [
10106
- 3,
10107
- 3
10108
- ];
10109
- if (this.debug) console.log("[CONTINUOUS-FETCH] Ad URL available, requesting via HLS ad player");
10110
- this.isShowingPlaceholder = false;
10111
- this.host.getAdPlayer().hidePlaceholder();
10112
- _state.label = 4;
10113
- case 4:
10114
- _state.trys.push([
10115
- 4,
10116
- 6,
10117
- ,
10118
- 10
10119
- ]);
10120
- return [
10121
- 4,
10122
- this.playSingleAd(nextAdUrl)
10123
- ];
10124
- case 5:
10125
- _state.sent();
10126
- return [
10127
- 3,
10128
- 10
10129
- ];
10266
+ throw error;
10130
10267
  case 6:
10131
- error = _state.sent();
10132
- errorMessage = error.message;
10133
- if (!errorMessage.includes("ad_duration_exceeds_budget")) return [
10134
- 3,
10135
- 8
10136
- ];
10137
- this.timing.consecutiveFailures++;
10138
- return [
10139
- 4,
10140
- this.tryNextAvailableAdWithRateLimit()
10141
- ];
10142
- case 7:
10143
- _state.sent();
10144
- return [
10145
- 2
10146
- ];
10147
- case 8:
10148
- if (!errorMessage.includes("permanently failed") && !errorMessage.includes("in cooldown")) {
10149
- this.timing.consecutiveFailures++;
10150
- }
10151
- return [
10152
- 4,
10153
- this.tryNextAvailableAdWithRateLimit()
10154
- ];
10155
- case 9:
10156
- _state.sent();
10157
- return [
10158
- 3,
10159
- 10
10160
- ];
10161
- case 10:
10162
- return [
10163
- 2
10164
- ];
10165
- case 11:
10166
- i++;
10167
- return [
10168
- 3,
10169
- 1
10170
- ];
10171
- case 12:
10172
- if (this.debug) console.log("[CONTINUOUS-FETCH] Placeholder timeout, ending ad break");
10173
- this.isShowingPlaceholder = false;
10174
- this.host.getAdPlayer().hidePlaceholder();
10175
- this.handleAdPodComplete();
10176
10268
  return [
10177
10269
  2
10178
10270
  ];
@@ -10186,7 +10278,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
10186
10278
  // Ad break completion
10187
10279
  // ───────────────────────────────────────────────────────────────
10188
10280
  key: "logBreakFunnel",
10189
- value: function logBreakFunnel() {
10281
+ value: function logBreakFunnel(endReason) {
10190
10282
  var funnel = this.breakFunnel;
10191
10283
  this.breakFunnel = {};
10192
10284
  if (Object.keys(funnel).length === 0) return;
@@ -10194,26 +10286,49 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
10194
10286
  var _funnel_stage;
10195
10287
  return (_funnel_stage = funnel[stage]) !== null && _funnel_stage !== void 0 ? _funnel_stage : 0;
10196
10288
  };
10289
+ var countPrefix = function countPrefix(prefix) {
10290
+ return Object.keys(funnel).reduce(function(total, stage) {
10291
+ var _funnel_stage;
10292
+ return stage.indexOf(prefix) === 0 ? total + ((_funnel_stage = funnel[stage]) !== null && _funnel_stage !== void 0 ? _funnel_stage : 0) : total;
10293
+ }, 0);
10294
+ };
10197
10295
  var breakId = this.opportunityEpoch;
10198
- if (count("request_sent") > 0 && count("impression_fired") === 0) {
10296
+ var requestRetries = count("gam_http_request_retry");
10297
+ var requests = count("gam_http_request_sent") - requestRetries;
10298
+ if (requests > 0 && count("impression_fired") === 0) {
10199
10299
  console.log("[AdBreak][FUNNEL] break_abandoned_before_start", {
10200
10300
  breakId: breakId,
10201
- requests: count("request_sent")
10301
+ requests: requests,
10302
+ endReason: endReason
10202
10303
  });
10203
10304
  }
10204
10305
  console.log("[AdBreak][FUNNEL] Break summary", {
10205
10306
  breakId: breakId,
10307
+ endReason: endReason,
10206
10308
  opportunities: count("opportunity_created"),
10207
- requests: count("request_sent"),
10309
+ vastUrlsGenerated: count("vast_url_generated"),
10310
+ requests: requests,
10311
+ requestRetries: requestRetries,
10312
+ gamResponses: count("gam_response_received"),
10313
+ requestsSuppressed: count("request_suppressed"),
10208
10314
  duplicates: count("duplicate_request_detected") + count("duplicate_break_start"),
10209
10315
  filled: count("vast_received"),
10210
10316
  noFill: count("no_fill"),
10317
+ fillRejected: count("vast_fill_rejected"),
10318
+ gamAdWithoutImpression: count("gam_ad_without_impression"),
10319
+ playbackFailedAfterFill: count("request_outcome:playback_failed"),
10211
10320
  requestFailed: count("request_failed"),
10212
10321
  requestAbortedTimeout: count("request_aborted_timeout"),
10213
10322
  credentialsRetries: count("vast_credentials_retry"),
10214
10323
  wrapperFailures: count("wrapper_fetch:failure"),
10215
10324
  noSupportedMedia: count("vast_no_supported_media"),
10216
- vpaidOnly: count("vast_no_supported_media:vpaid_only"),
10325
+ vpaidOnly: count("vast_no_supported_media:vpaid"),
10326
+ audioOnly: count("vast_no_supported_media:audio_only"),
10327
+ mediaFilesEvaluated: count("mediafile_evaluated"),
10328
+ mediaFilesAccepted: count("mediafile_evaluated:accepted"),
10329
+ controllerDestroys: countPrefix("controller_destroy:"),
10330
+ staleCallbacks: count("stale_callback_ignored") + count("stale_request_result_ignored"),
10331
+ tagAllowsAudio: count("tag_allows_audio"),
10217
10332
  missingImpression: count("vast_missing_impression"),
10218
10333
  discardedBudget: count("discarded_budget"),
10219
10334
  mediaCandidates: count("media_candidate:accepted") + count("media_candidate:rejected"),
@@ -10248,25 +10363,50 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
10248
10363
  {
10249
10364
  key: "handleAdPodComplete",
10250
10365
  value: function handleAdPodComplete() {
10366
+ var reason = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "unspecified";
10251
10367
  if (this.debug) {
10252
- console.log("[StormcloudVideoPlayer] Ad pod complete - cleaning up");
10368
+ console.log("[StormcloudVideoPlayer] Ad pod complete - cleaning up", {
10369
+ reason: reason
10370
+ });
10371
+ }
10372
+ var previousState = this.slotState;
10373
+ var alreadyEnded = previousState === "IDLE" && !this.inAdBreak;
10374
+ this.setSlotState("ENDING", reason);
10375
+ this.cancelScheduledRequest();
10376
+ var adPlayer = this.host.getAdPlayer();
10377
+ if (previousState === "REQUESTING") {
10378
+ var _adPlayer_abortPendingRequest;
10379
+ (_adPlayer_abortPendingRequest = adPlayer.abortPendingRequest) === null || _adPlayer_abortPendingRequest === void 0 ? void 0 : _adPlayer_abortPendingRequest.call(adPlayer, "VAST request aborted: ad break ended (".concat(reason, ")"));
10380
+ }
10381
+ if (!alreadyEnded) {
10382
+ console.log("[AD-CONTROLLER] stop", {
10383
+ controllerId: this.controllerGeneration,
10384
+ requestId: this.currentRequestId,
10385
+ state: previousState,
10386
+ reason: reason
10387
+ });
10253
10388
  }
10389
+ this.finalizeRequestDiagnostics(this.currentRequestId, "break_ended:".concat(reason));
10390
+ this.currentRequestId = void 0;
10254
10391
  this.timing.resetForBreakEnd();
10255
- this.stopContinuousFetching();
10392
+ this.placeholder.hide();
10256
10393
  this.clearPendingAdBreak();
10257
10394
  if (this.isShowingPlaceholder) {
10258
- this.host.getAdPlayer().hidePlaceholder();
10395
+ adPlayer.hidePlaceholder();
10259
10396
  this.isShowingPlaceholder = false;
10260
10397
  }
10261
- this.adRequestQueue = [];
10262
10398
  this.inAdBreak = false;
10263
10399
  this.adDetectSentForCurrentBreak = false;
10264
10400
  this.cueManager.activeScte35BreakKey = void 0;
10265
10401
  this.cueManager.scheduledScte35BreakKey = void 0;
10266
10402
  this.adPodQueue = [];
10267
10403
  this.showAds = false;
10268
- this.host.getAdPlayer().stop().catch(function() {});
10269
- this.logBreakFunnel();
10404
+ this.breakSource = void 0;
10405
+ this.followUpBaseVastUrl = void 0;
10406
+ this.unusableResponsesInBreak = 0;
10407
+ adPlayer.stop().catch(function() {});
10408
+ if (!alreadyEnded) this.logBreakFunnel(reason);
10409
+ this.setSlotState("IDLE", "break_complete");
10270
10410
  var restoredMuted = this.host.getAdPlayer().getOriginalMutedState();
10271
10411
  var restoredVolume = this.host.getAdPlayer().getOriginalVolume();
10272
10412
  if (this.host.video.muted !== restoredMuted) {
@@ -10560,25 +10700,23 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
10560
10700
  {
10561
10701
  key: "handleAdFailure",
10562
10702
  value: function handleAdFailure() {
10563
- this.timing.consecutiveFailures++;
10564
- this.timing.recordGamNoFill();
10565
- var remaining = this.timing.getRemainingAdMs();
10566
- if (this.debug) {
10567
- console.log("[CONTINUOUS-FETCH] Ad failure: remaining=".concat(remaining, "ms, queued ads=").concat(this.adRequestQueue.length, ", consecutiveFailures=").concat(this.timing.consecutiveFailures), this.adRequestQueue.length > 0 ? {
10568
- queuedUrls: _to_consumable_array(this.adRequestQueue)
10569
- } : {});
10570
- }
10571
- if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
10572
- if (this.debug) console.log("[CONTINUOUS-FETCH] Max consecutive failures reached (".concat(this.timing.consecutiveFailures, "), ending ad break gracefully"));
10573
- this.handleAdPodComplete();
10703
+ var reason = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "ad_failure";
10704
+ if (!this.inAdBreak) return;
10705
+ if (this.slotState === "REQUESTING" || this.slotState === "ENDING") {
10706
+ this.logOrchestratorFunnel("failure_deferred_to_request", {
10707
+ reason: reason,
10708
+ state: this.slotState
10709
+ });
10574
10710
  return;
10575
10711
  }
10576
- if (this.timing.hasTimeToStartAnotherAd()) {
10577
- this.tryNextAvailableAdWithRateLimit();
10578
- } else {
10579
- if (this.debug) console.log("[AD-ERROR] Ad failed and not enough time remaining for another ad. Failed URLs:", this.timing.failedVastUrls.size);
10580
- this.handleAdPodComplete();
10712
+ this.timing.consecutiveFailures++;
10713
+ var diag = this.currentRequestId != null ? this.requestDiagnostics.get(this.currentRequestId) : void 0;
10714
+ if (diag && !diag.failureReason) diag.failureReason = reason;
10715
+ if (this.debug) {
10716
+ console.log("[AdBreak] Ad failure (".concat(reason, "): remaining=").concat(this.timing.getRemainingAdMs(), "ms, consecutiveFailures=").concat(this.timing.consecutiveFailures));
10581
10717
  }
10718
+ this.setSlotState("NEEDS_NEXT_AD", reason);
10719
+ this.requestNextAd(reason);
10582
10720
  }
10583
10721
  }
10584
10722
  ]);
@@ -10621,7 +10759,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10621
10759
  return _this.adBreak.handleRequestWatchdogTimeout();
10622
10760
  },
10623
10761
  onFailsafeTimeout: function onFailsafeTimeout() {
10624
- return _this.adBreak.handleAdFailure();
10762
+ return _this.adBreak.handleAdFailure("failsafe_timeout");
10625
10763
  },
10626
10764
  getAdState: function getAdState() {
10627
10765
  return {
@@ -10871,6 +11009,21 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10871
11009
  adBehavior: adBehavior
10872
11010
  });
10873
11011
  }
11012
+ if (this.adBreak.isBreakActive()) {
11013
+ console.log("[AD-CONTROLLER] destroy skipped", {
11014
+ reason: "manifest_parsed_during_break",
11015
+ state: this.adBreak.getSlotState()
11016
+ });
11017
+ return [
11018
+ 2
11019
+ ];
11020
+ }
11021
+ if (this.debug) {
11022
+ console.log("[AD-CONTROLLER] destroy", {
11023
+ reason: "manifest_parsed",
11024
+ state: "IDLE"
11025
+ });
11026
+ }
10874
11027
  this.adPlayer.destroy();
10875
11028
  this.adPlayer = this.createAdPlayer(this.shouldContinueLiveStreamDuringAds());
10876
11029
  this.adPlayer.initialize();
@@ -11052,9 +11205,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11052
11205
  this.timing.setAdBreakDurationBoundary(marker.durationSeconds * 1e3);
11053
11206
  }
11054
11207
  this.timing.scheduleAdStopAtBreakBoundary();
11055
- if (!this.adPlayer.isAdPlaying() && this.timing.activeAdRequestToken === null && this.adBreak.adRequestQueue.length > 0 && this.timing.hasTimeToStartAnotherAd()) {
11056
- this.adBreak.tryNextAvailableAdWithRateLimit();
11057
- }
11058
11208
  return;
11059
11209
  }
11060
11210
  if (marker.type === "end") {
@@ -11066,12 +11216,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11066
11216
  }
11067
11217
  var remaining = this.timing.getRemainingAdMs();
11068
11218
  var adPlaying = this.adPlayer.isAdPlaying();
11069
- var hasQueuedAds = this.adBreak.adRequestQueue.length > 0;
11070
11219
  if (this.debug) {
11071
11220
  console.log("[StormcloudVideoPlayer] SCTE-35 end marker received:", {
11072
11221
  remaining: remaining,
11073
11222
  adPlaying: adPlaying,
11074
- hasQueuedAds: hasQueuedAds,
11223
+ adSlotState: this.adBreak.getSlotState(),
11075
11224
  activeAdRequest: this.timing.activeAdRequestToken !== null
11076
11225
  });
11077
11226
  }
@@ -11082,7 +11231,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11082
11231
  this.adBreak.noteStopBeforeStart("scte_end");
11083
11232
  this.adPlayer.stop().catch(function() {});
11084
11233
  }
11085
- this.adBreak.handleAdPodComplete();
11234
+ this.adBreak.handleAdPodComplete("scte_end");
11086
11235
  return;
11087
11236
  }
11088
11237
  }
@@ -11090,6 +11239,15 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11090
11239
  {
11091
11240
  key: "startScte35AdBreak",
11092
11241
  value: function startScte35AdBreak(marker, cueKey, durationMs) {
11242
+ if (this.adBreak.isBreakActive()) {
11243
+ if (this.debug) {
11244
+ console.log("[StormcloudVideoPlayer] Ignoring SCTE-35 break start: a break is already active", {
11245
+ state: this.adBreak.getSlotState(),
11246
+ cueKey: cueKey
11247
+ });
11248
+ }
11249
+ return;
11250
+ }
11093
11251
  this.adBreak.inAdBreak = true;
11094
11252
  this.cueManager.activeScte35BreakKey = cueKey !== null && cueKey !== void 0 ? cueKey : this.cueManager.pendingScte35CueKey;
11095
11253
  this.cueManager.scheduledScte35BreakKey = void 0;
@@ -11122,7 +11280,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11122
11280
  this.adBreak.noteStopBeforeStart("break_boundary");
11123
11281
  this.adPlayer.stop().catch(function() {});
11124
11282
  }
11125
- this.adBreak.handleAdPodComplete();
11283
+ this.adBreak.handleAdPodComplete("break_boundary");
11126
11284
  }
11127
11285
  },
11128
11286
  {
@@ -11132,14 +11290,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11132
11290
  key: "startAdPrefetch",
11133
11291
  value: function startAdPrefetch(marker, fragmentSn, cueKey) {
11134
11292
  if (this.adBreak.pendingAdBreak || this.adBreak.inAdBreak) return;
11135
- var scheduled = this.adConfig.findCurrentOrNextBreak(this.video.currentTime * 1e3);
11136
- var tags = this.adConfig.selectVastTagsForBreak(scheduled);
11137
- var baseVastUrl;
11138
- if (tags && tags.length > 0 && tags[0]) {
11139
- baseVastUrl = tags[0];
11140
- } else if (this.adConfig.apiVastTagUrl) {
11141
- baseVastUrl = this.adConfig.apiVastTagUrl;
11142
- } else {
11293
+ var baseVastUrl = this.adConfig.apiVastTagUrl;
11294
+ if (!baseVastUrl) {
11143
11295
  if (this.debug) console.warn("[StormcloudVideoPlayer] No VAST URL available for prefetch");
11144
11296
  return;
11145
11297
  }
@@ -11169,8 +11321,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11169
11321
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
11170
11322
  }, detectPayload), buildAnalyticsContext(this.config)).catch(function() {});
11171
11323
  if (this.debug) {
11172
- console.log("[PREFETCH] Starting ad prefetch for upcoming ad break");
11173
- console.log("[PREFETCH] Pre-generated pod request URL");
11324
+ console.log("[PREFETCH] Pre-generated pod request URL for upcoming ad break");
11174
11325
  }
11175
11326
  }
11176
11327
  },
@@ -11181,7 +11332,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11181
11332
  key: "onTimeUpdate",
11182
11333
  value: function onTimeUpdate(currentTimeSec) {
11183
11334
  var _this = this;
11184
- if (!this.adConfig.isVmapEnabled() || this.adConfig.vmapBreaks.length === 0) return;
11335
+ if (this.adConfig.vmapBreaks.length === 0) return;
11185
11336
  if (this.adPlayer.isAdPlaying() || this.adBreak.inAdBreak) return;
11186
11337
  var nowMs = currentTimeSec * 1e3;
11187
11338
  var breakToPlay = this.adConfig.findBreakForTime(nowMs);
@@ -11198,7 +11349,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11198
11349
  key: "onVideoEnded",
11199
11350
  value: function onVideoEnded() {
11200
11351
  var _this = this;
11201
- if (!this.adConfig.isVmapEnabled() || this.adConfig.vmapBreaks.length === 0) return;
11352
+ if (this.adConfig.vmapBreaks.length === 0) return;
11202
11353
  if (this.adPlayer.isAdPlaying() || this.adBreak.inAdBreak) return;
11203
11354
  var durationMs = Number.isFinite(this.video.duration) ? Math.floor(this.video.duration * 1e3) : 0;
11204
11355
  var postroll = this.adConfig.vmapBreaks.find(function(b) {
@@ -11251,7 +11402,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11251
11402
  if (durationMs > 0) {
11252
11403
  this.timing.setAdBreakDurationBoundary(durationMs);
11253
11404
  }
11254
- this.adBreak.noteOpportunity("vmap", key);
11405
+ this.adBreak.beginVmapBreak(key);
11255
11406
  _state.label = 1;
11256
11407
  case 1:
11257
11408
  _state.trys.push([
@@ -11262,7 +11413,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11262
11413
  ]);
11263
11414
  return [
11264
11415
  4,
11265
- this.adBreak.playSingleAd(first)
11416
+ this.adBreak.playSingleAd(first, "vmap")
11266
11417
  ];
11267
11418
  case 2:
11268
11419
  _state.sent();
@@ -11275,7 +11426,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11275
11426
  if (this.debug) {
11276
11427
  console.warn("[StormcloudVideoPlayer] VMAP ad request failed:", error);
11277
11428
  }
11278
- this.adBreak.handleAdPodComplete();
11429
+ this.adBreak.continueAfterRequestFailure();
11279
11430
  return [
11280
11431
  3,
11281
11432
  4
@@ -11417,7 +11568,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11417
11568
  key: "destroy",
11418
11569
  value: function destroy() {
11419
11570
  var _this_adPlayer;
11420
- this.adBreak.stopContinuousFetching();
11571
+ this.adBreak.cancelScheduledRequest();
11421
11572
  this.timing.destroy();
11422
11573
  this.adBreak.clearPendingAdBreak();
11423
11574
  this.placeholder.destroy();
@@ -11441,7 +11592,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11441
11592
  this.palNonce.sendPlaybackEnd();
11442
11593
  }
11443
11594
  this.palNonce.reset();
11444
- this.adBreak.adRequestQueue = [];
11445
11595
  this.timing.consecutiveFailures = 0;
11446
11596
  }
11447
11597
  }
@@ -11524,7 +11674,7 @@ var CRITICAL_PROPS = [
11524
11674
  var CONTROLS_HIDE_DELAY = 3e3;
11525
11675
  var DEFAULT_PLAYER_ASPECT_RATIO = 16 / 9;
11526
11676
  var StormcloudVideoPlayerComponent = import_react.default.memo(function(props) {
11527
- var src = props.src, autoplay = props.autoplay, muted = props.muted, lowLatencyMode = props.lowLatencyMode, allowNativeHls = props.allowNativeHls, isLiveStream = props.isLiveStream, driftToleranceMs = props.driftToleranceMs, immediateManifestAds = props.immediateManifestAds, debugAdTiming = props.debugAdTiming, showCustomControls = props.showCustomControls, hideLoadingIndicator = props.hideLoadingIndicator, onVolumeToggle = props.onVolumeToggle, onFullscreenToggle = props.onFullscreenToggle, onControlClick = props.onControlClick, onReady = props.onReady, wrapperClassName = props.wrapperClassName, wrapperStyle = props.wrapperStyle, className = props.className, style = props.style, controls = props.controls, playsInline = props.playsInline, preload = props.preload, poster = props.poster, children = props.children, licenseKey = props.licenseKey, vastMode = props.vastMode, vastTagUrl = props.vastTagUrl, isVmap = props.isVmap, vmapUrl = props.vmapUrl, minSegmentsBeforePlay = props.minSegmentsBeforePlay, ctvAdRequest = props.ctvAdRequest, programTitle = props.programTitle, channelName = props.channelName, restVideoAttrs = _object_without_properties(props, [
11677
+ var src = props.src, autoplay = props.autoplay, muted = props.muted, lowLatencyMode = props.lowLatencyMode, allowNativeHls = props.allowNativeHls, isLiveStream = props.isLiveStream, driftToleranceMs = props.driftToleranceMs, immediateManifestAds = props.immediateManifestAds, debugAdTiming = props.debugAdTiming, showCustomControls = props.showCustomControls, hideLoadingIndicator = props.hideLoadingIndicator, onVolumeToggle = props.onVolumeToggle, onFullscreenToggle = props.onFullscreenToggle, onControlClick = props.onControlClick, onReady = props.onReady, wrapperClassName = props.wrapperClassName, wrapperStyle = props.wrapperStyle, className = props.className, style = props.style, controls = props.controls, playsInline = props.playsInline, preload = props.preload, poster = props.poster, children = props.children, licenseKey = props.licenseKey, vastMode = props.vastMode, vastTagUrl = props.vastTagUrl, isVmap = props.isVmap, vmapUrl = props.vmapUrl, minSegmentsBeforePlay = props.minSegmentsBeforePlay, ctvAdRequest = props.ctvAdRequest, programTitle = props.programTitle, channelName = props.channelName, minRemainingMsToStartAd = props.minRemainingMsToStartAd, minRemainingMsToRequestAd = props.minRemainingMsToRequestAd, maxNoFillsPerBreak = props.maxNoFillsPerBreak, restVideoAttrs = _object_without_properties(props, [
11528
11678
  "src",
11529
11679
  "autoplay",
11530
11680
  "muted",
@@ -11557,7 +11707,10 @@ var StormcloudVideoPlayerComponent = import_react.default.memo(function(props) {
11557
11707
  "minSegmentsBeforePlay",
11558
11708
  "ctvAdRequest",
11559
11709
  "programTitle",
11560
- "channelName"
11710
+ "channelName",
11711
+ "minRemainingMsToStartAd",
11712
+ "minRemainingMsToRequestAd",
11713
+ "maxNoFillsPerBreak"
11561
11714
  ]);
11562
11715
  var videoRef = (0, import_react.useRef)(null);
11563
11716
  var playerRef = (0, import_react.useRef)(null);
@@ -11750,6 +11903,9 @@ var StormcloudVideoPlayerComponent = import_react.default.memo(function(props) {
11750
11903
  if (ctvAdRequest !== void 0) cfg.ctvAdRequest = ctvAdRequest;
11751
11904
  if (programTitle !== void 0) cfg.programTitle = programTitle;
11752
11905
  if (channelName !== void 0) cfg.channelName = channelName;
11906
+ if (minRemainingMsToStartAd !== void 0) cfg.minRemainingMsToStartAd = minRemainingMsToStartAd;
11907
+ if (minRemainingMsToRequestAd !== void 0) cfg.minRemainingMsToRequestAd = minRemainingMsToRequestAd;
11908
+ if (maxNoFillsPerBreak !== void 0) cfg.maxNoFillsPerBreak = maxNoFillsPerBreak;
11753
11909
  var player = new StormcloudVideoPlayer(cfg);
11754
11910
  playerRef.current = player;
11755
11911
  player.load().then(function() {