stormcloud-video-player 0.3.21 → 0.3.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/sdk/ima.cjs CHANGED
@@ -317,8 +317,6 @@ function createImaController(video, options) {
317
317
  var originalMutedState = false;
318
318
  var originalVolume = typeof video.volume === "number" && !Number.isNaN(video.volume) ? Math.max(0, Math.min(1, video.volume)) : 1;
319
319
  var listeners = /* @__PURE__ */ new Map();
320
- var preloadedVast = /* @__PURE__ */ new Map();
321
- var preloadingVast = /* @__PURE__ */ new Map();
322
320
  var adVideoElement;
323
321
  function setAdPlayingFlag(isPlaying) {
324
322
  if (isPlaying) {
@@ -468,15 +466,7 @@ function createImaController(video, options) {
468
466
  var adsLoadedReject;
469
467
  function makeAdsRequest(google, vastTagUrl) {
470
468
  var adsRequest = new google.ima.AdsRequest();
471
- var preloadedXml = preloadedVast.get(vastTagUrl);
472
- if (preloadedXml) {
473
- console.log("[IMA] \uD83D\uDCE6 Using preloaded VAST response");
474
- adsRequest.adsResponse = preloadedXml;
475
- preloadedVast.delete(vastTagUrl);
476
- } else {
477
- console.log("[IMA] \uD83D\uDCE1 Requesting VAST from URL (letting IMA fetch fresh)");
478
- adsRequest.adTagUrl = vastTagUrl;
479
- }
469
+ adsRequest.adTagUrl = vastTagUrl;
480
470
  var videoWidth = video.offsetWidth || video.clientWidth || 640;
481
471
  var videoHeight = video.offsetHeight || video.clientHeight || 480;
482
472
  adsRequest.linearAdSlotWidth = videoWidth;
@@ -524,36 +514,6 @@ function createImaController(video, options) {
524
514
  (_video_parentElement = video.parentElement) === null || _video_parentElement === void 0 ? void 0 : _video_parentElement.appendChild(container);
525
515
  adContainerEl = container;
526
516
  }
527
- function fetchVastDocument(vastTagUrl) {
528
- return _async_to_generator(function() {
529
- var response;
530
- return _ts_generator(this, function(_state) {
531
- switch(_state.label){
532
- case 0:
533
- return [
534
- 4,
535
- fetch(vastTagUrl, {
536
- mode: "cors",
537
- credentials: "include",
538
- headers: {
539
- "Accept": "application/xml, text/xml, */*"
540
- },
541
- referrerPolicy: "no-referrer-when-downgrade"
542
- })
543
- ];
544
- case 1:
545
- response = _state.sent();
546
- if (!response.ok) {
547
- throw new Error("Failed to preload VAST: ".concat(response.status));
548
- }
549
- return [
550
- 2,
551
- response.text()
552
- ];
553
- }
554
- });
555
- })();
556
- }
557
517
  function destroyAdsManager() {
558
518
  if (adsManager) {
559
519
  try {
@@ -591,7 +551,6 @@ function createImaController(video, options) {
591
551
  case 0:
592
552
  if (!vastTagUrl || vastTagUrl.trim() === "") {
593
553
  _$error = new Error("VAST tag URL is empty or undefined");
594
- console.warn("[IMA] \u274C", _$error.message);
595
554
  return [
596
555
  2,
597
556
  Promise.reject(_$error)
@@ -601,14 +560,12 @@ function createImaController(video, options) {
601
560
  new URL(vastTagUrl);
602
561
  } catch (e) {
603
562
  _$error1 = new Error("Invalid VAST tag URL format: ".concat(vastTagUrl));
604
- console.warn("[IMA] \u274C", _$error1.message);
605
563
  return [
606
564
  2,
607
565
  Promise.reject(_$error1)
608
566
  ];
609
567
  }
610
568
  if (adPlaying) {
611
- console.warn("[IMA] \u26A0\uFE0F Cannot request new ads while an ad is playing. Call stop() first.");
612
569
  return [
613
570
  2,
614
571
  Promise.reject(new Error("Ad already playing - cannot request new ads"))
@@ -676,7 +633,6 @@ function createImaController(video, options) {
676
633
  videoHeight = video.offsetHeight || video.clientHeight;
677
634
  if (!videoWidth || !videoHeight || videoWidth === 0 || videoHeight === 0) {
678
635
  _$error2 = new Error("Invalid video dimensions: ".concat(videoWidth, "x").concat(videoHeight, ". Cannot initialize ads."));
679
- console.warn("[IMA]", _$error2.message);
680
636
  currentReject === null || currentReject === void 0 ? void 0 : currentReject(_$error2);
681
637
  adsLoadedReject = void 0;
682
638
  adsLoadedResolve = void 0;
@@ -696,9 +652,12 @@ function createImaController(video, options) {
696
652
  var AdEvent = google.ima.AdEvent.Type;
697
653
  var AdErrorEvent = google.ima.AdErrorEvent.Type;
698
654
  adsManager.addEventListener(AdErrorEvent.AD_ERROR, function(errorEvent) {
699
- var _error_getMessage;
655
+ var _error_getErrorCode, _error_getVastErrorCode, _error_getMessage;
700
656
  var _$error = errorEvent.getError();
701
- console.error("[DEBUG-ERROR] \u274C AD_ERROR:", (_error_getMessage = _$error.getMessage) === null || _error_getMessage === void 0 ? void 0 : _error_getMessage.call(_$error));
657
+ var errorCode = ((_error_getErrorCode = _$error.getErrorCode) === null || _error_getErrorCode === void 0 ? void 0 : _error_getErrorCode.call(_$error)) || "unknown";
658
+ var vastErrorCode = ((_error_getVastErrorCode = _$error.getVastErrorCode) === null || _error_getVastErrorCode === void 0 ? void 0 : _error_getVastErrorCode.call(_$error)) || "N/A";
659
+ var errorMessage = ((_error_getMessage = _$error.getMessage) === null || _error_getMessage === void 0 ? void 0 : _error_getMessage.call(_$error)) || "Unknown error";
660
+ var isNoFill = errorCode === 303 || vastErrorCode === 303;
702
661
  destroyAdsManager();
703
662
  adPlaying = false;
704
663
  setAdPlayingFlag(false);
@@ -718,7 +677,7 @@ function createImaController(video, options) {
718
677
  adsLoadedReject = void 0;
719
678
  adsLoadedResolve = void 0;
720
679
  }
721
- if (lastAdTagUrl && retryAttempts < maxRetries) {
680
+ if (lastAdTagUrl && retryAttempts < maxRetries && !isNoFill) {
722
681
  var delay = backoffBaseMs * Math.pow(2, retryAttempts++);
723
682
  window.setTimeout(function() {
724
683
  try {
@@ -726,7 +685,12 @@ function createImaController(video, options) {
726
685
  } catch (e) {}
727
686
  }, delay);
728
687
  } else {
729
- emit("ad_error");
688
+ emit("ad_error", {
689
+ code: errorCode,
690
+ vastErrorCode: vastErrorCode,
691
+ message: errorMessage,
692
+ isNoFill: isNoFill
693
+ });
730
694
  if (!(options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds)) {
731
695
  if (video.paused) {
732
696
  var _video_play;
@@ -816,9 +780,12 @@ function createImaController(video, options) {
816
780
  }
817
781
  }, false);
818
782
  adsLoader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, function(adErrorEvent) {
819
- var _error_getMessage;
783
+ var _error_getErrorCode, _error_getVastErrorCode, _error_getMessage;
820
784
  var _$error = adErrorEvent.getError();
821
- console.error("[DEBUG-ERROR] \u274C ADS_LOADER ERROR:", (_error_getMessage = _$error.getMessage) === null || _error_getMessage === void 0 ? void 0 : _error_getMessage.call(_$error));
785
+ var errorCode = ((_error_getErrorCode = _$error.getErrorCode) === null || _error_getErrorCode === void 0 ? void 0 : _error_getErrorCode.call(_$error)) || "unknown";
786
+ var vastErrorCode = ((_error_getVastErrorCode = _$error.getVastErrorCode) === null || _error_getVastErrorCode === void 0 ? void 0 : _error_getVastErrorCode.call(_$error)) || "N/A";
787
+ var errorMessage = ((_error_getMessage = _$error.getMessage) === null || _error_getMessage === void 0 ? void 0 : _error_getMessage.call(_$error)) || "Unknown error";
788
+ var isNoFill = errorCode === 303 || vastErrorCode === 303;
822
789
  adPlaying = false;
823
790
  setAdPlayingFlag(false);
824
791
  if (adContainerEl) {
@@ -838,11 +805,16 @@ function createImaController(video, options) {
838
805
  }
839
806
  }
840
807
  if (adsLoadedReject) {
841
- adsLoadedReject(new Error("Ads loader error"));
808
+ adsLoadedReject(new Error(isNoFill ? "No ads available" : "Ads loader error"));
842
809
  adsLoadedReject = void 0;
843
810
  adsLoadedResolve = void 0;
844
811
  }
845
- emit("ad_error");
812
+ emit("ad_error", {
813
+ code: errorCode,
814
+ vastErrorCode: vastErrorCode,
815
+ message: errorMessage,
816
+ isNoFill: isNoFill
817
+ });
846
818
  }, false);
847
819
  }
848
820
  makeAdsRequest(google, vastTagUrl);
@@ -868,47 +840,6 @@ function createImaController(video, options) {
868
840
  });
869
841
  })();
870
842
  },
871
- preloadAds: function preloadAds(vastTagUrl) {
872
- return _async_to_generator(function() {
873
- var inflight, preloadPromise;
874
- return _ts_generator(this, function(_state) {
875
- if (!vastTagUrl || vastTagUrl.trim() === "") {
876
- return [
877
- 2,
878
- Promise.resolve()
879
- ];
880
- }
881
- if (preloadedVast.has(vastTagUrl)) {
882
- return [
883
- 2,
884
- Promise.resolve()
885
- ];
886
- }
887
- inflight = preloadingVast.get(vastTagUrl);
888
- if (inflight) {
889
- return [
890
- 2,
891
- inflight
892
- ];
893
- }
894
- preloadPromise = fetchVastDocument(vastTagUrl).then(function(xml) {
895
- preloadedVast.set(vastTagUrl, xml);
896
- }).catch(function() {
897
- preloadedVast.delete(vastTagUrl);
898
- }).finally(function() {
899
- preloadingVast.delete(vastTagUrl);
900
- });
901
- preloadingVast.set(vastTagUrl, preloadPromise);
902
- return [
903
- 2,
904
- preloadPromise
905
- ];
906
- });
907
- })();
908
- },
909
- hasPreloadedAd: function hasPreloadedAd(vastTagUrl) {
910
- return preloadedVast.has(vastTagUrl);
911
- },
912
843
  play: function play() {
913
844
  return _async_to_generator(function() {
914
845
  var _window_google, width, height, adVolume, _video_play;
@@ -944,7 +875,6 @@ function createImaController(video, options) {
944
875
  Promise.resolve()
945
876
  ];
946
877
  } catch (error) {
947
- console.error("[IMA] \u274C Error starting ad:", error);
948
878
  adPlaying = false;
949
879
  setAdPlayingFlag(false);
950
880
  if (!(options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds)) {
@@ -1017,8 +947,6 @@ function createImaController(video, options) {
1017
947
  adDisplayContainer = void 0;
1018
948
  adsLoader = void 0;
1019
949
  contentVideoHidden = false;
1020
- preloadedVast.clear();
1021
- preloadingVast.clear();
1022
950
  },
1023
951
  isAdPlaying: function isAdPlaying() {
1024
952
  return adPlaying;