stormcloud-video-player 0.8.63 → 0.8.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -740,6 +740,7 @@ function parseProgressOffset(offset) {
740
740
  } : void 0;
741
741
  }
742
742
  var MAX_VAST_WRAPPER_DEPTH = 5;
743
+ var VAST_REQUEST_TIMEOUT_MS = 5e3;
743
744
  var BEACON_TIMEOUT_MS = 3e4;
744
745
  var inFlightBeacons = /* @__PURE__ */ new Set();
745
746
  var VAST_ERROR_MEDIA_DISPLAY = 405;
@@ -763,7 +764,7 @@ function toVastMediaErrorCode(error) {
763
764
  }
764
765
  }
765
766
  function createHlsAdPlayer(contentVideo, options) {
766
- var _contentVideo_AD_VIDEO_PROP, _contentVideo_AD_CONTAINER_PROP;
767
+ var _contentVideo_AD_VIDEO_PROP, _contentVideo_AD_CONTAINER_PROP, _ref;
767
768
  var adPlaying = false;
768
769
  var originalMutedState = false;
769
770
  var originalVolume = Math.max(0, Math.min(1, contentVideo.volume || 1));
@@ -795,6 +796,16 @@ function createHlsAdPlayer(contentVideo, options) {
795
796
  var sawDecodedVideoFrame = false;
796
797
  var videoFrameCallbackHandle;
797
798
  var pendingPlayPromise;
799
+ var currentVastTagUrl;
800
+ var funnelContext = {};
801
+ var mediaCandidates = [];
802
+ var mediaCandidateIndex = 0;
803
+ var mediaStartTimerId;
804
+ var MEDIA_START_TIMEOUT_MS = (_ref = options === null || options === void 0 ? void 0 : options.mediaStartTimeoutMs) !== null && _ref !== void 0 ? _ref : 8e3;
805
+ var VAST_ERROR_MEDIA_TIMEOUT = 402;
806
+ var pendingVastRequests = /* @__PURE__ */ new Set();
807
+ var pendingRequestAbortReason;
808
+ var forcedMuteByAutoplay = false;
798
809
  function createTrackingState() {
799
810
  return {
800
811
  impression: false,
@@ -845,6 +856,77 @@ function createHlsAdPlayer(contentVideo, options) {
845
856
  }
846
857
  }
847
858
  }
859
+ var SENSITIVE_URL_PARAMS = /* @__PURE__ */ new Set([
860
+ "ppid",
861
+ "rdid",
862
+ "idtype",
863
+ "is_lat",
864
+ "ifa",
865
+ "idfa",
866
+ "aaid",
867
+ "uid",
868
+ "user_id",
869
+ "userid",
870
+ "device_id",
871
+ "deviceid",
872
+ "ip",
873
+ "ua",
874
+ "gdpr_consent",
875
+ "us_privacy",
876
+ "gpp",
877
+ "addtl_consent",
878
+ "cust_params",
879
+ "email"
880
+ ]);
881
+ function redactUrl(url) {
882
+ if (!url) return url;
883
+ try {
884
+ var parsed = new URL(url);
885
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
886
+ try {
887
+ for(var _iterator = Array.from(parsed.searchParams.keys())[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
888
+ var key = _step.value;
889
+ if (SENSITIVE_URL_PARAMS.has(key.toLowerCase())) {
890
+ parsed.searchParams.set(key, "REDACTED");
891
+ }
892
+ }
893
+ } catch (err) {
894
+ _didIteratorError = true;
895
+ _iteratorError = err;
896
+ } finally{
897
+ try {
898
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
899
+ _iterator.return();
900
+ }
901
+ } finally{
902
+ if (_didIteratorError) {
903
+ throw _iteratorError;
904
+ }
905
+ }
906
+ }
907
+ return parsed.toString();
908
+ } catch (unused) {
909
+ return url.split("?")[0];
910
+ }
911
+ }
912
+ function logFunnel(stage) {
913
+ var extra = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
914
+ var payload = _object_spread({
915
+ stage: stage,
916
+ breakId: funnelContext.breakId,
917
+ requestId: funnelContext.requestId,
918
+ visibilityState: typeof document !== "undefined" ? document.visibilityState : void 0,
919
+ adId: currentAd === null || currentAd === void 0 ? void 0 : currentAd.id,
920
+ podIndex: podIndex,
921
+ podSize: podAds.length,
922
+ vastUrl: redactUrl(currentVastTagUrl),
923
+ mediaUrl: currentAdMediaFile === null || currentAdMediaFile === void 0 ? void 0 : currentAdMediaFile.url,
924
+ mediaType: currentAdMediaFile === null || currentAdMediaFile === void 0 ? void 0 : currentAdMediaFile.type,
925
+ muted: adVideoElement ? adVideoElement.muted : void 0
926
+ }, extra);
927
+ console.log("[HlsAdPlayer][FUNNEL] ".concat(stage), payload);
928
+ emit("ad_funnel", payload);
929
+ }
848
930
  function buildTrackingMacroContext() {
849
931
  var options2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
850
932
  var _options2_ad;
@@ -884,20 +966,53 @@ function createHlsAdPlayer(contentVideo, options) {
884
966
  urls.forEach(function(url) {
885
967
  try {
886
968
  var trackingUrl = substituteVastTrackingMacros(url, macroContext);
969
+ var trackingHost;
970
+ try {
971
+ trackingHost = new URL(trackingUrl).host;
972
+ } catch (unused) {
973
+ logFunnel("tracking_url_invalid", {
974
+ trackingUrl: redactUrl(trackingUrl)
975
+ });
976
+ return;
977
+ }
978
+ var unexpanded = trackingUrl.match(/\[[A-Z_]+\]/g);
979
+ if (unexpanded) {
980
+ logFunnel("tracking_url_unexpanded_macro", {
981
+ trackingHost: trackingHost,
982
+ macros: Array.from(new Set(unexpanded))
983
+ });
984
+ }
887
985
  var img = new Image(1, 1);
888
986
  inFlightBeacons.add(img);
889
987
  var timeoutId;
890
- var release = function release() {
988
+ var release = function release(outcome) {
891
989
  if (timeoutId !== void 0) clearTimeout(timeoutId);
892
990
  img.onload = null;
893
991
  img.onerror = null;
894
992
  inFlightBeacons.delete(img);
993
+ console.log("[HlsAdPlayer] Tracking pixel settled (".concat(outcome, "): ").concat(trackingUrl));
994
+ if (outcome !== "load") {
995
+ logFunnel("tracking_request_settled", {
996
+ reason: outcome,
997
+ trackingHost: trackingHost
998
+ });
999
+ }
895
1000
  };
896
- img.onload = release;
897
- img.onerror = release;
898
- timeoutId = setTimeout(release, BEACON_TIMEOUT_MS);
1001
+ img.onload = function() {
1002
+ return release("load");
1003
+ };
1004
+ img.onerror = function() {
1005
+ return release("error");
1006
+ };
1007
+ timeoutId = setTimeout(function() {
1008
+ return release("timeout");
1009
+ }, BEACON_TIMEOUT_MS);
899
1010
  img.src = trackingUrl;
900
1011
  console.log("[HlsAdPlayer] Fired tracking pixel: ".concat(trackingUrl));
1012
+ logFunnel("tracking_request_created", {
1013
+ trackingHost: trackingHost,
1014
+ errorCode: options2 === null || options2 === void 0 ? void 0 : options2.errorCode
1015
+ });
901
1016
  } catch (error) {
902
1017
  console.warn("[HlsAdPlayer] Error firing tracking pixel:", error);
903
1018
  }
@@ -927,54 +1042,80 @@ function createHlsAdPlayer(contentVideo, options) {
927
1042
  bitrate: level.bitrate || 5e6
928
1043
  };
929
1044
  }
930
- function selectBestMediaFile(mediaFiles) {
931
- if (mediaFiles.length === 0) {
932
- throw new Error("No media files available");
933
- }
934
- var firstFile = mediaFiles[0];
935
- if (!firstFile) {
936
- throw new Error("No media files available");
937
- }
938
- if (mediaFiles.length === 1) {
939
- return firstFile;
940
- }
1045
+ function getMediaTargetQuality() {
941
1046
  var mainQuality = getMainStreamQuality();
942
- if (!mainQuality) {
943
- console.log("[HlsAdPlayer] No main stream quality info, using first media file");
944
- return firstFile;
945
- }
946
- console.log("[HlsAdPlayer] Main stream quality:", mainQuality);
947
- var scoredFiles = mediaFiles.map(function(file) {
948
- var widthDiff = Math.abs(file.width - mainQuality.width);
949
- var heightDiff = Math.abs(file.height - mainQuality.height);
950
- var resolutionDiff = widthDiff + heightDiff;
951
- var fileBitrate = (file.bitrate || 5e3) * 1e3;
952
- var bitrateDiff = Math.abs(fileBitrate - mainQuality.bitrate);
953
- var score = resolutionDiff * 2 + bitrateDiff / 1e3;
954
- return {
1047
+ var dpr = typeof window !== "undefined" && window.devicePixelRatio > 0 ? window.devicePixelRatio : 1;
1048
+ var containerWidth = ((adContainerEl === null || adContainerEl === void 0 ? void 0 : adContainerEl.clientWidth) || contentVideo.clientWidth) * dpr;
1049
+ var containerHeight = ((adContainerEl === null || adContainerEl === void 0 ? void 0 : adContainerEl.clientHeight) || contentVideo.clientHeight) * dpr;
1050
+ if (!mainQuality && !(containerWidth > 0 && containerHeight > 0)) {
1051
+ return null;
1052
+ }
1053
+ var base = mainQuality !== null && mainQuality !== void 0 ? mainQuality : {
1054
+ width: containerWidth,
1055
+ height: containerHeight,
1056
+ bitrate: 5e6
1057
+ };
1058
+ var width = containerWidth > 0 ? Math.min(base.width, containerWidth) : base.width;
1059
+ var height = containerHeight > 0 ? Math.min(base.height, containerHeight) : base.height;
1060
+ return {
1061
+ width: width,
1062
+ height: height,
1063
+ bitrate: base.bitrate
1064
+ };
1065
+ }
1066
+ function rankMediaCandidates(mediaFiles) {
1067
+ var probe = adVideoElement !== null && adVideoElement !== void 0 ? adVideoElement : document.createElement("video");
1068
+ var pageIsHttps = typeof location !== "undefined" && location.protocol === "https:";
1069
+ var target = getMediaTargetQuality();
1070
+ var accepted = [];
1071
+ mediaFiles.forEach(function(file, index) {
1072
+ var isHls = isHlsMediaFile(file);
1073
+ var mimeForProbe = isHls ? "application/vnd.apple.mpegurl" : file.type || "video/mp4";
1074
+ var canPlay2 = probe.canPlayType(mimeForProbe);
1075
+ var playable = isHls ? Hls.isSupported() || canPlay2 !== "" : canPlay2 !== "";
1076
+ var insecure = pageIsHttps && /^http:/i.test(file.url);
1077
+ var details = {
1078
+ index: index,
1079
+ candidateUrl: file.url,
1080
+ candidateType: file.type,
1081
+ width: file.width,
1082
+ height: file.height,
1083
+ bitrate: file.bitrate,
1084
+ canPlayType: canPlay2,
1085
+ hlsJs: isHls ? Hls.isSupported() : void 0
1086
+ };
1087
+ if (!playable) {
1088
+ logFunnel("media_candidate", _object_spread_props(_object_spread({}, details), {
1089
+ reason: "rejected",
1090
+ why: "cannot_play_type"
1091
+ }));
1092
+ return;
1093
+ }
1094
+ var score = 0;
1095
+ if (target) {
1096
+ var resolutionDiff = Math.abs(file.width - target.width) + Math.abs(file.height - target.height);
1097
+ var bitrateDiff = Math.abs((file.bitrate || 5e3) * 1e3 - target.bitrate);
1098
+ score = resolutionDiff * 2 + bitrateDiff / 1e3;
1099
+ }
1100
+ accepted.push({
955
1101
  file: file,
956
1102
  score: score,
957
- resolutionDiff: resolutionDiff,
958
- bitrateDiff: bitrateDiff
959
- };
1103
+ insecure: insecure
1104
+ });
1105
+ logFunnel("media_candidate", _object_spread_props(_object_spread({}, details), {
1106
+ reason: "accepted",
1107
+ // Mixed-content media is often auto-upgraded, so it is kept as a last resort.
1108
+ why: insecure ? "insecure_http_deprioritized" : "playable",
1109
+ score: score
1110
+ }));
960
1111
  });
961
- scoredFiles.sort(function(a, b) {
1112
+ accepted.sort(function(a, b) {
1113
+ if (a.insecure !== b.insecure) return a.insecure ? 1 : -1;
962
1114
  return a.score - b.score;
963
1115
  });
964
- var bestMatch = scoredFiles[0];
965
- if (!bestMatch) {
966
- console.log("[HlsAdPlayer] No best match found, using first media file");
967
- return firstFile;
968
- }
969
- console.log("[HlsAdPlayer] Selected media file:", {
970
- url: bestMatch.file.url,
971
- resolution: "".concat(bestMatch.file.width, "x").concat(bestMatch.file.height),
972
- bitrate: bestMatch.file.bitrate,
973
- score: bestMatch.score,
974
- resolutionDiff: bestMatch.resolutionDiff,
975
- bitrateDiff: bestMatch.bitrateDiff
1116
+ return accepted.map(function(entry) {
1117
+ return entry.file;
976
1118
  });
977
- return bestMatch.file;
978
1119
  }
979
1120
  function isHlsMediaFile(mediaFile) {
980
1121
  var type = mediaFile.type.toLowerCase();
@@ -991,9 +1132,10 @@ function createHlsAdPlayer(contentVideo, options) {
991
1132
  var url = (mediaFile.url.toLowerCase().split("?")[0] || "").trim();
992
1133
  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");
993
1134
  }
994
- function collectVideoMediaFiles(linear, verbose) {
1135
+ function collectVideoMediaFiles(linear, verbose, stats) {
995
1136
  var mediaFileElements = linear.querySelectorAll(":scope > MediaFiles > MediaFile");
996
1137
  var mediaFiles = [];
1138
+ if (stats) stats.total += mediaFileElements.length;
997
1139
  if (verbose) {
998
1140
  console.log("[HlsAdPlayer] Found ".concat(mediaFileElements.length, " MediaFile element(s) in VAST XML"));
999
1141
  }
@@ -1014,6 +1156,7 @@ function createHlsAdPlayer(contentVideo, options) {
1014
1156
  }
1015
1157
  var apiFramework = (mf.getAttribute("apiFramework") || "").toUpperCase();
1016
1158
  if (apiFramework === "VPAID") {
1159
+ if (stats) stats.vpaid++;
1017
1160
  if (verbose) {
1018
1161
  console.log("[HlsAdPlayer] MediaFile ".concat(index, " ignored (VPAID creatives are not supported)"));
1019
1162
  }
@@ -1029,11 +1172,13 @@ function createHlsAdPlayer(contentVideo, options) {
1029
1172
  bitrate: bitrateValue && bitrateValue > 0 ? bitrateValue : void 0
1030
1173
  };
1031
1174
  if (isAudioMediaFile(mediaFile)) {
1175
+ if (stats) stats.audio++;
1032
1176
  console.warn("[HlsAdPlayer] MediaFile ".concat(index, ' skipped (audio-only, type="').concat(type, '") — audio ads are not played to avoid a black screen'));
1033
1177
  return;
1034
1178
  }
1035
1179
  var hasExplicitDimensions = mf.getAttribute("width") != null && mf.getAttribute("height") != null;
1036
1180
  if (!isHlsMediaFile(mediaFile) && hasExplicitDimensions && (mediaFile.width <= 1 || mediaFile.height <= 1)) {
1181
+ if (stats) stats.audio++;
1037
1182
  console.warn("[HlsAdPlayer] MediaFile ".concat(index, " skipped (degenerate dimensions ").concat(mediaFile.width, "x").concat(mediaFile.height, ', type="').concat(type, '") — likely an audio-only placeholder rendition'));
1038
1183
  return;
1039
1184
  }
@@ -1042,8 +1187,11 @@ function createHlsAdPlayer(contentVideo, options) {
1042
1187
  if (verbose) {
1043
1188
  console.log("[HlsAdPlayer] Added ".concat(isHlsMediaFile(mediaFile) ? "HLS" : "progressive", " MediaFile: ").concat(url));
1044
1189
  }
1045
- } else if (verbose) {
1046
- console.log("[HlsAdPlayer] MediaFile ".concat(index, ' ignored (type="').concat(type, '" is not supported)'));
1190
+ } else {
1191
+ if (stats) stats.unsupported++;
1192
+ if (verbose) {
1193
+ console.log("[HlsAdPlayer] MediaFile ".concat(index, ' ignored (type="').concat(type, '" is not supported)'));
1194
+ }
1047
1195
  }
1048
1196
  });
1049
1197
  return mediaFiles;
@@ -1167,26 +1315,58 @@ function createHlsAdPlayer(contentVideo, options) {
1167
1315
  }
1168
1316
  function parseVastXml(xmlString) {
1169
1317
  try {
1170
- var _adElements_find;
1171
1318
  var xmlDoc = parseXml(xmlString);
1172
1319
  if (!xmlDoc) return {
1173
1320
  type: "empty"
1174
1321
  };
1175
1322
  var root = xmlDoc.documentElement;
1176
1323
  var adElements = Array.from(root.querySelectorAll(":scope > Ad"));
1177
- var adElement = (_adElements_find = adElements.find(function(el) {
1178
- return getAdSequence(el) === void 0;
1179
- })) !== null && _adElements_find !== void 0 ? _adElements_find : adElements[0];
1180
- if (!adElement) {
1324
+ if (adElements.length === 0) {
1181
1325
  var _root_getAttribute;
1182
1326
  console.warn("[HlsAdPlayer] No Ad element found in VAST ".concat((_root_getAttribute = root.getAttribute("version")) !== null && _root_getAttribute !== void 0 ? _root_getAttribute : "", " response"));
1183
1327
  return emptyVastResult(root);
1184
1328
  }
1185
- var parsed = parseAdElement(adElement, true);
1186
- if (parsed.type === "wrapper") {
1187
- console.log("[HlsAdPlayer] VAST wrapper detected, following VASTAdTagURI: ".concat(parsed.vastAdTagUri));
1329
+ var ordered = _to_consumable_array(adElements.filter(function(el) {
1330
+ return getAdSequence(el) === void 0;
1331
+ })).concat(_to_consumable_array(adElements.filter(function(el) {
1332
+ return getAdSequence(el) !== void 0;
1333
+ })));
1334
+ var firstEmpty;
1335
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1336
+ try {
1337
+ for(var _iterator = ordered.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1338
+ var _step_value = _sliced_to_array(_step.value, 2), index = _step_value[0], adElement = _step_value[1];
1339
+ var parsed = parseAdElement(adElement, true);
1340
+ if (parsed.type === "empty") {
1341
+ firstEmpty !== null && firstEmpty !== void 0 ? firstEmpty : firstEmpty = parsed;
1342
+ continue;
1343
+ }
1344
+ if (index > 0) {
1345
+ logFunnel("vast_ad_fallback", {
1346
+ usedAdIndex: index,
1347
+ adCount: ordered.length
1348
+ });
1349
+ }
1350
+ if (parsed.type === "wrapper") {
1351
+ console.log("[HlsAdPlayer] VAST wrapper detected, following VASTAdTagURI: ".concat(parsed.vastAdTagUri));
1352
+ }
1353
+ return parsed;
1354
+ }
1355
+ } catch (err) {
1356
+ _didIteratorError = true;
1357
+ _iteratorError = err;
1358
+ } finally{
1359
+ try {
1360
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1361
+ _iterator.return();
1362
+ }
1363
+ } finally{
1364
+ if (_didIteratorError) {
1365
+ throw _iteratorError;
1366
+ }
1367
+ }
1188
1368
  }
1189
- return parsed;
1369
+ return firstEmpty !== null && firstEmpty !== void 0 ? firstEmpty : emptyVastResult(root);
1190
1370
  } catch (error) {
1191
1371
  console.error("[HlsAdPlayer] Error parsing VAST XML:", error);
1192
1372
  return {
@@ -1232,6 +1412,10 @@ function createHlsAdPlayer(contentVideo, options) {
1232
1412
  pushUrls(errorUrls, inLine.querySelectorAll(":scope > Error"));
1233
1413
  if (adElement.getAttribute("conditionalAd") === "true") {
1234
1414
  console.warn("[HlsAdPlayer] Skipping conditional <Ad> (VPAID-only)");
1415
+ logFunnel("vast_no_supported_media", {
1416
+ reason: "vpaid_only",
1417
+ conditionalAd: true
1418
+ });
1235
1419
  return {
1236
1420
  type: "empty",
1237
1421
  errorUrls: errorUrls,
@@ -1240,11 +1424,17 @@ function createHlsAdPlayer(contentVideo, options) {
1240
1424
  }
1241
1425
  var linear;
1242
1426
  var mediaFiles = [];
1427
+ var rejectStats = {
1428
+ total: 0,
1429
+ vpaid: 0,
1430
+ audio: 0,
1431
+ unsupported: 0
1432
+ };
1243
1433
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1244
1434
  try {
1245
1435
  for(var _iterator = Array.from(inLine.querySelectorAll(":scope > Creatives > Creative > Linear"))[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1246
1436
  var candidate = _step.value;
1247
- var files = collectVideoMediaFiles(candidate, verbose);
1437
+ var files = collectVideoMediaFiles(candidate, verbose, rejectStats);
1248
1438
  if (files.length > 0) {
1249
1439
  linear = candidate;
1250
1440
  mediaFiles = files;
@@ -1267,6 +1457,10 @@ function createHlsAdPlayer(contentVideo, options) {
1267
1457
  }
1268
1458
  if (!linear) {
1269
1459
  console.warn("[HlsAdPlayer] No supported linear media files in <Ad>");
1460
+ var reason = rejectStats.total === 0 ? "no_mediafiles" : rejectStats.vpaid > 0 ? "vpaid_only" : rejectStats.audio > 0 ? "audio_only" : "unsupported_type";
1461
+ logFunnel("vast_no_supported_media", _object_spread({
1462
+ reason: reason
1463
+ }, rejectStats));
1270
1464
  return {
1271
1465
  type: "empty",
1272
1466
  errorUrls: errorUrls,
@@ -1298,77 +1492,122 @@ function createHlsAdPlayer(contentVideo, options) {
1298
1492
  function fetchVastXml(vastTagUrl) {
1299
1493
  var credentials = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "include";
1300
1494
  return _async_to_generator(function() {
1301
- var requestVast, response, error;
1495
+ var controller, timeoutId, requestVast, response, error, error1;
1302
1496
  return _ts_generator(this, function(_state) {
1303
1497
  switch(_state.label){
1304
1498
  case 0:
1499
+ if (destroyed) {
1500
+ throw new Error("VAST request skipped: ad player destroyed");
1501
+ }
1502
+ controller = typeof AbortController !== "undefined" ? new AbortController() : void 0;
1503
+ if (controller) pendingVastRequests.add(controller);
1504
+ timeoutId = controller ? setTimeout(function() {
1505
+ return controller.abort();
1506
+ }, VAST_REQUEST_TIMEOUT_MS) : void 0;
1305
1507
  requestVast = function requestVast(creds) {
1306
- return fetch(vastTagUrl, {
1508
+ return fetch(vastTagUrl, _object_spread({
1307
1509
  mode: "cors",
1308
1510
  credentials: creds,
1309
1511
  headers: {
1310
1512
  "Accept": "application/xml, text/xml, */*"
1311
1513
  },
1312
1514
  referrerPolicy: "no-referrer-when-downgrade"
1313
- });
1515
+ }, controller ? {
1516
+ signal: controller.signal
1517
+ } : {}));
1314
1518
  };
1315
1519
  _state.label = 1;
1316
1520
  case 1:
1317
1521
  _state.trys.push([
1318
1522
  1,
1319
- 3,
1523
+ 10,
1524
+ 11,
1525
+ 12
1526
+ ]);
1527
+ _state.label = 2;
1528
+ case 2:
1529
+ _state.trys.push([
1530
+ 2,
1531
+ 4,
1320
1532
  ,
1321
- 7
1533
+ 8
1322
1534
  ]);
1323
1535
  return [
1324
1536
  4,
1325
1537
  requestVast(credentials)
1326
1538
  ];
1327
- case 2:
1539
+ case 3:
1328
1540
  response = _state.sent();
1329
1541
  return [
1330
1542
  3,
1331
- 7
1543
+ 8
1332
1544
  ];
1333
- case 3:
1545
+ case 4:
1334
1546
  error = _state.sent();
1335
- if (!(credentials !== "omit")) return [
1547
+ if (!(credentials !== "omit" && !(controller === null || controller === void 0 ? void 0 : controller.signal.aborted))) return [
1336
1548
  3,
1337
- 5
1549
+ 6
1338
1550
  ];
1339
1551
  console.warn('[HlsAdPlayer] VAST fetch failed with credentials="'.concat(credentials, '", retrying without credentials:'), error);
1552
+ logFunnel("vast_credentials_retry", {
1553
+ errorMessage: error === null || error === void 0 ? void 0 : error.message
1554
+ });
1340
1555
  return [
1341
1556
  4,
1342
1557
  requestVast("omit")
1343
1558
  ];
1344
- case 4:
1559
+ case 5:
1345
1560
  response = _state.sent();
1346
1561
  return [
1347
1562
  3,
1348
- 6
1563
+ 7
1349
1564
  ];
1350
- case 5:
1351
- throw error;
1352
1565
  case 6:
1566
+ throw error;
1567
+ case 7:
1353
1568
  return [
1354
1569
  3,
1355
- 7
1570
+ 8
1356
1571
  ];
1357
- case 7:
1572
+ case 8:
1358
1573
  if (!response.ok) {
1359
1574
  throw new Error("Failed to fetch VAST: ".concat(response.statusText));
1360
1575
  }
1361
1576
  return [
1362
- 2,
1577
+ 4,
1363
1578
  response.text()
1364
1579
  ];
1580
+ case 9:
1581
+ return [
1582
+ 2,
1583
+ _state.sent()
1584
+ ];
1585
+ case 10:
1586
+ error1 = _state.sent();
1587
+ if (controller === null || controller === void 0 ? void 0 : controller.signal.aborted) {
1588
+ if (pendingRequestAbortReason) {
1589
+ throw new Error("".concat(pendingRequestAbortReason, " (timeout): ").concat(vastTagUrl));
1590
+ }
1591
+ throw new Error("VAST request timeout after ".concat(VAST_REQUEST_TIMEOUT_MS, "ms: ").concat(vastTagUrl));
1592
+ }
1593
+ throw error1;
1594
+ case 11:
1595
+ if (timeoutId !== void 0) clearTimeout(timeoutId);
1596
+ if (controller) pendingVastRequests.delete(controller);
1597
+ return [
1598
+ 7
1599
+ ];
1600
+ case 12:
1601
+ return [
1602
+ 2
1603
+ ];
1365
1604
  }
1366
1605
  });
1367
1606
  })();
1368
1607
  }
1369
1608
  function fetchAndParseVastAd(_0) {
1370
1609
  return _async_to_generator(function(vastTagUrl) {
1371
- var depth, accumulatedTracking, rules, vastXml, error, parsed, _parsed_errorUrls, _parsed_errorCode;
1610
+ var depth, accumulatedTracking, rules, vastXml, fetchStartedAt, error, parsed, _parsed_errorUrls, _parsed_errorCode;
1372
1611
  var _arguments = arguments;
1373
1612
  return _ts_generator(this, function(_state) {
1374
1613
  switch(_state.label){
@@ -1376,6 +1615,11 @@ function createHlsAdPlayer(contentVideo, options) {
1376
1615
  depth = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : 0, accumulatedTracking = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : createEmptyTrackingUrls(), rules = _arguments.length > 3 && _arguments[3] !== void 0 ? _arguments[3] : {
1377
1616
  followAdditionalWrappers: true
1378
1617
  };
1618
+ if (destroyed) return [
1619
+ 2,
1620
+ null
1621
+ ];
1622
+ fetchStartedAt = Date.now();
1379
1623
  _state.label = 1;
1380
1624
  case 1:
1381
1625
  _state.trys.push([
@@ -1398,14 +1642,35 @@ function createHlsAdPlayer(contentVideo, options) {
1398
1642
  error = _state.sent();
1399
1643
  if (depth === 0) throw error;
1400
1644
  console.warn("[HlsAdPlayer] Wrapped VAST request failed:", error);
1401
- fireTrackingPixels(accumulatedTracking.error, {
1402
- errorCode: VAST_ERROR_WRAPPER_TIMEOUT
1645
+ logFunnel("wrapper_fetch", {
1646
+ reason: "failure",
1647
+ depth: depth,
1648
+ wrapperUrl: redactUrl(vastTagUrl),
1649
+ elapsedMs: Date.now() - fetchStartedAt,
1650
+ errorMessage: error === null || error === void 0 ? void 0 : error.message
1403
1651
  });
1652
+ if (!destroyed) {
1653
+ fireTrackingPixels(accumulatedTracking.error, {
1654
+ errorCode: VAST_ERROR_WRAPPER_TIMEOUT
1655
+ });
1656
+ }
1404
1657
  return [
1405
1658
  2,
1406
1659
  null
1407
1660
  ];
1408
1661
  case 4:
1662
+ if (destroyed) return [
1663
+ 2,
1664
+ null
1665
+ ];
1666
+ if (depth > 0) {
1667
+ logFunnel("wrapper_fetch", {
1668
+ reason: "success",
1669
+ depth: depth,
1670
+ wrapperUrl: redactUrl(vastTagUrl),
1671
+ elapsedMs: Date.now() - fetchStartedAt
1672
+ });
1673
+ }
1409
1674
  console.log("[HlsAdPlayer] VAST XML received");
1410
1675
  console.log("[HlsAdPlayer] VAST XML content (first 2000 chars):", vastXml.substring(0, 2e3));
1411
1676
  parsed = parseVastXml(vastXml);
@@ -1437,6 +1702,9 @@ function createHlsAdPlayer(contentVideo, options) {
1437
1702
  ];
1438
1703
  }
1439
1704
  mergeTrackingUrls(parsed.ad.trackingUrls, accumulatedTracking);
1705
+ logFunnel("inline_resolved", {
1706
+ depth: depth
1707
+ });
1440
1708
  return [
1441
1709
  2,
1442
1710
  parsed.ad
@@ -1447,7 +1715,7 @@ function createHlsAdPlayer(contentVideo, options) {
1447
1715
  }
1448
1716
  function fetchAndParsePod(vastTagUrl) {
1449
1717
  return _async_to_generator(function() {
1450
- var _root_getAttribute, vastXml, trimmedXml, xmlDoc, root, adElements, _root_getAttribute1, _empty_errorUrls, empty, _empty_errorCode, resolveAd, podElements, buffet, ads, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, adElement, ad, err, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, adElement1, ad1, err;
1718
+ var _root_getAttribute, vastXml, trimmedXml, xmlDoc, root, adElements, _root_getAttribute1, _empty_errorUrls, empty, _empty_errorCode, resolveAd, podElements, buffet, resolveAll, ads, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, ad, err, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, ad1, err;
1451
1719
  return _ts_generator(this, function(_state) {
1452
1720
  switch(_state.label){
1453
1721
  case 0:
@@ -1457,6 +1725,10 @@ function createHlsAdPlayer(contentVideo, options) {
1457
1725
  ];
1458
1726
  case 1:
1459
1727
  vastXml = _state.sent();
1728
+ if (destroyed) return [
1729
+ 2,
1730
+ []
1731
+ ];
1460
1732
  console.log("[HlsAdPlayer] Pod VAST XML received (length=".concat(vastXml.length, ")"));
1461
1733
  trimmedXml = vastXml.trim();
1462
1734
  if (trimmedXml.length === 0) {
@@ -1528,6 +1800,13 @@ function createHlsAdPlayer(contentVideo, options) {
1528
1800
  buffet = adElements.filter(function(el) {
1529
1801
  return getAdSequence(el) === void 0;
1530
1802
  });
1803
+ resolveAll = function resolveAll(elements) {
1804
+ return Promise.all(elements.map(function(el) {
1805
+ return resolveAd(el).catch(function() {
1806
+ return null;
1807
+ });
1808
+ }));
1809
+ };
1531
1810
  ads = [];
1532
1811
  if (!(podElements.length === 0)) return [
1533
1812
  3,
@@ -1542,27 +1821,26 @@ function createHlsAdPlayer(contentVideo, options) {
1542
1821
  8,
1543
1822
  9
1544
1823
  ]);
1545
- _iterator = buffet[Symbol.iterator]();
1546
- _state.label = 3;
1824
+ return [
1825
+ 4,
1826
+ resolveAll(buffet)
1827
+ ];
1547
1828
  case 3:
1829
+ _iterator = _state.sent()[Symbol.iterator]();
1830
+ _state.label = 4;
1831
+ case 4:
1548
1832
  if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
1549
1833
  3,
1550
1834
  6
1551
1835
  ];
1552
- adElement = _step.value;
1553
- return [
1554
- 4,
1555
- resolveAd(adElement)
1556
- ];
1557
- case 4:
1558
- ad = _state.sent();
1836
+ ad = _step.value;
1559
1837
  if (ad) ads.push(ad);
1560
1838
  _state.label = 5;
1561
1839
  case 5:
1562
1840
  _iteratorNormalCompletion = true;
1563
1841
  return [
1564
1842
  3,
1565
- 3
1843
+ 4
1566
1844
  ];
1567
1845
  case 6:
1568
1846
  return [
@@ -1605,20 +1883,19 @@ function createHlsAdPlayer(contentVideo, options) {
1605
1883
  20,
1606
1884
  21
1607
1885
  ]);
1608
- _iterator1 = podElements[Symbol.iterator]();
1609
- _state.label = 12;
1886
+ return [
1887
+ 4,
1888
+ resolveAll(podElements)
1889
+ ];
1610
1890
  case 12:
1891
+ _iterator1 = _state.sent()[Symbol.iterator]();
1892
+ _state.label = 13;
1893
+ case 13:
1611
1894
  if (!!(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done)) return [
1612
1895
  3,
1613
1896
  18
1614
1897
  ];
1615
- adElement1 = _step1.value;
1616
- return [
1617
- 4,
1618
- resolveAd(adElement1)
1619
- ];
1620
- case 13:
1621
- ad1 = _state.sent();
1898
+ ad1 = _step1.value;
1622
1899
  _state.label = 14;
1623
1900
  case 14:
1624
1901
  if (!(!ad1 && buffet.length > 0)) return [
@@ -1627,7 +1904,9 @@ function createHlsAdPlayer(contentVideo, options) {
1627
1904
  ];
1628
1905
  return [
1629
1906
  4,
1630
- resolveAd(buffet.shift())
1907
+ resolveAd(buffet.shift()).catch(function() {
1908
+ return null;
1909
+ })
1631
1910
  ];
1632
1911
  case 15:
1633
1912
  ad1 = _state.sent();
@@ -1642,7 +1921,7 @@ function createHlsAdPlayer(contentVideo, options) {
1642
1921
  _iteratorNormalCompletion1 = true;
1643
1922
  return [
1644
1923
  3,
1645
- 12
1924
+ 13
1646
1925
  ];
1647
1926
  case 18:
1648
1927
  return [
@@ -1737,14 +2016,17 @@ function createHlsAdPlayer(contentVideo, options) {
1737
2016
  var progress = currentTime / currentAd.duration;
1738
2017
  if (progress >= 0.25 && !trackingFired.firstQuartile) {
1739
2018
  trackingFired.firstQuartile = true;
2019
+ logFunnel("first_quartile");
1740
2020
  fireTrackingPixels(currentAd.trackingUrls.firstQuartile);
1741
2021
  }
1742
2022
  if (progress >= 0.5 && !trackingFired.midpoint) {
1743
2023
  trackingFired.midpoint = true;
2024
+ logFunnel("midpoint");
1744
2025
  fireTrackingPixels(currentAd.trackingUrls.midpoint);
1745
2026
  }
1746
2027
  if (progress >= 0.75 && !trackingFired.thirdQuartile) {
1747
2028
  trackingFired.thirdQuartile = true;
2029
+ logFunnel("third_quartile");
1748
2030
  fireTrackingPixels(currentAd.trackingUrls.thirdQuartile);
1749
2031
  }
1750
2032
  };
@@ -1767,6 +2049,16 @@ function createHlsAdPlayer(contentVideo, options) {
1767
2049
  if (!trackingFired.impression) {
1768
2050
  trackingFired.impression = true;
1769
2051
  resolvedAds.add(currentAd);
2052
+ logFunnel("playing", {
2053
+ mutedByAutoplay: forcedMuteByAutoplay,
2054
+ candidateIndex: mediaCandidateIndex
2055
+ });
2056
+ logFunnel("impression_fired", {
2057
+ pixelCount: currentAd.trackingUrls.impression.length
2058
+ });
2059
+ if (currentAd.trackingUrls.impression.length === 0) {
2060
+ console.warn("[HlsAdPlayer] Ad started but VAST contained no <Impression> URLs - GAM will not count it");
2061
+ }
1770
2062
  fireTrackingPixels(currentAd.trackingUrls.impression);
1771
2063
  fireTrackingPixels(currentAd.trackingUrls.creativeView);
1772
2064
  fireTrackingPixels(currentAd.trackingUrls.verificationNotExecuted, {
@@ -1789,6 +2081,7 @@ function createHlsAdPlayer(contentVideo, options) {
1789
2081
  sampleViewability();
1790
2082
  settleViewability();
1791
2083
  trackingFired.complete = true;
2084
+ logFunnel("complete");
1792
2085
  fireTrackingPixels(currentAd.trackingUrls.complete);
1793
2086
  console.log("[HlsAdPlayer] Ad completed");
1794
2087
  if (podIndex < podAds.length - 1 && advanceToNextPodAd()) {
@@ -1797,16 +2090,41 @@ function createHlsAdPlayer(contentVideo, options) {
1797
2090
  handleAdComplete();
1798
2091
  };
1799
2092
  var onError = function onError(e) {
2093
+ var _adVideoElement_error, _adVideoElement_error1;
1800
2094
  if (!adPlaying) return;
1801
2095
  console.error("[HlsAdPlayer] Ad video error:", e);
1802
- reportCurrentAdError(toVastMediaErrorCode(adVideoElement === null || adVideoElement === void 0 ? void 0 : adVideoElement.error));
1803
- if (podIndex < podAds.length - 1 && advanceToNextPodAd()) {
1804
- return;
1805
- }
1806
- handleAdError();
2096
+ var vastErrorCode = toVastMediaErrorCode(adVideoElement === null || adVideoElement === void 0 ? void 0 : adVideoElement.error);
2097
+ logFunnel("media_error", {
2098
+ mediaErrorCode: adVideoElement === null || adVideoElement === void 0 ? void 0 : (_adVideoElement_error = adVideoElement.error) === null || _adVideoElement_error === void 0 ? void 0 : _adVideoElement_error.code,
2099
+ errorMessage: adVideoElement === null || adVideoElement === void 0 ? void 0 : (_adVideoElement_error1 = adVideoElement.error) === null || _adVideoElement_error1 === void 0 ? void 0 : _adVideoElement_error1.message,
2100
+ networkState: adVideoElement === null || adVideoElement === void 0 ? void 0 : adVideoElement.networkState,
2101
+ readyState: adVideoElement === null || adVideoElement === void 0 ? void 0 : adVideoElement.readyState,
2102
+ currentSrc: adVideoElement === null || adVideoElement === void 0 ? void 0 : adVideoElement.currentSrc,
2103
+ vastErrorCode: vastErrorCode
2104
+ });
2105
+ recoverFromAdFailure(vastErrorCode);
2106
+ };
2107
+ var onMediaDiagnostic = function onMediaDiagnostic(event) {
2108
+ if (!adPlaying || !adVideoElement || trackingFired.impression) return;
2109
+ if (!adVideoElement.currentSrc) return;
2110
+ logFunnel("media_event", {
2111
+ reason: event.type,
2112
+ readyState: adVideoElement.readyState,
2113
+ networkState: adVideoElement.networkState,
2114
+ currentSrc: adVideoElement.currentSrc
2115
+ });
1807
2116
  };
1808
2117
  var onVolumeChange = function onVolumeChange() {
1809
2118
  if (!currentAd || !adVideoElement) return;
2119
+ if (forcedMuteByAutoplay && !adVideoElement.muted) {
2120
+ var userActivation = navigator.userActivation;
2121
+ if (userActivation && !userActivation.isActive) {
2122
+ logFunnel("unexpected_unmute", {
2123
+ paused: adVideoElement.paused
2124
+ });
2125
+ }
2126
+ forcedMuteByAutoplay = false;
2127
+ }
1810
2128
  var muted = adVideoElement.muted || adVideoElement.volume === 0;
1811
2129
  if (!trackingFired.start) {
1812
2130
  trackingFired.lastMuted = muted;
@@ -1866,6 +2184,22 @@ function createHlsAdPlayer(contentVideo, options) {
1866
2184
  {
1867
2185
  type: "play",
1868
2186
  handler: onPlay
2187
+ },
2188
+ {
2189
+ type: "stalled",
2190
+ handler: onMediaDiagnostic
2191
+ },
2192
+ {
2193
+ type: "suspend",
2194
+ handler: onMediaDiagnostic
2195
+ },
2196
+ {
2197
+ type: "abort",
2198
+ handler: onMediaDiagnostic
2199
+ },
2200
+ {
2201
+ type: "emptied",
2202
+ handler: onMediaDiagnostic
1869
2203
  }
1870
2204
  ];
1871
2205
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
@@ -2155,16 +2489,51 @@ function createHlsAdPlayer(contentVideo, options) {
2155
2489
  function settlePendingPlay() {
2156
2490
  pendingPlayPromise = void 0;
2157
2491
  }
2492
+ function toVastPlayErrorCode(error) {
2493
+ return (error === null || error === void 0 ? void 0 : error.name) === "NotSupportedError" ? VAST_ERROR_NO_SUPPORTED_MEDIA : VAST_ERROR_MEDIA_DISPLAY;
2494
+ }
2495
+ function failAdPlayback(context, error) {
2496
+ var vastErrorCode = toVastPlayErrorCode(error);
2497
+ console.error("[HlsAdPlayer] Error starting ".concat(context, ":"), error);
2498
+ logFunnel("play_failed", {
2499
+ errorName: error === null || error === void 0 ? void 0 : error.name,
2500
+ errorMessage: error === null || error === void 0 ? void 0 : error.message,
2501
+ vastErrorCode: vastErrorCode
2502
+ });
2503
+ recoverFromAdFailure(vastErrorCode);
2504
+ }
2158
2505
  function startAdPlayback(context) {
2506
+ var isMutedRetry = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
2159
2507
  if (!adVideoElement) return;
2508
+ var computed = typeof getComputedStyle === "function" && adContainerEl ? getComputedStyle(adContainerEl) : void 0;
2509
+ logFunnel(isMutedRetry ? "muted_retry" : "play_called", {
2510
+ context: context,
2511
+ isConnected: adVideoElement.isConnected,
2512
+ clientWidth: adVideoElement.clientWidth,
2513
+ clientHeight: adVideoElement.clientHeight,
2514
+ containerDisplay: computed === null || computed === void 0 ? void 0 : computed.display,
2515
+ containerVisibility: computed === null || computed === void 0 ? void 0 : computed.visibility
2516
+ });
2160
2517
  var playPromise = adVideoElement.play();
2161
2518
  pendingPlayPromise = playPromise;
2162
2519
  playPromise.catch(function(error) {
2163
2520
  if (pendingPlayPromise !== playPromise) {
2164
2521
  return;
2165
2522
  }
2166
- console.error("[HlsAdPlayer] Error starting ".concat(context, ":"), error);
2167
- handleAdError();
2523
+ logFunnel("play_rejected", {
2524
+ context: context,
2525
+ errorName: error === null || error === void 0 ? void 0 : error.name,
2526
+ errorMessage: error === null || error === void 0 ? void 0 : error.message
2527
+ });
2528
+ if (!isMutedRetry && (error === null || error === void 0 ? void 0 : error.name) === "NotAllowedError" && adVideoElement && !adVideoElement.muted) {
2529
+ console.warn("[HlsAdPlayer] Unmuted ".concat(context, " blocked by autoplay policy - retrying muted"));
2530
+ originalMutedState = true;
2531
+ forcedMuteByAutoplay = true;
2532
+ adVideoElement.muted = true;
2533
+ startAdPlayback(context, true);
2534
+ return;
2535
+ }
2536
+ failAdPlayback(context, error);
2168
2537
  }).finally(function() {
2169
2538
  if (pendingPlayPromise === playPromise) {
2170
2539
  pendingPlayPromise = void 0;
@@ -2203,17 +2572,109 @@ function createHlsAdPlayer(contentVideo, options) {
2203
2572
  adVideoElement.volume = Math.max(0, Math.min(1, originalVolume));
2204
2573
  adVideoElement.muted = originalMutedState;
2205
2574
  }
2575
+ function clearMediaStartTimer() {
2576
+ if (mediaStartTimerId !== void 0) {
2577
+ clearTimeout(mediaStartTimerId);
2578
+ mediaStartTimerId = void 0;
2579
+ }
2580
+ }
2581
+ function startMediaStartTimer() {
2582
+ clearMediaStartTimer();
2583
+ if (!(MEDIA_START_TIMEOUT_MS > 0)) return;
2584
+ var startedAt = Date.now();
2585
+ mediaStartTimerId = setTimeout(function() {
2586
+ mediaStartTimerId = void 0;
2587
+ if (!adPlaying || trackingFired.impression) return;
2588
+ console.warn("[HlsAdPlayer] Ad media did not start playing within ".concat(MEDIA_START_TIMEOUT_MS, "ms"));
2589
+ logFunnel("play_resolved_but_never_started", {
2590
+ timeoutMs: MEDIA_START_TIMEOUT_MS,
2591
+ elapsedMs: Date.now() - startedAt,
2592
+ readyState: adVideoElement === null || adVideoElement === void 0 ? void 0 : adVideoElement.readyState,
2593
+ networkState: adVideoElement === null || adVideoElement === void 0 ? void 0 : adVideoElement.networkState,
2594
+ currentSrc: adVideoElement === null || adVideoElement === void 0 ? void 0 : adVideoElement.currentSrc,
2595
+ paused: adVideoElement === null || adVideoElement === void 0 ? void 0 : adVideoElement.paused,
2596
+ vastErrorCode: VAST_ERROR_MEDIA_TIMEOUT
2597
+ });
2598
+ recoverFromAdFailure(VAST_ERROR_MEDIA_TIMEOUT);
2599
+ }, MEDIA_START_TIMEOUT_MS);
2600
+ }
2601
+ function resetVideoElementForNextSource() {
2602
+ clearStallWatchdog();
2603
+ if (requiresMediaPipelineResetAfterAds()) {
2604
+ recreateAdVideoElement();
2605
+ setupAdEventListeners();
2606
+ } else {
2607
+ prepareVideoElementForNewSource();
2608
+ }
2609
+ }
2610
+ function tryNextMediaCandidate() {
2611
+ if (!currentAd || trackingFired.impression) return false;
2612
+ if (mediaCandidateIndex >= mediaCandidates.length - 1) return false;
2613
+ var failedUrl = currentAdMediaFile === null || currentAdMediaFile === void 0 ? void 0 : currentAdMediaFile.url;
2614
+ mediaCandidateIndex++;
2615
+ var next = mediaCandidates[mediaCandidateIndex];
2616
+ if (!next) return false;
2617
+ logFunnel("media_fallback", {
2618
+ failedUrl: failedUrl,
2619
+ nextUrl: next.url,
2620
+ nextType: next.type,
2621
+ candidateIndex: mediaCandidateIndex,
2622
+ candidateCount: mediaCandidates.length
2623
+ });
2624
+ resetVideoElementForNextSource();
2625
+ try {
2626
+ loadMediaCandidate(next);
2627
+ return true;
2628
+ } catch (error) {
2629
+ console.error("[HlsAdPlayer] Failed to load fallback media file:", error);
2630
+ return tryNextMediaCandidate();
2631
+ }
2632
+ }
2633
+ function recoverFromAdFailure(vastErrorCode) {
2634
+ clearMediaStartTimer();
2635
+ if (tryNextMediaCandidate()) return;
2636
+ reportCurrentAdError(vastErrorCode);
2637
+ if (podIndex < podAds.length - 1 && advanceToNextPodAd()) return;
2638
+ handleAdError();
2639
+ }
2206
2640
  function loadCurrentAdMedia() {
2207
2641
  if (!adVideoElement || !currentAd) {
2208
2642
  throw new Error("No ad video element or ad to load");
2209
2643
  }
2210
- var mediaFile = selectBestMediaFile(currentAd.mediaFiles);
2644
+ mediaCandidates = rankMediaCandidates(currentAd.mediaFiles);
2645
+ mediaCandidateIndex = 0;
2646
+ var mediaFile = mediaCandidates[0];
2211
2647
  if (!mediaFile) {
2212
- throw new Error("No media file available for ad");
2648
+ logFunnel("media_unsupported", {
2649
+ vastErrorCode: VAST_ERROR_NO_SUPPORTED_MEDIA,
2650
+ candidates: currentAd.mediaFiles.length
2651
+ });
2652
+ reportCurrentAdError(VAST_ERROR_NO_SUPPORTED_MEDIA);
2653
+ throw new Error("No media file this browser can play");
2654
+ }
2655
+ try {
2656
+ loadMediaCandidate(mediaFile);
2657
+ } catch (error) {
2658
+ if (tryNextMediaCandidate()) return;
2659
+ reportCurrentAdError(VAST_ERROR_NO_SUPPORTED_MEDIA);
2660
+ throw error;
2661
+ }
2662
+ }
2663
+ function loadMediaCandidate(mediaFile) {
2664
+ if (!adVideoElement || !currentAd) {
2665
+ throw new Error("No ad video element or ad to load");
2213
2666
  }
2214
2667
  currentAdMediaFile = mediaFile;
2215
2668
  var isHlsAd = isHlsMediaFile(mediaFile);
2669
+ logFunnel("media_selected", {
2670
+ width: mediaFile.width,
2671
+ height: mediaFile.height,
2672
+ bitrate: mediaFile.bitrate,
2673
+ candidateIndex: mediaCandidateIndex,
2674
+ candidates: mediaCandidates.length
2675
+ });
2216
2676
  console.log("[HlsAdPlayer] Loading ".concat(isHlsAd ? "HLS" : "progressive", " ad (pod ").concat(podIndex + 1, "/").concat(podAds.length || 1, ") from: ").concat(mediaFile.url));
2677
+ startMediaStartTimer();
2217
2678
  if (isHlsAd && Hls.isSupported()) {
2218
2679
  if (adHls) {
2219
2680
  adHls.destroy();
@@ -2222,6 +2683,9 @@ function createHlsAdPlayer(contentVideo, options) {
2222
2683
  enableWorker: true,
2223
2684
  lowLatencyMode: false
2224
2685
  });
2686
+ logFunnel("media_load", {
2687
+ pipeline: "hls.js"
2688
+ });
2225
2689
  adHls.loadSource(mediaFile.url);
2226
2690
  adHls.attachMedia(adVideoElement);
2227
2691
  adHls.on(Hls.Events.MANIFEST_PARSED, function() {
@@ -2231,10 +2695,24 @@ function createHlsAdPlayer(contentVideo, options) {
2231
2695
  adHls.on(Hls.Events.ERROR, function(_event, data) {
2232
2696
  console.error("[HlsAdPlayer] HLS error:", data);
2233
2697
  if (data.fatal) {
2234
- handleAdError();
2698
+ var _data_response, _data_response1, _data_frag;
2699
+ var vastErrorCode = data.type === Hls.ErrorTypes.NETWORK_ERROR ? 401 : VAST_ERROR_MEDIA_DISPLAY;
2700
+ logFunnel("hls_fatal", {
2701
+ reason: data.details,
2702
+ errorName: data.type,
2703
+ errorMessage: data.details,
2704
+ responseCode: (_data_response = data.response) === null || _data_response === void 0 ? void 0 : _data_response.code,
2705
+ responseText: (_data_response1 = data.response) === null || _data_response1 === void 0 ? void 0 : _data_response1.text,
2706
+ fragUrl: (_data_frag = data.frag) === null || _data_frag === void 0 ? void 0 : _data_frag.url,
2707
+ vastErrorCode: vastErrorCode
2708
+ });
2709
+ recoverFromAdFailure(vastErrorCode);
2235
2710
  }
2236
2711
  });
2237
2712
  } else if (isHlsAd && adVideoElement.canPlayType("application/vnd.apple.mpegurl")) {
2713
+ logFunnel("media_load", {
2714
+ pipeline: "native-hls"
2715
+ });
2238
2716
  adVideoElement.src = mediaFile.url;
2239
2717
  startAdPlayback("native HLS ad playback");
2240
2718
  } else if (!isHlsAd && isProgressiveMediaFile(mediaFile)) {
@@ -2242,45 +2720,47 @@ function createHlsAdPlayer(contentVideo, options) {
2242
2720
  adHls.destroy();
2243
2721
  adHls = void 0;
2244
2722
  }
2723
+ logFunnel("media_load", {
2724
+ pipeline: "progressive"
2725
+ });
2245
2726
  adVideoElement.src = mediaFile.url;
2246
2727
  adVideoElement.load();
2247
2728
  startAdPlayback("progressive ad playback");
2248
2729
  } else {
2730
+ clearMediaStartTimer();
2731
+ logFunnel("media_unsupported", {
2732
+ vastErrorCode: VAST_ERROR_NO_SUPPORTED_MEDIA
2733
+ });
2249
2734
  throw new Error("Unsupported ad media file type: ".concat(mediaFile.type));
2250
2735
  }
2251
2736
  }
2252
2737
  function advanceToNextPodAd() {
2253
- if (podIndex >= podAds.length - 1) {
2254
- return false;
2255
- }
2256
- settleViewability();
2257
- podIndex++;
2258
- currentAd = podAds[podIndex];
2259
- currentAdMediaFile = void 0;
2260
- resetAdTracking();
2261
- if (currentAd) {
2262
- console.log("[HlsAdPlayer] Advancing to next pod ad (".concat(podIndex + 1, "/").concat(podAds.length, "): ").concat(currentAd.title, ", duration: ").concat(currentAd.duration, "s"));
2263
- }
2264
- clearStallWatchdog();
2265
- if (requiresMediaPipelineResetAfterAds()) {
2266
- recreateAdVideoElement();
2267
- setupAdEventListeners();
2268
- } else {
2269
- prepareVideoElementForNewSource();
2270
- }
2271
- try {
2272
- loadCurrentAdMedia();
2273
- emit("pod_ad_started", {
2274
- index: podIndex,
2275
- total: podAds.length
2276
- });
2277
- return true;
2278
- } catch (error) {
2279
- console.error("[HlsAdPlayer] Failed to load next pod ad:", error);
2280
- return false;
2738
+ clearMediaStartTimer();
2739
+ while(podIndex < podAds.length - 1){
2740
+ settleViewability();
2741
+ podIndex++;
2742
+ currentAd = podAds[podIndex];
2743
+ currentAdMediaFile = void 0;
2744
+ resetAdTracking();
2745
+ if (currentAd) {
2746
+ console.log("[HlsAdPlayer] Advancing to next pod ad (".concat(podIndex + 1, "/").concat(podAds.length, "): ").concat(currentAd.title, ", duration: ").concat(currentAd.duration, "s"));
2747
+ }
2748
+ resetVideoElementForNextSource();
2749
+ try {
2750
+ loadCurrentAdMedia();
2751
+ emit("pod_ad_started", {
2752
+ index: podIndex,
2753
+ total: podAds.length
2754
+ });
2755
+ return true;
2756
+ } catch (error) {
2757
+ console.error("[HlsAdPlayer] Failed to load next pod ad:", error);
2758
+ }
2281
2759
  }
2760
+ return false;
2282
2761
  }
2283
2762
  function clearStallWatchdog() {
2763
+ clearMediaStartTimer();
2284
2764
  if (stallWatchdogId != null) {
2285
2765
  clearInterval(stallWatchdogId);
2286
2766
  stallWatchdogId = void 0;
@@ -2296,11 +2776,10 @@ function createHlsAdPlayer(contentVideo, options) {
2296
2776
  function handleAdStall() {
2297
2777
  console.warn("[HlsAdPlayer] Ad playback stalled (no progress) - recovering to avoid a blank frame");
2298
2778
  clearStallWatchdog();
2299
- reportCurrentAdError(VAST_ERROR_MEDIA_DISPLAY);
2300
- if (podIndex < podAds.length - 1 && advanceToNextPodAd()) {
2301
- return;
2302
- }
2303
- handleAdError();
2779
+ logFunnel("stall", {
2780
+ vastErrorCode: VAST_ERROR_MEDIA_DISPLAY
2781
+ });
2782
+ recoverFromAdFailure(VAST_ERROR_MEDIA_DISPLAY);
2304
2783
  }
2305
2784
  function getDecodedVideoFrameCount(video) {
2306
2785
  try {
@@ -2362,11 +2841,10 @@ function createHlsAdPlayer(contentVideo, options) {
2362
2841
  function handleVideoDecodeFailure() {
2363
2842
  console.warn("[HlsAdPlayer] Ad audio is advancing but no video frames decoded (black screen) - skipping this creative");
2364
2843
  clearStallWatchdog();
2365
- reportCurrentAdError(VAST_ERROR_MEDIA_DISPLAY);
2366
- if (podIndex < podAds.length - 1 && advanceToNextPodAd()) {
2367
- return;
2368
- }
2369
- handleAdError();
2844
+ logFunnel("decode_failure", {
2845
+ vastErrorCode: VAST_ERROR_MEDIA_DISPLAY
2846
+ });
2847
+ recoverFromAdFailure(VAST_ERROR_MEDIA_DISPLAY);
2370
2848
  }
2371
2849
  function startStallWatchdog() {
2372
2850
  clearStallWatchdog();
@@ -2490,6 +2968,15 @@ function createHlsAdPlayer(contentVideo, options) {
2490
2968
  Promise.reject(new Error("Ad already playing"))
2491
2969
  ];
2492
2970
  }
2971
+ if (destroyed) {
2972
+ return [
2973
+ 2,
2974
+ Promise.reject(new Error("Ad player destroyed"))
2975
+ ];
2976
+ }
2977
+ currentVastTagUrl = vastTagUrl;
2978
+ pendingRequestAbortReason = void 0;
2979
+ logFunnel("request_sent");
2493
2980
  _state.label = 1;
2494
2981
  case 1:
2495
2982
  _state.trys.push([
@@ -2524,8 +3011,18 @@ function createHlsAdPlayer(contentVideo, options) {
2524
3011
  ads = _state.sent();
2525
3012
  _state.label = 4;
2526
3013
  case 4:
3014
+ if (destroyed) {
3015
+ return [
3016
+ 2,
3017
+ Promise.reject(new Error("Ad player destroyed"))
3018
+ ];
3019
+ }
3020
+ if (!ads.length && pendingRequestAbortReason) {
3021
+ throw new Error(pendingRequestAbortReason);
3022
+ }
2527
3023
  if (!ads.length) {
2528
3024
  console.warn("[HlsAdPlayer] No ads available from VAST response");
3025
+ logFunnel("no_fill");
2529
3026
  emit("ad_error");
2530
3027
  return [
2531
3028
  2,
@@ -2536,6 +3033,23 @@ function createHlsAdPlayer(contentVideo, options) {
2536
3033
  podIndex = 0;
2537
3034
  currentAd = ads[0];
2538
3035
  currentAdMediaFile = void 0;
3036
+ logFunnel("vast_received", {
3037
+ adCount: ads.length,
3038
+ durations: ads.map(function(ad) {
3039
+ return ad.duration;
3040
+ }),
3041
+ impressionUrls: ads.map(function(ad) {
3042
+ return ad.trackingUrls.impression.length;
3043
+ })
3044
+ });
3045
+ ads.forEach(function(ad, index) {
3046
+ if (ad.trackingUrls.impression.length === 0) {
3047
+ logFunnel("vast_missing_impression", {
3048
+ adIndex: index,
3049
+ missingAdId: ad.id
3050
+ });
3051
+ }
3052
+ });
2539
3053
  console.log("[HlsAdPlayer] Pod parsed: ".concat(ads.length, ' ad(s), first="').concat(currentAd === null || currentAd === void 0 ? void 0 : currentAd.title, '", duration=').concat(currentAd === null || currentAd === void 0 ? void 0 : currentAd.duration, "s"));
2540
3054
  return [
2541
3055
  2,
@@ -2544,6 +3058,9 @@ function createHlsAdPlayer(contentVideo, options) {
2544
3058
  case 5:
2545
3059
  error = _state.sent();
2546
3060
  console.error("[HlsAdPlayer] Error requesting ads:", error);
3061
+ logFunnel("request_failed", {
3062
+ errorMessage: error === null || error === void 0 ? void 0 : error.message
3063
+ });
2547
3064
  emit("ad_error");
2548
3065
  return [
2549
3066
  2,
@@ -2599,13 +3116,22 @@ function createHlsAdPlayer(contentVideo, options) {
2599
3116
  adContainerEl.style.pointerEvents = "auto";
2600
3117
  }
2601
3118
  emit("content_pause");
2602
- loadCurrentAdMedia();
3119
+ try {
3120
+ loadCurrentAdMedia();
3121
+ } catch (loadError) {
3122
+ if (!(podIndex < podAds.length - 1 && advanceToNextPodAd())) {
3123
+ throw loadError;
3124
+ }
3125
+ }
2603
3126
  return [
2604
3127
  2,
2605
3128
  Promise.resolve()
2606
3129
  ];
2607
3130
  } catch (error) {
2608
3131
  console.error("[HlsAdPlayer] Error playing ad:", error);
3132
+ logFunnel("play_failed", {
3133
+ errorMessage: error === null || error === void 0 ? void 0 : error.message
3134
+ });
2609
3135
  handleAdError();
2610
3136
  return [
2611
3137
  2,
@@ -2647,6 +3173,9 @@ function createHlsAdPlayer(contentVideo, options) {
2647
3173
  var previousMutedState;
2648
3174
  return _ts_generator(this, function(_state) {
2649
3175
  console.log("[HlsAdPlayer] Stopping ad");
3176
+ if (adPlaying && currentAd && !trackingFired.impression) {
3177
+ logFunnel("stopped_before_start");
3178
+ }
2650
3179
  settleViewability();
2651
3180
  fireNotUsedForUnplayedAds();
2652
3181
  clearStallWatchdog();
@@ -2679,15 +3208,18 @@ function createHlsAdPlayer(contentVideo, options) {
2679
3208
  },
2680
3209
  destroy: function destroy() {
2681
3210
  console.log("[HlsAdPlayer] Destroying");
3211
+ if (adPlaying && currentAd && !trackingFired.impression) {
3212
+ logFunnel("stopped_before_start");
3213
+ }
2682
3214
  settleViewability();
2683
3215
  fireNotUsedForUnplayedAds();
2684
3216
  destroyed = true;
2685
- clearStallWatchdog();
3217
+ pendingRequestAbortReason = "Ad player destroyed";
2686
3218
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2687
3219
  try {
2688
- for(var _iterator = pendingTimeouts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2689
- var timeoutId = _step.value;
2690
- clearTimeout(timeoutId);
3220
+ for(var _iterator = Array.from(pendingVastRequests)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3221
+ var controller = _step.value;
3222
+ controller.abort();
2691
3223
  }
2692
3224
  } catch (err) {
2693
3225
  _didIteratorError = true;
@@ -2703,6 +3235,28 @@ function createHlsAdPlayer(contentVideo, options) {
2703
3235
  }
2704
3236
  }
2705
3237
  }
3238
+ pendingVastRequests.clear();
3239
+ clearStallWatchdog();
3240
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
3241
+ try {
3242
+ for(var _iterator1 = pendingTimeouts[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
3243
+ var timeoutId = _step1.value;
3244
+ clearTimeout(timeoutId);
3245
+ }
3246
+ } catch (err) {
3247
+ _didIteratorError1 = true;
3248
+ _iteratorError1 = err;
3249
+ } finally{
3250
+ try {
3251
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
3252
+ _iterator1.return();
3253
+ }
3254
+ } finally{
3255
+ if (_didIteratorError1) {
3256
+ throw _iteratorError1;
3257
+ }
3258
+ }
3259
+ }
2706
3260
  pendingTimeouts = [];
2707
3261
  adPlaying = false;
2708
3262
  setAdPlayingFlag(false);
@@ -2722,6 +3276,35 @@ function createHlsAdPlayer(contentVideo, options) {
2722
3276
  isAdPlaying: function isAdPlaying() {
2723
3277
  return adPlaying;
2724
3278
  },
3279
+ setFunnelContext: function setFunnelContext(context) {
3280
+ funnelContext = _object_spread({}, context);
3281
+ },
3282
+ abortPendingRequest: function abortPendingRequest() {
3283
+ var reason = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "VAST request aborted (timeout)";
3284
+ if (pendingVastRequests.size === 0) return;
3285
+ pendingRequestAbortReason = reason;
3286
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3287
+ try {
3288
+ for(var _iterator = Array.from(pendingVastRequests)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3289
+ var controller = _step.value;
3290
+ controller.abort();
3291
+ }
3292
+ } catch (err) {
3293
+ _didIteratorError = true;
3294
+ _iteratorError = err;
3295
+ } finally{
3296
+ try {
3297
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
3298
+ _iterator.return();
3299
+ }
3300
+ } finally{
3301
+ if (_didIteratorError) {
3302
+ throw _iteratorError;
3303
+ }
3304
+ }
3305
+ }
3306
+ pendingVastRequests.clear();
3307
+ },
2725
3308
  resize: function resize(width, height) {
2726
3309
  console.log("[HlsAdPlayer] Resizing to ".concat(width, "x").concat(height));
2727
3310
  if (adContainerEl) {
@@ -2757,6 +3340,13 @@ function createHlsAdPlayer(contentVideo, options) {
2757
3340
  if (adVideoElement && adPlaying) {
2758
3341
  var clamped = Math.max(0, Math.min(1, volume));
2759
3342
  adVideoElement.volume = clamped;
3343
+ var userActivation = navigator.userActivation;
3344
+ if (clamped > 0 && forcedMuteByAutoplay && userActivation && !userActivation.isActive) {
3345
+ logFunnel("unmute_blocked_without_gesture", {
3346
+ requestedVolume: clamped
3347
+ });
3348
+ return;
3349
+ }
2760
3350
  adVideoElement.muted = clamped === 0;
2761
3351
  }
2762
3352
  },
@@ -6832,7 +7422,7 @@ var AdTimingService = /*#__PURE__*/ function() {
6832
7422
  {
6833
7423
  key: "adFitsRemainingBudget",
6834
7424
  value: function adFitsRemainingBudget(durationMs) {
6835
- if (durationMs <= 0) {
7425
+ if (durationMs <= 0 || this.expectedAdBreakDurationMs == null) {
6836
7426
  return true;
6837
7427
  }
6838
7428
  return durationMs <= this.getDurationBudgetRemainingMs();
@@ -6891,6 +7481,11 @@ var AdTimingService = /*#__PURE__*/ function() {
6891
7481
  value: function markAdStarted() {
6892
7482
  this.currentAdIndex++;
6893
7483
  this.totalAdsInBreak = this.currentAdIndex;
7484
+ }
7485
+ },
7486
+ {
7487
+ key: "noteAdRequestSent",
7488
+ value: function noteAdRequestSent() {
6894
7489
  this.totalAdRequestsInBreak++;
6895
7490
  this.lastAdRequestTime = Date.now();
6896
7491
  }
@@ -6942,6 +7537,9 @@ var AdTimingService = /*#__PURE__*/ function() {
6942
7537
  if (message.includes("timeout")) {
6943
7538
  return true;
6944
7539
  }
7540
+ if (message.includes("ad player destroyed") || message.includes("aborted")) {
7541
+ return true;
7542
+ }
6945
7543
  if (message.includes("rate limit") || message.includes("too many requests")) {
6946
7544
  return true;
6947
7545
  }
@@ -8078,6 +8676,10 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8078
8676
  this.adDetectSentForCurrentBreak = false;
8079
8677
  this.continuousFetchingActive = false;
8080
8678
  this.continuousFetchLoopRunning = false;
8679
+ this.breakFunnel = {};
8680
+ this.controllerCallInFlight = false;
8681
+ this.playbackStartedForCurrentRequest = false;
8682
+ this.opportunityEpoch = -1;
8081
8683
  this.adRequestQueue = [];
8082
8684
  this.adPodQueue = [];
8083
8685
  this.maxPlaceholderDurationMs = 5e3;
@@ -8130,12 +8732,35 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8130
8732
  adPlayer.on("ad_interaction", function(event) {
8131
8733
  if (event) _this.host.onAdInteraction(event);
8132
8734
  });
8133
- adPlayer.on("all_ads_completed", function() {
8134
- sendAdImpressionTracking(_this.host.config.licenseKey, {
8735
+ adPlayer.on("ad_funnel", function(payload) {
8736
+ if (!(payload === null || payload === void 0 ? void 0 : payload.stage)) return;
8737
+ _this.countFunnelStage(payload.stage);
8738
+ if (payload.reason) {
8739
+ _this.countFunnelStage("".concat(payload.stage, ":").concat(payload.reason));
8740
+ }
8741
+ if (payload.stage === "impression_fired" && payload.pixelCount != null) {
8742
+ _this.countFunnelStage("impression_urls", payload.pixelCount);
8743
+ }
8744
+ if (payload.visibilityState === "hidden") {
8745
+ _this.countFunnelStage("while_hidden");
8746
+ }
8747
+ });
8748
+ adPlayer.on("ad_impression", function() {
8749
+ _this.timing.consecutiveFailures = 0;
8750
+ if (!_this.playbackStartedForCurrentRequest) {
8751
+ _this.playbackStartedForCurrentRequest = true;
8752
+ _this.timing.markAdStarted();
8753
+ }
8754
+ sendAdImpressionTracking(_this.host.config.licenseKey, _object_spread_props(_object_spread({
8135
8755
  source: "hls",
8136
- adIndex: _this.timing.currentAdIndex,
8756
+ adIndex: _this.timing.currentAdIndex
8757
+ }, _this.currentVastUrl ? {
8758
+ adUrl: _this.currentVastUrl
8759
+ } : {}), {
8137
8760
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
8138
- }, _this.analyticsContext).catch(function() {});
8761
+ }), _this.analyticsContext).catch(function() {});
8762
+ });
8763
+ adPlayer.on("all_ads_completed", function() {
8139
8764
  _this.timing.recordPlayedAdDuration(_this.host.getAdPlayer());
8140
8765
  var remaining = _this.timing.getRemainingAdMs();
8141
8766
  _this.timing.consecutiveFailures = 0;
@@ -8169,6 +8794,10 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8169
8794
  }
8170
8795
  }
8171
8796
  console.error("[AD-ERROR]", errorMessage, errorPayload || "");
8797
+ if (_this.controllerCallInFlight) {
8798
+ _this.timing.recordGamNoFill();
8799
+ return;
8800
+ }
8172
8801
  _this.handleAdFailure();
8173
8802
  });
8174
8803
  adPlayer.on("content_pause", function() {
@@ -8193,11 +8822,6 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8193
8822
  }
8194
8823
  });
8195
8824
  adPlayer.on("content_resume", function() {
8196
- sendAdImpressionTracking(_this.host.config.licenseKey, {
8197
- source: "hls",
8198
- adIndex: _this.timing.currentAdIndex,
8199
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
8200
- }, _this.analyticsContext).catch(function() {});
8201
8825
  if (!_this.host.video.muted) {
8202
8826
  _this.host.video.muted = true;
8203
8827
  if (_this.debug) {
@@ -8245,6 +8869,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8245
8869
  }
8246
8870
  var preservedMutedState = adPlayer.getOriginalMutedState();
8247
8871
  var preservedVolumeState = adPlayer.getOriginalVolume();
8872
+ this.playbackStartedForCurrentRequest = false;
8248
8873
  if (adPlayer) {
8249
8874
  try {
8250
8875
  adPlayer.destroy();
@@ -8334,9 +8959,10 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8334
8959
  if (this.timing.expectedAdBreakDurationMs == null && adBreakDurationMs != null) {
8335
8960
  this.timing.expectedAdBreakDurationMs = adBreakDurationMs;
8336
8961
  }
8962
+ this.noteOpportunity("scte35", this.cueManager.activeScte35BreakKey);
8337
8963
  return [
8338
8964
  4,
8339
- this.startOptimizedPod(baseVastUrl, adBreakDurationMs, currentMuted, currentVolume)
8965
+ this.startOptimizedPod(baseVastUrl, adBreakDurationMs)
8340
8966
  ];
8341
8967
  case 1:
8342
8968
  podPlayed = _state.sent();
@@ -8370,7 +8996,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8370
8996
  value: // ───────────────────────────────────────────────────────────────
8371
8997
  // Optimized pod (single multi-ad request)
8372
8998
  // ───────────────────────────────────────────────────────────────
8373
- function startOptimizedPod(baseVastUrl, breakDurationMs, currentMuted, currentVolume) {
8999
+ function startOptimizedPod(baseVastUrl, breakDurationMs) {
8374
9000
  return _async_to_generator(function() {
8375
9001
  var podUrl, adPlayer, requestToken, _ref, _adPlayer_getPodAdCount, podCount, error;
8376
9002
  return _ts_generator(this, function(_state) {
@@ -8393,7 +9019,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8393
9019
  adPlayer = this.host.getAdPlayer();
8394
9020
  requestToken = ++this.timing.adRequestTokenCounter;
8395
9021
  this.timing.activeAdRequestToken = requestToken;
8396
- this.timing.startAdRequestWatchdog(requestToken);
9022
+ this.currentVastUrl = podUrl;
8397
9023
  _state.label = 1;
8398
9024
  case 1:
8399
9025
  _state.trys.push([
@@ -8408,10 +9034,14 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8408
9034
  ];
8409
9035
  case 2:
8410
9036
  _state.sent();
8411
- this.timing.lastAdRequestTime = Date.now();
9037
+ this.timing.startAdRequestWatchdog(requestToken);
9038
+ this.timing.noteAdRequestSent();
9039
+ this.beginFunnelRequest(adPlayer, requestToken);
8412
9040
  return [
8413
9041
  4,
8414
- adPlayer.requestAds(podUrl)
9042
+ this.callController(function() {
9043
+ return adPlayer.requestAds(podUrl);
9044
+ })
8415
9045
  ];
8416
9046
  case 3:
8417
9047
  _state.sent();
@@ -8440,16 +9070,16 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8440
9070
  this.timing.startAdFailsafeTimer(requestToken);
8441
9071
  return [
8442
9072
  4,
8443
- adPlayer.play()
9073
+ this.callController(function() {
9074
+ return adPlayer.play();
9075
+ })
8444
9076
  ];
8445
9077
  case 4:
8446
9078
  _state.sent();
8447
- this.timing.markAdStarted();
8448
9079
  if (this.timing.expectedAdBreakDurationMs != null && this.timing.getAdBreakEndWallClockMs() == null) {
8449
9080
  this.timing.scheduleAdStopAtBreakBoundary();
8450
9081
  }
8451
- adPlayer.setAdVolume(currentMuted ? 0 : currentVolume);
8452
- this.timing.consecutiveFailures = 0;
9082
+ adPlayer.setAdVolume(getAdAudioVolume(adPlayer));
8453
9083
  this.continuousFetchingActive = true;
8454
9084
  this.startContinuousFetching(baseVastUrl);
8455
9085
  return [
@@ -8814,7 +9444,6 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8814
9444
  ];
8815
9445
  case 3:
8816
9446
  _state.sent();
8817
- this.timing.consecutiveFailures = 0;
8818
9447
  return [
8819
9448
  3,
8820
9449
  8
@@ -8827,6 +9456,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8827
9456
  3,
8828
9457
  6
8829
9458
  ];
9459
+ this.timing.consecutiveFailures++;
8830
9460
  return [
8831
9461
  4,
8832
9462
  this.tryNextAvailableAdWithRateLimit()
@@ -8896,13 +9526,159 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8896
9526
  }
8897
9527
  },
8898
9528
  {
8899
- key: "playSingleAd",
8900
- value: // ───────────────────────────────────────────────────────────────
9529
+ // ───────────────────────────────────────────────────────────────
8901
9530
  // Single ad playback
8902
9531
  // ───────────────────────────────────────────────────────────────
8903
- function playSingleAd(vastTagUrl) {
9532
+ key: "withCurrentPodBudget",
9533
+ value: function withCurrentPodBudget(vastTagUrl) {
9534
+ var remaining = Math.min(this.timing.getWallClockRemainingAdMs(), this.timing.getDurationBudgetRemainingMs());
9535
+ if (!(remaining > 0)) return vastTagUrl;
9536
+ try {
9537
+ var url = new URL(vastTagUrl);
9538
+ if (!url.searchParams.has("pmxd")) return vastTagUrl;
9539
+ var maxMs = Math.round(remaining);
9540
+ url.searchParams.set("pmxd", String(maxMs));
9541
+ var minMs = Number(url.searchParams.get("pmnd"));
9542
+ if (Number.isFinite(minMs) && minMs > maxMs) {
9543
+ url.searchParams.set("pmnd", String(maxMs));
9544
+ }
9545
+ return url.toString();
9546
+ } catch (unused) {
9547
+ return vastTagUrl;
9548
+ }
9549
+ }
9550
+ },
9551
+ {
9552
+ key: "countFunnelStage",
9553
+ value: function countFunnelStage(stage) {
9554
+ var amount = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
9555
+ var _this_breakFunnel_stage;
9556
+ this.breakFunnel[stage] = ((_this_breakFunnel_stage = this.breakFunnel[stage]) !== null && _this_breakFunnel_stage !== void 0 ? _this_breakFunnel_stage : 0) + amount;
9557
+ }
9558
+ },
9559
+ {
9560
+ key: "logOrchestratorFunnel",
9561
+ value: function logOrchestratorFunnel(stage) {
9562
+ var extra = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
9563
+ this.countFunnelStage(stage);
9564
+ console.log("[AdBreak][FUNNEL] ".concat(stage), _object_spread({
9565
+ breakId: this.timing.adBreakEpoch,
9566
+ requestId: this.currentRequestId,
9567
+ visibilityState: typeof document !== "undefined" ? document.visibilityState : void 0
9568
+ }, extra));
9569
+ }
9570
+ },
9571
+ {
9572
+ key: "noteOpportunity",
9573
+ value: function noteOpportunity(source, breakKey) {
9574
+ if (breakKey && breakKey === this.opportunityBreakKey && this.opportunityEpoch === this.timing.adBreakEpoch) {
9575
+ this.logOrchestratorFunnel("duplicate_break_start", {
9576
+ source: source,
9577
+ breakKey: breakKey
9578
+ });
9579
+ return;
9580
+ }
9581
+ this.opportunityBreakKey = breakKey;
9582
+ this.opportunityEpoch = this.timing.adBreakEpoch;
9583
+ this.logOrchestratorFunnel("opportunity_created", {
9584
+ source: source,
9585
+ breakKey: breakKey,
9586
+ expectedDurationMs: this.timing.expectedAdBreakDurationMs
9587
+ });
9588
+ }
9589
+ },
9590
+ {
9591
+ key: "beginFunnelRequest",
9592
+ value: function beginFunnelRequest(adPlayer, requestToken) {
9593
+ var _adPlayer_setFunnelContext;
9594
+ if (this.controllerCallInFlight) {
9595
+ this.logOrchestratorFunnel("duplicate_request_detected", {
9596
+ newRequestId: requestToken
9597
+ });
9598
+ }
9599
+ this.currentRequestId = requestToken;
9600
+ this.requestStartedAt = Date.now();
9601
+ (_adPlayer_setFunnelContext = adPlayer.setFunnelContext) === null || _adPlayer_setFunnelContext === void 0 ? void 0 : _adPlayer_setFunnelContext.call(adPlayer, {
9602
+ breakId: this.timing.adBreakEpoch,
9603
+ requestId: requestToken
9604
+ });
9605
+ }
9606
+ },
9607
+ {
9608
+ key: "isAdLoadingWithoutPlayback",
9609
+ value: function isAdLoadingWithoutPlayback() {
9610
+ return this.host.getAdPlayer().isAdPlaying() && !this.playbackStartedForCurrentRequest;
9611
+ }
9612
+ },
9613
+ {
9614
+ key: "noteStopBeforeStart",
9615
+ value: function noteStopBeforeStart(reason) {
9616
+ if (!this.isAdLoadingWithoutPlayback()) return;
9617
+ this.logOrchestratorFunnel("ad_stopped_before_start", {
9618
+ reason: reason,
9619
+ elapsedSinceRequestMs: this.requestStartedAt != null ? Date.now() - this.requestStartedAt : void 0
9620
+ });
9621
+ }
9622
+ },
9623
+ {
9624
+ key: "handleRequestWatchdogTimeout",
9625
+ value: function handleRequestWatchdogTimeout() {
9626
+ var adPlayer = this.host.getAdPlayer();
9627
+ if (this.controllerCallInFlight && adPlayer.abortPendingRequest) {
9628
+ this.logOrchestratorFunnel("request_aborted_timeout", {
9629
+ elapsedSinceRequestMs: this.requestStartedAt != null ? Date.now() - this.requestStartedAt : void 0
9630
+ });
9631
+ adPlayer.abortPendingRequest("VAST request aborted after request watchdog timeout");
9632
+ return;
9633
+ }
9634
+ this.handleAdFailure();
9635
+ }
9636
+ },
9637
+ {
9638
+ key: "callController",
9639
+ value: function callController(call) {
8904
9640
  return _async_to_generator(function() {
8905
- var adPlayer, requestToken, ap, playError, error, errorMessage;
9641
+ return _ts_generator(this, function(_state) {
9642
+ switch(_state.label){
9643
+ case 0:
9644
+ this.controllerCallInFlight = true;
9645
+ _state.label = 1;
9646
+ case 1:
9647
+ _state.trys.push([
9648
+ 1,
9649
+ ,
9650
+ 3,
9651
+ 4
9652
+ ]);
9653
+ return [
9654
+ 4,
9655
+ call()
9656
+ ];
9657
+ case 2:
9658
+ _state.sent();
9659
+ return [
9660
+ 3,
9661
+ 4
9662
+ ];
9663
+ case 3:
9664
+ this.controllerCallInFlight = false;
9665
+ return [
9666
+ 7
9667
+ ];
9668
+ case 4:
9669
+ return [
9670
+ 2
9671
+ ];
9672
+ }
9673
+ });
9674
+ }).call(this);
9675
+ }
9676
+ },
9677
+ {
9678
+ key: "playSingleAd",
9679
+ value: function playSingleAd(vastTagUrl) {
9680
+ return _async_to_generator(function() {
9681
+ var adPlayer, requestToken, ap, requestUrl, _ap_getLoadedAdDuration, adDurationS, remainingMs, playError, error, errorMessage;
8906
9682
  return _ts_generator(this, function(_state) {
8907
9683
  switch(_state.label){
8908
9684
  case 0:
@@ -8929,7 +9705,6 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8929
9705
  this.recreateAdController();
8930
9706
  requestToken = ++this.timing.adRequestTokenCounter;
8931
9707
  this.timing.activeAdRequestToken = requestToken;
8932
- this.timing.startAdRequestWatchdog(requestToken);
8933
9708
  _state.label = 1;
8934
9709
  case 1:
8935
9710
  _state.trys.push([
@@ -8944,17 +9719,23 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8944
9719
  ];
8945
9720
  case 2:
8946
9721
  _state.sent();
8947
- this.timing.lastAdRequestTime = Date.now();
9722
+ this.timing.startAdRequestWatchdog(requestToken);
9723
+ this.timing.noteAdRequestSent();
8948
9724
  ap = this.host.getAdPlayer();
9725
+ requestUrl = this.withCurrentPodBudget(vastTagUrl);
9726
+ this.currentVastUrl = requestUrl;
9727
+ this.beginFunnelRequest(ap, requestToken);
8949
9728
  return [
8950
9729
  4,
8951
- ap.requestAds(vastTagUrl)
9730
+ this.callController(function() {
9731
+ return ap.requestAds(requestUrl);
9732
+ })
8952
9733
  ];
8953
9734
  case 3:
8954
9735
  _state.sent();
8955
9736
  sendAdLoadedTracking(this.host.config.licenseKey, {
8956
9737
  source: "hls",
8957
- vastUrl: vastTagUrl,
9738
+ vastUrl: requestUrl,
8958
9739
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
8959
9740
  }, this.analyticsContext).catch(function() {});
8960
9741
  this.timing.clearAdRequestWatchdog();
@@ -8962,6 +9743,14 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8962
9743
  2
8963
9744
  ];
8964
9745
  if (!this.timing.ensureLoadedAdFitsBudget(ap)) {
9746
+ ;
9747
+ adDurationS = (_ap_getLoadedAdDuration = ap.getLoadedAdDuration) === null || _ap_getLoadedAdDuration === void 0 ? void 0 : _ap_getLoadedAdDuration.call(ap);
9748
+ remainingMs = Math.min(this.timing.getWallClockRemainingAdMs(), this.timing.getDurationBudgetRemainingMs());
9749
+ this.logOrchestratorFunnel("discarded_budget", {
9750
+ vastUrl: requestUrl,
9751
+ adDurationMs: adDurationS != null ? adDurationS * 1e3 : void 0,
9752
+ remainingMs: remainingMs
9753
+ });
8965
9754
  this.timing.rejectLoadedAdForDuration(ap);
8966
9755
  this.recreateAdController();
8967
9756
  throw new Error("ad_duration_exceeds_budget");
@@ -8977,16 +9766,16 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8977
9766
  this.timing.startAdFailsafeTimer(requestToken);
8978
9767
  return [
8979
9768
  4,
8980
- ap.play()
9769
+ this.callController(function() {
9770
+ return ap.play();
9771
+ })
8981
9772
  ];
8982
9773
  case 5:
8983
9774
  _state.sent();
8984
- this.timing.markAdStarted();
8985
9775
  if (this.timing.expectedAdBreakDurationMs != null && this.timing.getAdBreakEndWallClockMs() == null) {
8986
9776
  this.timing.scheduleAdStopAtBreakBoundary();
8987
9777
  }
8988
9778
  ap.setAdVolume(getAdAudioVolume(ap));
8989
- this.timing.consecutiveFailures = 0;
8990
9779
  this.timing.temporaryFailureUrls.delete(vastTagUrl);
8991
9780
  return [
8992
9781
  3,
@@ -9150,7 +9939,6 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9150
9939
  ];
9151
9940
  case 5:
9152
9941
  _state.sent();
9153
- this.timing.consecutiveFailures = 0;
9154
9942
  return [
9155
9943
  3,
9156
9944
  10
@@ -9162,6 +9950,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9162
9950
  3,
9163
9951
  8
9164
9952
  ];
9953
+ this.timing.consecutiveFailures++;
9165
9954
  return [
9166
9955
  4,
9167
9956
  this.tryNextAvailableAdWithRateLimit()
@@ -9212,6 +10001,67 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9212
10001
  // ───────────────────────────────────────────────────────────────
9213
10002
  // Ad break completion
9214
10003
  // ───────────────────────────────────────────────────────────────
10004
+ key: "logBreakFunnel",
10005
+ value: function logBreakFunnel() {
10006
+ var funnel = this.breakFunnel;
10007
+ this.breakFunnel = {};
10008
+ if (Object.keys(funnel).length === 0) return;
10009
+ var count = function count(stage) {
10010
+ var _funnel_stage;
10011
+ return (_funnel_stage = funnel[stage]) !== null && _funnel_stage !== void 0 ? _funnel_stage : 0;
10012
+ };
10013
+ var breakId = this.opportunityEpoch;
10014
+ if (count("request_sent") > 0 && count("impression_fired") === 0) {
10015
+ console.log("[AdBreak][FUNNEL] break_abandoned_before_start", {
10016
+ breakId: breakId,
10017
+ requests: count("request_sent")
10018
+ });
10019
+ }
10020
+ console.log("[AdBreak][FUNNEL] Break summary", {
10021
+ breakId: breakId,
10022
+ opportunities: count("opportunity_created"),
10023
+ requests: count("request_sent"),
10024
+ duplicates: count("duplicate_request_detected") + count("duplicate_break_start"),
10025
+ filled: count("vast_received"),
10026
+ noFill: count("no_fill"),
10027
+ requestFailed: count("request_failed"),
10028
+ requestAbortedTimeout: count("request_aborted_timeout"),
10029
+ credentialsRetries: count("vast_credentials_retry"),
10030
+ wrapperFailures: count("wrapper_fetch:failure"),
10031
+ noSupportedMedia: count("vast_no_supported_media"),
10032
+ vpaidOnly: count("vast_no_supported_media:vpaid_only"),
10033
+ missingImpression: count("vast_missing_impression"),
10034
+ discardedBudget: count("discarded_budget"),
10035
+ mediaCandidates: count("media_candidate:accepted") + count("media_candidate:rejected"),
10036
+ mediaRejected: count("media_candidate:rejected"),
10037
+ mediaFallbacks: count("media_fallback"),
10038
+ playCalled: count("play_called"),
10039
+ playRejected: count("play_rejected"),
10040
+ mutedRetry: count("muted_retry"),
10041
+ startTimeouts: count("play_resolved_but_never_started"),
10042
+ impressions: count("impression_fired"),
10043
+ impressionUrls: count("impression_urls"),
10044
+ trackingRequests: count("tracking_request_created"),
10045
+ trackingNotLoaded: count("tracking_request_settled:error") + count("tracking_request_settled:timeout"),
10046
+ trackingUnexpandedMacros: count("tracking_url_unexpanded_macro"),
10047
+ trackingInvalidUrls: count("tracking_url_invalid"),
10048
+ vastAdFallbacks: count("vast_ad_fallback"),
10049
+ mediaEvents: count("media_event"),
10050
+ quartile25: count("first_quartile"),
10051
+ quartile50: count("midpoint"),
10052
+ quartile75: count("third_quartile"),
10053
+ complete: count("complete"),
10054
+ stoppedBeforeStart: count("stopped_before_start"),
10055
+ stoppedBeforeStartByBreakEnd: count("ad_stopped_before_start"),
10056
+ unexpectedUnmutes: count("unexpected_unmute"),
10057
+ unmuteBlocked: count("unmute_blocked_without_gesture"),
10058
+ visibilityHidden: count("while_hidden"),
10059
+ playbackFailures: count("play_failed") + count("media_error") + count("hls_fatal") + count("stall") + count("decode_failure") + count("media_unsupported"),
10060
+ stages: funnel
10061
+ });
10062
+ }
10063
+ },
10064
+ {
9215
10065
  key: "handleAdPodComplete",
9216
10066
  value: function handleAdPodComplete() {
9217
10067
  if (this.debug) {
@@ -9232,6 +10082,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9232
10082
  this.adPodQueue = [];
9233
10083
  this.showAds = false;
9234
10084
  this.host.getAdPlayer().stop().catch(function() {});
10085
+ this.logBreakFunnel();
9235
10086
  var restoredMuted = this.host.getAdPlayer().getOriginalMutedState();
9236
10087
  var restoredVolume = this.host.getAdPlayer().getOriginalVolume();
9237
10088
  if (this.host.video.muted !== restoredMuted) {
@@ -9584,7 +10435,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
9584
10435
  _this.startScte35AdBreak(marker, cueKey, marker.durationSeconds != null ? marker.durationSeconds * 1e3 : _this.timing.expectedAdBreakDurationMs);
9585
10436
  },
9586
10437
  onWatchdogTimeout: function onWatchdogTimeout() {
9587
- return _this.adBreak.handleAdFailure();
10438
+ return _this.adBreak.handleRequestWatchdogTimeout();
9588
10439
  },
9589
10440
  onFailsafeTimeout: function onFailsafeTimeout() {
9590
10441
  return _this.adBreak.handleAdFailure();
@@ -9689,6 +10540,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
9689
10540
  licenseKey: this.config.licenseKey
9690
10541
  } : {}, ((_this_hlsEngine = this.hlsEngine) === null || _this_hlsEngine === void 0 ? void 0 : _this_hlsEngine.hls) ? {
9691
10542
  mainHlsInstance: this.hlsEngine.hls
10543
+ } : {}, this.config.adMediaStartTimeoutMs != null ? {
10544
+ mediaStartTimeoutMs: this.config.adMediaStartTimeoutMs
9692
10545
  } : {}));
9693
10546
  }
9694
10547
  },
@@ -10043,6 +10896,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10043
10896
  this.timing.clearAdStartTimer();
10044
10897
  this.timing.clearAdStopTimer();
10045
10898
  if (adPlaying) {
10899
+ this.adBreak.noteStopBeforeStart("scte_end");
10046
10900
  this.adPlayer.stop().catch(function() {});
10047
10901
  }
10048
10902
  this.adBreak.handleAdPodComplete();
@@ -10082,6 +10936,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10082
10936
  console.log("[StormcloudVideoPlayer] Ad break boundary reached (overrun=".concat(overrunMs, "ms) - hard-stopping ads and resuming stream"));
10083
10937
  }
10084
10938
  if (adPlaying) {
10939
+ this.adBreak.noteStopBeforeStart("break_boundary");
10085
10940
  this.adPlayer.stop().catch(function() {});
10086
10941
  }
10087
10942
  this.adBreak.handleAdPodComplete();
@@ -10210,6 +11065,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10210
11065
  this.adBreak.showAds = true;
10211
11066
  this.adBreak.inAdBreak = true;
10212
11067
  this.timing.currentAdBreakStartWallClockMs = Date.now();
11068
+ if (durationMs > 0) {
11069
+ this.timing.setAdBreakDurationBoundary(durationMs);
11070
+ }
11071
+ this.adBreak.noteOpportunity("vmap", key);
10213
11072
  _state.label = 1;
10214
11073
  case 1:
10215
11074
  _state.trys.push([