stormcloud-video-player 0.3.59 → 0.3.61

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.
@@ -1761,6 +1761,16 @@ function createHlsAdPlayer(contentVideo, options) {
1761
1761
  });
1762
1762
  return bestMatch.file;
1763
1763
  }
1764
+ function isHlsMediaFile(mediaFile) {
1765
+ var type = mediaFile.type.toLowerCase();
1766
+ var url = mediaFile.url.toLowerCase();
1767
+ return type === "application/x-mpegurl" || type === "application/vnd.apple.mpegurl" || type.includes("mpegurl") || url.includes(".m3u8");
1768
+ }
1769
+ function isProgressiveMediaFile(mediaFile) {
1770
+ var type = mediaFile.type.toLowerCase();
1771
+ var url = mediaFile.url.toLowerCase();
1772
+ return type.startsWith("video/") || url.endsWith(".mp4") || url.includes(".mp4?");
1773
+ }
1764
1774
  function parseVastXml(xmlString) {
1765
1775
  try {
1766
1776
  var _xmlDoc_querySelector, _xmlDoc_querySelector1, _xmlDoc_querySelector_textContent, _xmlDoc_querySelector2;
@@ -1792,30 +1802,32 @@ function createHlsAdPlayer(contentVideo, options) {
1792
1802
  var width = mf.getAttribute("width") || "";
1793
1803
  var height = mf.getAttribute("height") || "";
1794
1804
  console.log("[HlsAdPlayer] MediaFile ".concat(index, ': type="').concat(type, '", url="').concat(url, '", width="').concat(width, '", height="').concat(height, '"'));
1795
- if (type === "application/x-mpegURL" || type.includes("m3u8")) {
1796
- if (!url) {
1797
- console.warn("[HlsAdPlayer] MediaFile ".concat(index, " has HLS type but empty URL"));
1798
- return;
1799
- }
1800
- var bitrateAttr = mf.getAttribute("bitrate");
1801
- var bitrateValue = bitrateAttr ? parseInt(bitrateAttr, 10) : void 0;
1802
- mediaFiles.push({
1803
- url: url,
1804
- type: type,
1805
- width: parseInt(width || "1920", 10),
1806
- height: parseInt(height || "1080", 10),
1807
- bitrate: bitrateValue && bitrateValue > 0 ? bitrateValue : void 0
1808
- });
1809
- console.log("[HlsAdPlayer] Added HLS MediaFile: ".concat(url));
1805
+ var mediaFile = {
1806
+ url: url,
1807
+ type: type,
1808
+ width: parseInt(width || "1920", 10),
1809
+ height: parseInt(height || "1080", 10),
1810
+ bitrate: void 0
1811
+ };
1812
+ if (!url) {
1813
+ console.warn("[HlsAdPlayer] MediaFile ".concat(index, " has empty URL"));
1814
+ return;
1815
+ }
1816
+ var bitrateAttr = mf.getAttribute("bitrate");
1817
+ var bitrateValue = bitrateAttr ? parseInt(bitrateAttr, 10) : void 0;
1818
+ mediaFile.bitrate = bitrateValue && bitrateValue > 0 ? bitrateValue : void 0;
1819
+ if (isHlsMediaFile(mediaFile) || isProgressiveMediaFile(mediaFile)) {
1820
+ mediaFiles.push(mediaFile);
1821
+ console.log("[HlsAdPlayer] Added ".concat(isHlsMediaFile(mediaFile) ? "HLS" : "progressive", " MediaFile: ").concat(url));
1810
1822
  } else {
1811
- console.log("[HlsAdPlayer] MediaFile ".concat(index, ' ignored (type="').concat(type, '" is not HLS)'));
1823
+ console.log("[HlsAdPlayer] MediaFile ".concat(index, ' ignored (type="').concat(type, '" is not supported)'));
1812
1824
  }
1813
1825
  });
1814
1826
  if (mediaFiles.length === 0) {
1815
1827
  if (isNoAdAvailable) {
1816
1828
  console.warn("[HlsAdPlayer] No ads available (VAST response indicates no ads)");
1817
1829
  } else {
1818
- console.warn("[HlsAdPlayer] No HLS media files found in VAST XML");
1830
+ console.warn("[HlsAdPlayer] No supported media files found in VAST XML");
1819
1831
  }
1820
1832
  return null;
1821
1833
  }
@@ -2112,7 +2124,7 @@ function createHlsAdPlayer(contentVideo, options) {
2112
2124
  },
2113
2125
  play: function play() {
2114
2126
  return _async_to_generator(function() {
2115
- var contentVolume, adVolume, mediaFile;
2127
+ var contentVolume, adVolume, mediaFile, isHlsAd;
2116
2128
  return _ts_generator(this, function(_state) {
2117
2129
  if (!currentAd) {
2118
2130
  console.warn("[HlsAdPlayer] Cannot play: No ad loaded (no ads available)");
@@ -2164,8 +2176,9 @@ function createHlsAdPlayer(contentVideo, options) {
2164
2176
  if (!mediaFile) {
2165
2177
  throw new Error("No media file available for ad");
2166
2178
  }
2167
- console.log("[HlsAdPlayer] Loading ad from: ".concat(mediaFile.url));
2168
- if (import_hls.default.isSupported()) {
2179
+ isHlsAd = isHlsMediaFile(mediaFile);
2180
+ console.log("[HlsAdPlayer] Loading ".concat(isHlsAd ? "HLS" : "progressive", " ad from: ").concat(mediaFile.url));
2181
+ if (isHlsAd && import_hls.default.isSupported()) {
2169
2182
  if (adHls) {
2170
2183
  adHls.destroy();
2171
2184
  }
@@ -2188,14 +2201,25 @@ function createHlsAdPlayer(contentVideo, options) {
2188
2201
  handleAdError();
2189
2202
  }
2190
2203
  });
2191
- } else if (adVideoElement.canPlayType("application/vnd.apple.mpegurl")) {
2204
+ } else if (isHlsAd && adVideoElement.canPlayType("application/vnd.apple.mpegurl")) {
2192
2205
  adVideoElement.src = mediaFile.url;
2193
2206
  adVideoElement.play().catch(function(error) {
2194
2207
  console.error("[HlsAdPlayer] Error starting ad playback:", error);
2195
2208
  handleAdError();
2196
2209
  });
2210
+ } else if (!isHlsAd && isProgressiveMediaFile(mediaFile)) {
2211
+ if (adHls) {
2212
+ adHls.destroy();
2213
+ adHls = void 0;
2214
+ }
2215
+ adVideoElement.src = mediaFile.url;
2216
+ adVideoElement.load();
2217
+ adVideoElement.play().catch(function(error) {
2218
+ console.error("[HlsAdPlayer] Error starting progressive ad playback:", error);
2219
+ handleAdError();
2220
+ });
2197
2221
  } else {
2198
- throw new Error("HLS not supported");
2222
+ throw new Error("Unsupported ad media file type: ".concat(mediaFile.type));
2199
2223
  }
2200
2224
  return [
2201
2225
  2,
@@ -2636,40 +2660,66 @@ function getBrowserID(clientInfo) {
2636
2660
  });
2637
2661
  })();
2638
2662
  }
2639
- function sendInitialTracking(licenseKey) {
2663
+ var PLAYER_TRACKING_BASE_URL = "https://adstorm.co/api-adstorm-dev/adstorm/player-tracking";
2664
+ var TRACK_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/metrics/ingest");
2665
+ var HEARTBEAT_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/heartbeat");
2666
+ var IMPRESSIONS_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/impressions/ingest");
2667
+ function buildHeaders(licenseKey) {
2668
+ var headers = {
2669
+ "Content-Type": "application/json"
2670
+ };
2671
+ if (licenseKey) {
2672
+ headers["Authorization"] = "Bearer ".concat(licenseKey);
2673
+ }
2674
+ return headers;
2675
+ }
2676
+ function sendTrackRequest(licenseKey, body) {
2640
2677
  return _async_to_generator(function() {
2641
- var clientInfo, browserId, trackingData, headers, response, error;
2678
+ var response;
2642
2679
  return _ts_generator(this, function(_state) {
2643
2680
  switch(_state.label){
2644
2681
  case 0:
2645
- _state.trys.push([
2646
- 0,
2647
- 4,
2648
- ,
2649
- 5
2650
- ]);
2651
- clientInfo = getClientInfo();
2652
2682
  return [
2653
2683
  4,
2654
- getBrowserID(clientInfo)
2684
+ fetch(TRACK_URL, {
2685
+ method: "POST",
2686
+ headers: buildHeaders(licenseKey),
2687
+ body: JSON.stringify(body)
2688
+ })
2655
2689
  ];
2656
2690
  case 1:
2657
- browserId = _state.sent();
2658
- trackingData = _object_spread({
2659
- browserId: browserId
2660
- }, clientInfo);
2661
- headers = {
2662
- "Content-Type": "application/json"
2663
- };
2691
+ response = _state.sent();
2692
+ if (!response.ok) {
2693
+ throw new Error("HTTP error! status: ".concat(response.status));
2694
+ }
2695
+ return [
2696
+ 4,
2697
+ response.json()
2698
+ ];
2699
+ case 2:
2700
+ _state.sent();
2701
+ return [
2702
+ 2
2703
+ ];
2704
+ }
2705
+ });
2706
+ })();
2707
+ }
2708
+ function postJson(url, licenseKey, body) {
2709
+ return _async_to_generator(function() {
2710
+ var response;
2711
+ return _ts_generator(this, function(_state) {
2712
+ switch(_state.label){
2713
+ case 0:
2664
2714
  return [
2665
2715
  4,
2666
- fetch("https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/track", {
2716
+ fetch(url, {
2667
2717
  method: "POST",
2668
- headers: headers,
2669
- body: JSON.stringify(trackingData)
2718
+ headers: buildHeaders(licenseKey),
2719
+ body: JSON.stringify(body)
2670
2720
  })
2671
2721
  ];
2672
- case 2:
2722
+ case 1:
2673
2723
  response = _state.sent();
2674
2724
  if (!response.ok) {
2675
2725
  throw new Error("HTTP error! status: ".concat(response.status));
@@ -2678,35 +2728,63 @@ function sendInitialTracking(licenseKey) {
2678
2728
  4,
2679
2729
  response.json()
2680
2730
  ];
2681
- case 3:
2731
+ case 2:
2682
2732
  _state.sent();
2683
2733
  return [
2684
- 3,
2685
- 5
2734
+ 2
2686
2735
  ];
2687
- case 4:
2688
- error = _state.sent();
2689
- console.error("[StormcloudVideoPlayer] Error sending initial tracking data:", error);
2736
+ }
2737
+ });
2738
+ })();
2739
+ }
2740
+ function buildPlayerMetricEvent(_0) {
2741
+ return _async_to_generator(function(licenseKey) {
2742
+ var context, flags, _flags_captureAt, clientInfo, browserId, captureAt;
2743
+ var _arguments = arguments;
2744
+ return _ts_generator(this, function(_state) {
2745
+ switch(_state.label){
2746
+ case 0:
2747
+ context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {}, flags = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2748
+ clientInfo = getClientInfo();
2690
2749
  return [
2691
- 3,
2692
- 5
2750
+ 4,
2751
+ getBrowserID(clientInfo)
2693
2752
  ];
2694
- case 5:
2753
+ case 1:
2754
+ browserId = _state.sent();
2755
+ captureAt = (_flags_captureAt = flags.captureAt) !== null && _flags_captureAt !== void 0 ? _flags_captureAt : /* @__PURE__ */ new Date().toISOString();
2695
2756
  return [
2696
- 2
2757
+ 2,
2758
+ {
2759
+ player_id: browserId,
2760
+ browserId: browserId,
2761
+ device_type: clientInfo.deviceType,
2762
+ deviceType: clientInfo.deviceType,
2763
+ input_stream_type: context.inputStreamType,
2764
+ os: clientInfo.os,
2765
+ ad_loaded: flags.adLoaded,
2766
+ ad_detect: flags.adDetect,
2767
+ license_key: licenseKey,
2768
+ capture_at: captureAt,
2769
+ timestamp: captureAt
2770
+ }
2697
2771
  ];
2698
2772
  }
2699
2773
  });
2700
- })();
2774
+ }).apply(this, arguments);
2701
2775
  }
2702
- function sendHeartbeat(licenseKey) {
2703
- return _async_to_generator(function() {
2704
- var clientInfo, browserId, heartbeatData, headers, response, error;
2776
+ function sendInitialTracking(_0) {
2777
+ return _async_to_generator(function(licenseKey) {
2778
+ var context, clientInfo, browserId, trackingData, error;
2779
+ var _arguments = arguments;
2705
2780
  return _ts_generator(this, function(_state) {
2706
2781
  switch(_state.label){
2707
2782
  case 0:
2783
+ context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {};
2784
+ _state.label = 1;
2785
+ case 1:
2708
2786
  _state.trys.push([
2709
- 0,
2787
+ 1,
2710
2788
  4,
2711
2789
  ,
2712
2790
  5
@@ -2716,35 +2794,29 @@ function sendHeartbeat(licenseKey) {
2716
2794
  4,
2717
2795
  getBrowserID(clientInfo)
2718
2796
  ];
2719
- case 1:
2797
+ case 2:
2720
2798
  browserId = _state.sent();
2721
- heartbeatData = {
2722
- browserId: browserId,
2723
- timestamp: /* @__PURE__ */ new Date().toISOString()
2724
- };
2725
- headers = {
2726
- "Content-Type": "application/json"
2727
- };
2728
- if (licenseKey) {
2729
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2730
- }
2799
+ trackingData = _object_spread({
2800
+ browserId: browserId
2801
+ }, clientInfo);
2731
2802
  return [
2732
2803
  4,
2733
- fetch("https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/heartbeat", {
2734
- method: "POST",
2735
- headers: headers,
2736
- body: JSON.stringify(heartbeatData)
2804
+ sendTrackRequest(licenseKey, {
2805
+ events: [
2806
+ {
2807
+ player_id: browserId,
2808
+ device_type: clientInfo.deviceType,
2809
+ input_stream_type: context.inputStreamType,
2810
+ os: clientInfo.os,
2811
+ ad_loaded: false,
2812
+ ad_detect: false,
2813
+ license_key: licenseKey,
2814
+ capture_at: /* @__PURE__ */ new Date().toISOString()
2815
+ }
2816
+ ],
2817
+ trackingData: trackingData
2737
2818
  })
2738
2819
  ];
2739
- case 2:
2740
- response = _state.sent();
2741
- if (!response.ok) {
2742
- throw new Error("HTTP error! status: ".concat(response.status));
2743
- }
2744
- return [
2745
- 4,
2746
- response.json()
2747
- ];
2748
2820
  case 3:
2749
2821
  _state.sent();
2750
2822
  return [
@@ -2753,7 +2825,7 @@ function sendHeartbeat(licenseKey) {
2753
2825
  ];
2754
2826
  case 4:
2755
2827
  error = _state.sent();
2756
- console.error("[StormcloudVideoPlayer] Error sending heartbeat:", error);
2828
+ console.error("[StormcloudVideoPlayer] Error sending initial tracking data:", error);
2757
2829
  return [
2758
2830
  3,
2759
2831
  5
@@ -2764,95 +2836,74 @@ function sendHeartbeat(licenseKey) {
2764
2836
  ];
2765
2837
  }
2766
2838
  });
2767
- })();
2839
+ }).apply(this, arguments);
2768
2840
  }
2769
- var TRACK_API_URL = "https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/track";
2770
- function mapToAdTrackingSource(source, adPlayerType) {
2771
- if (source === "prebid" || source === "ima" || source === "hls") {
2772
- return source;
2773
- }
2774
- if (source === "preload" || source === "ssp") {
2775
- return source === "ssp" ? "prebid" : "ima";
2776
- }
2777
- return adPlayerType === "hls" ? "hls" : "ima";
2778
- }
2779
- function postAdTracking(licenseKey, body) {
2780
- return _async_to_generator(function() {
2781
- var headers, response;
2841
+ function sendAdDetectTracking(_0, _1) {
2842
+ return _async_to_generator(function(licenseKey, adDetectInfo) {
2843
+ var context, error;
2844
+ var _arguments = arguments;
2782
2845
  return _ts_generator(this, function(_state) {
2783
2846
  switch(_state.label){
2784
2847
  case 0:
2785
- headers = {
2786
- "Content-Type": "application/json"
2787
- };
2788
- if (licenseKey) {
2789
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2790
- }
2791
- return [
2792
- 4,
2793
- fetch(TRACK_API_URL, {
2794
- method: "POST",
2795
- headers: headers,
2796
- body: JSON.stringify(body)
2797
- })
2798
- ];
2848
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2849
+ _state.label = 1;
2799
2850
  case 1:
2800
- response = _state.sent();
2801
- if (!response.ok) {
2802
- throw new Error("HTTP error! status: ".concat(response.status));
2803
- }
2851
+ _state.trys.push([
2852
+ 1,
2853
+ 3,
2854
+ ,
2855
+ 4
2856
+ ]);
2804
2857
  return [
2805
2858
  4,
2806
- response.json()
2859
+ sendHeartbeat(licenseKey, context, {
2860
+ adDetect: true,
2861
+ captureAt: adDetectInfo.timestamp
2862
+ })
2807
2863
  ];
2808
2864
  case 2:
2809
2865
  _state.sent();
2866
+ return [
2867
+ 3,
2868
+ 4
2869
+ ];
2870
+ case 3:
2871
+ error = _state.sent();
2872
+ console.error("[StormcloudVideoPlayer] Error sending ad detect tracking:", error);
2873
+ return [
2874
+ 3,
2875
+ 4
2876
+ ];
2877
+ case 4:
2810
2878
  return [
2811
2879
  2
2812
2880
  ];
2813
2881
  }
2814
2882
  });
2815
- })();
2883
+ }).apply(this, arguments);
2816
2884
  }
2817
- function sendAdDetectTracking(licenseKey, payload) {
2818
- return _async_to_generator(function() {
2819
- var _payload_source, _payload_timestamp, clientInfo, browserId, adDetectInfo, body, error;
2885
+ function sendAdLoadedTracking(_0, _1) {
2886
+ return _async_to_generator(function(licenseKey, adLoadedInfo) {
2887
+ var context, error;
2888
+ var _arguments = arguments;
2820
2889
  return _ts_generator(this, function(_state) {
2821
2890
  switch(_state.label){
2822
2891
  case 0:
2892
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2893
+ _state.label = 1;
2894
+ case 1:
2823
2895
  _state.trys.push([
2824
- 0,
2896
+ 1,
2825
2897
  3,
2826
2898
  ,
2827
2899
  4
2828
2900
  ]);
2829
- clientInfo = getClientInfo();
2830
- return [
2831
- 4,
2832
- getBrowserID(clientInfo)
2833
- ];
2834
- case 1:
2835
- browserId = _state.sent();
2836
- adDetectInfo = _object_spread({
2837
- source: (_payload_source = payload.source) !== null && _payload_source !== void 0 ? _payload_source : "scte35",
2838
- timestamp: (_payload_timestamp = payload.timestamp) !== null && _payload_timestamp !== void 0 ? _payload_timestamp : /* @__PURE__ */ new Date().toISOString()
2839
- }, payload.durationSeconds != null && {
2840
- durationSeconds: payload.durationSeconds
2841
- }, payload.ptsSeconds != null && {
2842
- ptsSeconds: payload.ptsSeconds
2843
- }, payload.detectedAtFragmentSn != null && {
2844
- detectedAtFragmentSn: payload.detectedAtFragmentSn
2845
- });
2846
- body = _object_spread_props(_object_spread({
2847
- browserId: browserId
2848
- }, clientInfo, licenseKey && {
2849
- licenseKey: licenseKey
2850
- }), {
2851
- adDetectInfo: adDetectInfo
2852
- });
2853
2901
  return [
2854
2902
  4,
2855
- postAdTracking(licenseKey, body)
2903
+ sendHeartbeat(licenseKey, context, {
2904
+ adLoaded: true,
2905
+ captureAt: adLoadedInfo.timestamp
2906
+ })
2856
2907
  ];
2857
2908
  case 2:
2858
2909
  _state.sent();
@@ -2862,7 +2913,7 @@ function sendAdDetectTracking(licenseKey, payload) {
2862
2913
  ];
2863
2914
  case 3:
2864
2915
  error = _state.sent();
2865
- console.error("[StormcloudVideoPlayer] Error sending ad-detect tracking:", error);
2916
+ console.error("[StormcloudVideoPlayer] Error sending ad loaded tracking:", error);
2866
2917
  return [
2867
2918
  3,
2868
2919
  4
@@ -2873,126 +2924,116 @@ function sendAdDetectTracking(licenseKey, payload) {
2873
2924
  ];
2874
2925
  }
2875
2926
  });
2876
- })();
2927
+ }).apply(this, arguments);
2877
2928
  }
2878
- function sendAdLoadedTracking(licenseKey, payload, adPlayerType) {
2879
- return _async_to_generator(function() {
2880
- var clientInfo, browserId, source, adLoadedInfo, body, error;
2929
+ function sendAdImpressionTracking(_0, _1) {
2930
+ return _async_to_generator(function(licenseKey, adImpressionInfo) {
2931
+ var context, metricEvent, error;
2932
+ var _arguments = arguments;
2881
2933
  return _ts_generator(this, function(_state) {
2882
2934
  switch(_state.label){
2883
2935
  case 0:
2936
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2937
+ _state.label = 1;
2938
+ case 1:
2884
2939
  _state.trys.push([
2885
- 0,
2886
- 3,
2940
+ 1,
2941
+ 4,
2887
2942
  ,
2888
- 4
2943
+ 5
2889
2944
  ]);
2890
- clientInfo = getClientInfo();
2891
2945
  return [
2892
2946
  4,
2893
- getBrowserID(clientInfo)
2947
+ buildPlayerMetricEvent(licenseKey, context, {
2948
+ captureAt: adImpressionInfo.timestamp
2949
+ })
2894
2950
  ];
2895
- case 1:
2896
- browserId = _state.sent();
2897
- source = mapToAdTrackingSource(payload.source, adPlayerType);
2898
- adLoadedInfo = _object_spread({
2899
- source: source,
2900
- timestamp: /* @__PURE__ */ new Date().toISOString()
2901
- }, payload.vastUrl != null && {
2902
- vastUrl: payload.vastUrl
2903
- }, payload.durationSeconds != null && {
2904
- durationSeconds: payload.durationSeconds
2905
- });
2906
- body = _object_spread_props(_object_spread({
2907
- browserId: browserId
2908
- }, clientInfo, licenseKey && {
2909
- licenseKey: licenseKey
2910
- }), {
2911
- adLoadedInfo: adLoadedInfo
2912
- });
2951
+ case 2:
2952
+ metricEvent = _state.sent();
2913
2953
  return [
2914
2954
  4,
2915
- postAdTracking(licenseKey, body)
2955
+ Promise.all([
2956
+ postJson(HEARTBEAT_URL, licenseKey, metricEvent),
2957
+ postJson(IMPRESSIONS_URL, licenseKey, {
2958
+ events: [
2959
+ {
2960
+ player_id: metricEvent.player_id,
2961
+ ad_played_count: 1,
2962
+ ad_url: adImpressionInfo.adUrl,
2963
+ license_key: licenseKey,
2964
+ capture_at: adImpressionInfo.timestamp
2965
+ }
2966
+ ]
2967
+ })
2968
+ ])
2916
2969
  ];
2917
- case 2:
2970
+ case 3:
2918
2971
  _state.sent();
2919
2972
  return [
2920
2973
  3,
2921
- 4
2974
+ 5
2922
2975
  ];
2923
- case 3:
2976
+ case 4:
2924
2977
  error = _state.sent();
2925
- console.error("[StormcloudVideoPlayer] Error sending ad-loaded tracking:", error);
2978
+ console.error("[StormcloudVideoPlayer] Error sending ad impression tracking:", error);
2926
2979
  return [
2927
2980
  3,
2928
- 4
2981
+ 5
2929
2982
  ];
2930
- case 4:
2983
+ case 5:
2931
2984
  return [
2932
2985
  2
2933
2986
  ];
2934
2987
  }
2935
2988
  });
2936
- })();
2989
+ }).apply(this, arguments);
2937
2990
  }
2938
- function sendAdImpressionTracking(licenseKey, payload, adPlayerType) {
2939
- return _async_to_generator(function() {
2940
- var clientInfo, browserId, source, adImpressionInfo, body, error;
2991
+ function sendHeartbeat(_0) {
2992
+ return _async_to_generator(function(licenseKey) {
2993
+ var context, flags, heartbeatData, error;
2994
+ var _arguments = arguments;
2941
2995
  return _ts_generator(this, function(_state) {
2942
2996
  switch(_state.label){
2943
2997
  case 0:
2998
+ context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {}, flags = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2999
+ _state.label = 1;
3000
+ case 1:
2944
3001
  _state.trys.push([
2945
- 0,
2946
- 3,
3002
+ 1,
3003
+ 4,
2947
3004
  ,
2948
- 4
3005
+ 5
2949
3006
  ]);
2950
- clientInfo = getClientInfo();
2951
3007
  return [
2952
3008
  4,
2953
- getBrowserID(clientInfo)
3009
+ buildPlayerMetricEvent(licenseKey, context, flags)
2954
3010
  ];
2955
- case 1:
2956
- browserId = _state.sent();
2957
- source = mapToAdTrackingSource(payload.source, adPlayerType);
2958
- adImpressionInfo = _object_spread({
2959
- source: source,
2960
- adIndex: payload.adIndex,
2961
- timestamp: /* @__PURE__ */ new Date().toISOString()
2962
- }, payload.durationSeconds != null && {
2963
- durationSeconds: payload.durationSeconds
2964
- });
2965
- body = _object_spread_props(_object_spread({
2966
- browserId: browserId
2967
- }, clientInfo, licenseKey && {
2968
- licenseKey: licenseKey
2969
- }), {
2970
- adImpressionInfo: adImpressionInfo
2971
- });
3011
+ case 2:
3012
+ heartbeatData = _state.sent();
2972
3013
  return [
2973
3014
  4,
2974
- postAdTracking(licenseKey, body)
3015
+ postJson(HEARTBEAT_URL, licenseKey, heartbeatData)
2975
3016
  ];
2976
- case 2:
3017
+ case 3:
2977
3018
  _state.sent();
2978
3019
  return [
2979
3020
  3,
2980
- 4
3021
+ 5
2981
3022
  ];
2982
- case 3:
3023
+ case 4:
2983
3024
  error = _state.sent();
2984
- console.error("[StormcloudVideoPlayer] Error sending ad-impression tracking:", error);
3025
+ console.error("[StormcloudVideoPlayer] Error sending heartbeat:", error);
2985
3026
  return [
2986
3027
  3,
2987
- 4
3028
+ 5
2988
3029
  ];
2989
- case 4:
3030
+ case 5:
2990
3031
  return [
2991
3032
  2
2992
3033
  ];
2993
3034
  }
2994
3035
  });
2995
- })();
3036
+ }).apply(this, arguments);
2996
3037
  }
2997
3038
  // src/utils/polyfills.ts
2998
3039
  function polyfillURLSearchParams() {
@@ -3785,8 +3826,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3785
3826
  var _this = this;
3786
3827
  this.ima.on("all_ads_completed", function() {
3787
3828
  sendAdImpressionTracking(_this.config.licenseKey, {
3788
- adIndex: _this.currentAdIndex
3789
- }, _this.config.adPlayerType).catch(function() {});
3829
+ source: "ima",
3830
+ adIndex: _this.currentAdIndex,
3831
+ timestamp: /* @__PURE__ */ new Date().toISOString()
3832
+ }).catch(function() {});
3790
3833
  var remaining = _this.getRemainingAdMs();
3791
3834
  _this.consecutiveFailures = 0;
3792
3835
  if (_this.config.debugAdTiming) {
@@ -3847,8 +3890,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3847
3890
  });
3848
3891
  this.ima.on("content_resume", function() {
3849
3892
  sendAdImpressionTracking(_this.config.licenseKey, {
3850
- adIndex: _this.currentAdIndex
3851
- }, _this.config.adPlayerType).catch(function() {});
3893
+ source: "ima",
3894
+ adIndex: _this.currentAdIndex,
3895
+ timestamp: /* @__PURE__ */ new Date().toISOString()
3896
+ }).catch(function() {});
3852
3897
  if (!_this.video.muted) {
3853
3898
  _this.video.muted = true;
3854
3899
  _this.video.volume = 0;
@@ -4482,7 +4527,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4482
4527
  var detectPayload = {};
4483
4528
  if (marker.durationSeconds != null) detectPayload.durationSeconds = marker.durationSeconds;
4484
4529
  if (marker.ptsSeconds != null) detectPayload.ptsSeconds = marker.ptsSeconds;
4485
- sendAdDetectTracking(this.config.licenseKey, detectPayload).catch(function() {});
4530
+ sendAdDetectTracking(this.config.licenseKey, _object_spread({
4531
+ source: "scte35",
4532
+ timestamp: /* @__PURE__ */ new Date().toISOString()
4533
+ }, detectPayload)).catch(function() {});
4486
4534
  }
4487
4535
  var hasPrefetchedAds = this.pendingAdBreak && this.pendingAdBreak.vastUrls.length > 0;
4488
4536
  var durationMs = marker.durationSeconds != null ? marker.durationSeconds * 1e3 : ((_this_pendingAdBreak = this.pendingAdBreak) === null || _this_pendingAdBreak === void 0 ? void 0 : _this_pendingAdBreak.marker.durationSeconds) != null ? this.pendingAdBreak.marker.durationSeconds * 1e3 : void 0;
@@ -5724,7 +5772,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5724
5772
  if (marker.durationSeconds != null) detectPayload.durationSeconds = marker.durationSeconds;
5725
5773
  if (marker.ptsSeconds != null) detectPayload.ptsSeconds = marker.ptsSeconds;
5726
5774
  if (fragmentSn !== void 0) detectPayload.detectedAtFragmentSn = fragmentSn;
5727
- sendAdDetectTracking(this.config.licenseKey, detectPayload).catch(function() {});
5775
+ sendAdDetectTracking(this.config.licenseKey, _object_spread({
5776
+ source: "scte35",
5777
+ timestamp: /* @__PURE__ */ new Date().toISOString()
5778
+ }, detectPayload)).catch(function() {});
5728
5779
  if (this.config.debugAdTiming) {
5729
5780
  console.log("[PREFETCH] \uD83D\uDD04 Starting ad prefetch for upcoming ad break");
5730
5781
  console.log("[PREFETCH] \uD83D\uDCCB Pre-generated ".concat(generatedUrls.length, " VAST URLs"));
@@ -6205,9 +6256,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6205
6256
  preloadedController = preloaded.imaController;
6206
6257
  usePreloadedAd = true;
6207
6258
  sendAdLoadedTracking(this.config.licenseKey, {
6208
- source: "preload",
6209
- vastUrl: firstAdUrl
6210
- }, this.config.adPlayerType).catch(function() {});
6259
+ source: "ima",
6260
+ vastUrl: firstAdUrl,
6261
+ timestamp: /* @__PURE__ */ new Date().toISOString()
6262
+ }).catch(function() {});
6211
6263
  if (this.config.debugAdTiming) {
6212
6264
  console.log("[CONTINUOUS-FETCH] \uD83D\uDE80 Using preloaded ad from pool (preloaded in advance, ready immediately!)");
6213
6265
  console.log("[CONTINUOUS-FETCH] Pool still has ".concat(this.preloadPool.length, " preloaded ads ready"));
@@ -6297,9 +6349,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6297
6349
  case 5:
6298
6350
  _state.sent();
6299
6351
  sendAdLoadedTracking(this.config.licenseKey, {
6300
- source: "ssp",
6301
- vastUrl: firstAdUrl
6302
- }, this.config.adPlayerType).catch(function() {});
6352
+ source: "ima",
6353
+ vastUrl: firstAdUrl,
6354
+ timestamp: /* @__PURE__ */ new Date().toISOString()
6355
+ }).catch(function() {});
6303
6356
  if (this.config.debugAdTiming) {
6304
6357
  console.log("[CONTINUOUS-FETCH] \u2705 First ad request successful, starting playback");
6305
6358
  }
@@ -6695,9 +6748,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6695
6748
  console.log("[CONTINUOUS-FETCH] \uD83C\uDFAF Using preloaded ad from pool (".concat(this.preloadPool.length, " remaining in pool)"));
6696
6749
  }
6697
6750
  sendAdLoadedTracking(this.config.licenseKey, {
6698
- source: "preload",
6699
- vastUrl: preloaded.vastUrl
6700
- }, this.config.adPlayerType).catch(function() {});
6751
+ source: "ima",
6752
+ vastUrl: preloaded.vastUrl,
6753
+ timestamp: /* @__PURE__ */ new Date().toISOString()
6754
+ }).catch(function() {});
6701
6755
  _state.label = 1;
6702
6756
  case 1:
6703
6757
  _state.trys.push([
@@ -7449,9 +7503,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7449
7503
  case 3:
7450
7504
  _state.sent();
7451
7505
  sendAdLoadedTracking(this.config.licenseKey, {
7452
- source: "ssp",
7453
- vastUrl: vastTagUrl
7454
- }, this.config.adPlayerType).catch(function() {});
7506
+ source: "ima",
7507
+ vastUrl: vastTagUrl,
7508
+ timestamp: /* @__PURE__ */ new Date().toISOString()
7509
+ }).catch(function() {});
7455
7510
  this.clearAdRequestWatchdog();
7456
7511
  if (this.activeAdRequestToken !== requestToken) {
7457
7512
  return [