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,5 +1,5 @@
1
1
  import { Component } from 'react';
2
- import { S as StormcloudVideoPlayerConfig } from '../types-DYelrVG6.cjs';
2
+ import { S as StormcloudVideoPlayerConfig } from '../types-C23mJ_hh.cjs';
3
3
 
4
4
  interface HlsPlayerProps extends StormcloudVideoPlayerConfig {
5
5
  onMount?: (player: any) => void;
@@ -2697,9 +2697,6 @@ function sendInitialTracking(licenseKey) {
2697
2697
  headers = {
2698
2698
  "Content-Type": "application/json"
2699
2699
  };
2700
- if (licenseKey) {
2701
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2702
- }
2703
2700
  return [
2704
2701
  4,
2705
2702
  fetch("https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/track", {
@@ -2805,6 +2802,234 @@ function sendHeartbeat(licenseKey) {
2805
2802
  });
2806
2803
  })();
2807
2804
  }
2805
+ var TRACK_API_URL = "https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/track";
2806
+ function mapToAdTrackingSource(source, adPlayerType) {
2807
+ if (source === "prebid" || source === "ima" || source === "hls") {
2808
+ return source;
2809
+ }
2810
+ if (source === "preload" || source === "ssp") {
2811
+ return source === "ssp" ? "prebid" : "ima";
2812
+ }
2813
+ return adPlayerType === "hls" ? "hls" : "ima";
2814
+ }
2815
+ function postAdTracking(licenseKey, body) {
2816
+ return _async_to_generator(function() {
2817
+ var headers, response;
2818
+ return _ts_generator(this, function(_state) {
2819
+ switch(_state.label){
2820
+ case 0:
2821
+ headers = {
2822
+ "Content-Type": "application/json"
2823
+ };
2824
+ if (licenseKey) {
2825
+ headers["Authorization"] = "Bearer ".concat(licenseKey);
2826
+ }
2827
+ return [
2828
+ 4,
2829
+ fetch(TRACK_API_URL, {
2830
+ method: "POST",
2831
+ headers: headers,
2832
+ body: JSON.stringify(body)
2833
+ })
2834
+ ];
2835
+ case 1:
2836
+ response = _state.sent();
2837
+ if (!response.ok) {
2838
+ throw new Error("HTTP error! status: ".concat(response.status));
2839
+ }
2840
+ return [
2841
+ 4,
2842
+ response.json()
2843
+ ];
2844
+ case 2:
2845
+ _state.sent();
2846
+ return [
2847
+ 2
2848
+ ];
2849
+ }
2850
+ });
2851
+ })();
2852
+ }
2853
+ function sendAdDetectTracking(licenseKey, payload) {
2854
+ return _async_to_generator(function() {
2855
+ var _payload_source, _payload_timestamp, clientInfo, browserId, adDetectInfo, body, error;
2856
+ return _ts_generator(this, function(_state) {
2857
+ switch(_state.label){
2858
+ case 0:
2859
+ _state.trys.push([
2860
+ 0,
2861
+ 3,
2862
+ ,
2863
+ 4
2864
+ ]);
2865
+ clientInfo = getClientInfo();
2866
+ return [
2867
+ 4,
2868
+ getBrowserID(clientInfo)
2869
+ ];
2870
+ case 1:
2871
+ browserId = _state.sent();
2872
+ adDetectInfo = _object_spread({
2873
+ source: (_payload_source = payload.source) !== null && _payload_source !== void 0 ? _payload_source : "scte35",
2874
+ timestamp: (_payload_timestamp = payload.timestamp) !== null && _payload_timestamp !== void 0 ? _payload_timestamp : /* @__PURE__ */ new Date().toISOString()
2875
+ }, payload.durationSeconds != null && {
2876
+ durationSeconds: payload.durationSeconds
2877
+ }, payload.ptsSeconds != null && {
2878
+ ptsSeconds: payload.ptsSeconds
2879
+ }, payload.detectedAtFragmentSn != null && {
2880
+ detectedAtFragmentSn: payload.detectedAtFragmentSn
2881
+ });
2882
+ body = _object_spread_props(_object_spread({
2883
+ browserId: browserId
2884
+ }, clientInfo, licenseKey && {
2885
+ licenseKey: licenseKey
2886
+ }), {
2887
+ adDetectInfo: adDetectInfo
2888
+ });
2889
+ return [
2890
+ 4,
2891
+ postAdTracking(licenseKey, body)
2892
+ ];
2893
+ case 2:
2894
+ _state.sent();
2895
+ return [
2896
+ 3,
2897
+ 4
2898
+ ];
2899
+ case 3:
2900
+ error = _state.sent();
2901
+ console.error("[StormcloudVideoPlayer] Error sending ad-detect tracking:", error);
2902
+ return [
2903
+ 3,
2904
+ 4
2905
+ ];
2906
+ case 4:
2907
+ return [
2908
+ 2
2909
+ ];
2910
+ }
2911
+ });
2912
+ })();
2913
+ }
2914
+ function sendAdLoadedTracking(licenseKey, payload, adPlayerType) {
2915
+ return _async_to_generator(function() {
2916
+ var clientInfo, browserId, source, adLoadedInfo, body, error;
2917
+ return _ts_generator(this, function(_state) {
2918
+ switch(_state.label){
2919
+ case 0:
2920
+ _state.trys.push([
2921
+ 0,
2922
+ 3,
2923
+ ,
2924
+ 4
2925
+ ]);
2926
+ clientInfo = getClientInfo();
2927
+ return [
2928
+ 4,
2929
+ getBrowserID(clientInfo)
2930
+ ];
2931
+ case 1:
2932
+ browserId = _state.sent();
2933
+ source = mapToAdTrackingSource(payload.source, adPlayerType);
2934
+ adLoadedInfo = _object_spread({
2935
+ source: source,
2936
+ timestamp: /* @__PURE__ */ new Date().toISOString()
2937
+ }, payload.vastUrl != null && {
2938
+ vastUrl: payload.vastUrl
2939
+ }, payload.durationSeconds != null && {
2940
+ durationSeconds: payload.durationSeconds
2941
+ });
2942
+ body = _object_spread_props(_object_spread({
2943
+ browserId: browserId
2944
+ }, clientInfo, licenseKey && {
2945
+ licenseKey: licenseKey
2946
+ }), {
2947
+ adLoadedInfo: adLoadedInfo
2948
+ });
2949
+ return [
2950
+ 4,
2951
+ postAdTracking(licenseKey, body)
2952
+ ];
2953
+ case 2:
2954
+ _state.sent();
2955
+ return [
2956
+ 3,
2957
+ 4
2958
+ ];
2959
+ case 3:
2960
+ error = _state.sent();
2961
+ console.error("[StormcloudVideoPlayer] Error sending ad-loaded tracking:", error);
2962
+ return [
2963
+ 3,
2964
+ 4
2965
+ ];
2966
+ case 4:
2967
+ return [
2968
+ 2
2969
+ ];
2970
+ }
2971
+ });
2972
+ })();
2973
+ }
2974
+ function sendAdImpressionTracking(licenseKey, payload, adPlayerType) {
2975
+ return _async_to_generator(function() {
2976
+ var clientInfo, browserId, source, adImpressionInfo, body, error;
2977
+ return _ts_generator(this, function(_state) {
2978
+ switch(_state.label){
2979
+ case 0:
2980
+ _state.trys.push([
2981
+ 0,
2982
+ 3,
2983
+ ,
2984
+ 4
2985
+ ]);
2986
+ clientInfo = getClientInfo();
2987
+ return [
2988
+ 4,
2989
+ getBrowserID(clientInfo)
2990
+ ];
2991
+ case 1:
2992
+ browserId = _state.sent();
2993
+ source = mapToAdTrackingSource(payload.source, adPlayerType);
2994
+ adImpressionInfo = _object_spread({
2995
+ source: source,
2996
+ adIndex: payload.adIndex,
2997
+ timestamp: /* @__PURE__ */ new Date().toISOString()
2998
+ }, payload.durationSeconds != null && {
2999
+ durationSeconds: payload.durationSeconds
3000
+ });
3001
+ body = _object_spread_props(_object_spread({
3002
+ browserId: browserId
3003
+ }, clientInfo, licenseKey && {
3004
+ licenseKey: licenseKey
3005
+ }), {
3006
+ adImpressionInfo: adImpressionInfo
3007
+ });
3008
+ return [
3009
+ 4,
3010
+ postAdTracking(licenseKey, body)
3011
+ ];
3012
+ case 2:
3013
+ _state.sent();
3014
+ return [
3015
+ 3,
3016
+ 4
3017
+ ];
3018
+ case 3:
3019
+ error = _state.sent();
3020
+ console.error("[StormcloudVideoPlayer] Error sending ad-impression tracking:", error);
3021
+ return [
3022
+ 3,
3023
+ 4
3024
+ ];
3025
+ case 4:
3026
+ return [
3027
+ 2
3028
+ ];
3029
+ }
3030
+ });
3031
+ })();
3032
+ }
2808
3033
  // src/utils/polyfills.ts
2809
3034
  function polyfillURLSearchParams() {
2810
3035
  if (typeof URLSearchParams !== "undefined") {
@@ -3105,6 +3330,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3105
3330
  this.maxPreloadPoolSize = 2;
3106
3331
  this.preloadPoolActive = false;
3107
3332
  this.preloadPoolLoopRunning = false;
3333
+ this.adDetectSentForCurrentBreak = false;
3108
3334
  this.continuousFetchLoopRunning = false;
3109
3335
  initializePolyfills();
3110
3336
  var browserOverrides = getBrowserConfigOverrides();
@@ -3574,6 +3800,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3574
3800
  value: function attachImaEventListeners() {
3575
3801
  var _this = this;
3576
3802
  this.ima.on("all_ads_completed", function() {
3803
+ sendAdImpressionTracking(_this.config.licenseKey, {
3804
+ adIndex: _this.currentAdIndex
3805
+ }, _this.config.adPlayerType).catch(function() {});
3577
3806
  var remaining = _this.getRemainingAdMs();
3578
3807
  _this.consecutiveFailures = 0;
3579
3808
  if (_this.config.debugAdTiming) {
@@ -3636,6 +3865,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3636
3865
  }
3637
3866
  });
3638
3867
  this.ima.on("content_resume", function() {
3868
+ sendAdImpressionTracking(_this.config.licenseKey, {
3869
+ adIndex: _this.currentAdIndex
3870
+ }, _this.config.adPlayerType).catch(function() {});
3639
3871
  if (!_this.video.muted) {
3640
3872
  _this.video.muted = true;
3641
3873
  _this.video.volume = 0;
@@ -4019,6 +4251,13 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4019
4251
  }
4020
4252
  return;
4021
4253
  }
4254
+ if (!this.adDetectSentForCurrentBreak) {
4255
+ this.adDetectSentForCurrentBreak = true;
4256
+ var detectPayload = {};
4257
+ if (marker.durationSeconds != null) detectPayload.durationSeconds = marker.durationSeconds;
4258
+ if (marker.ptsSeconds != null) detectPayload.ptsSeconds = marker.ptsSeconds;
4259
+ sendAdDetectTracking(this.config.licenseKey, detectPayload).catch(function() {});
4260
+ }
4022
4261
  var hasPrefetchedAds = this.pendingAdBreak && this.pendingAdBreak.vastUrls.length > 0;
4023
4262
  this.inAdBreak = true;
4024
4263
  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;
@@ -4576,6 +4815,12 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4576
4815
  isFetching: false,
4577
4816
  fetchStartTime: Date.now()
4578
4817
  });
4818
+ this.adDetectSentForCurrentBreak = true;
4819
+ var detectPayload = {};
4820
+ if (marker.durationSeconds != null) detectPayload.durationSeconds = marker.durationSeconds;
4821
+ if (marker.ptsSeconds != null) detectPayload.ptsSeconds = marker.ptsSeconds;
4822
+ if (fragmentSn !== void 0) detectPayload.detectedAtFragmentSn = fragmentSn;
4823
+ sendAdDetectTracking(this.config.licenseKey, detectPayload).catch(function() {});
4579
4824
  if (this.config.debugAdTiming) {
4580
4825
  console.log("[PREFETCH] \uD83D\uDD04 Starting ad prefetch for upcoming ad break");
4581
4826
  console.log("[PREFETCH] \uD83D\uDCCB Pre-generated ".concat(generatedUrls.length, " VAST URLs"));
@@ -5051,6 +5296,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5051
5296
  firstAdUrl = preloaded.vastUrl;
5052
5297
  preloadedController = preloaded.imaController;
5053
5298
  usePreloadedAd = true;
5299
+ sendAdLoadedTracking(this.config.licenseKey, {
5300
+ source: "preload",
5301
+ vastUrl: firstAdUrl
5302
+ }, this.config.adPlayerType).catch(function() {});
5054
5303
  if (this.config.debugAdTiming) {
5055
5304
  console.log("[CONTINUOUS-FETCH] \uD83D\uDE80 Using preloaded ad from pool (preloaded in advance, ready immediately!)");
5056
5305
  console.log("[CONTINUOUS-FETCH] Pool still has ".concat(this.preloadPool.length, " preloaded ads ready"));
@@ -5140,6 +5389,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5140
5389
  ];
5141
5390
  case 5:
5142
5391
  _state.sent();
5392
+ sendAdLoadedTracking(this.config.licenseKey, {
5393
+ source: "ssp",
5394
+ vastUrl: firstAdUrl
5395
+ }, this.config.adPlayerType).catch(function() {});
5143
5396
  if (this.config.debugAdTiming) {
5144
5397
  console.log("[CONTINUOUS-FETCH] \u2705 First ad request successful, starting playback");
5145
5398
  }
@@ -5536,6 +5789,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5536
5789
  if (this.config.debugAdTiming) {
5537
5790
  console.log("[CONTINUOUS-FETCH] \uD83C\uDFAF Using preloaded ad from pool (".concat(this.preloadPool.length, " remaining in pool)"));
5538
5791
  }
5792
+ sendAdLoadedTracking(this.config.licenseKey, {
5793
+ source: "preload",
5794
+ vastUrl: preloaded.vastUrl
5795
+ }, this.config.adPlayerType).catch(function() {});
5539
5796
  _state.label = 1;
5540
5797
  case 1:
5541
5798
  _state.trys.push([
@@ -6240,6 +6497,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6240
6497
  ];
6241
6498
  case 3:
6242
6499
  _state.sent();
6500
+ sendAdLoadedTracking(this.config.licenseKey, {
6501
+ source: "ssp",
6502
+ vastUrl: vastTagUrl
6503
+ }, this.config.adPlayerType).catch(function() {});
6243
6504
  this.clearAdRequestWatchdog();
6244
6505
  if (this.activeAdRequestToken !== requestToken) {
6245
6506
  return [
@@ -6454,6 +6715,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6454
6715
  }
6455
6716
  this.adRequestQueue = [];
6456
6717
  this.inAdBreak = false;
6718
+ this.adDetectSentForCurrentBreak = false;
6457
6719
  this.expectedAdBreakDurationMs = void 0;
6458
6720
  this.currentAdBreakStartWallClockMs = void 0;
6459
6721
  this.clearAdStartTimer();