stormcloud-video-player 0.8.46 → 0.8.47

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.
@@ -200,15 +200,19 @@ module.exports = __toCommonJS(hlsAdPlayer_exports);
200
200
  var import_hls = __toESM(require("hls.js"), 1);
201
201
  var MAX_VAST_WRAPPER_DEPTH = 5;
202
202
  function createHlsAdPlayer(contentVideo, options) {
203
+ var _contentVideo_AD_VIDEO_PROP, _contentVideo_AD_CONTAINER_PROP;
203
204
  var adPlaying = false;
204
205
  var originalMutedState = false;
205
206
  var originalVolume = Math.max(0, Math.min(1, contentVideo.volume || 1));
206
207
  var listeners = /* @__PURE__ */ new Map();
207
208
  var licenseKey = options === null || options === void 0 ? void 0 : options.licenseKey;
208
209
  var mainHlsInstance = options === null || options === void 0 ? void 0 : options.mainHlsInstance;
209
- var adVideoElement;
210
+ var AD_CONTAINER_PROP = "__stormcloudAdContainer";
211
+ var AD_VIDEO_PROP = "__stormcloudAdVideo";
212
+ var adVideoElement = (_contentVideo_AD_VIDEO_PROP = contentVideo[AD_VIDEO_PROP]) !== null && _contentVideo_AD_VIDEO_PROP !== void 0 ? _contentVideo_AD_VIDEO_PROP : void 0;
210
213
  var adHls;
211
- var adContainerEl;
214
+ var adContainerEl = (_contentVideo_AD_CONTAINER_PROP = contentVideo[AD_CONTAINER_PROP]) !== null && _contentVideo_AD_CONTAINER_PROP !== void 0 ? _contentVideo_AD_CONTAINER_PROP : void 0;
215
+ var adEventHandlers = [];
212
216
  var currentAd;
213
217
  var podAds = [];
214
218
  var podIndex = 0;
@@ -852,7 +856,8 @@ function createHlsAdPlayer(contentVideo, options) {
852
856
  }
853
857
  function setupAdEventListeners() {
854
858
  if (!adVideoElement || !currentAd) return;
855
- adVideoElement.addEventListener("timeupdate", function() {
859
+ if (adEventHandlers.length > 0) return;
860
+ var onTimeUpdate = function onTimeUpdate() {
856
861
  if (!currentAd || !adVideoElement) return;
857
862
  noteAdProgress();
858
863
  var progress = adVideoElement.currentTime / currentAd.duration;
@@ -868,15 +873,15 @@ function createHlsAdPlayer(contentVideo, options) {
868
873
  trackingFired.thirdQuartile = true;
869
874
  fireTrackingPixels(currentAd.trackingUrls.thirdQuartile);
870
875
  }
871
- });
872
- adVideoElement.addEventListener("playing", function() {
876
+ };
877
+ var onPlaying = function onPlaying() {
873
878
  startStallWatchdog();
874
879
  if (!currentAd || trackingFired.start) return;
875
880
  trackingFired.start = true;
876
881
  fireTrackingPixels(currentAd.trackingUrls.start);
877
882
  console.log("[HlsAdPlayer] Ad started playing");
878
- });
879
- adVideoElement.addEventListener("ended", function() {
883
+ };
884
+ var onEnded = function onEnded() {
880
885
  if (!currentAd || trackingFired.complete) return;
881
886
  trackingFired.complete = true;
882
887
  fireTrackingPixels(currentAd.trackingUrls.complete);
@@ -885,8 +890,8 @@ function createHlsAdPlayer(contentVideo, options) {
885
890
  return;
886
891
  }
887
892
  handleAdComplete();
888
- });
889
- adVideoElement.addEventListener("error", function(e) {
893
+ };
894
+ var onError = function onError(e) {
890
895
  if (!adPlaying) return;
891
896
  console.error("[HlsAdPlayer] Ad video error:", e);
892
897
  if (currentAd) {
@@ -896,25 +901,100 @@ function createHlsAdPlayer(contentVideo, options) {
896
901
  return;
897
902
  }
898
903
  handleAdError();
899
- });
900
- adVideoElement.addEventListener("volumechange", function() {
901
- if (!currentAd) return;
904
+ };
905
+ var onVolumeChange = function onVolumeChange() {
906
+ if (!currentAd || !adVideoElement) return;
902
907
  if (adVideoElement.muted) {
903
908
  fireTrackingPixels(currentAd.trackingUrls.mute);
904
909
  } else {
905
910
  fireTrackingPixels(currentAd.trackingUrls.unmute);
906
911
  }
907
- });
908
- adVideoElement.addEventListener("pause", function() {
909
- if (currentAd && !adVideoElement.ended) {
912
+ };
913
+ var onPause = function onPause() {
914
+ if (currentAd && adVideoElement && !adVideoElement.ended) {
910
915
  fireTrackingPixels(currentAd.trackingUrls.pause);
911
916
  }
912
- });
913
- adVideoElement.addEventListener("play", function() {
914
- if (currentAd && adVideoElement.currentTime > 0) {
917
+ };
918
+ var onPlay = function onPlay() {
919
+ if (currentAd && adVideoElement && adVideoElement.currentTime > 0) {
915
920
  fireTrackingPixels(currentAd.trackingUrls.resume);
916
921
  }
917
- });
922
+ };
923
+ adEventHandlers = [
924
+ {
925
+ type: "timeupdate",
926
+ handler: onTimeUpdate
927
+ },
928
+ {
929
+ type: "playing",
930
+ handler: onPlaying
931
+ },
932
+ {
933
+ type: "ended",
934
+ handler: onEnded
935
+ },
936
+ {
937
+ type: "error",
938
+ handler: onError
939
+ },
940
+ {
941
+ type: "volumechange",
942
+ handler: onVolumeChange
943
+ },
944
+ {
945
+ type: "pause",
946
+ handler: onPause
947
+ },
948
+ {
949
+ type: "play",
950
+ handler: onPlay
951
+ }
952
+ ];
953
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
954
+ try {
955
+ for(var _iterator = adEventHandlers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
956
+ var _step_value = _step.value, type = _step_value.type, handler = _step_value.handler;
957
+ adVideoElement.addEventListener(type, handler);
958
+ }
959
+ } catch (err) {
960
+ _didIteratorError = true;
961
+ _iteratorError = err;
962
+ } finally{
963
+ try {
964
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
965
+ _iterator.return();
966
+ }
967
+ } finally{
968
+ if (_didIteratorError) {
969
+ throw _iteratorError;
970
+ }
971
+ }
972
+ }
973
+ }
974
+ function teardownAdEventListeners() {
975
+ if (adVideoElement) {
976
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
977
+ try {
978
+ for(var _iterator = adEventHandlers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
979
+ var _step_value = _step.value, type = _step_value.type, handler = _step_value.handler;
980
+ adVideoElement.removeEventListener(type, handler);
981
+ }
982
+ } catch (err) {
983
+ _didIteratorError = true;
984
+ _iteratorError = err;
985
+ } finally{
986
+ try {
987
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
988
+ _iterator.return();
989
+ }
990
+ } finally{
991
+ if (_didIteratorError) {
992
+ throw _iteratorError;
993
+ }
994
+ }
995
+ }
996
+ }
997
+ adEventHandlers = [];
918
998
  }
919
999
  function setAdPlayingFlag(isPlaying) {
920
1000
  if (isPlaying) {
@@ -1060,15 +1140,13 @@ function createHlsAdPlayer(contentVideo, options) {
1060
1140
  adHls = void 0;
1061
1141
  }
1062
1142
  if (adVideoElement) {
1063
- adVideoElement.pause();
1064
- adVideoElement.removeAttribute("src");
1065
1143
  try {
1144
+ adVideoElement.pause();
1145
+ adVideoElement.removeAttribute("src");
1066
1146
  adVideoElement.load();
1067
1147
  } catch (error) {
1068
- console.warn("[HlsAdPlayer] adVideoElement.load() threw after src removal:", error);
1148
+ console.warn("[HlsAdPlayer] Error releasing ad decoder:", error);
1069
1149
  }
1070
- adVideoElement.remove();
1071
- adVideoElement = void 0;
1072
1150
  }
1073
1151
  if (adContainerEl) {
1074
1152
  adContainerEl.style.display = "none";
@@ -1131,6 +1209,7 @@ function createHlsAdPlayer(contentVideo, options) {
1131
1209
  (_contentVideo_parentElement = contentVideo.parentElement) === null || _contentVideo_parentElement === void 0 ? void 0 : _contentVideo_parentElement.appendChild(container);
1132
1210
  adContainerEl = container;
1133
1211
  }
1212
+ contentVideo[AD_CONTAINER_PROP] = adContainerEl;
1134
1213
  },
1135
1214
  requestAds: function requestAds(vastTagUrl) {
1136
1215
  return _async_to_generator(function() {
@@ -1233,8 +1312,9 @@ function createHlsAdPlayer(contentVideo, options) {
1233
1312
  if (!adVideoElement) {
1234
1313
  adVideoElement = createAdVideoElement();
1235
1314
  adContainerEl === null || adContainerEl === void 0 ? void 0 : adContainerEl.appendChild(adVideoElement);
1236
- setupAdEventListeners();
1315
+ contentVideo[AD_VIDEO_PROP] = adVideoElement;
1237
1316
  }
1317
+ setupAdEventListeners();
1238
1318
  resetQuartileTracking(true);
1239
1319
  contentVolume = contentVideo.volume;
1240
1320
  originalVolume = Math.max(0, Math.min(1, contentVolume || originalVolume));
@@ -1362,11 +1442,8 @@ function createHlsAdPlayer(contentVideo, options) {
1362
1442
  setAdPlayingFlag(false);
1363
1443
  contentVideo.muted = originalMutedState;
1364
1444
  contentVideo.volume = Math.max(0, Math.min(1, originalVolume));
1445
+ teardownAdEventListeners();
1365
1446
  releaseAdDecoder();
1366
- if (adContainerEl === null || adContainerEl === void 0 ? void 0 : adContainerEl.parentElement) {
1367
- adContainerEl.parentElement.removeChild(adContainerEl);
1368
- }
1369
- adContainerEl = void 0;
1370
1447
  currentAd = void 0;
1371
1448
  podAds = [];
1372
1449
  podIndex = 0;