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.
package/lib/index.js CHANGED
@@ -848,7 +848,7 @@ function createHlsAdPlayer(contentVideo, options) {
848
848
  const xmlDoc = parser.parseFromString(xmlString, "text/xml");
849
849
  const parserError = xmlDoc.querySelector("parsererror");
850
850
  if (parserError) {
851
- console.error("[HlsAdPlayer] XML parsing error:", parserError.textContent);
851
+ console.error("[HlsAdPlayer] XML parsing error (malformed VAST XML):", parserError.textContent);
852
852
  return null;
853
853
  }
854
854
  const adElement = xmlDoc.querySelector("Ad");
@@ -858,28 +858,45 @@ function createHlsAdPlayer(contentVideo, options) {
858
858
  }
859
859
  const adId = adElement.getAttribute("id") || "unknown";
860
860
  const title = ((_a = xmlDoc.querySelector("AdTitle")) == null ? void 0 : _a.textContent) || "Ad";
861
+ const isNoAdAvailable = adId === "empty" || title.toLowerCase().includes("no ad available") || title.toLowerCase() === "no ad available";
861
862
  const durationText = ((_b = xmlDoc.querySelector("Duration")) == null ? void 0 : _b.textContent) || "00:00:30";
862
863
  const durationParts = durationText.split(":");
863
864
  const duration = parseInt(durationParts[0] || "0", 10) * 3600 + parseInt(durationParts[1] || "0", 10) * 60 + parseInt(durationParts[2] || "0", 10);
864
865
  const mediaFileElements = xmlDoc.querySelectorAll("MediaFile");
865
866
  const mediaFiles = [];
866
- mediaFileElements.forEach((mf) => {
867
+ console.log(`[HlsAdPlayer] Found ${mediaFileElements.length} MediaFile element(s) in VAST XML`);
868
+ mediaFileElements.forEach((mf, index) => {
867
869
  var _a2;
868
870
  const type = mf.getAttribute("type") || "";
871
+ const url = ((_a2 = mf.textContent) == null ? void 0 : _a2.trim()) || "";
872
+ const width = mf.getAttribute("width") || "";
873
+ const height = mf.getAttribute("height") || "";
874
+ console.log(`[HlsAdPlayer] MediaFile ${index}: type="${type}", url="${url}", width="${width}", height="${height}"`);
869
875
  if (type === "application/x-mpegURL" || type.includes("m3u8")) {
876
+ if (!url) {
877
+ console.warn(`[HlsAdPlayer] MediaFile ${index} has HLS type but empty URL`);
878
+ return;
879
+ }
870
880
  const bitrateAttr = mf.getAttribute("bitrate");
871
881
  const bitrateValue = bitrateAttr ? parseInt(bitrateAttr, 10) : void 0;
872
882
  mediaFiles.push({
873
- url: ((_a2 = mf.textContent) == null ? void 0 : _a2.trim()) || "",
883
+ url,
874
884
  type,
875
- width: parseInt(mf.getAttribute("width") || "1920", 10),
876
- height: parseInt(mf.getAttribute("height") || "1080", 10),
885
+ width: parseInt(width || "1920", 10),
886
+ height: parseInt(height || "1080", 10),
877
887
  bitrate: bitrateValue && bitrateValue > 0 ? bitrateValue : void 0
878
888
  });
889
+ console.log(`[HlsAdPlayer] Added HLS MediaFile: ${url}`);
890
+ } else {
891
+ console.log(`[HlsAdPlayer] MediaFile ${index} ignored (type="${type}" is not HLS)`);
879
892
  }
880
893
  });
881
894
  if (mediaFiles.length === 0) {
882
- console.warn("[HlsAdPlayer] No HLS media files found in VAST XML");
895
+ if (isNoAdAvailable) {
896
+ console.warn("[HlsAdPlayer] No ads available (VAST response indicates no ads)");
897
+ } else {
898
+ console.warn("[HlsAdPlayer] No HLS media files found in VAST XML");
899
+ }
883
900
  return null;
884
901
  }
885
902
  const trackingUrls = {
@@ -1067,9 +1084,11 @@ function createHlsAdPlayer(contentVideo, options) {
1067
1084
  }
1068
1085
  const vastXml = await response.text();
1069
1086
  console.log("[HlsAdPlayer] VAST XML received");
1087
+ console.log("[HlsAdPlayer] VAST XML content (first 2000 chars):", vastXml.substring(0, 2e3));
1070
1088
  const ad = parseVastXml(vastXml);
1071
1089
  if (!ad) {
1072
- throw new Error("Failed to parse VAST XML or no ads available");
1090
+ console.warn("[HlsAdPlayer] No ads available from VAST response");
1091
+ return Promise.resolve();
1073
1092
  }
1074
1093
  currentAd = ad;
1075
1094
  console.log(`[HlsAdPlayer] Ad parsed: ${ad.title}, duration: ${ad.duration}s`);
@@ -1084,7 +1103,7 @@ function createHlsAdPlayer(contentVideo, options) {
1084
1103
  },
1085
1104
  async play() {
1086
1105
  if (!currentAd) {
1087
- console.warn("[HlsAdPlayer] Cannot play: No ad loaded");
1106
+ console.warn("[HlsAdPlayer] Cannot play: No ad loaded (no ads available)");
1088
1107
  return Promise.reject(new Error("No ad loaded"));
1089
1108
  }
1090
1109
  console.log("[HlsAdPlayer] Starting ad playback");
@@ -2436,7 +2455,7 @@ var StormcloudVideoPlayer = class {
2436
2455
  this.apiVastTagUrl = vastEndpoint;
2437
2456
  if (this.config.debugAdTiming) {
2438
2457
  console.log(
2439
- "[StormcloudVideoPlayer] Using AdStorm VAST endpoint:",
2458
+ "[StormcloudVideoPlayer] Using AdStorm VAST endpoint (adstorm mode):",
2440
2459
  vastEndpoint
2441
2460
  );
2442
2461
  }
@@ -2692,12 +2711,20 @@ var StormcloudVideoPlayer = class {
2692
2711
  this.startAdFailsafeTimer();
2693
2712
  try {
2694
2713
  await this.ima.requestAds(vastTagUrl);
2695
- if (this.config.debugAdTiming) {
2696
- console.log("[StormcloudVideoPlayer] Ad request successful, starting playback");
2697
- }
2698
- await this.ima.play();
2699
- if (this.config.debugAdTiming) {
2700
- console.log("[StormcloudVideoPlayer] Ad playback started successfully");
2714
+ try {
2715
+ if (this.config.debugAdTiming) {
2716
+ console.log("[StormcloudVideoPlayer] Ad request completed, attempting playback");
2717
+ }
2718
+ await this.ima.play();
2719
+ if (this.config.debugAdTiming) {
2720
+ console.log("[StormcloudVideoPlayer] Ad playback started successfully");
2721
+ }
2722
+ } catch (playError) {
2723
+ if (this.config.debugAdTiming) {
2724
+ console.log("[StormcloudVideoPlayer] No ads available, skipping playback");
2725
+ }
2726
+ this.handleAdFailure();
2727
+ return;
2701
2728
  }
2702
2729
  } catch (error) {
2703
2730
  if (this.config.debugAdTiming) {
@@ -2923,7 +2950,8 @@ var CRITICAL_PROPS = [
2923
2950
  "allowNativeHls",
2924
2951
  "licenseKey",
2925
2952
  "lowLatencyMode",
2926
- "driftToleranceMs"
2953
+ "driftToleranceMs",
2954
+ "vastMode"
2927
2955
  ];
2928
2956
  var StormcloudVideoPlayerComponent = React.memo(
2929
2957
  (props) => {
@@ -2951,6 +2979,9 @@ var StormcloudVideoPlayerComponent = React.memo(
2951
2979
  poster,
2952
2980
  children,
2953
2981
  licenseKey,
2982
+ vastMode,
2983
+ vastTagUrl,
2984
+ adPlayerType,
2954
2985
  ...restVideoAttrs
2955
2986
  } = props;
2956
2987
  const videoRef = useRef(null);
@@ -3022,7 +3053,7 @@ var StormcloudVideoPlayerComponent = React.memo(
3022
3053
  const shouldShowEnhancedControls = showCustomControls && (isHlsStream ? allowNativeHls : true);
3023
3054
  const criticalPropsKey = useMemo(() => {
3024
3055
  return CRITICAL_PROPS.map((prop) => `${prop}:${props[prop]}`).join("|");
3025
- }, [src, allowNativeHls, licenseKey, lowLatencyMode, driftToleranceMs]);
3056
+ }, [src, allowNativeHls, licenseKey, lowLatencyMode, driftToleranceMs, vastMode]);
3026
3057
  useEffect(() => {
3027
3058
  if (typeof window === "undefined") return;
3028
3059
  const el = videoRef.current;
@@ -3063,6 +3094,9 @@ var StormcloudVideoPlayerComponent = React.memo(
3063
3094
  cfg.onFullscreenToggle = onFullscreenToggle;
3064
3095
  if (onControlClick !== void 0) cfg.onControlClick = onControlClick;
3065
3096
  if (licenseKey !== void 0) cfg.licenseKey = licenseKey;
3097
+ if (vastMode !== void 0) cfg.vastMode = vastMode;
3098
+ if (vastTagUrl !== void 0) cfg.vastTagUrl = vastTagUrl;
3099
+ if (adPlayerType !== void 0) cfg.adPlayerType = adPlayerType;
3066
3100
  const player = new StormcloudVideoPlayer(cfg);
3067
3101
  playerRef.current = player;
3068
3102
  player.load().then(() => {