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