stormcloud-video-player 0.2.14 → 0.2.15

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.
@@ -850,7 +850,7 @@ function createHlsAdPlayer(contentVideo, options) {
850
850
  const xmlDoc = parser.parseFromString(xmlString, "text/xml");
851
851
  const parserError = xmlDoc.querySelector("parsererror");
852
852
  if (parserError) {
853
- console.error("[HlsAdPlayer] XML parsing error:", parserError.textContent);
853
+ console.error("[HlsAdPlayer] XML parsing error (malformed VAST XML):", parserError.textContent);
854
854
  return null;
855
855
  }
856
856
  const adElement = xmlDoc.querySelector("Ad");
@@ -860,28 +860,45 @@ function createHlsAdPlayer(contentVideo, options) {
860
860
  }
861
861
  const adId = adElement.getAttribute("id") || "unknown";
862
862
  const title = ((_a = xmlDoc.querySelector("AdTitle")) == null ? void 0 : _a.textContent) || "Ad";
863
+ const isNoAdAvailable = adId === "empty" || title.toLowerCase().includes("no ad available") || title.toLowerCase() === "no ad available";
863
864
  const durationText = ((_b = xmlDoc.querySelector("Duration")) == null ? void 0 : _b.textContent) || "00:00:30";
864
865
  const durationParts = durationText.split(":");
865
866
  const duration = parseInt(durationParts[0] || "0", 10) * 3600 + parseInt(durationParts[1] || "0", 10) * 60 + parseInt(durationParts[2] || "0", 10);
866
867
  const mediaFileElements = xmlDoc.querySelectorAll("MediaFile");
867
868
  const mediaFiles = [];
868
- mediaFileElements.forEach((mf) => {
869
+ console.log(`[HlsAdPlayer] Found ${mediaFileElements.length} MediaFile element(s) in VAST XML`);
870
+ mediaFileElements.forEach((mf, index) => {
869
871
  var _a2;
870
872
  const type = mf.getAttribute("type") || "";
873
+ const url = ((_a2 = mf.textContent) == null ? void 0 : _a2.trim()) || "";
874
+ const width = mf.getAttribute("width") || "";
875
+ const height = mf.getAttribute("height") || "";
876
+ console.log(`[HlsAdPlayer] MediaFile ${index}: type="${type}", url="${url}", width="${width}", height="${height}"`);
871
877
  if (type === "application/x-mpegURL" || type.includes("m3u8")) {
878
+ if (!url) {
879
+ console.warn(`[HlsAdPlayer] MediaFile ${index} has HLS type but empty URL`);
880
+ return;
881
+ }
872
882
  const bitrateAttr = mf.getAttribute("bitrate");
873
883
  const bitrateValue = bitrateAttr ? parseInt(bitrateAttr, 10) : void 0;
874
884
  mediaFiles.push({
875
- url: ((_a2 = mf.textContent) == null ? void 0 : _a2.trim()) || "",
885
+ url,
876
886
  type,
877
- width: parseInt(mf.getAttribute("width") || "1920", 10),
878
- height: parseInt(mf.getAttribute("height") || "1080", 10),
887
+ width: parseInt(width || "1920", 10),
888
+ height: parseInt(height || "1080", 10),
879
889
  bitrate: bitrateValue && bitrateValue > 0 ? bitrateValue : void 0
880
890
  });
891
+ console.log(`[HlsAdPlayer] Added HLS MediaFile: ${url}`);
892
+ } else {
893
+ console.log(`[HlsAdPlayer] MediaFile ${index} ignored (type="${type}" is not HLS)`);
881
894
  }
882
895
  });
883
896
  if (mediaFiles.length === 0) {
884
- console.warn("[HlsAdPlayer] No HLS media files found in VAST XML");
897
+ if (isNoAdAvailable) {
898
+ console.warn("[HlsAdPlayer] No ads available (VAST response indicates no ads)");
899
+ } else {
900
+ console.warn("[HlsAdPlayer] No HLS media files found in VAST XML");
901
+ }
885
902
  return null;
886
903
  }
887
904
  const trackingUrls = {
@@ -1069,9 +1086,11 @@ function createHlsAdPlayer(contentVideo, options) {
1069
1086
  }
1070
1087
  const vastXml = await response.text();
1071
1088
  console.log("[HlsAdPlayer] VAST XML received");
1089
+ console.log("[HlsAdPlayer] VAST XML content (first 2000 chars):", vastXml.substring(0, 2e3));
1072
1090
  const ad = parseVastXml(vastXml);
1073
1091
  if (!ad) {
1074
- throw new Error("Failed to parse VAST XML or no ads available");
1092
+ console.warn("[HlsAdPlayer] No ads available from VAST response");
1093
+ return Promise.resolve();
1075
1094
  }
1076
1095
  currentAd = ad;
1077
1096
  console.log(`[HlsAdPlayer] Ad parsed: ${ad.title}, duration: ${ad.duration}s`);
@@ -1086,7 +1105,7 @@ function createHlsAdPlayer(contentVideo, options) {
1086
1105
  },
1087
1106
  async play() {
1088
1107
  if (!currentAd) {
1089
- console.warn("[HlsAdPlayer] Cannot play: No ad loaded");
1108
+ console.warn("[HlsAdPlayer] Cannot play: No ad loaded (no ads available)");
1090
1109
  return Promise.reject(new Error("No ad loaded"));
1091
1110
  }
1092
1111
  console.log("[HlsAdPlayer] Starting ad playback");
@@ -2438,7 +2457,7 @@ var StormcloudVideoPlayer = class {
2438
2457
  this.apiVastTagUrl = vastEndpoint;
2439
2458
  if (this.config.debugAdTiming) {
2440
2459
  console.log(
2441
- "[StormcloudVideoPlayer] Using AdStorm VAST endpoint:",
2460
+ "[StormcloudVideoPlayer] Using AdStorm VAST endpoint (adstorm mode):",
2442
2461
  vastEndpoint
2443
2462
  );
2444
2463
  }
@@ -2694,12 +2713,20 @@ var StormcloudVideoPlayer = class {
2694
2713
  this.startAdFailsafeTimer();
2695
2714
  try {
2696
2715
  await this.ima.requestAds(vastTagUrl);
2697
- if (this.config.debugAdTiming) {
2698
- console.log("[StormcloudVideoPlayer] Ad request successful, starting playback");
2699
- }
2700
- await this.ima.play();
2701
- if (this.config.debugAdTiming) {
2702
- console.log("[StormcloudVideoPlayer] Ad playback started successfully");
2716
+ try {
2717
+ if (this.config.debugAdTiming) {
2718
+ console.log("[StormcloudVideoPlayer] Ad request completed, attempting playback");
2719
+ }
2720
+ await this.ima.play();
2721
+ if (this.config.debugAdTiming) {
2722
+ console.log("[StormcloudVideoPlayer] Ad playback started successfully");
2723
+ }
2724
+ } catch (playError) {
2725
+ if (this.config.debugAdTiming) {
2726
+ console.log("[StormcloudVideoPlayer] No ads available, skipping playback");
2727
+ }
2728
+ this.handleAdFailure();
2729
+ return;
2703
2730
  }
2704
2731
  } catch (error) {
2705
2732
  if (this.config.debugAdTiming) {