stormcloud-video-player 0.8.65 → 0.8.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -329,26 +329,6 @@ function _ts_generator(thisArg, body) {
329
329
  };
330
330
  }
331
331
  }
332
- function _ts_values(o) {
333
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
334
- if (m) {
335
- return m.call(o);
336
- }
337
- if (o && typeof o.length === "number") {
338
- return {
339
- next: function() {
340
- if (o && i >= o.length) {
341
- o = void 0;
342
- }
343
- return {
344
- value: o && o[i++],
345
- done: !o
346
- };
347
- }
348
- };
349
- }
350
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
351
- }
352
332
  function _type_of(obj) {
353
333
  "@swc/helpers - typeof";
354
334
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
@@ -798,6 +778,8 @@ function createHlsAdPlayer(contentVideo, options) {
798
778
  var pendingPlayPromise;
799
779
  var currentVastTagUrl;
800
780
  var funnelContext = {};
781
+ var mediaProbe;
782
+ var lastPodAdElementCount = 0;
801
783
  var mediaCandidates = [];
802
784
  var mediaCandidateIndex = 0;
803
785
  var mediaStartTimerId;
@@ -915,6 +897,7 @@ function createHlsAdPlayer(contentVideo, options) {
915
897
  stage: stage,
916
898
  breakId: funnelContext.breakId,
917
899
  requestId: funnelContext.requestId,
900
+ controllerId: funnelContext.controllerId,
918
901
  visibilityState: typeof document !== "undefined" ? document.visibilityState : void 0,
919
902
  adId: currentAd === null || currentAd === void 0 ? void 0 : currentAd.id,
920
903
  podIndex: podIndex,
@@ -1104,7 +1087,6 @@ function createHlsAdPlayer(contentVideo, options) {
1104
1087
  });
1105
1088
  logFunnel("media_candidate", _object_spread_props(_object_spread({}, details), {
1106
1089
  reason: "accepted",
1107
- // Mixed-content media is often auto-upgraded, so it is kept as a last resort.
1108
1090
  why: insecure ? "insecure_http_deprioritized" : "playable",
1109
1091
  score: score
1110
1092
  }));
@@ -1132,6 +1114,145 @@ function createHlsAdPlayer(contentVideo, options) {
1132
1114
  var url = (mediaFile.url.toLowerCase().split("?")[0] || "").trim();
1133
1115
  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");
1134
1116
  }
1117
+ function getMediaProbe() {
1118
+ if (adVideoElement) return adVideoElement;
1119
+ if (!mediaProbe && typeof document !== "undefined") {
1120
+ mediaProbe = document.createElement("video");
1121
+ }
1122
+ return mediaProbe;
1123
+ }
1124
+ function evaluateMediaFile(mf) {
1125
+ var _mf_textContent;
1126
+ var type = mf.getAttribute("type") || "";
1127
+ var url = ((_mf_textContent = mf.textContent) === null || _mf_textContent === void 0 ? void 0 : _mf_textContent.trim()) || "";
1128
+ var delivery = mf.getAttribute("delivery") || void 0;
1129
+ var codec = mf.getAttribute("codec") || void 0;
1130
+ if (!url) {
1131
+ return {
1132
+ category: "missing_media",
1133
+ whyRejected: "empty_url",
1134
+ canPlayType: ""
1135
+ };
1136
+ }
1137
+ var apiFramework = (mf.getAttribute("apiFramework") || "").toUpperCase();
1138
+ if (apiFramework === "VPAID") {
1139
+ return {
1140
+ category: "vpaid",
1141
+ whyRejected: "vpaid_not_supported",
1142
+ canPlayType: ""
1143
+ };
1144
+ }
1145
+ try {
1146
+ var protocol = new URL(url).protocol;
1147
+ if (protocol !== "https:" && protocol !== "http:") {
1148
+ return {
1149
+ category: "invalid_url",
1150
+ whyRejected: "protocol_".concat(protocol),
1151
+ canPlayType: ""
1152
+ };
1153
+ }
1154
+ } catch (unused) {
1155
+ return {
1156
+ category: "invalid_url",
1157
+ whyRejected: "unparseable_url",
1158
+ canPlayType: ""
1159
+ };
1160
+ }
1161
+ var bitrateAttr = mf.getAttribute("bitrate");
1162
+ var bitrateValue = bitrateAttr ? parseInt(bitrateAttr, 10) : void 0;
1163
+ var file = {
1164
+ url: url,
1165
+ type: type,
1166
+ width: parseInt(mf.getAttribute("width") || "1920", 10),
1167
+ height: parseInt(mf.getAttribute("height") || "1080", 10),
1168
+ bitrate: bitrateValue && bitrateValue > 0 ? bitrateValue : void 0,
1169
+ delivery: delivery,
1170
+ codec: codec
1171
+ };
1172
+ if (isAudioMediaFile(file)) {
1173
+ return {
1174
+ category: "audio_only",
1175
+ whyRejected: type.toLowerCase().startsWith("audio/") ? "audio_mime" : "audio_extension",
1176
+ canPlayType: ""
1177
+ };
1178
+ }
1179
+ var isHls = isHlsMediaFile(file);
1180
+ var hasExplicitDimensions = mf.getAttribute("width") != null && mf.getAttribute("height") != null;
1181
+ if (!isHls && hasExplicitDimensions && (file.width <= 1 || file.height <= 1)) {
1182
+ return {
1183
+ category: "audio_only",
1184
+ whyRejected: "zero_dimensions",
1185
+ canPlayType: ""
1186
+ };
1187
+ }
1188
+ var probe = getMediaProbe();
1189
+ if (isHls) {
1190
+ var _ref;
1191
+ var nativeHls = (_ref = probe === null || probe === void 0 ? void 0 : probe.canPlayType("application/vnd.apple.mpegurl")) !== null && _ref !== void 0 ? _ref : "";
1192
+ if (Hls.isSupported()) {
1193
+ return {
1194
+ file: file,
1195
+ whyAccepted: "hls_js",
1196
+ canPlayType: nativeHls
1197
+ };
1198
+ }
1199
+ if (nativeHls !== "") {
1200
+ return {
1201
+ file: file,
1202
+ whyAccepted: "native_hls",
1203
+ canPlayType: nativeHls
1204
+ };
1205
+ }
1206
+ return {
1207
+ category: "unsupported_hls",
1208
+ whyRejected: "no_hls_support",
1209
+ canPlayType: nativeHls
1210
+ };
1211
+ }
1212
+ if (!isProgressiveMediaFile(file)) {
1213
+ return {
1214
+ category: "unsupported_mime",
1215
+ whyRejected: "not_a_video_mime",
1216
+ canPlayType: ""
1217
+ };
1218
+ }
1219
+ if (!probe) {
1220
+ return {
1221
+ file: file,
1222
+ whyAccepted: "no_probe_available",
1223
+ canPlayType: ""
1224
+ };
1225
+ }
1226
+ var baseType = type || "video/mp4";
1227
+ var canPlay2 = probe.canPlayType(baseType);
1228
+ if (canPlay2 === "") {
1229
+ return {
1230
+ category: "unsupported_mime",
1231
+ whyRejected: "canPlayType_empty",
1232
+ canPlayType: canPlay2
1233
+ };
1234
+ }
1235
+ if (codec) {
1236
+ var withCodec = probe.canPlayType("".concat(baseType, '; codecs="').concat(codec, '"'));
1237
+ if (withCodec === "") {
1238
+ return {
1239
+ category: "unsupported_codec",
1240
+ whyRejected: "codec_canPlayType_empty",
1241
+ canPlayType: withCodec
1242
+ };
1243
+ }
1244
+ return {
1245
+ file: file,
1246
+ whyAccepted: "canPlayType_".concat(withCodec),
1247
+ canPlayType: withCodec
1248
+ };
1249
+ }
1250
+ return {
1251
+ file: file,
1252
+ whyAccepted: "canPlayType_".concat(canPlay2),
1253
+ canPlayType: canPlay2
1254
+ };
1255
+ }
1135
1256
  function collectVideoMediaFiles(linear, verbose, stats) {
1136
1257
  var mediaFileElements = linear.querySelectorAll(":scope > MediaFiles > MediaFile");
1137
1258
  var mediaFiles = [];
@@ -1141,57 +1262,33 @@ function createHlsAdPlayer(contentVideo, options) {
1141
1262
  }
1142
1263
  mediaFileElements.forEach(function(mf, index) {
1143
1264
  var _mf_textContent;
1144
- var type = mf.getAttribute("type") || "";
1265
+ var result = evaluateMediaFile(mf);
1145
1266
  var url = ((_mf_textContent = mf.textContent) === null || _mf_textContent === void 0 ? void 0 : _mf_textContent.trim()) || "";
1146
- var width = mf.getAttribute("width") || "";
1147
- var height = mf.getAttribute("height") || "";
1148
- if (verbose) {
1149
- console.log("[HlsAdPlayer] MediaFile ".concat(index, ': type="').concat(type, '", url="').concat(url, '", width="').concat(width, '", height="').concat(height, '"'));
1150
- }
1151
- if (!url) {
1152
- if (verbose) {
1153
- console.warn("[HlsAdPlayer] MediaFile ".concat(index, " has empty URL"));
1154
- }
1155
- return;
1156
- }
1157
- var apiFramework = (mf.getAttribute("apiFramework") || "").toUpperCase();
1158
- if (apiFramework === "VPAID") {
1159
- if (stats) stats.vpaid++;
1160
- if (verbose) {
1161
- console.log("[HlsAdPlayer] MediaFile ".concat(index, " ignored (VPAID creatives are not supported)"));
1162
- }
1163
- return;
1164
- }
1165
- var bitrateAttr = mf.getAttribute("bitrate");
1166
- var bitrateValue = bitrateAttr ? parseInt(bitrateAttr, 10) : void 0;
1167
- var mediaFile = {
1168
- url: url,
1169
- type: type,
1170
- width: parseInt(width || "1920", 10),
1171
- height: parseInt(height || "1080", 10),
1172
- bitrate: bitrateValue && bitrateValue > 0 ? bitrateValue : void 0
1173
- };
1174
- if (isAudioMediaFile(mediaFile)) {
1175
- if (stats) stats.audio++;
1176
- console.warn("[HlsAdPlayer] MediaFile ".concat(index, ' skipped (audio-only, type="').concat(type, '") — audio ads are not played to avoid a black screen'));
1267
+ var accepted = "file" in result;
1268
+ logFunnel("mediafile_evaluated", {
1269
+ reason: accepted ? "accepted" : result.category,
1270
+ index: index,
1271
+ type: mf.getAttribute("type") || "",
1272
+ delivery: mf.getAttribute("delivery") || void 0,
1273
+ codec: mf.getAttribute("codec") || void 0,
1274
+ apiFramework: mf.getAttribute("apiFramework") || void 0,
1275
+ width: mf.getAttribute("width"),
1276
+ height: mf.getAttribute("height"),
1277
+ fileUrl: redactUrl(url),
1278
+ canPlayType: result.canPlayType,
1279
+ whyAccepted: accepted ? result.whyAccepted : void 0,
1280
+ whyRejected: accepted ? void 0 : result.whyRejected
1281
+ });
1282
+ if ("file" in result) {
1283
+ mediaFiles.push(result.file);
1177
1284
  return;
1178
1285
  }
1179
- var hasExplicitDimensions = mf.getAttribute("width") != null && mf.getAttribute("height") != null;
1180
- if (!isHlsMediaFile(mediaFile) && hasExplicitDimensions && (mediaFile.width <= 1 || mediaFile.height <= 1)) {
1181
- if (stats) stats.audio++;
1182
- 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'));
1183
- return;
1286
+ if (stats) {
1287
+ var _stats_categories_result_category;
1288
+ 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;
1184
1289
  }
1185
- if (isHlsMediaFile(mediaFile) || isProgressiveMediaFile(mediaFile)) {
1186
- mediaFiles.push(mediaFile);
1187
- if (verbose) {
1188
- console.log("[HlsAdPlayer] Added ".concat(isHlsMediaFile(mediaFile) ? "HLS" : "progressive", " MediaFile: ").concat(url));
1189
- }
1190
- } else {
1191
- if (stats) stats.unsupported++;
1192
- if (verbose) {
1193
- console.log("[HlsAdPlayer] MediaFile ".concat(index, ' ignored (type="').concat(type, '" is not supported)'));
1194
- }
1290
+ if (result.category === "audio_only") {
1291
+ 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'));
1195
1292
  }
1196
1293
  });
1197
1294
  return mediaFiles;
@@ -1413,7 +1510,7 @@ function createHlsAdPlayer(contentVideo, options) {
1413
1510
  if (adElement.getAttribute("conditionalAd") === "true") {
1414
1511
  console.warn("[HlsAdPlayer] Skipping conditional <Ad> (VPAID-only)");
1415
1512
  logFunnel("vast_no_supported_media", {
1416
- reason: "vpaid_only",
1513
+ reason: "vpaid",
1417
1514
  conditionalAd: true
1418
1515
  });
1419
1516
  return {
@@ -1426,9 +1523,7 @@ function createHlsAdPlayer(contentVideo, options) {
1426
1523
  var mediaFiles = [];
1427
1524
  var rejectStats = {
1428
1525
  total: 0,
1429
- vpaid: 0,
1430
- audio: 0,
1431
- unsupported: 0
1526
+ categories: {}
1432
1527
  };
1433
1528
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1434
1529
  try {
@@ -1457,10 +1552,39 @@ function createHlsAdPlayer(contentVideo, options) {
1457
1552
  }
1458
1553
  if (!linear) {
1459
1554
  console.warn("[HlsAdPlayer] No supported linear media files in <Ad>");
1460
- var reason = rejectStats.total === 0 ? "no_mediafiles" : rejectStats.vpaid > 0 ? "vpaid_only" : rejectStats.audio > 0 ? "audio_only" : "unsupported_type";
1461
- logFunnel("vast_no_supported_media", _object_spread({
1462
- reason: reason
1463
- }, rejectStats));
1555
+ var reason = "missing_media";
1556
+ var top = 0;
1557
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
1558
+ try {
1559
+ for(var _iterator1 = Object.keys(rejectStats.categories)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
1560
+ var category = _step1.value;
1561
+ var _rejectStats_categories_category;
1562
+ var count = (_rejectStats_categories_category = rejectStats.categories[category]) !== null && _rejectStats_categories_category !== void 0 ? _rejectStats_categories_category : 0;
1563
+ if (count > top) {
1564
+ top = count;
1565
+ reason = category;
1566
+ }
1567
+ }
1568
+ } catch (err) {
1569
+ _didIteratorError1 = true;
1570
+ _iteratorError1 = err;
1571
+ } finally{
1572
+ try {
1573
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
1574
+ _iterator1.return();
1575
+ }
1576
+ } finally{
1577
+ if (_didIteratorError1) {
1578
+ throw _iteratorError1;
1579
+ }
1580
+ }
1581
+ }
1582
+ if (rejectStats.total > 0 && top === 0) reason = "other";
1583
+ logFunnel("vast_no_supported_media", {
1584
+ reason: reason,
1585
+ mediaFileCount: rejectStats.total,
1586
+ rejectedByCategory: rejectStats.categories
1587
+ });
1464
1588
  return {
1465
1589
  type: "empty",
1466
1590
  errorUrls: errorUrls,
@@ -1490,9 +1614,9 @@ function createHlsAdPlayer(contentVideo, options) {
1490
1614
  }
1491
1615
  }
1492
1616
  function fetchVastXml(vastTagUrl) {
1493
- var credentials = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "include";
1617
+ var credentials = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "include", kind = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "gam";
1494
1618
  return _async_to_generator(function() {
1495
- var controller, timeoutId, requestVast, response, error, error1;
1619
+ var controller, timeoutId, startedAt, attempt, requestVast, response, error, error1;
1496
1620
  return _ts_generator(this, function(_state) {
1497
1621
  switch(_state.label){
1498
1622
  case 0:
@@ -1504,17 +1628,51 @@ function createHlsAdPlayer(contentVideo, options) {
1504
1628
  timeoutId = controller ? setTimeout(function() {
1505
1629
  return controller.abort();
1506
1630
  }, VAST_REQUEST_TIMEOUT_MS) : void 0;
1631
+ startedAt = Date.now();
1632
+ attempt = 0;
1507
1633
  requestVast = function requestVast(creds) {
1508
- return fetch(vastTagUrl, _object_spread({
1509
- mode: "cors",
1510
- credentials: creds,
1511
- headers: {
1512
- "Accept": "application/xml, text/xml, */*"
1513
- },
1514
- referrerPolicy: "no-referrer-when-downgrade"
1515
- }, controller ? {
1516
- signal: controller.signal
1517
- } : {}));
1634
+ return _async_to_generator(function() {
1635
+ var response;
1636
+ return _ts_generator(this, function(_state) {
1637
+ switch(_state.label){
1638
+ case 0:
1639
+ attempt++;
1640
+ if (kind === "gam") {
1641
+ logFunnel("gam_http_request_sent", {
1642
+ attempt: attempt,
1643
+ credentials: creds
1644
+ });
1645
+ }
1646
+ return [
1647
+ 4,
1648
+ fetch(vastTagUrl, _object_spread({
1649
+ mode: "cors",
1650
+ credentials: creds,
1651
+ headers: {
1652
+ "Accept": "application/xml, text/xml, */*"
1653
+ },
1654
+ referrerPolicy: "no-referrer-when-downgrade"
1655
+ }, controller ? {
1656
+ signal: controller.signal
1657
+ } : {}))
1658
+ ];
1659
+ case 1:
1660
+ response = _state.sent();
1661
+ if (kind === "gam") {
1662
+ logFunnel("gam_response_received", {
1663
+ attempt: attempt,
1664
+ httpStatus: response.status,
1665
+ ok: response.ok,
1666
+ elapsedMs: Date.now() - startedAt
1667
+ });
1668
+ }
1669
+ return [
1670
+ 2,
1671
+ response
1672
+ ];
1673
+ }
1674
+ });
1675
+ })();
1518
1676
  };
1519
1677
  _state.label = 1;
1520
1678
  case 1:
@@ -1571,7 +1729,7 @@ function createHlsAdPlayer(contentVideo, options) {
1571
1729
  ];
1572
1730
  case 8:
1573
1731
  if (!response.ok) {
1574
- throw new Error("Failed to fetch VAST: ".concat(response.statusText));
1732
+ throw new Error("Failed to fetch VAST: HTTP ".concat(response.status, " ").concat(response.statusText));
1575
1733
  }
1576
1734
  return [
1577
1735
  4,
@@ -1586,7 +1744,7 @@ function createHlsAdPlayer(contentVideo, options) {
1586
1744
  error1 = _state.sent();
1587
1745
  if (controller === null || controller === void 0 ? void 0 : controller.signal.aborted) {
1588
1746
  if (pendingRequestAbortReason) {
1589
- throw new Error("".concat(pendingRequestAbortReason, " (timeout): ").concat(vastTagUrl));
1747
+ throw new Error("".concat(pendingRequestAbortReason, ": ").concat(vastTagUrl));
1590
1748
  }
1591
1749
  throw new Error("VAST request timeout after ".concat(VAST_REQUEST_TIMEOUT_MS, "ms: ").concat(vastTagUrl));
1592
1750
  }
@@ -1630,7 +1788,7 @@ function createHlsAdPlayer(contentVideo, options) {
1630
1788
  ]);
1631
1789
  return [
1632
1790
  4,
1633
- fetchVastXml(vastTagUrl, depth === 0 ? "include" : "omit")
1791
+ fetchVastXml(vastTagUrl, depth === 0 ? "include" : "omit", depth === 0 ? "gam" : "wrapper")
1634
1792
  ];
1635
1793
  case 2:
1636
1794
  vastXml = _state.sent();
@@ -1715,10 +1873,11 @@ function createHlsAdPlayer(contentVideo, options) {
1715
1873
  }
1716
1874
  function fetchAndParsePod(vastTagUrl) {
1717
1875
  return _async_to_generator(function() {
1718
- 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;
1876
+ 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;
1719
1877
  return _ts_generator(this, function(_state) {
1720
1878
  switch(_state.label){
1721
1879
  case 0:
1880
+ lastPodAdElementCount = 0;
1722
1881
  return [
1723
1882
  4,
1724
1883
  fetchVastXml(vastTagUrl)
@@ -1733,6 +1892,10 @@ function createHlsAdPlayer(contentVideo, options) {
1733
1892
  trimmedXml = vastXml.trim();
1734
1893
  if (trimmedXml.length === 0) {
1735
1894
  console.warn("[HlsAdPlayer] Pod VAST response body is empty (no fill)");
1895
+ logFunnel("vast_parsed", {
1896
+ adElementCount: 0,
1897
+ reason: "empty_body"
1898
+ });
1736
1899
  return [
1737
1900
  2,
1738
1901
  []
@@ -1741,6 +1904,10 @@ function createHlsAdPlayer(contentVideo, options) {
1741
1904
  xmlDoc = parseXml(vastXml);
1742
1905
  if (!xmlDoc) {
1743
1906
  console.error("[HlsAdPlayer] Pod VAST XML content (first 2000 chars):", vastXml.substring(0, 2e3));
1907
+ logFunnel("vast_parsed", {
1908
+ adElementCount: 0,
1909
+ reason: "xml_parse_error"
1910
+ });
1744
1911
  return [
1745
1912
  2,
1746
1913
  []
@@ -1748,10 +1915,21 @@ function createHlsAdPlayer(contentVideo, options) {
1748
1915
  }
1749
1916
  root = xmlDoc.documentElement;
1750
1917
  adElements = Array.from(root.querySelectorAll(":scope > Ad"));
1918
+ logFunnel("vast_parsed", {
1919
+ reason: adElements.length > 0 ? "has_ads" : "no_ads",
1920
+ vastVersion: (_root_getAttribute = root.getAttribute("version")) !== null && _root_getAttribute !== void 0 ? _root_getAttribute : void 0,
1921
+ adElementCount: adElements.length,
1922
+ inlineCount: adElements.filter(function(el) {
1923
+ return el.querySelector(":scope > InLine");
1924
+ }).length,
1925
+ wrapperCount: adElements.filter(function(el) {
1926
+ return el.querySelector(":scope > Wrapper");
1927
+ }).length
1928
+ });
1751
1929
  if (adElements.length === 0) {
1752
1930
  ;
1753
1931
  ;
1754
- 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)"));
1932
+ 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)"));
1755
1933
  empty = emptyVastResult(root);
1756
1934
  if (empty.type === "empty" && ((_empty_errorUrls = empty.errorUrls) === null || _empty_errorUrls === void 0 ? void 0 : _empty_errorUrls.length)) {
1757
1935
  ;
@@ -1769,10 +1947,15 @@ function createHlsAdPlayer(contentVideo, options) {
1769
1947
  var _parsed_errorUrls, parsed, _parsed_errorCode;
1770
1948
  return _ts_generator(this, function(_state) {
1771
1949
  parsed = parseAdElement(adElement);
1772
- if (parsed.type === "inline") return [
1773
- 2,
1774
- parsed.ad
1775
- ];
1950
+ if (parsed.type === "inline") {
1951
+ logFunnel("inline_resolved", {
1952
+ depth: 0
1953
+ });
1954
+ return [
1955
+ 2,
1956
+ parsed.ad
1957
+ ];
1958
+ }
1776
1959
  if (parsed.type === "wrapper") {
1777
1960
  return [
1778
1961
  2,
@@ -1950,7 +2133,8 @@ function createHlsAdPlayer(contentVideo, options) {
1950
2133
  7
1951
2134
  ];
1952
2135
  case 21:
1953
- 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"));
2136
+ 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"));
2137
+ lastPodAdElementCount = adElements.length;
1954
2138
  return [
1955
2139
  2,
1956
2140
  ads
@@ -3020,6 +3204,17 @@ function createHlsAdPlayer(contentVideo, options) {
3020
3204
  if (!ads.length && pendingRequestAbortReason) {
3021
3205
  throw new Error(pendingRequestAbortReason);
3022
3206
  }
3207
+ if (!ads.length && lastPodAdElementCount > 0) {
3208
+ console.warn("[HlsAdPlayer] VAST response had ads but none were playable");
3209
+ logFunnel("vast_fill_rejected", {
3210
+ adElementCount: lastPodAdElementCount
3211
+ });
3212
+ emit("ad_error");
3213
+ return [
3214
+ 2,
3215
+ Promise.reject(new Error("VAST fill rejected: no playable ad in response"))
3216
+ ];
3217
+ }
3023
3218
  if (!ads.length) {
3024
3219
  console.warn("[HlsAdPlayer] No ads available from VAST response");
3025
3220
  logFunnel("no_fill");
@@ -5461,6 +5656,21 @@ function normalizeVastTagUrl(raw) {
5461
5656
  return raw;
5462
5657
  }
5463
5658
  }
5659
+ var GAM_AD_HOSTS = /* @__PURE__ */ new Set([
5660
+ "pubads.g.doubleclick.net",
5661
+ "securepubads.g.doubleclick.net"
5662
+ ]);
5663
+ function ensureVideoAdType(rawUrl) {
5664
+ try {
5665
+ var url = new URL(rawUrl);
5666
+ if (!GAM_AD_HOSTS.has(url.hostname)) return rawUrl;
5667
+ if (url.searchParams.has("ad_type")) return rawUrl;
5668
+ url.searchParams.set("ad_type", "video");
5669
+ return url.toString();
5670
+ } catch (unused) {
5671
+ return rawUrl;
5672
+ }
5673
+ }
5464
5674
  function applyVastMacros(baseUrl, ctx) {
5465
5675
  var expandedUrl = expandInlineMacroPlaceholders(baseUrl, ctx);
5466
5676
  var url;
@@ -7174,7 +7384,7 @@ var AdConfigManager = /*#__PURE__*/ function() {
7174
7384
  } : {}), {
7175
7385
  consent: this.consentSignals
7176
7386
  }));
7177
- var finalUrl = palNonce.injectNonce(urlWithMacros);
7387
+ var finalUrl = palNonce.injectNonce(ensureVideoAdType(urlWithMacros));
7178
7388
  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);
7179
7389
  return finalUrl;
7180
7390
  }
@@ -8666,6 +8876,18 @@ function resizePlayer(video, adPlayer, debug) {
8666
8876
  }
8667
8877
  }
8668
8878
  // src/player/AdBreakOrchestrator.ts
8879
+ var REQUEST_FAILURE_STAGES = /* @__PURE__ */ new Set([
8880
+ "no_fill",
8881
+ "vast_fill_rejected",
8882
+ "request_failed",
8883
+ "media_unsupported",
8884
+ "play_failed",
8885
+ "play_resolved_but_never_started",
8886
+ "hls_fatal",
8887
+ "media_error",
8888
+ "stall",
8889
+ "decode_failure"
8890
+ ]);
8669
8891
  var AdBreakOrchestrator = /*#__PURE__*/ function() {
8670
8892
  "use strict";
8671
8893
  function AdBreakOrchestrator(host, timing, adConfig, cueManager, placeholder) {
@@ -8674,15 +8896,17 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8674
8896
  this.showAds = false;
8675
8897
  this.isShowingPlaceholder = false;
8676
8898
  this.adDetectSentForCurrentBreak = false;
8677
- this.continuousFetchingActive = false;
8678
- this.continuousFetchLoopRunning = false;
8899
+ this.slotState = "IDLE";
8900
+ this.unusableResponsesInBreak = 0;
8901
+ this.controllerGeneration = 0;
8902
+ this.requestDiagnostics = /* @__PURE__ */ new Map();
8679
8903
  this.breakFunnel = {};
8680
8904
  this.controllerCallInFlight = false;
8681
8905
  this.playbackStartedForCurrentRequest = false;
8682
8906
  this.opportunityEpoch = -1;
8683
- this.adRequestQueue = [];
8684
8907
  this.adPodQueue = [];
8685
- this.maxPlaceholderDurationMs = 5e3;
8908
+ this.defaultMinRemainingMsToRequestAd = 1e4;
8909
+ this.defaultMaxNoFillsPerBreak = 2;
8686
8910
  this.pendingAdBreak = null;
8687
8911
  this.host = host;
8688
8912
  this.timing = timing;
@@ -8718,7 +8942,23 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8718
8942
  key: "attachImaEventListeners",
8719
8943
  value: function attachImaEventListeners() {
8720
8944
  var _this = this;
8721
- var adPlayer = this.host.getAdPlayer();
8945
+ var controller = this.host.getAdPlayer();
8946
+ var generation = this.controllerGeneration;
8947
+ var adPlayer = {
8948
+ on: function on(event, handler) {
8949
+ controller.on(event, function(payload) {
8950
+ if (generation !== _this.controllerGeneration) {
8951
+ _this.logOrchestratorFunnel("stale_callback_ignored", {
8952
+ event: event,
8953
+ staleControllerId: generation,
8954
+ currentControllerId: _this.controllerGeneration
8955
+ });
8956
+ return;
8957
+ }
8958
+ handler(payload);
8959
+ });
8960
+ }
8961
+ };
8722
8962
  adPlayer.on("pod_ad_started", function(payload) {
8723
8963
  _this.timing.notePodAdStarted();
8724
8964
  if (_this.debug) {
@@ -8734,19 +8974,29 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8734
8974
  });
8735
8975
  adPlayer.on("ad_funnel", function(payload) {
8736
8976
  if (!(payload === null || payload === void 0 ? void 0 : payload.stage)) return;
8737
- _this.countFunnelStage(payload.stage);
8977
+ var stage = payload.stage;
8978
+ _this.countFunnelStage(stage);
8738
8979
  if (payload.reason) {
8739
- _this.countFunnelStage("".concat(payload.stage, ":").concat(payload.reason));
8980
+ _this.countFunnelStage("".concat(stage, ":").concat(payload.reason));
8740
8981
  }
8741
- if (payload.stage === "impression_fired" && payload.pixelCount != null) {
8982
+ if (stage === "impression_fired" && payload.pixelCount != null) {
8742
8983
  _this.countFunnelStage("impression_urls", payload.pixelCount);
8743
8984
  }
8744
8985
  if (payload.visibilityState === "hidden") {
8745
8986
  _this.countFunnelStage("while_hidden");
8746
8987
  }
8988
+ if (stage === "gam_http_request_sent") {
8989
+ if (payload.attempt === 1) {
8990
+ _this.timing.noteAdRequestSent();
8991
+ } else {
8992
+ _this.countFunnelStage("gam_http_request_retry");
8993
+ }
8994
+ }
8995
+ _this.recordRequestDiagnostic(payload);
8747
8996
  });
8748
8997
  adPlayer.on("ad_impression", function() {
8749
8998
  _this.timing.consecutiveFailures = 0;
8999
+ _this.setSlotState("PLAYING", "impression");
8750
9000
  if (!_this.playbackStartedForCurrentRequest) {
8751
9001
  _this.playbackStartedForCurrentRequest = true;
8752
9002
  _this.timing.markAdStarted();
@@ -8765,16 +9015,11 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8765
9015
  var remaining = _this.timing.getRemainingAdMs();
8766
9016
  _this.timing.consecutiveFailures = 0;
8767
9017
  if (_this.debug) {
8768
- console.log("[StormcloudVideoPlayer] all_ads_completed event received - remaining=".concat(remaining, "ms, queued ads=").concat(_this.adRequestQueue.length), _this.adRequestQueue.length > 0 ? {
8769
- queuedUrls: _to_consumable_array(_this.adRequestQueue)
8770
- } : {});
9018
+ console.log("[StormcloudVideoPlayer] all_ads_completed event received - remaining=".concat(remaining, "ms"));
8771
9019
  }
8772
9020
  if (_this.inAdBreak) {
8773
- if (_this.timing.hasTimeToStartAnotherAd()) {
8774
- _this.tryNextAvailableAdWithRateLimit();
8775
- } else {
8776
- _this.handleAdPodComplete();
8777
- }
9021
+ _this.setSlotState("NEEDS_NEXT_AD", "all_ads_completed");
9022
+ _this.requestNextAd("all_ads_completed");
8778
9023
  }
8779
9024
  });
8780
9025
  adPlayer.on("ad_error", function(errorPayload) {
@@ -8795,10 +9040,9 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8795
9040
  }
8796
9041
  console.error("[AD-ERROR]", errorMessage, errorPayload || "");
8797
9042
  if (_this.controllerCallInFlight) {
8798
- _this.timing.recordGamNoFill();
8799
9043
  return;
8800
9044
  }
8801
- _this.handleAdFailure();
9045
+ _this.handleAdFailure("ad_error");
8802
9046
  });
8803
9047
  adPlayer.on("content_pause", function() {
8804
9048
  _this.timing.clearAdFailsafeTimer();
@@ -8837,26 +9081,32 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8837
9081
  }
8838
9082
  _this.timing.consecutiveFailures = 0;
8839
9083
  _this.timing.recordPlayedAdDuration(_this.host.getAdPlayer());
8840
- var remaining = _this.timing.getRemainingAdMs();
8841
9084
  if (_this.debug) {
8842
- console.log("[CONTINUOUS-FETCH] content_resume event: remaining=".concat(remaining, "ms, queued ads=").concat(_this.adRequestQueue.length), _this.adRequestQueue.length > 0 ? {
8843
- queuedUrls: _to_consumable_array(_this.adRequestQueue)
8844
- } : {});
8845
- }
8846
- if (_this.timing.hasTimeToStartAnotherAd()) {
8847
- _this.tryNextAvailableAdWithRateLimit();
8848
- } else {
8849
- _this.handleAdPodComplete();
9085
+ console.log("[AdBreak] content_resume: remaining=".concat(_this.timing.getRemainingAdMs(), "ms"));
8850
9086
  }
9087
+ _this.setSlotState("NEEDS_NEXT_AD", "ad_complete");
9088
+ _this.requestNextAd("ad_complete");
8851
9089
  });
8852
9090
  }
8853
9091
  },
8854
9092
  {
8855
9093
  key: "recreateAdController",
8856
- value: function recreateAdController() {
8857
- if (this.debug) {
8858
- console.log("[StormcloudVideoPlayer] Recreating AdController for new ad");
9094
+ value: function recreateAdController(reason) {
9095
+ if (reason === "new_request" && (this.slotState === "REQUESTING" || this.slotState === "READY")) {
9096
+ console.warn("[AD-CONTROLLER] destroy during active request", {
9097
+ controllerId: this.controllerGeneration,
9098
+ requestId: this.currentRequestId,
9099
+ state: this.slotState,
9100
+ reason: reason
9101
+ });
8859
9102
  }
9103
+ console.log("[AD-CONTROLLER] destroy", {
9104
+ controllerId: this.controllerGeneration,
9105
+ requestId: this.currentRequestId,
9106
+ state: this.slotState,
9107
+ reason: reason
9108
+ });
9109
+ this.countFunnelStage("controller_destroy:".concat(reason));
8860
9110
  var shouldShowPlaceholder = this.inAdBreak && this.showAds;
8861
9111
  var adPlayer = this.host.getAdPlayer();
8862
9112
  if (shouldShowPlaceholder && adPlayer) {
@@ -8883,9 +9133,16 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8883
9133
  var continueLiveStreamDuringAds = this.host.shouldContinueLiveStreamDuringAds();
8884
9134
  var newAdPlayer = this.host.createAdPlayer(continueLiveStreamDuringAds);
8885
9135
  this.host.setAdPlayer(newAdPlayer);
9136
+ this.controllerGeneration++;
8886
9137
  newAdPlayer.initialize();
8887
9138
  newAdPlayer.updateOriginalMutedState(preservedMutedState, preservedVolumeState);
8888
9139
  this.attachImaEventListeners();
9140
+ if (this.debug) {
9141
+ console.log("[AD-CONTROLLER] create", {
9142
+ controllerId: this.controllerGeneration,
9143
+ reason: reason
9144
+ });
9145
+ }
8889
9146
  if (shouldShowPlaceholder) {
8890
9147
  this.placeholder.show();
8891
9148
  newAdPlayer.showPlaceholder();
@@ -8906,32 +9163,57 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8906
9163
  }
8907
9164
  },
8908
9165
  {
8909
- key: "handleAdStart",
8910
- value: // ───────────────────────────────────────────────────────────────
9166
+ // ───────────────────────────────────────────────────────────────
8911
9167
  // Ad break start
8912
9168
  // ───────────────────────────────────────────────────────────────
8913
- function handleAdStart(_marker) {
9169
+ key: "isBreakActive",
9170
+ value: function isBreakActive() {
9171
+ return this.slotState !== "IDLE";
9172
+ }
9173
+ },
9174
+ {
9175
+ key: "getSlotState",
9176
+ value: function getSlotState() {
9177
+ return this.slotState;
9178
+ }
9179
+ },
9180
+ {
9181
+ key: "beginVmapBreak",
9182
+ value: function beginVmapBreak(breakKey) {
9183
+ this.breakSource = "vmap";
9184
+ this.followUpBaseVastUrl = void 0;
9185
+ this.unusableResponsesInBreak = 0;
9186
+ this.timing.totalAdRequestsInBreak = 0;
9187
+ this.setSlotState("NEEDS_NEXT_AD", "vmap_break_start");
9188
+ this.noteOpportunity("vmap", breakKey);
9189
+ }
9190
+ },
9191
+ {
9192
+ key: "handleAdStart",
9193
+ value: function handleAdStart(marker) {
8914
9194
  return _async_to_generator(function() {
8915
- var scheduled, tags, baseVastUrl, adBreakDurationMs, mode, currentMuted, currentVolume, podPlayed;
9195
+ var baseVastUrl, adBreakDurationMs, mode, currentMuted, currentVolume, epoch, podPlayed;
8916
9196
  return _ts_generator(this, function(_state) {
8917
9197
  switch(_state.label){
8918
9198
  case 0:
8919
- scheduled = this.adConfig.findCurrentOrNextBreak(this.host.video.currentTime * 1e3);
8920
- if (scheduled) {
8921
- this.adConfig.consumedVmapBreakIds.add(this.adConfig.getAdBreakKey(scheduled));
9199
+ if (this.slotState !== "IDLE") {
9200
+ this.logOrchestratorFunnel("duplicate_break_start", {
9201
+ source: "scte35",
9202
+ state: this.slotState
9203
+ });
9204
+ return [
9205
+ 2
9206
+ ];
8922
9207
  }
8923
- tags = this.adConfig.selectVastTagsForBreak(scheduled);
8924
- if (tags && tags.length > 0 && tags[0]) {
8925
- baseVastUrl = tags[0];
8926
- } else if (this.adConfig.apiVastTagUrl) {
8927
- baseVastUrl = this.adConfig.apiVastTagUrl;
8928
- } else {
9208
+ baseVastUrl = this.adConfig.apiVastTagUrl;
9209
+ if (!baseVastUrl) {
9210
+ console.warn("[AdBreak] SCTE-35 break started but no direct VAST tag is configured");
8929
9211
  this.clearPendingAdBreak();
8930
9212
  return [
8931
9213
  2
8932
9214
  ];
8933
9215
  }
8934
- adBreakDurationMs = _marker.durationSeconds != null ? _marker.durationSeconds * 1e3 : scheduled === null || scheduled === void 0 ? void 0 : scheduled.durationMs;
9216
+ adBreakDurationMs = marker.durationSeconds != null ? marker.durationSeconds * 1e3 : this.timing.expectedAdBreakDurationMs;
8935
9217
  if (this.debug) {
8936
9218
  mode = this.host.config.isLiveStream ? "LIVE" : "VOD";
8937
9219
  console.log("[CONTINUOUS-FETCH] ".concat(mode, " MODE: Target duration=").concat(adBreakDurationMs, "ms"));
@@ -8939,9 +9221,12 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8939
9221
  this.timing.failedVastUrls.clear();
8940
9222
  this.timing.temporaryFailureUrls.clear();
8941
9223
  this.timing.consecutiveFailures = 0;
8942
- this.continuousFetchingActive = true;
8943
9224
  this.isShowingPlaceholder = false;
8944
9225
  this.timing.totalAdRequestsInBreak = 0;
9226
+ this.breakSource = "scte35";
9227
+ this.followUpBaseVastUrl = baseVastUrl;
9228
+ this.unusableResponsesInBreak = 0;
9229
+ this.setSlotState("NEEDS_NEXT_AD", "scte35_break_start");
8945
9230
  if (this.adConfig.podAssignedByPrefetch) {
8946
9231
  this.adConfig.podAssignedByPrefetch = false;
8947
9232
  } else {
@@ -8960,29 +9245,17 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8960
9245
  this.timing.expectedAdBreakDurationMs = adBreakDurationMs;
8961
9246
  }
8962
9247
  this.noteOpportunity("scte35", this.cueManager.activeScte35BreakKey);
9248
+ epoch = this.timing.adBreakEpoch;
8963
9249
  return [
8964
9250
  4,
8965
9251
  this.startOptimizedPod(baseVastUrl, adBreakDurationMs)
8966
9252
  ];
8967
9253
  case 1:
8968
9254
  podPlayed = _state.sent();
8969
- if (!!podPlayed) return [
8970
- 3,
8971
- 3
8972
- ];
8973
- if (this.debug) {
8974
- console.log("[POD] Initial pod request did not fill; attempting top-up pod request");
9255
+ if (!podPlayed && this.inAdBreak && epoch === this.timing.adBreakEpoch) {
9256
+ this.setSlotState("NEEDS_NEXT_AD", "initial_request_failed");
9257
+ this.requestNextAd("initial_request_failed");
8975
9258
  }
8976
- this.continuousFetchingActive = true;
8977
- this.startContinuousFetching(baseVastUrl);
8978
- return [
8979
- 4,
8980
- this.tryNextAvailableAdWithRateLimit()
8981
- ];
8982
- case 2:
8983
- _state.sent();
8984
- _state.label = 3;
8985
- case 3:
8986
9259
  return [
8987
9260
  2
8988
9261
  ];
@@ -8998,10 +9271,11 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8998
9271
  // ───────────────────────────────────────────────────────────────
8999
9272
  function startOptimizedPod(baseVastUrl, breakDurationMs) {
9000
9273
  return _async_to_generator(function() {
9001
- var podUrl, adPlayer, requestToken, _ref, _adPlayer_getPodAdCount, podCount, error;
9274
+ var podUrl, prefetched, epoch, generation, adPlayer, requestToken, _ref, _adPlayer_getPodAdCount, podCount, error;
9002
9275
  return _ts_generator(this, function(_state) {
9003
9276
  switch(_state.label){
9004
9277
  case 0:
9278
+ prefetched = !!(this.pendingAdBreak && this.pendingAdBreak.vastUrls.length > 0);
9005
9279
  if (this.pendingAdBreak && this.pendingAdBreak.vastUrls.length > 0) {
9006
9280
  podUrl = this.pendingAdBreak.vastUrls[0];
9007
9281
  this.clearPendingAdBreak();
@@ -9014,12 +9288,16 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9014
9288
  false
9015
9289
  ];
9016
9290
  }
9017
- this.continuousFetchingActive = false;
9018
- this.recreateAdController();
9291
+ this.noteVastUrlGenerated(podUrl, prefetched ? "prefetch" : "break_start");
9292
+ epoch = this.timing.adBreakEpoch;
9293
+ this.recreateAdController("new_request");
9294
+ generation = this.controllerGeneration;
9019
9295
  adPlayer = this.host.getAdPlayer();
9020
9296
  requestToken = ++this.timing.adRequestTokenCounter;
9021
9297
  this.timing.activeAdRequestToken = requestToken;
9022
9298
  this.currentVastUrl = podUrl;
9299
+ this.setSlotState("REQUESTING", "initial_pod");
9300
+ this.beginFunnelRequest(adPlayer, requestToken, "initial_pod");
9023
9301
  _state.label = 1;
9024
9302
  case 1:
9025
9303
  _state.trys.push([
@@ -9034,9 +9312,11 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9034
9312
  ];
9035
9313
  case 2:
9036
9314
  _state.sent();
9315
+ if (this.isStale(epoch, generation)) return [
9316
+ 2,
9317
+ true
9318
+ ];
9037
9319
  this.timing.startAdRequestWatchdog(requestToken);
9038
- this.timing.noteAdRequestSent();
9039
- this.beginFunnelRequest(adPlayer, requestToken);
9040
9320
  return [
9041
9321
  4,
9042
9322
  this.callController(function() {
@@ -9046,7 +9326,10 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9046
9326
  case 3:
9047
9327
  _state.sent();
9048
9328
  this.timing.clearAdRequestWatchdog();
9049
- if (this.timing.activeAdRequestToken !== requestToken) {
9329
+ if (this.isStale(epoch, generation)) {
9330
+ this.logOrchestratorFunnel("stale_request_result_ignored", {
9331
+ requestId: requestToken
9332
+ });
9050
9333
  return [
9051
9334
  2,
9052
9335
  true
@@ -9054,11 +9337,16 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9054
9337
  }
9055
9338
  podCount = (_ref = (_adPlayer_getPodAdCount = adPlayer.getPodAdCount) === null || _adPlayer_getPodAdCount === void 0 ? void 0 : _adPlayer_getPodAdCount.call(adPlayer)) !== null && _ref !== void 0 ? _ref : 1;
9056
9339
  if (podCount < 1) {
9340
+ if (this.timing.activeAdRequestToken === requestToken) {
9341
+ this.timing.activeAdRequestToken = null;
9342
+ }
9343
+ this.recordRequestFailure(new Error("No ads available"), podUrl);
9057
9344
  return [
9058
9345
  2,
9059
9346
  false
9060
9347
  ];
9061
9348
  }
9349
+ this.setSlotState("READY", "vast_ready");
9062
9350
  if (this.debug) {
9063
9351
  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"));
9064
9352
  }
@@ -9076,12 +9364,14 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9076
9364
  ];
9077
9365
  case 4:
9078
9366
  _state.sent();
9367
+ if (this.isStale(epoch, generation)) return [
9368
+ 2,
9369
+ true
9370
+ ];
9079
9371
  if (this.timing.expectedAdBreakDurationMs != null && this.timing.getAdBreakEndWallClockMs() == null) {
9080
9372
  this.timing.scheduleAdStopAtBreakBoundary();
9081
9373
  }
9082
9374
  adPlayer.setAdVolume(getAdAudioVolume(adPlayer));
9083
- this.continuousFetchingActive = true;
9084
- this.startContinuousFetching(baseVastUrl);
9085
9375
  return [
9086
9376
  2,
9087
9377
  true
@@ -9093,14 +9383,20 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9093
9383
  if (this.timing.activeAdRequestToken === requestToken) {
9094
9384
  this.timing.activeAdRequestToken = null;
9095
9385
  }
9386
+ if (this.isStale(epoch, generation)) {
9387
+ this.logOrchestratorFunnel("stale_request_result_ignored", {
9388
+ requestId: requestToken,
9389
+ errorMessage: error === null || error === void 0 ? void 0 : error.message
9390
+ });
9391
+ return [
9392
+ 2,
9393
+ true
9394
+ ];
9395
+ }
9096
9396
  if (this.debug) {
9097
9397
  console.warn("[POD] Optimized pod request/play failed:", error);
9098
9398
  }
9099
- if (this.timing.isTemporaryAdError(error)) {
9100
- this.timing.temporaryFailureUrls.set(podUrl, Date.now());
9101
- }
9102
- this.continuousFetchingActive = true;
9103
- this.recreateAdController();
9399
+ this.recordRequestFailure(error, podUrl);
9104
9400
  return [
9105
9401
  2,
9106
9402
  false
@@ -9116,168 +9412,204 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9116
9412
  },
9117
9413
  {
9118
9414
  // ───────────────────────────────────────────────────────────────
9119
- // Continuous fetching
9415
+ // Next-ad scheduling (single flight)
9120
9416
  // ───────────────────────────────────────────────────────────────
9121
- key: "startContinuousFetching",
9122
- value: function startContinuousFetching(baseVastUrl) {
9123
- if (!this.continuousFetchingActive) {
9417
+ key: "setSlotState",
9418
+ value: function setSlotState(next, reason) {
9419
+ if (this.slotState === next) return;
9420
+ var previous = this.slotState;
9421
+ this.slotState = next;
9422
+ if (this.debug) {
9423
+ console.log("[AdBreak][STATE] ".concat(previous, " -> ").concat(next), {
9424
+ reason: reason,
9425
+ breakId: this.timing.adBreakEpoch,
9426
+ requestId: this.currentRequestId,
9427
+ controllerId: this.controllerGeneration
9428
+ });
9429
+ }
9430
+ }
9431
+ },
9432
+ {
9433
+ key: "isStale",
9434
+ value: function isStale(epoch, generation) {
9435
+ return !this.inAdBreak || epoch !== this.timing.adBreakEpoch || generation !== this.controllerGeneration;
9436
+ }
9437
+ },
9438
+ {
9439
+ key: "getMinRemainingMsToRequestAd",
9440
+ value: function getMinRemainingMsToRequestAd() {
9441
+ var configured = this.host.config.minRemainingMsToRequestAd;
9442
+ var floor = this.timing.getMinRemainingMsToStartAd();
9443
+ if (typeof configured === "number" && configured >= 0) {
9444
+ return Math.max(configured, floor);
9445
+ }
9446
+ return Math.max(this.defaultMinRemainingMsToRequestAd, floor);
9447
+ }
9448
+ },
9449
+ {
9450
+ key: "getMaxNoFillsPerBreak",
9451
+ value: function getMaxNoFillsPerBreak() {
9452
+ var configured = this.host.config.maxNoFillsPerBreak;
9453
+ return typeof configured === "number" && configured > 0 ? configured : this.defaultMaxNoFillsPerBreak;
9454
+ }
9455
+ },
9456
+ {
9457
+ key: "isBreakTimeBounded",
9458
+ value: function isBreakTimeBounded() {
9459
+ return this.breakSource === "scte35" || this.timing.expectedAdBreakDurationMs != null;
9460
+ }
9461
+ },
9462
+ {
9463
+ key: "getStopRequestingReason",
9464
+ value: function getStopRequestingReason(remainingMs) {
9465
+ if (this.breakSource === "vmap") {
9466
+ if (this.adPodQueue.length === 0) return "vmap_queue_empty";
9467
+ } else if (this.breakSource !== "scte35" || !this.followUpBaseVastUrl) {
9468
+ return "no_follow_up_source";
9469
+ }
9470
+ if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
9471
+ return "max_consecutive_failures";
9472
+ }
9473
+ if (this.unusableResponsesInBreak >= this.getMaxNoFillsPerBreak()) {
9474
+ return "unusable_response_limit";
9475
+ }
9476
+ if (this.timing.totalAdRequestsInBreak >= this.timing.maxTotalAdRequestsPerBreak) {
9477
+ return "request_cap";
9478
+ }
9479
+ if (this.timing.isGamInCooldown()) {
9480
+ return "gam_cooldown";
9481
+ }
9482
+ if (this.isBreakTimeBounded() && remainingMs < this.getMinRemainingMsToRequestAd()) {
9483
+ return "insufficient_break_time";
9484
+ }
9485
+ return void 0;
9486
+ }
9487
+ },
9488
+ {
9489
+ key: "getNextRequestDelayMs",
9490
+ value: function getNextRequestDelayMs() {
9491
+ var failures = this.timing.consecutiveFailures;
9492
+ var backoff = failures > 0 ? Math.min(this.timing.backoffBaseMs * Math.pow(2, failures), this.timing.maxBackoffMs) : 0;
9493
+ var minInterval = this.timing.minAdRequestIntervalMs + backoff;
9494
+ var sinceLast = Date.now() - this.timing.lastAdRequestTime;
9495
+ return Math.max(0, minInterval - sinceLast);
9496
+ }
9497
+ },
9498
+ {
9499
+ key: "requestNextAd",
9500
+ value: function requestNextAd(trigger) {
9501
+ var _this = this;
9502
+ if (!this.inAdBreak) return;
9503
+ if (this.slotState !== "NEEDS_NEXT_AD") {
9504
+ this.logOrchestratorFunnel("request_suppressed", {
9505
+ trigger: trigger,
9506
+ state: this.slotState,
9507
+ why: "slot_busy"
9508
+ });
9124
9509
  return;
9125
9510
  }
9126
- if (this.continuousFetchLoopRunning) {
9127
- if (this.debug) {
9128
- console.log("[CONTINUOUS-FETCH] Fetch loop already running, skipping duplicate start");
9129
- }
9511
+ if (this.nextAdTimerId != null) {
9512
+ this.logOrchestratorFunnel("request_suppressed", {
9513
+ trigger: trigger,
9514
+ state: this.slotState,
9515
+ why: "request_already_scheduled"
9516
+ });
9130
9517
  return;
9131
9518
  }
9132
- if (this.debug) {
9133
- console.log("[CONTINUOUS-FETCH] Starting continuous ad fetching loop");
9519
+ var remainingMs = this.timing.getRemainingAdMs();
9520
+ var stopReason = this.getStopRequestingReason(remainingMs);
9521
+ if (stopReason) {
9522
+ this.logOrchestratorFunnel("next_ad_decision", {
9523
+ trigger: trigger,
9524
+ decision: "end_break",
9525
+ reason: stopReason,
9526
+ remainingMs: remainingMs,
9527
+ requestsSent: this.timing.totalAdRequestsInBreak,
9528
+ unusableResponses: this.unusableResponsesInBreak,
9529
+ consecutiveFailures: this.timing.consecutiveFailures
9530
+ });
9531
+ this.handleAdPodComplete(stopReason);
9532
+ return;
9533
+ }
9534
+ var waitMs = this.getNextRequestDelayMs();
9535
+ if (waitMs > 0 && this.isBreakTimeBounded() && remainingMs - waitMs < this.getMinRemainingMsToRequestAd()) {
9536
+ this.logOrchestratorFunnel("next_ad_decision", {
9537
+ trigger: trigger,
9538
+ decision: "end_break",
9539
+ reason: "insufficient_break_time_after_backoff",
9540
+ remainingMs: remainingMs,
9541
+ waitMs: waitMs
9542
+ });
9543
+ this.handleAdPodComplete("insufficient_break_time_after_backoff");
9544
+ return;
9545
+ }
9546
+ this.logOrchestratorFunnel("next_ad_decision", {
9547
+ trigger: trigger,
9548
+ decision: waitMs > 0 ? "request_after_delay" : "request_now",
9549
+ waitMs: waitMs,
9550
+ remainingMs: remainingMs,
9551
+ consecutiveFailures: this.timing.consecutiveFailures
9552
+ });
9553
+ if (waitMs > 0) {
9554
+ if (!this.isShowingPlaceholder) {
9555
+ this.isShowingPlaceholder = true;
9556
+ this.host.getAdPlayer().showPlaceholder();
9557
+ }
9558
+ var epoch = this.timing.adBreakEpoch;
9559
+ this.nextAdTimerId = window.setTimeout(function() {
9560
+ _this.nextAdTimerId = void 0;
9561
+ if (!_this.inAdBreak || epoch !== _this.timing.adBreakEpoch) return;
9562
+ _this.requestNextAd("".concat(trigger, ":after_delay"));
9563
+ }, waitMs);
9564
+ return;
9134
9565
  }
9135
- this.continuousFetchLoopRunning = true;
9136
- this.continuousFetchLoop(baseVastUrl);
9566
+ void this.requestFollowUpAd(trigger);
9137
9567
  }
9138
9568
  },
9139
9569
  {
9140
- key: "continuousFetchLoop",
9141
- value: function continuousFetchLoop(baseVastUrl) {
9570
+ key: "requestFollowUpAd",
9571
+ value: function requestFollowUpAd(trigger) {
9142
9572
  return _async_to_generator(function() {
9143
- var _this, _loop, epoch, _ret;
9573
+ var url, epoch, unused;
9144
9574
  return _ts_generator(this, function(_state) {
9145
9575
  switch(_state.label){
9146
9576
  case 0:
9147
- _loop = function() {
9148
- var remaining, maxQueueSize, newAdUrl, queuedUrlsPreview, generationDelay;
9149
- return _ts_generator(this, function(_state) {
9150
- switch(_state.label){
9151
- case 0:
9152
- remaining = Math.min(_this.timing.getWallClockRemainingAdMs(), _this.timing.getDurationBudgetRemainingMs());
9153
- if (remaining <= _this.timing.getMinRemainingMsToStartAd()) {
9154
- if (_this.debug) {
9155
- 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"));
9156
- }
9157
- return [
9158
- 2,
9159
- "break"
9160
- ];
9161
- }
9162
- if (_this.timing.isGamInCooldown()) {
9163
- if (_this.debug) {
9164
- console.log("[CIRCUIT-BREAKER] GAM in cooldown, stopping URL generation");
9165
- }
9166
- return [
9167
- 2,
9168
- "break"
9169
- ];
9170
- }
9171
- if (_this.timing.consecutiveFailures >= _this.timing.maxConsecutiveFailures) {
9172
- if (_this.debug) {
9173
- console.log("[CONTINUOUS-FETCH] Too many consecutive failures (".concat(_this.timing.consecutiveFailures, "), stopping URL generation"));
9174
- }
9175
- return [
9176
- 2,
9177
- "break"
9178
- ];
9179
- }
9180
- if (_this.timing.totalAdRequestsInBreak >= _this.timing.maxTotalAdRequestsPerBreak) {
9181
- if (_this.debug) {
9182
- console.log("[CONTINUOUS-FETCH] Maximum ad requests reached (".concat(_this.timing.maxTotalAdRequestsPerBreak, "), stopping"));
9183
- }
9184
- return [
9185
- 2,
9186
- "break"
9187
- ];
9188
- }
9189
- maxQueueSize = 5;
9190
- if (!(_this.adRequestQueue.length >= maxQueueSize)) return [
9191
- 3,
9192
- 2
9193
- ];
9194
- if (_this.debug) {
9195
- console.log("[CONTINUOUS-FETCH] URL queue full (".concat(_this.adRequestQueue.length, "), waiting..."));
9196
- }
9197
- return [
9198
- 4,
9199
- new Promise(function(resolve) {
9200
- return setTimeout(resolve, 1e3);
9201
- })
9202
- ];
9203
- case 1:
9204
- _state.sent();
9205
- return [
9206
- 2,
9207
- "continue"
9208
- ];
9209
- case 2:
9210
- newAdUrl = _this.nextAdRequestUrl(baseVastUrl);
9211
- if (!(!newAdUrl || _this.timing.failedVastUrls.has(newAdUrl) || _this.timing.isUrlInCooldown(newAdUrl))) return [
9212
- 3,
9213
- 4
9214
- ];
9215
- return [
9216
- 4,
9217
- new Promise(function(resolve) {
9218
- return setTimeout(resolve, 500);
9219
- })
9220
- ];
9221
- case 3:
9222
- _state.sent();
9223
- return [
9224
- 2,
9225
- "continue"
9226
- ];
9227
- case 4:
9228
- if (_this.debug) {
9229
- queuedUrlsPreview = _to_consumable_array(_this.adRequestQueue).concat([
9230
- newAdUrl
9231
- ]);
9232
- console.log("[CONTINUOUS-FETCH] Queued VAST URL (queue size: ".concat(queuedUrlsPreview.length, ")"), {
9233
- queuedUrls: queuedUrlsPreview
9234
- });
9235
- }
9236
- _this.adRequestQueue.push(newAdUrl);
9237
- generationDelay = _this.timing.consecutiveFailures > 0 ? Math.min(1e3 * Math.pow(2, _this.timing.consecutiveFailures), 5e3) : 500;
9238
- return [
9239
- 4,
9240
- new Promise(function(resolve) {
9241
- return setTimeout(resolve, generationDelay);
9242
- })
9243
- ];
9244
- case 5:
9245
- _state.sent();
9246
- return [
9247
- 2
9248
- ];
9249
- }
9250
- });
9251
- };
9577
+ if (this.breakSource === "vmap") {
9578
+ url = this.adPodQueue.shift();
9579
+ } else if (this.followUpBaseVastUrl) {
9580
+ url = this.nextAdRequestUrl(this.followUpBaseVastUrl);
9581
+ }
9582
+ if (!url) return [
9583
+ 2
9584
+ ];
9585
+ this.noteVastUrlGenerated(ensureVideoAdType(url), trigger);
9252
9586
  epoch = this.timing.adBreakEpoch;
9253
9587
  _state.label = 1;
9254
9588
  case 1:
9255
- if (!(this.continuousFetchingActive && this.inAdBreak && epoch === this.timing.adBreakEpoch)) return [
9256
- 3,
9257
- 3
9258
- ];
9259
- _this = this;
9589
+ _state.trys.push([
9590
+ 1,
9591
+ 3,
9592
+ ,
9593
+ 4
9594
+ ]);
9260
9595
  return [
9261
- 5,
9262
- _ts_values(_loop())
9596
+ 4,
9597
+ this.playSingleAd(url, trigger)
9263
9598
  ];
9264
9599
  case 2:
9265
- _ret = _state.sent();
9266
- if (_ret === "break") return [
9600
+ _state.sent();
9601
+ return [
9267
9602
  3,
9268
- 3
9603
+ 4
9269
9604
  ];
9605
+ case 3:
9606
+ unused = _state.sent();
9607
+ this.continueAfterRequestFailure(epoch);
9270
9608
  return [
9271
9609
  3,
9272
- 1
9610
+ 4
9273
9611
  ];
9274
- case 3:
9275
- this.continuousFetchLoopRunning = false;
9276
- if (this.debug) {
9277
- console.log("[CONTINUOUS-FETCH] URL generation loop ended (queued: ".concat(this.adRequestQueue.length, ")"), this.adRequestQueue.length > 0 ? {
9278
- queuedUrls: _to_consumable_array(this.adRequestQueue)
9279
- } : {});
9280
- }
9612
+ case 4:
9281
9613
  return [
9282
9614
  2
9283
9615
  ];
@@ -9287,242 +9619,158 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9287
9619
  }
9288
9620
  },
9289
9621
  {
9290
- key: "stopContinuousFetching",
9291
- value: function stopContinuousFetching() {
9292
- this.continuousFetchingActive = false;
9293
- this.continuousFetchLoopRunning = false;
9294
- this.placeholder.hide();
9295
- if (this.debug) {
9296
- console.log("[CONTINUOUS-FETCH] Stopping continuous ad fetching");
9622
+ key: "continueAfterRequestFailure",
9623
+ value: function continueAfterRequestFailure() {
9624
+ var epoch = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.timing.adBreakEpoch;
9625
+ if (!this.inAdBreak || epoch !== this.timing.adBreakEpoch) return;
9626
+ this.setSlotState("NEEDS_NEXT_AD", "request_failed");
9627
+ this.requestNextAd("after_failure");
9628
+ }
9629
+ },
9630
+ {
9631
+ key: "cancelScheduledRequest",
9632
+ value: function cancelScheduledRequest() {
9633
+ if (this.nextAdTimerId != null) {
9634
+ clearTimeout(this.nextAdTimerId);
9635
+ this.nextAdTimerId = void 0;
9297
9636
  }
9298
9637
  }
9299
9638
  },
9300
9639
  {
9301
- key: "tryNextAvailableAdWithRateLimit",
9302
- value: // ───────────────────────────────────────────────────────────────
9303
- // Ad iteration
9640
+ key: "noteVastUrlGenerated",
9641
+ value: function noteVastUrlGenerated(url, source) {
9642
+ var _ref, _ref1, _ref2, _ref3, _ref4;
9643
+ var params;
9644
+ try {
9645
+ params = new URL(url).searchParams;
9646
+ } catch (unused) {}
9647
+ var adType = (_ref = params === null || params === void 0 ? void 0 : params.get("ad_type")) !== null && _ref !== void 0 ? _ref : void 0;
9648
+ this.logOrchestratorFunnel("vast_url_generated", {
9649
+ source: source,
9650
+ pod: (_ref1 = params === null || params === void 0 ? void 0 : params.get("pod")) !== null && _ref1 !== void 0 ? _ref1 : void 0,
9651
+ pmad: (_ref2 = params === null || params === void 0 ? void 0 : params.get("pmad")) !== null && _ref2 !== void 0 ? _ref2 : void 0,
9652
+ pmnd: (_ref3 = params === null || params === void 0 ? void 0 : params.get("pmnd")) !== null && _ref3 !== void 0 ? _ref3 : void 0,
9653
+ pmxd: (_ref4 = params === null || params === void 0 ? void 0 : params.get("pmxd")) !== null && _ref4 !== void 0 ? _ref4 : void 0,
9654
+ adType: adType
9655
+ });
9656
+ if (adType === "audio" || adType === "audio_video") {
9657
+ console.warn("[AdBreak] VAST tag requests ad_type=".concat(adType, "; GAM may return audio-only creatives, which this video player rejects"));
9658
+ this.countFunnelStage("tag_allows_audio");
9659
+ }
9660
+ }
9661
+ },
9662
+ {
9663
+ key: "recordRequestFailure",
9664
+ value: function recordRequestFailure(error, vastTagUrl) {
9665
+ var _diag_vastAdCount;
9666
+ var diag = this.currentRequestId != null ? this.requestDiagnostics.get(this.currentRequestId) : void 0;
9667
+ var message = (error === null || error === void 0 ? void 0 : error.message) || "";
9668
+ var outcome;
9669
+ if (message.includes("ad_duration_exceeds_budget")) {
9670
+ outcome = "discarded_budget";
9671
+ } else if (message.includes("VAST fill rejected")) {
9672
+ outcome = "fill_rejected";
9673
+ } else if (/no ads available|no fill|nofill/i.test(message)) {
9674
+ outcome = "no_fill";
9675
+ } else if (/timeout/i.test(message)) {
9676
+ outcome = "request_timeout";
9677
+ } else if (/destroyed|aborted/i.test(message)) {
9678
+ outcome = "request_aborted";
9679
+ } else if (diag && ((_diag_vastAdCount = diag.vastAdCount) !== null && _diag_vastAdCount !== void 0 ? _diag_vastAdCount : 0) > 0 && !diag.impressionFired) {
9680
+ outcome = "playback_failed";
9681
+ } else {
9682
+ outcome = "request_failed";
9683
+ }
9684
+ this.timing.consecutiveFailures++;
9685
+ if (outcome === "no_fill" || outcome === "fill_rejected" || outcome === "discarded_budget") {
9686
+ this.unusableResponsesInBreak++;
9687
+ }
9688
+ if (outcome === "no_fill") {
9689
+ this.timing.recordGamNoFill();
9690
+ }
9691
+ if (diag && !diag.failureReason) {
9692
+ diag.failureReason = "".concat(outcome, ": ").concat(message);
9693
+ }
9694
+ if (this.timing.isTemporaryAdError(error)) {
9695
+ this.timing.temporaryFailureUrls.set(vastTagUrl, Date.now());
9696
+ } else if (outcome !== "discarded_budget") {
9697
+ this.timing.failedVastUrls.add(vastTagUrl);
9698
+ }
9699
+ this.countFunnelStage("request_outcome:".concat(outcome));
9700
+ this.logOrchestratorFunnel("request_outcome", {
9701
+ outcome: outcome,
9702
+ errorMessage: message,
9703
+ consecutiveFailures: this.timing.consecutiveFailures,
9704
+ unusableResponsesInBreak: this.unusableResponsesInBreak
9705
+ });
9706
+ }
9707
+ },
9708
+ {
9304
9709
  // ───────────────────────────────────────────────────────────────
9305
- function tryNextAvailableAdWithRateLimit() {
9306
- return _async_to_generator(function() {
9307
- var epoch, backoffMultiplier, backoffDelay, effectiveMinInterval, timeSinceLastRequest, waitTime;
9308
- return _ts_generator(this, function(_state) {
9309
- switch(_state.label){
9310
- case 0:
9311
- if (!this.inAdBreak) {
9312
- return [
9313
- 2
9314
- ];
9315
- }
9316
- epoch = this.timing.adBreakEpoch;
9317
- if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
9318
- if (this.debug) {
9319
- console.log("[CONTINUOUS-FETCH] Too many consecutive failures (".concat(this.timing.consecutiveFailures, "), ending ad break gracefully"));
9320
- }
9321
- this.handleAdPodComplete();
9322
- return [
9323
- 2
9324
- ];
9325
- }
9326
- backoffMultiplier = Math.pow(2, this.timing.consecutiveFailures);
9327
- backoffDelay = Math.min(this.timing.backoffBaseMs * backoffMultiplier, this.timing.maxBackoffMs);
9328
- effectiveMinInterval = this.timing.minAdRequestIntervalMs + (this.timing.consecutiveFailures > 0 ? backoffDelay : 0);
9329
- timeSinceLastRequest = Date.now() - this.timing.lastAdRequestTime;
9330
- if (!(timeSinceLastRequest < effectiveMinInterval)) return [
9331
- 3,
9332
- 2
9333
- ];
9334
- waitTime = effectiveMinInterval - timeSinceLastRequest;
9335
- if (this.debug) {
9336
- console.log("[CONTINUOUS-FETCH] Rate limiting: waiting ".concat(waitTime, "ms before next request (backoff: ").concat(this.timing.consecutiveFailures, " failures)"));
9337
- }
9338
- return [
9339
- 4,
9340
- new Promise(function(resolve) {
9341
- return setTimeout(resolve, waitTime);
9342
- })
9343
- ];
9344
- case 1:
9345
- _state.sent();
9346
- _state.label = 2;
9347
- case 2:
9348
- if (!this.inAdBreak || epoch !== this.timing.adBreakEpoch) {
9349
- return [
9350
- 2
9351
- ];
9352
- }
9353
- return [
9354
- 2,
9355
- this.tryNextAvailableAd(0)
9356
- ];
9710
+ // Per-request diagnostics
9711
+ // ───────────────────────────────────────────────────────────────
9712
+ key: "recordRequestDiagnostic",
9713
+ value: function recordRequestDiagnostic(payload) {
9714
+ var requestId = payload.requestId;
9715
+ if (typeof requestId !== "number") return;
9716
+ var diag = this.requestDiagnostics.get(requestId);
9717
+ if (!diag) return;
9718
+ switch(payload.stage){
9719
+ case "gam_http_request_sent":
9720
+ diag.gamRequestSent++;
9721
+ break;
9722
+ case "gam_response_received":
9723
+ diag.vastHttpStatus = payload.httpStatus;
9724
+ break;
9725
+ case "vast_parsed":
9726
+ diag.vastAdCount = payload.adElementCount;
9727
+ break;
9728
+ case "wrapper_fetch":
9729
+ case "inline_resolved":
9730
+ if (typeof payload.depth === "number") {
9731
+ diag.wrapperDepth = Math.max(diag.wrapperDepth, payload.depth);
9357
9732
  }
9358
- });
9359
- }).call(this);
9733
+ if (payload.stage === "inline_resolved") diag.inlineResolved = true;
9734
+ break;
9735
+ case "mediafile_evaluated":
9736
+ diag.mediaCandidateCount++;
9737
+ if (payload.whyAccepted) diag.supportedMediaCount++;
9738
+ break;
9739
+ case "playing":
9740
+ diag.playStarted = true;
9741
+ break;
9742
+ case "impression_fired":
9743
+ diag.impressionFired = true;
9744
+ break;
9745
+ default:
9746
+ if (REQUEST_FAILURE_STAGES.has(payload.stage) && !diag.failureReason) {
9747
+ diag.failureReason = payload.reason ? "".concat(payload.stage, ":").concat(payload.reason) : payload.stage;
9748
+ }
9749
+ }
9360
9750
  }
9361
9751
  },
9362
9752
  {
9363
- key: "tryNextAvailableAd",
9364
- value: function tryNextAvailableAd() {
9365
- var retryCount = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
9366
- return _async_to_generator(function() {
9367
- var remaining, nextAdUrl, error, errorMessage, maxRetries;
9368
- return _ts_generator(this, function(_state) {
9369
- switch(_state.label){
9370
- case 0:
9371
- if (!this.inAdBreak) {
9372
- return [
9373
- 2
9374
- ];
9375
- }
9376
- remaining = this.timing.getRemainingAdMs();
9377
- if (!this.timing.hasTimeToStartAnotherAd()) {
9378
- if (this.debug) {
9379
- console.log("[CONTINUOUS-FETCH] Not enough time remaining (".concat(remaining, "ms) to start another ad, ending ad break"));
9380
- }
9381
- this.handleAdPodComplete();
9382
- return [
9383
- 2
9384
- ];
9385
- }
9386
- if (this.timing.isGamInCooldown()) {
9387
- if (this.debug) {
9388
- console.log("[CIRCUIT-BREAKER] GAM in cooldown, ending ad break gracefully");
9389
- }
9390
- this.handleAdPodComplete();
9391
- return [
9392
- 2
9393
- ];
9394
- }
9395
- if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
9396
- if (this.debug) {
9397
- console.log("[CONTINUOUS-FETCH] Too many consecutive failures (".concat(this.timing.consecutiveFailures, "), ending ad break"));
9398
- }
9399
- this.handleAdPodComplete();
9400
- return [
9401
- 2
9402
- ];
9403
- }
9404
- this.timing.cleanupTemporaryFailures();
9405
- _state.label = 1;
9406
- case 1:
9407
- if (!(this.adRequestQueue.length > 0)) return [
9408
- 3,
9409
- 9
9410
- ];
9411
- nextAdUrl = this.adRequestQueue.shift();
9412
- if (!nextAdUrl) return [
9413
- 3,
9414
- 1
9415
- ];
9416
- if (this.timing.failedVastUrls.has(nextAdUrl)) {
9417
- if (this.debug) console.log("[CONTINUOUS-FETCH] Skipping permanently-failed URL, trying next...");
9418
- return [
9419
- 3,
9420
- 1
9421
- ];
9422
- }
9423
- if (this.timing.isUrlInCooldown(nextAdUrl)) {
9424
- if (this.debug) console.log("[CONTINUOUS-FETCH] Skipping URL in cooldown (recent no-fill), trying next...");
9425
- return [
9426
- 3,
9427
- 1
9428
- ];
9429
- }
9430
- if (this.debug) {
9431
- console.log("[CONTINUOUS-FETCH] Requesting next ad via HLS ad player (".concat(this.timing.currentAdIndex + 1, ", ").concat(this.adRequestQueue.length, " remaining in queue)"));
9432
- }
9433
- _state.label = 2;
9434
- case 2:
9435
- _state.trys.push([
9436
- 2,
9437
- 4,
9438
- ,
9439
- 8
9440
- ]);
9441
- return [
9442
- 4,
9443
- this.playSingleAd(nextAdUrl)
9444
- ];
9445
- case 3:
9446
- _state.sent();
9447
- return [
9448
- 3,
9449
- 8
9450
- ];
9451
- case 4:
9452
- error = _state.sent();
9453
- errorMessage = error.message;
9454
- if (this.debug) console.log("[CONTINUOUS-FETCH] Ad request failed:", errorMessage);
9455
- if (!errorMessage.includes("ad_duration_exceeds_budget")) return [
9456
- 3,
9457
- 6
9458
- ];
9459
- this.timing.consecutiveFailures++;
9460
- return [
9461
- 4,
9462
- this.tryNextAvailableAdWithRateLimit()
9463
- ];
9464
- case 5:
9465
- _state.sent();
9466
- return [
9467
- 2
9468
- ];
9469
- case 6:
9470
- if (!errorMessage.includes("permanently failed") && !errorMessage.includes("in cooldown")) {
9471
- this.timing.consecutiveFailures++;
9472
- }
9473
- return [
9474
- 4,
9475
- this.tryNextAvailableAdWithRateLimit()
9476
- ];
9477
- case 7:
9478
- _state.sent();
9479
- return [
9480
- 3,
9481
- 8
9482
- ];
9483
- case 8:
9484
- return [
9485
- 2
9486
- ];
9487
- case 9:
9488
- maxRetries = 3;
9489
- if (!(this.continuousFetchingActive && retryCount < maxRetries && remaining > 2e3)) return [
9490
- 3,
9491
- 12
9492
- ];
9493
- if (this.debug) {
9494
- console.log("[CONTINUOUS-FETCH] Queue empty, waiting for URLs... (".concat(retryCount + 1, "/").concat(maxRetries, ")"));
9495
- }
9496
- return [
9497
- 4,
9498
- new Promise(function(resolve) {
9499
- return setTimeout(resolve, 500);
9500
- })
9501
- ];
9502
- case 10:
9503
- _state.sent();
9504
- return [
9505
- 4,
9506
- this.tryNextAvailableAd(retryCount + 1)
9507
- ];
9508
- case 11:
9509
- _state.sent();
9510
- return [
9511
- 2
9512
- ];
9513
- case 12:
9514
- if (!this.isShowingPlaceholder && remaining > 1e3) {
9515
- this.showPlaceholderAndWaitForAds();
9516
- } else {
9517
- if (this.debug) console.log("[CONTINUOUS-FETCH] No more ads available, ending ad break");
9518
- this.handleAdPodComplete();
9519
- }
9520
- return [
9521
- 2
9522
- ];
9523
- }
9524
- });
9525
- }).call(this);
9753
+ key: "finalizeRequestDiagnostics",
9754
+ value: function finalizeRequestDiagnostics(requestId, endReason) {
9755
+ var _diag_vastAdCount;
9756
+ if (requestId == null) return;
9757
+ var diag = this.requestDiagnostics.get(requestId);
9758
+ if (!diag) return;
9759
+ this.requestDiagnostics.delete(requestId);
9760
+ if (!diag.impressionFired && !diag.failureReason && endReason) {
9761
+ diag.failureReason = endReason;
9762
+ }
9763
+ var gamReturnedAdWithoutImpression = ((_diag_vastAdCount = diag.vastAdCount) !== null && _diag_vastAdCount !== void 0 ? _diag_vastAdCount : 0) > 0 && !diag.impressionFired;
9764
+ if (gamReturnedAdWithoutImpression) {
9765
+ this.countFunnelStage("gam_ad_without_impression");
9766
+ }
9767
+ var startedAt = diag.startedAt, fields = _object_without_properties(diag, [
9768
+ "startedAt"
9769
+ ]);
9770
+ console.log("[AdBreak][REQUEST] summary", _object_spread_props(_object_spread({}, fields), {
9771
+ durationMs: Date.now() - startedAt,
9772
+ gamReturnedAdWithoutImpression: gamReturnedAdWithoutImpression
9773
+ }));
9526
9774
  }
9527
9775
  },
9528
9776
  {
@@ -9530,7 +9778,8 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9530
9778
  // Single ad playback
9531
9779
  // ───────────────────────────────────────────────────────────────
9532
9780
  key: "withCurrentPodBudget",
9533
- value: function withCurrentPodBudget(vastTagUrl) {
9781
+ value: function withCurrentPodBudget(rawVastTagUrl) {
9782
+ var vastTagUrl = ensureVideoAdType(rawVastTagUrl);
9534
9783
  var remaining = Math.min(this.timing.getWallClockRemainingAdMs(), this.timing.getDurationBudgetRemainingMs());
9535
9784
  if (!(remaining > 0)) return vastTagUrl;
9536
9785
  try {
@@ -9589,18 +9838,34 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9589
9838
  },
9590
9839
  {
9591
9840
  key: "beginFunnelRequest",
9592
- value: function beginFunnelRequest(adPlayer, requestToken) {
9841
+ value: function beginFunnelRequest(adPlayer, requestToken, trigger) {
9593
9842
  var _adPlayer_setFunnelContext;
9594
9843
  if (this.controllerCallInFlight) {
9595
9844
  this.logOrchestratorFunnel("duplicate_request_detected", {
9596
9845
  newRequestId: requestToken
9597
9846
  });
9598
9847
  }
9848
+ this.finalizeRequestDiagnostics(this.currentRequestId);
9599
9849
  this.currentRequestId = requestToken;
9600
9850
  this.requestStartedAt = Date.now();
9851
+ this.requestDiagnostics.set(requestToken, {
9852
+ breakId: this.timing.adBreakEpoch,
9853
+ requestId: requestToken,
9854
+ controllerId: this.controllerGeneration,
9855
+ trigger: trigger,
9856
+ gamRequestSent: 0,
9857
+ wrapperDepth: 0,
9858
+ inlineResolved: false,
9859
+ mediaCandidateCount: 0,
9860
+ supportedMediaCount: 0,
9861
+ playStarted: false,
9862
+ impressionFired: false,
9863
+ startedAt: Date.now()
9864
+ });
9601
9865
  (_adPlayer_setFunnelContext = adPlayer.setFunnelContext) === null || _adPlayer_setFunnelContext === void 0 ? void 0 : _adPlayer_setFunnelContext.call(adPlayer, {
9602
9866
  breakId: this.timing.adBreakEpoch,
9603
- requestId: requestToken
9867
+ requestId: requestToken,
9868
+ controllerId: this.controllerGeneration
9604
9869
  });
9605
9870
  }
9606
9871
  },
@@ -9631,7 +9896,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9631
9896
  adPlayer.abortPendingRequest("VAST request aborted after request watchdog timeout");
9632
9897
  return;
9633
9898
  }
9634
- this.handleAdFailure();
9899
+ this.handleAdFailure("request_watchdog_timeout");
9635
9900
  }
9636
9901
  },
9637
9902
  {
@@ -9677,21 +9942,30 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9677
9942
  {
9678
9943
  key: "playSingleAd",
9679
9944
  value: function playSingleAd(vastTagUrl) {
9945
+ var trigger = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "vmap";
9680
9946
  return _async_to_generator(function() {
9681
- var adPlayer, requestToken, ap, requestUrl, _ap_getLoadedAdDuration, adDurationS, remainingMs, playError, error, errorMessage;
9947
+ var epoch, generation, requestToken, ap, requestUrl, _ap_getLoadedAdDuration, adDurationS, remainingMs, error;
9682
9948
  return _ts_generator(this, function(_state) {
9683
9949
  switch(_state.label){
9684
9950
  case 0:
9685
- adPlayer = this.host.getAdPlayer();
9686
- if (adPlayer.isAdPlaying()) return [
9687
- 2
9688
- ];
9951
+ if (this.slotState === "REQUESTING" || this.slotState === "READY" || this.slotState === "PLAYING" || this.slotState === "ENDING") {
9952
+ this.logOrchestratorFunnel("request_suppressed", {
9953
+ trigger: trigger,
9954
+ state: this.slotState,
9955
+ why: "request_in_flight"
9956
+ });
9957
+ return [
9958
+ 2
9959
+ ];
9960
+ }
9689
9961
  if (this.timing.failedVastUrls.has(vastTagUrl)) {
9690
9962
  if (this.debug) console.warn("[AD-ERROR] Skipping permanently-failed VAST URL:", vastTagUrl);
9963
+ this.timing.consecutiveFailures++;
9691
9964
  throw new Error("VAST URL permanently failed");
9692
9965
  }
9693
9966
  if (this.timing.isUrlInCooldown(vastTagUrl)) {
9694
9967
  if (this.debug) console.warn("[AD-ERROR] Skipping URL in cooldown (recent no-fill):", vastTagUrl);
9968
+ this.timing.consecutiveFailures++;
9695
9969
  throw new Error("VAST URL in cooldown after no-fill");
9696
9970
  }
9697
9971
  if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
@@ -9702,16 +9976,23 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9702
9976
  if (this.debug) console.warn("[CIRCUIT-BREAKER] GAM in cooldown, skipping ad request");
9703
9977
  throw new Error("GAM in cooldown");
9704
9978
  }
9705
- this.recreateAdController();
9979
+ epoch = this.timing.adBreakEpoch;
9980
+ this.recreateAdController("new_request");
9981
+ generation = this.controllerGeneration;
9706
9982
  requestToken = ++this.timing.adRequestTokenCounter;
9707
9983
  this.timing.activeAdRequestToken = requestToken;
9984
+ ap = this.host.getAdPlayer();
9985
+ requestUrl = this.withCurrentPodBudget(vastTagUrl);
9986
+ this.currentVastUrl = requestUrl;
9987
+ this.setSlotState("REQUESTING", trigger);
9988
+ this.beginFunnelRequest(ap, requestToken, trigger);
9708
9989
  _state.label = 1;
9709
9990
  case 1:
9710
9991
  _state.trys.push([
9711
9992
  1,
9712
- 8,
9993
+ 5,
9713
9994
  ,
9714
- 9
9995
+ 6
9715
9996
  ]);
9716
9997
  return [
9717
9998
  4,
@@ -9719,12 +10000,10 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9719
10000
  ];
9720
10001
  case 2:
9721
10002
  _state.sent();
10003
+ if (this.isStale(epoch, generation)) return [
10004
+ 2
10005
+ ];
9722
10006
  this.timing.startAdRequestWatchdog(requestToken);
9723
- this.timing.noteAdRequestSent();
9724
- ap = this.host.getAdPlayer();
9725
- requestUrl = this.withCurrentPodBudget(vastTagUrl);
9726
- this.currentVastUrl = requestUrl;
9727
- this.beginFunnelRequest(ap, requestToken);
9728
10007
  return [
9729
10008
  4,
9730
10009
  this.callController(function() {
@@ -9733,36 +10012,31 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9733
10012
  ];
9734
10013
  case 3:
9735
10014
  _state.sent();
10015
+ this.timing.clearAdRequestWatchdog();
10016
+ if (this.isStale(epoch, generation)) {
10017
+ this.logOrchestratorFunnel("stale_request_result_ignored", {
10018
+ requestId: requestToken
10019
+ });
10020
+ return [
10021
+ 2
10022
+ ];
10023
+ }
9736
10024
  sendAdLoadedTracking(this.host.config.licenseKey, {
9737
10025
  source: "hls",
9738
10026
  vastUrl: requestUrl,
9739
10027
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
9740
10028
  }, this.analyticsContext).catch(function() {});
9741
- this.timing.clearAdRequestWatchdog();
9742
- if (this.timing.activeAdRequestToken !== requestToken) return [
9743
- 2
9744
- ];
9745
10029
  if (!this.timing.ensureLoadedAdFitsBudget(ap)) {
9746
10030
  ;
9747
10031
  adDurationS = (_ap_getLoadedAdDuration = ap.getLoadedAdDuration) === null || _ap_getLoadedAdDuration === void 0 ? void 0 : _ap_getLoadedAdDuration.call(ap);
9748
10032
  remainingMs = Math.min(this.timing.getWallClockRemainingAdMs(), this.timing.getDurationBudgetRemainingMs());
9749
10033
  this.logOrchestratorFunnel("discarded_budget", {
9750
- vastUrl: requestUrl,
9751
10034
  adDurationMs: adDurationS != null ? adDurationS * 1e3 : void 0,
9752
10035
  remainingMs: remainingMs
9753
10036
  });
9754
- this.timing.rejectLoadedAdForDuration(ap);
9755
- this.recreateAdController();
9756
10037
  throw new Error("ad_duration_exceeds_budget");
9757
10038
  }
9758
- _state.label = 4;
9759
- case 4:
9760
- _state.trys.push([
9761
- 4,
9762
- 6,
9763
- ,
9764
- 7
9765
- ]);
10039
+ this.setSlotState("READY", "vast_ready");
9766
10040
  this.timing.startAdFailsafeTimer(requestToken);
9767
10041
  return [
9768
10042
  4,
@@ -9770,8 +10044,11 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9770
10044
  return ap.play();
9771
10045
  })
9772
10046
  ];
9773
- case 5:
10047
+ case 4:
9774
10048
  _state.sent();
10049
+ if (this.isStale(epoch, generation)) return [
10050
+ 2
10051
+ ];
9775
10052
  if (this.timing.expectedAdBreakDurationMs != null && this.timing.getAdBreakEndWallClockMs() == null) {
9776
10053
  this.timing.scheduleAdStopAtBreakBoundary();
9777
10054
  }
@@ -9779,216 +10056,31 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9779
10056
  this.timing.temporaryFailureUrls.delete(vastTagUrl);
9780
10057
  return [
9781
10058
  3,
9782
- 7
9783
- ];
9784
- case 6:
9785
- playError = _state.sent();
9786
- if (this.debug) console.error("[AD-ERROR] Failed to play ad:", playError);
9787
- if (this.timing.isTemporaryAdError(playError)) {
9788
- this.timing.temporaryFailureUrls.set(vastTagUrl, Date.now());
9789
- if (this.debug) console.log("[AD-ERROR] Temporary play error - URL can be retried after cooldown");
9790
- } else {
9791
- this.timing.failedVastUrls.add(vastTagUrl);
9792
- if (this.debug) console.log("[AD-ERROR] Permanent play error - URL blacklisted");
9793
- }
9794
- this.timing.clearAdFailsafeTimer();
9795
- if (this.timing.activeAdRequestToken === requestToken) {
9796
- this.timing.activeAdRequestToken = null;
9797
- }
9798
- throw playError;
9799
- case 7:
9800
- return [
9801
- 3,
9802
- 9
10059
+ 6
9803
10060
  ];
9804
- case 8:
10061
+ case 5:
9805
10062
  error = _state.sent();
9806
- errorMessage = (error === null || error === void 0 ? void 0 : error.message) || "";
9807
- if (this.debug) console.error("[AD-ERROR] Ad request failed:", errorMessage);
9808
- if (this.timing.isTemporaryAdError(error)) {
9809
- this.timing.temporaryFailureUrls.set(vastTagUrl, Date.now());
9810
- if (this.debug) console.log("[AD-ERROR] Temporary error (no-fill/timeout) - URL can be retried after cooldown");
9811
- } else {
9812
- this.timing.failedVastUrls.add(vastTagUrl);
9813
- if (this.debug) console.log("[AD-ERROR] Permanent error - URL blacklisted:", errorMessage);
9814
- }
9815
10063
  this.timing.clearAdRequestWatchdog();
9816
10064
  this.timing.clearAdFailsafeTimer();
9817
10065
  if (this.timing.activeAdRequestToken === requestToken) {
9818
10066
  this.timing.activeAdRequestToken = null;
9819
10067
  }
9820
- throw error;
9821
- case 9:
9822
- return [
9823
- 2
9824
- ];
9825
- }
9826
- });
9827
- }).call(this);
9828
- }
9829
- },
9830
- {
9831
- key: "showPlaceholderAndWaitForAds",
9832
- value: // ───────────────────────────────────────────────────────────────
9833
- // Placeholder wait
9834
- // ───────────────────────────────────────────────────────────────
9835
- function showPlaceholderAndWaitForAds() {
9836
- return _async_to_generator(function() {
9837
- var remaining, waitTime, checkInterval, maxChecks, i, nextAdUrl, error, errorMessage;
9838
- return _ts_generator(this, function(_state) {
9839
- switch(_state.label){
9840
- case 0:
9841
- remaining = this.timing.getRemainingAdMs();
9842
- waitTime = Math.min(this.maxPlaceholderDurationMs, remaining);
9843
- if (this.timing.isGamInCooldown()) {
9844
- if (this.debug) console.log("[CIRCUIT-BREAKER] GAM in cooldown, skipping placeholder wait");
9845
- this.handleAdPodComplete();
9846
- return [
9847
- 2
9848
- ];
9849
- }
9850
- if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
9851
- if (this.debug) console.log("[CONTINUOUS-FETCH] Skipping placeholder - too many consecutive failures");
9852
- this.handleAdPodComplete();
9853
- return [
9854
- 2
9855
- ];
9856
- }
9857
- if (waitTime < 1e3) {
9858
- this.handleAdPodComplete();
10068
+ if (this.isStale(epoch, generation)) {
10069
+ this.logOrchestratorFunnel("stale_request_result_ignored", {
10070
+ requestId: requestToken,
10071
+ errorMessage: error === null || error === void 0 ? void 0 : error.message
10072
+ });
9859
10073
  return [
9860
10074
  2
9861
10075
  ];
9862
10076
  }
9863
- if (this.debug) {
9864
- console.log("[CONTINUOUS-FETCH] Showing placeholder for ".concat(waitTime, "ms while waiting for ad URLs"));
10077
+ if (this.debug) console.error("[AD-ERROR] Ad request failed:", error === null || error === void 0 ? void 0 : error.message);
10078
+ this.recordRequestFailure(error, vastTagUrl);
10079
+ if ((error === null || error === void 0 ? void 0 : error.message) === "ad_duration_exceeds_budget") {
10080
+ this.recreateAdController("discarded_budget");
9865
10081
  }
9866
- this.isShowingPlaceholder = true;
9867
- this.host.getAdPlayer().showPlaceholder();
9868
- checkInterval = 300;
9869
- maxChecks = Math.floor(waitTime / checkInterval);
9870
- i = 0;
9871
- _state.label = 1;
9872
- case 1:
9873
- if (!(i < maxChecks)) return [
9874
- 3,
9875
- 12
9876
- ];
9877
- return [
9878
- 4,
9879
- new Promise(function(resolve) {
9880
- return setTimeout(resolve, checkInterval);
9881
- })
9882
- ];
9883
- case 2:
9884
- _state.sent();
9885
- if (!this.inAdBreak) return [
9886
- 2
9887
- ];
9888
- if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
9889
- if (this.debug) console.log("[CONTINUOUS-FETCH] Too many failures during placeholder wait");
9890
- return [
9891
- 3,
9892
- 12
9893
- ];
9894
- }
9895
- if (!this.timing.hasTimeToStartAnotherAd()) {
9896
- if (this.debug) console.log("[CONTINUOUS-FETCH] Not enough time remaining during placeholder wait, ending ad break");
9897
- return [
9898
- 3,
9899
- 12
9900
- ];
9901
- }
9902
- _state.label = 3;
9903
- case 3:
9904
- if (!(this.adRequestQueue.length > 0)) return [
9905
- 3,
9906
- 11
9907
- ];
9908
- if (!this.timing.hasTimeToStartAnotherAd()) return [
9909
- 3,
9910
- 11
9911
- ];
9912
- nextAdUrl = this.adRequestQueue.shift();
9913
- if (!nextAdUrl) return [
9914
- 3,
9915
- 3
9916
- ];
9917
- if (this.timing.failedVastUrls.has(nextAdUrl)) return [
9918
- 3,
9919
- 3
9920
- ];
9921
- if (this.timing.isUrlInCooldown(nextAdUrl)) return [
9922
- 3,
9923
- 3
9924
- ];
9925
- if (this.debug) console.log("[CONTINUOUS-FETCH] Ad URL available, requesting via HLS ad player");
9926
- this.isShowingPlaceholder = false;
9927
- this.host.getAdPlayer().hidePlaceholder();
9928
- _state.label = 4;
9929
- case 4:
9930
- _state.trys.push([
9931
- 4,
9932
- 6,
9933
- ,
9934
- 10
9935
- ]);
9936
- return [
9937
- 4,
9938
- this.playSingleAd(nextAdUrl)
9939
- ];
9940
- case 5:
9941
- _state.sent();
9942
- return [
9943
- 3,
9944
- 10
9945
- ];
10082
+ throw error;
9946
10083
  case 6:
9947
- error = _state.sent();
9948
- errorMessage = error.message;
9949
- if (!errorMessage.includes("ad_duration_exceeds_budget")) return [
9950
- 3,
9951
- 8
9952
- ];
9953
- this.timing.consecutiveFailures++;
9954
- return [
9955
- 4,
9956
- this.tryNextAvailableAdWithRateLimit()
9957
- ];
9958
- case 7:
9959
- _state.sent();
9960
- return [
9961
- 2
9962
- ];
9963
- case 8:
9964
- if (!errorMessage.includes("permanently failed") && !errorMessage.includes("in cooldown")) {
9965
- this.timing.consecutiveFailures++;
9966
- }
9967
- return [
9968
- 4,
9969
- this.tryNextAvailableAdWithRateLimit()
9970
- ];
9971
- case 9:
9972
- _state.sent();
9973
- return [
9974
- 3,
9975
- 10
9976
- ];
9977
- case 10:
9978
- return [
9979
- 2
9980
- ];
9981
- case 11:
9982
- i++;
9983
- return [
9984
- 3,
9985
- 1
9986
- ];
9987
- case 12:
9988
- if (this.debug) console.log("[CONTINUOUS-FETCH] Placeholder timeout, ending ad break");
9989
- this.isShowingPlaceholder = false;
9990
- this.host.getAdPlayer().hidePlaceholder();
9991
- this.handleAdPodComplete();
9992
10084
  return [
9993
10085
  2
9994
10086
  ];
@@ -10002,7 +10094,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
10002
10094
  // Ad break completion
10003
10095
  // ───────────────────────────────────────────────────────────────
10004
10096
  key: "logBreakFunnel",
10005
- value: function logBreakFunnel() {
10097
+ value: function logBreakFunnel(endReason) {
10006
10098
  var funnel = this.breakFunnel;
10007
10099
  this.breakFunnel = {};
10008
10100
  if (Object.keys(funnel).length === 0) return;
@@ -10010,26 +10102,49 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
10010
10102
  var _funnel_stage;
10011
10103
  return (_funnel_stage = funnel[stage]) !== null && _funnel_stage !== void 0 ? _funnel_stage : 0;
10012
10104
  };
10105
+ var countPrefix = function countPrefix(prefix) {
10106
+ return Object.keys(funnel).reduce(function(total, stage) {
10107
+ var _funnel_stage;
10108
+ return stage.indexOf(prefix) === 0 ? total + ((_funnel_stage = funnel[stage]) !== null && _funnel_stage !== void 0 ? _funnel_stage : 0) : total;
10109
+ }, 0);
10110
+ };
10013
10111
  var breakId = this.opportunityEpoch;
10014
- if (count("request_sent") > 0 && count("impression_fired") === 0) {
10112
+ var requestRetries = count("gam_http_request_retry");
10113
+ var requests = count("gam_http_request_sent") - requestRetries;
10114
+ if (requests > 0 && count("impression_fired") === 0) {
10015
10115
  console.log("[AdBreak][FUNNEL] break_abandoned_before_start", {
10016
10116
  breakId: breakId,
10017
- requests: count("request_sent")
10117
+ requests: requests,
10118
+ endReason: endReason
10018
10119
  });
10019
10120
  }
10020
10121
  console.log("[AdBreak][FUNNEL] Break summary", {
10021
10122
  breakId: breakId,
10123
+ endReason: endReason,
10022
10124
  opportunities: count("opportunity_created"),
10023
- requests: count("request_sent"),
10125
+ vastUrlsGenerated: count("vast_url_generated"),
10126
+ requests: requests,
10127
+ requestRetries: requestRetries,
10128
+ gamResponses: count("gam_response_received"),
10129
+ requestsSuppressed: count("request_suppressed"),
10024
10130
  duplicates: count("duplicate_request_detected") + count("duplicate_break_start"),
10025
10131
  filled: count("vast_received"),
10026
10132
  noFill: count("no_fill"),
10133
+ fillRejected: count("vast_fill_rejected"),
10134
+ gamAdWithoutImpression: count("gam_ad_without_impression"),
10135
+ playbackFailedAfterFill: count("request_outcome:playback_failed"),
10027
10136
  requestFailed: count("request_failed"),
10028
10137
  requestAbortedTimeout: count("request_aborted_timeout"),
10029
10138
  credentialsRetries: count("vast_credentials_retry"),
10030
10139
  wrapperFailures: count("wrapper_fetch:failure"),
10031
10140
  noSupportedMedia: count("vast_no_supported_media"),
10032
- vpaidOnly: count("vast_no_supported_media:vpaid_only"),
10141
+ vpaidOnly: count("vast_no_supported_media:vpaid"),
10142
+ audioOnly: count("vast_no_supported_media:audio_only"),
10143
+ mediaFilesEvaluated: count("mediafile_evaluated"),
10144
+ mediaFilesAccepted: count("mediafile_evaluated:accepted"),
10145
+ controllerDestroys: countPrefix("controller_destroy:"),
10146
+ staleCallbacks: count("stale_callback_ignored") + count("stale_request_result_ignored"),
10147
+ tagAllowsAudio: count("tag_allows_audio"),
10033
10148
  missingImpression: count("vast_missing_impression"),
10034
10149
  discardedBudget: count("discarded_budget"),
10035
10150
  mediaCandidates: count("media_candidate:accepted") + count("media_candidate:rejected"),
@@ -10064,25 +10179,50 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
10064
10179
  {
10065
10180
  key: "handleAdPodComplete",
10066
10181
  value: function handleAdPodComplete() {
10182
+ var reason = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "unspecified";
10067
10183
  if (this.debug) {
10068
- console.log("[StormcloudVideoPlayer] Ad pod complete - cleaning up");
10184
+ console.log("[StormcloudVideoPlayer] Ad pod complete - cleaning up", {
10185
+ reason: reason
10186
+ });
10187
+ }
10188
+ var previousState = this.slotState;
10189
+ var alreadyEnded = previousState === "IDLE" && !this.inAdBreak;
10190
+ this.setSlotState("ENDING", reason);
10191
+ this.cancelScheduledRequest();
10192
+ var adPlayer = this.host.getAdPlayer();
10193
+ if (previousState === "REQUESTING") {
10194
+ var _adPlayer_abortPendingRequest;
10195
+ (_adPlayer_abortPendingRequest = adPlayer.abortPendingRequest) === null || _adPlayer_abortPendingRequest === void 0 ? void 0 : _adPlayer_abortPendingRequest.call(adPlayer, "VAST request aborted: ad break ended (".concat(reason, ")"));
10196
+ }
10197
+ if (!alreadyEnded) {
10198
+ console.log("[AD-CONTROLLER] stop", {
10199
+ controllerId: this.controllerGeneration,
10200
+ requestId: this.currentRequestId,
10201
+ state: previousState,
10202
+ reason: reason
10203
+ });
10069
10204
  }
10205
+ this.finalizeRequestDiagnostics(this.currentRequestId, "break_ended:".concat(reason));
10206
+ this.currentRequestId = void 0;
10070
10207
  this.timing.resetForBreakEnd();
10071
- this.stopContinuousFetching();
10208
+ this.placeholder.hide();
10072
10209
  this.clearPendingAdBreak();
10073
10210
  if (this.isShowingPlaceholder) {
10074
- this.host.getAdPlayer().hidePlaceholder();
10211
+ adPlayer.hidePlaceholder();
10075
10212
  this.isShowingPlaceholder = false;
10076
10213
  }
10077
- this.adRequestQueue = [];
10078
10214
  this.inAdBreak = false;
10079
10215
  this.adDetectSentForCurrentBreak = false;
10080
10216
  this.cueManager.activeScte35BreakKey = void 0;
10081
10217
  this.cueManager.scheduledScte35BreakKey = void 0;
10082
10218
  this.adPodQueue = [];
10083
10219
  this.showAds = false;
10084
- this.host.getAdPlayer().stop().catch(function() {});
10085
- this.logBreakFunnel();
10220
+ this.breakSource = void 0;
10221
+ this.followUpBaseVastUrl = void 0;
10222
+ this.unusableResponsesInBreak = 0;
10223
+ adPlayer.stop().catch(function() {});
10224
+ if (!alreadyEnded) this.logBreakFunnel(reason);
10225
+ this.setSlotState("IDLE", "break_complete");
10086
10226
  var restoredMuted = this.host.getAdPlayer().getOriginalMutedState();
10087
10227
  var restoredVolume = this.host.getAdPlayer().getOriginalVolume();
10088
10228
  if (this.host.video.muted !== restoredMuted) {
@@ -10376,25 +10516,23 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
10376
10516
  {
10377
10517
  key: "handleAdFailure",
10378
10518
  value: function handleAdFailure() {
10379
- this.timing.consecutiveFailures++;
10380
- this.timing.recordGamNoFill();
10381
- var remaining = this.timing.getRemainingAdMs();
10382
- if (this.debug) {
10383
- 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 ? {
10384
- queuedUrls: _to_consumable_array(this.adRequestQueue)
10385
- } : {});
10386
- }
10387
- if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
10388
- if (this.debug) console.log("[CONTINUOUS-FETCH] Max consecutive failures reached (".concat(this.timing.consecutiveFailures, "), ending ad break gracefully"));
10389
- this.handleAdPodComplete();
10519
+ var reason = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "ad_failure";
10520
+ if (!this.inAdBreak) return;
10521
+ if (this.slotState === "REQUESTING" || this.slotState === "ENDING") {
10522
+ this.logOrchestratorFunnel("failure_deferred_to_request", {
10523
+ reason: reason,
10524
+ state: this.slotState
10525
+ });
10390
10526
  return;
10391
10527
  }
10392
- if (this.timing.hasTimeToStartAnotherAd()) {
10393
- this.tryNextAvailableAdWithRateLimit();
10394
- } else {
10395
- if (this.debug) console.log("[AD-ERROR] Ad failed and not enough time remaining for another ad. Failed URLs:", this.timing.failedVastUrls.size);
10396
- this.handleAdPodComplete();
10528
+ this.timing.consecutiveFailures++;
10529
+ var diag = this.currentRequestId != null ? this.requestDiagnostics.get(this.currentRequestId) : void 0;
10530
+ if (diag && !diag.failureReason) diag.failureReason = reason;
10531
+ if (this.debug) {
10532
+ console.log("[AdBreak] Ad failure (".concat(reason, "): remaining=").concat(this.timing.getRemainingAdMs(), "ms, consecutiveFailures=").concat(this.timing.consecutiveFailures));
10397
10533
  }
10534
+ this.setSlotState("NEEDS_NEXT_AD", reason);
10535
+ this.requestNextAd(reason);
10398
10536
  }
10399
10537
  }
10400
10538
  ]);
@@ -10438,7 +10576,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10438
10576
  return _this.adBreak.handleRequestWatchdogTimeout();
10439
10577
  },
10440
10578
  onFailsafeTimeout: function onFailsafeTimeout() {
10441
- return _this.adBreak.handleAdFailure();
10579
+ return _this.adBreak.handleAdFailure("failsafe_timeout");
10442
10580
  },
10443
10581
  getAdState: function getAdState() {
10444
10582
  return {
@@ -10688,6 +10826,21 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10688
10826
  adBehavior: adBehavior
10689
10827
  });
10690
10828
  }
10829
+ if (this.adBreak.isBreakActive()) {
10830
+ console.log("[AD-CONTROLLER] destroy skipped", {
10831
+ reason: "manifest_parsed_during_break",
10832
+ state: this.adBreak.getSlotState()
10833
+ });
10834
+ return [
10835
+ 2
10836
+ ];
10837
+ }
10838
+ if (this.debug) {
10839
+ console.log("[AD-CONTROLLER] destroy", {
10840
+ reason: "manifest_parsed",
10841
+ state: "IDLE"
10842
+ });
10843
+ }
10691
10844
  this.adPlayer.destroy();
10692
10845
  this.adPlayer = this.createAdPlayer(this.shouldContinueLiveStreamDuringAds());
10693
10846
  this.adPlayer.initialize();
@@ -10869,9 +11022,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10869
11022
  this.timing.setAdBreakDurationBoundary(marker.durationSeconds * 1e3);
10870
11023
  }
10871
11024
  this.timing.scheduleAdStopAtBreakBoundary();
10872
- if (!this.adPlayer.isAdPlaying() && this.timing.activeAdRequestToken === null && this.adBreak.adRequestQueue.length > 0 && this.timing.hasTimeToStartAnotherAd()) {
10873
- this.adBreak.tryNextAvailableAdWithRateLimit();
10874
- }
10875
11025
  return;
10876
11026
  }
10877
11027
  if (marker.type === "end") {
@@ -10883,12 +11033,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10883
11033
  }
10884
11034
  var remaining = this.timing.getRemainingAdMs();
10885
11035
  var adPlaying = this.adPlayer.isAdPlaying();
10886
- var hasQueuedAds = this.adBreak.adRequestQueue.length > 0;
10887
11036
  if (this.debug) {
10888
11037
  console.log("[StormcloudVideoPlayer] SCTE-35 end marker received:", {
10889
11038
  remaining: remaining,
10890
11039
  adPlaying: adPlaying,
10891
- hasQueuedAds: hasQueuedAds,
11040
+ adSlotState: this.adBreak.getSlotState(),
10892
11041
  activeAdRequest: this.timing.activeAdRequestToken !== null
10893
11042
  });
10894
11043
  }
@@ -10899,7 +11048,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10899
11048
  this.adBreak.noteStopBeforeStart("scte_end");
10900
11049
  this.adPlayer.stop().catch(function() {});
10901
11050
  }
10902
- this.adBreak.handleAdPodComplete();
11051
+ this.adBreak.handleAdPodComplete("scte_end");
10903
11052
  return;
10904
11053
  }
10905
11054
  }
@@ -10907,6 +11056,15 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10907
11056
  {
10908
11057
  key: "startScte35AdBreak",
10909
11058
  value: function startScte35AdBreak(marker, cueKey, durationMs) {
11059
+ if (this.adBreak.isBreakActive()) {
11060
+ if (this.debug) {
11061
+ console.log("[StormcloudVideoPlayer] Ignoring SCTE-35 break start: a break is already active", {
11062
+ state: this.adBreak.getSlotState(),
11063
+ cueKey: cueKey
11064
+ });
11065
+ }
11066
+ return;
11067
+ }
10910
11068
  this.adBreak.inAdBreak = true;
10911
11069
  this.cueManager.activeScte35BreakKey = cueKey !== null && cueKey !== void 0 ? cueKey : this.cueManager.pendingScte35CueKey;
10912
11070
  this.cueManager.scheduledScte35BreakKey = void 0;
@@ -10939,7 +11097,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10939
11097
  this.adBreak.noteStopBeforeStart("break_boundary");
10940
11098
  this.adPlayer.stop().catch(function() {});
10941
11099
  }
10942
- this.adBreak.handleAdPodComplete();
11100
+ this.adBreak.handleAdPodComplete("break_boundary");
10943
11101
  }
10944
11102
  },
10945
11103
  {
@@ -10949,14 +11107,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10949
11107
  key: "startAdPrefetch",
10950
11108
  value: function startAdPrefetch(marker, fragmentSn, cueKey) {
10951
11109
  if (this.adBreak.pendingAdBreak || this.adBreak.inAdBreak) return;
10952
- var scheduled = this.adConfig.findCurrentOrNextBreak(this.video.currentTime * 1e3);
10953
- var tags = this.adConfig.selectVastTagsForBreak(scheduled);
10954
- var baseVastUrl;
10955
- if (tags && tags.length > 0 && tags[0]) {
10956
- baseVastUrl = tags[0];
10957
- } else if (this.adConfig.apiVastTagUrl) {
10958
- baseVastUrl = this.adConfig.apiVastTagUrl;
10959
- } else {
11110
+ var baseVastUrl = this.adConfig.apiVastTagUrl;
11111
+ if (!baseVastUrl) {
10960
11112
  if (this.debug) console.warn("[StormcloudVideoPlayer] No VAST URL available for prefetch");
10961
11113
  return;
10962
11114
  }
@@ -10986,8 +11138,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10986
11138
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
10987
11139
  }, detectPayload), buildAnalyticsContext(this.config)).catch(function() {});
10988
11140
  if (this.debug) {
10989
- console.log("[PREFETCH] Starting ad prefetch for upcoming ad break");
10990
- console.log("[PREFETCH] Pre-generated pod request URL");
11141
+ console.log("[PREFETCH] Pre-generated pod request URL for upcoming ad break");
10991
11142
  }
10992
11143
  }
10993
11144
  },
@@ -10998,7 +11149,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10998
11149
  key: "onTimeUpdate",
10999
11150
  value: function onTimeUpdate(currentTimeSec) {
11000
11151
  var _this = this;
11001
- if (!this.adConfig.isVmapEnabled() || this.adConfig.vmapBreaks.length === 0) return;
11152
+ if (this.adConfig.vmapBreaks.length === 0) return;
11002
11153
  if (this.adPlayer.isAdPlaying() || this.adBreak.inAdBreak) return;
11003
11154
  var nowMs = currentTimeSec * 1e3;
11004
11155
  var breakToPlay = this.adConfig.findBreakForTime(nowMs);
@@ -11015,7 +11166,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11015
11166
  key: "onVideoEnded",
11016
11167
  value: function onVideoEnded() {
11017
11168
  var _this = this;
11018
- if (!this.adConfig.isVmapEnabled() || this.adConfig.vmapBreaks.length === 0) return;
11169
+ if (this.adConfig.vmapBreaks.length === 0) return;
11019
11170
  if (this.adPlayer.isAdPlaying() || this.adBreak.inAdBreak) return;
11020
11171
  var durationMs = Number.isFinite(this.video.duration) ? Math.floor(this.video.duration * 1e3) : 0;
11021
11172
  var postroll = this.adConfig.vmapBreaks.find(function(b) {
@@ -11068,7 +11219,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11068
11219
  if (durationMs > 0) {
11069
11220
  this.timing.setAdBreakDurationBoundary(durationMs);
11070
11221
  }
11071
- this.adBreak.noteOpportunity("vmap", key);
11222
+ this.adBreak.beginVmapBreak(key);
11072
11223
  _state.label = 1;
11073
11224
  case 1:
11074
11225
  _state.trys.push([
@@ -11079,7 +11230,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11079
11230
  ]);
11080
11231
  return [
11081
11232
  4,
11082
- this.adBreak.playSingleAd(first)
11233
+ this.adBreak.playSingleAd(first, "vmap")
11083
11234
  ];
11084
11235
  case 2:
11085
11236
  _state.sent();
@@ -11092,7 +11243,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11092
11243
  if (this.debug) {
11093
11244
  console.warn("[StormcloudVideoPlayer] VMAP ad request failed:", error);
11094
11245
  }
11095
- this.adBreak.handleAdPodComplete();
11246
+ this.adBreak.continueAfterRequestFailure();
11096
11247
  return [
11097
11248
  3,
11098
11249
  4
@@ -11234,7 +11385,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11234
11385
  key: "destroy",
11235
11386
  value: function destroy() {
11236
11387
  var _this_adPlayer;
11237
- this.adBreak.stopContinuousFetching();
11388
+ this.adBreak.cancelScheduledRequest();
11238
11389
  this.timing.destroy();
11239
11390
  this.adBreak.clearPendingAdBreak();
11240
11391
  this.placeholder.destroy();
@@ -11258,7 +11409,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11258
11409
  this.palNonce.sendPlaybackEnd();
11259
11410
  }
11260
11411
  this.palNonce.reset();
11261
- this.adBreak.adRequestQueue = [];
11262
11412
  this.timing.consecutiveFailures = 0;
11263
11413
  }
11264
11414
  }
@@ -11341,7 +11491,7 @@ var CRITICAL_PROPS = [
11341
11491
  var CONTROLS_HIDE_DELAY = 3e3;
11342
11492
  var DEFAULT_PLAYER_ASPECT_RATIO = 16 / 9;
11343
11493
  var StormcloudVideoPlayerComponent = React.memo(function(props) {
11344
- 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, [
11494
+ 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, [
11345
11495
  "src",
11346
11496
  "autoplay",
11347
11497
  "muted",
@@ -11374,7 +11524,10 @@ var StormcloudVideoPlayerComponent = React.memo(function(props) {
11374
11524
  "minSegmentsBeforePlay",
11375
11525
  "ctvAdRequest",
11376
11526
  "programTitle",
11377
- "channelName"
11527
+ "channelName",
11528
+ "minRemainingMsToStartAd",
11529
+ "minRemainingMsToRequestAd",
11530
+ "maxNoFillsPerBreak"
11378
11531
  ]);
11379
11532
  var videoRef = useRef(null);
11380
11533
  var playerRef = useRef(null);
@@ -11567,6 +11720,9 @@ var StormcloudVideoPlayerComponent = React.memo(function(props) {
11567
11720
  if (ctvAdRequest !== void 0) cfg.ctvAdRequest = ctvAdRequest;
11568
11721
  if (programTitle !== void 0) cfg.programTitle = programTitle;
11569
11722
  if (channelName !== void 0) cfg.channelName = channelName;
11723
+ if (minRemainingMsToStartAd !== void 0) cfg.minRemainingMsToStartAd = minRemainingMsToStartAd;
11724
+ if (minRemainingMsToRequestAd !== void 0) cfg.minRemainingMsToRequestAd = minRemainingMsToRequestAd;
11725
+ if (maxNoFillsPerBreak !== void 0) cfg.maxNoFillsPerBreak = maxNoFillsPerBreak;
11570
11726
  var player = new StormcloudVideoPlayer(cfg);
11571
11727
  playerRef.current = player;
11572
11728
  player.load().then(function() {