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.
@@ -700,6 +700,7 @@ function parseProgressOffset(offset) {
700
700
  } : void 0;
701
701
  }
702
702
  var MAX_VAST_WRAPPER_DEPTH = 5;
703
+ var VAST_REQUEST_TIMEOUT_MS = 5e3;
703
704
  var BEACON_TIMEOUT_MS = 3e4;
704
705
  var inFlightBeacons = /* @__PURE__ */ new Set();
705
706
  var VAST_ERROR_MEDIA_DISPLAY = 405;
@@ -723,7 +724,7 @@ function toVastMediaErrorCode(error) {
723
724
  }
724
725
  }
725
726
  function createHlsAdPlayer(contentVideo, options) {
726
- var _contentVideo_AD_VIDEO_PROP, _contentVideo_AD_CONTAINER_PROP;
727
+ var _contentVideo_AD_VIDEO_PROP, _contentVideo_AD_CONTAINER_PROP, _ref;
727
728
  var adPlaying = false;
728
729
  var originalMutedState = false;
729
730
  var originalVolume = Math.max(0, Math.min(1, contentVideo.volume || 1));
@@ -755,6 +756,16 @@ function createHlsAdPlayer(contentVideo, options) {
755
756
  var sawDecodedVideoFrame = false;
756
757
  var videoFrameCallbackHandle;
757
758
  var pendingPlayPromise;
759
+ var currentVastTagUrl;
760
+ var funnelContext = {};
761
+ var mediaCandidates = [];
762
+ var mediaCandidateIndex = 0;
763
+ var mediaStartTimerId;
764
+ var MEDIA_START_TIMEOUT_MS = (_ref = options === null || options === void 0 ? void 0 : options.mediaStartTimeoutMs) !== null && _ref !== void 0 ? _ref : 8e3;
765
+ var VAST_ERROR_MEDIA_TIMEOUT = 402;
766
+ var pendingVastRequests = /* @__PURE__ */ new Set();
767
+ var pendingRequestAbortReason;
768
+ var forcedMuteByAutoplay = false;
758
769
  function createTrackingState() {
759
770
  return {
760
771
  impression: false,
@@ -805,6 +816,77 @@ function createHlsAdPlayer(contentVideo, options) {
805
816
  }
806
817
  }
807
818
  }
819
+ var SENSITIVE_URL_PARAMS = /* @__PURE__ */ new Set([
820
+ "ppid",
821
+ "rdid",
822
+ "idtype",
823
+ "is_lat",
824
+ "ifa",
825
+ "idfa",
826
+ "aaid",
827
+ "uid",
828
+ "user_id",
829
+ "userid",
830
+ "device_id",
831
+ "deviceid",
832
+ "ip",
833
+ "ua",
834
+ "gdpr_consent",
835
+ "us_privacy",
836
+ "gpp",
837
+ "addtl_consent",
838
+ "cust_params",
839
+ "email"
840
+ ]);
841
+ function redactUrl(url) {
842
+ if (!url) return url;
843
+ try {
844
+ var parsed = new URL(url);
845
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
846
+ try {
847
+ for(var _iterator = Array.from(parsed.searchParams.keys())[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
848
+ var key = _step.value;
849
+ if (SENSITIVE_URL_PARAMS.has(key.toLowerCase())) {
850
+ parsed.searchParams.set(key, "REDACTED");
851
+ }
852
+ }
853
+ } catch (err) {
854
+ _didIteratorError = true;
855
+ _iteratorError = err;
856
+ } finally{
857
+ try {
858
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
859
+ _iterator.return();
860
+ }
861
+ } finally{
862
+ if (_didIteratorError) {
863
+ throw _iteratorError;
864
+ }
865
+ }
866
+ }
867
+ return parsed.toString();
868
+ } catch (unused) {
869
+ return url.split("?")[0];
870
+ }
871
+ }
872
+ function logFunnel(stage) {
873
+ var extra = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
874
+ var payload = _object_spread({
875
+ stage: stage,
876
+ breakId: funnelContext.breakId,
877
+ requestId: funnelContext.requestId,
878
+ visibilityState: typeof document !== "undefined" ? document.visibilityState : void 0,
879
+ adId: currentAd === null || currentAd === void 0 ? void 0 : currentAd.id,
880
+ podIndex: podIndex,
881
+ podSize: podAds.length,
882
+ vastUrl: redactUrl(currentVastTagUrl),
883
+ mediaUrl: currentAdMediaFile === null || currentAdMediaFile === void 0 ? void 0 : currentAdMediaFile.url,
884
+ mediaType: currentAdMediaFile === null || currentAdMediaFile === void 0 ? void 0 : currentAdMediaFile.type,
885
+ muted: adVideoElement ? adVideoElement.muted : void 0
886
+ }, extra);
887
+ console.log("[HlsAdPlayer][FUNNEL] ".concat(stage), payload);
888
+ emit("ad_funnel", payload);
889
+ }
808
890
  function buildTrackingMacroContext() {
809
891
  var options2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
810
892
  var _options2_ad;
@@ -844,20 +926,53 @@ function createHlsAdPlayer(contentVideo, options) {
844
926
  urls.forEach(function(url) {
845
927
  try {
846
928
  var trackingUrl = substituteVastTrackingMacros(url, macroContext);
929
+ var trackingHost;
930
+ try {
931
+ trackingHost = new URL(trackingUrl).host;
932
+ } catch (unused) {
933
+ logFunnel("tracking_url_invalid", {
934
+ trackingUrl: redactUrl(trackingUrl)
935
+ });
936
+ return;
937
+ }
938
+ var unexpanded = trackingUrl.match(/\[[A-Z_]+\]/g);
939
+ if (unexpanded) {
940
+ logFunnel("tracking_url_unexpanded_macro", {
941
+ trackingHost: trackingHost,
942
+ macros: Array.from(new Set(unexpanded))
943
+ });
944
+ }
847
945
  var img = new Image(1, 1);
848
946
  inFlightBeacons.add(img);
849
947
  var timeoutId;
850
- var release = function release() {
948
+ var release = function release(outcome) {
851
949
  if (timeoutId !== void 0) clearTimeout(timeoutId);
852
950
  img.onload = null;
853
951
  img.onerror = null;
854
952
  inFlightBeacons.delete(img);
953
+ console.log("[HlsAdPlayer] Tracking pixel settled (".concat(outcome, "): ").concat(trackingUrl));
954
+ if (outcome !== "load") {
955
+ logFunnel("tracking_request_settled", {
956
+ reason: outcome,
957
+ trackingHost: trackingHost
958
+ });
959
+ }
960
+ };
961
+ img.onload = function() {
962
+ return release("load");
963
+ };
964
+ img.onerror = function() {
965
+ return release("error");
855
966
  };
856
- img.onload = release;
857
- img.onerror = release;
858
- timeoutId = setTimeout(release, BEACON_TIMEOUT_MS);
967
+ timeoutId = setTimeout(function() {
968
+ return release("timeout");
969
+ }, BEACON_TIMEOUT_MS);
859
970
  img.src = trackingUrl;
860
971
  console.log("[HlsAdPlayer] Fired tracking pixel: ".concat(trackingUrl));
972
+ logFunnel("tracking_request_created", {
973
+ trackingHost: trackingHost,
974
+ errorCode: options2 === null || options2 === void 0 ? void 0 : options2.errorCode
975
+ });
861
976
  } catch (error) {
862
977
  console.warn("[HlsAdPlayer] Error firing tracking pixel:", error);
863
978
  }
@@ -887,54 +1002,80 @@ function createHlsAdPlayer(contentVideo, options) {
887
1002
  bitrate: level.bitrate || 5e6
888
1003
  };
889
1004
  }
890
- function selectBestMediaFile(mediaFiles) {
891
- if (mediaFiles.length === 0) {
892
- throw new Error("No media files available");
893
- }
894
- var firstFile = mediaFiles[0];
895
- if (!firstFile) {
896
- throw new Error("No media files available");
897
- }
898
- if (mediaFiles.length === 1) {
899
- return firstFile;
900
- }
1005
+ function getMediaTargetQuality() {
901
1006
  var mainQuality = getMainStreamQuality();
902
- if (!mainQuality) {
903
- console.log("[HlsAdPlayer] No main stream quality info, using first media file");
904
- return firstFile;
905
- }
906
- console.log("[HlsAdPlayer] Main stream quality:", mainQuality);
907
- var scoredFiles = mediaFiles.map(function(file) {
908
- var widthDiff = Math.abs(file.width - mainQuality.width);
909
- var heightDiff = Math.abs(file.height - mainQuality.height);
910
- var resolutionDiff = widthDiff + heightDiff;
911
- var fileBitrate = (file.bitrate || 5e3) * 1e3;
912
- var bitrateDiff = Math.abs(fileBitrate - mainQuality.bitrate);
913
- var score = resolutionDiff * 2 + bitrateDiff / 1e3;
914
- return {
1007
+ var dpr = typeof window !== "undefined" && window.devicePixelRatio > 0 ? window.devicePixelRatio : 1;
1008
+ var containerWidth = ((adContainerEl === null || adContainerEl === void 0 ? void 0 : adContainerEl.clientWidth) || contentVideo.clientWidth) * dpr;
1009
+ var containerHeight = ((adContainerEl === null || adContainerEl === void 0 ? void 0 : adContainerEl.clientHeight) || contentVideo.clientHeight) * dpr;
1010
+ if (!mainQuality && !(containerWidth > 0 && containerHeight > 0)) {
1011
+ return null;
1012
+ }
1013
+ var base = mainQuality !== null && mainQuality !== void 0 ? mainQuality : {
1014
+ width: containerWidth,
1015
+ height: containerHeight,
1016
+ bitrate: 5e6
1017
+ };
1018
+ var width = containerWidth > 0 ? Math.min(base.width, containerWidth) : base.width;
1019
+ var height = containerHeight > 0 ? Math.min(base.height, containerHeight) : base.height;
1020
+ return {
1021
+ width: width,
1022
+ height: height,
1023
+ bitrate: base.bitrate
1024
+ };
1025
+ }
1026
+ function rankMediaCandidates(mediaFiles) {
1027
+ var probe = adVideoElement !== null && adVideoElement !== void 0 ? adVideoElement : document.createElement("video");
1028
+ var pageIsHttps = typeof location !== "undefined" && location.protocol === "https:";
1029
+ var target = getMediaTargetQuality();
1030
+ var accepted = [];
1031
+ mediaFiles.forEach(function(file, index) {
1032
+ var isHls = isHlsMediaFile(file);
1033
+ var mimeForProbe = isHls ? "application/vnd.apple.mpegurl" : file.type || "video/mp4";
1034
+ var canPlay = probe.canPlayType(mimeForProbe);
1035
+ var playable = isHls ? import_hls.default.isSupported() || canPlay !== "" : canPlay !== "";
1036
+ var insecure = pageIsHttps && /^http:/i.test(file.url);
1037
+ var details = {
1038
+ index: index,
1039
+ candidateUrl: file.url,
1040
+ candidateType: file.type,
1041
+ width: file.width,
1042
+ height: file.height,
1043
+ bitrate: file.bitrate,
1044
+ canPlayType: canPlay,
1045
+ hlsJs: isHls ? import_hls.default.isSupported() : void 0
1046
+ };
1047
+ if (!playable) {
1048
+ logFunnel("media_candidate", _object_spread_props(_object_spread({}, details), {
1049
+ reason: "rejected",
1050
+ why: "cannot_play_type"
1051
+ }));
1052
+ return;
1053
+ }
1054
+ var score = 0;
1055
+ if (target) {
1056
+ var resolutionDiff = Math.abs(file.width - target.width) + Math.abs(file.height - target.height);
1057
+ var bitrateDiff = Math.abs((file.bitrate || 5e3) * 1e3 - target.bitrate);
1058
+ score = resolutionDiff * 2 + bitrateDiff / 1e3;
1059
+ }
1060
+ accepted.push({
915
1061
  file: file,
916
1062
  score: score,
917
- resolutionDiff: resolutionDiff,
918
- bitrateDiff: bitrateDiff
919
- };
1063
+ insecure: insecure
1064
+ });
1065
+ logFunnel("media_candidate", _object_spread_props(_object_spread({}, details), {
1066
+ reason: "accepted",
1067
+ // Mixed-content media is often auto-upgraded, so it is kept as a last resort.
1068
+ why: insecure ? "insecure_http_deprioritized" : "playable",
1069
+ score: score
1070
+ }));
920
1071
  });
921
- scoredFiles.sort(function(a, b) {
1072
+ accepted.sort(function(a, b) {
1073
+ if (a.insecure !== b.insecure) return a.insecure ? 1 : -1;
922
1074
  return a.score - b.score;
923
1075
  });
924
- var bestMatch = scoredFiles[0];
925
- if (!bestMatch) {
926
- console.log("[HlsAdPlayer] No best match found, using first media file");
927
- return firstFile;
928
- }
929
- console.log("[HlsAdPlayer] Selected media file:", {
930
- url: bestMatch.file.url,
931
- resolution: "".concat(bestMatch.file.width, "x").concat(bestMatch.file.height),
932
- bitrate: bestMatch.file.bitrate,
933
- score: bestMatch.score,
934
- resolutionDiff: bestMatch.resolutionDiff,
935
- bitrateDiff: bestMatch.bitrateDiff
1076
+ return accepted.map(function(entry) {
1077
+ return entry.file;
936
1078
  });
937
- return bestMatch.file;
938
1079
  }
939
1080
  function isHlsMediaFile(mediaFile) {
940
1081
  var type = mediaFile.type.toLowerCase();
@@ -951,9 +1092,10 @@ function createHlsAdPlayer(contentVideo, options) {
951
1092
  var url = (mediaFile.url.toLowerCase().split("?")[0] || "").trim();
952
1093
  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");
953
1094
  }
954
- function collectVideoMediaFiles(linear, verbose) {
1095
+ function collectVideoMediaFiles(linear, verbose, stats) {
955
1096
  var mediaFileElements = linear.querySelectorAll(":scope > MediaFiles > MediaFile");
956
1097
  var mediaFiles = [];
1098
+ if (stats) stats.total += mediaFileElements.length;
957
1099
  if (verbose) {
958
1100
  console.log("[HlsAdPlayer] Found ".concat(mediaFileElements.length, " MediaFile element(s) in VAST XML"));
959
1101
  }
@@ -974,6 +1116,7 @@ function createHlsAdPlayer(contentVideo, options) {
974
1116
  }
975
1117
  var apiFramework = (mf.getAttribute("apiFramework") || "").toUpperCase();
976
1118
  if (apiFramework === "VPAID") {
1119
+ if (stats) stats.vpaid++;
977
1120
  if (verbose) {
978
1121
  console.log("[HlsAdPlayer] MediaFile ".concat(index, " ignored (VPAID creatives are not supported)"));
979
1122
  }
@@ -989,11 +1132,13 @@ function createHlsAdPlayer(contentVideo, options) {
989
1132
  bitrate: bitrateValue && bitrateValue > 0 ? bitrateValue : void 0
990
1133
  };
991
1134
  if (isAudioMediaFile(mediaFile)) {
1135
+ if (stats) stats.audio++;
992
1136
  console.warn("[HlsAdPlayer] MediaFile ".concat(index, ' skipped (audio-only, type="').concat(type, '") — audio ads are not played to avoid a black screen'));
993
1137
  return;
994
1138
  }
995
1139
  var hasExplicitDimensions = mf.getAttribute("width") != null && mf.getAttribute("height") != null;
996
1140
  if (!isHlsMediaFile(mediaFile) && hasExplicitDimensions && (mediaFile.width <= 1 || mediaFile.height <= 1)) {
1141
+ if (stats) stats.audio++;
997
1142
  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'));
998
1143
  return;
999
1144
  }
@@ -1002,8 +1147,11 @@ function createHlsAdPlayer(contentVideo, options) {
1002
1147
  if (verbose) {
1003
1148
  console.log("[HlsAdPlayer] Added ".concat(isHlsMediaFile(mediaFile) ? "HLS" : "progressive", " MediaFile: ").concat(url));
1004
1149
  }
1005
- } else if (verbose) {
1006
- console.log("[HlsAdPlayer] MediaFile ".concat(index, ' ignored (type="').concat(type, '" is not supported)'));
1150
+ } else {
1151
+ if (stats) stats.unsupported++;
1152
+ if (verbose) {
1153
+ console.log("[HlsAdPlayer] MediaFile ".concat(index, ' ignored (type="').concat(type, '" is not supported)'));
1154
+ }
1007
1155
  }
1008
1156
  });
1009
1157
  return mediaFiles;
@@ -1127,26 +1275,58 @@ function createHlsAdPlayer(contentVideo, options) {
1127
1275
  }
1128
1276
  function parseVastXml(xmlString) {
1129
1277
  try {
1130
- var _adElements_find;
1131
1278
  var xmlDoc = parseXml(xmlString);
1132
1279
  if (!xmlDoc) return {
1133
1280
  type: "empty"
1134
1281
  };
1135
1282
  var root = xmlDoc.documentElement;
1136
1283
  var adElements = Array.from(root.querySelectorAll(":scope > Ad"));
1137
- var adElement = (_adElements_find = adElements.find(function(el) {
1138
- return getAdSequence(el) === void 0;
1139
- })) !== null && _adElements_find !== void 0 ? _adElements_find : adElements[0];
1140
- if (!adElement) {
1284
+ if (adElements.length === 0) {
1141
1285
  var _root_getAttribute;
1142
1286
  console.warn("[HlsAdPlayer] No Ad element found in VAST ".concat((_root_getAttribute = root.getAttribute("version")) !== null && _root_getAttribute !== void 0 ? _root_getAttribute : "", " response"));
1143
1287
  return emptyVastResult(root);
1144
1288
  }
1145
- var parsed = parseAdElement(adElement, true);
1146
- if (parsed.type === "wrapper") {
1147
- console.log("[HlsAdPlayer] VAST wrapper detected, following VASTAdTagURI: ".concat(parsed.vastAdTagUri));
1289
+ var ordered = _to_consumable_array(adElements.filter(function(el) {
1290
+ return getAdSequence(el) === void 0;
1291
+ })).concat(_to_consumable_array(adElements.filter(function(el) {
1292
+ return getAdSequence(el) !== void 0;
1293
+ })));
1294
+ var firstEmpty;
1295
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1296
+ try {
1297
+ for(var _iterator = ordered.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1298
+ var _step_value = _sliced_to_array(_step.value, 2), index = _step_value[0], adElement = _step_value[1];
1299
+ var parsed = parseAdElement(adElement, true);
1300
+ if (parsed.type === "empty") {
1301
+ firstEmpty !== null && firstEmpty !== void 0 ? firstEmpty : firstEmpty = parsed;
1302
+ continue;
1303
+ }
1304
+ if (index > 0) {
1305
+ logFunnel("vast_ad_fallback", {
1306
+ usedAdIndex: index,
1307
+ adCount: ordered.length
1308
+ });
1309
+ }
1310
+ if (parsed.type === "wrapper") {
1311
+ console.log("[HlsAdPlayer] VAST wrapper detected, following VASTAdTagURI: ".concat(parsed.vastAdTagUri));
1312
+ }
1313
+ return parsed;
1314
+ }
1315
+ } catch (err) {
1316
+ _didIteratorError = true;
1317
+ _iteratorError = err;
1318
+ } finally{
1319
+ try {
1320
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
1321
+ _iterator.return();
1322
+ }
1323
+ } finally{
1324
+ if (_didIteratorError) {
1325
+ throw _iteratorError;
1326
+ }
1327
+ }
1148
1328
  }
1149
- return parsed;
1329
+ return firstEmpty !== null && firstEmpty !== void 0 ? firstEmpty : emptyVastResult(root);
1150
1330
  } catch (error) {
1151
1331
  console.error("[HlsAdPlayer] Error parsing VAST XML:", error);
1152
1332
  return {
@@ -1192,6 +1372,10 @@ function createHlsAdPlayer(contentVideo, options) {
1192
1372
  pushUrls(errorUrls, inLine.querySelectorAll(":scope > Error"));
1193
1373
  if (adElement.getAttribute("conditionalAd") === "true") {
1194
1374
  console.warn("[HlsAdPlayer] Skipping conditional <Ad> (VPAID-only)");
1375
+ logFunnel("vast_no_supported_media", {
1376
+ reason: "vpaid_only",
1377
+ conditionalAd: true
1378
+ });
1195
1379
  return {
1196
1380
  type: "empty",
1197
1381
  errorUrls: errorUrls,
@@ -1200,11 +1384,17 @@ function createHlsAdPlayer(contentVideo, options) {
1200
1384
  }
1201
1385
  var linear;
1202
1386
  var mediaFiles = [];
1387
+ var rejectStats = {
1388
+ total: 0,
1389
+ vpaid: 0,
1390
+ audio: 0,
1391
+ unsupported: 0
1392
+ };
1203
1393
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
1204
1394
  try {
1205
1395
  for(var _iterator = Array.from(inLine.querySelectorAll(":scope > Creatives > Creative > Linear"))[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
1206
1396
  var candidate = _step.value;
1207
- var files = collectVideoMediaFiles(candidate, verbose);
1397
+ var files = collectVideoMediaFiles(candidate, verbose, rejectStats);
1208
1398
  if (files.length > 0) {
1209
1399
  linear = candidate;
1210
1400
  mediaFiles = files;
@@ -1227,6 +1417,10 @@ function createHlsAdPlayer(contentVideo, options) {
1227
1417
  }
1228
1418
  if (!linear) {
1229
1419
  console.warn("[HlsAdPlayer] No supported linear media files in <Ad>");
1420
+ var reason = rejectStats.total === 0 ? "no_mediafiles" : rejectStats.vpaid > 0 ? "vpaid_only" : rejectStats.audio > 0 ? "audio_only" : "unsupported_type";
1421
+ logFunnel("vast_no_supported_media", _object_spread({
1422
+ reason: reason
1423
+ }, rejectStats));
1230
1424
  return {
1231
1425
  type: "empty",
1232
1426
  errorUrls: errorUrls,
@@ -1258,77 +1452,122 @@ function createHlsAdPlayer(contentVideo, options) {
1258
1452
  function fetchVastXml(vastTagUrl) {
1259
1453
  var credentials = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "include";
1260
1454
  return _async_to_generator(function() {
1261
- var requestVast, response, error;
1455
+ var controller, timeoutId, requestVast, response, error, error1;
1262
1456
  return _ts_generator(this, function(_state) {
1263
1457
  switch(_state.label){
1264
1458
  case 0:
1459
+ if (destroyed) {
1460
+ throw new Error("VAST request skipped: ad player destroyed");
1461
+ }
1462
+ controller = typeof AbortController !== "undefined" ? new AbortController() : void 0;
1463
+ if (controller) pendingVastRequests.add(controller);
1464
+ timeoutId = controller ? setTimeout(function() {
1465
+ return controller.abort();
1466
+ }, VAST_REQUEST_TIMEOUT_MS) : void 0;
1265
1467
  requestVast = function requestVast(creds) {
1266
- return fetch(vastTagUrl, {
1468
+ return fetch(vastTagUrl, _object_spread({
1267
1469
  mode: "cors",
1268
1470
  credentials: creds,
1269
1471
  headers: {
1270
1472
  "Accept": "application/xml, text/xml, */*"
1271
1473
  },
1272
1474
  referrerPolicy: "no-referrer-when-downgrade"
1273
- });
1475
+ }, controller ? {
1476
+ signal: controller.signal
1477
+ } : {}));
1274
1478
  };
1275
1479
  _state.label = 1;
1276
1480
  case 1:
1277
1481
  _state.trys.push([
1278
1482
  1,
1279
- 3,
1483
+ 10,
1484
+ 11,
1485
+ 12
1486
+ ]);
1487
+ _state.label = 2;
1488
+ case 2:
1489
+ _state.trys.push([
1490
+ 2,
1491
+ 4,
1280
1492
  ,
1281
- 7
1493
+ 8
1282
1494
  ]);
1283
1495
  return [
1284
1496
  4,
1285
1497
  requestVast(credentials)
1286
1498
  ];
1287
- case 2:
1499
+ case 3:
1288
1500
  response = _state.sent();
1289
1501
  return [
1290
1502
  3,
1291
- 7
1503
+ 8
1292
1504
  ];
1293
- case 3:
1505
+ case 4:
1294
1506
  error = _state.sent();
1295
- if (!(credentials !== "omit")) return [
1507
+ if (!(credentials !== "omit" && !(controller === null || controller === void 0 ? void 0 : controller.signal.aborted))) return [
1296
1508
  3,
1297
- 5
1509
+ 6
1298
1510
  ];
1299
1511
  console.warn('[HlsAdPlayer] VAST fetch failed with credentials="'.concat(credentials, '", retrying without credentials:'), error);
1512
+ logFunnel("vast_credentials_retry", {
1513
+ errorMessage: error === null || error === void 0 ? void 0 : error.message
1514
+ });
1300
1515
  return [
1301
1516
  4,
1302
1517
  requestVast("omit")
1303
1518
  ];
1304
- case 4:
1519
+ case 5:
1305
1520
  response = _state.sent();
1306
1521
  return [
1307
1522
  3,
1308
- 6
1523
+ 7
1309
1524
  ];
1310
- case 5:
1311
- throw error;
1312
1525
  case 6:
1526
+ throw error;
1527
+ case 7:
1313
1528
  return [
1314
1529
  3,
1315
- 7
1530
+ 8
1316
1531
  ];
1317
- case 7:
1532
+ case 8:
1318
1533
  if (!response.ok) {
1319
1534
  throw new Error("Failed to fetch VAST: ".concat(response.statusText));
1320
1535
  }
1321
1536
  return [
1322
- 2,
1537
+ 4,
1323
1538
  response.text()
1324
1539
  ];
1540
+ case 9:
1541
+ return [
1542
+ 2,
1543
+ _state.sent()
1544
+ ];
1545
+ case 10:
1546
+ error1 = _state.sent();
1547
+ if (controller === null || controller === void 0 ? void 0 : controller.signal.aborted) {
1548
+ if (pendingRequestAbortReason) {
1549
+ throw new Error("".concat(pendingRequestAbortReason, " (timeout): ").concat(vastTagUrl));
1550
+ }
1551
+ throw new Error("VAST request timeout after ".concat(VAST_REQUEST_TIMEOUT_MS, "ms: ").concat(vastTagUrl));
1552
+ }
1553
+ throw error1;
1554
+ case 11:
1555
+ if (timeoutId !== void 0) clearTimeout(timeoutId);
1556
+ if (controller) pendingVastRequests.delete(controller);
1557
+ return [
1558
+ 7
1559
+ ];
1560
+ case 12:
1561
+ return [
1562
+ 2
1563
+ ];
1325
1564
  }
1326
1565
  });
1327
1566
  })();
1328
1567
  }
1329
1568
  function fetchAndParseVastAd(_0) {
1330
1569
  return _async_to_generator(function(vastTagUrl) {
1331
- var depth, accumulatedTracking, rules, vastXml, error, parsed, _parsed_errorUrls, _parsed_errorCode;
1570
+ var depth, accumulatedTracking, rules, vastXml, fetchStartedAt, error, parsed, _parsed_errorUrls, _parsed_errorCode;
1332
1571
  var _arguments = arguments;
1333
1572
  return _ts_generator(this, function(_state) {
1334
1573
  switch(_state.label){
@@ -1336,6 +1575,11 @@ function createHlsAdPlayer(contentVideo, options) {
1336
1575
  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] : {
1337
1576
  followAdditionalWrappers: true
1338
1577
  };
1578
+ if (destroyed) return [
1579
+ 2,
1580
+ null
1581
+ ];
1582
+ fetchStartedAt = Date.now();
1339
1583
  _state.label = 1;
1340
1584
  case 1:
1341
1585
  _state.trys.push([
@@ -1358,14 +1602,35 @@ function createHlsAdPlayer(contentVideo, options) {
1358
1602
  error = _state.sent();
1359
1603
  if (depth === 0) throw error;
1360
1604
  console.warn("[HlsAdPlayer] Wrapped VAST request failed:", error);
1361
- fireTrackingPixels(accumulatedTracking.error, {
1362
- errorCode: VAST_ERROR_WRAPPER_TIMEOUT
1605
+ logFunnel("wrapper_fetch", {
1606
+ reason: "failure",
1607
+ depth: depth,
1608
+ wrapperUrl: redactUrl(vastTagUrl),
1609
+ elapsedMs: Date.now() - fetchStartedAt,
1610
+ errorMessage: error === null || error === void 0 ? void 0 : error.message
1363
1611
  });
1612
+ if (!destroyed) {
1613
+ fireTrackingPixels(accumulatedTracking.error, {
1614
+ errorCode: VAST_ERROR_WRAPPER_TIMEOUT
1615
+ });
1616
+ }
1364
1617
  return [
1365
1618
  2,
1366
1619
  null
1367
1620
  ];
1368
1621
  case 4:
1622
+ if (destroyed) return [
1623
+ 2,
1624
+ null
1625
+ ];
1626
+ if (depth > 0) {
1627
+ logFunnel("wrapper_fetch", {
1628
+ reason: "success",
1629
+ depth: depth,
1630
+ wrapperUrl: redactUrl(vastTagUrl),
1631
+ elapsedMs: Date.now() - fetchStartedAt
1632
+ });
1633
+ }
1369
1634
  console.log("[HlsAdPlayer] VAST XML received");
1370
1635
  console.log("[HlsAdPlayer] VAST XML content (first 2000 chars):", vastXml.substring(0, 2e3));
1371
1636
  parsed = parseVastXml(vastXml);
@@ -1397,6 +1662,9 @@ function createHlsAdPlayer(contentVideo, options) {
1397
1662
  ];
1398
1663
  }
1399
1664
  mergeTrackingUrls(parsed.ad.trackingUrls, accumulatedTracking);
1665
+ logFunnel("inline_resolved", {
1666
+ depth: depth
1667
+ });
1400
1668
  return [
1401
1669
  2,
1402
1670
  parsed.ad
@@ -1407,7 +1675,7 @@ function createHlsAdPlayer(contentVideo, options) {
1407
1675
  }
1408
1676
  function fetchAndParsePod(vastTagUrl) {
1409
1677
  return _async_to_generator(function() {
1410
- 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;
1678
+ 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;
1411
1679
  return _ts_generator(this, function(_state) {
1412
1680
  switch(_state.label){
1413
1681
  case 0:
@@ -1417,6 +1685,10 @@ function createHlsAdPlayer(contentVideo, options) {
1417
1685
  ];
1418
1686
  case 1:
1419
1687
  vastXml = _state.sent();
1688
+ if (destroyed) return [
1689
+ 2,
1690
+ []
1691
+ ];
1420
1692
  console.log("[HlsAdPlayer] Pod VAST XML received (length=".concat(vastXml.length, ")"));
1421
1693
  trimmedXml = vastXml.trim();
1422
1694
  if (trimmedXml.length === 0) {
@@ -1488,6 +1760,13 @@ function createHlsAdPlayer(contentVideo, options) {
1488
1760
  buffet = adElements.filter(function(el) {
1489
1761
  return getAdSequence(el) === void 0;
1490
1762
  });
1763
+ resolveAll = function resolveAll(elements) {
1764
+ return Promise.all(elements.map(function(el) {
1765
+ return resolveAd(el).catch(function() {
1766
+ return null;
1767
+ });
1768
+ }));
1769
+ };
1491
1770
  ads = [];
1492
1771
  if (!(podElements.length === 0)) return [
1493
1772
  3,
@@ -1502,27 +1781,26 @@ function createHlsAdPlayer(contentVideo, options) {
1502
1781
  8,
1503
1782
  9
1504
1783
  ]);
1505
- _iterator = buffet[Symbol.iterator]();
1506
- _state.label = 3;
1784
+ return [
1785
+ 4,
1786
+ resolveAll(buffet)
1787
+ ];
1507
1788
  case 3:
1789
+ _iterator = _state.sent()[Symbol.iterator]();
1790
+ _state.label = 4;
1791
+ case 4:
1508
1792
  if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
1509
1793
  3,
1510
1794
  6
1511
1795
  ];
1512
- adElement = _step.value;
1513
- return [
1514
- 4,
1515
- resolveAd(adElement)
1516
- ];
1517
- case 4:
1518
- ad = _state.sent();
1796
+ ad = _step.value;
1519
1797
  if (ad) ads.push(ad);
1520
1798
  _state.label = 5;
1521
1799
  case 5:
1522
1800
  _iteratorNormalCompletion = true;
1523
1801
  return [
1524
1802
  3,
1525
- 3
1803
+ 4
1526
1804
  ];
1527
1805
  case 6:
1528
1806
  return [
@@ -1565,20 +1843,19 @@ function createHlsAdPlayer(contentVideo, options) {
1565
1843
  20,
1566
1844
  21
1567
1845
  ]);
1568
- _iterator1 = podElements[Symbol.iterator]();
1569
- _state.label = 12;
1846
+ return [
1847
+ 4,
1848
+ resolveAll(podElements)
1849
+ ];
1570
1850
  case 12:
1851
+ _iterator1 = _state.sent()[Symbol.iterator]();
1852
+ _state.label = 13;
1853
+ case 13:
1571
1854
  if (!!(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done)) return [
1572
1855
  3,
1573
1856
  18
1574
1857
  ];
1575
- adElement1 = _step1.value;
1576
- return [
1577
- 4,
1578
- resolveAd(adElement1)
1579
- ];
1580
- case 13:
1581
- ad1 = _state.sent();
1858
+ ad1 = _step1.value;
1582
1859
  _state.label = 14;
1583
1860
  case 14:
1584
1861
  if (!(!ad1 && buffet.length > 0)) return [
@@ -1587,7 +1864,9 @@ function createHlsAdPlayer(contentVideo, options) {
1587
1864
  ];
1588
1865
  return [
1589
1866
  4,
1590
- resolveAd(buffet.shift())
1867
+ resolveAd(buffet.shift()).catch(function() {
1868
+ return null;
1869
+ })
1591
1870
  ];
1592
1871
  case 15:
1593
1872
  ad1 = _state.sent();
@@ -1602,7 +1881,7 @@ function createHlsAdPlayer(contentVideo, options) {
1602
1881
  _iteratorNormalCompletion1 = true;
1603
1882
  return [
1604
1883
  3,
1605
- 12
1884
+ 13
1606
1885
  ];
1607
1886
  case 18:
1608
1887
  return [
@@ -1697,14 +1976,17 @@ function createHlsAdPlayer(contentVideo, options) {
1697
1976
  var progress = currentTime / currentAd.duration;
1698
1977
  if (progress >= 0.25 && !trackingFired.firstQuartile) {
1699
1978
  trackingFired.firstQuartile = true;
1979
+ logFunnel("first_quartile");
1700
1980
  fireTrackingPixels(currentAd.trackingUrls.firstQuartile);
1701
1981
  }
1702
1982
  if (progress >= 0.5 && !trackingFired.midpoint) {
1703
1983
  trackingFired.midpoint = true;
1984
+ logFunnel("midpoint");
1704
1985
  fireTrackingPixels(currentAd.trackingUrls.midpoint);
1705
1986
  }
1706
1987
  if (progress >= 0.75 && !trackingFired.thirdQuartile) {
1707
1988
  trackingFired.thirdQuartile = true;
1989
+ logFunnel("third_quartile");
1708
1990
  fireTrackingPixels(currentAd.trackingUrls.thirdQuartile);
1709
1991
  }
1710
1992
  };
@@ -1727,6 +2009,16 @@ function createHlsAdPlayer(contentVideo, options) {
1727
2009
  if (!trackingFired.impression) {
1728
2010
  trackingFired.impression = true;
1729
2011
  resolvedAds.add(currentAd);
2012
+ logFunnel("playing", {
2013
+ mutedByAutoplay: forcedMuteByAutoplay,
2014
+ candidateIndex: mediaCandidateIndex
2015
+ });
2016
+ logFunnel("impression_fired", {
2017
+ pixelCount: currentAd.trackingUrls.impression.length
2018
+ });
2019
+ if (currentAd.trackingUrls.impression.length === 0) {
2020
+ console.warn("[HlsAdPlayer] Ad started but VAST contained no <Impression> URLs - GAM will not count it");
2021
+ }
1730
2022
  fireTrackingPixels(currentAd.trackingUrls.impression);
1731
2023
  fireTrackingPixels(currentAd.trackingUrls.creativeView);
1732
2024
  fireTrackingPixels(currentAd.trackingUrls.verificationNotExecuted, {
@@ -1749,6 +2041,7 @@ function createHlsAdPlayer(contentVideo, options) {
1749
2041
  sampleViewability();
1750
2042
  settleViewability();
1751
2043
  trackingFired.complete = true;
2044
+ logFunnel("complete");
1752
2045
  fireTrackingPixels(currentAd.trackingUrls.complete);
1753
2046
  console.log("[HlsAdPlayer] Ad completed");
1754
2047
  if (podIndex < podAds.length - 1 && advanceToNextPodAd()) {
@@ -1757,16 +2050,41 @@ function createHlsAdPlayer(contentVideo, options) {
1757
2050
  handleAdComplete();
1758
2051
  };
1759
2052
  var onError = function onError(e) {
2053
+ var _adVideoElement_error, _adVideoElement_error1;
1760
2054
  if (!adPlaying) return;
1761
2055
  console.error("[HlsAdPlayer] Ad video error:", e);
1762
- reportCurrentAdError(toVastMediaErrorCode(adVideoElement === null || adVideoElement === void 0 ? void 0 : adVideoElement.error));
1763
- if (podIndex < podAds.length - 1 && advanceToNextPodAd()) {
1764
- return;
1765
- }
1766
- handleAdError();
2056
+ var vastErrorCode = toVastMediaErrorCode(adVideoElement === null || adVideoElement === void 0 ? void 0 : adVideoElement.error);
2057
+ logFunnel("media_error", {
2058
+ mediaErrorCode: adVideoElement === null || adVideoElement === void 0 ? void 0 : (_adVideoElement_error = adVideoElement.error) === null || _adVideoElement_error === void 0 ? void 0 : _adVideoElement_error.code,
2059
+ errorMessage: adVideoElement === null || adVideoElement === void 0 ? void 0 : (_adVideoElement_error1 = adVideoElement.error) === null || _adVideoElement_error1 === void 0 ? void 0 : _adVideoElement_error1.message,
2060
+ networkState: adVideoElement === null || adVideoElement === void 0 ? void 0 : adVideoElement.networkState,
2061
+ readyState: adVideoElement === null || adVideoElement === void 0 ? void 0 : adVideoElement.readyState,
2062
+ currentSrc: adVideoElement === null || adVideoElement === void 0 ? void 0 : adVideoElement.currentSrc,
2063
+ vastErrorCode: vastErrorCode
2064
+ });
2065
+ recoverFromAdFailure(vastErrorCode);
2066
+ };
2067
+ var onMediaDiagnostic = function onMediaDiagnostic(event) {
2068
+ if (!adPlaying || !adVideoElement || trackingFired.impression) return;
2069
+ if (!adVideoElement.currentSrc) return;
2070
+ logFunnel("media_event", {
2071
+ reason: event.type,
2072
+ readyState: adVideoElement.readyState,
2073
+ networkState: adVideoElement.networkState,
2074
+ currentSrc: adVideoElement.currentSrc
2075
+ });
1767
2076
  };
1768
2077
  var onVolumeChange = function onVolumeChange() {
1769
2078
  if (!currentAd || !adVideoElement) return;
2079
+ if (forcedMuteByAutoplay && !adVideoElement.muted) {
2080
+ var userActivation = navigator.userActivation;
2081
+ if (userActivation && !userActivation.isActive) {
2082
+ logFunnel("unexpected_unmute", {
2083
+ paused: adVideoElement.paused
2084
+ });
2085
+ }
2086
+ forcedMuteByAutoplay = false;
2087
+ }
1770
2088
  var muted = adVideoElement.muted || adVideoElement.volume === 0;
1771
2089
  if (!trackingFired.start) {
1772
2090
  trackingFired.lastMuted = muted;
@@ -1826,6 +2144,22 @@ function createHlsAdPlayer(contentVideo, options) {
1826
2144
  {
1827
2145
  type: "play",
1828
2146
  handler: onPlay
2147
+ },
2148
+ {
2149
+ type: "stalled",
2150
+ handler: onMediaDiagnostic
2151
+ },
2152
+ {
2153
+ type: "suspend",
2154
+ handler: onMediaDiagnostic
2155
+ },
2156
+ {
2157
+ type: "abort",
2158
+ handler: onMediaDiagnostic
2159
+ },
2160
+ {
2161
+ type: "emptied",
2162
+ handler: onMediaDiagnostic
1829
2163
  }
1830
2164
  ];
1831
2165
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
@@ -2115,16 +2449,51 @@ function createHlsAdPlayer(contentVideo, options) {
2115
2449
  function settlePendingPlay() {
2116
2450
  pendingPlayPromise = void 0;
2117
2451
  }
2452
+ function toVastPlayErrorCode(error) {
2453
+ return (error === null || error === void 0 ? void 0 : error.name) === "NotSupportedError" ? VAST_ERROR_NO_SUPPORTED_MEDIA : VAST_ERROR_MEDIA_DISPLAY;
2454
+ }
2455
+ function failAdPlayback(context, error) {
2456
+ var vastErrorCode = toVastPlayErrorCode(error);
2457
+ console.error("[HlsAdPlayer] Error starting ".concat(context, ":"), error);
2458
+ logFunnel("play_failed", {
2459
+ errorName: error === null || error === void 0 ? void 0 : error.name,
2460
+ errorMessage: error === null || error === void 0 ? void 0 : error.message,
2461
+ vastErrorCode: vastErrorCode
2462
+ });
2463
+ recoverFromAdFailure(vastErrorCode);
2464
+ }
2118
2465
  function startAdPlayback(context) {
2466
+ var isMutedRetry = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
2119
2467
  if (!adVideoElement) return;
2468
+ var computed = typeof getComputedStyle === "function" && adContainerEl ? getComputedStyle(adContainerEl) : void 0;
2469
+ logFunnel(isMutedRetry ? "muted_retry" : "play_called", {
2470
+ context: context,
2471
+ isConnected: adVideoElement.isConnected,
2472
+ clientWidth: adVideoElement.clientWidth,
2473
+ clientHeight: adVideoElement.clientHeight,
2474
+ containerDisplay: computed === null || computed === void 0 ? void 0 : computed.display,
2475
+ containerVisibility: computed === null || computed === void 0 ? void 0 : computed.visibility
2476
+ });
2120
2477
  var playPromise = adVideoElement.play();
2121
2478
  pendingPlayPromise = playPromise;
2122
2479
  playPromise.catch(function(error) {
2123
2480
  if (pendingPlayPromise !== playPromise) {
2124
2481
  return;
2125
2482
  }
2126
- console.error("[HlsAdPlayer] Error starting ".concat(context, ":"), error);
2127
- handleAdError();
2483
+ logFunnel("play_rejected", {
2484
+ context: context,
2485
+ errorName: error === null || error === void 0 ? void 0 : error.name,
2486
+ errorMessage: error === null || error === void 0 ? void 0 : error.message
2487
+ });
2488
+ if (!isMutedRetry && (error === null || error === void 0 ? void 0 : error.name) === "NotAllowedError" && adVideoElement && !adVideoElement.muted) {
2489
+ console.warn("[HlsAdPlayer] Unmuted ".concat(context, " blocked by autoplay policy - retrying muted"));
2490
+ originalMutedState = true;
2491
+ forcedMuteByAutoplay = true;
2492
+ adVideoElement.muted = true;
2493
+ startAdPlayback(context, true);
2494
+ return;
2495
+ }
2496
+ failAdPlayback(context, error);
2128
2497
  }).finally(function() {
2129
2498
  if (pendingPlayPromise === playPromise) {
2130
2499
  pendingPlayPromise = void 0;
@@ -2163,17 +2532,109 @@ function createHlsAdPlayer(contentVideo, options) {
2163
2532
  adVideoElement.volume = Math.max(0, Math.min(1, originalVolume));
2164
2533
  adVideoElement.muted = originalMutedState;
2165
2534
  }
2535
+ function clearMediaStartTimer() {
2536
+ if (mediaStartTimerId !== void 0) {
2537
+ clearTimeout(mediaStartTimerId);
2538
+ mediaStartTimerId = void 0;
2539
+ }
2540
+ }
2541
+ function startMediaStartTimer() {
2542
+ clearMediaStartTimer();
2543
+ if (!(MEDIA_START_TIMEOUT_MS > 0)) return;
2544
+ var startedAt = Date.now();
2545
+ mediaStartTimerId = setTimeout(function() {
2546
+ mediaStartTimerId = void 0;
2547
+ if (!adPlaying || trackingFired.impression) return;
2548
+ console.warn("[HlsAdPlayer] Ad media did not start playing within ".concat(MEDIA_START_TIMEOUT_MS, "ms"));
2549
+ logFunnel("play_resolved_but_never_started", {
2550
+ timeoutMs: MEDIA_START_TIMEOUT_MS,
2551
+ elapsedMs: Date.now() - startedAt,
2552
+ readyState: adVideoElement === null || adVideoElement === void 0 ? void 0 : adVideoElement.readyState,
2553
+ networkState: adVideoElement === null || adVideoElement === void 0 ? void 0 : adVideoElement.networkState,
2554
+ currentSrc: adVideoElement === null || adVideoElement === void 0 ? void 0 : adVideoElement.currentSrc,
2555
+ paused: adVideoElement === null || adVideoElement === void 0 ? void 0 : adVideoElement.paused,
2556
+ vastErrorCode: VAST_ERROR_MEDIA_TIMEOUT
2557
+ });
2558
+ recoverFromAdFailure(VAST_ERROR_MEDIA_TIMEOUT);
2559
+ }, MEDIA_START_TIMEOUT_MS);
2560
+ }
2561
+ function resetVideoElementForNextSource() {
2562
+ clearStallWatchdog();
2563
+ if (requiresMediaPipelineResetAfterAds()) {
2564
+ recreateAdVideoElement();
2565
+ setupAdEventListeners();
2566
+ } else {
2567
+ prepareVideoElementForNewSource();
2568
+ }
2569
+ }
2570
+ function tryNextMediaCandidate() {
2571
+ if (!currentAd || trackingFired.impression) return false;
2572
+ if (mediaCandidateIndex >= mediaCandidates.length - 1) return false;
2573
+ var failedUrl = currentAdMediaFile === null || currentAdMediaFile === void 0 ? void 0 : currentAdMediaFile.url;
2574
+ mediaCandidateIndex++;
2575
+ var next = mediaCandidates[mediaCandidateIndex];
2576
+ if (!next) return false;
2577
+ logFunnel("media_fallback", {
2578
+ failedUrl: failedUrl,
2579
+ nextUrl: next.url,
2580
+ nextType: next.type,
2581
+ candidateIndex: mediaCandidateIndex,
2582
+ candidateCount: mediaCandidates.length
2583
+ });
2584
+ resetVideoElementForNextSource();
2585
+ try {
2586
+ loadMediaCandidate(next);
2587
+ return true;
2588
+ } catch (error) {
2589
+ console.error("[HlsAdPlayer] Failed to load fallback media file:", error);
2590
+ return tryNextMediaCandidate();
2591
+ }
2592
+ }
2593
+ function recoverFromAdFailure(vastErrorCode) {
2594
+ clearMediaStartTimer();
2595
+ if (tryNextMediaCandidate()) return;
2596
+ reportCurrentAdError(vastErrorCode);
2597
+ if (podIndex < podAds.length - 1 && advanceToNextPodAd()) return;
2598
+ handleAdError();
2599
+ }
2166
2600
  function loadCurrentAdMedia() {
2167
2601
  if (!adVideoElement || !currentAd) {
2168
2602
  throw new Error("No ad video element or ad to load");
2169
2603
  }
2170
- var mediaFile = selectBestMediaFile(currentAd.mediaFiles);
2604
+ mediaCandidates = rankMediaCandidates(currentAd.mediaFiles);
2605
+ mediaCandidateIndex = 0;
2606
+ var mediaFile = mediaCandidates[0];
2171
2607
  if (!mediaFile) {
2172
- throw new Error("No media file available for ad");
2608
+ logFunnel("media_unsupported", {
2609
+ vastErrorCode: VAST_ERROR_NO_SUPPORTED_MEDIA,
2610
+ candidates: currentAd.mediaFiles.length
2611
+ });
2612
+ reportCurrentAdError(VAST_ERROR_NO_SUPPORTED_MEDIA);
2613
+ throw new Error("No media file this browser can play");
2614
+ }
2615
+ try {
2616
+ loadMediaCandidate(mediaFile);
2617
+ } catch (error) {
2618
+ if (tryNextMediaCandidate()) return;
2619
+ reportCurrentAdError(VAST_ERROR_NO_SUPPORTED_MEDIA);
2620
+ throw error;
2621
+ }
2622
+ }
2623
+ function loadMediaCandidate(mediaFile) {
2624
+ if (!adVideoElement || !currentAd) {
2625
+ throw new Error("No ad video element or ad to load");
2173
2626
  }
2174
2627
  currentAdMediaFile = mediaFile;
2175
2628
  var isHlsAd = isHlsMediaFile(mediaFile);
2629
+ logFunnel("media_selected", {
2630
+ width: mediaFile.width,
2631
+ height: mediaFile.height,
2632
+ bitrate: mediaFile.bitrate,
2633
+ candidateIndex: mediaCandidateIndex,
2634
+ candidates: mediaCandidates.length
2635
+ });
2176
2636
  console.log("[HlsAdPlayer] Loading ".concat(isHlsAd ? "HLS" : "progressive", " ad (pod ").concat(podIndex + 1, "/").concat(podAds.length || 1, ") from: ").concat(mediaFile.url));
2637
+ startMediaStartTimer();
2177
2638
  if (isHlsAd && import_hls.default.isSupported()) {
2178
2639
  if (adHls) {
2179
2640
  adHls.destroy();
@@ -2182,6 +2643,9 @@ function createHlsAdPlayer(contentVideo, options) {
2182
2643
  enableWorker: true,
2183
2644
  lowLatencyMode: false
2184
2645
  });
2646
+ logFunnel("media_load", {
2647
+ pipeline: "hls.js"
2648
+ });
2185
2649
  adHls.loadSource(mediaFile.url);
2186
2650
  adHls.attachMedia(adVideoElement);
2187
2651
  adHls.on(import_hls.default.Events.MANIFEST_PARSED, function() {
@@ -2191,10 +2655,24 @@ function createHlsAdPlayer(contentVideo, options) {
2191
2655
  adHls.on(import_hls.default.Events.ERROR, function(_event, data) {
2192
2656
  console.error("[HlsAdPlayer] HLS error:", data);
2193
2657
  if (data.fatal) {
2194
- handleAdError();
2658
+ var _data_response, _data_response1, _data_frag;
2659
+ var vastErrorCode = data.type === import_hls.default.ErrorTypes.NETWORK_ERROR ? 401 : VAST_ERROR_MEDIA_DISPLAY;
2660
+ logFunnel("hls_fatal", {
2661
+ reason: data.details,
2662
+ errorName: data.type,
2663
+ errorMessage: data.details,
2664
+ responseCode: (_data_response = data.response) === null || _data_response === void 0 ? void 0 : _data_response.code,
2665
+ responseText: (_data_response1 = data.response) === null || _data_response1 === void 0 ? void 0 : _data_response1.text,
2666
+ fragUrl: (_data_frag = data.frag) === null || _data_frag === void 0 ? void 0 : _data_frag.url,
2667
+ vastErrorCode: vastErrorCode
2668
+ });
2669
+ recoverFromAdFailure(vastErrorCode);
2195
2670
  }
2196
2671
  });
2197
2672
  } else if (isHlsAd && adVideoElement.canPlayType("application/vnd.apple.mpegurl")) {
2673
+ logFunnel("media_load", {
2674
+ pipeline: "native-hls"
2675
+ });
2198
2676
  adVideoElement.src = mediaFile.url;
2199
2677
  startAdPlayback("native HLS ad playback");
2200
2678
  } else if (!isHlsAd && isProgressiveMediaFile(mediaFile)) {
@@ -2202,45 +2680,47 @@ function createHlsAdPlayer(contentVideo, options) {
2202
2680
  adHls.destroy();
2203
2681
  adHls = void 0;
2204
2682
  }
2683
+ logFunnel("media_load", {
2684
+ pipeline: "progressive"
2685
+ });
2205
2686
  adVideoElement.src = mediaFile.url;
2206
2687
  adVideoElement.load();
2207
2688
  startAdPlayback("progressive ad playback");
2208
2689
  } else {
2690
+ clearMediaStartTimer();
2691
+ logFunnel("media_unsupported", {
2692
+ vastErrorCode: VAST_ERROR_NO_SUPPORTED_MEDIA
2693
+ });
2209
2694
  throw new Error("Unsupported ad media file type: ".concat(mediaFile.type));
2210
2695
  }
2211
2696
  }
2212
2697
  function advanceToNextPodAd() {
2213
- if (podIndex >= podAds.length - 1) {
2214
- return false;
2215
- }
2216
- settleViewability();
2217
- podIndex++;
2218
- currentAd = podAds[podIndex];
2219
- currentAdMediaFile = void 0;
2220
- resetAdTracking();
2221
- if (currentAd) {
2222
- console.log("[HlsAdPlayer] Advancing to next pod ad (".concat(podIndex + 1, "/").concat(podAds.length, "): ").concat(currentAd.title, ", duration: ").concat(currentAd.duration, "s"));
2223
- }
2224
- clearStallWatchdog();
2225
- if (requiresMediaPipelineResetAfterAds()) {
2226
- recreateAdVideoElement();
2227
- setupAdEventListeners();
2228
- } else {
2229
- prepareVideoElementForNewSource();
2230
- }
2231
- try {
2232
- loadCurrentAdMedia();
2233
- emit("pod_ad_started", {
2234
- index: podIndex,
2235
- total: podAds.length
2236
- });
2237
- return true;
2238
- } catch (error) {
2239
- console.error("[HlsAdPlayer] Failed to load next pod ad:", error);
2240
- return false;
2698
+ clearMediaStartTimer();
2699
+ while(podIndex < podAds.length - 1){
2700
+ settleViewability();
2701
+ podIndex++;
2702
+ currentAd = podAds[podIndex];
2703
+ currentAdMediaFile = void 0;
2704
+ resetAdTracking();
2705
+ if (currentAd) {
2706
+ console.log("[HlsAdPlayer] Advancing to next pod ad (".concat(podIndex + 1, "/").concat(podAds.length, "): ").concat(currentAd.title, ", duration: ").concat(currentAd.duration, "s"));
2707
+ }
2708
+ resetVideoElementForNextSource();
2709
+ try {
2710
+ loadCurrentAdMedia();
2711
+ emit("pod_ad_started", {
2712
+ index: podIndex,
2713
+ total: podAds.length
2714
+ });
2715
+ return true;
2716
+ } catch (error) {
2717
+ console.error("[HlsAdPlayer] Failed to load next pod ad:", error);
2718
+ }
2241
2719
  }
2720
+ return false;
2242
2721
  }
2243
2722
  function clearStallWatchdog() {
2723
+ clearMediaStartTimer();
2244
2724
  if (stallWatchdogId != null) {
2245
2725
  clearInterval(stallWatchdogId);
2246
2726
  stallWatchdogId = void 0;
@@ -2256,11 +2736,10 @@ function createHlsAdPlayer(contentVideo, options) {
2256
2736
  function handleAdStall() {
2257
2737
  console.warn("[HlsAdPlayer] Ad playback stalled (no progress) - recovering to avoid a blank frame");
2258
2738
  clearStallWatchdog();
2259
- reportCurrentAdError(VAST_ERROR_MEDIA_DISPLAY);
2260
- if (podIndex < podAds.length - 1 && advanceToNextPodAd()) {
2261
- return;
2262
- }
2263
- handleAdError();
2739
+ logFunnel("stall", {
2740
+ vastErrorCode: VAST_ERROR_MEDIA_DISPLAY
2741
+ });
2742
+ recoverFromAdFailure(VAST_ERROR_MEDIA_DISPLAY);
2264
2743
  }
2265
2744
  function getDecodedVideoFrameCount(video) {
2266
2745
  try {
@@ -2322,11 +2801,10 @@ function createHlsAdPlayer(contentVideo, options) {
2322
2801
  function handleVideoDecodeFailure() {
2323
2802
  console.warn("[HlsAdPlayer] Ad audio is advancing but no video frames decoded (black screen) - skipping this creative");
2324
2803
  clearStallWatchdog();
2325
- reportCurrentAdError(VAST_ERROR_MEDIA_DISPLAY);
2326
- if (podIndex < podAds.length - 1 && advanceToNextPodAd()) {
2327
- return;
2328
- }
2329
- handleAdError();
2804
+ logFunnel("decode_failure", {
2805
+ vastErrorCode: VAST_ERROR_MEDIA_DISPLAY
2806
+ });
2807
+ recoverFromAdFailure(VAST_ERROR_MEDIA_DISPLAY);
2330
2808
  }
2331
2809
  function startStallWatchdog() {
2332
2810
  clearStallWatchdog();
@@ -2450,6 +2928,15 @@ function createHlsAdPlayer(contentVideo, options) {
2450
2928
  Promise.reject(new Error("Ad already playing"))
2451
2929
  ];
2452
2930
  }
2931
+ if (destroyed) {
2932
+ return [
2933
+ 2,
2934
+ Promise.reject(new Error("Ad player destroyed"))
2935
+ ];
2936
+ }
2937
+ currentVastTagUrl = vastTagUrl;
2938
+ pendingRequestAbortReason = void 0;
2939
+ logFunnel("request_sent");
2453
2940
  _state.label = 1;
2454
2941
  case 1:
2455
2942
  _state.trys.push([
@@ -2484,8 +2971,18 @@ function createHlsAdPlayer(contentVideo, options) {
2484
2971
  ads = _state.sent();
2485
2972
  _state.label = 4;
2486
2973
  case 4:
2974
+ if (destroyed) {
2975
+ return [
2976
+ 2,
2977
+ Promise.reject(new Error("Ad player destroyed"))
2978
+ ];
2979
+ }
2980
+ if (!ads.length && pendingRequestAbortReason) {
2981
+ throw new Error(pendingRequestAbortReason);
2982
+ }
2487
2983
  if (!ads.length) {
2488
2984
  console.warn("[HlsAdPlayer] No ads available from VAST response");
2985
+ logFunnel("no_fill");
2489
2986
  emit("ad_error");
2490
2987
  return [
2491
2988
  2,
@@ -2496,6 +2993,23 @@ function createHlsAdPlayer(contentVideo, options) {
2496
2993
  podIndex = 0;
2497
2994
  currentAd = ads[0];
2498
2995
  currentAdMediaFile = void 0;
2996
+ logFunnel("vast_received", {
2997
+ adCount: ads.length,
2998
+ durations: ads.map(function(ad) {
2999
+ return ad.duration;
3000
+ }),
3001
+ impressionUrls: ads.map(function(ad) {
3002
+ return ad.trackingUrls.impression.length;
3003
+ })
3004
+ });
3005
+ ads.forEach(function(ad, index) {
3006
+ if (ad.trackingUrls.impression.length === 0) {
3007
+ logFunnel("vast_missing_impression", {
3008
+ adIndex: index,
3009
+ missingAdId: ad.id
3010
+ });
3011
+ }
3012
+ });
2499
3013
  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"));
2500
3014
  return [
2501
3015
  2,
@@ -2504,6 +3018,9 @@ function createHlsAdPlayer(contentVideo, options) {
2504
3018
  case 5:
2505
3019
  error = _state.sent();
2506
3020
  console.error("[HlsAdPlayer] Error requesting ads:", error);
3021
+ logFunnel("request_failed", {
3022
+ errorMessage: error === null || error === void 0 ? void 0 : error.message
3023
+ });
2507
3024
  emit("ad_error");
2508
3025
  return [
2509
3026
  2,
@@ -2559,13 +3076,22 @@ function createHlsAdPlayer(contentVideo, options) {
2559
3076
  adContainerEl.style.pointerEvents = "auto";
2560
3077
  }
2561
3078
  emit("content_pause");
2562
- loadCurrentAdMedia();
3079
+ try {
3080
+ loadCurrentAdMedia();
3081
+ } catch (loadError) {
3082
+ if (!(podIndex < podAds.length - 1 && advanceToNextPodAd())) {
3083
+ throw loadError;
3084
+ }
3085
+ }
2563
3086
  return [
2564
3087
  2,
2565
3088
  Promise.resolve()
2566
3089
  ];
2567
3090
  } catch (error) {
2568
3091
  console.error("[HlsAdPlayer] Error playing ad:", error);
3092
+ logFunnel("play_failed", {
3093
+ errorMessage: error === null || error === void 0 ? void 0 : error.message
3094
+ });
2569
3095
  handleAdError();
2570
3096
  return [
2571
3097
  2,
@@ -2607,6 +3133,9 @@ function createHlsAdPlayer(contentVideo, options) {
2607
3133
  var previousMutedState;
2608
3134
  return _ts_generator(this, function(_state) {
2609
3135
  console.log("[HlsAdPlayer] Stopping ad");
3136
+ if (adPlaying && currentAd && !trackingFired.impression) {
3137
+ logFunnel("stopped_before_start");
3138
+ }
2610
3139
  settleViewability();
2611
3140
  fireNotUsedForUnplayedAds();
2612
3141
  clearStallWatchdog();
@@ -2639,15 +3168,18 @@ function createHlsAdPlayer(contentVideo, options) {
2639
3168
  },
2640
3169
  destroy: function destroy() {
2641
3170
  console.log("[HlsAdPlayer] Destroying");
3171
+ if (adPlaying && currentAd && !trackingFired.impression) {
3172
+ logFunnel("stopped_before_start");
3173
+ }
2642
3174
  settleViewability();
2643
3175
  fireNotUsedForUnplayedAds();
2644
3176
  destroyed = true;
2645
- clearStallWatchdog();
3177
+ pendingRequestAbortReason = "Ad player destroyed";
2646
3178
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2647
3179
  try {
2648
- for(var _iterator = pendingTimeouts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2649
- var timeoutId = _step.value;
2650
- clearTimeout(timeoutId);
3180
+ for(var _iterator = Array.from(pendingVastRequests)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3181
+ var controller = _step.value;
3182
+ controller.abort();
2651
3183
  }
2652
3184
  } catch (err) {
2653
3185
  _didIteratorError = true;
@@ -2663,6 +3195,28 @@ function createHlsAdPlayer(contentVideo, options) {
2663
3195
  }
2664
3196
  }
2665
3197
  }
3198
+ pendingVastRequests.clear();
3199
+ clearStallWatchdog();
3200
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
3201
+ try {
3202
+ for(var _iterator1 = pendingTimeouts[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
3203
+ var timeoutId = _step1.value;
3204
+ clearTimeout(timeoutId);
3205
+ }
3206
+ } catch (err) {
3207
+ _didIteratorError1 = true;
3208
+ _iteratorError1 = err;
3209
+ } finally{
3210
+ try {
3211
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
3212
+ _iterator1.return();
3213
+ }
3214
+ } finally{
3215
+ if (_didIteratorError1) {
3216
+ throw _iteratorError1;
3217
+ }
3218
+ }
3219
+ }
2666
3220
  pendingTimeouts = [];
2667
3221
  adPlaying = false;
2668
3222
  setAdPlayingFlag(false);
@@ -2682,6 +3236,35 @@ function createHlsAdPlayer(contentVideo, options) {
2682
3236
  isAdPlaying: function isAdPlaying() {
2683
3237
  return adPlaying;
2684
3238
  },
3239
+ setFunnelContext: function setFunnelContext(context) {
3240
+ funnelContext = _object_spread({}, context);
3241
+ },
3242
+ abortPendingRequest: function abortPendingRequest() {
3243
+ var reason = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "VAST request aborted (timeout)";
3244
+ if (pendingVastRequests.size === 0) return;
3245
+ pendingRequestAbortReason = reason;
3246
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3247
+ try {
3248
+ for(var _iterator = Array.from(pendingVastRequests)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3249
+ var controller = _step.value;
3250
+ controller.abort();
3251
+ }
3252
+ } catch (err) {
3253
+ _didIteratorError = true;
3254
+ _iteratorError = err;
3255
+ } finally{
3256
+ try {
3257
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
3258
+ _iterator.return();
3259
+ }
3260
+ } finally{
3261
+ if (_didIteratorError) {
3262
+ throw _iteratorError;
3263
+ }
3264
+ }
3265
+ }
3266
+ pendingVastRequests.clear();
3267
+ },
2685
3268
  resize: function resize(width, height) {
2686
3269
  console.log("[HlsAdPlayer] Resizing to ".concat(width, "x").concat(height));
2687
3270
  if (adContainerEl) {
@@ -2717,6 +3300,13 @@ function createHlsAdPlayer(contentVideo, options) {
2717
3300
  if (adVideoElement && adPlaying) {
2718
3301
  var clamped = Math.max(0, Math.min(1, volume));
2719
3302
  adVideoElement.volume = clamped;
3303
+ var userActivation = navigator.userActivation;
3304
+ if (clamped > 0 && forcedMuteByAutoplay && userActivation && !userActivation.isActive) {
3305
+ logFunnel("unmute_blocked_without_gesture", {
3306
+ requestedVolume: clamped
3307
+ });
3308
+ return;
3309
+ }
2720
3310
  adVideoElement.muted = clamped === 0;
2721
3311
  }
2722
3312
  },
@@ -6780,7 +7370,7 @@ var AdTimingService = /*#__PURE__*/ function() {
6780
7370
  {
6781
7371
  key: "adFitsRemainingBudget",
6782
7372
  value: function adFitsRemainingBudget(durationMs) {
6783
- if (durationMs <= 0) {
7373
+ if (durationMs <= 0 || this.expectedAdBreakDurationMs == null) {
6784
7374
  return true;
6785
7375
  }
6786
7376
  return durationMs <= this.getDurationBudgetRemainingMs();
@@ -6839,6 +7429,11 @@ var AdTimingService = /*#__PURE__*/ function() {
6839
7429
  value: function markAdStarted() {
6840
7430
  this.currentAdIndex++;
6841
7431
  this.totalAdsInBreak = this.currentAdIndex;
7432
+ }
7433
+ },
7434
+ {
7435
+ key: "noteAdRequestSent",
7436
+ value: function noteAdRequestSent() {
6842
7437
  this.totalAdRequestsInBreak++;
6843
7438
  this.lastAdRequestTime = Date.now();
6844
7439
  }
@@ -6890,6 +7485,9 @@ var AdTimingService = /*#__PURE__*/ function() {
6890
7485
  if (message.includes("timeout")) {
6891
7486
  return true;
6892
7487
  }
7488
+ if (message.includes("ad player destroyed") || message.includes("aborted")) {
7489
+ return true;
7490
+ }
6893
7491
  if (message.includes("rate limit") || message.includes("too many requests")) {
6894
7492
  return true;
6895
7493
  }
@@ -8023,6 +8621,10 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8023
8621
  this.adDetectSentForCurrentBreak = false;
8024
8622
  this.continuousFetchingActive = false;
8025
8623
  this.continuousFetchLoopRunning = false;
8624
+ this.breakFunnel = {};
8625
+ this.controllerCallInFlight = false;
8626
+ this.playbackStartedForCurrentRequest = false;
8627
+ this.opportunityEpoch = -1;
8026
8628
  this.adRequestQueue = [];
8027
8629
  this.adPodQueue = [];
8028
8630
  this.maxPlaceholderDurationMs = 5e3;
@@ -8075,12 +8677,35 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8075
8677
  adPlayer.on("ad_interaction", function(event) {
8076
8678
  if (event) _this.host.onAdInteraction(event);
8077
8679
  });
8078
- adPlayer.on("all_ads_completed", function() {
8079
- sendAdImpressionTracking(_this.host.config.licenseKey, {
8680
+ adPlayer.on("ad_funnel", function(payload) {
8681
+ if (!(payload === null || payload === void 0 ? void 0 : payload.stage)) return;
8682
+ _this.countFunnelStage(payload.stage);
8683
+ if (payload.reason) {
8684
+ _this.countFunnelStage("".concat(payload.stage, ":").concat(payload.reason));
8685
+ }
8686
+ if (payload.stage === "impression_fired" && payload.pixelCount != null) {
8687
+ _this.countFunnelStage("impression_urls", payload.pixelCount);
8688
+ }
8689
+ if (payload.visibilityState === "hidden") {
8690
+ _this.countFunnelStage("while_hidden");
8691
+ }
8692
+ });
8693
+ adPlayer.on("ad_impression", function() {
8694
+ _this.timing.consecutiveFailures = 0;
8695
+ if (!_this.playbackStartedForCurrentRequest) {
8696
+ _this.playbackStartedForCurrentRequest = true;
8697
+ _this.timing.markAdStarted();
8698
+ }
8699
+ sendAdImpressionTracking(_this.host.config.licenseKey, _object_spread_props(_object_spread({
8080
8700
  source: "hls",
8081
- adIndex: _this.timing.currentAdIndex,
8701
+ adIndex: _this.timing.currentAdIndex
8702
+ }, _this.currentVastUrl ? {
8703
+ adUrl: _this.currentVastUrl
8704
+ } : {}), {
8082
8705
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
8083
- }, _this.analyticsContext).catch(function() {});
8706
+ }), _this.analyticsContext).catch(function() {});
8707
+ });
8708
+ adPlayer.on("all_ads_completed", function() {
8084
8709
  _this.timing.recordPlayedAdDuration(_this.host.getAdPlayer());
8085
8710
  var remaining = _this.timing.getRemainingAdMs();
8086
8711
  _this.timing.consecutiveFailures = 0;
@@ -8114,6 +8739,10 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8114
8739
  }
8115
8740
  }
8116
8741
  console.error("[AD-ERROR]", errorMessage, errorPayload || "");
8742
+ if (_this.controllerCallInFlight) {
8743
+ _this.timing.recordGamNoFill();
8744
+ return;
8745
+ }
8117
8746
  _this.handleAdFailure();
8118
8747
  });
8119
8748
  adPlayer.on("content_pause", function() {
@@ -8138,11 +8767,6 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8138
8767
  }
8139
8768
  });
8140
8769
  adPlayer.on("content_resume", function() {
8141
- sendAdImpressionTracking(_this.host.config.licenseKey, {
8142
- source: "hls",
8143
- adIndex: _this.timing.currentAdIndex,
8144
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
8145
- }, _this.analyticsContext).catch(function() {});
8146
8770
  if (!_this.host.video.muted) {
8147
8771
  _this.host.video.muted = true;
8148
8772
  if (_this.debug) {
@@ -8190,6 +8814,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8190
8814
  }
8191
8815
  var preservedMutedState = adPlayer.getOriginalMutedState();
8192
8816
  var preservedVolumeState = adPlayer.getOriginalVolume();
8817
+ this.playbackStartedForCurrentRequest = false;
8193
8818
  if (adPlayer) {
8194
8819
  try {
8195
8820
  adPlayer.destroy();
@@ -8279,9 +8904,10 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8279
8904
  if (this.timing.expectedAdBreakDurationMs == null && adBreakDurationMs != null) {
8280
8905
  this.timing.expectedAdBreakDurationMs = adBreakDurationMs;
8281
8906
  }
8907
+ this.noteOpportunity("scte35", this.cueManager.activeScte35BreakKey);
8282
8908
  return [
8283
8909
  4,
8284
- this.startOptimizedPod(baseVastUrl, adBreakDurationMs, currentMuted, currentVolume)
8910
+ this.startOptimizedPod(baseVastUrl, adBreakDurationMs)
8285
8911
  ];
8286
8912
  case 1:
8287
8913
  podPlayed = _state.sent();
@@ -8315,7 +8941,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8315
8941
  value: // ───────────────────────────────────────────────────────────────
8316
8942
  // Optimized pod (single multi-ad request)
8317
8943
  // ───────────────────────────────────────────────────────────────
8318
- function startOptimizedPod(baseVastUrl, breakDurationMs, currentMuted, currentVolume) {
8944
+ function startOptimizedPod(baseVastUrl, breakDurationMs) {
8319
8945
  return _async_to_generator(function() {
8320
8946
  var podUrl, adPlayer, requestToken, _ref, _adPlayer_getPodAdCount, podCount, error;
8321
8947
  return _ts_generator(this, function(_state) {
@@ -8338,7 +8964,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8338
8964
  adPlayer = this.host.getAdPlayer();
8339
8965
  requestToken = ++this.timing.adRequestTokenCounter;
8340
8966
  this.timing.activeAdRequestToken = requestToken;
8341
- this.timing.startAdRequestWatchdog(requestToken);
8967
+ this.currentVastUrl = podUrl;
8342
8968
  _state.label = 1;
8343
8969
  case 1:
8344
8970
  _state.trys.push([
@@ -8353,10 +8979,14 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8353
8979
  ];
8354
8980
  case 2:
8355
8981
  _state.sent();
8356
- this.timing.lastAdRequestTime = Date.now();
8982
+ this.timing.startAdRequestWatchdog(requestToken);
8983
+ this.timing.noteAdRequestSent();
8984
+ this.beginFunnelRequest(adPlayer, requestToken);
8357
8985
  return [
8358
8986
  4,
8359
- adPlayer.requestAds(podUrl)
8987
+ this.callController(function() {
8988
+ return adPlayer.requestAds(podUrl);
8989
+ })
8360
8990
  ];
8361
8991
  case 3:
8362
8992
  _state.sent();
@@ -8385,16 +9015,16 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8385
9015
  this.timing.startAdFailsafeTimer(requestToken);
8386
9016
  return [
8387
9017
  4,
8388
- adPlayer.play()
9018
+ this.callController(function() {
9019
+ return adPlayer.play();
9020
+ })
8389
9021
  ];
8390
9022
  case 4:
8391
9023
  _state.sent();
8392
- this.timing.markAdStarted();
8393
9024
  if (this.timing.expectedAdBreakDurationMs != null && this.timing.getAdBreakEndWallClockMs() == null) {
8394
9025
  this.timing.scheduleAdStopAtBreakBoundary();
8395
9026
  }
8396
- adPlayer.setAdVolume(currentMuted ? 0 : currentVolume);
8397
- this.timing.consecutiveFailures = 0;
9027
+ adPlayer.setAdVolume(getAdAudioVolume(adPlayer));
8398
9028
  this.continuousFetchingActive = true;
8399
9029
  this.startContinuousFetching(baseVastUrl);
8400
9030
  return [
@@ -8759,7 +9389,6 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8759
9389
  ];
8760
9390
  case 3:
8761
9391
  _state.sent();
8762
- this.timing.consecutiveFailures = 0;
8763
9392
  return [
8764
9393
  3,
8765
9394
  8
@@ -8772,6 +9401,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8772
9401
  3,
8773
9402
  6
8774
9403
  ];
9404
+ this.timing.consecutiveFailures++;
8775
9405
  return [
8776
9406
  4,
8777
9407
  this.tryNextAvailableAdWithRateLimit()
@@ -8841,13 +9471,159 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8841
9471
  }
8842
9472
  },
8843
9473
  {
8844
- key: "playSingleAd",
8845
- value: // ───────────────────────────────────────────────────────────────
9474
+ // ───────────────────────────────────────────────────────────────
8846
9475
  // Single ad playback
8847
9476
  // ───────────────────────────────────────────────────────────────
8848
- function playSingleAd(vastTagUrl) {
9477
+ key: "withCurrentPodBudget",
9478
+ value: function withCurrentPodBudget(vastTagUrl) {
9479
+ var remaining = Math.min(this.timing.getWallClockRemainingAdMs(), this.timing.getDurationBudgetRemainingMs());
9480
+ if (!(remaining > 0)) return vastTagUrl;
9481
+ try {
9482
+ var url = new URL(vastTagUrl);
9483
+ if (!url.searchParams.has("pmxd")) return vastTagUrl;
9484
+ var maxMs = Math.round(remaining);
9485
+ url.searchParams.set("pmxd", String(maxMs));
9486
+ var minMs = Number(url.searchParams.get("pmnd"));
9487
+ if (Number.isFinite(minMs) && minMs > maxMs) {
9488
+ url.searchParams.set("pmnd", String(maxMs));
9489
+ }
9490
+ return url.toString();
9491
+ } catch (unused) {
9492
+ return vastTagUrl;
9493
+ }
9494
+ }
9495
+ },
9496
+ {
9497
+ key: "countFunnelStage",
9498
+ value: function countFunnelStage(stage) {
9499
+ var amount = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
9500
+ var _this_breakFunnel_stage;
9501
+ this.breakFunnel[stage] = ((_this_breakFunnel_stage = this.breakFunnel[stage]) !== null && _this_breakFunnel_stage !== void 0 ? _this_breakFunnel_stage : 0) + amount;
9502
+ }
9503
+ },
9504
+ {
9505
+ key: "logOrchestratorFunnel",
9506
+ value: function logOrchestratorFunnel(stage) {
9507
+ var extra = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
9508
+ this.countFunnelStage(stage);
9509
+ console.log("[AdBreak][FUNNEL] ".concat(stage), _object_spread({
9510
+ breakId: this.timing.adBreakEpoch,
9511
+ requestId: this.currentRequestId,
9512
+ visibilityState: typeof document !== "undefined" ? document.visibilityState : void 0
9513
+ }, extra));
9514
+ }
9515
+ },
9516
+ {
9517
+ key: "noteOpportunity",
9518
+ value: function noteOpportunity(source, breakKey) {
9519
+ if (breakKey && breakKey === this.opportunityBreakKey && this.opportunityEpoch === this.timing.adBreakEpoch) {
9520
+ this.logOrchestratorFunnel("duplicate_break_start", {
9521
+ source: source,
9522
+ breakKey: breakKey
9523
+ });
9524
+ return;
9525
+ }
9526
+ this.opportunityBreakKey = breakKey;
9527
+ this.opportunityEpoch = this.timing.adBreakEpoch;
9528
+ this.logOrchestratorFunnel("opportunity_created", {
9529
+ source: source,
9530
+ breakKey: breakKey,
9531
+ expectedDurationMs: this.timing.expectedAdBreakDurationMs
9532
+ });
9533
+ }
9534
+ },
9535
+ {
9536
+ key: "beginFunnelRequest",
9537
+ value: function beginFunnelRequest(adPlayer, requestToken) {
9538
+ var _adPlayer_setFunnelContext;
9539
+ if (this.controllerCallInFlight) {
9540
+ this.logOrchestratorFunnel("duplicate_request_detected", {
9541
+ newRequestId: requestToken
9542
+ });
9543
+ }
9544
+ this.currentRequestId = requestToken;
9545
+ this.requestStartedAt = Date.now();
9546
+ (_adPlayer_setFunnelContext = adPlayer.setFunnelContext) === null || _adPlayer_setFunnelContext === void 0 ? void 0 : _adPlayer_setFunnelContext.call(adPlayer, {
9547
+ breakId: this.timing.adBreakEpoch,
9548
+ requestId: requestToken
9549
+ });
9550
+ }
9551
+ },
9552
+ {
9553
+ key: "isAdLoadingWithoutPlayback",
9554
+ value: function isAdLoadingWithoutPlayback() {
9555
+ return this.host.getAdPlayer().isAdPlaying() && !this.playbackStartedForCurrentRequest;
9556
+ }
9557
+ },
9558
+ {
9559
+ key: "noteStopBeforeStart",
9560
+ value: function noteStopBeforeStart(reason) {
9561
+ if (!this.isAdLoadingWithoutPlayback()) return;
9562
+ this.logOrchestratorFunnel("ad_stopped_before_start", {
9563
+ reason: reason,
9564
+ elapsedSinceRequestMs: this.requestStartedAt != null ? Date.now() - this.requestStartedAt : void 0
9565
+ });
9566
+ }
9567
+ },
9568
+ {
9569
+ key: "handleRequestWatchdogTimeout",
9570
+ value: function handleRequestWatchdogTimeout() {
9571
+ var adPlayer = this.host.getAdPlayer();
9572
+ if (this.controllerCallInFlight && adPlayer.abortPendingRequest) {
9573
+ this.logOrchestratorFunnel("request_aborted_timeout", {
9574
+ elapsedSinceRequestMs: this.requestStartedAt != null ? Date.now() - this.requestStartedAt : void 0
9575
+ });
9576
+ adPlayer.abortPendingRequest("VAST request aborted after request watchdog timeout");
9577
+ return;
9578
+ }
9579
+ this.handleAdFailure();
9580
+ }
9581
+ },
9582
+ {
9583
+ key: "callController",
9584
+ value: function callController(call) {
8849
9585
  return _async_to_generator(function() {
8850
- var adPlayer, requestToken, ap, playError, error, errorMessage;
9586
+ return _ts_generator(this, function(_state) {
9587
+ switch(_state.label){
9588
+ case 0:
9589
+ this.controllerCallInFlight = true;
9590
+ _state.label = 1;
9591
+ case 1:
9592
+ _state.trys.push([
9593
+ 1,
9594
+ ,
9595
+ 3,
9596
+ 4
9597
+ ]);
9598
+ return [
9599
+ 4,
9600
+ call()
9601
+ ];
9602
+ case 2:
9603
+ _state.sent();
9604
+ return [
9605
+ 3,
9606
+ 4
9607
+ ];
9608
+ case 3:
9609
+ this.controllerCallInFlight = false;
9610
+ return [
9611
+ 7
9612
+ ];
9613
+ case 4:
9614
+ return [
9615
+ 2
9616
+ ];
9617
+ }
9618
+ });
9619
+ }).call(this);
9620
+ }
9621
+ },
9622
+ {
9623
+ key: "playSingleAd",
9624
+ value: function playSingleAd(vastTagUrl) {
9625
+ return _async_to_generator(function() {
9626
+ var adPlayer, requestToken, ap, requestUrl, _ap_getLoadedAdDuration, adDurationS, remainingMs, playError, error, errorMessage;
8851
9627
  return _ts_generator(this, function(_state) {
8852
9628
  switch(_state.label){
8853
9629
  case 0:
@@ -8874,7 +9650,6 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8874
9650
  this.recreateAdController();
8875
9651
  requestToken = ++this.timing.adRequestTokenCounter;
8876
9652
  this.timing.activeAdRequestToken = requestToken;
8877
- this.timing.startAdRequestWatchdog(requestToken);
8878
9653
  _state.label = 1;
8879
9654
  case 1:
8880
9655
  _state.trys.push([
@@ -8889,17 +9664,23 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8889
9664
  ];
8890
9665
  case 2:
8891
9666
  _state.sent();
8892
- this.timing.lastAdRequestTime = Date.now();
9667
+ this.timing.startAdRequestWatchdog(requestToken);
9668
+ this.timing.noteAdRequestSent();
8893
9669
  ap = this.host.getAdPlayer();
9670
+ requestUrl = this.withCurrentPodBudget(vastTagUrl);
9671
+ this.currentVastUrl = requestUrl;
9672
+ this.beginFunnelRequest(ap, requestToken);
8894
9673
  return [
8895
9674
  4,
8896
- ap.requestAds(vastTagUrl)
9675
+ this.callController(function() {
9676
+ return ap.requestAds(requestUrl);
9677
+ })
8897
9678
  ];
8898
9679
  case 3:
8899
9680
  _state.sent();
8900
9681
  sendAdLoadedTracking(this.host.config.licenseKey, {
8901
9682
  source: "hls",
8902
- vastUrl: vastTagUrl,
9683
+ vastUrl: requestUrl,
8903
9684
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
8904
9685
  }, this.analyticsContext).catch(function() {});
8905
9686
  this.timing.clearAdRequestWatchdog();
@@ -8907,6 +9688,14 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8907
9688
  2
8908
9689
  ];
8909
9690
  if (!this.timing.ensureLoadedAdFitsBudget(ap)) {
9691
+ ;
9692
+ adDurationS = (_ap_getLoadedAdDuration = ap.getLoadedAdDuration) === null || _ap_getLoadedAdDuration === void 0 ? void 0 : _ap_getLoadedAdDuration.call(ap);
9693
+ remainingMs = Math.min(this.timing.getWallClockRemainingAdMs(), this.timing.getDurationBudgetRemainingMs());
9694
+ this.logOrchestratorFunnel("discarded_budget", {
9695
+ vastUrl: requestUrl,
9696
+ adDurationMs: adDurationS != null ? adDurationS * 1e3 : void 0,
9697
+ remainingMs: remainingMs
9698
+ });
8910
9699
  this.timing.rejectLoadedAdForDuration(ap);
8911
9700
  this.recreateAdController();
8912
9701
  throw new Error("ad_duration_exceeds_budget");
@@ -8922,16 +9711,16 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
8922
9711
  this.timing.startAdFailsafeTimer(requestToken);
8923
9712
  return [
8924
9713
  4,
8925
- ap.play()
9714
+ this.callController(function() {
9715
+ return ap.play();
9716
+ })
8926
9717
  ];
8927
9718
  case 5:
8928
9719
  _state.sent();
8929
- this.timing.markAdStarted();
8930
9720
  if (this.timing.expectedAdBreakDurationMs != null && this.timing.getAdBreakEndWallClockMs() == null) {
8931
9721
  this.timing.scheduleAdStopAtBreakBoundary();
8932
9722
  }
8933
9723
  ap.setAdVolume(getAdAudioVolume(ap));
8934
- this.timing.consecutiveFailures = 0;
8935
9724
  this.timing.temporaryFailureUrls.delete(vastTagUrl);
8936
9725
  return [
8937
9726
  3,
@@ -9095,7 +9884,6 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9095
9884
  ];
9096
9885
  case 5:
9097
9886
  _state.sent();
9098
- this.timing.consecutiveFailures = 0;
9099
9887
  return [
9100
9888
  3,
9101
9889
  10
@@ -9107,6 +9895,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9107
9895
  3,
9108
9896
  8
9109
9897
  ];
9898
+ this.timing.consecutiveFailures++;
9110
9899
  return [
9111
9900
  4,
9112
9901
  this.tryNextAvailableAdWithRateLimit()
@@ -9157,6 +9946,67 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9157
9946
  // ───────────────────────────────────────────────────────────────
9158
9947
  // Ad break completion
9159
9948
  // ───────────────────────────────────────────────────────────────
9949
+ key: "logBreakFunnel",
9950
+ value: function logBreakFunnel() {
9951
+ var funnel = this.breakFunnel;
9952
+ this.breakFunnel = {};
9953
+ if (Object.keys(funnel).length === 0) return;
9954
+ var count = function count(stage) {
9955
+ var _funnel_stage;
9956
+ return (_funnel_stage = funnel[stage]) !== null && _funnel_stage !== void 0 ? _funnel_stage : 0;
9957
+ };
9958
+ var breakId = this.opportunityEpoch;
9959
+ if (count("request_sent") > 0 && count("impression_fired") === 0) {
9960
+ console.log("[AdBreak][FUNNEL] break_abandoned_before_start", {
9961
+ breakId: breakId,
9962
+ requests: count("request_sent")
9963
+ });
9964
+ }
9965
+ console.log("[AdBreak][FUNNEL] Break summary", {
9966
+ breakId: breakId,
9967
+ opportunities: count("opportunity_created"),
9968
+ requests: count("request_sent"),
9969
+ duplicates: count("duplicate_request_detected") + count("duplicate_break_start"),
9970
+ filled: count("vast_received"),
9971
+ noFill: count("no_fill"),
9972
+ requestFailed: count("request_failed"),
9973
+ requestAbortedTimeout: count("request_aborted_timeout"),
9974
+ credentialsRetries: count("vast_credentials_retry"),
9975
+ wrapperFailures: count("wrapper_fetch:failure"),
9976
+ noSupportedMedia: count("vast_no_supported_media"),
9977
+ vpaidOnly: count("vast_no_supported_media:vpaid_only"),
9978
+ missingImpression: count("vast_missing_impression"),
9979
+ discardedBudget: count("discarded_budget"),
9980
+ mediaCandidates: count("media_candidate:accepted") + count("media_candidate:rejected"),
9981
+ mediaRejected: count("media_candidate:rejected"),
9982
+ mediaFallbacks: count("media_fallback"),
9983
+ playCalled: count("play_called"),
9984
+ playRejected: count("play_rejected"),
9985
+ mutedRetry: count("muted_retry"),
9986
+ startTimeouts: count("play_resolved_but_never_started"),
9987
+ impressions: count("impression_fired"),
9988
+ impressionUrls: count("impression_urls"),
9989
+ trackingRequests: count("tracking_request_created"),
9990
+ trackingNotLoaded: count("tracking_request_settled:error") + count("tracking_request_settled:timeout"),
9991
+ trackingUnexpandedMacros: count("tracking_url_unexpanded_macro"),
9992
+ trackingInvalidUrls: count("tracking_url_invalid"),
9993
+ vastAdFallbacks: count("vast_ad_fallback"),
9994
+ mediaEvents: count("media_event"),
9995
+ quartile25: count("first_quartile"),
9996
+ quartile50: count("midpoint"),
9997
+ quartile75: count("third_quartile"),
9998
+ complete: count("complete"),
9999
+ stoppedBeforeStart: count("stopped_before_start"),
10000
+ stoppedBeforeStartByBreakEnd: count("ad_stopped_before_start"),
10001
+ unexpectedUnmutes: count("unexpected_unmute"),
10002
+ unmuteBlocked: count("unmute_blocked_without_gesture"),
10003
+ visibilityHidden: count("while_hidden"),
10004
+ playbackFailures: count("play_failed") + count("media_error") + count("hls_fatal") + count("stall") + count("decode_failure") + count("media_unsupported"),
10005
+ stages: funnel
10006
+ });
10007
+ }
10008
+ },
10009
+ {
9160
10010
  key: "handleAdPodComplete",
9161
10011
  value: function handleAdPodComplete() {
9162
10012
  if (this.debug) {
@@ -9177,6 +10027,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
9177
10027
  this.adPodQueue = [];
9178
10028
  this.showAds = false;
9179
10029
  this.host.getAdPlayer().stop().catch(function() {});
10030
+ this.logBreakFunnel();
9180
10031
  var restoredMuted = this.host.getAdPlayer().getOriginalMutedState();
9181
10032
  var restoredVolume = this.host.getAdPlayer().getOriginalVolume();
9182
10033
  if (this.host.video.muted !== restoredMuted) {
@@ -9528,7 +10379,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
9528
10379
  _this.startScte35AdBreak(marker, cueKey, marker.durationSeconds != null ? marker.durationSeconds * 1e3 : _this.timing.expectedAdBreakDurationMs);
9529
10380
  },
9530
10381
  onWatchdogTimeout: function onWatchdogTimeout() {
9531
- return _this.adBreak.handleAdFailure();
10382
+ return _this.adBreak.handleRequestWatchdogTimeout();
9532
10383
  },
9533
10384
  onFailsafeTimeout: function onFailsafeTimeout() {
9534
10385
  return _this.adBreak.handleAdFailure();
@@ -9633,6 +10484,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
9633
10484
  licenseKey: this.config.licenseKey
9634
10485
  } : {}, ((_this_hlsEngine = this.hlsEngine) === null || _this_hlsEngine === void 0 ? void 0 : _this_hlsEngine.hls) ? {
9635
10486
  mainHlsInstance: this.hlsEngine.hls
10487
+ } : {}, this.config.adMediaStartTimeoutMs != null ? {
10488
+ mediaStartTimeoutMs: this.config.adMediaStartTimeoutMs
9636
10489
  } : {}));
9637
10490
  }
9638
10491
  },
@@ -9987,6 +10840,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
9987
10840
  this.timing.clearAdStartTimer();
9988
10841
  this.timing.clearAdStopTimer();
9989
10842
  if (adPlaying) {
10843
+ this.adBreak.noteStopBeforeStart("scte_end");
9990
10844
  this.adPlayer.stop().catch(function() {});
9991
10845
  }
9992
10846
  this.adBreak.handleAdPodComplete();
@@ -10026,6 +10880,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10026
10880
  console.log("[StormcloudVideoPlayer] Ad break boundary reached (overrun=".concat(overrunMs, "ms) - hard-stopping ads and resuming stream"));
10027
10881
  }
10028
10882
  if (adPlaying) {
10883
+ this.adBreak.noteStopBeforeStart("break_boundary");
10029
10884
  this.adPlayer.stop().catch(function() {});
10030
10885
  }
10031
10886
  this.adBreak.handleAdPodComplete();
@@ -10154,6 +11009,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
10154
11009
  this.adBreak.showAds = true;
10155
11010
  this.adBreak.inAdBreak = true;
10156
11011
  this.timing.currentAdBreakStartWallClockMs = Date.now();
11012
+ if (durationMs > 0) {
11013
+ this.timing.setAdBreakDurationBoundary(durationMs);
11014
+ }
11015
+ this.adBreak.noteOpportunity("vmap", key);
10157
11016
  _state.label = 1;
10158
11017
  case 1:
10159
11018
  _state.trys.push([