stormcloud-video-player 0.7.10 → 0.7.12

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.
@@ -1443,7 +1443,6 @@ function createAdStormPlayer(contentVideo, options) {
1443
1443
  contentVideo.muted = originalMutedState;
1444
1444
  contentVideo.volume = originalVolume;
1445
1445
  currentAd = void 0;
1446
- tornDown = false;
1447
1446
  return [
1448
1447
  2,
1449
1448
  Promise.resolve()
@@ -1558,6 +1557,15 @@ function createAdStormPlayer(contentVideo, options) {
1558
1557
  if (!token) return [
1559
1558
  2
1560
1559
  ];
1560
+ if (currentAd) {
1561
+ preloadSlots.set(token, {
1562
+ ad: currentAd
1563
+ });
1564
+ currentAd = void 0;
1565
+ return [
1566
+ 2
1567
+ ];
1568
+ }
1561
1569
  requestContext = typeof arg1 === "string" ? arg2 : arg1;
1562
1570
  return [
1563
1571
  4,
@@ -2051,56 +2059,6 @@ function sendInitialTracking(licenseKey) {
2051
2059
  });
2052
2060
  })();
2053
2061
  }
2054
- function sendAdDetectTracking(licenseKey, adDetectInfo) {
2055
- return _async_to_generator(function() {
2056
- var clientInfo, browserId, trackingData, error;
2057
- return _ts_generator(this, function(_state) {
2058
- switch(_state.label){
2059
- case 0:
2060
- _state.trys.push([
2061
- 0,
2062
- 3,
2063
- ,
2064
- 4
2065
- ]);
2066
- clientInfo = getClientInfo();
2067
- return [
2068
- 4,
2069
- getBrowserID(clientInfo)
2070
- ];
2071
- case 1:
2072
- browserId = _state.sent();
2073
- trackingData = _object_spread({
2074
- browserId: browserId
2075
- }, clientInfo);
2076
- return [
2077
- 4,
2078
- sendTrackRequest(licenseKey, _object_spread_props(_object_spread({}, trackingData), {
2079
- licenseKey: licenseKey,
2080
- adDetectInfo: adDetectInfo
2081
- }))
2082
- ];
2083
- case 2:
2084
- _state.sent();
2085
- return [
2086
- 3,
2087
- 4
2088
- ];
2089
- case 3:
2090
- error = _state.sent();
2091
- console.error("[StormcloudVideoPlayer] Error sending ad detect tracking:", error);
2092
- return [
2093
- 3,
2094
- 4
2095
- ];
2096
- case 4:
2097
- return [
2098
- 2
2099
- ];
2100
- }
2101
- });
2102
- })();
2103
- }
2104
2062
  function sendAdLoadedTracking(licenseKey, adLoadedInfo) {
2105
2063
  return _async_to_generator(function() {
2106
2064
  var clientInfo, browserId, trackingData, error;
@@ -2785,7 +2743,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
2785
2743
  this.continuousFetchLoopPromise = null;
2786
2744
  this.attached = false;
2787
2745
  this.inAdBreak = false;
2788
- this.ptsDriftEmaMs = 0;
2789
2746
  this.adPodQueue = [];
2790
2747
  this.lastHeartbeatTime = 0;
2791
2748
  this.currentAdIndex = 0;
@@ -2804,10 +2761,12 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
2804
2761
  this.isInAdTransition = false;
2805
2762
  this.maxPlaceholderDurationMs = 5e3;
2806
2763
  this.isShowingPlaceholder = false;
2764
+ this.lastAdInsertionPoint = null;
2765
+ this.processedAdInsertionUpdatedAt = null;
2807
2766
  this.totalAdRequestsInBreak = 0;
2808
2767
  this.maxTotalAdRequestsPerBreak = 20;
2809
2768
  this.pendingAdBreak = null;
2810
- this.savedMutedStateBeforeScte = null;
2769
+ this.savedMutedStateBeforeAd = null;
2811
2770
  this.consecutiveFailures = 0;
2812
2771
  this.maxConsecutiveFailures = 5;
2813
2772
  this.lastAdRequestTime = 0;
@@ -2820,7 +2779,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
2820
2779
  this.adRequestRetryBackoffMs = 1500;
2821
2780
  this.preloadedTokens = [];
2822
2781
  this.debugLogEntries = [];
2823
- this.scteMarkerHistory = [];
2782
+ this.adInsertionDebugHistory = [];
2824
2783
  initializePolyfills();
2825
2784
  var browserOverrides = getBrowserConfigOverrides();
2826
2785
  this.config = _object_spread({}, browserOverrides, config);
@@ -3005,6 +2964,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3005
2964
  _state.sent();
3006
2965
  _state.label = 2;
3007
2966
  case 2:
2967
+ if (!this.config.disableAds && this.config.projectId) {
2968
+ this.startAdInsertionPolling();
2969
+ }
3008
2970
  return [
3009
2971
  2
3010
2972
  ];
@@ -3012,78 +2974,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3012
2974
  });
3013
2975
  }).call(_this);
3014
2976
  });
3015
- this.hls.on(import_hls.default.Events.LEVEL_LOADED, function(_evt, data) {
2977
+ this.hls.on(import_hls.default.Events.LEVEL_LOADED, function() {
3016
2978
  if (_this.inAdBreak || _this.pendingAdBreak) {
3017
2979
  return;
3018
2980
  }
3019
- var details = data === null || data === void 0 ? void 0 : data.details;
3020
- if (!details || !details.fragments || details.fragments.length === 0) {
3021
- return;
3022
- }
3023
- var fragmentsToScan = Math.min(5, details.fragments.length);
3024
- for(var i = 0; i < fragmentsToScan; i++){
3025
- var frag = details.fragments[i];
3026
- var tagList = frag === null || frag === void 0 ? void 0 : frag.tagList;
3027
- if (!Array.isArray(tagList)) continue;
3028
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3029
- try {
3030
- for(var _iterator = tagList[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3031
- var entry = _step.value;
3032
- var tag = "";
3033
- var value = "";
3034
- if (Array.isArray(entry)) {
3035
- var _entry_, _entry_1;
3036
- tag = String((_entry_ = entry[0]) !== null && _entry_ !== void 0 ? _entry_ : "");
3037
- value = String((_entry_1 = entry[1]) !== null && _entry_1 !== void 0 ? _entry_1 : "");
3038
- } else if (typeof entry === "string") {
3039
- var idx = entry.indexOf(":");
3040
- if (idx >= 0) {
3041
- tag = entry.substring(0, idx);
3042
- value = entry.substring(idx + 1);
3043
- } else {
3044
- tag = entry;
3045
- }
3046
- }
3047
- if (!tag) continue;
3048
- if (tag.includes("EXT-X-CUE-OUT") || tag.includes("EXT-X-DATERANGE")) {
3049
- var attrs = tag.includes("EXT-X-DATERANGE") ? _this.parseAttributeList(value) : {};
3050
- var hasScteOut = tag.includes("EXT-X-CUE-OUT") || "SCTE35-OUT" in attrs || attrs["SCTE35-OUT"] !== void 0;
3051
- if (hasScteOut) {
3052
- var durationSeconds = _this.parseCueOutDuration(value);
3053
- var marker = _object_spread_props(_object_spread({
3054
- type: "start"
3055
- }, durationSeconds !== void 0 ? {
3056
- durationSeconds: durationSeconds
3057
- } : {}), {
3058
- raw: {
3059
- tag: tag,
3060
- value: value,
3061
- earlyDetection: true
3062
- }
3063
- });
3064
- if (_this.config.debugAdTiming) {
3065
- console.log("[StormcloudVideoPlayer] \uD83C\uDFAF EARLY SCTE-35 DETECTION: Ad break marker found in fragment", i, "- starting pre-fetch (NOT playing yet)");
3066
- }
3067
- _this.startAdPrefetch(marker, frag === null || frag === void 0 ? void 0 : frag.sn);
3068
- return;
3069
- }
3070
- }
3071
- }
3072
- } catch (err) {
3073
- _didIteratorError = true;
3074
- _iteratorError = err;
3075
- } finally{
3076
- try {
3077
- if (!_iteratorNormalCompletion && _iterator.return != null) {
3078
- _iterator.return();
3079
- }
3080
- } finally{
3081
- if (_didIteratorError) {
3082
- throw _iteratorError;
3083
- }
3084
- }
3085
- }
3086
- }
2981
+ _this.checkAdInsertionInManifest();
3087
2982
  });
3088
2983
  this.hls.on(import_hls.default.Events.FRAG_BUFFERED, function(_evt, data) {
3089
2984
  return _async_to_generator(function() {
@@ -3145,111 +3040,55 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3145
3040
  });
3146
3041
  }).call(_this);
3147
3042
  });
3148
- this.hls.on(import_hls.default.Events.FRAG_PARSING_METADATA, function(_evt, data) {
3149
- var id3Tags = ((data === null || data === void 0 ? void 0 : data.samples) || []).map(function(s) {
3150
- return {
3151
- key: "ID3",
3152
- value: s === null || s === void 0 ? void 0 : s.data,
3153
- ptsSeconds: s === null || s === void 0 ? void 0 : s.pts
3154
- };
3155
- });
3156
- id3Tags.forEach(function(tag) {
3157
- return _this.onId3Tag(tag);
3158
- });
3159
- });
3160
3043
  this.hls.on(import_hls.default.Events.FRAG_CHANGED, function(_evt, data) {
3161
3044
  var frag = data === null || data === void 0 ? void 0 : data.frag;
3162
- var tagList = frag === null || frag === void 0 ? void 0 : frag.tagList;
3163
- if (!Array.isArray(tagList)) return;
3164
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3165
- try {
3166
- for(var _iterator = tagList[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3167
- var entry = _step.value;
3168
- var tag = "";
3169
- var value = "";
3170
- if (Array.isArray(entry)) {
3171
- var _entry_, _entry_1;
3172
- tag = String((_entry_ = entry[0]) !== null && _entry_ !== void 0 ? _entry_ : "");
3173
- value = String((_entry_1 = entry[1]) !== null && _entry_1 !== void 0 ? _entry_1 : "");
3174
- } else if (typeof entry === "string") {
3175
- var idx = entry.indexOf(":");
3176
- if (idx >= 0) {
3177
- tag = entry.substring(0, idx);
3178
- value = entry.substring(idx + 1);
3179
- } else {
3180
- tag = entry;
3181
- value = "";
3182
- }
3045
+ if (!frag) return;
3046
+ if (_this.lastAdInsertionPoint && !_this.inAdBreak && _this.lastAdInsertionPoint.updated_at !== _this.processedAdInsertionUpdatedAt) {
3047
+ var segmentName = _this.lastAdInsertionPoint.segment_ts_name;
3048
+ if (_this.fragmentMatchesSegment(frag, segmentName)) {
3049
+ var _ref;
3050
+ _this.processedAdInsertionUpdatedAt = _this.lastAdInsertionPoint.updated_at;
3051
+ var offsetMs = (_this.lastAdInsertionPoint.offset_seconds || 0) * 1e3;
3052
+ _this.pushAdInsertionDebug("segment_playing", segmentName, {
3053
+ offsetSeconds: _this.lastAdInsertionPoint.offset_seconds,
3054
+ detail: "sn=".concat((_ref = frag === null || frag === void 0 ? void 0 : frag.sn) !== null && _ref !== void 0 ? _ref : "?")
3055
+ });
3056
+ if (_this.config.debugAdTiming) {
3057
+ console.log('[StormcloudVideoPlayer] Ad insertion segment "'.concat(segmentName, '" now playing — scheduling ad start in ').concat(offsetMs, "ms"));
3183
3058
  }
3184
- if (!tag) continue;
3185
- if (tag.includes("EXT-X-CUE-OUT-CONT")) {
3186
- var prog = _this.parseCueOutCont(value);
3187
- var marker = _object_spread_props(_object_spread({
3188
- type: "progress"
3189
- }, (prog === null || prog === void 0 ? void 0 : prog.duration) !== void 0 ? {
3190
- durationSeconds: prog.duration
3191
- } : {}, (prog === null || prog === void 0 ? void 0 : prog.elapsed) !== void 0 ? {
3192
- ptsSeconds: prog.elapsed
3193
- } : {}), {
3194
- raw: {
3195
- tag: tag,
3196
- value: value
3197
- }
3198
- });
3199
- _this.onScte35Marker(marker);
3200
- } else if (tag.includes("EXT-X-CUE-OUT")) {
3201
- var durationSeconds = _this.parseCueOutDuration(value);
3202
- var marker1 = _object_spread_props(_object_spread({
3203
- type: "start"
3204
- }, durationSeconds !== void 0 ? {
3205
- durationSeconds: durationSeconds
3206
- } : {}), {
3207
- raw: {
3208
- tag: tag,
3209
- value: value
3210
- }
3059
+ _this.pushAdInsertionDebug("ad_scheduled", segmentName, {
3060
+ offsetSeconds: _this.lastAdInsertionPoint.offset_seconds,
3061
+ detail: "in ".concat(offsetMs, "ms, dur=60s")
3062
+ });
3063
+ _this.clearAdInsertionOffsetTimer();
3064
+ _this.adInsertionOffsetTimerId = window.setTimeout(function() {
3065
+ _this.adInsertionOffsetTimerId = void 0;
3066
+ if (_this.inAdBreak) return;
3067
+ _this.pushAdInsertionDebug("ad_triggered", segmentName, {
3068
+ detail: "ad break started (60s)"
3211
3069
  });
3212
- _this.onScte35Marker(marker1);
3213
- } else if (tag.includes("EXT-X-CUE-IN")) {
3214
- _this.onScte35Marker({
3215
- type: "end",
3216
- raw: {
3217
- tag: tag,
3218
- value: value
3219
- }
3220
- });
3221
- } else if (tag.includes("EXT-X-DATERANGE")) {
3222
- var _attrs_CLASS;
3223
- var attrs = _this.parseAttributeList(value);
3224
- var hasScteOut = "SCTE35-OUT" in attrs || attrs["SCTE35-OUT"] !== void 0;
3225
- var hasScteIn = "SCTE35-IN" in attrs || attrs["SCTE35-IN"] !== void 0;
3226
- var klass = String((_attrs_CLASS = attrs["CLASS"]) !== null && _attrs_CLASS !== void 0 ? _attrs_CLASS : "");
3227
- var duration = _this.toNumber(attrs["DURATION"]);
3228
- if (hasScteOut || /com\.apple\.hls\.cue/i.test(klass)) {
3229
- var marker2 = _object_spread_props(_object_spread({
3230
- type: "start"
3231
- }, duration !== void 0 ? {
3232
- durationSeconds: duration
3233
- } : {}), {
3234
- raw: {
3235
- tag: tag,
3236
- value: value,
3237
- attrs: attrs
3238
- }
3239
- });
3240
- _this.onScte35Marker(marker2);
3241
- }
3242
- if (hasScteIn) {
3243
- _this.onScte35Marker({
3244
- type: "end",
3245
- raw: {
3246
- tag: tag,
3247
- value: value,
3248
- attrs: attrs
3249
- }
3250
- });
3251
- }
3252
- }
3070
+ void _this.handleAdStart(60);
3071
+ }, offsetMs);
3072
+ }
3073
+ }
3074
+ });
3075
+ this.hls.on(import_hls.default.Events.FRAG_PARSING_USERDATA, function(_evt, data) {
3076
+ var _ref;
3077
+ var samples = (_ref = data === null || data === void 0 ? void 0 : data.samples) !== null && _ref !== void 0 ? _ref : [];
3078
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3079
+ try {
3080
+ for(var _iterator = samples[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3081
+ var sample = _step.value;
3082
+ var _ref1, _ref2;
3083
+ var _data_frag, _data_frag1;
3084
+ var bytes = sample === null || sample === void 0 ? void 0 : sample.data;
3085
+ if (!bytes || bytes.length < 5) continue;
3086
+ var isSCTE35 = bytes[0] === 252;
3087
+ if (!isSCTE35) continue;
3088
+ var segName = (_ref1 = (_ref2 = data === null || data === void 0 ? void 0 : (_data_frag = data.frag) === null || _data_frag === void 0 ? void 0 : _data_frag.relurl) !== null && _ref2 !== void 0 ? _ref2 : data === null || data === void 0 ? void 0 : (_data_frag1 = data.frag) === null || _data_frag1 === void 0 ? void 0 : _data_frag1.url) !== null && _ref1 !== void 0 ? _ref1 : "";
3089
+ _this.pushAdInsertionDebug("scte35_inserted", segName, {
3090
+ detail: "len=".concat(bytes.length, "B")
3091
+ });
3253
3092
  }
3254
3093
  } catch (err) {
3255
3094
  _didIteratorError = true;
@@ -3340,8 +3179,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3340
3179
  _this.activeAdRequestToken = null;
3341
3180
  _this.showAds = true;
3342
3181
  if (_this.config.disableFiller) {
3343
- if (_this.savedMutedStateBeforeScte == null) {
3344
- _this.savedMutedStateBeforeScte = {
3182
+ if (_this.savedMutedStateBeforeAd == null) {
3183
+ _this.savedMutedStateBeforeAd = {
3345
3184
  muted: _this.video.muted,
3346
3185
  volume: _this.video.volume
3347
3186
  };
@@ -3369,10 +3208,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3369
3208
  });
3370
3209
  this.adLayer.on("content_resume", function() {
3371
3210
  var _ref, _ref1;
3372
- var _this_savedMutedStateBeforeScte, _this_savedMutedStateBeforeScte1;
3211
+ var _this_savedMutedStateBeforeAd, _this_savedMutedStateBeforeAd1;
3373
3212
  var remaining = _this.getRemainingAdMs();
3374
- var breakMuted = (_ref = (_this_savedMutedStateBeforeScte = _this.savedMutedStateBeforeScte) === null || _this_savedMutedStateBeforeScte === void 0 ? void 0 : _this_savedMutedStateBeforeScte.muted) !== null && _ref !== void 0 ? _ref : _this.adLayer.getOriginalMutedState();
3375
- var breakVolume = (_ref1 = (_this_savedMutedStateBeforeScte1 = _this.savedMutedStateBeforeScte) === null || _this_savedMutedStateBeforeScte1 === void 0 ? void 0 : _this_savedMutedStateBeforeScte1.volume) !== null && _ref1 !== void 0 ? _ref1 : _this.adLayer.getOriginalVolume();
3213
+ var breakMuted = (_ref = (_this_savedMutedStateBeforeAd = _this.savedMutedStateBeforeAd) === null || _this_savedMutedStateBeforeAd === void 0 ? void 0 : _this_savedMutedStateBeforeAd.muted) !== null && _ref !== void 0 ? _ref : _this.adLayer.getOriginalMutedState();
3214
+ var breakVolume = (_ref1 = (_this_savedMutedStateBeforeAd1 = _this.savedMutedStateBeforeAd) === null || _this_savedMutedStateBeforeAd1 === void 0 ? void 0 : _this_savedMutedStateBeforeAd1.volume) !== null && _ref1 !== void 0 ? _ref1 : _this.adLayer.getOriginalVolume();
3376
3215
  if (_this.config.debugAdTiming) {
3377
3216
  console.log("[StormcloudVideoPlayer] content_resume received, inAdBreak=%s, remaining=%s, preloadedTokens=%d, pendingNext=%s", _this.inAdBreak, remaining, _this.preloadedTokens.length, !!_this.pendingNextAdBids);
3378
3217
  }
@@ -3449,7 +3288,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3449
3288
  var remainingFinal = _this.getRemainingAdMs();
3450
3289
  if (_this.inAdBreak && remainingFinal > _this.MIN_AD_REMAINING_MS) {
3451
3290
  if (_this.config.debugAdTiming) {
3452
- console.log("[StormcloudVideoPlayer] content_resume: no more ads, showing filler for", remainingFinal, "ms");
3291
+ console.log("[StormcloudVideoPlayer] content_resume: ad ended/failed with time remaining, showing filler and continuing fetch for", remainingFinal, "ms");
3453
3292
  }
3454
3293
  if (!_this.config.disableFiller) {
3455
3294
  _this.showPlaceholderLayer();
@@ -3467,7 +3306,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3467
3306
  (_this_video_play = _this.video.play()) === null || _this_video_play === void 0 ? void 0 : _this_video_play.catch(function() {});
3468
3307
  }
3469
3308
  }
3470
- _this.stopContinuousFetching();
3309
+ _this.continuousFetchingActive = true;
3310
+ _this.startContinuousFetchLoop();
3471
3311
  return;
3472
3312
  }
3473
3313
  if (_this.config.debugAdTiming) {
@@ -3614,547 +3454,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3614
3454
  return !!(this.config.allowNativeHls && canNative);
3615
3455
  }
3616
3456
  },
3617
- {
3618
- key: "onId3Tag",
3619
- value: function onId3Tag(tag) {
3620
- if (typeof tag.ptsSeconds === "number") {
3621
- this.updatePtsDrift(tag.ptsSeconds);
3622
- }
3623
- var marker = this.parseScte35FromId3(tag);
3624
- if (marker) {
3625
- this.onScte35Marker(marker);
3626
- }
3627
- }
3628
- },
3629
- {
3630
- key: "parseScte35FromId3",
3631
- value: function parseScte35FromId3(tag) {
3632
- var text = this.decodeId3ValueToText(tag.value);
3633
- if (!text) return void 0;
3634
- var cueOutMatch = text.match(/EXT-X-CUE-OUT(?::([^\r\n]*))?/i) || text.match(/CUE-OUT(?::([^\r\n]*))?/i);
3635
- if (cueOutMatch) {
3636
- var _cueOutMatch_;
3637
- var arg = ((_cueOutMatch_ = cueOutMatch[1]) !== null && _cueOutMatch_ !== void 0 ? _cueOutMatch_ : "").trim();
3638
- var dur = this.parseCueOutDuration(arg);
3639
- var marker = _object_spread_props(_object_spread({
3640
- type: "start"
3641
- }, tag.ptsSeconds !== void 0 ? {
3642
- ptsSeconds: tag.ptsSeconds
3643
- } : {}, dur !== void 0 ? {
3644
- durationSeconds: dur
3645
- } : {}), {
3646
- raw: {
3647
- id3: text
3648
- }
3649
- });
3650
- return marker;
3651
- }
3652
- var cueOutContMatch = text.match(/EXT-X-CUE-OUT-CONT:([^\r\n]*)/i);
3653
- if (cueOutContMatch) {
3654
- var _cueOutContMatch_;
3655
- var arg1 = ((_cueOutContMatch_ = cueOutContMatch[1]) !== null && _cueOutContMatch_ !== void 0 ? _cueOutContMatch_ : "").trim();
3656
- var cont = this.parseCueOutCont(arg1);
3657
- var marker1 = _object_spread_props(_object_spread({
3658
- type: "progress"
3659
- }, tag.ptsSeconds !== void 0 ? {
3660
- ptsSeconds: tag.ptsSeconds
3661
- } : {}, (cont === null || cont === void 0 ? void 0 : cont.duration) !== void 0 ? {
3662
- durationSeconds: cont.duration
3663
- } : {}), {
3664
- raw: {
3665
- id3: text
3666
- }
3667
- });
3668
- return marker1;
3669
- }
3670
- var cueInMatch = text.match(/EXT-X-CUE-IN\b/i) || text.match(/CUE-IN\b/i);
3671
- if (cueInMatch) {
3672
- var marker2 = _object_spread_props(_object_spread({
3673
- type: "end"
3674
- }, tag.ptsSeconds !== void 0 ? {
3675
- ptsSeconds: tag.ptsSeconds
3676
- } : {}), {
3677
- raw: {
3678
- id3: text
3679
- }
3680
- });
3681
- return marker2;
3682
- }
3683
- var daterangeMatch = text.match(/EXT-X-DATERANGE:([^\r\n]*)/i);
3684
- if (daterangeMatch) {
3685
- var _daterangeMatch_, _attrs_CLASS;
3686
- var attrs = this.parseAttributeList((_daterangeMatch_ = daterangeMatch[1]) !== null && _daterangeMatch_ !== void 0 ? _daterangeMatch_ : "");
3687
- var hasScteOut = "SCTE35-OUT" in attrs || attrs["SCTE35-OUT"] !== void 0;
3688
- var hasScteIn = "SCTE35-IN" in attrs || attrs["SCTE35-IN"] !== void 0;
3689
- var klass = String((_attrs_CLASS = attrs["CLASS"]) !== null && _attrs_CLASS !== void 0 ? _attrs_CLASS : "");
3690
- var duration = this.toNumber(attrs["DURATION"]);
3691
- if (hasScteOut || /com\.apple\.hls\.cue/i.test(klass)) {
3692
- var marker3 = _object_spread_props(_object_spread({
3693
- type: "start"
3694
- }, tag.ptsSeconds !== void 0 ? {
3695
- ptsSeconds: tag.ptsSeconds
3696
- } : {}, duration !== void 0 ? {
3697
- durationSeconds: duration
3698
- } : {}), {
3699
- raw: {
3700
- id3: text,
3701
- attrs: attrs
3702
- }
3703
- });
3704
- return marker3;
3705
- }
3706
- if (hasScteIn) {
3707
- var marker4 = _object_spread_props(_object_spread({
3708
- type: "end"
3709
- }, tag.ptsSeconds !== void 0 ? {
3710
- ptsSeconds: tag.ptsSeconds
3711
- } : {}), {
3712
- raw: {
3713
- id3: text,
3714
- attrs: attrs
3715
- }
3716
- });
3717
- return marker4;
3718
- }
3719
- }
3720
- if (/SCTE35-OUT/i.test(text)) {
3721
- var marker5 = _object_spread_props(_object_spread({
3722
- type: "start"
3723
- }, tag.ptsSeconds !== void 0 ? {
3724
- ptsSeconds: tag.ptsSeconds
3725
- } : {}), {
3726
- raw: {
3727
- id3: text
3728
- }
3729
- });
3730
- return marker5;
3731
- }
3732
- if (/SCTE35-IN/i.test(text)) {
3733
- var marker6 = _object_spread_props(_object_spread({
3734
- type: "end"
3735
- }, tag.ptsSeconds !== void 0 ? {
3736
- ptsSeconds: tag.ptsSeconds
3737
- } : {}), {
3738
- raw: {
3739
- id3: text
3740
- }
3741
- });
3742
- return marker6;
3743
- }
3744
- if (_instanceof(tag.value, Uint8Array)) {
3745
- var bin = this.parseScte35Binary(tag.value);
3746
- if (bin) return bin;
3747
- }
3748
- return void 0;
3749
- }
3750
- },
3751
- {
3752
- key: "decodeId3ValueToText",
3753
- value: function decodeId3ValueToText(value) {
3754
- try {
3755
- if (typeof value === "string") return value;
3756
- var decoder = new TextDecoder("utf-8", {
3757
- fatal: false
3758
- });
3759
- var text = decoder.decode(value);
3760
- if (text && /[\x20-\x7E]/.test(text)) return text;
3761
- var out = "";
3762
- for(var i = 0; i < value.length; i++)out += String.fromCharCode(value[i]);
3763
- return out;
3764
- } catch (unused) {
3765
- return void 0;
3766
- }
3767
- }
3768
- },
3769
- {
3770
- key: "onScte35Marker",
3771
- value: function onScte35Marker(marker) {
3772
- var _this = this;
3773
- if (this.config.disableAds) return;
3774
- this.pushScteMarker(marker);
3775
- this.pushDebugLog("info", "scte35", "SCTE-35 marker detected", {
3776
- type: marker.type,
3777
- ptsSeconds: marker.ptsSeconds,
3778
- durationSeconds: marker.durationSeconds,
3779
- currentTime: this.video.currentTime
3780
- });
3781
- if (this.config.debugAdTiming) {
3782
- console.log("[StormcloudVideoPlayer] SCTE-35 marker detected:", {
3783
- type: marker.type,
3784
- ptsSeconds: marker.ptsSeconds,
3785
- durationSeconds: marker.durationSeconds,
3786
- currentTime: this.video.currentTime,
3787
- raw: marker.raw,
3788
- hasPendingAdBreak: !!this.pendingAdBreak
3789
- });
3790
- }
3791
- if (marker.type === "start") {
3792
- var _this_config_immediateManifestAds;
3793
- var _this_pendingAdBreak;
3794
- if (this.savedMutedStateBeforeScte == null) {
3795
- this.savedMutedStateBeforeScte = {
3796
- muted: this.video.muted,
3797
- volume: this.video.volume
3798
- };
3799
- this.adLayer.updateOriginalMutedState(this.video.muted, this.video.volume);
3800
- }
3801
- if (!this.config.disableFiller && !this.video.muted && !this.adLayer.isAdPlaying()) {
3802
- this.video.muted = true;
3803
- this.video.volume = 0;
3804
- if (this.config.debugAdTiming) {
3805
- console.log("[StormcloudVideoPlayer] Muted video on SCTE start marker");
3806
- }
3807
- }
3808
- if (this.inAdBreak) {
3809
- if (marker.durationSeconds != null) {
3810
- var newDurationMs = marker.durationSeconds * 1e3;
3811
- if (this.expectedAdBreakDurationMs == null || newDurationMs > this.expectedAdBreakDurationMs) {
3812
- this.expectedAdBreakDurationMs = newDurationMs;
3813
- var elapsedMs = this.currentAdBreakStartWallClockMs != null ? Date.now() - this.currentAdBreakStartWallClockMs : 0;
3814
- var remainingMs = Math.max(0, newDurationMs - elapsedMs);
3815
- this.scheduleAdStopCountdown(remainingMs);
3816
- if (this.config.debugAdTiming) {
3817
- console.log("[StormcloudVideoPlayer] Updated ad break duration from subsequent marker: ".concat(newDurationMs, "ms, remaining: ").concat(remainingMs, "ms"));
3818
- }
3819
- }
3820
- }
3821
- return;
3822
- }
3823
- this.inAdBreak = true;
3824
- var durationMs = marker.durationSeconds != null ? marker.durationSeconds * 1e3 : ((_this_pendingAdBreak = this.pendingAdBreak) === null || _this_pendingAdBreak === void 0 ? void 0 : _this_pendingAdBreak.marker.durationSeconds) != null ? this.pendingAdBreak.marker.durationSeconds * 1e3 : void 0;
3825
- this.expectedAdBreakDurationMs = durationMs;
3826
- this.currentAdBreakStartWallClockMs = Date.now();
3827
- if (this.config.licenseKey) {
3828
- var _this_pendingAdBreak1;
3829
- var adDetectInfo = _object_spread({
3830
- source: "scte35",
3831
- timestamp: /* @__PURE__ */ new Date().toISOString()
3832
- }, marker.durationSeconds != null && {
3833
- durationSeconds: marker.durationSeconds
3834
- }, marker.ptsSeconds != null && {
3835
- ptsSeconds: marker.ptsSeconds
3836
- }, ((_this_pendingAdBreak1 = this.pendingAdBreak) === null || _this_pendingAdBreak1 === void 0 ? void 0 : _this_pendingAdBreak1.detectedAtFragmentSn) != null && {
3837
- detectedAtFragmentSn: this.pendingAdBreak.detectedAtFragmentSn
3838
- });
3839
- sendAdDetectTracking(this.config.licenseKey, adDetectInfo);
3840
- }
3841
- var isManifestMarker = this.isManifestBasedMarker(marker);
3842
- var forceImmediate = (_this_config_immediateManifestAds = this.config.immediateManifestAds) !== null && _this_config_immediateManifestAds !== void 0 ? _this_config_immediateManifestAds : true;
3843
- if (this.config.debugAdTiming) {
3844
- console.log("[StormcloudVideoPlayer] Ad start decision:", {
3845
- isManifestMarker: isManifestMarker,
3846
- forceImmediate: forceImmediate,
3847
- hasPts: typeof marker.ptsSeconds === "number"
3848
- });
3849
- }
3850
- if (isManifestMarker && forceImmediate) {
3851
- if (this.config.debugAdTiming) {
3852
- console.log("[StormcloudVideoPlayer] Starting ad immediately (manifest-based)");
3853
- }
3854
- this.clearAdStartTimer();
3855
- this.handleAdStart(marker);
3856
- } else if (typeof marker.ptsSeconds === "number") {
3857
- var _this_config_driftToleranceMs;
3858
- var tol = (_this_config_driftToleranceMs = this.config.driftToleranceMs) !== null && _this_config_driftToleranceMs !== void 0 ? _this_config_driftToleranceMs : 1e3;
3859
- var nowMs = this.video.currentTime * 1e3;
3860
- var estCurrentPtsMs = nowMs - this.ptsDriftEmaMs;
3861
- var deltaMs = Math.floor(marker.ptsSeconds * 1e3 - estCurrentPtsMs);
3862
- if (this.config.debugAdTiming) {
3863
- console.log("[StormcloudVideoPlayer] PTS-based timing calculation:", {
3864
- nowMs: nowMs,
3865
- estCurrentPtsMs: estCurrentPtsMs,
3866
- markerPtsMs: marker.ptsSeconds * 1e3,
3867
- deltaMs: deltaMs,
3868
- tolerance: tol
3869
- });
3870
- }
3871
- if (deltaMs > tol) {
3872
- if (this.config.debugAdTiming) {
3873
- console.log("[StormcloudVideoPlayer] Scheduling ad start in ".concat(deltaMs, "ms"));
3874
- }
3875
- this.scheduleAdStartIn(deltaMs);
3876
- } else {
3877
- if (this.config.debugAdTiming) {
3878
- console.log("[StormcloudVideoPlayer] Starting ad immediately (within tolerance)");
3879
- }
3880
- this.clearAdStartTimer();
3881
- this.handleAdStart(marker);
3882
- }
3883
- } else {
3884
- if (this.config.debugAdTiming) {
3885
- console.log("[StormcloudVideoPlayer] Starting ad immediately (fallback)");
3886
- }
3887
- this.clearAdStartTimer();
3888
- this.handleAdStart(marker);
3889
- }
3890
- if (this.expectedAdBreakDurationMs != null) {
3891
- this.scheduleAdStopCountdown(this.expectedAdBreakDurationMs);
3892
- }
3893
- return;
3894
- }
3895
- if (marker.type === "progress" && this.inAdBreak) {
3896
- if (marker.durationSeconds != null) {
3897
- this.expectedAdBreakDurationMs = marker.durationSeconds * 1e3;
3898
- }
3899
- if (this.expectedAdBreakDurationMs != null && this.currentAdBreakStartWallClockMs != null) {
3900
- var elapsedMs1 = Date.now() - this.currentAdBreakStartWallClockMs;
3901
- var remainingMs1 = Math.max(0, this.expectedAdBreakDurationMs - elapsedMs1);
3902
- this.scheduleAdStopCountdown(remainingMs1);
3903
- }
3904
- if (!this.adLayer.isAdPlaying() && this.pendingNextAdBids != null && this.pendingNextAdBids.length > 0) {
3905
- var bids = this.pendingNextAdBids;
3906
- this.pendingNextAdBids = null;
3907
- this.currentAdIndex++;
3908
- this.adLayer.playAd(bids).catch(function() {
3909
- return _this.handleAdFailure();
3910
- });
3911
- }
3912
- return;
3913
- }
3914
- if (marker.type === "end") {
3915
- var remaining = this.getRemainingAdMs();
3916
- var adPlaying = this.adLayer.isAdPlaying();
3917
- var hasQueuedAds = this.pendingNextAdBids != null && this.pendingNextAdBids.length > 0;
3918
- if (this.config.debugAdTiming) {
3919
- console.log("[StormcloudVideoPlayer] SCTE-35 end marker received:", {
3920
- inAdBreak: this.inAdBreak,
3921
- remaining: remaining,
3922
- adPlaying: adPlaying,
3923
- hasQueuedAds: hasQueuedAds,
3924
- activeAdRequest: this.activeAdRequestToken !== null
3925
- });
3926
- }
3927
- if (!this.inAdBreak) {
3928
- if (this.config.debugAdTiming) {
3929
- console.log("[StormcloudVideoPlayer] Ignoring SCTE-35 end marker - not in ad break");
3930
- }
3931
- return;
3932
- }
3933
- if (adPlaying || remaining > 500) {
3934
- if (this.config.debugAdTiming) {
3935
- console.log("[StormcloudVideoPlayer] Ignoring premature SCTE-35 end marker - ads still active or time remaining");
3936
- }
3937
- return;
3938
- }
3939
- this.inAdBreak = false;
3940
- this.expectedAdBreakDurationMs = void 0;
3941
- this.currentAdBreakStartWallClockMs = void 0;
3942
- this.clearAdStartTimer();
3943
- this.clearAdStopTimer();
3944
- if (adPlaying) {
3945
- this.adLayer.stop().catch(function() {});
3946
- }
3947
- this.handleAdPodComplete();
3948
- return;
3949
- }
3950
- }
3951
- },
3952
- {
3953
- key: "parseCueOutDuration",
3954
- value: function parseCueOutDuration(value) {
3955
- var num = parseFloat(value.trim());
3956
- if (!Number.isNaN(num)) return num;
3957
- var match = value.match(/(?:^|[,\s])DURATION\s*=\s*([0-9.]+)/i) || value.match(/Duration\s*=\s*([0-9.]+)/i);
3958
- if (match && match[1] != null) {
3959
- var dStr = match[1];
3960
- var d = parseFloat(dStr);
3961
- return Number.isNaN(d) ? void 0 : d;
3962
- }
3963
- return void 0;
3964
- }
3965
- },
3966
- {
3967
- key: "parseCueOutCont",
3968
- value: function parseCueOutCont(value) {
3969
- var res = {};
3970
- var elapsedMatch = value.match(/Elapsed\s*=\s*([0-9.]+)/i);
3971
- var durationMatch = value.match(/Duration\s*=\s*([0-9.]+)/i);
3972
- if (elapsedMatch && elapsedMatch[1] != null) {
3973
- var e = parseFloat(elapsedMatch[1]);
3974
- if (!Number.isNaN(e)) res.elapsed = e;
3975
- }
3976
- if (durationMatch && durationMatch[1] != null) {
3977
- var d = parseFloat(durationMatch[1]);
3978
- if (!Number.isNaN(d)) res.duration = d;
3979
- }
3980
- if (!("elapsed" in res) || !("duration" in res)) {
3981
- var slashMatch = value.match(/([0-9.]+)\s*\/\s*([0-9.]+)/);
3982
- if (slashMatch && slashMatch[1] && slashMatch[2]) {
3983
- var elapsed = parseFloat(slashMatch[1]);
3984
- var duration = parseFloat(slashMatch[2]);
3985
- if (!Number.isNaN(elapsed) && !("elapsed" in res)) res.elapsed = elapsed;
3986
- if (!Number.isNaN(duration) && !("duration" in res)) res.duration = duration;
3987
- }
3988
- }
3989
- if ("elapsed" in res || "duration" in res) return res;
3990
- return void 0;
3991
- }
3992
- },
3993
- {
3994
- key: "parseAttributeList",
3995
- value: function parseAttributeList(value) {
3996
- var attrs = {};
3997
- var regex = /([A-Z0-9-]+)=(("[^"]*")|([^",]*))(?:,|$)/gi;
3998
- var match;
3999
- while((match = regex.exec(value)) !== null){
4000
- var _match_, _ref, _match_1;
4001
- var key = (_match_ = match[1]) !== null && _match_ !== void 0 ? _match_ : "";
4002
- var rawVal = (_ref = (_match_1 = match[3]) !== null && _match_1 !== void 0 ? _match_1 : match[4]) !== null && _ref !== void 0 ? _ref : "";
4003
- if (rawVal.startsWith('"') && rawVal.endsWith('"')) {
4004
- rawVal = rawVal.slice(1, -1);
4005
- }
4006
- if (key) {
4007
- attrs[key] = rawVal;
4008
- }
4009
- }
4010
- return attrs;
4011
- }
4012
- },
4013
- {
4014
- key: "toNumber",
4015
- value: function toNumber(val) {
4016
- if (val == null) return void 0;
4017
- var n = typeof val === "string" ? parseFloat(val) : Number(val);
4018
- return Number.isNaN(n) ? void 0 : n;
4019
- }
4020
- },
4021
- {
4022
- key: "isManifestBasedMarker",
4023
- value: function isManifestBasedMarker(marker) {
4024
- var raw = marker.raw;
4025
- if (!raw) return false;
4026
- if (raw.tag) {
4027
- var tag = String(raw.tag);
4028
- return tag.includes("EXT-X-CUE-OUT") || tag.includes("EXT-X-CUE-IN") || tag.includes("EXT-X-DATERANGE");
4029
- }
4030
- if (raw.id3) return false;
4031
- if (raw.splice_command_type) return false;
4032
- return false;
4033
- }
4034
- },
4035
- {
4036
- key: "parseScte35Binary",
4037
- value: function parseScte35Binary(data) {
4038
- var BitReader = /*#__PURE__*/ function() {
4039
- function BitReader(buf) {
4040
- _class_call_check(this, BitReader);
4041
- this.buf = buf;
4042
- this.bytePos = 0;
4043
- this.bitPos = 0;
4044
- }
4045
- _create_class(BitReader, [
4046
- {
4047
- key: "readBits",
4048
- value: function readBits(numBits) {
4049
- var result = 0;
4050
- while(numBits > 0){
4051
- if (this.bytePos >= this.buf.length) return result;
4052
- var remainingInByte = 8 - this.bitPos;
4053
- var toRead = Math.min(numBits, remainingInByte);
4054
- var currentByte = this.buf[this.bytePos];
4055
- var shift = remainingInByte - toRead;
4056
- var mask = (1 << toRead) - 1 & 255;
4057
- var bits = currentByte >> shift & mask;
4058
- result = result << toRead | bits;
4059
- this.bitPos += toRead;
4060
- if (this.bitPos >= 8) {
4061
- this.bitPos = 0;
4062
- this.bytePos += 1;
4063
- }
4064
- numBits -= toRead;
4065
- }
4066
- return result >>> 0;
4067
- }
4068
- },
4069
- {
4070
- key: "skipBits",
4071
- value: function skipBits(n) {
4072
- this.readBits(n);
4073
- }
4074
- }
4075
- ]);
4076
- return BitReader;
4077
- }();
4078
- var r = new BitReader(data);
4079
- var tableId = r.readBits(8);
4080
- if (tableId !== 252) return void 0;
4081
- r.readBits(1);
4082
- r.readBits(1);
4083
- r.readBits(2);
4084
- var sectionLength = r.readBits(12);
4085
- r.readBits(8);
4086
- r.readBits(1);
4087
- r.readBits(6);
4088
- var ptsAdjHigh = r.readBits(1);
4089
- var ptsAdjLow = r.readBits(32);
4090
- void ptsAdjHigh;
4091
- void ptsAdjLow;
4092
- r.readBits(8);
4093
- r.readBits(12);
4094
- var spliceCommandLength = r.readBits(12);
4095
- var spliceCommandType = r.readBits(8);
4096
- if (spliceCommandType !== 5) {
4097
- return void 0;
4098
- }
4099
- r.readBits(32);
4100
- var cancel = r.readBits(1) === 1;
4101
- r.readBits(7);
4102
- if (cancel) return void 0;
4103
- var outOfNetwork = r.readBits(1) === 1;
4104
- var programSpliceFlag = r.readBits(1) === 1;
4105
- var durationFlag = r.readBits(1) === 1;
4106
- var spliceImmediateFlag = r.readBits(1) === 1;
4107
- r.readBits(4);
4108
- if (programSpliceFlag && !spliceImmediateFlag) {
4109
- var timeSpecifiedFlag = r.readBits(1) === 1;
4110
- if (timeSpecifiedFlag) {
4111
- r.readBits(6);
4112
- r.readBits(33);
4113
- } else {
4114
- r.readBits(7);
4115
- }
4116
- } else if (!programSpliceFlag) {
4117
- var componentCount = r.readBits(8);
4118
- for(var i = 0; i < componentCount; i++){
4119
- r.readBits(8);
4120
- if (!spliceImmediateFlag) {
4121
- var timeSpecifiedFlag1 = r.readBits(1) === 1;
4122
- if (timeSpecifiedFlag1) {
4123
- r.readBits(6);
4124
- r.readBits(33);
4125
- } else {
4126
- r.readBits(7);
4127
- }
4128
- }
4129
- }
4130
- }
4131
- var durationSeconds = void 0;
4132
- if (durationFlag) {
4133
- r.readBits(6);
4134
- r.readBits(1);
4135
- var high = r.readBits(1);
4136
- var low = r.readBits(32);
4137
- var durationTicks = high * 4294967296 + low;
4138
- durationSeconds = durationTicks / 9e4;
4139
- }
4140
- r.readBits(16);
4141
- r.readBits(8);
4142
- r.readBits(8);
4143
- if (outOfNetwork) {
4144
- var marker = _object_spread_props(_object_spread({
4145
- type: "start"
4146
- }, durationSeconds !== void 0 ? {
4147
- durationSeconds: durationSeconds
4148
- } : {}), {
4149
- raw: {
4150
- splice_command_type: 5
4151
- }
4152
- });
4153
- return marker;
4154
- }
4155
- return void 0;
4156
- }
4157
- },
4158
3457
  {
4159
3458
  key: "initializeTracking",
4160
3459
  value: function initializeTracking() {
@@ -4276,35 +3575,35 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4276
3575
  },
4277
3576
  {
4278
3577
  key: "startAdPrefetch",
4279
- value: function startAdPrefetch(marker, fragmentSn) {
3578
+ value: function startAdPrefetch(durationSeconds, fragmentSn) {
4280
3579
  if (this.config.disableAds) return;
4281
3580
  if (this.pendingAdBreak || this.inAdBreak) {
4282
3581
  return;
4283
3582
  }
4284
- this.pendingAdBreak = _object_spread_props(_object_spread({
4285
- marker: marker
4286
- }, fragmentSn !== void 0 ? {
3583
+ this.pendingAdBreak = _object_spread_props(_object_spread({}, durationSeconds !== void 0 ? {
3584
+ durationSeconds: durationSeconds
3585
+ } : {}, fragmentSn !== void 0 ? {
4287
3586
  detectedAtFragmentSn: fragmentSn
4288
3587
  } : {}), {
4289
3588
  isFetching: false,
4290
3589
  fetchStartTime: Date.now()
4291
3590
  });
4292
- void this.runAdPrefetch(marker);
3591
+ void this.runAdPrefetch(durationSeconds);
4293
3592
  if (this.config.debugAdTiming) {
4294
- console.log("[PREFETCH] Ad break marker registered, multi-ad prefetch started");
3593
+ console.log("[PREFETCH] Ad break registered, multi-ad prefetch started");
4295
3594
  }
4296
3595
  }
4297
3596
  },
4298
3597
  {
4299
3598
  key: "runAdPrefetch",
4300
- value: function runAdPrefetch(marker) {
3599
+ value: function runAdPrefetch(durationSeconds) {
4301
3600
  return _async_to_generator(function() {
4302
- var _this, _marker_durationSeconds, _ref, _firstBids_, durSec, context, firstBids, unused, adDurationSec, estimatedCount, firstToken, remaining, results, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, result, token;
3601
+ var _this, _ref, _firstBids_, durSec, context, firstBids, unused, adDurationSec, estimatedCount, firstToken, unused1, remaining, results, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, result, token, unused2, err;
4303
3602
  return _ts_generator(this, function(_state) {
4304
3603
  switch(_state.label){
4305
3604
  case 0:
4306
3605
  _this = this;
4307
- durSec = (_marker_durationSeconds = marker.durationSeconds) !== null && _marker_durationSeconds !== void 0 ? _marker_durationSeconds : 60;
3606
+ durSec = durationSeconds !== null && durationSeconds !== void 0 ? durationSeconds : 60;
4308
3607
  context = {
4309
3608
  breakDurationSec: durSec,
4310
3609
  remainingBreakSec: durSec
@@ -4354,14 +3653,43 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4354
3653
  console.log("[PREFETCH] Ad duration=".concat(adDurationSec, "s, break=").concat(durSec, "s → ").concat(estimatedCount, " ad(s) needed"));
4355
3654
  }
4356
3655
  firstToken = "preload_".concat(Date.now(), "_").concat(Math.random().toString(36).slice(2, 7));
4357
- this.preloadedTokens.push(firstToken);
4358
- void this.adLayer.preloadAd(firstBids, firstToken);
3656
+ _state.label = 5;
3657
+ case 5:
3658
+ _state.trys.push([
3659
+ 5,
3660
+ 7,
3661
+ ,
3662
+ 8
3663
+ ]);
3664
+ return [
3665
+ 4,
3666
+ this.adLayer.preloadAd(firstBids, firstToken)
3667
+ ];
3668
+ case 6:
3669
+ _state.sent();
3670
+ if (!this.inAdBreak) {
3671
+ this.preloadedTokens.push(firstToken);
3672
+ if (this.config.debugAdTiming) {
3673
+ console.log("[PREFETCH] First ad preloaded and queued, token=".concat(firstToken));
3674
+ }
3675
+ }
3676
+ return [
3677
+ 3,
3678
+ 8
3679
+ ];
3680
+ case 7:
3681
+ unused1 = _state.sent();
4359
3682
  if (this.config.debugAdTiming) {
4360
- console.log("[PREFETCH] First ad preloading, token=".concat(firstToken));
3683
+ console.warn("[PREFETCH] First ad preload failed, token=".concat(firstToken));
4361
3684
  }
3685
+ return [
3686
+ 3,
3687
+ 8
3688
+ ];
3689
+ case 8:
4362
3690
  if (!(estimatedCount > 1)) return [
4363
3691
  3,
4364
- 6
3692
+ 19
4365
3693
  ];
4366
3694
  remaining = Array.from({
4367
3695
  length: estimatedCount - 1
@@ -4383,38 +3711,100 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4383
3711
  4,
4384
3712
  Promise.all(remaining)
4385
3713
  ];
4386
- case 5:
3714
+ case 9:
4387
3715
  results = _state.sent();
4388
3716
  _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3717
+ _state.label = 10;
3718
+ case 10:
3719
+ _state.trys.push([
3720
+ 10,
3721
+ 17,
3722
+ 18,
3723
+ 19
3724
+ ]);
3725
+ _iterator = results[Symbol.iterator]();
3726
+ _state.label = 11;
3727
+ case 11:
3728
+ if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
3729
+ 3,
3730
+ 16
3731
+ ];
3732
+ result = _step.value;
3733
+ if (this.inAdBreak) return [
3734
+ 3,
3735
+ 16
3736
+ ];
3737
+ if (!(result.ok && result.value.length > 0)) return [
3738
+ 3,
3739
+ 15
3740
+ ];
3741
+ token = "preload_".concat(Date.now(), "_").concat(Math.random().toString(36).slice(2, 7));
3742
+ _state.label = 12;
3743
+ case 12:
3744
+ _state.trys.push([
3745
+ 12,
3746
+ 14,
3747
+ ,
3748
+ 15
3749
+ ]);
3750
+ return [
3751
+ 4,
3752
+ this.adLayer.preloadAd(result.value, token)
3753
+ ];
3754
+ case 13:
3755
+ _state.sent();
3756
+ if (!this.inAdBreak) {
3757
+ this.preloadedTokens.push(token);
3758
+ if (this.config.debugAdTiming) {
3759
+ console.log("[PREFETCH] Additional ad preloaded and queued, token=".concat(token));
3760
+ }
3761
+ }
3762
+ return [
3763
+ 3,
3764
+ 15
3765
+ ];
3766
+ case 14:
3767
+ unused2 = _state.sent();
3768
+ if (this.config.debugAdTiming) {
3769
+ console.warn("[PREFETCH] Additional ad preload failed, token=".concat(token));
3770
+ }
3771
+ return [
3772
+ 3,
3773
+ 15
3774
+ ];
3775
+ case 15:
3776
+ _iteratorNormalCompletion = true;
3777
+ return [
3778
+ 3,
3779
+ 11
3780
+ ];
3781
+ case 16:
3782
+ return [
3783
+ 3,
3784
+ 19
3785
+ ];
3786
+ case 17:
3787
+ err = _state.sent();
3788
+ _didIteratorError = true;
3789
+ _iteratorError = err;
3790
+ return [
3791
+ 3,
3792
+ 19
3793
+ ];
3794
+ case 18:
4389
3795
  try {
4390
- for(_iterator = results[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
4391
- result = _step.value;
4392
- if (this.inAdBreak) break;
4393
- if (result.ok && result.value.length > 0) {
4394
- token = "preload_".concat(Date.now(), "_").concat(Math.random().toString(36).slice(2, 7));
4395
- this.preloadedTokens.push(token);
4396
- void this.adLayer.preloadAd(result.value, token);
4397
- if (this.config.debugAdTiming) {
4398
- console.log("[PREFETCH] Additional ad preloading, token=".concat(token));
4399
- }
4400
- }
3796
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
3797
+ _iterator.return();
4401
3798
  }
4402
- } catch (err) {
4403
- _didIteratorError = true;
4404
- _iteratorError = err;
4405
3799
  } finally{
4406
- try {
4407
- if (!_iteratorNormalCompletion && _iterator.return != null) {
4408
- _iterator.return();
4409
- }
4410
- } finally{
4411
- if (_didIteratorError) {
4412
- throw _iteratorError;
4413
- }
3800
+ if (_didIteratorError) {
3801
+ throw _iteratorError;
4414
3802
  }
4415
3803
  }
4416
- _state.label = 6;
4417
- case 6:
3804
+ return [
3805
+ 7
3806
+ ];
3807
+ case 19:
4418
3808
  if (this.config.debugAdTiming) {
4419
3809
  console.log("[PREFETCH] Pre-fetch complete: ".concat(this.preloadedTokens.length, " ad(s) queued"));
4420
3810
  }
@@ -4462,6 +3852,177 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4462
3852
  this.preloadedTokens = [];
4463
3853
  }
4464
3854
  },
3855
+ {
3856
+ key: "startAdInsertionPolling",
3857
+ value: function startAdInsertionPolling() {
3858
+ var _this = this;
3859
+ if (this.adInsertionPollingId != null) return;
3860
+ this.fetchAdInsertionPoint();
3861
+ this.adInsertionPollingId = window.setInterval(function() {
3862
+ _this.fetchAdInsertionPoint();
3863
+ }, 1e3);
3864
+ }
3865
+ },
3866
+ {
3867
+ key: "stopAdInsertionPolling",
3868
+ value: function stopAdInsertionPolling() {
3869
+ if (this.adInsertionPollingId != null) {
3870
+ clearInterval(this.adInsertionPollingId);
3871
+ this.adInsertionPollingId = void 0;
3872
+ }
3873
+ }
3874
+ },
3875
+ {
3876
+ key: "fetchAdInsertionPoint",
3877
+ value: function fetchAdInsertionPoint() {
3878
+ return _async_to_generator(function() {
3879
+ var _this_lastAdInsertionPoint, resp, data, isNew, unused;
3880
+ return _ts_generator(this, function(_state) {
3881
+ switch(_state.label){
3882
+ case 0:
3883
+ if (!this.config.projectId) return [
3884
+ 2
3885
+ ];
3886
+ _state.label = 1;
3887
+ case 1:
3888
+ _state.trys.push([
3889
+ 1,
3890
+ 4,
3891
+ ,
3892
+ 5
3893
+ ]);
3894
+ return [
3895
+ 4,
3896
+ fetch("https://adstorm.co/api-adstorm-dev/adstorm/swirl/projects/".concat(encodeURIComponent(this.config.projectId), "/ad-insertion-point"))
3897
+ ];
3898
+ case 2:
3899
+ resp = _state.sent();
3900
+ if (!resp.ok) return [
3901
+ 2
3902
+ ];
3903
+ return [
3904
+ 4,
3905
+ resp.json()
3906
+ ];
3907
+ case 3:
3908
+ data = _state.sent();
3909
+ isNew = data.updated_at !== ((_this_lastAdInsertionPoint = this.lastAdInsertionPoint) === null || _this_lastAdInsertionPoint === void 0 ? void 0 : _this_lastAdInsertionPoint.updated_at);
3910
+ this.lastAdInsertionPoint = data;
3911
+ if (isNew) {
3912
+ this.pushAdInsertionDebug("api_response", data.segment_ts_name, {
3913
+ offsetSeconds: data.offset_seconds,
3914
+ updatedAt: data.updated_at,
3915
+ detail: "project=".concat(data.project_id)
3916
+ });
3917
+ }
3918
+ if (this.config.debugAdTiming) {
3919
+ console.log("[StormcloudVideoPlayer] Ad insertion point API response:", data);
3920
+ }
3921
+ return [
3922
+ 3,
3923
+ 5
3924
+ ];
3925
+ case 4:
3926
+ unused = _state.sent();
3927
+ if (this.config.debugAdTiming) {
3928
+ console.warn("[StormcloudVideoPlayer] Ad insertion point API fetch failed");
3929
+ }
3930
+ return [
3931
+ 3,
3932
+ 5
3933
+ ];
3934
+ case 5:
3935
+ return [
3936
+ 2
3937
+ ];
3938
+ }
3939
+ });
3940
+ }).call(this);
3941
+ }
3942
+ },
3943
+ {
3944
+ key: "checkAdInsertionInManifest",
3945
+ value: function checkAdInsertionInManifest() {
3946
+ var _this_hls;
3947
+ if (!this.lastAdInsertionPoint) return;
3948
+ if (this.inAdBreak || this.pendingAdBreak) return;
3949
+ if (this.lastAdInsertionPoint.updated_at === this.processedAdInsertionUpdatedAt) return;
3950
+ var segmentName = this.lastAdInsertionPoint.segment_ts_name;
3951
+ var levels = (_this_hls = this.hls) === null || _this_hls === void 0 ? void 0 : _this_hls.levels;
3952
+ if (!levels) return;
3953
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3954
+ try {
3955
+ for(var _iterator = levels[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3956
+ var level = _step.value;
3957
+ var _level_details;
3958
+ var fragments = (_level_details = level.details) === null || _level_details === void 0 ? void 0 : _level_details.fragments;
3959
+ if (!Array.isArray(fragments)) continue;
3960
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
3961
+ try {
3962
+ for(var _iterator1 = fragments[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
3963
+ var frag = _step1.value;
3964
+ if (this.fragmentMatchesSegment(frag, segmentName)) {
3965
+ var _ref;
3966
+ this.pushAdInsertionDebug("segment_found", segmentName, {
3967
+ detail: "sn=".concat((_ref = frag === null || frag === void 0 ? void 0 : frag.sn) !== null && _ref !== void 0 ? _ref : "?")
3968
+ });
3969
+ if (this.config.debugAdTiming) {
3970
+ console.log('[StormcloudVideoPlayer] Ad insertion segment "'.concat(segmentName, '" found in manifest — starting pre-fetch'));
3971
+ }
3972
+ this.startAdPrefetch(60, frag === null || frag === void 0 ? void 0 : frag.sn);
3973
+ return;
3974
+ }
3975
+ }
3976
+ } catch (err) {
3977
+ _didIteratorError1 = true;
3978
+ _iteratorError1 = err;
3979
+ } finally{
3980
+ try {
3981
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
3982
+ _iterator1.return();
3983
+ }
3984
+ } finally{
3985
+ if (_didIteratorError1) {
3986
+ throw _iteratorError1;
3987
+ }
3988
+ }
3989
+ }
3990
+ }
3991
+ } catch (err) {
3992
+ _didIteratorError = true;
3993
+ _iteratorError = err;
3994
+ } finally{
3995
+ try {
3996
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
3997
+ _iterator.return();
3998
+ }
3999
+ } finally{
4000
+ if (_didIteratorError) {
4001
+ throw _iteratorError;
4002
+ }
4003
+ }
4004
+ }
4005
+ }
4006
+ },
4007
+ {
4008
+ key: "fragmentMatchesSegment",
4009
+ value: function fragmentMatchesSegment(frag, segmentName) {
4010
+ var _rawUrl_split_;
4011
+ var rawUrl = (frag === null || frag === void 0 ? void 0 : frag.url) || (frag === null || frag === void 0 ? void 0 : frag.relurl) || "";
4012
+ var url = (_rawUrl_split_ = rawUrl.split("?")[0]) !== null && _rawUrl_split_ !== void 0 ? _rawUrl_split_ : "";
4013
+ var name = segmentName.startsWith("/") ? segmentName : "/" + segmentName;
4014
+ return url.endsWith(name) || url.includes(name);
4015
+ }
4016
+ },
4017
+ {
4018
+ key: "clearAdInsertionOffsetTimer",
4019
+ value: function clearAdInsertionOffsetTimer() {
4020
+ if (this.adInsertionOffsetTimerId != null) {
4021
+ clearTimeout(this.adInsertionOffsetTimerId);
4022
+ this.adInsertionOffsetTimerId = void 0;
4023
+ }
4024
+ }
4025
+ },
4465
4026
  {
4466
4027
  key: "startContinuousFetchLoop",
4467
4028
  value: function startContinuousFetchLoop() {
@@ -4787,13 +4348,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4787
4348
  },
4788
4349
  {
4789
4350
  key: "handleAdStart",
4790
- value: function handleAdStart(_marker) {
4351
+ value: function handleAdStart(durationSeconds) {
4791
4352
  return _async_to_generator(function() {
4792
- var _this_savedMutedStateBeforeScte, adBreakDurationMs, mode, state, adBreakToken, adVolume, token, remaining, err;
4353
+ var _this_savedMutedStateBeforeAd, adBreakDurationMs, mode, state, adBreakToken, adVolume, token, remaining, err;
4793
4354
  return _ts_generator(this, function(_state) {
4794
4355
  switch(_state.label){
4795
4356
  case 0:
4796
- adBreakDurationMs = _marker.durationSeconds != null ? _marker.durationSeconds * 1e3 : void 0;
4357
+ adBreakDurationMs = durationSeconds != null ? durationSeconds * 1e3 : void 0;
4797
4358
  if (this.config.debugAdTiming) {
4798
4359
  mode = this.isLiveStream ? "LIVE" : "VOD";
4799
4360
  console.log("[CONTINUOUS-FETCH] \uD83D\uDCFA ".concat(mode, " MODE: Target duration=").concat(adBreakDurationMs, "ms"));
@@ -4804,13 +4365,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4804
4365
  this.pendingNextAdBids = null;
4805
4366
  this.isShowingPlaceholder = false;
4806
4367
  this.totalAdRequestsInBreak = 0;
4807
- if (this.savedMutedStateBeforeScte == null && !this.video.muted) {
4808
- this.savedMutedStateBeforeScte = {
4368
+ if (this.savedMutedStateBeforeAd == null && !this.video.muted) {
4369
+ this.savedMutedStateBeforeAd = {
4809
4370
  muted: false,
4810
4371
  volume: this.video.volume
4811
4372
  };
4812
4373
  }
4813
- state = (_this_savedMutedStateBeforeScte = this.savedMutedStateBeforeScte) !== null && _this_savedMutedStateBeforeScte !== void 0 ? _this_savedMutedStateBeforeScte : {
4374
+ state = (_this_savedMutedStateBeforeAd = this.savedMutedStateBeforeAd) !== null && _this_savedMutedStateBeforeAd !== void 0 ? _this_savedMutedStateBeforeAd : {
4814
4375
  muted: this.video.muted,
4815
4376
  volume: this.video.volume
4816
4377
  };
@@ -4837,6 +4398,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4837
4398
  if (this.expectedAdBreakDurationMs == null && adBreakDurationMs != null) {
4838
4399
  this.expectedAdBreakDurationMs = adBreakDurationMs;
4839
4400
  }
4401
+ if (this.expectedAdBreakDurationMs != null) {
4402
+ this.scheduleAdStopCountdown(this.expectedAdBreakDurationMs);
4403
+ }
4840
4404
  this.clearPendingAdBreak();
4841
4405
  adBreakToken = Date.now();
4842
4406
  this.activeAdRequestToken = adBreakToken;
@@ -5335,54 +4899,18 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5335
4899
  this.handleAdPodComplete();
5336
4900
  }
5337
4901
  },
5338
- {
5339
- key: "scheduleAdStartIn",
5340
- value: function scheduleAdStartIn(delayMs) {
5341
- var _this = this;
5342
- this.clearAdStartTimer();
5343
- var ms = Math.max(0, Math.floor(delayMs));
5344
- if (ms === 0) {
5345
- this.handleAdStart({
5346
- type: "start"
5347
- }).catch(function() {});
5348
- return;
5349
- }
5350
- this.adStartTimerId = window.setTimeout(function() {
5351
- _this.handleAdStart({
5352
- type: "start"
5353
- }).catch(function() {});
5354
- }, ms);
5355
- }
5356
- },
5357
- {
5358
- key: "clearAdStartTimer",
5359
- value: function clearAdStartTimer() {
5360
- if (this.adStartTimerId != null) {
5361
- clearTimeout(this.adStartTimerId);
5362
- this.adStartTimerId = void 0;
5363
- }
5364
- }
5365
- },
5366
- {
5367
- key: "updatePtsDrift",
5368
- value: function updatePtsDrift(ptsSecondsSample) {
5369
- var sampleMs = (this.video.currentTime - ptsSecondsSample) * 1e3;
5370
- if (!Number.isFinite(sampleMs) || Math.abs(sampleMs) > 6e4) return;
5371
- var alpha = 0.1;
5372
- this.ptsDriftEmaMs = this.ptsDriftEmaMs * (1 - alpha) + sampleMs * alpha;
5373
- }
5374
- },
5375
4902
  {
5376
4903
  key: "handleAdPodComplete",
5377
4904
  value: function handleAdPodComplete() {
5378
4905
  var _this = this;
5379
4906
  var _ref, _ref1;
5380
- var _this_savedMutedStateBeforeScte, _this_savedMutedStateBeforeScte1;
4907
+ var _this_savedMutedStateBeforeAd, _this_savedMutedStateBeforeAd1;
5381
4908
  if (this.config.debugAdTiming) {
5382
4909
  console.log("[StormcloudVideoPlayer] \uD83C\uDFC1 Ad pod complete - cleaning up");
5383
4910
  }
5384
4911
  this.clearAdRequestWatchdog();
5385
4912
  this.clearAdFailsafeTimer();
4913
+ this.clearAdInsertionOffsetTimer();
5386
4914
  this.activeAdRequestToken = null;
5387
4915
  this.isInAdTransition = false;
5388
4916
  this.stopContinuousFetching();
@@ -5398,7 +4926,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5398
4926
  this.inAdBreak = false;
5399
4927
  this.expectedAdBreakDurationMs = void 0;
5400
4928
  this.currentAdBreakStartWallClockMs = void 0;
5401
- this.clearAdStartTimer();
5402
4929
  this.clearAdStopTimer();
5403
4930
  this.adPodQueue = [];
5404
4931
  this.showAds = false;
@@ -5406,8 +4933,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5406
4933
  this.totalAdsInBreak = 0;
5407
4934
  this.totalAdRequestsInBreak = 0;
5408
4935
  this.consecutiveFailures = 0;
5409
- var restoredMuted = (_ref = (_this_savedMutedStateBeforeScte = this.savedMutedStateBeforeScte) === null || _this_savedMutedStateBeforeScte === void 0 ? void 0 : _this_savedMutedStateBeforeScte.muted) !== null && _ref !== void 0 ? _ref : this.adLayer.getOriginalMutedState();
5410
- var restoredVolume = (_ref1 = (_this_savedMutedStateBeforeScte1 = this.savedMutedStateBeforeScte) === null || _this_savedMutedStateBeforeScte1 === void 0 ? void 0 : _this_savedMutedStateBeforeScte1.volume) !== null && _ref1 !== void 0 ? _ref1 : this.adLayer.getOriginalVolume();
4936
+ var restoredMuted = (_ref = (_this_savedMutedStateBeforeAd = this.savedMutedStateBeforeAd) === null || _this_savedMutedStateBeforeAd === void 0 ? void 0 : _this_savedMutedStateBeforeAd.muted) !== null && _ref !== void 0 ? _ref : this.adLayer.getOriginalMutedState();
4937
+ var restoredVolume = (_ref1 = (_this_savedMutedStateBeforeAd1 = this.savedMutedStateBeforeAd) === null || _this_savedMutedStateBeforeAd1 === void 0 ? void 0 : _this_savedMutedStateBeforeAd1.volume) !== null && _ref1 !== void 0 ? _ref1 : this.adLayer.getOriginalVolume();
5411
4938
  this.adLayer.updateOriginalMutedState(restoredMuted, restoredVolume);
5412
4939
  this.adLayer.stop().catch(function() {});
5413
4940
  if (this.video.muted !== restoredMuted) {
@@ -5516,7 +5043,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5516
5043
  }, delay);
5517
5044
  });
5518
5045
  }
5519
- this.savedMutedStateBeforeScte = null;
5046
+ this.savedMutedStateBeforeAd = null;
5520
5047
  }
5521
5048
  },
5522
5049
  {
@@ -5666,19 +5193,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5666
5193
  return Math.max(0, this.expectedAdBreakDurationMs - elapsed);
5667
5194
  }
5668
5195
  },
5669
- {
5670
- key: "pushScteMarker",
5671
- value: function pushScteMarker(marker) {
5672
- if (!this.config.debugAdTiming) return;
5673
- this.scteMarkerHistory.push({
5674
- timestampMs: Date.now(),
5675
- marker: marker
5676
- });
5677
- if (this.scteMarkerHistory.length > DEBUG_HISTORY_LIMIT) {
5678
- this.scteMarkerHistory = this.scteMarkerHistory.slice(-DEBUG_HISTORY_LIMIT);
5679
- }
5680
- }
5681
- },
5682
5196
  {
5683
5197
  key: "pushDebugLog",
5684
5198
  value: function pushDebugLog(level, category, message, details) {
@@ -5697,20 +5211,29 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5697
5211
  }
5698
5212
  },
5699
5213
  {
5700
- key: "getRecentScteMarkers",
5701
- value: function getRecentScteMarkers() {
5702
- return this.scteMarkerHistory.map(function(entry) {
5703
- return _object_spread({
5704
- timestampMs: entry.timestampMs,
5705
- type: entry.marker.type
5706
- }, entry.marker.ptsSeconds !== void 0 ? {
5707
- ptsSeconds: entry.marker.ptsSeconds
5708
- } : {}, entry.marker.durationSeconds !== void 0 ? {
5709
- durationSeconds: entry.marker.durationSeconds
5710
- } : {}, entry.marker.raw !== void 0 ? {
5711
- raw: entry.marker.raw
5712
- } : {});
5713
- });
5214
+ key: "pushAdInsertionDebug",
5215
+ value: function pushAdInsertionDebug(event, segmentName, opts) {
5216
+ if (!this.config.debugAdTiming) return;
5217
+ this.adInsertionDebugHistory.push(_object_spread({
5218
+ timestampMs: Date.now(),
5219
+ event: event,
5220
+ segmentName: segmentName
5221
+ }, (opts === null || opts === void 0 ? void 0 : opts.offsetSeconds) !== void 0 ? {
5222
+ offsetSeconds: opts.offsetSeconds
5223
+ } : {}, (opts === null || opts === void 0 ? void 0 : opts.updatedAt) ? {
5224
+ updatedAt: opts.updatedAt
5225
+ } : {}, (opts === null || opts === void 0 ? void 0 : opts.detail) ? {
5226
+ detail: opts.detail
5227
+ } : {}));
5228
+ if (this.adInsertionDebugHistory.length > DEBUG_HISTORY_LIMIT) {
5229
+ this.adInsertionDebugHistory = this.adInsertionDebugHistory.slice(-DEBUG_HISTORY_LIMIT);
5230
+ }
5231
+ }
5232
+ },
5233
+ {
5234
+ key: "getAdInsertionDebugLog",
5235
+ value: function getAdInsertionDebugLog() {
5236
+ return this.adInsertionDebugHistory.slice();
5714
5237
  }
5715
5238
  },
5716
5239
  {
@@ -5979,9 +5502,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5979
5502
  key: "destroy",
5980
5503
  value: function destroy() {
5981
5504
  var _this_hls, _this_adLayer;
5505
+ this.stopAdInsertionPolling();
5506
+ this.clearAdInsertionOffsetTimer();
5982
5507
  this.stopContinuousFetching();
5983
5508
  this.stopFillerBreakTimer();
5984
- this.clearAdStartTimer();
5985
5509
  this.clearAdStopTimer();
5986
5510
  this.clearAdFailsafeTimer();
5987
5511
  this.clearAdRequestWatchdog();
@@ -6009,7 +5533,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6009
5533
  (_this_adLayer = this.adLayer) === null || _this_adLayer === void 0 ? void 0 : _this_adLayer.destroy();
6010
5534
  this.consecutiveFailures = 0;
6011
5535
  this.debugLogEntries = [];
6012
- this.scteMarkerHistory = [];
5536
+ this.adInsertionDebugHistory = [];
6013
5537
  }
6014
5538
  }
6015
5539
  ]);