stormcloud-video-player 0.8.13 → 0.8.14

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.
@@ -2288,6 +2288,20 @@ function generateCorrelator() {
2288
2288
  return String(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER) + 1);
2289
2289
  }
2290
2290
  var UNEXPANDED_MACRO_PATTERN = /^(\[[^\]]*\]|\{[^}]*\}|%%[^%]*%%)$/;
2291
+ var CTV_UNSUPPORTED_PARAMS = [
2292
+ "description_url",
2293
+ "tfcd",
2294
+ "npa",
2295
+ "min_ad_duration",
2296
+ "max_ad_duration",
2297
+ "unviewed_position_start",
2298
+ "impl",
2299
+ "scor",
2300
+ "vad_type",
2301
+ "gdpr",
2302
+ "gdpr_consent",
2303
+ "us_privacy"
2304
+ ];
2291
2305
  function applyVastMacros(baseUrl, ctx) {
2292
2306
  var url;
2293
2307
  try {
@@ -2297,16 +2311,42 @@ function applyVastMacros(baseUrl, ctx) {
2297
2311
  }
2298
2312
  var params = url.searchParams;
2299
2313
  params.set("correlator", ctx.correlator);
2300
- params.set("scor", ctx.streamCorrelator);
2314
+ if (ctx.isCtv) {
2315
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2316
+ try {
2317
+ for(var _iterator = CTV_UNSUPPORTED_PARAMS[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2318
+ var key = _step.value;
2319
+ params.delete(key);
2320
+ }
2321
+ } catch (err) {
2322
+ _didIteratorError = true;
2323
+ _iteratorError = err;
2324
+ } finally{
2325
+ try {
2326
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2327
+ _iterator.return();
2328
+ }
2329
+ } finally{
2330
+ if (_didIteratorError) {
2331
+ throw _iteratorError;
2332
+ }
2333
+ }
2334
+ }
2335
+ } else {
2336
+ params.set("scor", ctx.streamCorrelator);
2337
+ }
2301
2338
  if (ctx.pod != null) {
2302
2339
  params.set("pod", String(ctx.pod));
2303
2340
  }
2304
2341
  if (ctx.adPosition != null) {
2305
2342
  params.set("ppos", String(ctx.adPosition));
2306
2343
  }
2307
- if (ctx.pageUrl) {
2308
- params.set("url", ctx.pageUrl);
2309
- params.set("description_url", ctx.pageUrl);
2344
+ var requestUrl = ctx.contentUrl || ctx.pageUrl;
2345
+ if (requestUrl) {
2346
+ params.set("url", requestUrl);
2347
+ if (!ctx.isCtv) {
2348
+ params.set("description_url", requestUrl);
2349
+ }
2310
2350
  }
2311
2351
  if (ctx.adWillPlayMuted != null) {
2312
2352
  params.set("vpmute", ctx.adWillPlayMuted ? "1" : "0");
@@ -2314,6 +2354,20 @@ function applyVastMacros(baseUrl, ctx) {
2314
2354
  if (ctx.adWillAutoPlay != null) {
2315
2355
  params.set("vpa", ctx.adWillAutoPlay ? "auto" : "click");
2316
2356
  }
2357
+ if (ctx.appId) {
2358
+ params.set("msid", ctx.appId);
2359
+ }
2360
+ if (ctx.appName) {
2361
+ params.set("an", ctx.appName);
2362
+ }
2363
+ if (ctx.sessionId) {
2364
+ params.set("sid", ctx.sessionId);
2365
+ }
2366
+ if (ctx.deviceTypeHint != null) {
2367
+ params.set("dth", String(ctx.deviceTypeHint));
2368
+ } else if (ctx.isCtv) {
2369
+ params.set("dth", "5");
2370
+ }
2317
2371
  if (ctx.deviceId && ctx.deviceIdType) {
2318
2372
  params.set("rdid", ctx.deviceId);
2319
2373
  params.set("idtype", ctx.deviceIdType);
@@ -2323,15 +2377,17 @@ function applyVastMacros(baseUrl, ctx) {
2323
2377
  params.delete("idtype");
2324
2378
  params.delete("is_lat");
2325
2379
  }
2326
- var consent = ctx.consent;
2327
- if ((consent === null || consent === void 0 ? void 0 : consent.gdpr) != null) {
2328
- params.set("gdpr", consent.gdpr);
2329
- }
2330
- if ((consent === null || consent === void 0 ? void 0 : consent.gdprConsent) != null) {
2331
- params.set("gdpr_consent", consent.gdprConsent);
2332
- }
2333
- if ((consent === null || consent === void 0 ? void 0 : consent.usPrivacy) != null) {
2334
- params.set("us_privacy", consent.usPrivacy);
2380
+ if (!ctx.isCtv) {
2381
+ var consent = ctx.consent;
2382
+ if ((consent === null || consent === void 0 ? void 0 : consent.gdpr) != null) {
2383
+ params.set("gdpr", consent.gdpr);
2384
+ }
2385
+ if ((consent === null || consent === void 0 ? void 0 : consent.gdprConsent) != null) {
2386
+ params.set("gdpr_consent", consent.gdprConsent);
2387
+ }
2388
+ if ((consent === null || consent === void 0 ? void 0 : consent.usPrivacy) != null) {
2389
+ params.set("us_privacy", consent.usPrivacy);
2390
+ }
2335
2391
  }
2336
2392
  if (ctx.adTest) {
2337
2393
  params.set("adtest", "on");
@@ -2342,23 +2398,23 @@ function applyVastMacros(baseUrl, ctx) {
2342
2398
  staleKeys.push(key);
2343
2399
  }
2344
2400
  });
2345
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2401
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
2346
2402
  try {
2347
- for(var _iterator = staleKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2348
- var key = _step.value;
2349
- params.delete(key);
2403
+ for(var _iterator1 = staleKeys[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
2404
+ var key1 = _step1.value;
2405
+ params.delete(key1);
2350
2406
  }
2351
2407
  } catch (err) {
2352
- _didIteratorError = true;
2353
- _iteratorError = err;
2408
+ _didIteratorError1 = true;
2409
+ _iteratorError1 = err;
2354
2410
  } finally{
2355
2411
  try {
2356
- if (!_iteratorNormalCompletion && _iterator.return != null) {
2357
- _iterator.return();
2412
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
2413
+ _iterator1.return();
2358
2414
  }
2359
2415
  } finally{
2360
- if (_didIteratorError) {
2361
- throw _iteratorError;
2416
+ if (_didIteratorError1) {
2417
+ throw _iteratorError1;
2362
2418
  }
2363
2419
  }
2364
2420
  }
@@ -2598,6 +2654,262 @@ function logBrowserInfo() {
2598
2654
  userAgent: navigator.userAgent
2599
2655
  }));
2600
2656
  }
2657
+ // src/utils/ctvVastSignals.ts
2658
+ var AIRY_ANDROID_APP_ID = "com.freeairytv.android";
2659
+ var AIRY_APP_NAME = "AiryTV Movies & TV";
2660
+ var CTV_SESSION_STORAGE_KEY = "stormcloud.ctv.sid";
2661
+ var DEVICE_ID_STORAGE_KEYS = [
2662
+ "rdid",
2663
+ "ifa",
2664
+ "advertisingId",
2665
+ "advertising_id",
2666
+ "deviceAdvertisingId",
2667
+ "aaid",
2668
+ "adid",
2669
+ "rida",
2670
+ "tifa"
2671
+ ];
2672
+ function resolveCtvVastSignals() {
2673
+ var _ref, _bridgeSignals_limitAdTracking;
2674
+ var bridgeSignals = readNativeBridgeSignals();
2675
+ var deviceId = bridgeSignals.deviceId || readStoredDeviceId();
2676
+ var deviceIdType = bridgeSignals.deviceIdType || readStoredString("deviceIdType") || inferDeviceIdType();
2677
+ return _object_spread_props(_object_spread({
2678
+ contentUrl: "https://".concat(AIRY_ANDROID_APP_ID, ".example.com"),
2679
+ appId: AIRY_ANDROID_APP_ID,
2680
+ appName: AIRY_APP_NAME,
2681
+ sessionId: getOrCreateCtvSessionId()
2682
+ }, deviceId ? {
2683
+ deviceId: deviceId
2684
+ } : {}, deviceId && deviceIdType ? {
2685
+ deviceIdType: deviceIdType
2686
+ } : {}, deviceId ? {
2687
+ limitAdTracking: (_ref = (_bridgeSignals_limitAdTracking = bridgeSignals.limitAdTracking) !== null && _bridgeSignals_limitAdTracking !== void 0 ? _bridgeSignals_limitAdTracking : readStoredLimitAdTracking()) !== null && _ref !== void 0 ? _ref : false
2688
+ } : {}), {
2689
+ deviceTypeHint: 5
2690
+ });
2691
+ }
2692
+ function getOrCreateCtvSessionId() {
2693
+ var existing = readStoredString(CTV_SESSION_STORAGE_KEY);
2694
+ if (existing) {
2695
+ return existing;
2696
+ }
2697
+ var sessionId = createUuid();
2698
+ try {
2699
+ var _window_localStorage;
2700
+ (_window_localStorage = window.localStorage) === null || _window_localStorage === void 0 ? void 0 : _window_localStorage.setItem(CTV_SESSION_STORAGE_KEY, sessionId);
2701
+ } catch (unused) {}
2702
+ return sessionId;
2703
+ }
2704
+ function createUuid() {
2705
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
2706
+ return crypto.randomUUID();
2707
+ }
2708
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(char) {
2709
+ var value = Math.floor(Math.random() * 16);
2710
+ var nibble = char === "x" ? value : value & 3 | 8;
2711
+ return nibble.toString(16);
2712
+ });
2713
+ }
2714
+ function readNativeBridgeSignals() {
2715
+ if (typeof window === "undefined") {
2716
+ return {};
2717
+ }
2718
+ var candidates = [
2719
+ window.__STORMCLOUD_CTV_AD_INFO__,
2720
+ window.__STORMCLOUD_CTV__,
2721
+ window.stormcloudCtv,
2722
+ window.AiryTV,
2723
+ window.Android
2724
+ ].filter(Boolean);
2725
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2726
+ try {
2727
+ for(var _iterator = candidates[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2728
+ var source = _step.value;
2729
+ var deviceId = readBridgeValue(source, [
2730
+ "rdid",
2731
+ "ifa",
2732
+ "advertisingId",
2733
+ "adId",
2734
+ "deviceId"
2735
+ ]) || void 0;
2736
+ if (!deviceId) continue;
2737
+ var deviceIdType = readBridgeValue(source, [
2738
+ "idtype",
2739
+ "deviceIdType",
2740
+ "advertisingIdType"
2741
+ ]) || inferDeviceIdType();
2742
+ var limitAdTracking = readBridgeBoolean(source, [
2743
+ "is_lat",
2744
+ "limitAdTracking",
2745
+ "limitedAdTracking",
2746
+ "lat"
2747
+ ]);
2748
+ return _object_spread({
2749
+ deviceId: deviceId
2750
+ }, deviceIdType ? {
2751
+ deviceIdType: deviceIdType
2752
+ } : {}, limitAdTracking != null ? {
2753
+ limitAdTracking: limitAdTracking
2754
+ } : {});
2755
+ }
2756
+ } catch (err) {
2757
+ _didIteratorError = true;
2758
+ _iteratorError = err;
2759
+ } finally{
2760
+ try {
2761
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2762
+ _iterator.return();
2763
+ }
2764
+ } finally{
2765
+ if (_didIteratorError) {
2766
+ throw _iteratorError;
2767
+ }
2768
+ }
2769
+ }
2770
+ return {};
2771
+ }
2772
+ function readBridgeValue(source, keys) {
2773
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2774
+ try {
2775
+ for(var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2776
+ var key = _step.value;
2777
+ var value = source === null || source === void 0 ? void 0 : source[key];
2778
+ if (typeof value === "string" && value) {
2779
+ return value;
2780
+ }
2781
+ if (typeof value === "function") {
2782
+ try {
2783
+ var result = value.call(source);
2784
+ if (typeof result === "string" && result) {
2785
+ return result;
2786
+ }
2787
+ } catch (unused) {}
2788
+ }
2789
+ }
2790
+ } catch (err) {
2791
+ _didIteratorError = true;
2792
+ _iteratorError = err;
2793
+ } finally{
2794
+ try {
2795
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2796
+ _iterator.return();
2797
+ }
2798
+ } finally{
2799
+ if (_didIteratorError) {
2800
+ throw _iteratorError;
2801
+ }
2802
+ }
2803
+ }
2804
+ return void 0;
2805
+ }
2806
+ function readBridgeBoolean(source, keys) {
2807
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2808
+ try {
2809
+ for(var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2810
+ var key = _step.value;
2811
+ var value = source === null || source === void 0 ? void 0 : source[key];
2812
+ var normalized = normalizeBoolean(value);
2813
+ if (normalized != null) {
2814
+ return normalized;
2815
+ }
2816
+ if (typeof value === "function") {
2817
+ try {
2818
+ var result = normalizeBoolean(value.call(source));
2819
+ if (result != null) {
2820
+ return result;
2821
+ }
2822
+ } catch (unused) {}
2823
+ }
2824
+ }
2825
+ } catch (err) {
2826
+ _didIteratorError = true;
2827
+ _iteratorError = err;
2828
+ } finally{
2829
+ try {
2830
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2831
+ _iterator.return();
2832
+ }
2833
+ } finally{
2834
+ if (_didIteratorError) {
2835
+ throw _iteratorError;
2836
+ }
2837
+ }
2838
+ }
2839
+ return void 0;
2840
+ }
2841
+ function readStoredDeviceId() {
2842
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2843
+ try {
2844
+ for(var _iterator = DEVICE_ID_STORAGE_KEYS[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2845
+ var key = _step.value;
2846
+ var value = readStoredString(key);
2847
+ if (value) {
2848
+ return value;
2849
+ }
2850
+ }
2851
+ } catch (err) {
2852
+ _didIteratorError = true;
2853
+ _iteratorError = err;
2854
+ } finally{
2855
+ try {
2856
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2857
+ _iterator.return();
2858
+ }
2859
+ } finally{
2860
+ if (_didIteratorError) {
2861
+ throw _iteratorError;
2862
+ }
2863
+ }
2864
+ }
2865
+ return void 0;
2866
+ }
2867
+ function readStoredString(key) {
2868
+ if (typeof window === "undefined") {
2869
+ return void 0;
2870
+ }
2871
+ try {
2872
+ var _window_localStorage;
2873
+ var value = (_window_localStorage = window.localStorage) === null || _window_localStorage === void 0 ? void 0 : _window_localStorage.getItem(key);
2874
+ return value || void 0;
2875
+ } catch (unused) {
2876
+ return void 0;
2877
+ }
2878
+ }
2879
+ function readStoredLimitAdTracking() {
2880
+ return normalizeBoolean(readStoredString("limitAdTracking") || readStoredString("limitedAdTracking") || readStoredString("is_lat"));
2881
+ }
2882
+ function normalizeBoolean(value) {
2883
+ if (typeof value === "boolean") {
2884
+ return value;
2885
+ }
2886
+ if (typeof value === "number") {
2887
+ return value === 1;
2888
+ }
2889
+ if (typeof value === "string") {
2890
+ var normalized = value.toLowerCase();
2891
+ if (normalized === "1" || normalized === "true" || normalized === "yes") {
2892
+ return true;
2893
+ }
2894
+ if (normalized === "0" || normalized === "false" || normalized === "no") {
2895
+ return false;
2896
+ }
2897
+ }
2898
+ return void 0;
2899
+ }
2900
+ function inferDeviceIdType() {
2901
+ if (typeof navigator === "undefined") {
2902
+ return void 0;
2903
+ }
2904
+ var ua = navigator.userAgent;
2905
+ if (/Roku/i.test(ua)) return "rida";
2906
+ if (/Tizen|Samsung/i.test(ua)) return "tifa";
2907
+ if (/AppleTV/i.test(ua)) return "tvOS";
2908
+ if (/AFT|Fire TV|Amazon/i.test(ua)) return "afai";
2909
+ if (/Web0S|webOS|LG/i.test(ua)) return "lgudid";
2910
+ if (/Android|Google TV/i.test(ua)) return "aaid";
2911
+ return void 0;
2912
+ }
2601
2913
  // src/player/StormcloudVideoPlayer.ts
2602
2914
  var StormcloudVideoPlayer = /*#__PURE__*/ function() {
2603
2915
  function StormcloudVideoPlayer(config) {
@@ -5039,17 +5351,24 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5039
5351
  for(var i = 0; i < count; i++){
5040
5352
  this.adRequestPositionInBreak++;
5041
5353
  var adWillPlayMuted = this.inAdBreak ? this.adPlayer.getOriginalMutedState() : this.video.muted;
5354
+ var ctvSignals = this.config.ctvAdRequest ? resolveCtvVastSignals() : void 0;
5042
5355
  var urlWithMacros = applyVastMacros(baseUrl, {
5043
5356
  correlator: generateCorrelator(),
5044
5357
  streamCorrelator: this.streamCorrelator,
5045
5358
  pod: this.podCounter > 0 ? this.podCounter : void 0,
5046
5359
  adPosition: this.adRequestPositionInBreak,
5047
- pageUrl: typeof window !== "undefined" ? window.location.href : void 0,
5360
+ isCtv: this.config.ctvAdRequest,
5361
+ contentUrl: ctvSignals === null || ctvSignals === void 0 ? void 0 : ctvSignals.contentUrl,
5362
+ pageUrl: !this.config.ctvAdRequest && typeof window !== "undefined" ? window.location.href : void 0,
5048
5363
  adWillPlayMuted: adWillPlayMuted,
5049
5364
  adWillAutoPlay: !!this.config.autoplay,
5050
- deviceId: this.config.deviceId,
5051
- deviceIdType: this.config.deviceIdType,
5052
- limitAdTracking: this.config.limitAdTracking,
5365
+ appId: ctvSignals === null || ctvSignals === void 0 ? void 0 : ctvSignals.appId,
5366
+ appName: ctvSignals === null || ctvSignals === void 0 ? void 0 : ctvSignals.appName,
5367
+ sessionId: ctvSignals === null || ctvSignals === void 0 ? void 0 : ctvSignals.sessionId,
5368
+ deviceId: ctvSignals === null || ctvSignals === void 0 ? void 0 : ctvSignals.deviceId,
5369
+ deviceIdType: ctvSignals === null || ctvSignals === void 0 ? void 0 : ctvSignals.deviceIdType,
5370
+ limitAdTracking: ctvSignals === null || ctvSignals === void 0 ? void 0 : ctvSignals.limitAdTracking,
5371
+ deviceTypeHint: ctvSignals === null || ctvSignals === void 0 ? void 0 : ctvSignals.deviceTypeHint,
5053
5372
  adTest: this.config.adTest,
5054
5373
  consent: this.consentSignals
5055
5374
  });