stormcloud-video-player 0.3.60 → 0.3.62

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.
@@ -2660,40 +2660,66 @@ function getBrowserID(clientInfo) {
2660
2660
  });
2661
2661
  })();
2662
2662
  }
2663
- 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) {
2664
2677
  return _async_to_generator(function() {
2665
- var clientInfo, browserId, trackingData, headers, response, error;
2678
+ var response;
2666
2679
  return _ts_generator(this, function(_state) {
2667
2680
  switch(_state.label){
2668
2681
  case 0:
2669
- _state.trys.push([
2670
- 0,
2671
- 4,
2672
- ,
2673
- 5
2674
- ]);
2675
- clientInfo = getClientInfo();
2676
2682
  return [
2677
2683
  4,
2678
- getBrowserID(clientInfo)
2684
+ fetch(TRACK_URL, {
2685
+ method: "POST",
2686
+ headers: buildHeaders(licenseKey),
2687
+ body: JSON.stringify(body)
2688
+ })
2679
2689
  ];
2680
2690
  case 1:
2681
- browserId = _state.sent();
2682
- trackingData = _object_spread({
2683
- browserId: browserId
2684
- }, clientInfo);
2685
- headers = {
2686
- "Content-Type": "application/json"
2687
- };
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:
2688
2714
  return [
2689
2715
  4,
2690
- fetch("https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/track", {
2716
+ fetch(url, {
2691
2717
  method: "POST",
2692
- headers: headers,
2693
- body: JSON.stringify(trackingData)
2718
+ headers: buildHeaders(licenseKey),
2719
+ body: JSON.stringify(body)
2694
2720
  })
2695
2721
  ];
2696
- case 2:
2722
+ case 1:
2697
2723
  response = _state.sent();
2698
2724
  if (!response.ok) {
2699
2725
  throw new Error("HTTP error! status: ".concat(response.status));
@@ -2702,35 +2728,63 @@ function sendInitialTracking(licenseKey) {
2702
2728
  4,
2703
2729
  response.json()
2704
2730
  ];
2705
- case 3:
2731
+ case 2:
2706
2732
  _state.sent();
2707
2733
  return [
2708
- 3,
2709
- 5
2734
+ 2
2710
2735
  ];
2711
- case 4:
2712
- error = _state.sent();
2713
- 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();
2714
2749
  return [
2715
- 3,
2716
- 5
2750
+ 4,
2751
+ getBrowserID(clientInfo)
2717
2752
  ];
2718
- 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();
2719
2756
  return [
2720
- 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
+ }
2721
2771
  ];
2722
2772
  }
2723
2773
  });
2724
- })();
2774
+ }).apply(this, arguments);
2725
2775
  }
2726
- function sendHeartbeat(licenseKey) {
2727
- return _async_to_generator(function() {
2728
- 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;
2729
2780
  return _ts_generator(this, function(_state) {
2730
2781
  switch(_state.label){
2731
2782
  case 0:
2783
+ context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {};
2784
+ _state.label = 1;
2785
+ case 1:
2732
2786
  _state.trys.push([
2733
- 0,
2787
+ 1,
2734
2788
  4,
2735
2789
  ,
2736
2790
  5
@@ -2740,35 +2794,29 @@ function sendHeartbeat(licenseKey) {
2740
2794
  4,
2741
2795
  getBrowserID(clientInfo)
2742
2796
  ];
2743
- case 1:
2797
+ case 2:
2744
2798
  browserId = _state.sent();
2745
- heartbeatData = {
2746
- browserId: browserId,
2747
- timestamp: /* @__PURE__ */ new Date().toISOString()
2748
- };
2749
- headers = {
2750
- "Content-Type": "application/json"
2751
- };
2752
- if (licenseKey) {
2753
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2754
- }
2799
+ trackingData = _object_spread({
2800
+ browserId: browserId
2801
+ }, clientInfo);
2755
2802
  return [
2756
2803
  4,
2757
- fetch("https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/heartbeat", {
2758
- method: "POST",
2759
- headers: headers,
2760
- 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
2761
2818
  })
2762
2819
  ];
2763
- case 2:
2764
- response = _state.sent();
2765
- if (!response.ok) {
2766
- throw new Error("HTTP error! status: ".concat(response.status));
2767
- }
2768
- return [
2769
- 4,
2770
- response.json()
2771
- ];
2772
2820
  case 3:
2773
2821
  _state.sent();
2774
2822
  return [
@@ -2777,7 +2825,7 @@ function sendHeartbeat(licenseKey) {
2777
2825
  ];
2778
2826
  case 4:
2779
2827
  error = _state.sent();
2780
- console.error("[StormcloudVideoPlayer] Error sending heartbeat:", error);
2828
+ console.error("[StormcloudVideoPlayer] Error sending initial tracking data:", error);
2781
2829
  return [
2782
2830
  3,
2783
2831
  5
@@ -2788,95 +2836,74 @@ function sendHeartbeat(licenseKey) {
2788
2836
  ];
2789
2837
  }
2790
2838
  });
2791
- })();
2839
+ }).apply(this, arguments);
2792
2840
  }
2793
- var TRACK_API_URL = "https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/track";
2794
- function mapToAdTrackingSource(source, adPlayerType) {
2795
- if (source === "prebid" || source === "ima" || source === "hls") {
2796
- return source;
2797
- }
2798
- if (source === "preload" || source === "ssp") {
2799
- return source === "ssp" ? "prebid" : "ima";
2800
- }
2801
- return adPlayerType === "hls" ? "hls" : "ima";
2802
- }
2803
- function postAdTracking(licenseKey, body) {
2804
- return _async_to_generator(function() {
2805
- var headers, response;
2841
+ function sendAdDetectTracking(_0, _1) {
2842
+ return _async_to_generator(function(licenseKey, adDetectInfo) {
2843
+ var context, error;
2844
+ var _arguments = arguments;
2806
2845
  return _ts_generator(this, function(_state) {
2807
2846
  switch(_state.label){
2808
2847
  case 0:
2809
- headers = {
2810
- "Content-Type": "application/json"
2811
- };
2812
- if (licenseKey) {
2813
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2814
- }
2815
- return [
2816
- 4,
2817
- fetch(TRACK_API_URL, {
2818
- method: "POST",
2819
- headers: headers,
2820
- body: JSON.stringify(body)
2821
- })
2822
- ];
2848
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2849
+ _state.label = 1;
2823
2850
  case 1:
2824
- response = _state.sent();
2825
- if (!response.ok) {
2826
- throw new Error("HTTP error! status: ".concat(response.status));
2827
- }
2851
+ _state.trys.push([
2852
+ 1,
2853
+ 3,
2854
+ ,
2855
+ 4
2856
+ ]);
2828
2857
  return [
2829
2858
  4,
2830
- response.json()
2859
+ sendHeartbeat(licenseKey, context, {
2860
+ adDetect: true,
2861
+ captureAt: adDetectInfo.timestamp
2862
+ })
2831
2863
  ];
2832
2864
  case 2:
2833
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:
2834
2878
  return [
2835
2879
  2
2836
2880
  ];
2837
2881
  }
2838
2882
  });
2839
- })();
2883
+ }).apply(this, arguments);
2840
2884
  }
2841
- function sendAdDetectTracking(licenseKey, payload) {
2842
- return _async_to_generator(function() {
2843
- 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;
2844
2889
  return _ts_generator(this, function(_state) {
2845
2890
  switch(_state.label){
2846
2891
  case 0:
2892
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2893
+ _state.label = 1;
2894
+ case 1:
2847
2895
  _state.trys.push([
2848
- 0,
2896
+ 1,
2849
2897
  3,
2850
2898
  ,
2851
2899
  4
2852
2900
  ]);
2853
- clientInfo = getClientInfo();
2854
- return [
2855
- 4,
2856
- getBrowserID(clientInfo)
2857
- ];
2858
- case 1:
2859
- browserId = _state.sent();
2860
- adDetectInfo = _object_spread({
2861
- source: (_payload_source = payload.source) !== null && _payload_source !== void 0 ? _payload_source : "scte35",
2862
- timestamp: (_payload_timestamp = payload.timestamp) !== null && _payload_timestamp !== void 0 ? _payload_timestamp : /* @__PURE__ */ new Date().toISOString()
2863
- }, payload.durationSeconds != null && {
2864
- durationSeconds: payload.durationSeconds
2865
- }, payload.ptsSeconds != null && {
2866
- ptsSeconds: payload.ptsSeconds
2867
- }, payload.detectedAtFragmentSn != null && {
2868
- detectedAtFragmentSn: payload.detectedAtFragmentSn
2869
- });
2870
- body = _object_spread_props(_object_spread({
2871
- browserId: browserId
2872
- }, clientInfo, licenseKey && {
2873
- licenseKey: licenseKey
2874
- }), {
2875
- adDetectInfo: adDetectInfo
2876
- });
2877
2901
  return [
2878
2902
  4,
2879
- postAdTracking(licenseKey, body)
2903
+ sendHeartbeat(licenseKey, context, {
2904
+ adLoaded: true,
2905
+ captureAt: adLoadedInfo.timestamp
2906
+ })
2880
2907
  ];
2881
2908
  case 2:
2882
2909
  _state.sent();
@@ -2886,7 +2913,7 @@ function sendAdDetectTracking(licenseKey, payload) {
2886
2913
  ];
2887
2914
  case 3:
2888
2915
  error = _state.sent();
2889
- console.error("[StormcloudVideoPlayer] Error sending ad-detect tracking:", error);
2916
+ console.error("[StormcloudVideoPlayer] Error sending ad loaded tracking:", error);
2890
2917
  return [
2891
2918
  3,
2892
2919
  4
@@ -2897,126 +2924,116 @@ function sendAdDetectTracking(licenseKey, payload) {
2897
2924
  ];
2898
2925
  }
2899
2926
  });
2900
- })();
2927
+ }).apply(this, arguments);
2901
2928
  }
2902
- function sendAdLoadedTracking(licenseKey, payload, adPlayerType) {
2903
- return _async_to_generator(function() {
2904
- 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;
2905
2933
  return _ts_generator(this, function(_state) {
2906
2934
  switch(_state.label){
2907
2935
  case 0:
2936
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2937
+ _state.label = 1;
2938
+ case 1:
2908
2939
  _state.trys.push([
2909
- 0,
2910
- 3,
2940
+ 1,
2941
+ 4,
2911
2942
  ,
2912
- 4
2943
+ 5
2913
2944
  ]);
2914
- clientInfo = getClientInfo();
2915
2945
  return [
2916
2946
  4,
2917
- getBrowserID(clientInfo)
2947
+ buildPlayerMetricEvent(licenseKey, context, {
2948
+ captureAt: adImpressionInfo.timestamp
2949
+ })
2918
2950
  ];
2919
- case 1:
2920
- browserId = _state.sent();
2921
- source = mapToAdTrackingSource(payload.source, adPlayerType);
2922
- adLoadedInfo = _object_spread({
2923
- source: source,
2924
- timestamp: /* @__PURE__ */ new Date().toISOString()
2925
- }, payload.vastUrl != null && {
2926
- vastUrl: payload.vastUrl
2927
- }, payload.durationSeconds != null && {
2928
- durationSeconds: payload.durationSeconds
2929
- });
2930
- body = _object_spread_props(_object_spread({
2931
- browserId: browserId
2932
- }, clientInfo, licenseKey && {
2933
- licenseKey: licenseKey
2934
- }), {
2935
- adLoadedInfo: adLoadedInfo
2936
- });
2951
+ case 2:
2952
+ metricEvent = _state.sent();
2937
2953
  return [
2938
2954
  4,
2939
- 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
+ ])
2940
2969
  ];
2941
- case 2:
2970
+ case 3:
2942
2971
  _state.sent();
2943
2972
  return [
2944
2973
  3,
2945
- 4
2974
+ 5
2946
2975
  ];
2947
- case 3:
2976
+ case 4:
2948
2977
  error = _state.sent();
2949
- console.error("[StormcloudVideoPlayer] Error sending ad-loaded tracking:", error);
2978
+ console.error("[StormcloudVideoPlayer] Error sending ad impression tracking:", error);
2950
2979
  return [
2951
2980
  3,
2952
- 4
2981
+ 5
2953
2982
  ];
2954
- case 4:
2983
+ case 5:
2955
2984
  return [
2956
2985
  2
2957
2986
  ];
2958
2987
  }
2959
2988
  });
2960
- })();
2989
+ }).apply(this, arguments);
2961
2990
  }
2962
- function sendAdImpressionTracking(licenseKey, payload, adPlayerType) {
2963
- return _async_to_generator(function() {
2964
- 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;
2965
2995
  return _ts_generator(this, function(_state) {
2966
2996
  switch(_state.label){
2967
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:
2968
3001
  _state.trys.push([
2969
- 0,
2970
- 3,
3002
+ 1,
3003
+ 4,
2971
3004
  ,
2972
- 4
3005
+ 5
2973
3006
  ]);
2974
- clientInfo = getClientInfo();
2975
3007
  return [
2976
3008
  4,
2977
- getBrowserID(clientInfo)
3009
+ buildPlayerMetricEvent(licenseKey, context, flags)
2978
3010
  ];
2979
- case 1:
2980
- browserId = _state.sent();
2981
- source = mapToAdTrackingSource(payload.source, adPlayerType);
2982
- adImpressionInfo = _object_spread({
2983
- source: source,
2984
- adIndex: payload.adIndex,
2985
- timestamp: /* @__PURE__ */ new Date().toISOString()
2986
- }, payload.durationSeconds != null && {
2987
- durationSeconds: payload.durationSeconds
2988
- });
2989
- body = _object_spread_props(_object_spread({
2990
- browserId: browserId
2991
- }, clientInfo, licenseKey && {
2992
- licenseKey: licenseKey
2993
- }), {
2994
- adImpressionInfo: adImpressionInfo
2995
- });
3011
+ case 2:
3012
+ heartbeatData = _state.sent();
2996
3013
  return [
2997
3014
  4,
2998
- postAdTracking(licenseKey, body)
3015
+ postJson(HEARTBEAT_URL, licenseKey, heartbeatData)
2999
3016
  ];
3000
- case 2:
3017
+ case 3:
3001
3018
  _state.sent();
3002
3019
  return [
3003
3020
  3,
3004
- 4
3021
+ 5
3005
3022
  ];
3006
- case 3:
3023
+ case 4:
3007
3024
  error = _state.sent();
3008
- console.error("[StormcloudVideoPlayer] Error sending ad-impression tracking:", error);
3025
+ console.error("[StormcloudVideoPlayer] Error sending heartbeat:", error);
3009
3026
  return [
3010
3027
  3,
3011
- 4
3028
+ 5
3012
3029
  ];
3013
- case 4:
3030
+ case 5:
3014
3031
  return [
3015
3032
  2
3016
3033
  ];
3017
3034
  }
3018
3035
  });
3019
- })();
3036
+ }).apply(this, arguments);
3020
3037
  }
3021
3038
  // src/utils/polyfills.ts
3022
3039
  function polyfillURLSearchParams() {
@@ -3372,7 +3389,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3372
3389
  key: "load",
3373
3390
  value: function load() {
3374
3391
  return _async_to_generator(function() {
3375
- var _this, error, _this_config_lowLatencyMode, _this_video_play;
3392
+ var _this, error, _this_config_isLiveStream, _this_config_lowLatencyMode, _this_video_play;
3376
3393
  return _ts_generator(this, function(_state) {
3377
3394
  switch(_state.label){
3378
3395
  case 0:
@@ -3416,7 +3433,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3416
3433
  this.nativeHlsMode = true;
3417
3434
  this.videoSrcProtection = this.config.src;
3418
3435
  this.video.src = this.config.src;
3419
- this.isLiveStream = (_this_config_lowLatencyMode = this.config.lowLatencyMode) !== null && _this_config_lowLatencyMode !== void 0 ? _this_config_lowLatencyMode : false;
3436
+ this.isLiveStream = (_this_config_isLiveStream = this.config.isLiveStream) !== null && _this_config_isLiveStream !== void 0 ? _this_config_isLiveStream : (_this_config_lowLatencyMode = this.config.lowLatencyMode) !== null && _this_config_lowLatencyMode !== void 0 ? _this_config_lowLatencyMode : false;
3420
3437
  if (this.config.debugAdTiming) {
3421
3438
  console.log("[StormcloudVideoPlayer] Using native HLS playback - VOD mode:", {
3422
3439
  isLive: this.isLiveStream,
@@ -3467,19 +3484,28 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3467
3484
  });
3468
3485
  this.hls.on(import_hls2.default.Events.MANIFEST_PARSED, function(_, data) {
3469
3486
  return _async_to_generator(function() {
3470
- var _this_config_minSegmentsBeforePlay, _ref, _this_hls_levels, _this_hls, adBehavior, minSegments, _this_video_play;
3487
+ var _this_config_isLiveStream, _ref, _this_config_minSegmentsBeforePlay, _this_hls_levels, _this_hls, prerollKey, adBehavior, minSegments, _this_video_play;
3471
3488
  return _ts_generator(this, function(_state) {
3472
3489
  switch(_state.label){
3473
3490
  case 0:
3474
- if (this.config.allowNativeHls === false) {
3475
- this.isLiveStream = true;
3476
- } else {
3477
- ;
3478
- ;
3479
- this.isLiveStream = (_ref = (_this_hls = this.hls) === null || _this_hls === void 0 ? void 0 : (_this_hls_levels = _this_hls.levels) === null || _this_hls_levels === void 0 ? void 0 : _this_hls_levels.some(function(level) {
3480
- var _level_details, _level_details1;
3481
- return (level === null || level === void 0 ? void 0 : (_level_details = level.details) === null || _level_details === void 0 ? void 0 : _level_details.live) === true || (level === null || level === void 0 ? void 0 : (_level_details1 = level.details) === null || _level_details1 === void 0 ? void 0 : _level_details1.type) === "LIVE";
3482
- })) !== null && _ref !== void 0 ? _ref : false;
3491
+ this.isLiveStream = (_this_config_isLiveStream = this.config.isLiveStream) !== null && _this_config_isLiveStream !== void 0 ? _this_config_isLiveStream : (_ref = (_this_hls = this.hls) === null || _this_hls === void 0 ? void 0 : (_this_hls_levels = _this_hls.levels) === null || _this_hls_levels === void 0 ? void 0 : _this_hls_levels.some(function(level) {
3492
+ var _level_details, _level_details1;
3493
+ return (level === null || level === void 0 ? void 0 : (_level_details = level.details) === null || _level_details === void 0 ? void 0 : _level_details.live) === true || (level === null || level === void 0 ? void 0 : (_level_details1 = level.details) === null || _level_details1 === void 0 ? void 0 : _level_details1.type) === "LIVE";
3494
+ })) !== null && _ref !== void 0 ? _ref : false;
3495
+ if (!this.isLiveStream && this.vmapBreaks.length === 0 && this.apiVastTagUrl) {
3496
+ prerollKey = "synthetic-vod-preroll";
3497
+ if (!this.consumedVmapBreakIds.has(prerollKey)) {
3498
+ this.vmapBreaks = [
3499
+ {
3500
+ id: prerollKey,
3501
+ startTimeMs: 0,
3502
+ vastTagUrl: this.apiVastTagUrl
3503
+ }
3504
+ ];
3505
+ if (this.config.debugAdTiming) {
3506
+ console.log("[StormcloudVideoPlayer] Injected synthetic VOD preroll from apiVastTagUrl");
3507
+ }
3508
+ }
3483
3509
  }
3484
3510
  if (this.config.debugAdTiming) {
3485
3511
  adBehavior = this.shouldContinueLiveStreamDuringAds() ? "live (main video continues muted during ads)" : "vod (main video pauses during ads)";
@@ -3809,8 +3835,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3809
3835
  var _this = this;
3810
3836
  this.ima.on("all_ads_completed", function() {
3811
3837
  sendAdImpressionTracking(_this.config.licenseKey, {
3812
- adIndex: _this.currentAdIndex
3813
- }, _this.config.adPlayerType).catch(function() {});
3838
+ source: "ima",
3839
+ adIndex: _this.currentAdIndex,
3840
+ timestamp: /* @__PURE__ */ new Date().toISOString()
3841
+ }).catch(function() {});
3814
3842
  var remaining = _this.getRemainingAdMs();
3815
3843
  _this.consecutiveFailures = 0;
3816
3844
  if (_this.config.debugAdTiming) {
@@ -3871,8 +3899,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3871
3899
  });
3872
3900
  this.ima.on("content_resume", function() {
3873
3901
  sendAdImpressionTracking(_this.config.licenseKey, {
3874
- adIndex: _this.currentAdIndex
3875
- }, _this.config.adPlayerType).catch(function() {});
3902
+ source: "ima",
3903
+ adIndex: _this.currentAdIndex,
3904
+ timestamp: /* @__PURE__ */ new Date().toISOString()
3905
+ }).catch(function() {});
3876
3906
  if (!_this.video.muted) {
3877
3907
  _this.video.muted = true;
3878
3908
  _this.video.volume = 0;
@@ -4506,7 +4536,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4506
4536
  var detectPayload = {};
4507
4537
  if (marker.durationSeconds != null) detectPayload.durationSeconds = marker.durationSeconds;
4508
4538
  if (marker.ptsSeconds != null) detectPayload.ptsSeconds = marker.ptsSeconds;
4509
- sendAdDetectTracking(this.config.licenseKey, detectPayload).catch(function() {});
4539
+ sendAdDetectTracking(this.config.licenseKey, _object_spread({
4540
+ source: "scte35",
4541
+ timestamp: /* @__PURE__ */ new Date().toISOString()
4542
+ }, detectPayload)).catch(function() {});
4510
4543
  }
4511
4544
  var hasPrefetchedAds = this.pendingAdBreak && this.pendingAdBreak.vastUrls.length > 0;
4512
4545
  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;
@@ -5748,7 +5781,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5748
5781
  if (marker.durationSeconds != null) detectPayload.durationSeconds = marker.durationSeconds;
5749
5782
  if (marker.ptsSeconds != null) detectPayload.ptsSeconds = marker.ptsSeconds;
5750
5783
  if (fragmentSn !== void 0) detectPayload.detectedAtFragmentSn = fragmentSn;
5751
- sendAdDetectTracking(this.config.licenseKey, detectPayload).catch(function() {});
5784
+ sendAdDetectTracking(this.config.licenseKey, _object_spread({
5785
+ source: "scte35",
5786
+ timestamp: /* @__PURE__ */ new Date().toISOString()
5787
+ }, detectPayload)).catch(function() {});
5752
5788
  if (this.config.debugAdTiming) {
5753
5789
  console.log("[PREFETCH] \uD83D\uDD04 Starting ad prefetch for upcoming ad break");
5754
5790
  console.log("[PREFETCH] \uD83D\uDCCB Pre-generated ".concat(generatedUrls.length, " VAST URLs"));
@@ -6229,9 +6265,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6229
6265
  preloadedController = preloaded.imaController;
6230
6266
  usePreloadedAd = true;
6231
6267
  sendAdLoadedTracking(this.config.licenseKey, {
6232
- source: "preload",
6233
- vastUrl: firstAdUrl
6234
- }, this.config.adPlayerType).catch(function() {});
6268
+ source: "ima",
6269
+ vastUrl: firstAdUrl,
6270
+ timestamp: /* @__PURE__ */ new Date().toISOString()
6271
+ }).catch(function() {});
6235
6272
  if (this.config.debugAdTiming) {
6236
6273
  console.log("[CONTINUOUS-FETCH] \uD83D\uDE80 Using preloaded ad from pool (preloaded in advance, ready immediately!)");
6237
6274
  console.log("[CONTINUOUS-FETCH] Pool still has ".concat(this.preloadPool.length, " preloaded ads ready"));
@@ -6321,9 +6358,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6321
6358
  case 5:
6322
6359
  _state.sent();
6323
6360
  sendAdLoadedTracking(this.config.licenseKey, {
6324
- source: "ssp",
6325
- vastUrl: firstAdUrl
6326
- }, this.config.adPlayerType).catch(function() {});
6361
+ source: "ima",
6362
+ vastUrl: firstAdUrl,
6363
+ timestamp: /* @__PURE__ */ new Date().toISOString()
6364
+ }).catch(function() {});
6327
6365
  if (this.config.debugAdTiming) {
6328
6366
  console.log("[CONTINUOUS-FETCH] \u2705 First ad request successful, starting playback");
6329
6367
  }
@@ -6719,9 +6757,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
6719
6757
  console.log("[CONTINUOUS-FETCH] \uD83C\uDFAF Using preloaded ad from pool (".concat(this.preloadPool.length, " remaining in pool)"));
6720
6758
  }
6721
6759
  sendAdLoadedTracking(this.config.licenseKey, {
6722
- source: "preload",
6723
- vastUrl: preloaded.vastUrl
6724
- }, this.config.adPlayerType).catch(function() {});
6760
+ source: "ima",
6761
+ vastUrl: preloaded.vastUrl,
6762
+ timestamp: /* @__PURE__ */ new Date().toISOString()
6763
+ }).catch(function() {});
6725
6764
  _state.label = 1;
6726
6765
  case 1:
6727
6766
  _state.trys.push([
@@ -7473,9 +7512,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7473
7512
  case 3:
7474
7513
  _state.sent();
7475
7514
  sendAdLoadedTracking(this.config.licenseKey, {
7476
- source: "ssp",
7477
- vastUrl: vastTagUrl
7478
- }, this.config.adPlayerType).catch(function() {});
7515
+ source: "ima",
7516
+ vastUrl: vastTagUrl,
7517
+ timestamp: /* @__PURE__ */ new Date().toISOString()
7518
+ }).catch(function() {});
7479
7519
  this.clearAdRequestWatchdog();
7480
7520
  if (this.activeAdRequestToken !== requestToken) {
7481
7521
  return [
@@ -7903,7 +7943,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7903
7943
  continue;
7904
7944
  }
7905
7945
  var end = breakStartMs + (b.durationMs || 0);
7906
- if (nowMs >= breakStartMs && (b.durationMs ? nowMs < end : nowMs <= breakStartMs + tol)) {
7946
+ var effectiveTol = breakStartMs === 0 ? Math.max(tol, 3e4) : tol;
7947
+ if (nowMs >= breakStartMs && (b.durationMs ? nowMs < end : nowMs <= breakStartMs + effectiveTol)) {
7907
7948
  return b;
7908
7949
  }
7909
7950
  }