stormcloud-video-player 0.3.54 → 0.3.55

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.
@@ -1,4 +1,4 @@
1
- import { S as StormcloudVideoPlayerConfig } from '../types-DYelrVG6.cjs';
1
+ import { S as StormcloudVideoPlayerConfig } from '../types-C23mJ_hh.cjs';
2
2
 
3
3
  declare class StormcloudVideoPlayer {
4
4
  private readonly video;
@@ -63,6 +63,7 @@ declare class StormcloudVideoPlayer {
63
63
  private readonly maxPreloadPoolSize;
64
64
  private preloadPoolActive;
65
65
  private preloadPoolLoopRunning;
66
+ private adDetectSentForCurrentBreak;
66
67
  constructor(config: StormcloudVideoPlayerConfig);
67
68
  private createAdPlayer;
68
69
  load(): Promise<void>;
@@ -2661,9 +2661,6 @@ function sendInitialTracking(licenseKey) {
2661
2661
  headers = {
2662
2662
  "Content-Type": "application/json"
2663
2663
  };
2664
- if (licenseKey) {
2665
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2666
- }
2667
2664
  return [
2668
2665
  4,
2669
2666
  fetch("https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/track", {
@@ -2769,6 +2766,234 @@ function sendHeartbeat(licenseKey) {
2769
2766
  });
2770
2767
  })();
2771
2768
  }
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;
2782
+ return _ts_generator(this, function(_state) {
2783
+ switch(_state.label){
2784
+ 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
+ ];
2799
+ case 1:
2800
+ response = _state.sent();
2801
+ if (!response.ok) {
2802
+ throw new Error("HTTP error! status: ".concat(response.status));
2803
+ }
2804
+ return [
2805
+ 4,
2806
+ response.json()
2807
+ ];
2808
+ case 2:
2809
+ _state.sent();
2810
+ return [
2811
+ 2
2812
+ ];
2813
+ }
2814
+ });
2815
+ })();
2816
+ }
2817
+ function sendAdDetectTracking(licenseKey, payload) {
2818
+ return _async_to_generator(function() {
2819
+ var _payload_source, _payload_timestamp, clientInfo, browserId, adDetectInfo, body, error;
2820
+ return _ts_generator(this, function(_state) {
2821
+ switch(_state.label){
2822
+ case 0:
2823
+ _state.trys.push([
2824
+ 0,
2825
+ 3,
2826
+ ,
2827
+ 4
2828
+ ]);
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
+ return [
2854
+ 4,
2855
+ postAdTracking(licenseKey, body)
2856
+ ];
2857
+ case 2:
2858
+ _state.sent();
2859
+ return [
2860
+ 3,
2861
+ 4
2862
+ ];
2863
+ case 3:
2864
+ error = _state.sent();
2865
+ console.error("[StormcloudVideoPlayer] Error sending ad-detect tracking:", error);
2866
+ return [
2867
+ 3,
2868
+ 4
2869
+ ];
2870
+ case 4:
2871
+ return [
2872
+ 2
2873
+ ];
2874
+ }
2875
+ });
2876
+ })();
2877
+ }
2878
+ function sendAdLoadedTracking(licenseKey, payload, adPlayerType) {
2879
+ return _async_to_generator(function() {
2880
+ var clientInfo, browserId, source, adLoadedInfo, body, error;
2881
+ return _ts_generator(this, function(_state) {
2882
+ switch(_state.label){
2883
+ case 0:
2884
+ _state.trys.push([
2885
+ 0,
2886
+ 3,
2887
+ ,
2888
+ 4
2889
+ ]);
2890
+ clientInfo = getClientInfo();
2891
+ return [
2892
+ 4,
2893
+ getBrowserID(clientInfo)
2894
+ ];
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
+ });
2913
+ return [
2914
+ 4,
2915
+ postAdTracking(licenseKey, body)
2916
+ ];
2917
+ case 2:
2918
+ _state.sent();
2919
+ return [
2920
+ 3,
2921
+ 4
2922
+ ];
2923
+ case 3:
2924
+ error = _state.sent();
2925
+ console.error("[StormcloudVideoPlayer] Error sending ad-loaded tracking:", error);
2926
+ return [
2927
+ 3,
2928
+ 4
2929
+ ];
2930
+ case 4:
2931
+ return [
2932
+ 2
2933
+ ];
2934
+ }
2935
+ });
2936
+ })();
2937
+ }
2938
+ function sendAdImpressionTracking(licenseKey, payload, adPlayerType) {
2939
+ return _async_to_generator(function() {
2940
+ var clientInfo, browserId, source, adImpressionInfo, body, error;
2941
+ return _ts_generator(this, function(_state) {
2942
+ switch(_state.label){
2943
+ case 0:
2944
+ _state.trys.push([
2945
+ 0,
2946
+ 3,
2947
+ ,
2948
+ 4
2949
+ ]);
2950
+ clientInfo = getClientInfo();
2951
+ return [
2952
+ 4,
2953
+ getBrowserID(clientInfo)
2954
+ ];
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
+ });
2972
+ return [
2973
+ 4,
2974
+ postAdTracking(licenseKey, body)
2975
+ ];
2976
+ case 2:
2977
+ _state.sent();
2978
+ return [
2979
+ 3,
2980
+ 4
2981
+ ];
2982
+ case 3:
2983
+ error = _state.sent();
2984
+ console.error("[StormcloudVideoPlayer] Error sending ad-impression tracking:", error);
2985
+ return [
2986
+ 3,
2987
+ 4
2988
+ ];
2989
+ case 4:
2990
+ return [
2991
+ 2
2992
+ ];
2993
+ }
2994
+ });
2995
+ })();
2996
+ }
2772
2997
  // src/utils/polyfills.ts
2773
2998
  function polyfillURLSearchParams() {
2774
2999
  if (typeof URLSearchParams !== "undefined") {
@@ -3069,6 +3294,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3069
3294
  this.maxPreloadPoolSize = 2;
3070
3295
  this.preloadPoolActive = false;
3071
3296
  this.preloadPoolLoopRunning = false;
3297
+ this.adDetectSentForCurrentBreak = false;
3072
3298
  this.continuousFetchLoopRunning = false;
3073
3299
  initializePolyfills();
3074
3300
  var browserOverrides = getBrowserConfigOverrides();
@@ -3538,6 +3764,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3538
3764
  value: function attachImaEventListeners() {
3539
3765
  var _this = this;
3540
3766
  this.ima.on("all_ads_completed", function() {
3767
+ sendAdImpressionTracking(_this.config.licenseKey, {
3768
+ adIndex: _this.currentAdIndex
3769
+ }, _this.config.adPlayerType).catch(function() {});
3541
3770
  var remaining = _this.getRemainingAdMs();
3542
3771
  _this.consecutiveFailures = 0;
3543
3772
  if (_this.config.debugAdTiming) {
@@ -3600,6 +3829,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3600
3829
  }
3601
3830
  });
3602
3831
  this.ima.on("content_resume", function() {
3832
+ sendAdImpressionTracking(_this.config.licenseKey, {
3833
+ adIndex: _this.currentAdIndex
3834
+ }, _this.config.adPlayerType).catch(function() {});
3603
3835
  if (!_this.video.muted) {
3604
3836
  _this.video.muted = true;
3605
3837
  _this.video.volume = 0;
@@ -3983,6 +4215,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3983
4215
  }
3984
4216
  return;
3985
4217
  }
4218
+ if (!this.adDetectSentForCurrentBreak) {
4219
+ this.adDetectSentForCurrentBreak = true;
4220
+ var detectPayload = {};
4221
+ if (marker.durationSeconds != null) detectPayload.durationSeconds = marker.durationSeconds;
4222
+ if (marker.ptsSeconds != null) detectPayload.ptsSeconds = marker.ptsSeconds;
4223
+ sendAdDetectTracking(this.config.licenseKey, detectPayload).catch(function() {});
4224
+ }
3986
4225
  var hasPrefetchedAds = this.pendingAdBreak && this.pendingAdBreak.vastUrls.length > 0;
3987
4226
  this.inAdBreak = true;
3988
4227
  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;
@@ -4540,6 +4779,12 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4540
4779
  isFetching: false,
4541
4780
  fetchStartTime: Date.now()
4542
4781
  });
4782
+ this.adDetectSentForCurrentBreak = true;
4783
+ var detectPayload = {};
4784
+ if (marker.durationSeconds != null) detectPayload.durationSeconds = marker.durationSeconds;
4785
+ if (marker.ptsSeconds != null) detectPayload.ptsSeconds = marker.ptsSeconds;
4786
+ if (fragmentSn !== void 0) detectPayload.detectedAtFragmentSn = fragmentSn;
4787
+ sendAdDetectTracking(this.config.licenseKey, detectPayload).catch(function() {});
4543
4788
  if (this.config.debugAdTiming) {
4544
4789
  console.log("[PREFETCH] \uD83D\uDD04 Starting ad prefetch for upcoming ad break");
4545
4790
  console.log("[PREFETCH] \uD83D\uDCCB Pre-generated ".concat(generatedUrls.length, " VAST URLs"));
@@ -5015,6 +5260,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5015
5260
  firstAdUrl = preloaded.vastUrl;
5016
5261
  preloadedController = preloaded.imaController;
5017
5262
  usePreloadedAd = true;
5263
+ sendAdLoadedTracking(this.config.licenseKey, {
5264
+ source: "preload",
5265
+ vastUrl: firstAdUrl
5266
+ }, this.config.adPlayerType).catch(function() {});
5018
5267
  if (this.config.debugAdTiming) {
5019
5268
  console.log("[CONTINUOUS-FETCH] \uD83D\uDE80 Using preloaded ad from pool (preloaded in advance, ready immediately!)");
5020
5269
  console.log("[CONTINUOUS-FETCH] Pool still has ".concat(this.preloadPool.length, " preloaded ads ready"));
@@ -5104,6 +5353,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5104
5353
  ];
5105
5354
  case 5:
5106
5355
  _state.sent();
5356
+ sendAdLoadedTracking(this.config.licenseKey, {
5357
+ source: "ssp",
5358
+ vastUrl: firstAdUrl
5359
+ }, this.config.adPlayerType).catch(function() {});
5107
5360
  if (this.config.debugAdTiming) {
5108
5361
  console.log("[CONTINUOUS-FETCH] \u2705 First ad request successful, starting playback");
5109
5362
  }
@@ -5500,6 +5753,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5500
5753
  if (this.config.debugAdTiming) {
5501
5754
  console.log("[CONTINUOUS-FETCH] \uD83C\uDFAF Using preloaded ad from pool (".concat(this.preloadPool.length, " remaining in pool)"));
5502
5755
  }
5756
+ sendAdLoadedTracking(this.config.licenseKey, {
5757
+ source: "preload",
5758
+ vastUrl: preloaded.vastUrl
5759
+ }, this.config.adPlayerType).catch(function() {});
5503
5760
  _state.label = 1;
5504
5761
  case 1:
5505
5762
  _state.trys.push([
@@ -6204,6 +6461,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6204
6461
  ];
6205
6462
  case 3:
6206
6463
  _state.sent();
6464
+ sendAdLoadedTracking(this.config.licenseKey, {
6465
+ source: "ssp",
6466
+ vastUrl: vastTagUrl
6467
+ }, this.config.adPlayerType).catch(function() {});
6207
6468
  this.clearAdRequestWatchdog();
6208
6469
  if (this.activeAdRequestToken !== requestToken) {
6209
6470
  return [
@@ -6418,6 +6679,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6418
6679
  }
6419
6680
  this.adRequestQueue = [];
6420
6681
  this.inAdBreak = false;
6682
+ this.adDetectSentForCurrentBreak = false;
6421
6683
  this.expectedAdBreakDurationMs = void 0;
6422
6684
  this.currentAdBreakStartWallClockMs = void 0;
6423
6685
  this.clearAdStartTimer();