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.
@@ -284,26 +284,6 @@ function _ts_generator(thisArg, body) {
284
284
  };
285
285
  }
286
286
  }
287
- function _ts_values(o) {
288
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
289
- if (m) {
290
- return m.call(o);
291
- }
292
- if (o && typeof o.length === "number") {
293
- return {
294
- next: function() {
295
- if (o && i >= o.length) {
296
- o = void 0;
297
- }
298
- return {
299
- value: o && o[i++],
300
- done: !o
301
- };
302
- }
303
- };
304
- }
305
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
306
- }
307
287
  function _type_of(obj) {
308
288
  "@swc/helpers - typeof";
309
289
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
@@ -795,6 +775,8 @@ function createHlsAdPlayer(contentVideo, options) {
795
775
  var pendingPlayPromise;
796
776
  var currentVastTagUrl;
797
777
  var funnelContext = {};
778
+ var mediaProbe;
779
+ var lastPodAdElementCount = 0;
798
780
  var mediaCandidates = [];
799
781
  var mediaCandidateIndex = 0;
800
782
  var mediaStartTimerId;
@@ -912,6 +894,7 @@ function createHlsAdPlayer(contentVideo, options) {
912
894
  stage: stage,
913
895
  breakId: funnelContext.breakId,
914
896
  requestId: funnelContext.requestId,
897
+ controllerId: funnelContext.controllerId,
915
898
  visibilityState: typeof document !== "undefined" ? document.visibilityState : void 0,
916
899
  adId: currentAd === null || currentAd === void 0 ? void 0 : currentAd.id,
917
900
  podIndex: podIndex,
@@ -1101,7 +1084,6 @@ function createHlsAdPlayer(contentVideo, options) {
1101
1084
  });
1102
1085
  logFunnel("media_candidate", _object_spread_props(_object_spread({}, details), {
1103
1086
  reason: "accepted",
1104
- // Mixed-content media is often auto-upgraded, so it is kept as a last resort.
1105
1087
  why: insecure ? "insecure_http_deprioritized" : "playable",
1106
1088
  score: score
1107
1089
  }));
@@ -1129,6 +1111,145 @@ function createHlsAdPlayer(contentVideo, options) {
1129
1111
  var url = (mediaFile.url.toLowerCase().split("?")[0] || "").trim();
1130
1112
  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");
1131
1113
  }
1114
+ function getMediaProbe() {
1115
+ if (adVideoElement) return adVideoElement;
1116
+ if (!mediaProbe && typeof document !== "undefined") {
1117
+ mediaProbe = document.createElement("video");
1118
+ }
1119
+ return mediaProbe;
1120
+ }
1121
+ function evaluateMediaFile(mf) {
1122
+ var _mf_textContent;
1123
+ var type = mf.getAttribute("type") || "";
1124
+ var url = ((_mf_textContent = mf.textContent) === null || _mf_textContent === void 0 ? void 0 : _mf_textContent.trim()) || "";
1125
+ var delivery = mf.getAttribute("delivery") || void 0;
1126
+ var codec = mf.getAttribute("codec") || void 0;
1127
+ if (!url) {
1128
+ return {
1129
+ category: "missing_media",
1130
+ whyRejected: "empty_url",
1131
+ canPlayType: ""
1132
+ };
1133
+ }
1134
+ var apiFramework = (mf.getAttribute("apiFramework") || "").toUpperCase();
1135
+ if (apiFramework === "VPAID") {
1136
+ return {
1137
+ category: "vpaid",
1138
+ whyRejected: "vpaid_not_supported",
1139
+ canPlayType: ""
1140
+ };
1141
+ }
1142
+ try {
1143
+ var protocol = new URL(url).protocol;
1144
+ if (protocol !== "https:" && protocol !== "http:") {
1145
+ return {
1146
+ category: "invalid_url",
1147
+ whyRejected: "protocol_".concat(protocol),
1148
+ canPlayType: ""
1149
+ };
1150
+ }
1151
+ } catch (unused) {
1152
+ return {
1153
+ category: "invalid_url",
1154
+ whyRejected: "unparseable_url",
1155
+ canPlayType: ""
1156
+ };
1157
+ }
1158
+ var bitrateAttr = mf.getAttribute("bitrate");
1159
+ var bitrateValue = bitrateAttr ? parseInt(bitrateAttr, 10) : void 0;
1160
+ var file = {
1161
+ url: url,
1162
+ type: type,
1163
+ width: parseInt(mf.getAttribute("width") || "1920", 10),
1164
+ height: parseInt(mf.getAttribute("height") || "1080", 10),
1165
+ bitrate: bitrateValue && bitrateValue > 0 ? bitrateValue : void 0,
1166
+ delivery: delivery,
1167
+ codec: codec
1168
+ };
1169
+ if (isAudioMediaFile(file)) {
1170
+ return {
1171
+ category: "audio_only",
1172
+ whyRejected: type.toLowerCase().startsWith("audio/") ? "audio_mime" : "audio_extension",
1173
+ canPlayType: ""
1174
+ };
1175
+ }
1176
+ var isHls = isHlsMediaFile(file);
1177
+ var hasExplicitDimensions = mf.getAttribute("width") != null && mf.getAttribute("height") != null;
1178
+ if (!isHls && hasExplicitDimensions && (file.width <= 1 || file.height <= 1)) {
1179
+ return {
1180
+ category: "audio_only",
1181
+ whyRejected: "zero_dimensions",
1182
+ canPlayType: ""
1183
+ };
1184
+ }
1185
+ var probe = getMediaProbe();
1186
+ if (isHls) {
1187
+ var _ref;
1188
+ var nativeHls = (_ref = probe === null || probe === void 0 ? void 0 : probe.canPlayType("application/vnd.apple.mpegurl")) !== null && _ref !== void 0 ? _ref : "";
1189
+ if (import_hls.default.isSupported()) {
1190
+ return {
1191
+ file: file,
1192
+ whyAccepted: "hls_js",
1193
+ canPlayType: nativeHls
1194
+ };
1195
+ }
1196
+ if (nativeHls !== "") {
1197
+ return {
1198
+ file: file,
1199
+ whyAccepted: "native_hls",
1200
+ canPlayType: nativeHls
1201
+ };
1202
+ }
1203
+ return {
1204
+ category: "unsupported_hls",
1205
+ whyRejected: "no_hls_support",
1206
+ canPlayType: nativeHls
1207
+ };
1208
+ }
1209
+ if (!isProgressiveMediaFile(file)) {
1210
+ return {
1211
+ category: "unsupported_mime",
1212
+ whyRejected: "not_a_video_mime",
1213
+ canPlayType: ""
1214
+ };
1215
+ }
1216
+ if (!probe) {
1217
+ return {
1218
+ file: file,
1219
+ whyAccepted: "no_probe_available",
1220
+ canPlayType: ""
1221
+ };
1222
+ }
1223
+ var baseType = type || "video/mp4";
1224
+ var canPlay = probe.canPlayType(baseType);
1225
+ if (canPlay === "") {
1226
+ return {
1227
+ category: "unsupported_mime",
1228
+ whyRejected: "canPlayType_empty",
1229
+ canPlayType: canPlay
1230
+ };
1231
+ }
1232
+ if (codec) {
1233
+ var withCodec = probe.canPlayType("".concat(baseType, '; codecs="').concat(codec, '"'));
1234
+ if (withCodec === "") {
1235
+ return {
1236
+ category: "unsupported_codec",
1237
+ whyRejected: "codec_canPlayType_empty",
1238
+ canPlayType: withCodec
1239
+ };
1240
+ }
1241
+ return {
1242
+ file: file,
1243
+ whyAccepted: "canPlayType_".concat(withCodec),
1244
+ canPlayType: withCodec
1245
+ };
1246
+ }
1247
+ return {
1248
+ file: file,
1249
+ whyAccepted: "canPlayType_".concat(canPlay),
1250
+ canPlayType: canPlay
1251
+ };
1252
+ }
1132
1253
  function collectVideoMediaFiles(linear, verbose, stats) {
1133
1254
  var mediaFileElements = linear.querySelectorAll(":scope > MediaFiles > MediaFile");
1134
1255
  var mediaFiles = [];
@@ -1138,57 +1259,33 @@ function createHlsAdPlayer(contentVideo, options) {
1138
1259
  }
1139
1260
  mediaFileElements.forEach(function(mf, index) {
1140
1261
  var _mf_textContent;
1141
- var type = mf.getAttribute("type") || "";
1262
+ var result = evaluateMediaFile(mf);
1142
1263
  var url = ((_mf_textContent = mf.textContent) === null || _mf_textContent === void 0 ? void 0 : _mf_textContent.trim()) || "";
1143
- var width = mf.getAttribute("width") || "";
1144
- var height = mf.getAttribute("height") || "";
1145
- if (verbose) {
1146
- console.log("[HlsAdPlayer] MediaFile ".concat(index, ': type="').concat(type, '", url="').concat(url, '", width="').concat(width, '", height="').concat(height, '"'));
1147
- }
1148
- if (!url) {
1149
- if (verbose) {
1150
- console.warn("[HlsAdPlayer] MediaFile ".concat(index, " has empty URL"));
1151
- }
1152
- return;
1153
- }
1154
- var apiFramework = (mf.getAttribute("apiFramework") || "").toUpperCase();
1155
- if (apiFramework === "VPAID") {
1156
- if (stats) stats.vpaid++;
1157
- if (verbose) {
1158
- console.log("[HlsAdPlayer] MediaFile ".concat(index, " ignored (VPAID creatives are not supported)"));
1159
- }
1160
- return;
1161
- }
1162
- var bitrateAttr = mf.getAttribute("bitrate");
1163
- var bitrateValue = bitrateAttr ? parseInt(bitrateAttr, 10) : void 0;
1164
- var mediaFile = {
1165
- url: url,
1166
- type: type,
1167
- width: parseInt(width || "1920", 10),
1168
- height: parseInt(height || "1080", 10),
1169
- bitrate: bitrateValue && bitrateValue > 0 ? bitrateValue : void 0
1170
- };
1171
- if (isAudioMediaFile(mediaFile)) {
1172
- if (stats) stats.audio++;
1173
- console.warn("[HlsAdPlayer] MediaFile ".concat(index, ' skipped (audio-only, type="').concat(type, '") — audio ads are not played to avoid a black screen'));
1264
+ var accepted = "file" in result;
1265
+ logFunnel("mediafile_evaluated", {
1266
+ reason: accepted ? "accepted" : result.category,
1267
+ index: index,
1268
+ type: mf.getAttribute("type") || "",
1269
+ delivery: mf.getAttribute("delivery") || void 0,
1270
+ codec: mf.getAttribute("codec") || void 0,
1271
+ apiFramework: mf.getAttribute("apiFramework") || void 0,
1272
+ width: mf.getAttribute("width"),
1273
+ height: mf.getAttribute("height"),
1274
+ fileUrl: redactUrl(url),
1275
+ canPlayType: result.canPlayType,
1276
+ whyAccepted: accepted ? result.whyAccepted : void 0,
1277
+ whyRejected: accepted ? void 0 : result.whyRejected
1278
+ });
1279
+ if ("file" in result) {
1280
+ mediaFiles.push(result.file);
1174
1281
  return;
1175
1282
  }
1176
- var hasExplicitDimensions = mf.getAttribute("width") != null && mf.getAttribute("height") != null;
1177
- if (!isHlsMediaFile(mediaFile) && hasExplicitDimensions && (mediaFile.width <= 1 || mediaFile.height <= 1)) {
1178
- if (stats) stats.audio++;
1179
- 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'));
1180
- return;
1283
+ if (stats) {
1284
+ var _stats_categories_result_category;
1285
+ 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;
1181
1286
  }
1182
- if (isHlsMediaFile(mediaFile) || isProgressiveMediaFile(mediaFile)) {
1183
- mediaFiles.push(mediaFile);
1184
- if (verbose) {
1185
- console.log("[HlsAdPlayer] Added ".concat(isHlsMediaFile(mediaFile) ? "HLS" : "progressive", " MediaFile: ").concat(url));
1186
- }
1187
- } else {
1188
- if (stats) stats.unsupported++;
1189
- if (verbose) {
1190
- console.log("[HlsAdPlayer] MediaFile ".concat(index, ' ignored (type="').concat(type, '" is not supported)'));
1191
- }
1287
+ if (result.category === "audio_only") {
1288
+ 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'));
1192
1289
  }
1193
1290
  });
1194
1291
  return mediaFiles;
@@ -1410,7 +1507,7 @@ function createHlsAdPlayer(contentVideo, options) {
1410
1507
  if (adElement.getAttribute("conditionalAd") === "true") {
1411
1508
  console.warn("[HlsAdPlayer] Skipping conditional <Ad> (VPAID-only)");
1412
1509
  logFunnel("vast_no_supported_media", {
1413
- reason: "vpaid_only",
1510
+ reason: "vpaid",
1414
1511
  conditionalAd: true
1415
1512
  });
1416
1513
  return {
@@ -1423,9 +1520,7 @@ function createHlsAdPlayer(contentVideo, options) {
1423
1520
  var mediaFiles = [];
1424
1521
  var rejectStats = {
1425
1522
  total: 0,
1426
- vpaid: 0,
1427
- audio: 0,
1428
- unsupported: 0
1523
+ categories: {}
1429
1524
  };
1430
1525
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1431
1526
  try {
@@ -1454,10 +1549,39 @@ function createHlsAdPlayer(contentVideo, options) {
1454
1549
  }
1455
1550
  if (!linear) {
1456
1551
  console.warn("[HlsAdPlayer] No supported linear media files in <Ad>");
1457
- var reason = rejectStats.total === 0 ? "no_mediafiles" : rejectStats.vpaid > 0 ? "vpaid_only" : rejectStats.audio > 0 ? "audio_only" : "unsupported_type";
1458
- logFunnel("vast_no_supported_media", _object_spread({
1459
- reason: reason
1460
- }, rejectStats));
1552
+ var reason = "missing_media";
1553
+ var top = 0;
1554
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
1555
+ try {
1556
+ for(var _iterator1 = Object.keys(rejectStats.categories)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
1557
+ var category = _step1.value;
1558
+ var _rejectStats_categories_category;
1559
+ var count = (_rejectStats_categories_category = rejectStats.categories[category]) !== null && _rejectStats_categories_category !== void 0 ? _rejectStats_categories_category : 0;
1560
+ if (count > top) {
1561
+ top = count;
1562
+ reason = category;
1563
+ }
1564
+ }
1565
+ } catch (err) {
1566
+ _didIteratorError1 = true;
1567
+ _iteratorError1 = err;
1568
+ } finally{
1569
+ try {
1570
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
1571
+ _iterator1.return();
1572
+ }
1573
+ } finally{
1574
+ if (_didIteratorError1) {
1575
+ throw _iteratorError1;
1576
+ }
1577
+ }
1578
+ }
1579
+ if (rejectStats.total > 0 && top === 0) reason = "other";
1580
+ logFunnel("vast_no_supported_media", {
1581
+ reason: reason,
1582
+ mediaFileCount: rejectStats.total,
1583
+ rejectedByCategory: rejectStats.categories
1584
+ });
1461
1585
  return {
1462
1586
  type: "empty",
1463
1587
  errorUrls: errorUrls,
@@ -1487,9 +1611,9 @@ function createHlsAdPlayer(contentVideo, options) {
1487
1611
  }
1488
1612
  }
1489
1613
  function fetchVastXml(vastTagUrl) {
1490
- var credentials = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "include";
1614
+ var credentials = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "include", kind = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "gam";
1491
1615
  return _async_to_generator(function() {
1492
- var controller, timeoutId, requestVast, response, error, error1;
1616
+ var controller, timeoutId, startedAt, attempt, requestVast, response, error, error1;
1493
1617
  return _ts_generator(this, function(_state) {
1494
1618
  switch(_state.label){
1495
1619
  case 0:
@@ -1501,17 +1625,51 @@ function createHlsAdPlayer(contentVideo, options) {
1501
1625
  timeoutId = controller ? setTimeout(function() {
1502
1626
  return controller.abort();
1503
1627
  }, VAST_REQUEST_TIMEOUT_MS) : void 0;
1628
+ startedAt = Date.now();
1629
+ attempt = 0;
1504
1630
  requestVast = function requestVast(creds) {
1505
- return fetch(vastTagUrl, _object_spread({
1506
- mode: "cors",
1507
- credentials: creds,
1508
- headers: {
1509
- "Accept": "application/xml, text/xml, */*"
1510
- },
1511
- referrerPolicy: "no-referrer-when-downgrade"
1512
- }, controller ? {
1513
- signal: controller.signal
1514
- } : {}));
1631
+ return _async_to_generator(function() {
1632
+ var response;
1633
+ return _ts_generator(this, function(_state) {
1634
+ switch(_state.label){
1635
+ case 0:
1636
+ attempt++;
1637
+ if (kind === "gam") {
1638
+ logFunnel("gam_http_request_sent", {
1639
+ attempt: attempt,
1640
+ credentials: creds
1641
+ });
1642
+ }
1643
+ return [
1644
+ 4,
1645
+ fetch(vastTagUrl, _object_spread({
1646
+ mode: "cors",
1647
+ credentials: creds,
1648
+ headers: {
1649
+ "Accept": "application/xml, text/xml, */*"
1650
+ },
1651
+ referrerPolicy: "no-referrer-when-downgrade"
1652
+ }, controller ? {
1653
+ signal: controller.signal
1654
+ } : {}))
1655
+ ];
1656
+ case 1:
1657
+ response = _state.sent();
1658
+ if (kind === "gam") {
1659
+ logFunnel("gam_response_received", {
1660
+ attempt: attempt,
1661
+ httpStatus: response.status,
1662
+ ok: response.ok,
1663
+ elapsedMs: Date.now() - startedAt
1664
+ });
1665
+ }
1666
+ return [
1667
+ 2,
1668
+ response
1669
+ ];
1670
+ }
1671
+ });
1672
+ })();
1515
1673
  };
1516
1674
  _state.label = 1;
1517
1675
  case 1:
@@ -1568,7 +1726,7 @@ function createHlsAdPlayer(contentVideo, options) {
1568
1726
  ];
1569
1727
  case 8:
1570
1728
  if (!response.ok) {
1571
- throw new Error("Failed to fetch VAST: ".concat(response.statusText));
1729
+ throw new Error("Failed to fetch VAST: HTTP ".concat(response.status, " ").concat(response.statusText));
1572
1730
  }
1573
1731
  return [
1574
1732
  4,
@@ -1583,7 +1741,7 @@ function createHlsAdPlayer(contentVideo, options) {
1583
1741
  error1 = _state.sent();
1584
1742
  if (controller === null || controller === void 0 ? void 0 : controller.signal.aborted) {
1585
1743
  if (pendingRequestAbortReason) {
1586
- throw new Error("".concat(pendingRequestAbortReason, " (timeout): ").concat(vastTagUrl));
1744
+ throw new Error("".concat(pendingRequestAbortReason, ": ").concat(vastTagUrl));
1587
1745
  }
1588
1746
  throw new Error("VAST request timeout after ".concat(VAST_REQUEST_TIMEOUT_MS, "ms: ").concat(vastTagUrl));
1589
1747
  }
@@ -1627,7 +1785,7 @@ function createHlsAdPlayer(contentVideo, options) {
1627
1785
  ]);
1628
1786
  return [
1629
1787
  4,
1630
- fetchVastXml(vastTagUrl, depth === 0 ? "include" : "omit")
1788
+ fetchVastXml(vastTagUrl, depth === 0 ? "include" : "omit", depth === 0 ? "gam" : "wrapper")
1631
1789
  ];
1632
1790
  case 2:
1633
1791
  vastXml = _state.sent();
@@ -1712,10 +1870,11 @@ function createHlsAdPlayer(contentVideo, options) {
1712
1870
  }
1713
1871
  function fetchAndParsePod(vastTagUrl) {
1714
1872
  return _async_to_generator(function() {
1715
- 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;
1873
+ 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;
1716
1874
  return _ts_generator(this, function(_state) {
1717
1875
  switch(_state.label){
1718
1876
  case 0:
1877
+ lastPodAdElementCount = 0;
1719
1878
  return [
1720
1879
  4,
1721
1880
  fetchVastXml(vastTagUrl)
@@ -1730,6 +1889,10 @@ function createHlsAdPlayer(contentVideo, options) {
1730
1889
  trimmedXml = vastXml.trim();
1731
1890
  if (trimmedXml.length === 0) {
1732
1891
  console.warn("[HlsAdPlayer] Pod VAST response body is empty (no fill)");
1892
+ logFunnel("vast_parsed", {
1893
+ adElementCount: 0,
1894
+ reason: "empty_body"
1895
+ });
1733
1896
  return [
1734
1897
  2,
1735
1898
  []
@@ -1738,6 +1901,10 @@ function createHlsAdPlayer(contentVideo, options) {
1738
1901
  xmlDoc = parseXml(vastXml);
1739
1902
  if (!xmlDoc) {
1740
1903
  console.error("[HlsAdPlayer] Pod VAST XML content (first 2000 chars):", vastXml.substring(0, 2e3));
1904
+ logFunnel("vast_parsed", {
1905
+ adElementCount: 0,
1906
+ reason: "xml_parse_error"
1907
+ });
1741
1908
  return [
1742
1909
  2,
1743
1910
  []
@@ -1745,10 +1912,21 @@ function createHlsAdPlayer(contentVideo, options) {
1745
1912
  }
1746
1913
  root = xmlDoc.documentElement;
1747
1914
  adElements = Array.from(root.querySelectorAll(":scope > Ad"));
1915
+ logFunnel("vast_parsed", {
1916
+ reason: adElements.length > 0 ? "has_ads" : "no_ads",
1917
+ vastVersion: (_root_getAttribute = root.getAttribute("version")) !== null && _root_getAttribute !== void 0 ? _root_getAttribute : void 0,
1918
+ adElementCount: adElements.length,
1919
+ inlineCount: adElements.filter(function(el) {
1920
+ return el.querySelector(":scope > InLine");
1921
+ }).length,
1922
+ wrapperCount: adElements.filter(function(el) {
1923
+ return el.querySelector(":scope > Wrapper");
1924
+ }).length
1925
+ });
1748
1926
  if (adElements.length === 0) {
1749
1927
  ;
1750
1928
  ;
1751
- 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)"));
1929
+ 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)"));
1752
1930
  empty = emptyVastResult(root);
1753
1931
  if (empty.type === "empty" && ((_empty_errorUrls = empty.errorUrls) === null || _empty_errorUrls === void 0 ? void 0 : _empty_errorUrls.length)) {
1754
1932
  ;
@@ -1766,10 +1944,15 @@ function createHlsAdPlayer(contentVideo, options) {
1766
1944
  var _parsed_errorUrls, parsed, _parsed_errorCode;
1767
1945
  return _ts_generator(this, function(_state) {
1768
1946
  parsed = parseAdElement(adElement);
1769
- if (parsed.type === "inline") return [
1770
- 2,
1771
- parsed.ad
1772
- ];
1947
+ if (parsed.type === "inline") {
1948
+ logFunnel("inline_resolved", {
1949
+ depth: 0
1950
+ });
1951
+ return [
1952
+ 2,
1953
+ parsed.ad
1954
+ ];
1955
+ }
1773
1956
  if (parsed.type === "wrapper") {
1774
1957
  return [
1775
1958
  2,
@@ -1947,7 +2130,8 @@ function createHlsAdPlayer(contentVideo, options) {
1947
2130
  7
1948
2131
  ];
1949
2132
  case 21:
1950
- 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"));
2133
+ 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"));
2134
+ lastPodAdElementCount = adElements.length;
1951
2135
  return [
1952
2136
  2,
1953
2137
  ads
@@ -3017,6 +3201,17 @@ function createHlsAdPlayer(contentVideo, options) {
3017
3201
  if (!ads.length && pendingRequestAbortReason) {
3018
3202
  throw new Error(pendingRequestAbortReason);
3019
3203
  }
3204
+ if (!ads.length && lastPodAdElementCount > 0) {
3205
+ console.warn("[HlsAdPlayer] VAST response had ads but none were playable");
3206
+ logFunnel("vast_fill_rejected", {
3207
+ adElementCount: lastPodAdElementCount
3208
+ });
3209
+ emit("ad_error");
3210
+ return [
3211
+ 2,
3212
+ Promise.reject(new Error("VAST fill rejected: no playable ad in response"))
3213
+ ];
3214
+ }
3020
3215
  if (!ads.length) {
3021
3216
  console.warn("[HlsAdPlayer] No ads available from VAST response");
3022
3217
  logFunnel("no_fill");
@@ -5450,6 +5645,21 @@ function normalizeVastTagUrl(raw) {
5450
5645
  return raw;
5451
5646
  }
5452
5647
  }
5648
+ var GAM_AD_HOSTS = /* @__PURE__ */ new Set([
5649
+ "pubads.g.doubleclick.net",
5650
+ "securepubads.g.doubleclick.net"
5651
+ ]);
5652
+ function ensureVideoAdType(rawUrl) {
5653
+ try {
5654
+ var url = new URL(rawUrl);
5655
+ if (!GAM_AD_HOSTS.has(url.hostname)) return rawUrl;
5656
+ if (url.searchParams.has("ad_type")) return rawUrl;
5657
+ url.searchParams.set("ad_type", "video");
5658
+ return url.toString();
5659
+ } catch (unused) {
5660
+ return rawUrl;
5661
+ }
5662
+ }
5453
5663
  function applyVastMacros(baseUrl, ctx) {
5454
5664
  var expandedUrl = expandInlineMacroPlaceholders(baseUrl, ctx);
5455
5665
  var url;
@@ -7160,7 +7370,7 @@ var AdConfigManager = /*#__PURE__*/ function() {
7160
7370
  } : {}), {
7161
7371
  consent: this.consentSignals
7162
7372
  }));
7163
- var finalUrl = palNonce.injectNonce(urlWithMacros);
7373
+ var finalUrl = palNonce.injectNonce(ensureVideoAdType(urlWithMacros));
7164
7374
  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);
7165
7375
  return finalUrl;
7166
7376
  }
@@ -8649,6 +8859,18 @@ function resizePlayer(video, adPlayer, debug) {
8649
8859
  }
8650
8860
  }
8651
8861
  // src/player/AdBreakOrchestrator.ts
8862
+ var REQUEST_FAILURE_STAGES = /* @__PURE__ */ new Set([
8863
+ "no_fill",
8864
+ "vast_fill_rejected",
8865
+ "request_failed",
8866
+ "media_unsupported",
8867
+ "play_failed",
8868
+ "play_resolved_but_never_started",
8869
+ "hls_fatal",
8870
+ "media_error",
8871
+ "stall",
8872
+ "decode_failure"
8873
+ ]);
8652
8874
  var AdBreakOrchestrator = /*#__PURE__*/ function() {
8653
8875
  function AdBreakOrchestrator(host, timing, adConfig, cueManager, placeholder) {
8654
8876
  _class_call_check(this, AdBreakOrchestrator);
@@ -8656,15 +8878,17 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8656
8878
  this.showAds = false;
8657
8879
  this.isShowingPlaceholder = false;
8658
8880
  this.adDetectSentForCurrentBreak = false;
8659
- this.continuousFetchingActive = false;
8660
- this.continuousFetchLoopRunning = false;
8881
+ this.slotState = "IDLE";
8882
+ this.unusableResponsesInBreak = 0;
8883
+ this.controllerGeneration = 0;
8884
+ this.requestDiagnostics = /* @__PURE__ */ new Map();
8661
8885
  this.breakFunnel = {};
8662
8886
  this.controllerCallInFlight = false;
8663
8887
  this.playbackStartedForCurrentRequest = false;
8664
8888
  this.opportunityEpoch = -1;
8665
- this.adRequestQueue = [];
8666
8889
  this.adPodQueue = [];
8667
- this.maxPlaceholderDurationMs = 5e3;
8890
+ this.defaultMinRemainingMsToRequestAd = 1e4;
8891
+ this.defaultMaxNoFillsPerBreak = 2;
8668
8892
  this.pendingAdBreak = null;
8669
8893
  this.host = host;
8670
8894
  this.timing = timing;
@@ -8700,7 +8924,23 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8700
8924
  key: "attachImaEventListeners",
8701
8925
  value: function attachImaEventListeners() {
8702
8926
  var _this = this;
8703
- var adPlayer = this.host.getAdPlayer();
8927
+ var controller = this.host.getAdPlayer();
8928
+ var generation = this.controllerGeneration;
8929
+ var adPlayer = {
8930
+ on: function on(event, handler) {
8931
+ controller.on(event, function(payload) {
8932
+ if (generation !== _this.controllerGeneration) {
8933
+ _this.logOrchestratorFunnel("stale_callback_ignored", {
8934
+ event: event,
8935
+ staleControllerId: generation,
8936
+ currentControllerId: _this.controllerGeneration
8937
+ });
8938
+ return;
8939
+ }
8940
+ handler(payload);
8941
+ });
8942
+ }
8943
+ };
8704
8944
  adPlayer.on("pod_ad_started", function(payload) {
8705
8945
  _this.timing.notePodAdStarted();
8706
8946
  if (_this.debug) {
@@ -8716,19 +8956,29 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8716
8956
  });
8717
8957
  adPlayer.on("ad_funnel", function(payload) {
8718
8958
  if (!(payload === null || payload === void 0 ? void 0 : payload.stage)) return;
8719
- _this.countFunnelStage(payload.stage);
8959
+ var stage = payload.stage;
8960
+ _this.countFunnelStage(stage);
8720
8961
  if (payload.reason) {
8721
- _this.countFunnelStage("".concat(payload.stage, ":").concat(payload.reason));
8962
+ _this.countFunnelStage("".concat(stage, ":").concat(payload.reason));
8722
8963
  }
8723
- if (payload.stage === "impression_fired" && payload.pixelCount != null) {
8964
+ if (stage === "impression_fired" && payload.pixelCount != null) {
8724
8965
  _this.countFunnelStage("impression_urls", payload.pixelCount);
8725
8966
  }
8726
8967
  if (payload.visibilityState === "hidden") {
8727
8968
  _this.countFunnelStage("while_hidden");
8728
8969
  }
8970
+ if (stage === "gam_http_request_sent") {
8971
+ if (payload.attempt === 1) {
8972
+ _this.timing.noteAdRequestSent();
8973
+ } else {
8974
+ _this.countFunnelStage("gam_http_request_retry");
8975
+ }
8976
+ }
8977
+ _this.recordRequestDiagnostic(payload);
8729
8978
  });
8730
8979
  adPlayer.on("ad_impression", function() {
8731
8980
  _this.timing.consecutiveFailures = 0;
8981
+ _this.setSlotState("PLAYING", "impression");
8732
8982
  if (!_this.playbackStartedForCurrentRequest) {
8733
8983
  _this.playbackStartedForCurrentRequest = true;
8734
8984
  _this.timing.markAdStarted();
@@ -8747,16 +8997,11 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8747
8997
  var remaining = _this.timing.getRemainingAdMs();
8748
8998
  _this.timing.consecutiveFailures = 0;
8749
8999
  if (_this.debug) {
8750
- console.log("[StormcloudVideoPlayer] all_ads_completed event received - remaining=".concat(remaining, "ms, queued ads=").concat(_this.adRequestQueue.length), _this.adRequestQueue.length > 0 ? {
8751
- queuedUrls: _to_consumable_array(_this.adRequestQueue)
8752
- } : {});
9000
+ console.log("[StormcloudVideoPlayer] all_ads_completed event received - remaining=".concat(remaining, "ms"));
8753
9001
  }
8754
9002
  if (_this.inAdBreak) {
8755
- if (_this.timing.hasTimeToStartAnotherAd()) {
8756
- _this.tryNextAvailableAdWithRateLimit();
8757
- } else {
8758
- _this.handleAdPodComplete();
8759
- }
9003
+ _this.setSlotState("NEEDS_NEXT_AD", "all_ads_completed");
9004
+ _this.requestNextAd("all_ads_completed");
8760
9005
  }
8761
9006
  });
8762
9007
  adPlayer.on("ad_error", function(errorPayload) {
@@ -8777,10 +9022,9 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8777
9022
  }
8778
9023
  console.error("[AD-ERROR]", errorMessage, errorPayload || "");
8779
9024
  if (_this.controllerCallInFlight) {
8780
- _this.timing.recordGamNoFill();
8781
9025
  return;
8782
9026
  }
8783
- _this.handleAdFailure();
9027
+ _this.handleAdFailure("ad_error");
8784
9028
  });
8785
9029
  adPlayer.on("content_pause", function() {
8786
9030
  _this.timing.clearAdFailsafeTimer();
@@ -8819,26 +9063,32 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8819
9063
  }
8820
9064
  _this.timing.consecutiveFailures = 0;
8821
9065
  _this.timing.recordPlayedAdDuration(_this.host.getAdPlayer());
8822
- var remaining = _this.timing.getRemainingAdMs();
8823
9066
  if (_this.debug) {
8824
- console.log("[CONTINUOUS-FETCH] content_resume event: remaining=".concat(remaining, "ms, queued ads=").concat(_this.adRequestQueue.length), _this.adRequestQueue.length > 0 ? {
8825
- queuedUrls: _to_consumable_array(_this.adRequestQueue)
8826
- } : {});
8827
- }
8828
- if (_this.timing.hasTimeToStartAnotherAd()) {
8829
- _this.tryNextAvailableAdWithRateLimit();
8830
- } else {
8831
- _this.handleAdPodComplete();
9067
+ console.log("[AdBreak] content_resume: remaining=".concat(_this.timing.getRemainingAdMs(), "ms"));
8832
9068
  }
9069
+ _this.setSlotState("NEEDS_NEXT_AD", "ad_complete");
9070
+ _this.requestNextAd("ad_complete");
8833
9071
  });
8834
9072
  }
8835
9073
  },
8836
9074
  {
8837
9075
  key: "recreateAdController",
8838
- value: function recreateAdController() {
8839
- if (this.debug) {
8840
- console.log("[StormcloudVideoPlayer] Recreating AdController for new ad");
9076
+ value: function recreateAdController(reason) {
9077
+ if (reason === "new_request" && (this.slotState === "REQUESTING" || this.slotState === "READY")) {
9078
+ console.warn("[AD-CONTROLLER] destroy during active request", {
9079
+ controllerId: this.controllerGeneration,
9080
+ requestId: this.currentRequestId,
9081
+ state: this.slotState,
9082
+ reason: reason
9083
+ });
8841
9084
  }
9085
+ console.log("[AD-CONTROLLER] destroy", {
9086
+ controllerId: this.controllerGeneration,
9087
+ requestId: this.currentRequestId,
9088
+ state: this.slotState,
9089
+ reason: reason
9090
+ });
9091
+ this.countFunnelStage("controller_destroy:".concat(reason));
8842
9092
  var shouldShowPlaceholder = this.inAdBreak && this.showAds;
8843
9093
  var adPlayer = this.host.getAdPlayer();
8844
9094
  if (shouldShowPlaceholder && adPlayer) {
@@ -8865,9 +9115,16 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8865
9115
  var continueLiveStreamDuringAds = this.host.shouldContinueLiveStreamDuringAds();
8866
9116
  var newAdPlayer = this.host.createAdPlayer(continueLiveStreamDuringAds);
8867
9117
  this.host.setAdPlayer(newAdPlayer);
9118
+ this.controllerGeneration++;
8868
9119
  newAdPlayer.initialize();
8869
9120
  newAdPlayer.updateOriginalMutedState(preservedMutedState, preservedVolumeState);
8870
9121
  this.attachImaEventListeners();
9122
+ if (this.debug) {
9123
+ console.log("[AD-CONTROLLER] create", {
9124
+ controllerId: this.controllerGeneration,
9125
+ reason: reason
9126
+ });
9127
+ }
8871
9128
  if (shouldShowPlaceholder) {
8872
9129
  this.placeholder.show();
8873
9130
  newAdPlayer.showPlaceholder();
@@ -8888,32 +9145,57 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8888
9145
  }
8889
9146
  },
8890
9147
  {
8891
- key: "handleAdStart",
8892
- value: // ───────────────────────────────────────────────────────────────
9148
+ // ───────────────────────────────────────────────────────────────
8893
9149
  // Ad break start
8894
9150
  // ───────────────────────────────────────────────────────────────
8895
- function handleAdStart(_marker) {
9151
+ key: "isBreakActive",
9152
+ value: function isBreakActive() {
9153
+ return this.slotState !== "IDLE";
9154
+ }
9155
+ },
9156
+ {
9157
+ key: "getSlotState",
9158
+ value: function getSlotState() {
9159
+ return this.slotState;
9160
+ }
9161
+ },
9162
+ {
9163
+ key: "beginVmapBreak",
9164
+ value: function beginVmapBreak(breakKey) {
9165
+ this.breakSource = "vmap";
9166
+ this.followUpBaseVastUrl = void 0;
9167
+ this.unusableResponsesInBreak = 0;
9168
+ this.timing.totalAdRequestsInBreak = 0;
9169
+ this.setSlotState("NEEDS_NEXT_AD", "vmap_break_start");
9170
+ this.noteOpportunity("vmap", breakKey);
9171
+ }
9172
+ },
9173
+ {
9174
+ key: "handleAdStart",
9175
+ value: function handleAdStart(marker) {
8896
9176
  return _async_to_generator(function() {
8897
- var scheduled, tags, baseVastUrl, adBreakDurationMs, mode, currentMuted, currentVolume, podPlayed;
9177
+ var baseVastUrl, adBreakDurationMs, mode, currentMuted, currentVolume, epoch, podPlayed;
8898
9178
  return _ts_generator(this, function(_state) {
8899
9179
  switch(_state.label){
8900
9180
  case 0:
8901
- scheduled = this.adConfig.findCurrentOrNextBreak(this.host.video.currentTime * 1e3);
8902
- if (scheduled) {
8903
- this.adConfig.consumedVmapBreakIds.add(this.adConfig.getAdBreakKey(scheduled));
9181
+ if (this.slotState !== "IDLE") {
9182
+ this.logOrchestratorFunnel("duplicate_break_start", {
9183
+ source: "scte35",
9184
+ state: this.slotState
9185
+ });
9186
+ return [
9187
+ 2
9188
+ ];
8904
9189
  }
8905
- tags = this.adConfig.selectVastTagsForBreak(scheduled);
8906
- if (tags && tags.length > 0 && tags[0]) {
8907
- baseVastUrl = tags[0];
8908
- } else if (this.adConfig.apiVastTagUrl) {
8909
- baseVastUrl = this.adConfig.apiVastTagUrl;
8910
- } else {
9190
+ baseVastUrl = this.adConfig.apiVastTagUrl;
9191
+ if (!baseVastUrl) {
9192
+ console.warn("[AdBreak] SCTE-35 break started but no direct VAST tag is configured");
8911
9193
  this.clearPendingAdBreak();
8912
9194
  return [
8913
9195
  2
8914
9196
  ];
8915
9197
  }
8916
- adBreakDurationMs = _marker.durationSeconds != null ? _marker.durationSeconds * 1e3 : scheduled === null || scheduled === void 0 ? void 0 : scheduled.durationMs;
9198
+ adBreakDurationMs = marker.durationSeconds != null ? marker.durationSeconds * 1e3 : this.timing.expectedAdBreakDurationMs;
8917
9199
  if (this.debug) {
8918
9200
  mode = this.host.config.isLiveStream ? "LIVE" : "VOD";
8919
9201
  console.log("[CONTINUOUS-FETCH] ".concat(mode, " MODE: Target duration=").concat(adBreakDurationMs, "ms"));
@@ -8921,9 +9203,12 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8921
9203
  this.timing.failedVastUrls.clear();
8922
9204
  this.timing.temporaryFailureUrls.clear();
8923
9205
  this.timing.consecutiveFailures = 0;
8924
- this.continuousFetchingActive = true;
8925
9206
  this.isShowingPlaceholder = false;
8926
9207
  this.timing.totalAdRequestsInBreak = 0;
9208
+ this.breakSource = "scte35";
9209
+ this.followUpBaseVastUrl = baseVastUrl;
9210
+ this.unusableResponsesInBreak = 0;
9211
+ this.setSlotState("NEEDS_NEXT_AD", "scte35_break_start");
8927
9212
  if (this.adConfig.podAssignedByPrefetch) {
8928
9213
  this.adConfig.podAssignedByPrefetch = false;
8929
9214
  } else {
@@ -8942,29 +9227,17 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8942
9227
  this.timing.expectedAdBreakDurationMs = adBreakDurationMs;
8943
9228
  }
8944
9229
  this.noteOpportunity("scte35", this.cueManager.activeScte35BreakKey);
9230
+ epoch = this.timing.adBreakEpoch;
8945
9231
  return [
8946
9232
  4,
8947
9233
  this.startOptimizedPod(baseVastUrl, adBreakDurationMs)
8948
9234
  ];
8949
9235
  case 1:
8950
9236
  podPlayed = _state.sent();
8951
- if (!!podPlayed) return [
8952
- 3,
8953
- 3
8954
- ];
8955
- if (this.debug) {
8956
- console.log("[POD] Initial pod request did not fill; attempting top-up pod request");
9237
+ if (!podPlayed && this.inAdBreak && epoch === this.timing.adBreakEpoch) {
9238
+ this.setSlotState("NEEDS_NEXT_AD", "initial_request_failed");
9239
+ this.requestNextAd("initial_request_failed");
8957
9240
  }
8958
- this.continuousFetchingActive = true;
8959
- this.startContinuousFetching(baseVastUrl);
8960
- return [
8961
- 4,
8962
- this.tryNextAvailableAdWithRateLimit()
8963
- ];
8964
- case 2:
8965
- _state.sent();
8966
- _state.label = 3;
8967
- case 3:
8968
9241
  return [
8969
9242
  2
8970
9243
  ];
@@ -8980,10 +9253,11 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8980
9253
  // ───────────────────────────────────────────────────────────────
8981
9254
  function startOptimizedPod(baseVastUrl, breakDurationMs) {
8982
9255
  return _async_to_generator(function() {
8983
- var podUrl, adPlayer, requestToken, _ref, _adPlayer_getPodAdCount, podCount, error;
9256
+ var podUrl, prefetched, epoch, generation, adPlayer, requestToken, _ref, _adPlayer_getPodAdCount, podCount, error;
8984
9257
  return _ts_generator(this, function(_state) {
8985
9258
  switch(_state.label){
8986
9259
  case 0:
9260
+ prefetched = !!(this.pendingAdBreak && this.pendingAdBreak.vastUrls.length > 0);
8987
9261
  if (this.pendingAdBreak && this.pendingAdBreak.vastUrls.length > 0) {
8988
9262
  podUrl = this.pendingAdBreak.vastUrls[0];
8989
9263
  this.clearPendingAdBreak();
@@ -8996,12 +9270,16 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8996
9270
  false
8997
9271
  ];
8998
9272
  }
8999
- this.continuousFetchingActive = false;
9000
- this.recreateAdController();
9273
+ this.noteVastUrlGenerated(podUrl, prefetched ? "prefetch" : "break_start");
9274
+ epoch = this.timing.adBreakEpoch;
9275
+ this.recreateAdController("new_request");
9276
+ generation = this.controllerGeneration;
9001
9277
  adPlayer = this.host.getAdPlayer();
9002
9278
  requestToken = ++this.timing.adRequestTokenCounter;
9003
9279
  this.timing.activeAdRequestToken = requestToken;
9004
9280
  this.currentVastUrl = podUrl;
9281
+ this.setSlotState("REQUESTING", "initial_pod");
9282
+ this.beginFunnelRequest(adPlayer, requestToken, "initial_pod");
9005
9283
  _state.label = 1;
9006
9284
  case 1:
9007
9285
  _state.trys.push([
@@ -9016,9 +9294,11 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9016
9294
  ];
9017
9295
  case 2:
9018
9296
  _state.sent();
9297
+ if (this.isStale(epoch, generation)) return [
9298
+ 2,
9299
+ true
9300
+ ];
9019
9301
  this.timing.startAdRequestWatchdog(requestToken);
9020
- this.timing.noteAdRequestSent();
9021
- this.beginFunnelRequest(adPlayer, requestToken);
9022
9302
  return [
9023
9303
  4,
9024
9304
  this.callController(function() {
@@ -9028,7 +9308,10 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9028
9308
  case 3:
9029
9309
  _state.sent();
9030
9310
  this.timing.clearAdRequestWatchdog();
9031
- if (this.timing.activeAdRequestToken !== requestToken) {
9311
+ if (this.isStale(epoch, generation)) {
9312
+ this.logOrchestratorFunnel("stale_request_result_ignored", {
9313
+ requestId: requestToken
9314
+ });
9032
9315
  return [
9033
9316
  2,
9034
9317
  true
@@ -9036,11 +9319,16 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9036
9319
  }
9037
9320
  podCount = (_ref = (_adPlayer_getPodAdCount = adPlayer.getPodAdCount) === null || _adPlayer_getPodAdCount === void 0 ? void 0 : _adPlayer_getPodAdCount.call(adPlayer)) !== null && _ref !== void 0 ? _ref : 1;
9038
9321
  if (podCount < 1) {
9322
+ if (this.timing.activeAdRequestToken === requestToken) {
9323
+ this.timing.activeAdRequestToken = null;
9324
+ }
9325
+ this.recordRequestFailure(new Error("No ads available"), podUrl);
9039
9326
  return [
9040
9327
  2,
9041
9328
  false
9042
9329
  ];
9043
9330
  }
9331
+ this.setSlotState("READY", "vast_ready");
9044
9332
  if (this.debug) {
9045
9333
  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"));
9046
9334
  }
@@ -9058,12 +9346,14 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9058
9346
  ];
9059
9347
  case 4:
9060
9348
  _state.sent();
9349
+ if (this.isStale(epoch, generation)) return [
9350
+ 2,
9351
+ true
9352
+ ];
9061
9353
  if (this.timing.expectedAdBreakDurationMs != null && this.timing.getAdBreakEndWallClockMs() == null) {
9062
9354
  this.timing.scheduleAdStopAtBreakBoundary();
9063
9355
  }
9064
9356
  adPlayer.setAdVolume(getAdAudioVolume(adPlayer));
9065
- this.continuousFetchingActive = true;
9066
- this.startContinuousFetching(baseVastUrl);
9067
9357
  return [
9068
9358
  2,
9069
9359
  true
@@ -9075,14 +9365,20 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9075
9365
  if (this.timing.activeAdRequestToken === requestToken) {
9076
9366
  this.timing.activeAdRequestToken = null;
9077
9367
  }
9368
+ if (this.isStale(epoch, generation)) {
9369
+ this.logOrchestratorFunnel("stale_request_result_ignored", {
9370
+ requestId: requestToken,
9371
+ errorMessage: error === null || error === void 0 ? void 0 : error.message
9372
+ });
9373
+ return [
9374
+ 2,
9375
+ true
9376
+ ];
9377
+ }
9078
9378
  if (this.debug) {
9079
9379
  console.warn("[POD] Optimized pod request/play failed:", error);
9080
9380
  }
9081
- if (this.timing.isTemporaryAdError(error)) {
9082
- this.timing.temporaryFailureUrls.set(podUrl, Date.now());
9083
- }
9084
- this.continuousFetchingActive = true;
9085
- this.recreateAdController();
9381
+ this.recordRequestFailure(error, podUrl);
9086
9382
  return [
9087
9383
  2,
9088
9384
  false
@@ -9098,168 +9394,204 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9098
9394
  },
9099
9395
  {
9100
9396
  // ───────────────────────────────────────────────────────────────
9101
- // Continuous fetching
9397
+ // Next-ad scheduling (single flight)
9102
9398
  // ───────────────────────────────────────────────────────────────
9103
- key: "startContinuousFetching",
9104
- value: function startContinuousFetching(baseVastUrl) {
9105
- if (!this.continuousFetchingActive) {
9399
+ key: "setSlotState",
9400
+ value: function setSlotState(next, reason) {
9401
+ if (this.slotState === next) return;
9402
+ var previous = this.slotState;
9403
+ this.slotState = next;
9404
+ if (this.debug) {
9405
+ console.log("[AdBreak][STATE] ".concat(previous, " -> ").concat(next), {
9406
+ reason: reason,
9407
+ breakId: this.timing.adBreakEpoch,
9408
+ requestId: this.currentRequestId,
9409
+ controllerId: this.controllerGeneration
9410
+ });
9411
+ }
9412
+ }
9413
+ },
9414
+ {
9415
+ key: "isStale",
9416
+ value: function isStale(epoch, generation) {
9417
+ return !this.inAdBreak || epoch !== this.timing.adBreakEpoch || generation !== this.controllerGeneration;
9418
+ }
9419
+ },
9420
+ {
9421
+ key: "getMinRemainingMsToRequestAd",
9422
+ value: function getMinRemainingMsToRequestAd() {
9423
+ var configured = this.host.config.minRemainingMsToRequestAd;
9424
+ var floor = this.timing.getMinRemainingMsToStartAd();
9425
+ if (typeof configured === "number" && configured >= 0) {
9426
+ return Math.max(configured, floor);
9427
+ }
9428
+ return Math.max(this.defaultMinRemainingMsToRequestAd, floor);
9429
+ }
9430
+ },
9431
+ {
9432
+ key: "getMaxNoFillsPerBreak",
9433
+ value: function getMaxNoFillsPerBreak() {
9434
+ var configured = this.host.config.maxNoFillsPerBreak;
9435
+ return typeof configured === "number" && configured > 0 ? configured : this.defaultMaxNoFillsPerBreak;
9436
+ }
9437
+ },
9438
+ {
9439
+ key: "isBreakTimeBounded",
9440
+ value: function isBreakTimeBounded() {
9441
+ return this.breakSource === "scte35" || this.timing.expectedAdBreakDurationMs != null;
9442
+ }
9443
+ },
9444
+ {
9445
+ key: "getStopRequestingReason",
9446
+ value: function getStopRequestingReason(remainingMs) {
9447
+ if (this.breakSource === "vmap") {
9448
+ if (this.adPodQueue.length === 0) return "vmap_queue_empty";
9449
+ } else if (this.breakSource !== "scte35" || !this.followUpBaseVastUrl) {
9450
+ return "no_follow_up_source";
9451
+ }
9452
+ if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
9453
+ return "max_consecutive_failures";
9454
+ }
9455
+ if (this.unusableResponsesInBreak >= this.getMaxNoFillsPerBreak()) {
9456
+ return "unusable_response_limit";
9457
+ }
9458
+ if (this.timing.totalAdRequestsInBreak >= this.timing.maxTotalAdRequestsPerBreak) {
9459
+ return "request_cap";
9460
+ }
9461
+ if (this.timing.isGamInCooldown()) {
9462
+ return "gam_cooldown";
9463
+ }
9464
+ if (this.isBreakTimeBounded() && remainingMs < this.getMinRemainingMsToRequestAd()) {
9465
+ return "insufficient_break_time";
9466
+ }
9467
+ return void 0;
9468
+ }
9469
+ },
9470
+ {
9471
+ key: "getNextRequestDelayMs",
9472
+ value: function getNextRequestDelayMs() {
9473
+ var failures = this.timing.consecutiveFailures;
9474
+ var backoff = failures > 0 ? Math.min(this.timing.backoffBaseMs * Math.pow(2, failures), this.timing.maxBackoffMs) : 0;
9475
+ var minInterval = this.timing.minAdRequestIntervalMs + backoff;
9476
+ var sinceLast = Date.now() - this.timing.lastAdRequestTime;
9477
+ return Math.max(0, minInterval - sinceLast);
9478
+ }
9479
+ },
9480
+ {
9481
+ key: "requestNextAd",
9482
+ value: function requestNextAd(trigger) {
9483
+ var _this = this;
9484
+ if (!this.inAdBreak) return;
9485
+ if (this.slotState !== "NEEDS_NEXT_AD") {
9486
+ this.logOrchestratorFunnel("request_suppressed", {
9487
+ trigger: trigger,
9488
+ state: this.slotState,
9489
+ why: "slot_busy"
9490
+ });
9106
9491
  return;
9107
9492
  }
9108
- if (this.continuousFetchLoopRunning) {
9109
- if (this.debug) {
9110
- console.log("[CONTINUOUS-FETCH] Fetch loop already running, skipping duplicate start");
9111
- }
9493
+ if (this.nextAdTimerId != null) {
9494
+ this.logOrchestratorFunnel("request_suppressed", {
9495
+ trigger: trigger,
9496
+ state: this.slotState,
9497
+ why: "request_already_scheduled"
9498
+ });
9112
9499
  return;
9113
9500
  }
9114
- if (this.debug) {
9115
- console.log("[CONTINUOUS-FETCH] Starting continuous ad fetching loop");
9501
+ var remainingMs = this.timing.getRemainingAdMs();
9502
+ var stopReason = this.getStopRequestingReason(remainingMs);
9503
+ if (stopReason) {
9504
+ this.logOrchestratorFunnel("next_ad_decision", {
9505
+ trigger: trigger,
9506
+ decision: "end_break",
9507
+ reason: stopReason,
9508
+ remainingMs: remainingMs,
9509
+ requestsSent: this.timing.totalAdRequestsInBreak,
9510
+ unusableResponses: this.unusableResponsesInBreak,
9511
+ consecutiveFailures: this.timing.consecutiveFailures
9512
+ });
9513
+ this.handleAdPodComplete(stopReason);
9514
+ return;
9515
+ }
9516
+ var waitMs = this.getNextRequestDelayMs();
9517
+ if (waitMs > 0 && this.isBreakTimeBounded() && remainingMs - waitMs < this.getMinRemainingMsToRequestAd()) {
9518
+ this.logOrchestratorFunnel("next_ad_decision", {
9519
+ trigger: trigger,
9520
+ decision: "end_break",
9521
+ reason: "insufficient_break_time_after_backoff",
9522
+ remainingMs: remainingMs,
9523
+ waitMs: waitMs
9524
+ });
9525
+ this.handleAdPodComplete("insufficient_break_time_after_backoff");
9526
+ return;
9527
+ }
9528
+ this.logOrchestratorFunnel("next_ad_decision", {
9529
+ trigger: trigger,
9530
+ decision: waitMs > 0 ? "request_after_delay" : "request_now",
9531
+ waitMs: waitMs,
9532
+ remainingMs: remainingMs,
9533
+ consecutiveFailures: this.timing.consecutiveFailures
9534
+ });
9535
+ if (waitMs > 0) {
9536
+ if (!this.isShowingPlaceholder) {
9537
+ this.isShowingPlaceholder = true;
9538
+ this.host.getAdPlayer().showPlaceholder();
9539
+ }
9540
+ var epoch = this.timing.adBreakEpoch;
9541
+ this.nextAdTimerId = window.setTimeout(function() {
9542
+ _this.nextAdTimerId = void 0;
9543
+ if (!_this.inAdBreak || epoch !== _this.timing.adBreakEpoch) return;
9544
+ _this.requestNextAd("".concat(trigger, ":after_delay"));
9545
+ }, waitMs);
9546
+ return;
9116
9547
  }
9117
- this.continuousFetchLoopRunning = true;
9118
- this.continuousFetchLoop(baseVastUrl);
9548
+ void this.requestFollowUpAd(trigger);
9119
9549
  }
9120
9550
  },
9121
9551
  {
9122
- key: "continuousFetchLoop",
9123
- value: function continuousFetchLoop(baseVastUrl) {
9552
+ key: "requestFollowUpAd",
9553
+ value: function requestFollowUpAd(trigger) {
9124
9554
  return _async_to_generator(function() {
9125
- var _this, _loop, epoch, _ret;
9555
+ var url, epoch, unused;
9126
9556
  return _ts_generator(this, function(_state) {
9127
9557
  switch(_state.label){
9128
9558
  case 0:
9129
- _loop = function() {
9130
- var remaining, maxQueueSize, newAdUrl, queuedUrlsPreview, generationDelay;
9131
- return _ts_generator(this, function(_state) {
9132
- switch(_state.label){
9133
- case 0:
9134
- remaining = Math.min(_this.timing.getWallClockRemainingAdMs(), _this.timing.getDurationBudgetRemainingMs());
9135
- if (remaining <= _this.timing.getMinRemainingMsToStartAd()) {
9136
- if (_this.debug) {
9137
- 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"));
9138
- }
9139
- return [
9140
- 2,
9141
- "break"
9142
- ];
9143
- }
9144
- if (_this.timing.isGamInCooldown()) {
9145
- if (_this.debug) {
9146
- console.log("[CIRCUIT-BREAKER] GAM in cooldown, stopping URL generation");
9147
- }
9148
- return [
9149
- 2,
9150
- "break"
9151
- ];
9152
- }
9153
- if (_this.timing.consecutiveFailures >= _this.timing.maxConsecutiveFailures) {
9154
- if (_this.debug) {
9155
- console.log("[CONTINUOUS-FETCH] Too many consecutive failures (".concat(_this.timing.consecutiveFailures, "), stopping URL generation"));
9156
- }
9157
- return [
9158
- 2,
9159
- "break"
9160
- ];
9161
- }
9162
- if (_this.timing.totalAdRequestsInBreak >= _this.timing.maxTotalAdRequestsPerBreak) {
9163
- if (_this.debug) {
9164
- console.log("[CONTINUOUS-FETCH] Maximum ad requests reached (".concat(_this.timing.maxTotalAdRequestsPerBreak, "), stopping"));
9165
- }
9166
- return [
9167
- 2,
9168
- "break"
9169
- ];
9170
- }
9171
- maxQueueSize = 5;
9172
- if (!(_this.adRequestQueue.length >= maxQueueSize)) return [
9173
- 3,
9174
- 2
9175
- ];
9176
- if (_this.debug) {
9177
- console.log("[CONTINUOUS-FETCH] URL queue full (".concat(_this.adRequestQueue.length, "), waiting..."));
9178
- }
9179
- return [
9180
- 4,
9181
- new Promise(function(resolve) {
9182
- return setTimeout(resolve, 1e3);
9183
- })
9184
- ];
9185
- case 1:
9186
- _state.sent();
9187
- return [
9188
- 2,
9189
- "continue"
9190
- ];
9191
- case 2:
9192
- newAdUrl = _this.nextAdRequestUrl(baseVastUrl);
9193
- if (!(!newAdUrl || _this.timing.failedVastUrls.has(newAdUrl) || _this.timing.isUrlInCooldown(newAdUrl))) return [
9194
- 3,
9195
- 4
9196
- ];
9197
- return [
9198
- 4,
9199
- new Promise(function(resolve) {
9200
- return setTimeout(resolve, 500);
9201
- })
9202
- ];
9203
- case 3:
9204
- _state.sent();
9205
- return [
9206
- 2,
9207
- "continue"
9208
- ];
9209
- case 4:
9210
- if (_this.debug) {
9211
- queuedUrlsPreview = _to_consumable_array(_this.adRequestQueue).concat([
9212
- newAdUrl
9213
- ]);
9214
- console.log("[CONTINUOUS-FETCH] Queued VAST URL (queue size: ".concat(queuedUrlsPreview.length, ")"), {
9215
- queuedUrls: queuedUrlsPreview
9216
- });
9217
- }
9218
- _this.adRequestQueue.push(newAdUrl);
9219
- generationDelay = _this.timing.consecutiveFailures > 0 ? Math.min(1e3 * Math.pow(2, _this.timing.consecutiveFailures), 5e3) : 500;
9220
- return [
9221
- 4,
9222
- new Promise(function(resolve) {
9223
- return setTimeout(resolve, generationDelay);
9224
- })
9225
- ];
9226
- case 5:
9227
- _state.sent();
9228
- return [
9229
- 2
9230
- ];
9231
- }
9232
- });
9233
- };
9559
+ if (this.breakSource === "vmap") {
9560
+ url = this.adPodQueue.shift();
9561
+ } else if (this.followUpBaseVastUrl) {
9562
+ url = this.nextAdRequestUrl(this.followUpBaseVastUrl);
9563
+ }
9564
+ if (!url) return [
9565
+ 2
9566
+ ];
9567
+ this.noteVastUrlGenerated(ensureVideoAdType(url), trigger);
9234
9568
  epoch = this.timing.adBreakEpoch;
9235
9569
  _state.label = 1;
9236
9570
  case 1:
9237
- if (!(this.continuousFetchingActive && this.inAdBreak && epoch === this.timing.adBreakEpoch)) return [
9238
- 3,
9239
- 3
9240
- ];
9241
- _this = this;
9571
+ _state.trys.push([
9572
+ 1,
9573
+ 3,
9574
+ ,
9575
+ 4
9576
+ ]);
9242
9577
  return [
9243
- 5,
9244
- _ts_values(_loop())
9578
+ 4,
9579
+ this.playSingleAd(url, trigger)
9245
9580
  ];
9246
9581
  case 2:
9247
- _ret = _state.sent();
9248
- if (_ret === "break") return [
9582
+ _state.sent();
9583
+ return [
9249
9584
  3,
9250
- 3
9585
+ 4
9251
9586
  ];
9587
+ case 3:
9588
+ unused = _state.sent();
9589
+ this.continueAfterRequestFailure(epoch);
9252
9590
  return [
9253
9591
  3,
9254
- 1
9592
+ 4
9255
9593
  ];
9256
- case 3:
9257
- this.continuousFetchLoopRunning = false;
9258
- if (this.debug) {
9259
- console.log("[CONTINUOUS-FETCH] URL generation loop ended (queued: ".concat(this.adRequestQueue.length, ")"), this.adRequestQueue.length > 0 ? {
9260
- queuedUrls: _to_consumable_array(this.adRequestQueue)
9261
- } : {});
9262
- }
9594
+ case 4:
9263
9595
  return [
9264
9596
  2
9265
9597
  ];
@@ -9269,242 +9601,158 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9269
9601
  }
9270
9602
  },
9271
9603
  {
9272
- key: "stopContinuousFetching",
9273
- value: function stopContinuousFetching() {
9274
- this.continuousFetchingActive = false;
9275
- this.continuousFetchLoopRunning = false;
9276
- this.placeholder.hide();
9277
- if (this.debug) {
9278
- console.log("[CONTINUOUS-FETCH] Stopping continuous ad fetching");
9604
+ key: "continueAfterRequestFailure",
9605
+ value: function continueAfterRequestFailure() {
9606
+ var epoch = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.timing.adBreakEpoch;
9607
+ if (!this.inAdBreak || epoch !== this.timing.adBreakEpoch) return;
9608
+ this.setSlotState("NEEDS_NEXT_AD", "request_failed");
9609
+ this.requestNextAd("after_failure");
9610
+ }
9611
+ },
9612
+ {
9613
+ key: "cancelScheduledRequest",
9614
+ value: function cancelScheduledRequest() {
9615
+ if (this.nextAdTimerId != null) {
9616
+ clearTimeout(this.nextAdTimerId);
9617
+ this.nextAdTimerId = void 0;
9279
9618
  }
9280
9619
  }
9281
9620
  },
9282
9621
  {
9283
- key: "tryNextAvailableAdWithRateLimit",
9284
- value: // ───────────────────────────────────────────────────────────────
9285
- // Ad iteration
9622
+ key: "noteVastUrlGenerated",
9623
+ value: function noteVastUrlGenerated(url, source) {
9624
+ var _ref, _ref1, _ref2, _ref3, _ref4;
9625
+ var params;
9626
+ try {
9627
+ params = new URL(url).searchParams;
9628
+ } catch (unused) {}
9629
+ var adType = (_ref = params === null || params === void 0 ? void 0 : params.get("ad_type")) !== null && _ref !== void 0 ? _ref : void 0;
9630
+ this.logOrchestratorFunnel("vast_url_generated", {
9631
+ source: source,
9632
+ pod: (_ref1 = params === null || params === void 0 ? void 0 : params.get("pod")) !== null && _ref1 !== void 0 ? _ref1 : void 0,
9633
+ pmad: (_ref2 = params === null || params === void 0 ? void 0 : params.get("pmad")) !== null && _ref2 !== void 0 ? _ref2 : void 0,
9634
+ pmnd: (_ref3 = params === null || params === void 0 ? void 0 : params.get("pmnd")) !== null && _ref3 !== void 0 ? _ref3 : void 0,
9635
+ pmxd: (_ref4 = params === null || params === void 0 ? void 0 : params.get("pmxd")) !== null && _ref4 !== void 0 ? _ref4 : void 0,
9636
+ adType: adType
9637
+ });
9638
+ if (adType === "audio" || adType === "audio_video") {
9639
+ console.warn("[AdBreak] VAST tag requests ad_type=".concat(adType, "; GAM may return audio-only creatives, which this video player rejects"));
9640
+ this.countFunnelStage("tag_allows_audio");
9641
+ }
9642
+ }
9643
+ },
9644
+ {
9645
+ key: "recordRequestFailure",
9646
+ value: function recordRequestFailure(error, vastTagUrl) {
9647
+ var _diag_vastAdCount;
9648
+ var diag = this.currentRequestId != null ? this.requestDiagnostics.get(this.currentRequestId) : void 0;
9649
+ var message = (error === null || error === void 0 ? void 0 : error.message) || "";
9650
+ var outcome;
9651
+ if (message.includes("ad_duration_exceeds_budget")) {
9652
+ outcome = "discarded_budget";
9653
+ } else if (message.includes("VAST fill rejected")) {
9654
+ outcome = "fill_rejected";
9655
+ } else if (/no ads available|no fill|nofill/i.test(message)) {
9656
+ outcome = "no_fill";
9657
+ } else if (/timeout/i.test(message)) {
9658
+ outcome = "request_timeout";
9659
+ } else if (/destroyed|aborted/i.test(message)) {
9660
+ outcome = "request_aborted";
9661
+ } else if (diag && ((_diag_vastAdCount = diag.vastAdCount) !== null && _diag_vastAdCount !== void 0 ? _diag_vastAdCount : 0) > 0 && !diag.impressionFired) {
9662
+ outcome = "playback_failed";
9663
+ } else {
9664
+ outcome = "request_failed";
9665
+ }
9666
+ this.timing.consecutiveFailures++;
9667
+ if (outcome === "no_fill" || outcome === "fill_rejected" || outcome === "discarded_budget") {
9668
+ this.unusableResponsesInBreak++;
9669
+ }
9670
+ if (outcome === "no_fill") {
9671
+ this.timing.recordGamNoFill();
9672
+ }
9673
+ if (diag && !diag.failureReason) {
9674
+ diag.failureReason = "".concat(outcome, ": ").concat(message);
9675
+ }
9676
+ if (this.timing.isTemporaryAdError(error)) {
9677
+ this.timing.temporaryFailureUrls.set(vastTagUrl, Date.now());
9678
+ } else if (outcome !== "discarded_budget") {
9679
+ this.timing.failedVastUrls.add(vastTagUrl);
9680
+ }
9681
+ this.countFunnelStage("request_outcome:".concat(outcome));
9682
+ this.logOrchestratorFunnel("request_outcome", {
9683
+ outcome: outcome,
9684
+ errorMessage: message,
9685
+ consecutiveFailures: this.timing.consecutiveFailures,
9686
+ unusableResponsesInBreak: this.unusableResponsesInBreak
9687
+ });
9688
+ }
9689
+ },
9690
+ {
9286
9691
  // ───────────────────────────────────────────────────────────────
9287
- function tryNextAvailableAdWithRateLimit() {
9288
- return _async_to_generator(function() {
9289
- var epoch, backoffMultiplier, backoffDelay, effectiveMinInterval, timeSinceLastRequest, waitTime;
9290
- return _ts_generator(this, function(_state) {
9291
- switch(_state.label){
9292
- case 0:
9293
- if (!this.inAdBreak) {
9294
- return [
9295
- 2
9296
- ];
9297
- }
9298
- epoch = this.timing.adBreakEpoch;
9299
- if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
9300
- if (this.debug) {
9301
- console.log("[CONTINUOUS-FETCH] Too many consecutive failures (".concat(this.timing.consecutiveFailures, "), ending ad break gracefully"));
9302
- }
9303
- this.handleAdPodComplete();
9304
- return [
9305
- 2
9306
- ];
9307
- }
9308
- backoffMultiplier = Math.pow(2, this.timing.consecutiveFailures);
9309
- backoffDelay = Math.min(this.timing.backoffBaseMs * backoffMultiplier, this.timing.maxBackoffMs);
9310
- effectiveMinInterval = this.timing.minAdRequestIntervalMs + (this.timing.consecutiveFailures > 0 ? backoffDelay : 0);
9311
- timeSinceLastRequest = Date.now() - this.timing.lastAdRequestTime;
9312
- if (!(timeSinceLastRequest < effectiveMinInterval)) return [
9313
- 3,
9314
- 2
9315
- ];
9316
- waitTime = effectiveMinInterval - timeSinceLastRequest;
9317
- if (this.debug) {
9318
- console.log("[CONTINUOUS-FETCH] Rate limiting: waiting ".concat(waitTime, "ms before next request (backoff: ").concat(this.timing.consecutiveFailures, " failures)"));
9319
- }
9320
- return [
9321
- 4,
9322
- new Promise(function(resolve) {
9323
- return setTimeout(resolve, waitTime);
9324
- })
9325
- ];
9326
- case 1:
9327
- _state.sent();
9328
- _state.label = 2;
9329
- case 2:
9330
- if (!this.inAdBreak || epoch !== this.timing.adBreakEpoch) {
9331
- return [
9332
- 2
9333
- ];
9334
- }
9335
- return [
9336
- 2,
9337
- this.tryNextAvailableAd(0)
9338
- ];
9692
+ // Per-request diagnostics
9693
+ // ───────────────────────────────────────────────────────────────
9694
+ key: "recordRequestDiagnostic",
9695
+ value: function recordRequestDiagnostic(payload) {
9696
+ var requestId = payload.requestId;
9697
+ if (typeof requestId !== "number") return;
9698
+ var diag = this.requestDiagnostics.get(requestId);
9699
+ if (!diag) return;
9700
+ switch(payload.stage){
9701
+ case "gam_http_request_sent":
9702
+ diag.gamRequestSent++;
9703
+ break;
9704
+ case "gam_response_received":
9705
+ diag.vastHttpStatus = payload.httpStatus;
9706
+ break;
9707
+ case "vast_parsed":
9708
+ diag.vastAdCount = payload.adElementCount;
9709
+ break;
9710
+ case "wrapper_fetch":
9711
+ case "inline_resolved":
9712
+ if (typeof payload.depth === "number") {
9713
+ diag.wrapperDepth = Math.max(diag.wrapperDepth, payload.depth);
9339
9714
  }
9340
- });
9341
- }).call(this);
9715
+ if (payload.stage === "inline_resolved") diag.inlineResolved = true;
9716
+ break;
9717
+ case "mediafile_evaluated":
9718
+ diag.mediaCandidateCount++;
9719
+ if (payload.whyAccepted) diag.supportedMediaCount++;
9720
+ break;
9721
+ case "playing":
9722
+ diag.playStarted = true;
9723
+ break;
9724
+ case "impression_fired":
9725
+ diag.impressionFired = true;
9726
+ break;
9727
+ default:
9728
+ if (REQUEST_FAILURE_STAGES.has(payload.stage) && !diag.failureReason) {
9729
+ diag.failureReason = payload.reason ? "".concat(payload.stage, ":").concat(payload.reason) : payload.stage;
9730
+ }
9731
+ }
9342
9732
  }
9343
9733
  },
9344
9734
  {
9345
- key: "tryNextAvailableAd",
9346
- value: function tryNextAvailableAd() {
9347
- var retryCount = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
9348
- return _async_to_generator(function() {
9349
- var remaining, nextAdUrl, error, errorMessage, maxRetries;
9350
- return _ts_generator(this, function(_state) {
9351
- switch(_state.label){
9352
- case 0:
9353
- if (!this.inAdBreak) {
9354
- return [
9355
- 2
9356
- ];
9357
- }
9358
- remaining = this.timing.getRemainingAdMs();
9359
- if (!this.timing.hasTimeToStartAnotherAd()) {
9360
- if (this.debug) {
9361
- console.log("[CONTINUOUS-FETCH] Not enough time remaining (".concat(remaining, "ms) to start another ad, ending ad break"));
9362
- }
9363
- this.handleAdPodComplete();
9364
- return [
9365
- 2
9366
- ];
9367
- }
9368
- if (this.timing.isGamInCooldown()) {
9369
- if (this.debug) {
9370
- console.log("[CIRCUIT-BREAKER] GAM in cooldown, ending ad break gracefully");
9371
- }
9372
- this.handleAdPodComplete();
9373
- return [
9374
- 2
9375
- ];
9376
- }
9377
- if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
9378
- if (this.debug) {
9379
- console.log("[CONTINUOUS-FETCH] Too many consecutive failures (".concat(this.timing.consecutiveFailures, "), ending ad break"));
9380
- }
9381
- this.handleAdPodComplete();
9382
- return [
9383
- 2
9384
- ];
9385
- }
9386
- this.timing.cleanupTemporaryFailures();
9387
- _state.label = 1;
9388
- case 1:
9389
- if (!(this.adRequestQueue.length > 0)) return [
9390
- 3,
9391
- 9
9392
- ];
9393
- nextAdUrl = this.adRequestQueue.shift();
9394
- if (!nextAdUrl) return [
9395
- 3,
9396
- 1
9397
- ];
9398
- if (this.timing.failedVastUrls.has(nextAdUrl)) {
9399
- if (this.debug) console.log("[CONTINUOUS-FETCH] Skipping permanently-failed URL, trying next...");
9400
- return [
9401
- 3,
9402
- 1
9403
- ];
9404
- }
9405
- if (this.timing.isUrlInCooldown(nextAdUrl)) {
9406
- if (this.debug) console.log("[CONTINUOUS-FETCH] Skipping URL in cooldown (recent no-fill), trying next...");
9407
- return [
9408
- 3,
9409
- 1
9410
- ];
9411
- }
9412
- if (this.debug) {
9413
- console.log("[CONTINUOUS-FETCH] Requesting next ad via HLS ad player (".concat(this.timing.currentAdIndex + 1, ", ").concat(this.adRequestQueue.length, " remaining in queue)"));
9414
- }
9415
- _state.label = 2;
9416
- case 2:
9417
- _state.trys.push([
9418
- 2,
9419
- 4,
9420
- ,
9421
- 8
9422
- ]);
9423
- return [
9424
- 4,
9425
- this.playSingleAd(nextAdUrl)
9426
- ];
9427
- case 3:
9428
- _state.sent();
9429
- return [
9430
- 3,
9431
- 8
9432
- ];
9433
- case 4:
9434
- error = _state.sent();
9435
- errorMessage = error.message;
9436
- if (this.debug) console.log("[CONTINUOUS-FETCH] Ad request failed:", errorMessage);
9437
- if (!errorMessage.includes("ad_duration_exceeds_budget")) return [
9438
- 3,
9439
- 6
9440
- ];
9441
- this.timing.consecutiveFailures++;
9442
- return [
9443
- 4,
9444
- this.tryNextAvailableAdWithRateLimit()
9445
- ];
9446
- case 5:
9447
- _state.sent();
9448
- return [
9449
- 2
9450
- ];
9451
- case 6:
9452
- if (!errorMessage.includes("permanently failed") && !errorMessage.includes("in cooldown")) {
9453
- this.timing.consecutiveFailures++;
9454
- }
9455
- return [
9456
- 4,
9457
- this.tryNextAvailableAdWithRateLimit()
9458
- ];
9459
- case 7:
9460
- _state.sent();
9461
- return [
9462
- 3,
9463
- 8
9464
- ];
9465
- case 8:
9466
- return [
9467
- 2
9468
- ];
9469
- case 9:
9470
- maxRetries = 3;
9471
- if (!(this.continuousFetchingActive && retryCount < maxRetries && remaining > 2e3)) return [
9472
- 3,
9473
- 12
9474
- ];
9475
- if (this.debug) {
9476
- console.log("[CONTINUOUS-FETCH] Queue empty, waiting for URLs... (".concat(retryCount + 1, "/").concat(maxRetries, ")"));
9477
- }
9478
- return [
9479
- 4,
9480
- new Promise(function(resolve) {
9481
- return setTimeout(resolve, 500);
9482
- })
9483
- ];
9484
- case 10:
9485
- _state.sent();
9486
- return [
9487
- 4,
9488
- this.tryNextAvailableAd(retryCount + 1)
9489
- ];
9490
- case 11:
9491
- _state.sent();
9492
- return [
9493
- 2
9494
- ];
9495
- case 12:
9496
- if (!this.isShowingPlaceholder && remaining > 1e3) {
9497
- this.showPlaceholderAndWaitForAds();
9498
- } else {
9499
- if (this.debug) console.log("[CONTINUOUS-FETCH] No more ads available, ending ad break");
9500
- this.handleAdPodComplete();
9501
- }
9502
- return [
9503
- 2
9504
- ];
9505
- }
9506
- });
9507
- }).call(this);
9735
+ key: "finalizeRequestDiagnostics",
9736
+ value: function finalizeRequestDiagnostics(requestId, endReason) {
9737
+ var _diag_vastAdCount;
9738
+ if (requestId == null) return;
9739
+ var diag = this.requestDiagnostics.get(requestId);
9740
+ if (!diag) return;
9741
+ this.requestDiagnostics.delete(requestId);
9742
+ if (!diag.impressionFired && !diag.failureReason && endReason) {
9743
+ diag.failureReason = endReason;
9744
+ }
9745
+ var gamReturnedAdWithoutImpression = ((_diag_vastAdCount = diag.vastAdCount) !== null && _diag_vastAdCount !== void 0 ? _diag_vastAdCount : 0) > 0 && !diag.impressionFired;
9746
+ if (gamReturnedAdWithoutImpression) {
9747
+ this.countFunnelStage("gam_ad_without_impression");
9748
+ }
9749
+ var startedAt = diag.startedAt, fields = _object_without_properties(diag, [
9750
+ "startedAt"
9751
+ ]);
9752
+ console.log("[AdBreak][REQUEST] summary", _object_spread_props(_object_spread({}, fields), {
9753
+ durationMs: Date.now() - startedAt,
9754
+ gamReturnedAdWithoutImpression: gamReturnedAdWithoutImpression
9755
+ }));
9508
9756
  }
9509
9757
  },
9510
9758
  {
@@ -9512,7 +9760,8 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9512
9760
  // Single ad playback
9513
9761
  // ───────────────────────────────────────────────────────────────
9514
9762
  key: "withCurrentPodBudget",
9515
- value: function withCurrentPodBudget(vastTagUrl) {
9763
+ value: function withCurrentPodBudget(rawVastTagUrl) {
9764
+ var vastTagUrl = ensureVideoAdType(rawVastTagUrl);
9516
9765
  var remaining = Math.min(this.timing.getWallClockRemainingAdMs(), this.timing.getDurationBudgetRemainingMs());
9517
9766
  if (!(remaining > 0)) return vastTagUrl;
9518
9767
  try {
@@ -9571,18 +9820,34 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9571
9820
  },
9572
9821
  {
9573
9822
  key: "beginFunnelRequest",
9574
- value: function beginFunnelRequest(adPlayer, requestToken) {
9823
+ value: function beginFunnelRequest(adPlayer, requestToken, trigger) {
9575
9824
  var _adPlayer_setFunnelContext;
9576
9825
  if (this.controllerCallInFlight) {
9577
9826
  this.logOrchestratorFunnel("duplicate_request_detected", {
9578
9827
  newRequestId: requestToken
9579
9828
  });
9580
9829
  }
9830
+ this.finalizeRequestDiagnostics(this.currentRequestId);
9581
9831
  this.currentRequestId = requestToken;
9582
9832
  this.requestStartedAt = Date.now();
9833
+ this.requestDiagnostics.set(requestToken, {
9834
+ breakId: this.timing.adBreakEpoch,
9835
+ requestId: requestToken,
9836
+ controllerId: this.controllerGeneration,
9837
+ trigger: trigger,
9838
+ gamRequestSent: 0,
9839
+ wrapperDepth: 0,
9840
+ inlineResolved: false,
9841
+ mediaCandidateCount: 0,
9842
+ supportedMediaCount: 0,
9843
+ playStarted: false,
9844
+ impressionFired: false,
9845
+ startedAt: Date.now()
9846
+ });
9583
9847
  (_adPlayer_setFunnelContext = adPlayer.setFunnelContext) === null || _adPlayer_setFunnelContext === void 0 ? void 0 : _adPlayer_setFunnelContext.call(adPlayer, {
9584
9848
  breakId: this.timing.adBreakEpoch,
9585
- requestId: requestToken
9849
+ requestId: requestToken,
9850
+ controllerId: this.controllerGeneration
9586
9851
  });
9587
9852
  }
9588
9853
  },
@@ -9613,7 +9878,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9613
9878
  adPlayer.abortPendingRequest("VAST request aborted after request watchdog timeout");
9614
9879
  return;
9615
9880
  }
9616
- this.handleAdFailure();
9881
+ this.handleAdFailure("request_watchdog_timeout");
9617
9882
  }
9618
9883
  },
9619
9884
  {
@@ -9659,21 +9924,30 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9659
9924
  {
9660
9925
  key: "playSingleAd",
9661
9926
  value: function playSingleAd(vastTagUrl) {
9927
+ var trigger = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "vmap";
9662
9928
  return _async_to_generator(function() {
9663
- var adPlayer, requestToken, ap, requestUrl, _ap_getLoadedAdDuration, adDurationS, remainingMs, playError, error, errorMessage;
9929
+ var epoch, generation, requestToken, ap, requestUrl, _ap_getLoadedAdDuration, adDurationS, remainingMs, error;
9664
9930
  return _ts_generator(this, function(_state) {
9665
9931
  switch(_state.label){
9666
9932
  case 0:
9667
- adPlayer = this.host.getAdPlayer();
9668
- if (adPlayer.isAdPlaying()) return [
9669
- 2
9670
- ];
9933
+ if (this.slotState === "REQUESTING" || this.slotState === "READY" || this.slotState === "PLAYING" || this.slotState === "ENDING") {
9934
+ this.logOrchestratorFunnel("request_suppressed", {
9935
+ trigger: trigger,
9936
+ state: this.slotState,
9937
+ why: "request_in_flight"
9938
+ });
9939
+ return [
9940
+ 2
9941
+ ];
9942
+ }
9671
9943
  if (this.timing.failedVastUrls.has(vastTagUrl)) {
9672
9944
  if (this.debug) console.warn("[AD-ERROR] Skipping permanently-failed VAST URL:", vastTagUrl);
9945
+ this.timing.consecutiveFailures++;
9673
9946
  throw new Error("VAST URL permanently failed");
9674
9947
  }
9675
9948
  if (this.timing.isUrlInCooldown(vastTagUrl)) {
9676
9949
  if (this.debug) console.warn("[AD-ERROR] Skipping URL in cooldown (recent no-fill):", vastTagUrl);
9950
+ this.timing.consecutiveFailures++;
9677
9951
  throw new Error("VAST URL in cooldown after no-fill");
9678
9952
  }
9679
9953
  if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
@@ -9684,16 +9958,23 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9684
9958
  if (this.debug) console.warn("[CIRCUIT-BREAKER] GAM in cooldown, skipping ad request");
9685
9959
  throw new Error("GAM in cooldown");
9686
9960
  }
9687
- this.recreateAdController();
9961
+ epoch = this.timing.adBreakEpoch;
9962
+ this.recreateAdController("new_request");
9963
+ generation = this.controllerGeneration;
9688
9964
  requestToken = ++this.timing.adRequestTokenCounter;
9689
9965
  this.timing.activeAdRequestToken = requestToken;
9966
+ ap = this.host.getAdPlayer();
9967
+ requestUrl = this.withCurrentPodBudget(vastTagUrl);
9968
+ this.currentVastUrl = requestUrl;
9969
+ this.setSlotState("REQUESTING", trigger);
9970
+ this.beginFunnelRequest(ap, requestToken, trigger);
9690
9971
  _state.label = 1;
9691
9972
  case 1:
9692
9973
  _state.trys.push([
9693
9974
  1,
9694
- 8,
9975
+ 5,
9695
9976
  ,
9696
- 9
9977
+ 6
9697
9978
  ]);
9698
9979
  return [
9699
9980
  4,
@@ -9701,12 +9982,10 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9701
9982
  ];
9702
9983
  case 2:
9703
9984
  _state.sent();
9985
+ if (this.isStale(epoch, generation)) return [
9986
+ 2
9987
+ ];
9704
9988
  this.timing.startAdRequestWatchdog(requestToken);
9705
- this.timing.noteAdRequestSent();
9706
- ap = this.host.getAdPlayer();
9707
- requestUrl = this.withCurrentPodBudget(vastTagUrl);
9708
- this.currentVastUrl = requestUrl;
9709
- this.beginFunnelRequest(ap, requestToken);
9710
9989
  return [
9711
9990
  4,
9712
9991
  this.callController(function() {
@@ -9715,36 +9994,31 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9715
9994
  ];
9716
9995
  case 3:
9717
9996
  _state.sent();
9997
+ this.timing.clearAdRequestWatchdog();
9998
+ if (this.isStale(epoch, generation)) {
9999
+ this.logOrchestratorFunnel("stale_request_result_ignored", {
10000
+ requestId: requestToken
10001
+ });
10002
+ return [
10003
+ 2
10004
+ ];
10005
+ }
9718
10006
  sendAdLoadedTracking(this.host.config.licenseKey, {
9719
10007
  source: "hls",
9720
10008
  vastUrl: requestUrl,
9721
10009
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
9722
10010
  }, this.analyticsContext).catch(function() {});
9723
- this.timing.clearAdRequestWatchdog();
9724
- if (this.timing.activeAdRequestToken !== requestToken) return [
9725
- 2
9726
- ];
9727
10011
  if (!this.timing.ensureLoadedAdFitsBudget(ap)) {
9728
10012
  ;
9729
10013
  adDurationS = (_ap_getLoadedAdDuration = ap.getLoadedAdDuration) === null || _ap_getLoadedAdDuration === void 0 ? void 0 : _ap_getLoadedAdDuration.call(ap);
9730
10014
  remainingMs = Math.min(this.timing.getWallClockRemainingAdMs(), this.timing.getDurationBudgetRemainingMs());
9731
10015
  this.logOrchestratorFunnel("discarded_budget", {
9732
- vastUrl: requestUrl,
9733
10016
  adDurationMs: adDurationS != null ? adDurationS * 1e3 : void 0,
9734
10017
  remainingMs: remainingMs
9735
10018
  });
9736
- this.timing.rejectLoadedAdForDuration(ap);
9737
- this.recreateAdController();
9738
10019
  throw new Error("ad_duration_exceeds_budget");
9739
10020
  }
9740
- _state.label = 4;
9741
- case 4:
9742
- _state.trys.push([
9743
- 4,
9744
- 6,
9745
- ,
9746
- 7
9747
- ]);
10021
+ this.setSlotState("READY", "vast_ready");
9748
10022
  this.timing.startAdFailsafeTimer(requestToken);
9749
10023
  return [
9750
10024
  4,
@@ -9752,8 +10026,11 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9752
10026
  return ap.play();
9753
10027
  })
9754
10028
  ];
9755
- case 5:
10029
+ case 4:
9756
10030
  _state.sent();
10031
+ if (this.isStale(epoch, generation)) return [
10032
+ 2
10033
+ ];
9757
10034
  if (this.timing.expectedAdBreakDurationMs != null && this.timing.getAdBreakEndWallClockMs() == null) {
9758
10035
  this.timing.scheduleAdStopAtBreakBoundary();
9759
10036
  }
@@ -9761,216 +10038,31 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9761
10038
  this.timing.temporaryFailureUrls.delete(vastTagUrl);
9762
10039
  return [
9763
10040
  3,
9764
- 7
9765
- ];
9766
- case 6:
9767
- playError = _state.sent();
9768
- if (this.debug) console.error("[AD-ERROR] Failed to play ad:", playError);
9769
- if (this.timing.isTemporaryAdError(playError)) {
9770
- this.timing.temporaryFailureUrls.set(vastTagUrl, Date.now());
9771
- if (this.debug) console.log("[AD-ERROR] Temporary play error - URL can be retried after cooldown");
9772
- } else {
9773
- this.timing.failedVastUrls.add(vastTagUrl);
9774
- if (this.debug) console.log("[AD-ERROR] Permanent play error - URL blacklisted");
9775
- }
9776
- this.timing.clearAdFailsafeTimer();
9777
- if (this.timing.activeAdRequestToken === requestToken) {
9778
- this.timing.activeAdRequestToken = null;
9779
- }
9780
- throw playError;
9781
- case 7:
9782
- return [
9783
- 3,
9784
- 9
10041
+ 6
9785
10042
  ];
9786
- case 8:
10043
+ case 5:
9787
10044
  error = _state.sent();
9788
- errorMessage = (error === null || error === void 0 ? void 0 : error.message) || "";
9789
- if (this.debug) console.error("[AD-ERROR] Ad request failed:", errorMessage);
9790
- if (this.timing.isTemporaryAdError(error)) {
9791
- this.timing.temporaryFailureUrls.set(vastTagUrl, Date.now());
9792
- if (this.debug) console.log("[AD-ERROR] Temporary error (no-fill/timeout) - URL can be retried after cooldown");
9793
- } else {
9794
- this.timing.failedVastUrls.add(vastTagUrl);
9795
- if (this.debug) console.log("[AD-ERROR] Permanent error - URL blacklisted:", errorMessage);
9796
- }
9797
10045
  this.timing.clearAdRequestWatchdog();
9798
10046
  this.timing.clearAdFailsafeTimer();
9799
10047
  if (this.timing.activeAdRequestToken === requestToken) {
9800
10048
  this.timing.activeAdRequestToken = null;
9801
10049
  }
9802
- throw error;
9803
- case 9:
9804
- return [
9805
- 2
9806
- ];
9807
- }
9808
- });
9809
- }).call(this);
9810
- }
9811
- },
9812
- {
9813
- key: "showPlaceholderAndWaitForAds",
9814
- value: // ───────────────────────────────────────────────────────────────
9815
- // Placeholder wait
9816
- // ───────────────────────────────────────────────────────────────
9817
- function showPlaceholderAndWaitForAds() {
9818
- return _async_to_generator(function() {
9819
- var remaining, waitTime, checkInterval, maxChecks, i, nextAdUrl, error, errorMessage;
9820
- return _ts_generator(this, function(_state) {
9821
- switch(_state.label){
9822
- case 0:
9823
- remaining = this.timing.getRemainingAdMs();
9824
- waitTime = Math.min(this.maxPlaceholderDurationMs, remaining);
9825
- if (this.timing.isGamInCooldown()) {
9826
- if (this.debug) console.log("[CIRCUIT-BREAKER] GAM in cooldown, skipping placeholder wait");
9827
- this.handleAdPodComplete();
9828
- return [
9829
- 2
9830
- ];
9831
- }
9832
- if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
9833
- if (this.debug) console.log("[CONTINUOUS-FETCH] Skipping placeholder - too many consecutive failures");
9834
- this.handleAdPodComplete();
9835
- return [
9836
- 2
9837
- ];
9838
- }
9839
- if (waitTime < 1e3) {
9840
- this.handleAdPodComplete();
10050
+ if (this.isStale(epoch, generation)) {
10051
+ this.logOrchestratorFunnel("stale_request_result_ignored", {
10052
+ requestId: requestToken,
10053
+ errorMessage: error === null || error === void 0 ? void 0 : error.message
10054
+ });
9841
10055
  return [
9842
10056
  2
9843
10057
  ];
9844
10058
  }
9845
- if (this.debug) {
9846
- console.log("[CONTINUOUS-FETCH] Showing placeholder for ".concat(waitTime, "ms while waiting for ad URLs"));
10059
+ if (this.debug) console.error("[AD-ERROR] Ad request failed:", error === null || error === void 0 ? void 0 : error.message);
10060
+ this.recordRequestFailure(error, vastTagUrl);
10061
+ if ((error === null || error === void 0 ? void 0 : error.message) === "ad_duration_exceeds_budget") {
10062
+ this.recreateAdController("discarded_budget");
9847
10063
  }
9848
- this.isShowingPlaceholder = true;
9849
- this.host.getAdPlayer().showPlaceholder();
9850
- checkInterval = 300;
9851
- maxChecks = Math.floor(waitTime / checkInterval);
9852
- i = 0;
9853
- _state.label = 1;
9854
- case 1:
9855
- if (!(i < maxChecks)) return [
9856
- 3,
9857
- 12
9858
- ];
9859
- return [
9860
- 4,
9861
- new Promise(function(resolve) {
9862
- return setTimeout(resolve, checkInterval);
9863
- })
9864
- ];
9865
- case 2:
9866
- _state.sent();
9867
- if (!this.inAdBreak) return [
9868
- 2
9869
- ];
9870
- if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
9871
- if (this.debug) console.log("[CONTINUOUS-FETCH] Too many failures during placeholder wait");
9872
- return [
9873
- 3,
9874
- 12
9875
- ];
9876
- }
9877
- if (!this.timing.hasTimeToStartAnotherAd()) {
9878
- if (this.debug) console.log("[CONTINUOUS-FETCH] Not enough time remaining during placeholder wait, ending ad break");
9879
- return [
9880
- 3,
9881
- 12
9882
- ];
9883
- }
9884
- _state.label = 3;
9885
- case 3:
9886
- if (!(this.adRequestQueue.length > 0)) return [
9887
- 3,
9888
- 11
9889
- ];
9890
- if (!this.timing.hasTimeToStartAnotherAd()) return [
9891
- 3,
9892
- 11
9893
- ];
9894
- nextAdUrl = this.adRequestQueue.shift();
9895
- if (!nextAdUrl) return [
9896
- 3,
9897
- 3
9898
- ];
9899
- if (this.timing.failedVastUrls.has(nextAdUrl)) return [
9900
- 3,
9901
- 3
9902
- ];
9903
- if (this.timing.isUrlInCooldown(nextAdUrl)) return [
9904
- 3,
9905
- 3
9906
- ];
9907
- if (this.debug) console.log("[CONTINUOUS-FETCH] Ad URL available, requesting via HLS ad player");
9908
- this.isShowingPlaceholder = false;
9909
- this.host.getAdPlayer().hidePlaceholder();
9910
- _state.label = 4;
9911
- case 4:
9912
- _state.trys.push([
9913
- 4,
9914
- 6,
9915
- ,
9916
- 10
9917
- ]);
9918
- return [
9919
- 4,
9920
- this.playSingleAd(nextAdUrl)
9921
- ];
9922
- case 5:
9923
- _state.sent();
9924
- return [
9925
- 3,
9926
- 10
9927
- ];
10064
+ throw error;
9928
10065
  case 6:
9929
- error = _state.sent();
9930
- errorMessage = error.message;
9931
- if (!errorMessage.includes("ad_duration_exceeds_budget")) return [
9932
- 3,
9933
- 8
9934
- ];
9935
- this.timing.consecutiveFailures++;
9936
- return [
9937
- 4,
9938
- this.tryNextAvailableAdWithRateLimit()
9939
- ];
9940
- case 7:
9941
- _state.sent();
9942
- return [
9943
- 2
9944
- ];
9945
- case 8:
9946
- if (!errorMessage.includes("permanently failed") && !errorMessage.includes("in cooldown")) {
9947
- this.timing.consecutiveFailures++;
9948
- }
9949
- return [
9950
- 4,
9951
- this.tryNextAvailableAdWithRateLimit()
9952
- ];
9953
- case 9:
9954
- _state.sent();
9955
- return [
9956
- 3,
9957
- 10
9958
- ];
9959
- case 10:
9960
- return [
9961
- 2
9962
- ];
9963
- case 11:
9964
- i++;
9965
- return [
9966
- 3,
9967
- 1
9968
- ];
9969
- case 12:
9970
- if (this.debug) console.log("[CONTINUOUS-FETCH] Placeholder timeout, ending ad break");
9971
- this.isShowingPlaceholder = false;
9972
- this.host.getAdPlayer().hidePlaceholder();
9973
- this.handleAdPodComplete();
9974
10066
  return [
9975
10067
  2
9976
10068
  ];
@@ -9984,7 +10076,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9984
10076
  // Ad break completion
9985
10077
  // ───────────────────────────────────────────────────────────────
9986
10078
  key: "logBreakFunnel",
9987
- value: function logBreakFunnel() {
10079
+ value: function logBreakFunnel(endReason) {
9988
10080
  var funnel = this.breakFunnel;
9989
10081
  this.breakFunnel = {};
9990
10082
  if (Object.keys(funnel).length === 0) return;
@@ -9992,26 +10084,49 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9992
10084
  var _funnel_stage;
9993
10085
  return (_funnel_stage = funnel[stage]) !== null && _funnel_stage !== void 0 ? _funnel_stage : 0;
9994
10086
  };
10087
+ var countPrefix = function countPrefix(prefix) {
10088
+ return Object.keys(funnel).reduce(function(total, stage) {
10089
+ var _funnel_stage;
10090
+ return stage.indexOf(prefix) === 0 ? total + ((_funnel_stage = funnel[stage]) !== null && _funnel_stage !== void 0 ? _funnel_stage : 0) : total;
10091
+ }, 0);
10092
+ };
9995
10093
  var breakId = this.opportunityEpoch;
9996
- if (count("request_sent") > 0 && count("impression_fired") === 0) {
10094
+ var requestRetries = count("gam_http_request_retry");
10095
+ var requests = count("gam_http_request_sent") - requestRetries;
10096
+ if (requests > 0 && count("impression_fired") === 0) {
9997
10097
  console.log("[AdBreak][FUNNEL] break_abandoned_before_start", {
9998
10098
  breakId: breakId,
9999
- requests: count("request_sent")
10099
+ requests: requests,
10100
+ endReason: endReason
10000
10101
  });
10001
10102
  }
10002
10103
  console.log("[AdBreak][FUNNEL] Break summary", {
10003
10104
  breakId: breakId,
10105
+ endReason: endReason,
10004
10106
  opportunities: count("opportunity_created"),
10005
- requests: count("request_sent"),
10107
+ vastUrlsGenerated: count("vast_url_generated"),
10108
+ requests: requests,
10109
+ requestRetries: requestRetries,
10110
+ gamResponses: count("gam_response_received"),
10111
+ requestsSuppressed: count("request_suppressed"),
10006
10112
  duplicates: count("duplicate_request_detected") + count("duplicate_break_start"),
10007
10113
  filled: count("vast_received"),
10008
10114
  noFill: count("no_fill"),
10115
+ fillRejected: count("vast_fill_rejected"),
10116
+ gamAdWithoutImpression: count("gam_ad_without_impression"),
10117
+ playbackFailedAfterFill: count("request_outcome:playback_failed"),
10009
10118
  requestFailed: count("request_failed"),
10010
10119
  requestAbortedTimeout: count("request_aborted_timeout"),
10011
10120
  credentialsRetries: count("vast_credentials_retry"),
10012
10121
  wrapperFailures: count("wrapper_fetch:failure"),
10013
10122
  noSupportedMedia: count("vast_no_supported_media"),
10014
- vpaidOnly: count("vast_no_supported_media:vpaid_only"),
10123
+ vpaidOnly: count("vast_no_supported_media:vpaid"),
10124
+ audioOnly: count("vast_no_supported_media:audio_only"),
10125
+ mediaFilesEvaluated: count("mediafile_evaluated"),
10126
+ mediaFilesAccepted: count("mediafile_evaluated:accepted"),
10127
+ controllerDestroys: countPrefix("controller_destroy:"),
10128
+ staleCallbacks: count("stale_callback_ignored") + count("stale_request_result_ignored"),
10129
+ tagAllowsAudio: count("tag_allows_audio"),
10015
10130
  missingImpression: count("vast_missing_impression"),
10016
10131
  discardedBudget: count("discarded_budget"),
10017
10132
  mediaCandidates: count("media_candidate:accepted") + count("media_candidate:rejected"),
@@ -10046,25 +10161,50 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
10046
10161
  {
10047
10162
  key: "handleAdPodComplete",
10048
10163
  value: function handleAdPodComplete() {
10164
+ var reason = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "unspecified";
10049
10165
  if (this.debug) {
10050
- console.log("[StormcloudVideoPlayer] Ad pod complete - cleaning up");
10166
+ console.log("[StormcloudVideoPlayer] Ad pod complete - cleaning up", {
10167
+ reason: reason
10168
+ });
10169
+ }
10170
+ var previousState = this.slotState;
10171
+ var alreadyEnded = previousState === "IDLE" && !this.inAdBreak;
10172
+ this.setSlotState("ENDING", reason);
10173
+ this.cancelScheduledRequest();
10174
+ var adPlayer = this.host.getAdPlayer();
10175
+ if (previousState === "REQUESTING") {
10176
+ var _adPlayer_abortPendingRequest;
10177
+ (_adPlayer_abortPendingRequest = adPlayer.abortPendingRequest) === null || _adPlayer_abortPendingRequest === void 0 ? void 0 : _adPlayer_abortPendingRequest.call(adPlayer, "VAST request aborted: ad break ended (".concat(reason, ")"));
10178
+ }
10179
+ if (!alreadyEnded) {
10180
+ console.log("[AD-CONTROLLER] stop", {
10181
+ controllerId: this.controllerGeneration,
10182
+ requestId: this.currentRequestId,
10183
+ state: previousState,
10184
+ reason: reason
10185
+ });
10051
10186
  }
10187
+ this.finalizeRequestDiagnostics(this.currentRequestId, "break_ended:".concat(reason));
10188
+ this.currentRequestId = void 0;
10052
10189
  this.timing.resetForBreakEnd();
10053
- this.stopContinuousFetching();
10190
+ this.placeholder.hide();
10054
10191
  this.clearPendingAdBreak();
10055
10192
  if (this.isShowingPlaceholder) {
10056
- this.host.getAdPlayer().hidePlaceholder();
10193
+ adPlayer.hidePlaceholder();
10057
10194
  this.isShowingPlaceholder = false;
10058
10195
  }
10059
- this.adRequestQueue = [];
10060
10196
  this.inAdBreak = false;
10061
10197
  this.adDetectSentForCurrentBreak = false;
10062
10198
  this.cueManager.activeScte35BreakKey = void 0;
10063
10199
  this.cueManager.scheduledScte35BreakKey = void 0;
10064
10200
  this.adPodQueue = [];
10065
10201
  this.showAds = false;
10066
- this.host.getAdPlayer().stop().catch(function() {});
10067
- this.logBreakFunnel();
10202
+ this.breakSource = void 0;
10203
+ this.followUpBaseVastUrl = void 0;
10204
+ this.unusableResponsesInBreak = 0;
10205
+ adPlayer.stop().catch(function() {});
10206
+ if (!alreadyEnded) this.logBreakFunnel(reason);
10207
+ this.setSlotState("IDLE", "break_complete");
10068
10208
  var restoredMuted = this.host.getAdPlayer().getOriginalMutedState();
10069
10209
  var restoredVolume = this.host.getAdPlayer().getOriginalVolume();
10070
10210
  if (this.host.video.muted !== restoredMuted) {
@@ -10358,25 +10498,23 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
10358
10498
  {
10359
10499
  key: "handleAdFailure",
10360
10500
  value: function handleAdFailure() {
10361
- this.timing.consecutiveFailures++;
10362
- this.timing.recordGamNoFill();
10363
- var remaining = this.timing.getRemainingAdMs();
10364
- if (this.debug) {
10365
- 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 ? {
10366
- queuedUrls: _to_consumable_array(this.adRequestQueue)
10367
- } : {});
10368
- }
10369
- if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
10370
- if (this.debug) console.log("[CONTINUOUS-FETCH] Max consecutive failures reached (".concat(this.timing.consecutiveFailures, "), ending ad break gracefully"));
10371
- this.handleAdPodComplete();
10501
+ var reason = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "ad_failure";
10502
+ if (!this.inAdBreak) return;
10503
+ if (this.slotState === "REQUESTING" || this.slotState === "ENDING") {
10504
+ this.logOrchestratorFunnel("failure_deferred_to_request", {
10505
+ reason: reason,
10506
+ state: this.slotState
10507
+ });
10372
10508
  return;
10373
10509
  }
10374
- if (this.timing.hasTimeToStartAnotherAd()) {
10375
- this.tryNextAvailableAdWithRateLimit();
10376
- } else {
10377
- if (this.debug) console.log("[AD-ERROR] Ad failed and not enough time remaining for another ad. Failed URLs:", this.timing.failedVastUrls.size);
10378
- this.handleAdPodComplete();
10510
+ this.timing.consecutiveFailures++;
10511
+ var diag = this.currentRequestId != null ? this.requestDiagnostics.get(this.currentRequestId) : void 0;
10512
+ if (diag && !diag.failureReason) diag.failureReason = reason;
10513
+ if (this.debug) {
10514
+ console.log("[AdBreak] Ad failure (".concat(reason, "): remaining=").concat(this.timing.getRemainingAdMs(), "ms, consecutiveFailures=").concat(this.timing.consecutiveFailures));
10379
10515
  }
10516
+ this.setSlotState("NEEDS_NEXT_AD", reason);
10517
+ this.requestNextAd(reason);
10380
10518
  }
10381
10519
  }
10382
10520
  ]);
@@ -10419,7 +10557,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10419
10557
  return _this.adBreak.handleRequestWatchdogTimeout();
10420
10558
  },
10421
10559
  onFailsafeTimeout: function onFailsafeTimeout() {
10422
- return _this.adBreak.handleAdFailure();
10560
+ return _this.adBreak.handleAdFailure("failsafe_timeout");
10423
10561
  },
10424
10562
  getAdState: function getAdState() {
10425
10563
  return {
@@ -10669,6 +10807,21 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10669
10807
  adBehavior: adBehavior
10670
10808
  });
10671
10809
  }
10810
+ if (this.adBreak.isBreakActive()) {
10811
+ console.log("[AD-CONTROLLER] destroy skipped", {
10812
+ reason: "manifest_parsed_during_break",
10813
+ state: this.adBreak.getSlotState()
10814
+ });
10815
+ return [
10816
+ 2
10817
+ ];
10818
+ }
10819
+ if (this.debug) {
10820
+ console.log("[AD-CONTROLLER] destroy", {
10821
+ reason: "manifest_parsed",
10822
+ state: "IDLE"
10823
+ });
10824
+ }
10672
10825
  this.adPlayer.destroy();
10673
10826
  this.adPlayer = this.createAdPlayer(this.shouldContinueLiveStreamDuringAds());
10674
10827
  this.adPlayer.initialize();
@@ -10850,9 +11003,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10850
11003
  this.timing.setAdBreakDurationBoundary(marker.durationSeconds * 1e3);
10851
11004
  }
10852
11005
  this.timing.scheduleAdStopAtBreakBoundary();
10853
- if (!this.adPlayer.isAdPlaying() && this.timing.activeAdRequestToken === null && this.adBreak.adRequestQueue.length > 0 && this.timing.hasTimeToStartAnotherAd()) {
10854
- this.adBreak.tryNextAvailableAdWithRateLimit();
10855
- }
10856
11006
  return;
10857
11007
  }
10858
11008
  if (marker.type === "end") {
@@ -10864,12 +11014,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10864
11014
  }
10865
11015
  var remaining = this.timing.getRemainingAdMs();
10866
11016
  var adPlaying = this.adPlayer.isAdPlaying();
10867
- var hasQueuedAds = this.adBreak.adRequestQueue.length > 0;
10868
11017
  if (this.debug) {
10869
11018
  console.log("[StormcloudVideoPlayer] SCTE-35 end marker received:", {
10870
11019
  remaining: remaining,
10871
11020
  adPlaying: adPlaying,
10872
- hasQueuedAds: hasQueuedAds,
11021
+ adSlotState: this.adBreak.getSlotState(),
10873
11022
  activeAdRequest: this.timing.activeAdRequestToken !== null
10874
11023
  });
10875
11024
  }
@@ -10880,7 +11029,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10880
11029
  this.adBreak.noteStopBeforeStart("scte_end");
10881
11030
  this.adPlayer.stop().catch(function() {});
10882
11031
  }
10883
- this.adBreak.handleAdPodComplete();
11032
+ this.adBreak.handleAdPodComplete("scte_end");
10884
11033
  return;
10885
11034
  }
10886
11035
  }
@@ -10888,6 +11037,15 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10888
11037
  {
10889
11038
  key: "startScte35AdBreak",
10890
11039
  value: function startScte35AdBreak(marker, cueKey, durationMs) {
11040
+ if (this.adBreak.isBreakActive()) {
11041
+ if (this.debug) {
11042
+ console.log("[StormcloudVideoPlayer] Ignoring SCTE-35 break start: a break is already active", {
11043
+ state: this.adBreak.getSlotState(),
11044
+ cueKey: cueKey
11045
+ });
11046
+ }
11047
+ return;
11048
+ }
10891
11049
  this.adBreak.inAdBreak = true;
10892
11050
  this.cueManager.activeScte35BreakKey = cueKey !== null && cueKey !== void 0 ? cueKey : this.cueManager.pendingScte35CueKey;
10893
11051
  this.cueManager.scheduledScte35BreakKey = void 0;
@@ -10920,7 +11078,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10920
11078
  this.adBreak.noteStopBeforeStart("break_boundary");
10921
11079
  this.adPlayer.stop().catch(function() {});
10922
11080
  }
10923
- this.adBreak.handleAdPodComplete();
11081
+ this.adBreak.handleAdPodComplete("break_boundary");
10924
11082
  }
10925
11083
  },
10926
11084
  {
@@ -10930,14 +11088,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10930
11088
  key: "startAdPrefetch",
10931
11089
  value: function startAdPrefetch(marker, fragmentSn, cueKey) {
10932
11090
  if (this.adBreak.pendingAdBreak || this.adBreak.inAdBreak) return;
10933
- var scheduled = this.adConfig.findCurrentOrNextBreak(this.video.currentTime * 1e3);
10934
- var tags = this.adConfig.selectVastTagsForBreak(scheduled);
10935
- var baseVastUrl;
10936
- if (tags && tags.length > 0 && tags[0]) {
10937
- baseVastUrl = tags[0];
10938
- } else if (this.adConfig.apiVastTagUrl) {
10939
- baseVastUrl = this.adConfig.apiVastTagUrl;
10940
- } else {
11091
+ var baseVastUrl = this.adConfig.apiVastTagUrl;
11092
+ if (!baseVastUrl) {
10941
11093
  if (this.debug) console.warn("[StormcloudVideoPlayer] No VAST URL available for prefetch");
10942
11094
  return;
10943
11095
  }
@@ -10967,8 +11119,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10967
11119
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
10968
11120
  }, detectPayload), buildAnalyticsContext(this.config)).catch(function() {});
10969
11121
  if (this.debug) {
10970
- console.log("[PREFETCH] Starting ad prefetch for upcoming ad break");
10971
- console.log("[PREFETCH] Pre-generated pod request URL");
11122
+ console.log("[PREFETCH] Pre-generated pod request URL for upcoming ad break");
10972
11123
  }
10973
11124
  }
10974
11125
  },
@@ -10979,7 +11130,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10979
11130
  key: "onTimeUpdate",
10980
11131
  value: function onTimeUpdate(currentTimeSec) {
10981
11132
  var _this = this;
10982
- if (!this.adConfig.isVmapEnabled() || this.adConfig.vmapBreaks.length === 0) return;
11133
+ if (this.adConfig.vmapBreaks.length === 0) return;
10983
11134
  if (this.adPlayer.isAdPlaying() || this.adBreak.inAdBreak) return;
10984
11135
  var nowMs = currentTimeSec * 1e3;
10985
11136
  var breakToPlay = this.adConfig.findBreakForTime(nowMs);
@@ -10996,7 +11147,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10996
11147
  key: "onVideoEnded",
10997
11148
  value: function onVideoEnded() {
10998
11149
  var _this = this;
10999
- if (!this.adConfig.isVmapEnabled() || this.adConfig.vmapBreaks.length === 0) return;
11150
+ if (this.adConfig.vmapBreaks.length === 0) return;
11000
11151
  if (this.adPlayer.isAdPlaying() || this.adBreak.inAdBreak) return;
11001
11152
  var durationMs = Number.isFinite(this.video.duration) ? Math.floor(this.video.duration * 1e3) : 0;
11002
11153
  var postroll = this.adConfig.vmapBreaks.find(function(b) {
@@ -11049,7 +11200,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11049
11200
  if (durationMs > 0) {
11050
11201
  this.timing.setAdBreakDurationBoundary(durationMs);
11051
11202
  }
11052
- this.adBreak.noteOpportunity("vmap", key);
11203
+ this.adBreak.beginVmapBreak(key);
11053
11204
  _state.label = 1;
11054
11205
  case 1:
11055
11206
  _state.trys.push([
@@ -11060,7 +11211,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11060
11211
  ]);
11061
11212
  return [
11062
11213
  4,
11063
- this.adBreak.playSingleAd(first)
11214
+ this.adBreak.playSingleAd(first, "vmap")
11064
11215
  ];
11065
11216
  case 2:
11066
11217
  _state.sent();
@@ -11073,7 +11224,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11073
11224
  if (this.debug) {
11074
11225
  console.warn("[StormcloudVideoPlayer] VMAP ad request failed:", error);
11075
11226
  }
11076
- this.adBreak.handleAdPodComplete();
11227
+ this.adBreak.continueAfterRequestFailure();
11077
11228
  return [
11078
11229
  3,
11079
11230
  4
@@ -11215,7 +11366,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11215
11366
  key: "destroy",
11216
11367
  value: function destroy() {
11217
11368
  var _this_adPlayer;
11218
- this.adBreak.stopContinuousFetching();
11369
+ this.adBreak.cancelScheduledRequest();
11219
11370
  this.timing.destroy();
11220
11371
  this.adBreak.clearPendingAdBreak();
11221
11372
  this.placeholder.destroy();
@@ -11239,7 +11390,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11239
11390
  this.palNonce.sendPlaybackEnd();
11240
11391
  }
11241
11392
  this.palNonce.reset();
11242
- this.adBreak.adRequestQueue = [];
11243
11393
  this.timing.consecutiveFailures = 0;
11244
11394
  }
11245
11395
  }
@@ -11322,7 +11472,7 @@ var CRITICAL_PROPS = [
11322
11472
  var CONTROLS_HIDE_DELAY = 3e3;
11323
11473
  var DEFAULT_PLAYER_ASPECT_RATIO = 16 / 9;
11324
11474
  var StormcloudVideoPlayerComponent = import_react.default.memo(function(props) {
11325
- 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, [
11475
+ 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, [
11326
11476
  "src",
11327
11477
  "autoplay",
11328
11478
  "muted",
@@ -11355,7 +11505,10 @@ var StormcloudVideoPlayerComponent = import_react.default.memo(function(props) {
11355
11505
  "minSegmentsBeforePlay",
11356
11506
  "ctvAdRequest",
11357
11507
  "programTitle",
11358
- "channelName"
11508
+ "channelName",
11509
+ "minRemainingMsToStartAd",
11510
+ "minRemainingMsToRequestAd",
11511
+ "maxNoFillsPerBreak"
11359
11512
  ]);
11360
11513
  var videoRef = (0, import_react.useRef)(null);
11361
11514
  var playerRef = (0, import_react.useRef)(null);
@@ -11548,6 +11701,9 @@ var StormcloudVideoPlayerComponent = import_react.default.memo(function(props) {
11548
11701
  if (ctvAdRequest !== void 0) cfg.ctvAdRequest = ctvAdRequest;
11549
11702
  if (programTitle !== void 0) cfg.programTitle = programTitle;
11550
11703
  if (channelName !== void 0) cfg.channelName = channelName;
11704
+ if (minRemainingMsToStartAd !== void 0) cfg.minRemainingMsToStartAd = minRemainingMsToStartAd;
11705
+ if (minRemainingMsToRequestAd !== void 0) cfg.minRemainingMsToRequestAd = minRemainingMsToRequestAd;
11706
+ if (maxNoFillsPerBreak !== void 0) cfg.maxNoFillsPerBreak = maxNoFillsPerBreak;
11551
11707
  var player = new StormcloudVideoPlayer(cfg);
11552
11708
  playerRef.current = player;
11553
11709
  player.load().then(function() {