stormcloud-video-player 0.8.47 → 0.8.48

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
@@ -539,6 +539,56 @@ function createHlsAdPlayer(contentVideo, options) {
539
539
  var url = mediaFile.url.toLowerCase();
540
540
  return type.startsWith("video/") || url.endsWith(".mp4") || url.includes(".mp4?");
541
541
  }
542
+ function isAudioMediaFile(mediaFile) {
543
+ var type = mediaFile.type.toLowerCase();
544
+ var url = (mediaFile.url.toLowerCase().split("?")[0] || "").trim();
545
+ return type.startsWith("audio/") || url.endsWith(".mp3") || url.endsWith(".aac") || url.endsWith(".m4a") || url.endsWith(".ogg") || url.endsWith(".oga") || url.endsWith(".opus") || url.endsWith(".wav") || url.endsWith(".weba");
546
+ }
547
+ function collectVideoMediaFiles(scope, verbose) {
548
+ var mediaFileElements = scope.querySelectorAll("MediaFile");
549
+ var mediaFiles = [];
550
+ if (verbose) {
551
+ console.log("[HlsAdPlayer] Found ".concat(mediaFileElements.length, " MediaFile element(s) in VAST XML"));
552
+ }
553
+ mediaFileElements.forEach(function(mf, index) {
554
+ var _mf_textContent;
555
+ var type = mf.getAttribute("type") || "";
556
+ var url = ((_mf_textContent = mf.textContent) === null || _mf_textContent === void 0 ? void 0 : _mf_textContent.trim()) || "";
557
+ var width = mf.getAttribute("width") || "";
558
+ var height = mf.getAttribute("height") || "";
559
+ if (verbose) {
560
+ console.log("[HlsAdPlayer] MediaFile ".concat(index, ': type="').concat(type, '", url="').concat(url, '", width="').concat(width, '", height="').concat(height, '"'));
561
+ }
562
+ if (!url) {
563
+ if (verbose) {
564
+ console.warn("[HlsAdPlayer] MediaFile ".concat(index, " has empty URL"));
565
+ }
566
+ return;
567
+ }
568
+ var bitrateAttr = mf.getAttribute("bitrate");
569
+ var bitrateValue = bitrateAttr ? parseInt(bitrateAttr, 10) : void 0;
570
+ var mediaFile = {
571
+ url: url,
572
+ type: type,
573
+ width: parseInt(width || "1920", 10),
574
+ height: parseInt(height || "1080", 10),
575
+ bitrate: bitrateValue && bitrateValue > 0 ? bitrateValue : void 0
576
+ };
577
+ if (isAudioMediaFile(mediaFile)) {
578
+ console.warn("[HlsAdPlayer] MediaFile ".concat(index, ' skipped (audio-only, type="').concat(type, '") — audio ads are not played to avoid a black screen'));
579
+ return;
580
+ }
581
+ if (isHlsMediaFile(mediaFile) || isProgressiveMediaFile(mediaFile)) {
582
+ mediaFiles.push(mediaFile);
583
+ if (verbose) {
584
+ console.log("[HlsAdPlayer] Added ".concat(isHlsMediaFile(mediaFile) ? "HLS" : "progressive", " MediaFile: ").concat(url));
585
+ }
586
+ } else if (verbose) {
587
+ console.log("[HlsAdPlayer] MediaFile ".concat(index, ' ignored (type="').concat(type, '" is not supported)'));
588
+ }
589
+ });
590
+ return mediaFiles;
591
+ }
542
592
  function createEmptyTrackingUrls() {
543
593
  return {
544
594
  impression: [],
@@ -626,37 +676,7 @@ function createHlsAdPlayer(contentVideo, options) {
626
676
  var durationText = ((_xmlDoc_querySelector3 = xmlDoc.querySelector("Duration")) === null || _xmlDoc_querySelector3 === void 0 ? void 0 : _xmlDoc_querySelector3.textContent) || "00:00:30";
627
677
  var durationParts = durationText.split(":");
628
678
  var duration = parseInt(durationParts[0] || "0", 10) * 3600 + parseInt(durationParts[1] || "0", 10) * 60 + parseInt(durationParts[2] || "0", 10);
629
- var mediaFileElements = xmlDoc.querySelectorAll("MediaFile");
630
- var mediaFiles = [];
631
- console.log("[HlsAdPlayer] Found ".concat(mediaFileElements.length, " MediaFile element(s) in VAST XML"));
632
- mediaFileElements.forEach(function(mf, index) {
633
- var _mf_textContent;
634
- var type = mf.getAttribute("type") || "";
635
- var url = ((_mf_textContent = mf.textContent) === null || _mf_textContent === void 0 ? void 0 : _mf_textContent.trim()) || "";
636
- var width = mf.getAttribute("width") || "";
637
- var height = mf.getAttribute("height") || "";
638
- console.log("[HlsAdPlayer] MediaFile ".concat(index, ': type="').concat(type, '", url="').concat(url, '", width="').concat(width, '", height="').concat(height, '"'));
639
- var mediaFile = {
640
- url: url,
641
- type: type,
642
- width: parseInt(width || "1920", 10),
643
- height: parseInt(height || "1080", 10),
644
- bitrate: void 0
645
- };
646
- if (!url) {
647
- console.warn("[HlsAdPlayer] MediaFile ".concat(index, " has empty URL"));
648
- return;
649
- }
650
- var bitrateAttr = mf.getAttribute("bitrate");
651
- var bitrateValue = bitrateAttr ? parseInt(bitrateAttr, 10) : void 0;
652
- mediaFile.bitrate = bitrateValue && bitrateValue > 0 ? bitrateValue : void 0;
653
- if (isHlsMediaFile(mediaFile) || isProgressiveMediaFile(mediaFile)) {
654
- mediaFiles.push(mediaFile);
655
- console.log("[HlsAdPlayer] Added ".concat(isHlsMediaFile(mediaFile) ? "HLS" : "progressive", " MediaFile: ").concat(url));
656
- } else {
657
- console.log("[HlsAdPlayer] MediaFile ".concat(index, ' ignored (type="').concat(type, '" is not supported)'));
658
- }
659
- });
679
+ var mediaFiles = collectVideoMediaFiles(xmlDoc, true);
660
680
  if (mediaFiles.length === 0) {
661
681
  if (isNoAdAvailable) {
662
682
  console.warn("[HlsAdPlayer] No ads available (VAST response indicates no ads)");
@@ -704,28 +724,7 @@ function createHlsAdPlayer(contentVideo, options) {
704
724
  var durationText = ((_adElement_querySelector3 = adElement.querySelector("Duration")) === null || _adElement_querySelector3 === void 0 ? void 0 : _adElement_querySelector3.textContent) || "00:00:30";
705
725
  var durationParts = durationText.split(":");
706
726
  var duration = parseInt(durationParts[0] || "0", 10) * 3600 + parseInt(durationParts[1] || "0", 10) * 60 + parseInt(durationParts[2] || "0", 10);
707
- var mediaFileElements = adElement.querySelectorAll("MediaFile");
708
- var mediaFiles = [];
709
- mediaFileElements.forEach(function(mf) {
710
- var _mf_textContent;
711
- var type = mf.getAttribute("type") || "";
712
- var url = ((_mf_textContent = mf.textContent) === null || _mf_textContent === void 0 ? void 0 : _mf_textContent.trim()) || "";
713
- var width = mf.getAttribute("width") || "";
714
- var height = mf.getAttribute("height") || "";
715
- if (!url) return;
716
- var bitrateAttr = mf.getAttribute("bitrate");
717
- var bitrateValue = bitrateAttr ? parseInt(bitrateAttr, 10) : void 0;
718
- var mediaFile = {
719
- url: url,
720
- type: type,
721
- width: parseInt(width || "1920", 10),
722
- height: parseInt(height || "1080", 10),
723
- bitrate: bitrateValue && bitrateValue > 0 ? bitrateValue : void 0
724
- };
725
- if (isHlsMediaFile(mediaFile) || isProgressiveMediaFile(mediaFile)) {
726
- mediaFiles.push(mediaFile);
727
- }
728
- });
727
+ var mediaFiles = collectVideoMediaFiles(adElement, false);
729
728
  if (mediaFiles.length === 0) {
730
729
  if (isNoAdAvailable) {
731
730
  console.warn("[HlsAdPlayer] Pod <Ad> indicates no ad available");