stormcloud-video-player 0.8.65 → 0.8.66

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.
@@ -178,6 +178,42 @@ function _object_spread_props(target, source) {
178
178
  }
179
179
  return target;
180
180
  }
181
+ function _object_without_properties(source, excluded) {
182
+ if (source == null) return {};
183
+ var target = {}, sourceKeys, key, i;
184
+ if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
185
+ sourceKeys = Reflect.ownKeys(Object(source));
186
+ for(i = 0; i < sourceKeys.length; i++){
187
+ key = sourceKeys[i];
188
+ if (excluded.indexOf(key) >= 0) continue;
189
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
190
+ target[key] = source[key];
191
+ }
192
+ return target;
193
+ }
194
+ target = _object_without_properties_loose(source, excluded);
195
+ if (Object.getOwnPropertySymbols) {
196
+ sourceKeys = Object.getOwnPropertySymbols(source);
197
+ for(i = 0; i < sourceKeys.length; i++){
198
+ key = sourceKeys[i];
199
+ if (excluded.indexOf(key) >= 0) continue;
200
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
201
+ target[key] = source[key];
202
+ }
203
+ }
204
+ return target;
205
+ }
206
+ function _object_without_properties_loose(source, excluded) {
207
+ if (source == null) return {};
208
+ var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
209
+ for(i = 0; i < sourceKeys.length; i++){
210
+ key = sourceKeys[i];
211
+ if (excluded.indexOf(key) >= 0) continue;
212
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
213
+ target[key] = source[key];
214
+ }
215
+ return target;
216
+ }
181
217
  function _possible_constructor_return(self, call) {
182
218
  if (call && (_type_of(call) === "object" || typeof call === "function")) return call;
183
219
  return _assert_this_initialized(self);
@@ -294,26 +330,6 @@ function _ts_generator(thisArg, body) {
294
330
  };
295
331
  }
296
332
  }
297
- function _ts_values(o) {
298
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
299
- if (m) {
300
- return m.call(o);
301
- }
302
- if (o && typeof o.length === "number") {
303
- return {
304
- next: function() {
305
- if (o && i >= o.length) {
306
- o = void 0;
307
- }
308
- return {
309
- value: o && o[i++],
310
- done: !o
311
- };
312
- }
313
- };
314
- }
315
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
316
- }
317
333
  function _type_of(obj) {
318
334
  "@swc/helpers - typeof";
319
335
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
@@ -841,6 +857,8 @@ function createHlsAdPlayer(contentVideo, options) {
841
857
  var pendingPlayPromise;
842
858
  var currentVastTagUrl;
843
859
  var funnelContext = {};
860
+ var mediaProbe;
861
+ var lastPodAdElementCount = 0;
844
862
  var mediaCandidates = [];
845
863
  var mediaCandidateIndex = 0;
846
864
  var mediaStartTimerId;
@@ -958,6 +976,7 @@ function createHlsAdPlayer(contentVideo, options) {
958
976
  stage: stage,
959
977
  breakId: funnelContext.breakId,
960
978
  requestId: funnelContext.requestId,
979
+ controllerId: funnelContext.controllerId,
961
980
  visibilityState: typeof document !== "undefined" ? document.visibilityState : void 0,
962
981
  adId: currentAd === null || currentAd === void 0 ? void 0 : currentAd.id,
963
982
  podIndex: podIndex,
@@ -1147,7 +1166,6 @@ function createHlsAdPlayer(contentVideo, options) {
1147
1166
  });
1148
1167
  logFunnel("media_candidate", _object_spread_props(_object_spread({}, details), {
1149
1168
  reason: "accepted",
1150
- // Mixed-content media is often auto-upgraded, so it is kept as a last resort.
1151
1169
  why: insecure ? "insecure_http_deprioritized" : "playable",
1152
1170
  score: score
1153
1171
  }));
@@ -1175,6 +1193,145 @@ function createHlsAdPlayer(contentVideo, options) {
1175
1193
  var url = (mediaFile.url.toLowerCase().split("?")[0] || "").trim();
1176
1194
  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");
1177
1195
  }
1196
+ function getMediaProbe() {
1197
+ if (adVideoElement) return adVideoElement;
1198
+ if (!mediaProbe && typeof document !== "undefined") {
1199
+ mediaProbe = document.createElement("video");
1200
+ }
1201
+ return mediaProbe;
1202
+ }
1203
+ function evaluateMediaFile(mf) {
1204
+ var _mf_textContent;
1205
+ var type = mf.getAttribute("type") || "";
1206
+ var url = ((_mf_textContent = mf.textContent) === null || _mf_textContent === void 0 ? void 0 : _mf_textContent.trim()) || "";
1207
+ var delivery = mf.getAttribute("delivery") || void 0;
1208
+ var codec = mf.getAttribute("codec") || void 0;
1209
+ if (!url) {
1210
+ return {
1211
+ category: "missing_media",
1212
+ whyRejected: "empty_url",
1213
+ canPlayType: ""
1214
+ };
1215
+ }
1216
+ var apiFramework = (mf.getAttribute("apiFramework") || "").toUpperCase();
1217
+ if (apiFramework === "VPAID") {
1218
+ return {
1219
+ category: "vpaid",
1220
+ whyRejected: "vpaid_not_supported",
1221
+ canPlayType: ""
1222
+ };
1223
+ }
1224
+ try {
1225
+ var protocol = new URL(url).protocol;
1226
+ if (protocol !== "https:" && protocol !== "http:") {
1227
+ return {
1228
+ category: "invalid_url",
1229
+ whyRejected: "protocol_".concat(protocol),
1230
+ canPlayType: ""
1231
+ };
1232
+ }
1233
+ } catch (unused) {
1234
+ return {
1235
+ category: "invalid_url",
1236
+ whyRejected: "unparseable_url",
1237
+ canPlayType: ""
1238
+ };
1239
+ }
1240
+ var bitrateAttr = mf.getAttribute("bitrate");
1241
+ var bitrateValue = bitrateAttr ? parseInt(bitrateAttr, 10) : void 0;
1242
+ var file = {
1243
+ url: url,
1244
+ type: type,
1245
+ width: parseInt(mf.getAttribute("width") || "1920", 10),
1246
+ height: parseInt(mf.getAttribute("height") || "1080", 10),
1247
+ bitrate: bitrateValue && bitrateValue > 0 ? bitrateValue : void 0,
1248
+ delivery: delivery,
1249
+ codec: codec
1250
+ };
1251
+ if (isAudioMediaFile(file)) {
1252
+ return {
1253
+ category: "audio_only",
1254
+ whyRejected: type.toLowerCase().startsWith("audio/") ? "audio_mime" : "audio_extension",
1255
+ canPlayType: ""
1256
+ };
1257
+ }
1258
+ var isHls = isHlsMediaFile(file);
1259
+ var hasExplicitDimensions = mf.getAttribute("width") != null && mf.getAttribute("height") != null;
1260
+ if (!isHls && hasExplicitDimensions && (file.width <= 1 || file.height <= 1)) {
1261
+ return {
1262
+ category: "audio_only",
1263
+ whyRejected: "zero_dimensions",
1264
+ canPlayType: ""
1265
+ };
1266
+ }
1267
+ var probe = getMediaProbe();
1268
+ if (isHls) {
1269
+ var _ref;
1270
+ var nativeHls = (_ref = probe === null || probe === void 0 ? void 0 : probe.canPlayType("application/vnd.apple.mpegurl")) !== null && _ref !== void 0 ? _ref : "";
1271
+ if (import_hls.default.isSupported()) {
1272
+ return {
1273
+ file: file,
1274
+ whyAccepted: "hls_js",
1275
+ canPlayType: nativeHls
1276
+ };
1277
+ }
1278
+ if (nativeHls !== "") {
1279
+ return {
1280
+ file: file,
1281
+ whyAccepted: "native_hls",
1282
+ canPlayType: nativeHls
1283
+ };
1284
+ }
1285
+ return {
1286
+ category: "unsupported_hls",
1287
+ whyRejected: "no_hls_support",
1288
+ canPlayType: nativeHls
1289
+ };
1290
+ }
1291
+ if (!isProgressiveMediaFile(file)) {
1292
+ return {
1293
+ category: "unsupported_mime",
1294
+ whyRejected: "not_a_video_mime",
1295
+ canPlayType: ""
1296
+ };
1297
+ }
1298
+ if (!probe) {
1299
+ return {
1300
+ file: file,
1301
+ whyAccepted: "no_probe_available",
1302
+ canPlayType: ""
1303
+ };
1304
+ }
1305
+ var baseType = type || "video/mp4";
1306
+ var canPlay2 = probe.canPlayType(baseType);
1307
+ if (canPlay2 === "") {
1308
+ return {
1309
+ category: "unsupported_mime",
1310
+ whyRejected: "canPlayType_empty",
1311
+ canPlayType: canPlay2
1312
+ };
1313
+ }
1314
+ if (codec) {
1315
+ var withCodec = probe.canPlayType("".concat(baseType, '; codecs="').concat(codec, '"'));
1316
+ if (withCodec === "") {
1317
+ return {
1318
+ category: "unsupported_codec",
1319
+ whyRejected: "codec_canPlayType_empty",
1320
+ canPlayType: withCodec
1321
+ };
1322
+ }
1323
+ return {
1324
+ file: file,
1325
+ whyAccepted: "canPlayType_".concat(withCodec),
1326
+ canPlayType: withCodec
1327
+ };
1328
+ }
1329
+ return {
1330
+ file: file,
1331
+ whyAccepted: "canPlayType_".concat(canPlay2),
1332
+ canPlayType: canPlay2
1333
+ };
1334
+ }
1178
1335
  function collectVideoMediaFiles(linear, verbose, stats) {
1179
1336
  var mediaFileElements = linear.querySelectorAll(":scope > MediaFiles > MediaFile");
1180
1337
  var mediaFiles = [];
@@ -1184,57 +1341,33 @@ function createHlsAdPlayer(contentVideo, options) {
1184
1341
  }
1185
1342
  mediaFileElements.forEach(function(mf, index) {
1186
1343
  var _mf_textContent;
1187
- var type = mf.getAttribute("type") || "";
1344
+ var result = evaluateMediaFile(mf);
1188
1345
  var url = ((_mf_textContent = mf.textContent) === null || _mf_textContent === void 0 ? void 0 : _mf_textContent.trim()) || "";
1189
- var width = mf.getAttribute("width") || "";
1190
- var height = mf.getAttribute("height") || "";
1191
- if (verbose) {
1192
- console.log("[HlsAdPlayer] MediaFile ".concat(index, ': type="').concat(type, '", url="').concat(url, '", width="').concat(width, '", height="').concat(height, '"'));
1193
- }
1194
- if (!url) {
1195
- if (verbose) {
1196
- console.warn("[HlsAdPlayer] MediaFile ".concat(index, " has empty URL"));
1197
- }
1198
- return;
1199
- }
1200
- var apiFramework = (mf.getAttribute("apiFramework") || "").toUpperCase();
1201
- if (apiFramework === "VPAID") {
1202
- if (stats) stats.vpaid++;
1203
- if (verbose) {
1204
- console.log("[HlsAdPlayer] MediaFile ".concat(index, " ignored (VPAID creatives are not supported)"));
1205
- }
1206
- return;
1207
- }
1208
- var bitrateAttr = mf.getAttribute("bitrate");
1209
- var bitrateValue = bitrateAttr ? parseInt(bitrateAttr, 10) : void 0;
1210
- var mediaFile = {
1211
- url: url,
1212
- type: type,
1213
- width: parseInt(width || "1920", 10),
1214
- height: parseInt(height || "1080", 10),
1215
- bitrate: bitrateValue && bitrateValue > 0 ? bitrateValue : void 0
1216
- };
1217
- if (isAudioMediaFile(mediaFile)) {
1218
- if (stats) stats.audio++;
1219
- console.warn("[HlsAdPlayer] MediaFile ".concat(index, ' skipped (audio-only, type="').concat(type, '") — audio ads are not played to avoid a black screen'));
1346
+ var accepted = "file" in result;
1347
+ logFunnel("mediafile_evaluated", {
1348
+ reason: accepted ? "accepted" : result.category,
1349
+ index: index,
1350
+ type: mf.getAttribute("type") || "",
1351
+ delivery: mf.getAttribute("delivery") || void 0,
1352
+ codec: mf.getAttribute("codec") || void 0,
1353
+ apiFramework: mf.getAttribute("apiFramework") || void 0,
1354
+ width: mf.getAttribute("width"),
1355
+ height: mf.getAttribute("height"),
1356
+ fileUrl: redactUrl(url),
1357
+ canPlayType: result.canPlayType,
1358
+ whyAccepted: accepted ? result.whyAccepted : void 0,
1359
+ whyRejected: accepted ? void 0 : result.whyRejected
1360
+ });
1361
+ if ("file" in result) {
1362
+ mediaFiles.push(result.file);
1220
1363
  return;
1221
1364
  }
1222
- var hasExplicitDimensions = mf.getAttribute("width") != null && mf.getAttribute("height") != null;
1223
- if (!isHlsMediaFile(mediaFile) && hasExplicitDimensions && (mediaFile.width <= 1 || mediaFile.height <= 1)) {
1224
- if (stats) stats.audio++;
1225
- 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'));
1226
- return;
1365
+ if (stats) {
1366
+ var _stats_categories_result_category;
1367
+ 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;
1227
1368
  }
1228
- if (isHlsMediaFile(mediaFile) || isProgressiveMediaFile(mediaFile)) {
1229
- mediaFiles.push(mediaFile);
1230
- if (verbose) {
1231
- console.log("[HlsAdPlayer] Added ".concat(isHlsMediaFile(mediaFile) ? "HLS" : "progressive", " MediaFile: ").concat(url));
1232
- }
1233
- } else {
1234
- if (stats) stats.unsupported++;
1235
- if (verbose) {
1236
- console.log("[HlsAdPlayer] MediaFile ".concat(index, ' ignored (type="').concat(type, '" is not supported)'));
1237
- }
1369
+ if (result.category === "audio_only") {
1370
+ 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'));
1238
1371
  }
1239
1372
  });
1240
1373
  return mediaFiles;
@@ -1456,7 +1589,7 @@ function createHlsAdPlayer(contentVideo, options) {
1456
1589
  if (adElement.getAttribute("conditionalAd") === "true") {
1457
1590
  console.warn("[HlsAdPlayer] Skipping conditional <Ad> (VPAID-only)");
1458
1591
  logFunnel("vast_no_supported_media", {
1459
- reason: "vpaid_only",
1592
+ reason: "vpaid",
1460
1593
  conditionalAd: true
1461
1594
  });
1462
1595
  return {
@@ -1469,9 +1602,7 @@ function createHlsAdPlayer(contentVideo, options) {
1469
1602
  var mediaFiles = [];
1470
1603
  var rejectStats = {
1471
1604
  total: 0,
1472
- vpaid: 0,
1473
- audio: 0,
1474
- unsupported: 0
1605
+ categories: {}
1475
1606
  };
1476
1607
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1477
1608
  try {
@@ -1500,10 +1631,39 @@ function createHlsAdPlayer(contentVideo, options) {
1500
1631
  }
1501
1632
  if (!linear) {
1502
1633
  console.warn("[HlsAdPlayer] No supported linear media files in <Ad>");
1503
- var reason = rejectStats.total === 0 ? "no_mediafiles" : rejectStats.vpaid > 0 ? "vpaid_only" : rejectStats.audio > 0 ? "audio_only" : "unsupported_type";
1504
- logFunnel("vast_no_supported_media", _object_spread({
1505
- reason: reason
1506
- }, rejectStats));
1634
+ var reason = "missing_media";
1635
+ var top = 0;
1636
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
1637
+ try {
1638
+ for(var _iterator1 = Object.keys(rejectStats.categories)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
1639
+ var category = _step1.value;
1640
+ var _rejectStats_categories_category;
1641
+ var count = (_rejectStats_categories_category = rejectStats.categories[category]) !== null && _rejectStats_categories_category !== void 0 ? _rejectStats_categories_category : 0;
1642
+ if (count > top) {
1643
+ top = count;
1644
+ reason = category;
1645
+ }
1646
+ }
1647
+ } catch (err) {
1648
+ _didIteratorError1 = true;
1649
+ _iteratorError1 = err;
1650
+ } finally{
1651
+ try {
1652
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
1653
+ _iterator1.return();
1654
+ }
1655
+ } finally{
1656
+ if (_didIteratorError1) {
1657
+ throw _iteratorError1;
1658
+ }
1659
+ }
1660
+ }
1661
+ if (rejectStats.total > 0 && top === 0) reason = "other";
1662
+ logFunnel("vast_no_supported_media", {
1663
+ reason: reason,
1664
+ mediaFileCount: rejectStats.total,
1665
+ rejectedByCategory: rejectStats.categories
1666
+ });
1507
1667
  return {
1508
1668
  type: "empty",
1509
1669
  errorUrls: errorUrls,
@@ -1533,9 +1693,9 @@ function createHlsAdPlayer(contentVideo, options) {
1533
1693
  }
1534
1694
  }
1535
1695
  function fetchVastXml(vastTagUrl) {
1536
- var credentials = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "include";
1696
+ var credentials = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "include", kind = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "gam";
1537
1697
  return _async_to_generator(function() {
1538
- var controller, timeoutId, requestVast, response, error, error1;
1698
+ var controller, timeoutId, startedAt, attempt, requestVast, response, error, error1;
1539
1699
  return _ts_generator(this, function(_state) {
1540
1700
  switch(_state.label){
1541
1701
  case 0:
@@ -1547,17 +1707,51 @@ function createHlsAdPlayer(contentVideo, options) {
1547
1707
  timeoutId = controller ? setTimeout(function() {
1548
1708
  return controller.abort();
1549
1709
  }, VAST_REQUEST_TIMEOUT_MS) : void 0;
1710
+ startedAt = Date.now();
1711
+ attempt = 0;
1550
1712
  requestVast = function requestVast(creds) {
1551
- return fetch(vastTagUrl, _object_spread({
1552
- mode: "cors",
1553
- credentials: creds,
1554
- headers: {
1555
- "Accept": "application/xml, text/xml, */*"
1556
- },
1557
- referrerPolicy: "no-referrer-when-downgrade"
1558
- }, controller ? {
1559
- signal: controller.signal
1560
- } : {}));
1713
+ return _async_to_generator(function() {
1714
+ var response;
1715
+ return _ts_generator(this, function(_state) {
1716
+ switch(_state.label){
1717
+ case 0:
1718
+ attempt++;
1719
+ if (kind === "gam") {
1720
+ logFunnel("gam_http_request_sent", {
1721
+ attempt: attempt,
1722
+ credentials: creds
1723
+ });
1724
+ }
1725
+ return [
1726
+ 4,
1727
+ fetch(vastTagUrl, _object_spread({
1728
+ mode: "cors",
1729
+ credentials: creds,
1730
+ headers: {
1731
+ "Accept": "application/xml, text/xml, */*"
1732
+ },
1733
+ referrerPolicy: "no-referrer-when-downgrade"
1734
+ }, controller ? {
1735
+ signal: controller.signal
1736
+ } : {}))
1737
+ ];
1738
+ case 1:
1739
+ response = _state.sent();
1740
+ if (kind === "gam") {
1741
+ logFunnel("gam_response_received", {
1742
+ attempt: attempt,
1743
+ httpStatus: response.status,
1744
+ ok: response.ok,
1745
+ elapsedMs: Date.now() - startedAt
1746
+ });
1747
+ }
1748
+ return [
1749
+ 2,
1750
+ response
1751
+ ];
1752
+ }
1753
+ });
1754
+ })();
1561
1755
  };
1562
1756
  _state.label = 1;
1563
1757
  case 1:
@@ -1614,7 +1808,7 @@ function createHlsAdPlayer(contentVideo, options) {
1614
1808
  ];
1615
1809
  case 8:
1616
1810
  if (!response.ok) {
1617
- throw new Error("Failed to fetch VAST: ".concat(response.statusText));
1811
+ throw new Error("Failed to fetch VAST: HTTP ".concat(response.status, " ").concat(response.statusText));
1618
1812
  }
1619
1813
  return [
1620
1814
  4,
@@ -1629,7 +1823,7 @@ function createHlsAdPlayer(contentVideo, options) {
1629
1823
  error1 = _state.sent();
1630
1824
  if (controller === null || controller === void 0 ? void 0 : controller.signal.aborted) {
1631
1825
  if (pendingRequestAbortReason) {
1632
- throw new Error("".concat(pendingRequestAbortReason, " (timeout): ").concat(vastTagUrl));
1826
+ throw new Error("".concat(pendingRequestAbortReason, ": ").concat(vastTagUrl));
1633
1827
  }
1634
1828
  throw new Error("VAST request timeout after ".concat(VAST_REQUEST_TIMEOUT_MS, "ms: ").concat(vastTagUrl));
1635
1829
  }
@@ -1673,7 +1867,7 @@ function createHlsAdPlayer(contentVideo, options) {
1673
1867
  ]);
1674
1868
  return [
1675
1869
  4,
1676
- fetchVastXml(vastTagUrl, depth === 0 ? "include" : "omit")
1870
+ fetchVastXml(vastTagUrl, depth === 0 ? "include" : "omit", depth === 0 ? "gam" : "wrapper")
1677
1871
  ];
1678
1872
  case 2:
1679
1873
  vastXml = _state.sent();
@@ -1758,10 +1952,11 @@ function createHlsAdPlayer(contentVideo, options) {
1758
1952
  }
1759
1953
  function fetchAndParsePod(vastTagUrl) {
1760
1954
  return _async_to_generator(function() {
1761
- 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;
1955
+ 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;
1762
1956
  return _ts_generator(this, function(_state) {
1763
1957
  switch(_state.label){
1764
1958
  case 0:
1959
+ lastPodAdElementCount = 0;
1765
1960
  return [
1766
1961
  4,
1767
1962
  fetchVastXml(vastTagUrl)
@@ -1776,6 +1971,10 @@ function createHlsAdPlayer(contentVideo, options) {
1776
1971
  trimmedXml = vastXml.trim();
1777
1972
  if (trimmedXml.length === 0) {
1778
1973
  console.warn("[HlsAdPlayer] Pod VAST response body is empty (no fill)");
1974
+ logFunnel("vast_parsed", {
1975
+ adElementCount: 0,
1976
+ reason: "empty_body"
1977
+ });
1779
1978
  return [
1780
1979
  2,
1781
1980
  []
@@ -1784,6 +1983,10 @@ function createHlsAdPlayer(contentVideo, options) {
1784
1983
  xmlDoc = parseXml(vastXml);
1785
1984
  if (!xmlDoc) {
1786
1985
  console.error("[HlsAdPlayer] Pod VAST XML content (first 2000 chars):", vastXml.substring(0, 2e3));
1986
+ logFunnel("vast_parsed", {
1987
+ adElementCount: 0,
1988
+ reason: "xml_parse_error"
1989
+ });
1787
1990
  return [
1788
1991
  2,
1789
1992
  []
@@ -1791,10 +1994,21 @@ function createHlsAdPlayer(contentVideo, options) {
1791
1994
  }
1792
1995
  root = xmlDoc.documentElement;
1793
1996
  adElements = Array.from(root.querySelectorAll(":scope > Ad"));
1997
+ logFunnel("vast_parsed", {
1998
+ reason: adElements.length > 0 ? "has_ads" : "no_ads",
1999
+ vastVersion: (_root_getAttribute = root.getAttribute("version")) !== null && _root_getAttribute !== void 0 ? _root_getAttribute : void 0,
2000
+ adElementCount: adElements.length,
2001
+ inlineCount: adElements.filter(function(el) {
2002
+ return el.querySelector(":scope > InLine");
2003
+ }).length,
2004
+ wrapperCount: adElements.filter(function(el) {
2005
+ return el.querySelector(":scope > Wrapper");
2006
+ }).length
2007
+ });
1794
2008
  if (adElements.length === 0) {
1795
2009
  ;
1796
2010
  ;
1797
- 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)"));
2011
+ 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)"));
1798
2012
  empty = emptyVastResult(root);
1799
2013
  if (empty.type === "empty" && ((_empty_errorUrls = empty.errorUrls) === null || _empty_errorUrls === void 0 ? void 0 : _empty_errorUrls.length)) {
1800
2014
  ;
@@ -1812,10 +2026,15 @@ function createHlsAdPlayer(contentVideo, options) {
1812
2026
  var _parsed_errorUrls, parsed, _parsed_errorCode;
1813
2027
  return _ts_generator(this, function(_state) {
1814
2028
  parsed = parseAdElement(adElement);
1815
- if (parsed.type === "inline") return [
1816
- 2,
1817
- parsed.ad
1818
- ];
2029
+ if (parsed.type === "inline") {
2030
+ logFunnel("inline_resolved", {
2031
+ depth: 0
2032
+ });
2033
+ return [
2034
+ 2,
2035
+ parsed.ad
2036
+ ];
2037
+ }
1819
2038
  if (parsed.type === "wrapper") {
1820
2039
  return [
1821
2040
  2,
@@ -1993,7 +2212,8 @@ function createHlsAdPlayer(contentVideo, options) {
1993
2212
  7
1994
2213
  ];
1995
2214
  case 21:
1996
- 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"));
2215
+ 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"));
2216
+ lastPodAdElementCount = adElements.length;
1997
2217
  return [
1998
2218
  2,
1999
2219
  ads
@@ -3063,6 +3283,17 @@ function createHlsAdPlayer(contentVideo, options) {
3063
3283
  if (!ads.length && pendingRequestAbortReason) {
3064
3284
  throw new Error(pendingRequestAbortReason);
3065
3285
  }
3286
+ if (!ads.length && lastPodAdElementCount > 0) {
3287
+ console.warn("[HlsAdPlayer] VAST response had ads but none were playable");
3288
+ logFunnel("vast_fill_rejected", {
3289
+ adElementCount: lastPodAdElementCount
3290
+ });
3291
+ emit("ad_error");
3292
+ return [
3293
+ 2,
3294
+ Promise.reject(new Error("VAST fill rejected: no playable ad in response"))
3295
+ ];
3296
+ }
3066
3297
  if (!ads.length) {
3067
3298
  console.warn("[HlsAdPlayer] No ads available from VAST response");
3068
3299
  logFunnel("no_fill");
@@ -5496,6 +5727,21 @@ function normalizeVastTagUrl(raw) {
5496
5727
  return raw;
5497
5728
  }
5498
5729
  }
5730
+ var GAM_AD_HOSTS = /* @__PURE__ */ new Set([
5731
+ "pubads.g.doubleclick.net",
5732
+ "securepubads.g.doubleclick.net"
5733
+ ]);
5734
+ function ensureVideoAdType(rawUrl) {
5735
+ try {
5736
+ var url = new URL(rawUrl);
5737
+ if (!GAM_AD_HOSTS.has(url.hostname)) return rawUrl;
5738
+ if (url.searchParams.has("ad_type")) return rawUrl;
5739
+ url.searchParams.set("ad_type", "video");
5740
+ return url.toString();
5741
+ } catch (unused) {
5742
+ return rawUrl;
5743
+ }
5744
+ }
5499
5745
  function applyVastMacros(baseUrl, ctx) {
5500
5746
  var expandedUrl = expandInlineMacroPlaceholders(baseUrl, ctx);
5501
5747
  var url;
@@ -7206,7 +7452,7 @@ var AdConfigManager = /*#__PURE__*/ function() {
7206
7452
  } : {}), {
7207
7453
  consent: this.consentSignals
7208
7454
  }));
7209
- var finalUrl = palNonce.injectNonce(urlWithMacros);
7455
+ var finalUrl = palNonce.injectNonce(ensureVideoAdType(urlWithMacros));
7210
7456
  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);
7211
7457
  return finalUrl;
7212
7458
  }
@@ -8695,6 +8941,18 @@ function resizePlayer(video, adPlayer, debug) {
8695
8941
  }
8696
8942
  }
8697
8943
  // src/player/AdBreakOrchestrator.ts
8944
+ var REQUEST_FAILURE_STAGES = /* @__PURE__ */ new Set([
8945
+ "no_fill",
8946
+ "vast_fill_rejected",
8947
+ "request_failed",
8948
+ "media_unsupported",
8949
+ "play_failed",
8950
+ "play_resolved_but_never_started",
8951
+ "hls_fatal",
8952
+ "media_error",
8953
+ "stall",
8954
+ "decode_failure"
8955
+ ]);
8698
8956
  var AdBreakOrchestrator = /*#__PURE__*/ function() {
8699
8957
  function AdBreakOrchestrator(host, timing, adConfig, cueManager, placeholder) {
8700
8958
  _class_call_check(this, AdBreakOrchestrator);
@@ -8702,15 +8960,17 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8702
8960
  this.showAds = false;
8703
8961
  this.isShowingPlaceholder = false;
8704
8962
  this.adDetectSentForCurrentBreak = false;
8705
- this.continuousFetchingActive = false;
8706
- this.continuousFetchLoopRunning = false;
8963
+ this.slotState = "IDLE";
8964
+ this.unusableResponsesInBreak = 0;
8965
+ this.controllerGeneration = 0;
8966
+ this.requestDiagnostics = /* @__PURE__ */ new Map();
8707
8967
  this.breakFunnel = {};
8708
8968
  this.controllerCallInFlight = false;
8709
8969
  this.playbackStartedForCurrentRequest = false;
8710
8970
  this.opportunityEpoch = -1;
8711
- this.adRequestQueue = [];
8712
8971
  this.adPodQueue = [];
8713
- this.maxPlaceholderDurationMs = 5e3;
8972
+ this.defaultMinRemainingMsToRequestAd = 1e4;
8973
+ this.defaultMaxNoFillsPerBreak = 2;
8714
8974
  this.pendingAdBreak = null;
8715
8975
  this.host = host;
8716
8976
  this.timing = timing;
@@ -8746,7 +9006,23 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8746
9006
  key: "attachImaEventListeners",
8747
9007
  value: function attachImaEventListeners() {
8748
9008
  var _this = this;
8749
- var adPlayer = this.host.getAdPlayer();
9009
+ var controller = this.host.getAdPlayer();
9010
+ var generation = this.controllerGeneration;
9011
+ var adPlayer = {
9012
+ on: function on(event, handler) {
9013
+ controller.on(event, function(payload) {
9014
+ if (generation !== _this.controllerGeneration) {
9015
+ _this.logOrchestratorFunnel("stale_callback_ignored", {
9016
+ event: event,
9017
+ staleControllerId: generation,
9018
+ currentControllerId: _this.controllerGeneration
9019
+ });
9020
+ return;
9021
+ }
9022
+ handler(payload);
9023
+ });
9024
+ }
9025
+ };
8750
9026
  adPlayer.on("pod_ad_started", function(payload) {
8751
9027
  _this.timing.notePodAdStarted();
8752
9028
  if (_this.debug) {
@@ -8762,19 +9038,29 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8762
9038
  });
8763
9039
  adPlayer.on("ad_funnel", function(payload) {
8764
9040
  if (!(payload === null || payload === void 0 ? void 0 : payload.stage)) return;
8765
- _this.countFunnelStage(payload.stage);
9041
+ var stage = payload.stage;
9042
+ _this.countFunnelStage(stage);
8766
9043
  if (payload.reason) {
8767
- _this.countFunnelStage("".concat(payload.stage, ":").concat(payload.reason));
9044
+ _this.countFunnelStage("".concat(stage, ":").concat(payload.reason));
8768
9045
  }
8769
- if (payload.stage === "impression_fired" && payload.pixelCount != null) {
9046
+ if (stage === "impression_fired" && payload.pixelCount != null) {
8770
9047
  _this.countFunnelStage("impression_urls", payload.pixelCount);
8771
9048
  }
8772
9049
  if (payload.visibilityState === "hidden") {
8773
9050
  _this.countFunnelStage("while_hidden");
8774
9051
  }
9052
+ if (stage === "gam_http_request_sent") {
9053
+ if (payload.attempt === 1) {
9054
+ _this.timing.noteAdRequestSent();
9055
+ } else {
9056
+ _this.countFunnelStage("gam_http_request_retry");
9057
+ }
9058
+ }
9059
+ _this.recordRequestDiagnostic(payload);
8775
9060
  });
8776
9061
  adPlayer.on("ad_impression", function() {
8777
9062
  _this.timing.consecutiveFailures = 0;
9063
+ _this.setSlotState("PLAYING", "impression");
8778
9064
  if (!_this.playbackStartedForCurrentRequest) {
8779
9065
  _this.playbackStartedForCurrentRequest = true;
8780
9066
  _this.timing.markAdStarted();
@@ -8793,16 +9079,11 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8793
9079
  var remaining = _this.timing.getRemainingAdMs();
8794
9080
  _this.timing.consecutiveFailures = 0;
8795
9081
  if (_this.debug) {
8796
- console.log("[StormcloudVideoPlayer] all_ads_completed event received - remaining=".concat(remaining, "ms, queued ads=").concat(_this.adRequestQueue.length), _this.adRequestQueue.length > 0 ? {
8797
- queuedUrls: _to_consumable_array(_this.adRequestQueue)
8798
- } : {});
9082
+ console.log("[StormcloudVideoPlayer] all_ads_completed event received - remaining=".concat(remaining, "ms"));
8799
9083
  }
8800
9084
  if (_this.inAdBreak) {
8801
- if (_this.timing.hasTimeToStartAnotherAd()) {
8802
- _this.tryNextAvailableAdWithRateLimit();
8803
- } else {
8804
- _this.handleAdPodComplete();
8805
- }
9085
+ _this.setSlotState("NEEDS_NEXT_AD", "all_ads_completed");
9086
+ _this.requestNextAd("all_ads_completed");
8806
9087
  }
8807
9088
  });
8808
9089
  adPlayer.on("ad_error", function(errorPayload) {
@@ -8823,10 +9104,9 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8823
9104
  }
8824
9105
  console.error("[AD-ERROR]", errorMessage, errorPayload || "");
8825
9106
  if (_this.controllerCallInFlight) {
8826
- _this.timing.recordGamNoFill();
8827
9107
  return;
8828
9108
  }
8829
- _this.handleAdFailure();
9109
+ _this.handleAdFailure("ad_error");
8830
9110
  });
8831
9111
  adPlayer.on("content_pause", function() {
8832
9112
  _this.timing.clearAdFailsafeTimer();
@@ -8865,26 +9145,32 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8865
9145
  }
8866
9146
  _this.timing.consecutiveFailures = 0;
8867
9147
  _this.timing.recordPlayedAdDuration(_this.host.getAdPlayer());
8868
- var remaining = _this.timing.getRemainingAdMs();
8869
9148
  if (_this.debug) {
8870
- console.log("[CONTINUOUS-FETCH] content_resume event: remaining=".concat(remaining, "ms, queued ads=").concat(_this.adRequestQueue.length), _this.adRequestQueue.length > 0 ? {
8871
- queuedUrls: _to_consumable_array(_this.adRequestQueue)
8872
- } : {});
8873
- }
8874
- if (_this.timing.hasTimeToStartAnotherAd()) {
8875
- _this.tryNextAvailableAdWithRateLimit();
8876
- } else {
8877
- _this.handleAdPodComplete();
9149
+ console.log("[AdBreak] content_resume: remaining=".concat(_this.timing.getRemainingAdMs(), "ms"));
8878
9150
  }
9151
+ _this.setSlotState("NEEDS_NEXT_AD", "ad_complete");
9152
+ _this.requestNextAd("ad_complete");
8879
9153
  });
8880
9154
  }
8881
9155
  },
8882
9156
  {
8883
9157
  key: "recreateAdController",
8884
- value: function recreateAdController() {
8885
- if (this.debug) {
8886
- console.log("[StormcloudVideoPlayer] Recreating AdController for new ad");
9158
+ value: function recreateAdController(reason) {
9159
+ if (reason === "new_request" && (this.slotState === "REQUESTING" || this.slotState === "READY")) {
9160
+ console.warn("[AD-CONTROLLER] destroy during active request", {
9161
+ controllerId: this.controllerGeneration,
9162
+ requestId: this.currentRequestId,
9163
+ state: this.slotState,
9164
+ reason: reason
9165
+ });
8887
9166
  }
9167
+ console.log("[AD-CONTROLLER] destroy", {
9168
+ controllerId: this.controllerGeneration,
9169
+ requestId: this.currentRequestId,
9170
+ state: this.slotState,
9171
+ reason: reason
9172
+ });
9173
+ this.countFunnelStage("controller_destroy:".concat(reason));
8888
9174
  var shouldShowPlaceholder = this.inAdBreak && this.showAds;
8889
9175
  var adPlayer = this.host.getAdPlayer();
8890
9176
  if (shouldShowPlaceholder && adPlayer) {
@@ -8911,9 +9197,16 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8911
9197
  var continueLiveStreamDuringAds = this.host.shouldContinueLiveStreamDuringAds();
8912
9198
  var newAdPlayer = this.host.createAdPlayer(continueLiveStreamDuringAds);
8913
9199
  this.host.setAdPlayer(newAdPlayer);
9200
+ this.controllerGeneration++;
8914
9201
  newAdPlayer.initialize();
8915
9202
  newAdPlayer.updateOriginalMutedState(preservedMutedState, preservedVolumeState);
8916
9203
  this.attachImaEventListeners();
9204
+ if (this.debug) {
9205
+ console.log("[AD-CONTROLLER] create", {
9206
+ controllerId: this.controllerGeneration,
9207
+ reason: reason
9208
+ });
9209
+ }
8917
9210
  if (shouldShowPlaceholder) {
8918
9211
  this.placeholder.show();
8919
9212
  newAdPlayer.showPlaceholder();
@@ -8934,32 +9227,57 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8934
9227
  }
8935
9228
  },
8936
9229
  {
8937
- key: "handleAdStart",
8938
- value: // ───────────────────────────────────────────────────────────────
9230
+ // ───────────────────────────────────────────────────────────────
8939
9231
  // Ad break start
8940
9232
  // ───────────────────────────────────────────────────────────────
8941
- function handleAdStart(_marker) {
9233
+ key: "isBreakActive",
9234
+ value: function isBreakActive() {
9235
+ return this.slotState !== "IDLE";
9236
+ }
9237
+ },
9238
+ {
9239
+ key: "getSlotState",
9240
+ value: function getSlotState() {
9241
+ return this.slotState;
9242
+ }
9243
+ },
9244
+ {
9245
+ key: "beginVmapBreak",
9246
+ value: function beginVmapBreak(breakKey) {
9247
+ this.breakSource = "vmap";
9248
+ this.followUpBaseVastUrl = void 0;
9249
+ this.unusableResponsesInBreak = 0;
9250
+ this.timing.totalAdRequestsInBreak = 0;
9251
+ this.setSlotState("NEEDS_NEXT_AD", "vmap_break_start");
9252
+ this.noteOpportunity("vmap", breakKey);
9253
+ }
9254
+ },
9255
+ {
9256
+ key: "handleAdStart",
9257
+ value: function handleAdStart(marker) {
8942
9258
  return _async_to_generator(function() {
8943
- var scheduled, tags, baseVastUrl, adBreakDurationMs, mode, currentMuted, currentVolume, podPlayed;
9259
+ var baseVastUrl, adBreakDurationMs, mode, currentMuted, currentVolume, epoch, podPlayed;
8944
9260
  return _ts_generator(this, function(_state) {
8945
9261
  switch(_state.label){
8946
9262
  case 0:
8947
- scheduled = this.adConfig.findCurrentOrNextBreak(this.host.video.currentTime * 1e3);
8948
- if (scheduled) {
8949
- this.adConfig.consumedVmapBreakIds.add(this.adConfig.getAdBreakKey(scheduled));
9263
+ if (this.slotState !== "IDLE") {
9264
+ this.logOrchestratorFunnel("duplicate_break_start", {
9265
+ source: "scte35",
9266
+ state: this.slotState
9267
+ });
9268
+ return [
9269
+ 2
9270
+ ];
8950
9271
  }
8951
- tags = this.adConfig.selectVastTagsForBreak(scheduled);
8952
- if (tags && tags.length > 0 && tags[0]) {
8953
- baseVastUrl = tags[0];
8954
- } else if (this.adConfig.apiVastTagUrl) {
8955
- baseVastUrl = this.adConfig.apiVastTagUrl;
8956
- } else {
9272
+ baseVastUrl = this.adConfig.apiVastTagUrl;
9273
+ if (!baseVastUrl) {
9274
+ console.warn("[AdBreak] SCTE-35 break started but no direct VAST tag is configured");
8957
9275
  this.clearPendingAdBreak();
8958
9276
  return [
8959
9277
  2
8960
9278
  ];
8961
9279
  }
8962
- adBreakDurationMs = _marker.durationSeconds != null ? _marker.durationSeconds * 1e3 : scheduled === null || scheduled === void 0 ? void 0 : scheduled.durationMs;
9280
+ adBreakDurationMs = marker.durationSeconds != null ? marker.durationSeconds * 1e3 : this.timing.expectedAdBreakDurationMs;
8963
9281
  if (this.debug) {
8964
9282
  mode = this.host.config.isLiveStream ? "LIVE" : "VOD";
8965
9283
  console.log("[CONTINUOUS-FETCH] ".concat(mode, " MODE: Target duration=").concat(adBreakDurationMs, "ms"));
@@ -8967,9 +9285,12 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8967
9285
  this.timing.failedVastUrls.clear();
8968
9286
  this.timing.temporaryFailureUrls.clear();
8969
9287
  this.timing.consecutiveFailures = 0;
8970
- this.continuousFetchingActive = true;
8971
9288
  this.isShowingPlaceholder = false;
8972
9289
  this.timing.totalAdRequestsInBreak = 0;
9290
+ this.breakSource = "scte35";
9291
+ this.followUpBaseVastUrl = baseVastUrl;
9292
+ this.unusableResponsesInBreak = 0;
9293
+ this.setSlotState("NEEDS_NEXT_AD", "scte35_break_start");
8973
9294
  if (this.adConfig.podAssignedByPrefetch) {
8974
9295
  this.adConfig.podAssignedByPrefetch = false;
8975
9296
  } else {
@@ -8988,29 +9309,17 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8988
9309
  this.timing.expectedAdBreakDurationMs = adBreakDurationMs;
8989
9310
  }
8990
9311
  this.noteOpportunity("scte35", this.cueManager.activeScte35BreakKey);
9312
+ epoch = this.timing.adBreakEpoch;
8991
9313
  return [
8992
9314
  4,
8993
9315
  this.startOptimizedPod(baseVastUrl, adBreakDurationMs)
8994
9316
  ];
8995
9317
  case 1:
8996
9318
  podPlayed = _state.sent();
8997
- if (!!podPlayed) return [
8998
- 3,
8999
- 3
9000
- ];
9001
- if (this.debug) {
9002
- console.log("[POD] Initial pod request did not fill; attempting top-up pod request");
9319
+ if (!podPlayed && this.inAdBreak && epoch === this.timing.adBreakEpoch) {
9320
+ this.setSlotState("NEEDS_NEXT_AD", "initial_request_failed");
9321
+ this.requestNextAd("initial_request_failed");
9003
9322
  }
9004
- this.continuousFetchingActive = true;
9005
- this.startContinuousFetching(baseVastUrl);
9006
- return [
9007
- 4,
9008
- this.tryNextAvailableAdWithRateLimit()
9009
- ];
9010
- case 2:
9011
- _state.sent();
9012
- _state.label = 3;
9013
- case 3:
9014
9323
  return [
9015
9324
  2
9016
9325
  ];
@@ -9026,10 +9335,11 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9026
9335
  // ───────────────────────────────────────────────────────────────
9027
9336
  function startOptimizedPod(baseVastUrl, breakDurationMs) {
9028
9337
  return _async_to_generator(function() {
9029
- var podUrl, adPlayer, requestToken, _ref, _adPlayer_getPodAdCount, podCount, error;
9338
+ var podUrl, prefetched, epoch, generation, adPlayer, requestToken, _ref, _adPlayer_getPodAdCount, podCount, error;
9030
9339
  return _ts_generator(this, function(_state) {
9031
9340
  switch(_state.label){
9032
9341
  case 0:
9342
+ prefetched = !!(this.pendingAdBreak && this.pendingAdBreak.vastUrls.length > 0);
9033
9343
  if (this.pendingAdBreak && this.pendingAdBreak.vastUrls.length > 0) {
9034
9344
  podUrl = this.pendingAdBreak.vastUrls[0];
9035
9345
  this.clearPendingAdBreak();
@@ -9042,12 +9352,16 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9042
9352
  false
9043
9353
  ];
9044
9354
  }
9045
- this.continuousFetchingActive = false;
9046
- this.recreateAdController();
9355
+ this.noteVastUrlGenerated(podUrl, prefetched ? "prefetch" : "break_start");
9356
+ epoch = this.timing.adBreakEpoch;
9357
+ this.recreateAdController("new_request");
9358
+ generation = this.controllerGeneration;
9047
9359
  adPlayer = this.host.getAdPlayer();
9048
9360
  requestToken = ++this.timing.adRequestTokenCounter;
9049
9361
  this.timing.activeAdRequestToken = requestToken;
9050
9362
  this.currentVastUrl = podUrl;
9363
+ this.setSlotState("REQUESTING", "initial_pod");
9364
+ this.beginFunnelRequest(adPlayer, requestToken, "initial_pod");
9051
9365
  _state.label = 1;
9052
9366
  case 1:
9053
9367
  _state.trys.push([
@@ -9062,9 +9376,11 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9062
9376
  ];
9063
9377
  case 2:
9064
9378
  _state.sent();
9379
+ if (this.isStale(epoch, generation)) return [
9380
+ 2,
9381
+ true
9382
+ ];
9065
9383
  this.timing.startAdRequestWatchdog(requestToken);
9066
- this.timing.noteAdRequestSent();
9067
- this.beginFunnelRequest(adPlayer, requestToken);
9068
9384
  return [
9069
9385
  4,
9070
9386
  this.callController(function() {
@@ -9074,7 +9390,10 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9074
9390
  case 3:
9075
9391
  _state.sent();
9076
9392
  this.timing.clearAdRequestWatchdog();
9077
- if (this.timing.activeAdRequestToken !== requestToken) {
9393
+ if (this.isStale(epoch, generation)) {
9394
+ this.logOrchestratorFunnel("stale_request_result_ignored", {
9395
+ requestId: requestToken
9396
+ });
9078
9397
  return [
9079
9398
  2,
9080
9399
  true
@@ -9082,11 +9401,16 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9082
9401
  }
9083
9402
  podCount = (_ref = (_adPlayer_getPodAdCount = adPlayer.getPodAdCount) === null || _adPlayer_getPodAdCount === void 0 ? void 0 : _adPlayer_getPodAdCount.call(adPlayer)) !== null && _ref !== void 0 ? _ref : 1;
9084
9403
  if (podCount < 1) {
9404
+ if (this.timing.activeAdRequestToken === requestToken) {
9405
+ this.timing.activeAdRequestToken = null;
9406
+ }
9407
+ this.recordRequestFailure(new Error("No ads available"), podUrl);
9085
9408
  return [
9086
9409
  2,
9087
9410
  false
9088
9411
  ];
9089
9412
  }
9413
+ this.setSlotState("READY", "vast_ready");
9090
9414
  if (this.debug) {
9091
9415
  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"));
9092
9416
  }
@@ -9104,12 +9428,14 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9104
9428
  ];
9105
9429
  case 4:
9106
9430
  _state.sent();
9431
+ if (this.isStale(epoch, generation)) return [
9432
+ 2,
9433
+ true
9434
+ ];
9107
9435
  if (this.timing.expectedAdBreakDurationMs != null && this.timing.getAdBreakEndWallClockMs() == null) {
9108
9436
  this.timing.scheduleAdStopAtBreakBoundary();
9109
9437
  }
9110
9438
  adPlayer.setAdVolume(getAdAudioVolume(adPlayer));
9111
- this.continuousFetchingActive = true;
9112
- this.startContinuousFetching(baseVastUrl);
9113
9439
  return [
9114
9440
  2,
9115
9441
  true
@@ -9121,14 +9447,20 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9121
9447
  if (this.timing.activeAdRequestToken === requestToken) {
9122
9448
  this.timing.activeAdRequestToken = null;
9123
9449
  }
9450
+ if (this.isStale(epoch, generation)) {
9451
+ this.logOrchestratorFunnel("stale_request_result_ignored", {
9452
+ requestId: requestToken,
9453
+ errorMessage: error === null || error === void 0 ? void 0 : error.message
9454
+ });
9455
+ return [
9456
+ 2,
9457
+ true
9458
+ ];
9459
+ }
9124
9460
  if (this.debug) {
9125
9461
  console.warn("[POD] Optimized pod request/play failed:", error);
9126
9462
  }
9127
- if (this.timing.isTemporaryAdError(error)) {
9128
- this.timing.temporaryFailureUrls.set(podUrl, Date.now());
9129
- }
9130
- this.continuousFetchingActive = true;
9131
- this.recreateAdController();
9463
+ this.recordRequestFailure(error, podUrl);
9132
9464
  return [
9133
9465
  2,
9134
9466
  false
@@ -9144,168 +9476,204 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9144
9476
  },
9145
9477
  {
9146
9478
  // ───────────────────────────────────────────────────────────────
9147
- // Continuous fetching
9479
+ // Next-ad scheduling (single flight)
9148
9480
  // ───────────────────────────────────────────────────────────────
9149
- key: "startContinuousFetching",
9150
- value: function startContinuousFetching(baseVastUrl) {
9151
- if (!this.continuousFetchingActive) {
9481
+ key: "setSlotState",
9482
+ value: function setSlotState(next, reason) {
9483
+ if (this.slotState === next) return;
9484
+ var previous = this.slotState;
9485
+ this.slotState = next;
9486
+ if (this.debug) {
9487
+ console.log("[AdBreak][STATE] ".concat(previous, " -> ").concat(next), {
9488
+ reason: reason,
9489
+ breakId: this.timing.adBreakEpoch,
9490
+ requestId: this.currentRequestId,
9491
+ controllerId: this.controllerGeneration
9492
+ });
9493
+ }
9494
+ }
9495
+ },
9496
+ {
9497
+ key: "isStale",
9498
+ value: function isStale(epoch, generation) {
9499
+ return !this.inAdBreak || epoch !== this.timing.adBreakEpoch || generation !== this.controllerGeneration;
9500
+ }
9501
+ },
9502
+ {
9503
+ key: "getMinRemainingMsToRequestAd",
9504
+ value: function getMinRemainingMsToRequestAd() {
9505
+ var configured = this.host.config.minRemainingMsToRequestAd;
9506
+ var floor = this.timing.getMinRemainingMsToStartAd();
9507
+ if (typeof configured === "number" && configured >= 0) {
9508
+ return Math.max(configured, floor);
9509
+ }
9510
+ return Math.max(this.defaultMinRemainingMsToRequestAd, floor);
9511
+ }
9512
+ },
9513
+ {
9514
+ key: "getMaxNoFillsPerBreak",
9515
+ value: function getMaxNoFillsPerBreak() {
9516
+ var configured = this.host.config.maxNoFillsPerBreak;
9517
+ return typeof configured === "number" && configured > 0 ? configured : this.defaultMaxNoFillsPerBreak;
9518
+ }
9519
+ },
9520
+ {
9521
+ key: "isBreakTimeBounded",
9522
+ value: function isBreakTimeBounded() {
9523
+ return this.breakSource === "scte35" || this.timing.expectedAdBreakDurationMs != null;
9524
+ }
9525
+ },
9526
+ {
9527
+ key: "getStopRequestingReason",
9528
+ value: function getStopRequestingReason(remainingMs) {
9529
+ if (this.breakSource === "vmap") {
9530
+ if (this.adPodQueue.length === 0) return "vmap_queue_empty";
9531
+ } else if (this.breakSource !== "scte35" || !this.followUpBaseVastUrl) {
9532
+ return "no_follow_up_source";
9533
+ }
9534
+ if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
9535
+ return "max_consecutive_failures";
9536
+ }
9537
+ if (this.unusableResponsesInBreak >= this.getMaxNoFillsPerBreak()) {
9538
+ return "unusable_response_limit";
9539
+ }
9540
+ if (this.timing.totalAdRequestsInBreak >= this.timing.maxTotalAdRequestsPerBreak) {
9541
+ return "request_cap";
9542
+ }
9543
+ if (this.timing.isGamInCooldown()) {
9544
+ return "gam_cooldown";
9545
+ }
9546
+ if (this.isBreakTimeBounded() && remainingMs < this.getMinRemainingMsToRequestAd()) {
9547
+ return "insufficient_break_time";
9548
+ }
9549
+ return void 0;
9550
+ }
9551
+ },
9552
+ {
9553
+ key: "getNextRequestDelayMs",
9554
+ value: function getNextRequestDelayMs() {
9555
+ var failures = this.timing.consecutiveFailures;
9556
+ var backoff = failures > 0 ? Math.min(this.timing.backoffBaseMs * Math.pow(2, failures), this.timing.maxBackoffMs) : 0;
9557
+ var minInterval = this.timing.minAdRequestIntervalMs + backoff;
9558
+ var sinceLast = Date.now() - this.timing.lastAdRequestTime;
9559
+ return Math.max(0, minInterval - sinceLast);
9560
+ }
9561
+ },
9562
+ {
9563
+ key: "requestNextAd",
9564
+ value: function requestNextAd(trigger) {
9565
+ var _this = this;
9566
+ if (!this.inAdBreak) return;
9567
+ if (this.slotState !== "NEEDS_NEXT_AD") {
9568
+ this.logOrchestratorFunnel("request_suppressed", {
9569
+ trigger: trigger,
9570
+ state: this.slotState,
9571
+ why: "slot_busy"
9572
+ });
9152
9573
  return;
9153
9574
  }
9154
- if (this.continuousFetchLoopRunning) {
9155
- if (this.debug) {
9156
- console.log("[CONTINUOUS-FETCH] Fetch loop already running, skipping duplicate start");
9157
- }
9575
+ if (this.nextAdTimerId != null) {
9576
+ this.logOrchestratorFunnel("request_suppressed", {
9577
+ trigger: trigger,
9578
+ state: this.slotState,
9579
+ why: "request_already_scheduled"
9580
+ });
9158
9581
  return;
9159
9582
  }
9160
- if (this.debug) {
9161
- console.log("[CONTINUOUS-FETCH] Starting continuous ad fetching loop");
9583
+ var remainingMs = this.timing.getRemainingAdMs();
9584
+ var stopReason = this.getStopRequestingReason(remainingMs);
9585
+ if (stopReason) {
9586
+ this.logOrchestratorFunnel("next_ad_decision", {
9587
+ trigger: trigger,
9588
+ decision: "end_break",
9589
+ reason: stopReason,
9590
+ remainingMs: remainingMs,
9591
+ requestsSent: this.timing.totalAdRequestsInBreak,
9592
+ unusableResponses: this.unusableResponsesInBreak,
9593
+ consecutiveFailures: this.timing.consecutiveFailures
9594
+ });
9595
+ this.handleAdPodComplete(stopReason);
9596
+ return;
9162
9597
  }
9163
- this.continuousFetchLoopRunning = true;
9164
- this.continuousFetchLoop(baseVastUrl);
9598
+ var waitMs = this.getNextRequestDelayMs();
9599
+ if (waitMs > 0 && this.isBreakTimeBounded() && remainingMs - waitMs < this.getMinRemainingMsToRequestAd()) {
9600
+ this.logOrchestratorFunnel("next_ad_decision", {
9601
+ trigger: trigger,
9602
+ decision: "end_break",
9603
+ reason: "insufficient_break_time_after_backoff",
9604
+ remainingMs: remainingMs,
9605
+ waitMs: waitMs
9606
+ });
9607
+ this.handleAdPodComplete("insufficient_break_time_after_backoff");
9608
+ return;
9609
+ }
9610
+ this.logOrchestratorFunnel("next_ad_decision", {
9611
+ trigger: trigger,
9612
+ decision: waitMs > 0 ? "request_after_delay" : "request_now",
9613
+ waitMs: waitMs,
9614
+ remainingMs: remainingMs,
9615
+ consecutiveFailures: this.timing.consecutiveFailures
9616
+ });
9617
+ if (waitMs > 0) {
9618
+ if (!this.isShowingPlaceholder) {
9619
+ this.isShowingPlaceholder = true;
9620
+ this.host.getAdPlayer().showPlaceholder();
9621
+ }
9622
+ var epoch = this.timing.adBreakEpoch;
9623
+ this.nextAdTimerId = window.setTimeout(function() {
9624
+ _this.nextAdTimerId = void 0;
9625
+ if (!_this.inAdBreak || epoch !== _this.timing.adBreakEpoch) return;
9626
+ _this.requestNextAd("".concat(trigger, ":after_delay"));
9627
+ }, waitMs);
9628
+ return;
9629
+ }
9630
+ void this.requestFollowUpAd(trigger);
9165
9631
  }
9166
9632
  },
9167
9633
  {
9168
- key: "continuousFetchLoop",
9169
- value: function continuousFetchLoop(baseVastUrl) {
9634
+ key: "requestFollowUpAd",
9635
+ value: function requestFollowUpAd(trigger) {
9170
9636
  return _async_to_generator(function() {
9171
- var _this, _loop, epoch, _ret;
9637
+ var url, epoch, unused;
9172
9638
  return _ts_generator(this, function(_state) {
9173
9639
  switch(_state.label){
9174
9640
  case 0:
9175
- _loop = function() {
9176
- var remaining, maxQueueSize, newAdUrl, queuedUrlsPreview, generationDelay;
9177
- return _ts_generator(this, function(_state) {
9178
- switch(_state.label){
9179
- case 0:
9180
- remaining = Math.min(_this.timing.getWallClockRemainingAdMs(), _this.timing.getDurationBudgetRemainingMs());
9181
- if (remaining <= _this.timing.getMinRemainingMsToStartAd()) {
9182
- if (_this.debug) {
9183
- 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"));
9184
- }
9185
- return [
9186
- 2,
9187
- "break"
9188
- ];
9189
- }
9190
- if (_this.timing.isGamInCooldown()) {
9191
- if (_this.debug) {
9192
- console.log("[CIRCUIT-BREAKER] GAM in cooldown, stopping URL generation");
9193
- }
9194
- return [
9195
- 2,
9196
- "break"
9197
- ];
9198
- }
9199
- if (_this.timing.consecutiveFailures >= _this.timing.maxConsecutiveFailures) {
9200
- if (_this.debug) {
9201
- console.log("[CONTINUOUS-FETCH] Too many consecutive failures (".concat(_this.timing.consecutiveFailures, "), stopping URL generation"));
9202
- }
9203
- return [
9204
- 2,
9205
- "break"
9206
- ];
9207
- }
9208
- if (_this.timing.totalAdRequestsInBreak >= _this.timing.maxTotalAdRequestsPerBreak) {
9209
- if (_this.debug) {
9210
- console.log("[CONTINUOUS-FETCH] Maximum ad requests reached (".concat(_this.timing.maxTotalAdRequestsPerBreak, "), stopping"));
9211
- }
9212
- return [
9213
- 2,
9214
- "break"
9215
- ];
9216
- }
9217
- maxQueueSize = 5;
9218
- if (!(_this.adRequestQueue.length >= maxQueueSize)) return [
9219
- 3,
9220
- 2
9221
- ];
9222
- if (_this.debug) {
9223
- console.log("[CONTINUOUS-FETCH] URL queue full (".concat(_this.adRequestQueue.length, "), waiting..."));
9224
- }
9225
- return [
9226
- 4,
9227
- new Promise(function(resolve) {
9228
- return setTimeout(resolve, 1e3);
9229
- })
9230
- ];
9231
- case 1:
9232
- _state.sent();
9233
- return [
9234
- 2,
9235
- "continue"
9236
- ];
9237
- case 2:
9238
- newAdUrl = _this.nextAdRequestUrl(baseVastUrl);
9239
- if (!(!newAdUrl || _this.timing.failedVastUrls.has(newAdUrl) || _this.timing.isUrlInCooldown(newAdUrl))) return [
9240
- 3,
9241
- 4
9242
- ];
9243
- return [
9244
- 4,
9245
- new Promise(function(resolve) {
9246
- return setTimeout(resolve, 500);
9247
- })
9248
- ];
9249
- case 3:
9250
- _state.sent();
9251
- return [
9252
- 2,
9253
- "continue"
9254
- ];
9255
- case 4:
9256
- if (_this.debug) {
9257
- queuedUrlsPreview = _to_consumable_array(_this.adRequestQueue).concat([
9258
- newAdUrl
9259
- ]);
9260
- console.log("[CONTINUOUS-FETCH] Queued VAST URL (queue size: ".concat(queuedUrlsPreview.length, ")"), {
9261
- queuedUrls: queuedUrlsPreview
9262
- });
9263
- }
9264
- _this.adRequestQueue.push(newAdUrl);
9265
- generationDelay = _this.timing.consecutiveFailures > 0 ? Math.min(1e3 * Math.pow(2, _this.timing.consecutiveFailures), 5e3) : 500;
9266
- return [
9267
- 4,
9268
- new Promise(function(resolve) {
9269
- return setTimeout(resolve, generationDelay);
9270
- })
9271
- ];
9272
- case 5:
9273
- _state.sent();
9274
- return [
9275
- 2
9276
- ];
9277
- }
9278
- });
9279
- };
9641
+ if (this.breakSource === "vmap") {
9642
+ url = this.adPodQueue.shift();
9643
+ } else if (this.followUpBaseVastUrl) {
9644
+ url = this.nextAdRequestUrl(this.followUpBaseVastUrl);
9645
+ }
9646
+ if (!url) return [
9647
+ 2
9648
+ ];
9649
+ this.noteVastUrlGenerated(ensureVideoAdType(url), trigger);
9280
9650
  epoch = this.timing.adBreakEpoch;
9281
9651
  _state.label = 1;
9282
9652
  case 1:
9283
- if (!(this.continuousFetchingActive && this.inAdBreak && epoch === this.timing.adBreakEpoch)) return [
9653
+ _state.trys.push([
9654
+ 1,
9284
9655
  3,
9285
- 3
9286
- ];
9287
- _this = this;
9288
- return [
9289
- 5,
9290
- _ts_values(_loop())
9656
+ ,
9657
+ 4
9658
+ ]);
9659
+ return [
9660
+ 4,
9661
+ this.playSingleAd(url, trigger)
9291
9662
  ];
9292
9663
  case 2:
9293
- _ret = _state.sent();
9294
- if (_ret === "break") return [
9664
+ _state.sent();
9665
+ return [
9295
9666
  3,
9296
- 3
9667
+ 4
9297
9668
  ];
9669
+ case 3:
9670
+ unused = _state.sent();
9671
+ this.continueAfterRequestFailure(epoch);
9298
9672
  return [
9299
9673
  3,
9300
- 1
9674
+ 4
9301
9675
  ];
9302
- case 3:
9303
- this.continuousFetchLoopRunning = false;
9304
- if (this.debug) {
9305
- console.log("[CONTINUOUS-FETCH] URL generation loop ended (queued: ".concat(this.adRequestQueue.length, ")"), this.adRequestQueue.length > 0 ? {
9306
- queuedUrls: _to_consumable_array(this.adRequestQueue)
9307
- } : {});
9308
- }
9676
+ case 4:
9309
9677
  return [
9310
9678
  2
9311
9679
  ];
@@ -9315,242 +9683,158 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9315
9683
  }
9316
9684
  },
9317
9685
  {
9318
- key: "stopContinuousFetching",
9319
- value: function stopContinuousFetching() {
9320
- this.continuousFetchingActive = false;
9321
- this.continuousFetchLoopRunning = false;
9322
- this.placeholder.hide();
9323
- if (this.debug) {
9324
- console.log("[CONTINUOUS-FETCH] Stopping continuous ad fetching");
9686
+ key: "continueAfterRequestFailure",
9687
+ value: function continueAfterRequestFailure() {
9688
+ var epoch = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.timing.adBreakEpoch;
9689
+ if (!this.inAdBreak || epoch !== this.timing.adBreakEpoch) return;
9690
+ this.setSlotState("NEEDS_NEXT_AD", "request_failed");
9691
+ this.requestNextAd("after_failure");
9692
+ }
9693
+ },
9694
+ {
9695
+ key: "cancelScheduledRequest",
9696
+ value: function cancelScheduledRequest() {
9697
+ if (this.nextAdTimerId != null) {
9698
+ clearTimeout(this.nextAdTimerId);
9699
+ this.nextAdTimerId = void 0;
9325
9700
  }
9326
9701
  }
9327
9702
  },
9328
9703
  {
9329
- key: "tryNextAvailableAdWithRateLimit",
9330
- value: // ───────────────────────────────────────────────────────────────
9331
- // Ad iteration
9704
+ key: "noteVastUrlGenerated",
9705
+ value: function noteVastUrlGenerated(url, source) {
9706
+ var _ref, _ref1, _ref2, _ref3, _ref4;
9707
+ var params;
9708
+ try {
9709
+ params = new URL(url).searchParams;
9710
+ } catch (unused) {}
9711
+ var adType = (_ref = params === null || params === void 0 ? void 0 : params.get("ad_type")) !== null && _ref !== void 0 ? _ref : void 0;
9712
+ this.logOrchestratorFunnel("vast_url_generated", {
9713
+ source: source,
9714
+ pod: (_ref1 = params === null || params === void 0 ? void 0 : params.get("pod")) !== null && _ref1 !== void 0 ? _ref1 : void 0,
9715
+ pmad: (_ref2 = params === null || params === void 0 ? void 0 : params.get("pmad")) !== null && _ref2 !== void 0 ? _ref2 : void 0,
9716
+ pmnd: (_ref3 = params === null || params === void 0 ? void 0 : params.get("pmnd")) !== null && _ref3 !== void 0 ? _ref3 : void 0,
9717
+ pmxd: (_ref4 = params === null || params === void 0 ? void 0 : params.get("pmxd")) !== null && _ref4 !== void 0 ? _ref4 : void 0,
9718
+ adType: adType
9719
+ });
9720
+ if (adType === "audio" || adType === "audio_video") {
9721
+ console.warn("[AdBreak] VAST tag requests ad_type=".concat(adType, "; GAM may return audio-only creatives, which this video player rejects"));
9722
+ this.countFunnelStage("tag_allows_audio");
9723
+ }
9724
+ }
9725
+ },
9726
+ {
9727
+ key: "recordRequestFailure",
9728
+ value: function recordRequestFailure(error, vastTagUrl) {
9729
+ var _diag_vastAdCount;
9730
+ var diag = this.currentRequestId != null ? this.requestDiagnostics.get(this.currentRequestId) : void 0;
9731
+ var message = (error === null || error === void 0 ? void 0 : error.message) || "";
9732
+ var outcome;
9733
+ if (message.includes("ad_duration_exceeds_budget")) {
9734
+ outcome = "discarded_budget";
9735
+ } else if (message.includes("VAST fill rejected")) {
9736
+ outcome = "fill_rejected";
9737
+ } else if (/no ads available|no fill|nofill/i.test(message)) {
9738
+ outcome = "no_fill";
9739
+ } else if (/timeout/i.test(message)) {
9740
+ outcome = "request_timeout";
9741
+ } else if (/destroyed|aborted/i.test(message)) {
9742
+ outcome = "request_aborted";
9743
+ } else if (diag && ((_diag_vastAdCount = diag.vastAdCount) !== null && _diag_vastAdCount !== void 0 ? _diag_vastAdCount : 0) > 0 && !diag.impressionFired) {
9744
+ outcome = "playback_failed";
9745
+ } else {
9746
+ outcome = "request_failed";
9747
+ }
9748
+ this.timing.consecutiveFailures++;
9749
+ if (outcome === "no_fill" || outcome === "fill_rejected" || outcome === "discarded_budget") {
9750
+ this.unusableResponsesInBreak++;
9751
+ }
9752
+ if (outcome === "no_fill") {
9753
+ this.timing.recordGamNoFill();
9754
+ }
9755
+ if (diag && !diag.failureReason) {
9756
+ diag.failureReason = "".concat(outcome, ": ").concat(message);
9757
+ }
9758
+ if (this.timing.isTemporaryAdError(error)) {
9759
+ this.timing.temporaryFailureUrls.set(vastTagUrl, Date.now());
9760
+ } else if (outcome !== "discarded_budget") {
9761
+ this.timing.failedVastUrls.add(vastTagUrl);
9762
+ }
9763
+ this.countFunnelStage("request_outcome:".concat(outcome));
9764
+ this.logOrchestratorFunnel("request_outcome", {
9765
+ outcome: outcome,
9766
+ errorMessage: message,
9767
+ consecutiveFailures: this.timing.consecutiveFailures,
9768
+ unusableResponsesInBreak: this.unusableResponsesInBreak
9769
+ });
9770
+ }
9771
+ },
9772
+ {
9332
9773
  // ───────────────────────────────────────────────────────────────
9333
- function tryNextAvailableAdWithRateLimit() {
9334
- return _async_to_generator(function() {
9335
- var epoch, backoffMultiplier, backoffDelay, effectiveMinInterval, timeSinceLastRequest, waitTime;
9336
- return _ts_generator(this, function(_state) {
9337
- switch(_state.label){
9338
- case 0:
9339
- if (!this.inAdBreak) {
9340
- return [
9341
- 2
9342
- ];
9343
- }
9344
- epoch = this.timing.adBreakEpoch;
9345
- if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
9346
- if (this.debug) {
9347
- console.log("[CONTINUOUS-FETCH] Too many consecutive failures (".concat(this.timing.consecutiveFailures, "), ending ad break gracefully"));
9348
- }
9349
- this.handleAdPodComplete();
9350
- return [
9351
- 2
9352
- ];
9353
- }
9354
- backoffMultiplier = Math.pow(2, this.timing.consecutiveFailures);
9355
- backoffDelay = Math.min(this.timing.backoffBaseMs * backoffMultiplier, this.timing.maxBackoffMs);
9356
- effectiveMinInterval = this.timing.minAdRequestIntervalMs + (this.timing.consecutiveFailures > 0 ? backoffDelay : 0);
9357
- timeSinceLastRequest = Date.now() - this.timing.lastAdRequestTime;
9358
- if (!(timeSinceLastRequest < effectiveMinInterval)) return [
9359
- 3,
9360
- 2
9361
- ];
9362
- waitTime = effectiveMinInterval - timeSinceLastRequest;
9363
- if (this.debug) {
9364
- console.log("[CONTINUOUS-FETCH] Rate limiting: waiting ".concat(waitTime, "ms before next request (backoff: ").concat(this.timing.consecutiveFailures, " failures)"));
9365
- }
9366
- return [
9367
- 4,
9368
- new Promise(function(resolve) {
9369
- return setTimeout(resolve, waitTime);
9370
- })
9371
- ];
9372
- case 1:
9373
- _state.sent();
9374
- _state.label = 2;
9375
- case 2:
9376
- if (!this.inAdBreak || epoch !== this.timing.adBreakEpoch) {
9377
- return [
9378
- 2
9379
- ];
9380
- }
9381
- return [
9382
- 2,
9383
- this.tryNextAvailableAd(0)
9384
- ];
9774
+ // Per-request diagnostics
9775
+ // ───────────────────────────────────────────────────────────────
9776
+ key: "recordRequestDiagnostic",
9777
+ value: function recordRequestDiagnostic(payload) {
9778
+ var requestId = payload.requestId;
9779
+ if (typeof requestId !== "number") return;
9780
+ var diag = this.requestDiagnostics.get(requestId);
9781
+ if (!diag) return;
9782
+ switch(payload.stage){
9783
+ case "gam_http_request_sent":
9784
+ diag.gamRequestSent++;
9785
+ break;
9786
+ case "gam_response_received":
9787
+ diag.vastHttpStatus = payload.httpStatus;
9788
+ break;
9789
+ case "vast_parsed":
9790
+ diag.vastAdCount = payload.adElementCount;
9791
+ break;
9792
+ case "wrapper_fetch":
9793
+ case "inline_resolved":
9794
+ if (typeof payload.depth === "number") {
9795
+ diag.wrapperDepth = Math.max(diag.wrapperDepth, payload.depth);
9385
9796
  }
9386
- });
9387
- }).call(this);
9797
+ if (payload.stage === "inline_resolved") diag.inlineResolved = true;
9798
+ break;
9799
+ case "mediafile_evaluated":
9800
+ diag.mediaCandidateCount++;
9801
+ if (payload.whyAccepted) diag.supportedMediaCount++;
9802
+ break;
9803
+ case "playing":
9804
+ diag.playStarted = true;
9805
+ break;
9806
+ case "impression_fired":
9807
+ diag.impressionFired = true;
9808
+ break;
9809
+ default:
9810
+ if (REQUEST_FAILURE_STAGES.has(payload.stage) && !diag.failureReason) {
9811
+ diag.failureReason = payload.reason ? "".concat(payload.stage, ":").concat(payload.reason) : payload.stage;
9812
+ }
9813
+ }
9388
9814
  }
9389
9815
  },
9390
9816
  {
9391
- key: "tryNextAvailableAd",
9392
- value: function tryNextAvailableAd() {
9393
- var retryCount = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
9394
- return _async_to_generator(function() {
9395
- var remaining, nextAdUrl, error, errorMessage, maxRetries;
9396
- return _ts_generator(this, function(_state) {
9397
- switch(_state.label){
9398
- case 0:
9399
- if (!this.inAdBreak) {
9400
- return [
9401
- 2
9402
- ];
9403
- }
9404
- remaining = this.timing.getRemainingAdMs();
9405
- if (!this.timing.hasTimeToStartAnotherAd()) {
9406
- if (this.debug) {
9407
- console.log("[CONTINUOUS-FETCH] Not enough time remaining (".concat(remaining, "ms) to start another ad, ending ad break"));
9408
- }
9409
- this.handleAdPodComplete();
9410
- return [
9411
- 2
9412
- ];
9413
- }
9414
- if (this.timing.isGamInCooldown()) {
9415
- if (this.debug) {
9416
- console.log("[CIRCUIT-BREAKER] GAM in cooldown, ending ad break gracefully");
9417
- }
9418
- this.handleAdPodComplete();
9419
- return [
9420
- 2
9421
- ];
9422
- }
9423
- if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
9424
- if (this.debug) {
9425
- console.log("[CONTINUOUS-FETCH] Too many consecutive failures (".concat(this.timing.consecutiveFailures, "), ending ad break"));
9426
- }
9427
- this.handleAdPodComplete();
9428
- return [
9429
- 2
9430
- ];
9431
- }
9432
- this.timing.cleanupTemporaryFailures();
9433
- _state.label = 1;
9434
- case 1:
9435
- if (!(this.adRequestQueue.length > 0)) return [
9436
- 3,
9437
- 9
9438
- ];
9439
- nextAdUrl = this.adRequestQueue.shift();
9440
- if (!nextAdUrl) return [
9441
- 3,
9442
- 1
9443
- ];
9444
- if (this.timing.failedVastUrls.has(nextAdUrl)) {
9445
- if (this.debug) console.log("[CONTINUOUS-FETCH] Skipping permanently-failed URL, trying next...");
9446
- return [
9447
- 3,
9448
- 1
9449
- ];
9450
- }
9451
- if (this.timing.isUrlInCooldown(nextAdUrl)) {
9452
- if (this.debug) console.log("[CONTINUOUS-FETCH] Skipping URL in cooldown (recent no-fill), trying next...");
9453
- return [
9454
- 3,
9455
- 1
9456
- ];
9457
- }
9458
- if (this.debug) {
9459
- console.log("[CONTINUOUS-FETCH] Requesting next ad via HLS ad player (".concat(this.timing.currentAdIndex + 1, ", ").concat(this.adRequestQueue.length, " remaining in queue)"));
9460
- }
9461
- _state.label = 2;
9462
- case 2:
9463
- _state.trys.push([
9464
- 2,
9465
- 4,
9466
- ,
9467
- 8
9468
- ]);
9469
- return [
9470
- 4,
9471
- this.playSingleAd(nextAdUrl)
9472
- ];
9473
- case 3:
9474
- _state.sent();
9475
- return [
9476
- 3,
9477
- 8
9478
- ];
9479
- case 4:
9480
- error = _state.sent();
9481
- errorMessage = error.message;
9482
- if (this.debug) console.log("[CONTINUOUS-FETCH] Ad request failed:", errorMessage);
9483
- if (!errorMessage.includes("ad_duration_exceeds_budget")) return [
9484
- 3,
9485
- 6
9486
- ];
9487
- this.timing.consecutiveFailures++;
9488
- return [
9489
- 4,
9490
- this.tryNextAvailableAdWithRateLimit()
9491
- ];
9492
- case 5:
9493
- _state.sent();
9494
- return [
9495
- 2
9496
- ];
9497
- case 6:
9498
- if (!errorMessage.includes("permanently failed") && !errorMessage.includes("in cooldown")) {
9499
- this.timing.consecutiveFailures++;
9500
- }
9501
- return [
9502
- 4,
9503
- this.tryNextAvailableAdWithRateLimit()
9504
- ];
9505
- case 7:
9506
- _state.sent();
9507
- return [
9508
- 3,
9509
- 8
9510
- ];
9511
- case 8:
9512
- return [
9513
- 2
9514
- ];
9515
- case 9:
9516
- maxRetries = 3;
9517
- if (!(this.continuousFetchingActive && retryCount < maxRetries && remaining > 2e3)) return [
9518
- 3,
9519
- 12
9520
- ];
9521
- if (this.debug) {
9522
- console.log("[CONTINUOUS-FETCH] Queue empty, waiting for URLs... (".concat(retryCount + 1, "/").concat(maxRetries, ")"));
9523
- }
9524
- return [
9525
- 4,
9526
- new Promise(function(resolve) {
9527
- return setTimeout(resolve, 500);
9528
- })
9529
- ];
9530
- case 10:
9531
- _state.sent();
9532
- return [
9533
- 4,
9534
- this.tryNextAvailableAd(retryCount + 1)
9535
- ];
9536
- case 11:
9537
- _state.sent();
9538
- return [
9539
- 2
9540
- ];
9541
- case 12:
9542
- if (!this.isShowingPlaceholder && remaining > 1e3) {
9543
- this.showPlaceholderAndWaitForAds();
9544
- } else {
9545
- if (this.debug) console.log("[CONTINUOUS-FETCH] No more ads available, ending ad break");
9546
- this.handleAdPodComplete();
9547
- }
9548
- return [
9549
- 2
9550
- ];
9551
- }
9552
- });
9553
- }).call(this);
9817
+ key: "finalizeRequestDiagnostics",
9818
+ value: function finalizeRequestDiagnostics(requestId, endReason) {
9819
+ var _diag_vastAdCount;
9820
+ if (requestId == null) return;
9821
+ var diag = this.requestDiagnostics.get(requestId);
9822
+ if (!diag) return;
9823
+ this.requestDiagnostics.delete(requestId);
9824
+ if (!diag.impressionFired && !diag.failureReason && endReason) {
9825
+ diag.failureReason = endReason;
9826
+ }
9827
+ var gamReturnedAdWithoutImpression = ((_diag_vastAdCount = diag.vastAdCount) !== null && _diag_vastAdCount !== void 0 ? _diag_vastAdCount : 0) > 0 && !diag.impressionFired;
9828
+ if (gamReturnedAdWithoutImpression) {
9829
+ this.countFunnelStage("gam_ad_without_impression");
9830
+ }
9831
+ var startedAt = diag.startedAt, fields = _object_without_properties(diag, [
9832
+ "startedAt"
9833
+ ]);
9834
+ console.log("[AdBreak][REQUEST] summary", _object_spread_props(_object_spread({}, fields), {
9835
+ durationMs: Date.now() - startedAt,
9836
+ gamReturnedAdWithoutImpression: gamReturnedAdWithoutImpression
9837
+ }));
9554
9838
  }
9555
9839
  },
9556
9840
  {
@@ -9558,7 +9842,8 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9558
9842
  // Single ad playback
9559
9843
  // ───────────────────────────────────────────────────────────────
9560
9844
  key: "withCurrentPodBudget",
9561
- value: function withCurrentPodBudget(vastTagUrl) {
9845
+ value: function withCurrentPodBudget(rawVastTagUrl) {
9846
+ var vastTagUrl = ensureVideoAdType(rawVastTagUrl);
9562
9847
  var remaining = Math.min(this.timing.getWallClockRemainingAdMs(), this.timing.getDurationBudgetRemainingMs());
9563
9848
  if (!(remaining > 0)) return vastTagUrl;
9564
9849
  try {
@@ -9617,18 +9902,34 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9617
9902
  },
9618
9903
  {
9619
9904
  key: "beginFunnelRequest",
9620
- value: function beginFunnelRequest(adPlayer, requestToken) {
9905
+ value: function beginFunnelRequest(adPlayer, requestToken, trigger) {
9621
9906
  var _adPlayer_setFunnelContext;
9622
9907
  if (this.controllerCallInFlight) {
9623
9908
  this.logOrchestratorFunnel("duplicate_request_detected", {
9624
9909
  newRequestId: requestToken
9625
9910
  });
9626
9911
  }
9912
+ this.finalizeRequestDiagnostics(this.currentRequestId);
9627
9913
  this.currentRequestId = requestToken;
9628
9914
  this.requestStartedAt = Date.now();
9915
+ this.requestDiagnostics.set(requestToken, {
9916
+ breakId: this.timing.adBreakEpoch,
9917
+ requestId: requestToken,
9918
+ controllerId: this.controllerGeneration,
9919
+ trigger: trigger,
9920
+ gamRequestSent: 0,
9921
+ wrapperDepth: 0,
9922
+ inlineResolved: false,
9923
+ mediaCandidateCount: 0,
9924
+ supportedMediaCount: 0,
9925
+ playStarted: false,
9926
+ impressionFired: false,
9927
+ startedAt: Date.now()
9928
+ });
9629
9929
  (_adPlayer_setFunnelContext = adPlayer.setFunnelContext) === null || _adPlayer_setFunnelContext === void 0 ? void 0 : _adPlayer_setFunnelContext.call(adPlayer, {
9630
9930
  breakId: this.timing.adBreakEpoch,
9631
- requestId: requestToken
9931
+ requestId: requestToken,
9932
+ controllerId: this.controllerGeneration
9632
9933
  });
9633
9934
  }
9634
9935
  },
@@ -9659,7 +9960,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9659
9960
  adPlayer.abortPendingRequest("VAST request aborted after request watchdog timeout");
9660
9961
  return;
9661
9962
  }
9662
- this.handleAdFailure();
9963
+ this.handleAdFailure("request_watchdog_timeout");
9663
9964
  }
9664
9965
  },
9665
9966
  {
@@ -9705,21 +10006,30 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9705
10006
  {
9706
10007
  key: "playSingleAd",
9707
10008
  value: function playSingleAd(vastTagUrl) {
10009
+ var trigger = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "vmap";
9708
10010
  return _async_to_generator(function() {
9709
- var adPlayer, requestToken, ap, requestUrl, _ap_getLoadedAdDuration, adDurationS, remainingMs, playError, error, errorMessage;
10011
+ var epoch, generation, requestToken, ap, requestUrl, _ap_getLoadedAdDuration, adDurationS, remainingMs, error;
9710
10012
  return _ts_generator(this, function(_state) {
9711
10013
  switch(_state.label){
9712
10014
  case 0:
9713
- adPlayer = this.host.getAdPlayer();
9714
- if (adPlayer.isAdPlaying()) return [
9715
- 2
9716
- ];
10015
+ if (this.slotState === "REQUESTING" || this.slotState === "READY" || this.slotState === "PLAYING" || this.slotState === "ENDING") {
10016
+ this.logOrchestratorFunnel("request_suppressed", {
10017
+ trigger: trigger,
10018
+ state: this.slotState,
10019
+ why: "request_in_flight"
10020
+ });
10021
+ return [
10022
+ 2
10023
+ ];
10024
+ }
9717
10025
  if (this.timing.failedVastUrls.has(vastTagUrl)) {
9718
10026
  if (this.debug) console.warn("[AD-ERROR] Skipping permanently-failed VAST URL:", vastTagUrl);
10027
+ this.timing.consecutiveFailures++;
9719
10028
  throw new Error("VAST URL permanently failed");
9720
10029
  }
9721
10030
  if (this.timing.isUrlInCooldown(vastTagUrl)) {
9722
10031
  if (this.debug) console.warn("[AD-ERROR] Skipping URL in cooldown (recent no-fill):", vastTagUrl);
10032
+ this.timing.consecutiveFailures++;
9723
10033
  throw new Error("VAST URL in cooldown after no-fill");
9724
10034
  }
9725
10035
  if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
@@ -9730,16 +10040,23 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9730
10040
  if (this.debug) console.warn("[CIRCUIT-BREAKER] GAM in cooldown, skipping ad request");
9731
10041
  throw new Error("GAM in cooldown");
9732
10042
  }
9733
- this.recreateAdController();
10043
+ epoch = this.timing.adBreakEpoch;
10044
+ this.recreateAdController("new_request");
10045
+ generation = this.controllerGeneration;
9734
10046
  requestToken = ++this.timing.adRequestTokenCounter;
9735
10047
  this.timing.activeAdRequestToken = requestToken;
10048
+ ap = this.host.getAdPlayer();
10049
+ requestUrl = this.withCurrentPodBudget(vastTagUrl);
10050
+ this.currentVastUrl = requestUrl;
10051
+ this.setSlotState("REQUESTING", trigger);
10052
+ this.beginFunnelRequest(ap, requestToken, trigger);
9736
10053
  _state.label = 1;
9737
10054
  case 1:
9738
10055
  _state.trys.push([
9739
10056
  1,
9740
- 8,
10057
+ 5,
9741
10058
  ,
9742
- 9
10059
+ 6
9743
10060
  ]);
9744
10061
  return [
9745
10062
  4,
@@ -9747,12 +10064,10 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9747
10064
  ];
9748
10065
  case 2:
9749
10066
  _state.sent();
10067
+ if (this.isStale(epoch, generation)) return [
10068
+ 2
10069
+ ];
9750
10070
  this.timing.startAdRequestWatchdog(requestToken);
9751
- this.timing.noteAdRequestSent();
9752
- ap = this.host.getAdPlayer();
9753
- requestUrl = this.withCurrentPodBudget(vastTagUrl);
9754
- this.currentVastUrl = requestUrl;
9755
- this.beginFunnelRequest(ap, requestToken);
9756
10071
  return [
9757
10072
  4,
9758
10073
  this.callController(function() {
@@ -9761,36 +10076,31 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9761
10076
  ];
9762
10077
  case 3:
9763
10078
  _state.sent();
10079
+ this.timing.clearAdRequestWatchdog();
10080
+ if (this.isStale(epoch, generation)) {
10081
+ this.logOrchestratorFunnel("stale_request_result_ignored", {
10082
+ requestId: requestToken
10083
+ });
10084
+ return [
10085
+ 2
10086
+ ];
10087
+ }
9764
10088
  sendAdLoadedTracking(this.host.config.licenseKey, {
9765
10089
  source: "hls",
9766
10090
  vastUrl: requestUrl,
9767
10091
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
9768
10092
  }, this.analyticsContext).catch(function() {});
9769
- this.timing.clearAdRequestWatchdog();
9770
- if (this.timing.activeAdRequestToken !== requestToken) return [
9771
- 2
9772
- ];
9773
10093
  if (!this.timing.ensureLoadedAdFitsBudget(ap)) {
9774
10094
  ;
9775
10095
  adDurationS = (_ap_getLoadedAdDuration = ap.getLoadedAdDuration) === null || _ap_getLoadedAdDuration === void 0 ? void 0 : _ap_getLoadedAdDuration.call(ap);
9776
10096
  remainingMs = Math.min(this.timing.getWallClockRemainingAdMs(), this.timing.getDurationBudgetRemainingMs());
9777
10097
  this.logOrchestratorFunnel("discarded_budget", {
9778
- vastUrl: requestUrl,
9779
10098
  adDurationMs: adDurationS != null ? adDurationS * 1e3 : void 0,
9780
10099
  remainingMs: remainingMs
9781
10100
  });
9782
- this.timing.rejectLoadedAdForDuration(ap);
9783
- this.recreateAdController();
9784
10101
  throw new Error("ad_duration_exceeds_budget");
9785
10102
  }
9786
- _state.label = 4;
9787
- case 4:
9788
- _state.trys.push([
9789
- 4,
9790
- 6,
9791
- ,
9792
- 7
9793
- ]);
10103
+ this.setSlotState("READY", "vast_ready");
9794
10104
  this.timing.startAdFailsafeTimer(requestToken);
9795
10105
  return [
9796
10106
  4,
@@ -9798,8 +10108,11 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9798
10108
  return ap.play();
9799
10109
  })
9800
10110
  ];
9801
- case 5:
10111
+ case 4:
9802
10112
  _state.sent();
10113
+ if (this.isStale(epoch, generation)) return [
10114
+ 2
10115
+ ];
9803
10116
  if (this.timing.expectedAdBreakDurationMs != null && this.timing.getAdBreakEndWallClockMs() == null) {
9804
10117
  this.timing.scheduleAdStopAtBreakBoundary();
9805
10118
  }
@@ -9807,216 +10120,31 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9807
10120
  this.timing.temporaryFailureUrls.delete(vastTagUrl);
9808
10121
  return [
9809
10122
  3,
9810
- 7
9811
- ];
9812
- case 6:
9813
- playError = _state.sent();
9814
- if (this.debug) console.error("[AD-ERROR] Failed to play ad:", playError);
9815
- if (this.timing.isTemporaryAdError(playError)) {
9816
- this.timing.temporaryFailureUrls.set(vastTagUrl, Date.now());
9817
- if (this.debug) console.log("[AD-ERROR] Temporary play error - URL can be retried after cooldown");
9818
- } else {
9819
- this.timing.failedVastUrls.add(vastTagUrl);
9820
- if (this.debug) console.log("[AD-ERROR] Permanent play error - URL blacklisted");
9821
- }
9822
- this.timing.clearAdFailsafeTimer();
9823
- if (this.timing.activeAdRequestToken === requestToken) {
9824
- this.timing.activeAdRequestToken = null;
9825
- }
9826
- throw playError;
9827
- case 7:
9828
- return [
9829
- 3,
9830
- 9
10123
+ 6
9831
10124
  ];
9832
- case 8:
10125
+ case 5:
9833
10126
  error = _state.sent();
9834
- errorMessage = (error === null || error === void 0 ? void 0 : error.message) || "";
9835
- if (this.debug) console.error("[AD-ERROR] Ad request failed:", errorMessage);
9836
- if (this.timing.isTemporaryAdError(error)) {
9837
- this.timing.temporaryFailureUrls.set(vastTagUrl, Date.now());
9838
- if (this.debug) console.log("[AD-ERROR] Temporary error (no-fill/timeout) - URL can be retried after cooldown");
9839
- } else {
9840
- this.timing.failedVastUrls.add(vastTagUrl);
9841
- if (this.debug) console.log("[AD-ERROR] Permanent error - URL blacklisted:", errorMessage);
9842
- }
9843
10127
  this.timing.clearAdRequestWatchdog();
9844
10128
  this.timing.clearAdFailsafeTimer();
9845
10129
  if (this.timing.activeAdRequestToken === requestToken) {
9846
10130
  this.timing.activeAdRequestToken = null;
9847
10131
  }
9848
- throw error;
9849
- case 9:
9850
- return [
9851
- 2
9852
- ];
9853
- }
9854
- });
9855
- }).call(this);
9856
- }
9857
- },
9858
- {
9859
- key: "showPlaceholderAndWaitForAds",
9860
- value: // ───────────────────────────────────────────────────────────────
9861
- // Placeholder wait
9862
- // ───────────────────────────────────────────────────────────────
9863
- function showPlaceholderAndWaitForAds() {
9864
- return _async_to_generator(function() {
9865
- var remaining, waitTime, checkInterval, maxChecks, i, nextAdUrl, error, errorMessage;
9866
- return _ts_generator(this, function(_state) {
9867
- switch(_state.label){
9868
- case 0:
9869
- remaining = this.timing.getRemainingAdMs();
9870
- waitTime = Math.min(this.maxPlaceholderDurationMs, remaining);
9871
- if (this.timing.isGamInCooldown()) {
9872
- if (this.debug) console.log("[CIRCUIT-BREAKER] GAM in cooldown, skipping placeholder wait");
9873
- this.handleAdPodComplete();
9874
- return [
9875
- 2
9876
- ];
9877
- }
9878
- if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
9879
- if (this.debug) console.log("[CONTINUOUS-FETCH] Skipping placeholder - too many consecutive failures");
9880
- this.handleAdPodComplete();
9881
- return [
9882
- 2
9883
- ];
9884
- }
9885
- if (waitTime < 1e3) {
9886
- this.handleAdPodComplete();
10132
+ if (this.isStale(epoch, generation)) {
10133
+ this.logOrchestratorFunnel("stale_request_result_ignored", {
10134
+ requestId: requestToken,
10135
+ errorMessage: error === null || error === void 0 ? void 0 : error.message
10136
+ });
9887
10137
  return [
9888
10138
  2
9889
10139
  ];
9890
10140
  }
9891
- if (this.debug) {
9892
- console.log("[CONTINUOUS-FETCH] Showing placeholder for ".concat(waitTime, "ms while waiting for ad URLs"));
10141
+ if (this.debug) console.error("[AD-ERROR] Ad request failed:", error === null || error === void 0 ? void 0 : error.message);
10142
+ this.recordRequestFailure(error, vastTagUrl);
10143
+ if ((error === null || error === void 0 ? void 0 : error.message) === "ad_duration_exceeds_budget") {
10144
+ this.recreateAdController("discarded_budget");
9893
10145
  }
9894
- this.isShowingPlaceholder = true;
9895
- this.host.getAdPlayer().showPlaceholder();
9896
- checkInterval = 300;
9897
- maxChecks = Math.floor(waitTime / checkInterval);
9898
- i = 0;
9899
- _state.label = 1;
9900
- case 1:
9901
- if (!(i < maxChecks)) return [
9902
- 3,
9903
- 12
9904
- ];
9905
- return [
9906
- 4,
9907
- new Promise(function(resolve) {
9908
- return setTimeout(resolve, checkInterval);
9909
- })
9910
- ];
9911
- case 2:
9912
- _state.sent();
9913
- if (!this.inAdBreak) return [
9914
- 2
9915
- ];
9916
- if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
9917
- if (this.debug) console.log("[CONTINUOUS-FETCH] Too many failures during placeholder wait");
9918
- return [
9919
- 3,
9920
- 12
9921
- ];
9922
- }
9923
- if (!this.timing.hasTimeToStartAnotherAd()) {
9924
- if (this.debug) console.log("[CONTINUOUS-FETCH] Not enough time remaining during placeholder wait, ending ad break");
9925
- return [
9926
- 3,
9927
- 12
9928
- ];
9929
- }
9930
- _state.label = 3;
9931
- case 3:
9932
- if (!(this.adRequestQueue.length > 0)) return [
9933
- 3,
9934
- 11
9935
- ];
9936
- if (!this.timing.hasTimeToStartAnotherAd()) return [
9937
- 3,
9938
- 11
9939
- ];
9940
- nextAdUrl = this.adRequestQueue.shift();
9941
- if (!nextAdUrl) return [
9942
- 3,
9943
- 3
9944
- ];
9945
- if (this.timing.failedVastUrls.has(nextAdUrl)) return [
9946
- 3,
9947
- 3
9948
- ];
9949
- if (this.timing.isUrlInCooldown(nextAdUrl)) return [
9950
- 3,
9951
- 3
9952
- ];
9953
- if (this.debug) console.log("[CONTINUOUS-FETCH] Ad URL available, requesting via HLS ad player");
9954
- this.isShowingPlaceholder = false;
9955
- this.host.getAdPlayer().hidePlaceholder();
9956
- _state.label = 4;
9957
- case 4:
9958
- _state.trys.push([
9959
- 4,
9960
- 6,
9961
- ,
9962
- 10
9963
- ]);
9964
- return [
9965
- 4,
9966
- this.playSingleAd(nextAdUrl)
9967
- ];
9968
- case 5:
9969
- _state.sent();
9970
- return [
9971
- 3,
9972
- 10
9973
- ];
10146
+ throw error;
9974
10147
  case 6:
9975
- error = _state.sent();
9976
- errorMessage = error.message;
9977
- if (!errorMessage.includes("ad_duration_exceeds_budget")) return [
9978
- 3,
9979
- 8
9980
- ];
9981
- this.timing.consecutiveFailures++;
9982
- return [
9983
- 4,
9984
- this.tryNextAvailableAdWithRateLimit()
9985
- ];
9986
- case 7:
9987
- _state.sent();
9988
- return [
9989
- 2
9990
- ];
9991
- case 8:
9992
- if (!errorMessage.includes("permanently failed") && !errorMessage.includes("in cooldown")) {
9993
- this.timing.consecutiveFailures++;
9994
- }
9995
- return [
9996
- 4,
9997
- this.tryNextAvailableAdWithRateLimit()
9998
- ];
9999
- case 9:
10000
- _state.sent();
10001
- return [
10002
- 3,
10003
- 10
10004
- ];
10005
- case 10:
10006
- return [
10007
- 2
10008
- ];
10009
- case 11:
10010
- i++;
10011
- return [
10012
- 3,
10013
- 1
10014
- ];
10015
- case 12:
10016
- if (this.debug) console.log("[CONTINUOUS-FETCH] Placeholder timeout, ending ad break");
10017
- this.isShowingPlaceholder = false;
10018
- this.host.getAdPlayer().hidePlaceholder();
10019
- this.handleAdPodComplete();
10020
10148
  return [
10021
10149
  2
10022
10150
  ];
@@ -10030,7 +10158,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
10030
10158
  // Ad break completion
10031
10159
  // ───────────────────────────────────────────────────────────────
10032
10160
  key: "logBreakFunnel",
10033
- value: function logBreakFunnel() {
10161
+ value: function logBreakFunnel(endReason) {
10034
10162
  var funnel = this.breakFunnel;
10035
10163
  this.breakFunnel = {};
10036
10164
  if (Object.keys(funnel).length === 0) return;
@@ -10038,26 +10166,49 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
10038
10166
  var _funnel_stage;
10039
10167
  return (_funnel_stage = funnel[stage]) !== null && _funnel_stage !== void 0 ? _funnel_stage : 0;
10040
10168
  };
10169
+ var countPrefix = function countPrefix(prefix) {
10170
+ return Object.keys(funnel).reduce(function(total, stage) {
10171
+ var _funnel_stage;
10172
+ return stage.indexOf(prefix) === 0 ? total + ((_funnel_stage = funnel[stage]) !== null && _funnel_stage !== void 0 ? _funnel_stage : 0) : total;
10173
+ }, 0);
10174
+ };
10041
10175
  var breakId = this.opportunityEpoch;
10042
- if (count("request_sent") > 0 && count("impression_fired") === 0) {
10176
+ var requestRetries = count("gam_http_request_retry");
10177
+ var requests = count("gam_http_request_sent") - requestRetries;
10178
+ if (requests > 0 && count("impression_fired") === 0) {
10043
10179
  console.log("[AdBreak][FUNNEL] break_abandoned_before_start", {
10044
10180
  breakId: breakId,
10045
- requests: count("request_sent")
10181
+ requests: requests,
10182
+ endReason: endReason
10046
10183
  });
10047
10184
  }
10048
10185
  console.log("[AdBreak][FUNNEL] Break summary", {
10049
10186
  breakId: breakId,
10187
+ endReason: endReason,
10050
10188
  opportunities: count("opportunity_created"),
10051
- requests: count("request_sent"),
10189
+ vastUrlsGenerated: count("vast_url_generated"),
10190
+ requests: requests,
10191
+ requestRetries: requestRetries,
10192
+ gamResponses: count("gam_response_received"),
10193
+ requestsSuppressed: count("request_suppressed"),
10052
10194
  duplicates: count("duplicate_request_detected") + count("duplicate_break_start"),
10053
10195
  filled: count("vast_received"),
10054
10196
  noFill: count("no_fill"),
10197
+ fillRejected: count("vast_fill_rejected"),
10198
+ gamAdWithoutImpression: count("gam_ad_without_impression"),
10199
+ playbackFailedAfterFill: count("request_outcome:playback_failed"),
10055
10200
  requestFailed: count("request_failed"),
10056
10201
  requestAbortedTimeout: count("request_aborted_timeout"),
10057
10202
  credentialsRetries: count("vast_credentials_retry"),
10058
10203
  wrapperFailures: count("wrapper_fetch:failure"),
10059
10204
  noSupportedMedia: count("vast_no_supported_media"),
10060
- vpaidOnly: count("vast_no_supported_media:vpaid_only"),
10205
+ vpaidOnly: count("vast_no_supported_media:vpaid"),
10206
+ audioOnly: count("vast_no_supported_media:audio_only"),
10207
+ mediaFilesEvaluated: count("mediafile_evaluated"),
10208
+ mediaFilesAccepted: count("mediafile_evaluated:accepted"),
10209
+ controllerDestroys: countPrefix("controller_destroy:"),
10210
+ staleCallbacks: count("stale_callback_ignored") + count("stale_request_result_ignored"),
10211
+ tagAllowsAudio: count("tag_allows_audio"),
10061
10212
  missingImpression: count("vast_missing_impression"),
10062
10213
  discardedBudget: count("discarded_budget"),
10063
10214
  mediaCandidates: count("media_candidate:accepted") + count("media_candidate:rejected"),
@@ -10092,25 +10243,50 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
10092
10243
  {
10093
10244
  key: "handleAdPodComplete",
10094
10245
  value: function handleAdPodComplete() {
10246
+ var reason = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "unspecified";
10095
10247
  if (this.debug) {
10096
- console.log("[StormcloudVideoPlayer] Ad pod complete - cleaning up");
10248
+ console.log("[StormcloudVideoPlayer] Ad pod complete - cleaning up", {
10249
+ reason: reason
10250
+ });
10251
+ }
10252
+ var previousState = this.slotState;
10253
+ var alreadyEnded = previousState === "IDLE" && !this.inAdBreak;
10254
+ this.setSlotState("ENDING", reason);
10255
+ this.cancelScheduledRequest();
10256
+ var adPlayer = this.host.getAdPlayer();
10257
+ if (previousState === "REQUESTING") {
10258
+ var _adPlayer_abortPendingRequest;
10259
+ (_adPlayer_abortPendingRequest = adPlayer.abortPendingRequest) === null || _adPlayer_abortPendingRequest === void 0 ? void 0 : _adPlayer_abortPendingRequest.call(adPlayer, "VAST request aborted: ad break ended (".concat(reason, ")"));
10260
+ }
10261
+ if (!alreadyEnded) {
10262
+ console.log("[AD-CONTROLLER] stop", {
10263
+ controllerId: this.controllerGeneration,
10264
+ requestId: this.currentRequestId,
10265
+ state: previousState,
10266
+ reason: reason
10267
+ });
10097
10268
  }
10269
+ this.finalizeRequestDiagnostics(this.currentRequestId, "break_ended:".concat(reason));
10270
+ this.currentRequestId = void 0;
10098
10271
  this.timing.resetForBreakEnd();
10099
- this.stopContinuousFetching();
10272
+ this.placeholder.hide();
10100
10273
  this.clearPendingAdBreak();
10101
10274
  if (this.isShowingPlaceholder) {
10102
- this.host.getAdPlayer().hidePlaceholder();
10275
+ adPlayer.hidePlaceholder();
10103
10276
  this.isShowingPlaceholder = false;
10104
10277
  }
10105
- this.adRequestQueue = [];
10106
10278
  this.inAdBreak = false;
10107
10279
  this.adDetectSentForCurrentBreak = false;
10108
10280
  this.cueManager.activeScte35BreakKey = void 0;
10109
10281
  this.cueManager.scheduledScte35BreakKey = void 0;
10110
10282
  this.adPodQueue = [];
10111
10283
  this.showAds = false;
10112
- this.host.getAdPlayer().stop().catch(function() {});
10113
- this.logBreakFunnel();
10284
+ this.breakSource = void 0;
10285
+ this.followUpBaseVastUrl = void 0;
10286
+ this.unusableResponsesInBreak = 0;
10287
+ adPlayer.stop().catch(function() {});
10288
+ if (!alreadyEnded) this.logBreakFunnel(reason);
10289
+ this.setSlotState("IDLE", "break_complete");
10114
10290
  var restoredMuted = this.host.getAdPlayer().getOriginalMutedState();
10115
10291
  var restoredVolume = this.host.getAdPlayer().getOriginalVolume();
10116
10292
  if (this.host.video.muted !== restoredMuted) {
@@ -10404,25 +10580,23 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
10404
10580
  {
10405
10581
  key: "handleAdFailure",
10406
10582
  value: function handleAdFailure() {
10407
- this.timing.consecutiveFailures++;
10408
- this.timing.recordGamNoFill();
10409
- var remaining = this.timing.getRemainingAdMs();
10410
- if (this.debug) {
10411
- 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 ? {
10412
- queuedUrls: _to_consumable_array(this.adRequestQueue)
10413
- } : {});
10414
- }
10415
- if (this.timing.consecutiveFailures >= this.timing.maxConsecutiveFailures) {
10416
- if (this.debug) console.log("[CONTINUOUS-FETCH] Max consecutive failures reached (".concat(this.timing.consecutiveFailures, "), ending ad break gracefully"));
10417
- this.handleAdPodComplete();
10583
+ var reason = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "ad_failure";
10584
+ if (!this.inAdBreak) return;
10585
+ if (this.slotState === "REQUESTING" || this.slotState === "ENDING") {
10586
+ this.logOrchestratorFunnel("failure_deferred_to_request", {
10587
+ reason: reason,
10588
+ state: this.slotState
10589
+ });
10418
10590
  return;
10419
10591
  }
10420
- if (this.timing.hasTimeToStartAnotherAd()) {
10421
- this.tryNextAvailableAdWithRateLimit();
10422
- } else {
10423
- if (this.debug) console.log("[AD-ERROR] Ad failed and not enough time remaining for another ad. Failed URLs:", this.timing.failedVastUrls.size);
10424
- this.handleAdPodComplete();
10592
+ this.timing.consecutiveFailures++;
10593
+ var diag = this.currentRequestId != null ? this.requestDiagnostics.get(this.currentRequestId) : void 0;
10594
+ if (diag && !diag.failureReason) diag.failureReason = reason;
10595
+ if (this.debug) {
10596
+ console.log("[AdBreak] Ad failure (".concat(reason, "): remaining=").concat(this.timing.getRemainingAdMs(), "ms, consecutiveFailures=").concat(this.timing.consecutiveFailures));
10425
10597
  }
10598
+ this.setSlotState("NEEDS_NEXT_AD", reason);
10599
+ this.requestNextAd(reason);
10426
10600
  }
10427
10601
  }
10428
10602
  ]);
@@ -10465,7 +10639,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10465
10639
  return _this.adBreak.handleRequestWatchdogTimeout();
10466
10640
  },
10467
10641
  onFailsafeTimeout: function onFailsafeTimeout() {
10468
- return _this.adBreak.handleAdFailure();
10642
+ return _this.adBreak.handleAdFailure("failsafe_timeout");
10469
10643
  },
10470
10644
  getAdState: function getAdState() {
10471
10645
  return {
@@ -10715,6 +10889,21 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10715
10889
  adBehavior: adBehavior
10716
10890
  });
10717
10891
  }
10892
+ if (this.adBreak.isBreakActive()) {
10893
+ console.log("[AD-CONTROLLER] destroy skipped", {
10894
+ reason: "manifest_parsed_during_break",
10895
+ state: this.adBreak.getSlotState()
10896
+ });
10897
+ return [
10898
+ 2
10899
+ ];
10900
+ }
10901
+ if (this.debug) {
10902
+ console.log("[AD-CONTROLLER] destroy", {
10903
+ reason: "manifest_parsed",
10904
+ state: "IDLE"
10905
+ });
10906
+ }
10718
10907
  this.adPlayer.destroy();
10719
10908
  this.adPlayer = this.createAdPlayer(this.shouldContinueLiveStreamDuringAds());
10720
10909
  this.adPlayer.initialize();
@@ -10896,9 +11085,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10896
11085
  this.timing.setAdBreakDurationBoundary(marker.durationSeconds * 1e3);
10897
11086
  }
10898
11087
  this.timing.scheduleAdStopAtBreakBoundary();
10899
- if (!this.adPlayer.isAdPlaying() && this.timing.activeAdRequestToken === null && this.adBreak.adRequestQueue.length > 0 && this.timing.hasTimeToStartAnotherAd()) {
10900
- this.adBreak.tryNextAvailableAdWithRateLimit();
10901
- }
10902
11088
  return;
10903
11089
  }
10904
11090
  if (marker.type === "end") {
@@ -10910,12 +11096,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10910
11096
  }
10911
11097
  var remaining = this.timing.getRemainingAdMs();
10912
11098
  var adPlaying = this.adPlayer.isAdPlaying();
10913
- var hasQueuedAds = this.adBreak.adRequestQueue.length > 0;
10914
11099
  if (this.debug) {
10915
11100
  console.log("[StormcloudVideoPlayer] SCTE-35 end marker received:", {
10916
11101
  remaining: remaining,
10917
11102
  adPlaying: adPlaying,
10918
- hasQueuedAds: hasQueuedAds,
11103
+ adSlotState: this.adBreak.getSlotState(),
10919
11104
  activeAdRequest: this.timing.activeAdRequestToken !== null
10920
11105
  });
10921
11106
  }
@@ -10926,7 +11111,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10926
11111
  this.adBreak.noteStopBeforeStart("scte_end");
10927
11112
  this.adPlayer.stop().catch(function() {});
10928
11113
  }
10929
- this.adBreak.handleAdPodComplete();
11114
+ this.adBreak.handleAdPodComplete("scte_end");
10930
11115
  return;
10931
11116
  }
10932
11117
  }
@@ -10934,6 +11119,15 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10934
11119
  {
10935
11120
  key: "startScte35AdBreak",
10936
11121
  value: function startScte35AdBreak(marker, cueKey, durationMs) {
11122
+ if (this.adBreak.isBreakActive()) {
11123
+ if (this.debug) {
11124
+ console.log("[StormcloudVideoPlayer] Ignoring SCTE-35 break start: a break is already active", {
11125
+ state: this.adBreak.getSlotState(),
11126
+ cueKey: cueKey
11127
+ });
11128
+ }
11129
+ return;
11130
+ }
10937
11131
  this.adBreak.inAdBreak = true;
10938
11132
  this.cueManager.activeScte35BreakKey = cueKey !== null && cueKey !== void 0 ? cueKey : this.cueManager.pendingScte35CueKey;
10939
11133
  this.cueManager.scheduledScte35BreakKey = void 0;
@@ -10966,7 +11160,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10966
11160
  this.adBreak.noteStopBeforeStart("break_boundary");
10967
11161
  this.adPlayer.stop().catch(function() {});
10968
11162
  }
10969
- this.adBreak.handleAdPodComplete();
11163
+ this.adBreak.handleAdPodComplete("break_boundary");
10970
11164
  }
10971
11165
  },
10972
11166
  {
@@ -10976,14 +11170,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10976
11170
  key: "startAdPrefetch",
10977
11171
  value: function startAdPrefetch(marker, fragmentSn, cueKey) {
10978
11172
  if (this.adBreak.pendingAdBreak || this.adBreak.inAdBreak) return;
10979
- var scheduled = this.adConfig.findCurrentOrNextBreak(this.video.currentTime * 1e3);
10980
- var tags = this.adConfig.selectVastTagsForBreak(scheduled);
10981
- var baseVastUrl;
10982
- if (tags && tags.length > 0 && tags[0]) {
10983
- baseVastUrl = tags[0];
10984
- } else if (this.adConfig.apiVastTagUrl) {
10985
- baseVastUrl = this.adConfig.apiVastTagUrl;
10986
- } else {
11173
+ var baseVastUrl = this.adConfig.apiVastTagUrl;
11174
+ if (!baseVastUrl) {
10987
11175
  if (this.debug) console.warn("[StormcloudVideoPlayer] No VAST URL available for prefetch");
10988
11176
  return;
10989
11177
  }
@@ -11013,8 +11201,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11013
11201
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
11014
11202
  }, detectPayload), buildAnalyticsContext(this.config)).catch(function() {});
11015
11203
  if (this.debug) {
11016
- console.log("[PREFETCH] Starting ad prefetch for upcoming ad break");
11017
- console.log("[PREFETCH] Pre-generated pod request URL");
11204
+ console.log("[PREFETCH] Pre-generated pod request URL for upcoming ad break");
11018
11205
  }
11019
11206
  }
11020
11207
  },
@@ -11025,7 +11212,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11025
11212
  key: "onTimeUpdate",
11026
11213
  value: function onTimeUpdate(currentTimeSec) {
11027
11214
  var _this = this;
11028
- if (!this.adConfig.isVmapEnabled() || this.adConfig.vmapBreaks.length === 0) return;
11215
+ if (this.adConfig.vmapBreaks.length === 0) return;
11029
11216
  if (this.adPlayer.isAdPlaying() || this.adBreak.inAdBreak) return;
11030
11217
  var nowMs = currentTimeSec * 1e3;
11031
11218
  var breakToPlay = this.adConfig.findBreakForTime(nowMs);
@@ -11042,7 +11229,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11042
11229
  key: "onVideoEnded",
11043
11230
  value: function onVideoEnded() {
11044
11231
  var _this = this;
11045
- if (!this.adConfig.isVmapEnabled() || this.adConfig.vmapBreaks.length === 0) return;
11232
+ if (this.adConfig.vmapBreaks.length === 0) return;
11046
11233
  if (this.adPlayer.isAdPlaying() || this.adBreak.inAdBreak) return;
11047
11234
  var durationMs = Number.isFinite(this.video.duration) ? Math.floor(this.video.duration * 1e3) : 0;
11048
11235
  var postroll = this.adConfig.vmapBreaks.find(function(b) {
@@ -11095,7 +11282,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11095
11282
  if (durationMs > 0) {
11096
11283
  this.timing.setAdBreakDurationBoundary(durationMs);
11097
11284
  }
11098
- this.adBreak.noteOpportunity("vmap", key);
11285
+ this.adBreak.beginVmapBreak(key);
11099
11286
  _state.label = 1;
11100
11287
  case 1:
11101
11288
  _state.trys.push([
@@ -11106,7 +11293,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11106
11293
  ]);
11107
11294
  return [
11108
11295
  4,
11109
- this.adBreak.playSingleAd(first)
11296
+ this.adBreak.playSingleAd(first, "vmap")
11110
11297
  ];
11111
11298
  case 2:
11112
11299
  _state.sent();
@@ -11119,7 +11306,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11119
11306
  if (this.debug) {
11120
11307
  console.warn("[StormcloudVideoPlayer] VMAP ad request failed:", error);
11121
11308
  }
11122
- this.adBreak.handleAdPodComplete();
11309
+ this.adBreak.continueAfterRequestFailure();
11123
11310
  return [
11124
11311
  3,
11125
11312
  4
@@ -11261,7 +11448,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11261
11448
  key: "destroy",
11262
11449
  value: function destroy() {
11263
11450
  var _this_adPlayer;
11264
- this.adBreak.stopContinuousFetching();
11451
+ this.adBreak.cancelScheduledRequest();
11265
11452
  this.timing.destroy();
11266
11453
  this.adBreak.clearPendingAdBreak();
11267
11454
  this.placeholder.destroy();
@@ -11285,7 +11472,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
11285
11472
  this.palNonce.sendPlaybackEnd();
11286
11473
  }
11287
11474
  this.palNonce.reset();
11288
- this.adBreak.adRequestQueue = [];
11289
11475
  this.timing.consecutiveFailures = 0;
11290
11476
  }
11291
11477
  }