stormcloud-video-player 0.8.18 → 0.8.20

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.
Files changed (48) hide show
  1. package/README.md +67 -83
  2. package/dist/stormcloud-vp.min.js +1 -1
  3. package/lib/index.cjs +686 -353
  4. package/lib/index.cjs.map +1 -1
  5. package/lib/index.d.cts +1 -1
  6. package/lib/index.d.ts +1 -1
  7. package/lib/index.js +686 -353
  8. package/lib/index.js.map +1 -1
  9. package/lib/player/AdBreakOrchestrator.cjs +11 -11
  10. package/lib/player/AdBreakOrchestrator.cjs.map +1 -1
  11. package/lib/player/AdBreakOrchestrator.d.cts +4 -4
  12. package/lib/player/{VmapManager.cjs → AdConfigManager.cjs} +561 -217
  13. package/lib/player/AdConfigManager.cjs.map +1 -0
  14. package/lib/player/{VmapManager.d.cts → AdConfigManager.d.cts} +3 -3
  15. package/lib/player/AdPreloadPool.d.cts +1 -1
  16. package/lib/player/AdTimingService.d.cts +1 -1
  17. package/lib/player/HlsEngine.d.cts +1 -1
  18. package/lib/player/PlayerControls.d.cts +1 -1
  19. package/lib/player/Scte35CueManager.d.cts +1 -1
  20. package/lib/player/Scte35Parser.d.cts +1 -1
  21. package/lib/player/StormcloudVideoPlayer.cjs +686 -353
  22. package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
  23. package/lib/player/StormcloudVideoPlayer.d.cts +2 -2
  24. package/lib/player/playerTypes.d.cts +1 -1
  25. package/lib/players/HlsPlayer.cjs +686 -353
  26. package/lib/players/HlsPlayer.cjs.map +1 -1
  27. package/lib/players/HlsPlayer.d.cts +1 -1
  28. package/lib/players/index.cjs +686 -353
  29. package/lib/players/index.cjs.map +1 -1
  30. package/lib/sdk/hlsAdPlayer.cjs +5 -4
  31. package/lib/sdk/hlsAdPlayer.cjs.map +1 -1
  32. package/lib/sdk/hlsAdPlayer.d.cts +1 -1
  33. package/lib/types-BAP8n5mE.d.cts +126 -0
  34. package/lib/ui/StormcloudVideoPlayer.cjs +686 -353
  35. package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
  36. package/lib/ui/StormcloudVideoPlayer.d.cts +1 -1
  37. package/lib/utils/ctvVastSignals.cjs +103 -33
  38. package/lib/utils/ctvVastSignals.cjs.map +1 -1
  39. package/lib/utils/ctvVastSignals.d.cts +1 -13
  40. package/lib/utils/tracking.d.cts +1 -1
  41. package/lib/utils/vastEnvironmentSignals.cjs +450 -0
  42. package/lib/utils/vastEnvironmentSignals.cjs.map +1 -0
  43. package/lib/utils/vastEnvironmentSignals.d.cts +16 -0
  44. package/lib/utils/vastMacros.cjs +347 -25
  45. package/lib/utils/vastMacros.cjs.map +1 -1
  46. package/lib/utils/vastMacros.d.cts +3 -1
  47. package/package.json +1 -1
  48. package/lib/player/VmapManager.cjs.map +0 -1
@@ -813,6 +813,7 @@ function createHlsAdPlayer(contentVideo, options) {
813
813
  handleAdComplete();
814
814
  });
815
815
  adVideoElement.addEventListener("error", function(e) {
816
+ if (!adPlaying) return;
816
817
  console.error("[HlsAdPlayer] Ad video error:", e);
817
818
  if (currentAd) {
818
819
  fireTrackingPixels(currentAd.trackingUrls.error);
@@ -1014,15 +1015,15 @@ function createHlsAdPlayer(contentVideo, options) {
1014
1015
  adVideoElement.muted = originalMutedState;
1015
1016
  console.log("[HlsAdPlayer] Set ad video volume to ".concat(adVideoElement.volume, ", muted: ").concat(adVideoElement.muted, ", originalMutedState: ").concat(originalMutedState, ", contentVolume: ").concat(contentVolume));
1016
1017
  }
1018
+ mediaFile = selectBestMediaFile(currentAd.mediaFiles);
1019
+ if (!mediaFile) {
1020
+ throw new Error("No media file available for ad");
1021
+ }
1017
1022
  if (adContainerEl) {
1018
1023
  adContainerEl.style.display = "flex";
1019
1024
  adContainerEl.style.pointerEvents = "auto";
1020
1025
  }
1021
1026
  emit("content_pause");
1022
- mediaFile = selectBestMediaFile(currentAd.mediaFiles);
1023
- if (!mediaFile) {
1024
- throw new Error("No media file available for ad");
1025
- }
1026
1027
  isHlsAd = isHlsMediaFile(mediaFile);
1027
1028
  console.log("[HlsAdPlayer] Loading ".concat(isHlsAd ? "HLS" : "progressive", " ad from: ").concat(mediaFile.url));
1028
1029
  if (isHlsAd && import_hls.default.isSupported()) {
@@ -2308,22 +2309,337 @@ function initializePolyfills() {
2308
2309
  polyfillTextEncoder();
2309
2310
  polyfillPromiseFinally();
2310
2311
  }
2311
- // src/utils/vastMacros.ts
2312
- function generateCorrelator() {
2313
- if (typeof crypto !== "undefined" && crypto.getRandomValues) {
2312
+ // src/utils/vastEnvironmentSignals.ts
2313
+ var AIRY_ANDROID_APP_ID = "com.freeairytv.android";
2314
+ var AIRY_WEBOS_APP_ID = "com.freeairytv.webos";
2315
+ var AIRY_TIZEN_APP_ID = "com.freeairytv.samsung";
2316
+ var AIRY_ROKU_APP_ID = "com.freeairytv.roku";
2317
+ var AIRY_APP_NAME = "AiryTV Movies & TV";
2318
+ var AIRY_DEFAULT_CONTENT_URL = "https://live.airy.tv";
2319
+ var CTV_SESSION_STORAGE_KEY = "stormcloud.ctv.sid";
2320
+ function getDefaultAppId() {
2321
+ if (typeof navigator === "undefined") return AIRY_ANDROID_APP_ID;
2322
+ var ua = navigator.userAgent;
2323
+ if (/Web0S|webOS|LG Browser|LGSTB|LGE/i.test(ua)) return AIRY_WEBOS_APP_ID;
2324
+ if (/Tizen|Samsung/i.test(ua)) return AIRY_TIZEN_APP_ID;
2325
+ if (/Roku/i.test(ua)) return AIRY_ROKU_APP_ID;
2326
+ return AIRY_ANDROID_APP_ID;
2327
+ }
2328
+ var DEVICE_ID_STORAGE_KEYS = [
2329
+ "rdid",
2330
+ "ifa",
2331
+ "advertisingId",
2332
+ "advertising_id",
2333
+ "deviceAdvertisingId",
2334
+ "aaid",
2335
+ "adid",
2336
+ "rida",
2337
+ "tifa",
2338
+ "lgudid"
2339
+ ];
2340
+ var ANDROID_ID_TYPES = /* @__PURE__ */ new Set([
2341
+ "aaid",
2342
+ "adid"
2343
+ ]);
2344
+ function resolveVastEnvironmentSignals(isCtv) {
2345
+ var _ref, _bridgeSignals_limitAdTracking;
2346
+ var bridgeSignals = readNativeBridgeSignals();
2347
+ var deviceId = bridgeSignals.deviceId || readStoredDeviceId();
2348
+ var deviceIdType = bridgeSignals.deviceIdType || readStoredString("deviceIdType") || readStoredString("idtype") || inferDeviceIdType();
2349
+ var limitAdTracking = deviceId != null ? (_ref = (_bridgeSignals_limitAdTracking = bridgeSignals.limitAdTracking) !== null && _bridgeSignals_limitAdTracking !== void 0 ? _bridgeSignals_limitAdTracking : readStoredLimitAdTracking()) !== null && _ref !== void 0 ? _ref : false : void 0;
2350
+ if (isCtv) {
2351
+ return _object_spread_props(_object_spread({
2352
+ isCtv: true,
2353
+ contentUrl: bridgeSignals.contentUrl || readStoredString("contentUrl") || AIRY_DEFAULT_CONTENT_URL,
2354
+ appId: bridgeSignals.appId || readStoredString("appId") || readStoredString("msid") || getDefaultAppId(),
2355
+ appName: bridgeSignals.appName || readStoredString("appName") || readStoredString("an") || AIRY_APP_NAME,
2356
+ sessionId: getOrCreateCtvSessionId()
2357
+ }, deviceId ? {
2358
+ deviceId: deviceId
2359
+ } : {}, deviceIdType ? {
2360
+ deviceIdType: deviceIdType
2361
+ } : {}, limitAdTracking != null ? {
2362
+ limitAdTracking: limitAdTracking
2363
+ } : {}), {
2364
+ deviceTypeHint: 5
2365
+ });
2366
+ }
2367
+ return _object_spread({
2368
+ isCtv: false
2369
+ }, deviceId ? {
2370
+ deviceId: deviceId
2371
+ } : {}, deviceIdType ? {
2372
+ deviceIdType: deviceIdType
2373
+ } : {}, limitAdTracking != null ? {
2374
+ limitAdTracking: limitAdTracking
2375
+ } : {});
2376
+ }
2377
+ function inferDeviceIdType() {
2378
+ if (typeof navigator === "undefined") {
2379
+ return void 0;
2380
+ }
2381
+ var ua = navigator.userAgent;
2382
+ if (/Roku/i.test(ua)) return "rida";
2383
+ if (/Tizen|Samsung/i.test(ua)) return "tifa";
2384
+ if (/AppleTV|Apple TV/i.test(ua)) return "tvOS";
2385
+ if (/AFT|Fire TV|Amazon/i.test(ua)) return "afai";
2386
+ if (/Web0S|webOS|LG Browser|LGSTB|LGE/i.test(ua)) return "lgudid";
2387
+ if (/Android|Google TV/i.test(ua)) return "aaid";
2388
+ if (/iPhone|iPad|iPod/i.test(ua)) return "idfa";
2389
+ return void 0;
2390
+ }
2391
+ function isEquivalentDeviceIdType(tagType, runtimeType) {
2392
+ if (!tagType || !runtimeType) return false;
2393
+ var tag = tagType.toLowerCase();
2394
+ var runtime = runtimeType.toLowerCase();
2395
+ if (tag === runtime) return true;
2396
+ return ANDROID_ID_TYPES.has(tag) && ANDROID_ID_TYPES.has(runtime);
2397
+ }
2398
+ function getOrCreateCtvSessionId() {
2399
+ var existing = readStoredString(CTV_SESSION_STORAGE_KEY);
2400
+ if (existing) {
2401
+ return existing;
2402
+ }
2403
+ var sessionId = createUuid();
2404
+ try {
2405
+ var _window_localStorage;
2406
+ (_window_localStorage = window.localStorage) === null || _window_localStorage === void 0 ? void 0 : _window_localStorage.setItem(CTV_SESSION_STORAGE_KEY, sessionId);
2407
+ } catch (unused) {}
2408
+ return sessionId;
2409
+ }
2410
+ function createUuid() {
2411
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
2412
+ return crypto.randomUUID();
2413
+ }
2414
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(char) {
2415
+ var value = Math.floor(Math.random() * 16);
2416
+ var nibble = char === "x" ? value : value & 3 | 8;
2417
+ return nibble.toString(16);
2418
+ });
2419
+ }
2420
+ function readNativeBridgeSignals() {
2421
+ if (typeof window === "undefined") {
2422
+ return {};
2423
+ }
2424
+ var candidates = [
2425
+ window.__STORMCLOUD_CTV_AD_INFO__,
2426
+ window.__STORMCLOUD_CTV__,
2427
+ window.stormcloudCtv,
2428
+ window.AiryTV,
2429
+ window.Android,
2430
+ window.webOS,
2431
+ window.tizen,
2432
+ window.amazon
2433
+ ].filter(Boolean);
2434
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2435
+ try {
2436
+ for(var _iterator = candidates[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2437
+ var source = _step.value;
2438
+ var contentUrl = readBridgeValue(source, [
2439
+ "contentUrl",
2440
+ "url",
2441
+ "videoUrl",
2442
+ "canonicalUrl"
2443
+ ]) || void 0;
2444
+ var appId = readBridgeValue(source, [
2445
+ "appId",
2446
+ "msid",
2447
+ "applicationId",
2448
+ "packageName"
2449
+ ]) || void 0;
2450
+ var appName = readBridgeValue(source, [
2451
+ "appName",
2452
+ "an",
2453
+ "applicationName"
2454
+ ]) || void 0;
2455
+ var deviceId = readBridgeValue(source, [
2456
+ "rdid",
2457
+ "ifa",
2458
+ "advertisingId",
2459
+ "adId",
2460
+ "deviceId",
2461
+ "lgudid",
2462
+ "LGUDID",
2463
+ "tifa",
2464
+ "rida",
2465
+ "afai",
2466
+ "aaid"
2467
+ ]) || void 0;
2468
+ if (!contentUrl && !deviceId && !appId && !appName) continue;
2469
+ var deviceIdType = readBridgeValue(source, [
2470
+ "idtype",
2471
+ "deviceIdType",
2472
+ "advertisingIdType",
2473
+ "idType"
2474
+ ]) || inferDeviceIdType();
2475
+ var limitAdTracking = readBridgeBoolean(source, [
2476
+ "is_lat",
2477
+ "limitAdTracking",
2478
+ "limitedAdTracking",
2479
+ "lat"
2480
+ ]);
2481
+ return _object_spread({}, contentUrl ? {
2482
+ contentUrl: contentUrl
2483
+ } : {}, appId ? {
2484
+ appId: appId
2485
+ } : {}, appName ? {
2486
+ appName: appName
2487
+ } : {}, deviceId ? {
2488
+ deviceId: deviceId
2489
+ } : {}, deviceId && deviceIdType ? {
2490
+ deviceIdType: deviceIdType
2491
+ } : {}, deviceId && limitAdTracking != null ? {
2492
+ limitAdTracking: limitAdTracking
2493
+ } : {});
2494
+ }
2495
+ } catch (err) {
2496
+ _didIteratorError = true;
2497
+ _iteratorError = err;
2498
+ } finally{
2314
2499
  try {
2315
- var _buf_, _buf_1;
2316
- var buf = new Uint32Array(2);
2317
- crypto.getRandomValues(buf);
2318
- var value = ((_buf_ = buf[0]) !== null && _buf_ !== void 0 ? _buf_ : 0) * 2097152 + (((_buf_1 = buf[1]) !== null && _buf_1 !== void 0 ? _buf_1 : 0) & 2097151);
2319
- if (value > 0) {
2320
- return String(value);
2500
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2501
+ _iterator.return();
2321
2502
  }
2322
- } catch (unused) {}
2503
+ } finally{
2504
+ if (_didIteratorError) {
2505
+ throw _iteratorError;
2506
+ }
2507
+ }
2323
2508
  }
2324
- return String(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER) + 1);
2509
+ return {};
2510
+ }
2511
+ function readBridgeValue(source, keys) {
2512
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2513
+ try {
2514
+ for(var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2515
+ var key = _step.value;
2516
+ var value = source === null || source === void 0 ? void 0 : source[key];
2517
+ if (typeof value === "string" && value) {
2518
+ return value;
2519
+ }
2520
+ if (typeof value === "function") {
2521
+ try {
2522
+ var result = value.call(source);
2523
+ if (typeof result === "string" && result) {
2524
+ return result;
2525
+ }
2526
+ } catch (unused) {}
2527
+ }
2528
+ }
2529
+ } catch (err) {
2530
+ _didIteratorError = true;
2531
+ _iteratorError = err;
2532
+ } finally{
2533
+ try {
2534
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2535
+ _iterator.return();
2536
+ }
2537
+ } finally{
2538
+ if (_didIteratorError) {
2539
+ throw _iteratorError;
2540
+ }
2541
+ }
2542
+ }
2543
+ return void 0;
2544
+ }
2545
+ function readBridgeBoolean(source, keys) {
2546
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2547
+ try {
2548
+ for(var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2549
+ var key = _step.value;
2550
+ var value = source === null || source === void 0 ? void 0 : source[key];
2551
+ var normalized = normalizeBoolean(value);
2552
+ if (normalized != null) {
2553
+ return normalized;
2554
+ }
2555
+ if (typeof value === "function") {
2556
+ try {
2557
+ var result = normalizeBoolean(value.call(source));
2558
+ if (result != null) {
2559
+ return result;
2560
+ }
2561
+ } catch (unused) {}
2562
+ }
2563
+ }
2564
+ } catch (err) {
2565
+ _didIteratorError = true;
2566
+ _iteratorError = err;
2567
+ } finally{
2568
+ try {
2569
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2570
+ _iterator.return();
2571
+ }
2572
+ } finally{
2573
+ if (_didIteratorError) {
2574
+ throw _iteratorError;
2575
+ }
2576
+ }
2577
+ }
2578
+ return void 0;
2579
+ }
2580
+ function readStoredDeviceId() {
2581
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2582
+ try {
2583
+ for(var _iterator = DEVICE_ID_STORAGE_KEYS[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2584
+ var key = _step.value;
2585
+ var value = readStoredString(key);
2586
+ if (value) {
2587
+ return value;
2588
+ }
2589
+ }
2590
+ } catch (err) {
2591
+ _didIteratorError = true;
2592
+ _iteratorError = err;
2593
+ } finally{
2594
+ try {
2595
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2596
+ _iterator.return();
2597
+ }
2598
+ } finally{
2599
+ if (_didIteratorError) {
2600
+ throw _iteratorError;
2601
+ }
2602
+ }
2603
+ }
2604
+ return void 0;
2605
+ }
2606
+ function readStoredString(key) {
2607
+ if (typeof window === "undefined") {
2608
+ return void 0;
2609
+ }
2610
+ try {
2611
+ var _window_localStorage;
2612
+ var value = (_window_localStorage = window.localStorage) === null || _window_localStorage === void 0 ? void 0 : _window_localStorage.getItem(key);
2613
+ return value || void 0;
2614
+ } catch (unused) {
2615
+ return void 0;
2616
+ }
2617
+ }
2618
+ function readStoredLimitAdTracking() {
2619
+ return normalizeBoolean(readStoredString("limitAdTracking") || readStoredString("limitedAdTracking") || readStoredString("is_lat"));
2620
+ }
2621
+ function normalizeBoolean(value) {
2622
+ if (typeof value === "boolean") {
2623
+ return value;
2624
+ }
2625
+ if (typeof value === "number") {
2626
+ return value === 1;
2627
+ }
2628
+ if (typeof value === "string") {
2629
+ var normalized = value.toLowerCase();
2630
+ if (normalized === "1" || normalized === "true" || normalized === "yes") {
2631
+ return true;
2632
+ }
2633
+ if (normalized === "0" || normalized === "false" || normalized === "no") {
2634
+ return false;
2635
+ }
2636
+ }
2637
+ return void 0;
2325
2638
  }
2639
+ // src/utils/vastMacros.ts
2326
2640
  var UNEXPANDED_MACRO_PATTERN = /^(\[[^\]]*\]|\{[^}]*\}|%%[^%]*%%)$/;
2641
+ var INVALID_VAST_PARAM_KEY = /^\s|\s$/;
2642
+ var EXAMPLE_COM_URL = /example\.com/i;
2327
2643
  var CTV_UNSUPPORTED_PARAMS = [
2328
2644
  "description_url",
2329
2645
  "tfcd",
@@ -2338,14 +2654,288 @@ var CTV_UNSUPPORTED_PARAMS = [
2338
2654
  "gdpr_consent",
2339
2655
  "us_privacy"
2340
2656
  ];
2657
+ var INLINE_DEVICE_MACRO_REPLACEMENTS = [
2658
+ {
2659
+ pattern: /\[RDID\]/gi,
2660
+ getValue: function getValue(ctx) {
2661
+ return ctx.deviceId;
2662
+ }
2663
+ },
2664
+ {
2665
+ pattern: /\[IFA\]/gi,
2666
+ getValue: function getValue(ctx) {
2667
+ return ctx.deviceId;
2668
+ }
2669
+ },
2670
+ {
2671
+ pattern: /\[ADVERTISING[_-]?ID(?:ENTIFIER)?\]/gi,
2672
+ getValue: function getValue(ctx) {
2673
+ return ctx.deviceId;
2674
+ }
2675
+ },
2676
+ {
2677
+ pattern: /\[DEVICE[_-]?ID\]/gi,
2678
+ getValue: function getValue(ctx) {
2679
+ return ctx.deviceId;
2680
+ }
2681
+ },
2682
+ {
2683
+ pattern: /\[IDTYPE\]/gi,
2684
+ getValue: function getValue(ctx) {
2685
+ return ctx.deviceIdType;
2686
+ }
2687
+ },
2688
+ {
2689
+ pattern: /\{rdid\}/gi,
2690
+ getValue: function getValue(ctx) {
2691
+ return ctx.deviceId;
2692
+ }
2693
+ },
2694
+ {
2695
+ pattern: /\{device[_-]?id\}/gi,
2696
+ getValue: function getValue(ctx) {
2697
+ return ctx.deviceId;
2698
+ }
2699
+ },
2700
+ {
2701
+ pattern: /\{idtype\}/gi,
2702
+ getValue: function getValue(ctx) {
2703
+ return ctx.deviceIdType;
2704
+ }
2705
+ },
2706
+ {
2707
+ pattern: /%%ADVERTISING_IDENTIFIER_PLAIN%%/gi,
2708
+ getValue: function getValue(ctx) {
2709
+ return ctx.deviceId;
2710
+ }
2711
+ },
2712
+ {
2713
+ pattern: /%%ADVERTISING_ID_OPT_OUT%%/gi,
2714
+ getValue: function getValue(ctx) {
2715
+ return ctx.limitAdTracking != null ? ctx.limitAdTracking ? "1" : "0" : void 0;
2716
+ }
2717
+ },
2718
+ {
2719
+ pattern: /%%ADVERTISING_ID_TYPE%%/gi,
2720
+ getValue: function getValue(ctx) {
2721
+ return ctx.deviceIdType;
2722
+ }
2723
+ },
2724
+ {
2725
+ pattern: /%%ADVERTISING_ID%%/gi,
2726
+ getValue: function getValue(ctx) {
2727
+ return ctx.deviceId;
2728
+ }
2729
+ },
2730
+ {
2731
+ pattern: /%%LIMIT_AD_TRACKING%%/gi,
2732
+ getValue: function getValue(ctx) {
2733
+ return ctx.limitAdTracking != null ? ctx.limitAdTracking ? "1" : "0" : void 0;
2734
+ }
2735
+ },
2736
+ {
2737
+ pattern: /%%MSID%%/gi,
2738
+ getValue: function getValue(ctx) {
2739
+ return ctx.appId;
2740
+ }
2741
+ },
2742
+ {
2743
+ pattern: /%%APP_NAME%%/gi,
2744
+ getValue: function getValue(ctx) {
2745
+ return ctx.appName;
2746
+ }
2747
+ },
2748
+ {
2749
+ pattern: /%%SESSION_ID%%/gi,
2750
+ getValue: function getValue(ctx) {
2751
+ return ctx.sessionId;
2752
+ }
2753
+ },
2754
+ {
2755
+ pattern: /%%CORRELATOR%%/gi,
2756
+ getValue: function getValue(ctx) {
2757
+ return ctx.correlator;
2758
+ }
2759
+ }
2760
+ ];
2761
+ function isMacroPlaceholder(value) {
2762
+ if (value == null) return true;
2763
+ var trimmed = value.trim();
2764
+ if (!trimmed) return true;
2765
+ if (UNEXPANDED_MACRO_PATTERN.test(trimmed)) return true;
2766
+ return /^(unknown|null|undefined|none|n\/a|\$\{[^}]+\})$/i.test(trimmed);
2767
+ }
2768
+ function generateCorrelator() {
2769
+ if (typeof crypto !== "undefined" && crypto.getRandomValues) {
2770
+ try {
2771
+ var _buf_, _buf_1;
2772
+ var buf = new Uint32Array(2);
2773
+ crypto.getRandomValues(buf);
2774
+ var value = ((_buf_ = buf[0]) !== null && _buf_ !== void 0 ? _buf_ : 0) * 2097152 + (((_buf_1 = buf[1]) !== null && _buf_1 !== void 0 ? _buf_1 : 0) & 2097151);
2775
+ if (value > 0) {
2776
+ return String(value);
2777
+ }
2778
+ } catch (unused) {}
2779
+ }
2780
+ return String(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER) + 1);
2781
+ }
2782
+ function expandInlineMacroPlaceholders(baseUrl, ctx) {
2783
+ var url = baseUrl;
2784
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2785
+ try {
2786
+ for(var _iterator = INLINE_DEVICE_MACRO_REPLACEMENTS[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2787
+ var _step_value = _step.value, pattern = _step_value.pattern, getValue = _step_value.getValue;
2788
+ var value = getValue(ctx);
2789
+ if (value != null && value !== "") {
2790
+ url = url.replace(pattern, encodeURIComponent(value));
2791
+ }
2792
+ }
2793
+ } catch (err) {
2794
+ _didIteratorError = true;
2795
+ _iteratorError = err;
2796
+ } finally{
2797
+ try {
2798
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2799
+ _iterator.return();
2800
+ }
2801
+ } finally{
2802
+ if (_didIteratorError) {
2803
+ throw _iteratorError;
2804
+ }
2805
+ }
2806
+ }
2807
+ return url;
2808
+ }
2809
+ function applyDeviceIdentityParams(params, ctx) {
2810
+ var _ctx_deviceId, _ctx_deviceIdType;
2811
+ var runtimeId = (_ctx_deviceId = ctx.deviceId) === null || _ctx_deviceId === void 0 ? void 0 : _ctx_deviceId.trim();
2812
+ var runtimeType = ((_ctx_deviceIdType = ctx.deviceIdType) === null || _ctx_deviceIdType === void 0 ? void 0 : _ctx_deviceIdType.trim()) || inferDeviceIdType();
2813
+ var tagRdid = params.get("rdid");
2814
+ var tagType = params.get("idtype");
2815
+ var tagLat = params.get("is_lat");
2816
+ var latValue = ctx.limitAdTracking != null ? ctx.limitAdTracking ? "1" : "0" : void 0;
2817
+ if (runtimeId) {
2818
+ params.set("rdid", runtimeId);
2819
+ params.set("idtype", runtimeType || tagType || "aaid");
2820
+ params.set("is_lat", latValue !== null && latValue !== void 0 ? latValue : isMacroPlaceholder(tagLat) ? "0" : tagLat);
2821
+ return;
2822
+ }
2823
+ var tagRdidValid = Boolean(tagRdid && !isMacroPlaceholder(tagRdid));
2824
+ var tagTypeValid = Boolean(tagType && !isMacroPlaceholder(tagType));
2825
+ if (tagRdidValid && tagTypeValid && runtimeType && !isEquivalentDeviceIdType(tagType, runtimeType)) {
2826
+ params.delete("rdid");
2827
+ params.delete("idtype");
2828
+ params.delete("is_lat");
2829
+ return;
2830
+ }
2831
+ if (tagRdidValid) {
2832
+ if (isMacroPlaceholder(tagType) && runtimeType) {
2833
+ params.set("idtype", runtimeType);
2834
+ }
2835
+ if (isMacroPlaceholder(tagLat)) {
2836
+ params.set("is_lat", latValue !== null && latValue !== void 0 ? latValue : "0");
2837
+ }
2838
+ return;
2839
+ }
2840
+ params.delete("rdid");
2841
+ params.delete("idtype");
2842
+ params.delete("is_lat");
2843
+ }
2844
+ function removeBrokenAppNameOrphans(params, appName) {
2845
+ var toDelete = [];
2846
+ params.forEach(function(_value, key) {
2847
+ if (!key || INVALID_VAST_PARAM_KEY.test(key)) {
2848
+ toDelete.push(key);
2849
+ }
2850
+ });
2851
+ if (appName && appName.includes("&")) {
2852
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
2853
+ try {
2854
+ for(var _iterator = appName.split("&").slice(1)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
2855
+ var suffix = _step.value;
2856
+ var trimmed = suffix.trimStart();
2857
+ if (!trimmed) continue;
2858
+ toDelete.push(suffix, " ".concat(trimmed), trimmed);
2859
+ }
2860
+ } catch (err) {
2861
+ _didIteratorError = true;
2862
+ _iteratorError = err;
2863
+ } finally{
2864
+ try {
2865
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
2866
+ _iterator.return();
2867
+ }
2868
+ } finally{
2869
+ if (_didIteratorError) {
2870
+ throw _iteratorError;
2871
+ }
2872
+ }
2873
+ }
2874
+ }
2875
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
2876
+ try {
2877
+ for(var _iterator1 = new Set(toDelete)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
2878
+ var key = _step1.value;
2879
+ if (key) params.delete(key);
2880
+ }
2881
+ } catch (err) {
2882
+ _didIteratorError1 = true;
2883
+ _iteratorError1 = err;
2884
+ } finally{
2885
+ try {
2886
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
2887
+ _iterator1.return();
2888
+ }
2889
+ } finally{
2890
+ if (_didIteratorError1) {
2891
+ throw _iteratorError1;
2892
+ }
2893
+ }
2894
+ }
2895
+ }
2896
+ function normalizeVastTagUrl(raw) {
2897
+ if (!raw) return raw;
2898
+ try {
2899
+ var url = new URL(raw);
2900
+ var anValue = url.searchParams.get("an");
2901
+ if (anValue !== null) {
2902
+ var orphanFragments = [];
2903
+ url.searchParams.forEach(function(_value, key) {
2904
+ if (key && INVALID_VAST_PARAM_KEY.test(key)) {
2905
+ orphanFragments.push(key.trim());
2906
+ }
2907
+ });
2908
+ if (orphanFragments.length > 0) {
2909
+ var reconstructed = [
2910
+ anValue.trimEnd()
2911
+ ].concat(_to_consumable_array(orphanFragments)).filter(Boolean).join(" & ");
2912
+ url.searchParams.forEach(function(_value, key) {
2913
+ if (key && INVALID_VAST_PARAM_KEY.test(key)) {
2914
+ url.searchParams.delete(key);
2915
+ }
2916
+ });
2917
+ url.searchParams.set("an", reconstructed);
2918
+ return url.toString().replace(/([?&]an=)([^&]*)/, function(_match, prefix, val) {
2919
+ return prefix + val.replace(/\+/g, "%20");
2920
+ });
2921
+ }
2922
+ }
2923
+ removeBrokenAppNameOrphans(url.searchParams);
2924
+ return url.toString();
2925
+ } catch (unused) {
2926
+ return raw;
2927
+ }
2928
+ }
2341
2929
  function applyVastMacros(baseUrl, ctx) {
2930
+ var expandedUrl = expandInlineMacroPlaceholders(baseUrl, ctx);
2342
2931
  var url;
2343
2932
  try {
2344
- url = new URL(baseUrl);
2933
+ url = new URL(normalizeVastTagUrl(expandedUrl));
2345
2934
  } catch (unused) {
2346
- return replaceCorrelatorFallback(baseUrl, ctx.correlator);
2935
+ return replaceCorrelatorFallback(expandedUrl, ctx.correlator);
2347
2936
  }
2348
2937
  var params = url.searchParams;
2938
+ removeBrokenAppNameOrphans(params, ctx.appName);
2349
2939
  params.set("correlator", ctx.correlator);
2350
2940
  if (ctx.isCtv) {
2351
2941
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
@@ -2383,6 +2973,12 @@ function applyVastMacros(baseUrl, ctx) {
2383
2973
  if (!ctx.isCtv) {
2384
2974
  params.set("description_url", requestUrl);
2385
2975
  }
2976
+ } else {
2977
+ var existingUrl = params.get("url") || "";
2978
+ if (EXAMPLE_COM_URL.test(existingUrl)) {
2979
+ params.delete("url");
2980
+ params.delete("description_url");
2981
+ }
2386
2982
  }
2387
2983
  if (ctx.adWillPlayMuted != null) {
2388
2984
  params.set("vpmute", ctx.adWillPlayMuted ? "1" : "0");
@@ -2394,6 +2990,7 @@ function applyVastMacros(baseUrl, ctx) {
2394
2990
  params.set("msid", ctx.appId);
2395
2991
  }
2396
2992
  if (ctx.appName) {
2993
+ removeBrokenAppNameOrphans(params, ctx.appName);
2397
2994
  params.set("an", ctx.appName);
2398
2995
  }
2399
2996
  if (ctx.sessionId) {
@@ -2404,15 +3001,7 @@ function applyVastMacros(baseUrl, ctx) {
2404
3001
  } else if (ctx.isCtv) {
2405
3002
  params.set("dth", "5");
2406
3003
  }
2407
- if (ctx.deviceId && ctx.deviceIdType) {
2408
- params.set("rdid", ctx.deviceId);
2409
- params.set("idtype", ctx.deviceIdType);
2410
- params.set("is_lat", ctx.limitAdTracking ? "1" : "0");
2411
- } else {
2412
- params.delete("rdid");
2413
- params.delete("idtype");
2414
- params.delete("is_lat");
2415
- }
3004
+ applyDeviceIdentityParams(params, ctx);
2416
3005
  if (!ctx.isCtv) {
2417
3006
  var consent = ctx.consent;
2418
3007
  if ((consent === null || consent === void 0 ? void 0 : consent.gdpr) != null) {
@@ -2430,7 +3019,7 @@ function applyVastMacros(baseUrl, ctx) {
2430
3019
  }
2431
3020
  var staleKeys = [];
2432
3021
  params.forEach(function(value, key) {
2433
- if (UNEXPANDED_MACRO_PATTERN.test(value)) {
3022
+ if (isMacroPlaceholder(value)) {
2434
3023
  staleKeys.push(key);
2435
3024
  }
2436
3025
  });
@@ -2454,6 +3043,7 @@ function applyVastMacros(baseUrl, ctx) {
2454
3043
  }
2455
3044
  }
2456
3045
  }
3046
+ removeBrokenAppNameOrphans(params, ctx.appName);
2457
3047
  return url.toString();
2458
3048
  }
2459
3049
  function replaceCorrelatorFallback(baseUrl, correlator) {
@@ -3704,276 +4294,10 @@ var Scte35CueManager = /*#__PURE__*/ function() {
3704
4294
  ]);
3705
4295
  return Scte35CueManager;
3706
4296
  }();
3707
- // src/utils/ctvVastSignals.ts
3708
- var AIRY_ANDROID_APP_ID = "com.freeairytv.android";
3709
- var AIRY_APP_NAME = "AiryTV Movies & TV";
3710
- var AIRY_DEFAULT_CONTENT_URL = "https://live.airy.tv";
3711
- var CTV_SESSION_STORAGE_KEY = "stormcloud.ctv.sid";
3712
- var DEVICE_ID_STORAGE_KEYS = [
3713
- "rdid",
3714
- "ifa",
3715
- "advertisingId",
3716
- "advertising_id",
3717
- "deviceAdvertisingId",
3718
- "aaid",
3719
- "adid",
3720
- "rida",
3721
- "tifa"
3722
- ];
3723
- function resolveCtvVastSignals() {
3724
- var _ref, _bridgeSignals_limitAdTracking;
3725
- var bridgeSignals = readNativeBridgeSignals();
3726
- var deviceId = bridgeSignals.deviceId || readStoredDeviceId();
3727
- var deviceIdType = bridgeSignals.deviceIdType || readStoredString("deviceIdType") || inferDeviceIdType();
3728
- var contentUrl = bridgeSignals.contentUrl || readStoredString("contentUrl") || AIRY_DEFAULT_CONTENT_URL;
3729
- return _object_spread_props(_object_spread({
3730
- contentUrl: contentUrl,
3731
- appId: AIRY_ANDROID_APP_ID,
3732
- appName: AIRY_APP_NAME,
3733
- sessionId: getOrCreateCtvSessionId()
3734
- }, deviceId ? {
3735
- deviceId: deviceId
3736
- } : {}, deviceId && deviceIdType ? {
3737
- deviceIdType: deviceIdType
3738
- } : {}, deviceId ? {
3739
- limitAdTracking: (_ref = (_bridgeSignals_limitAdTracking = bridgeSignals.limitAdTracking) !== null && _bridgeSignals_limitAdTracking !== void 0 ? _bridgeSignals_limitAdTracking : readStoredLimitAdTracking()) !== null && _ref !== void 0 ? _ref : false
3740
- } : {}), {
3741
- deviceTypeHint: 5
3742
- });
3743
- }
3744
- function getOrCreateCtvSessionId() {
3745
- var existing = readStoredString(CTV_SESSION_STORAGE_KEY);
3746
- if (existing) {
3747
- return existing;
3748
- }
3749
- var sessionId = createUuid();
3750
- try {
3751
- var _window_localStorage;
3752
- (_window_localStorage = window.localStorage) === null || _window_localStorage === void 0 ? void 0 : _window_localStorage.setItem(CTV_SESSION_STORAGE_KEY, sessionId);
3753
- } catch (unused) {}
3754
- return sessionId;
3755
- }
3756
- function createUuid() {
3757
- if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
3758
- return crypto.randomUUID();
3759
- }
3760
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(char) {
3761
- var value = Math.floor(Math.random() * 16);
3762
- var nibble = char === "x" ? value : value & 3 | 8;
3763
- return nibble.toString(16);
3764
- });
3765
- }
3766
- function readNativeBridgeSignals() {
3767
- if (typeof window === "undefined") {
3768
- return {};
3769
- }
3770
- var candidates = [
3771
- window.__STORMCLOUD_CTV_AD_INFO__,
3772
- window.__STORMCLOUD_CTV__,
3773
- window.stormcloudCtv,
3774
- window.AiryTV,
3775
- window.Android
3776
- ].filter(Boolean);
3777
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3778
- try {
3779
- for(var _iterator = candidates[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3780
- var source = _step.value;
3781
- var contentUrl = readBridgeValue(source, [
3782
- "contentUrl",
3783
- "url",
3784
- "videoUrl",
3785
- "canonicalUrl"
3786
- ]) || void 0;
3787
- var deviceId = readBridgeValue(source, [
3788
- "rdid",
3789
- "ifa",
3790
- "advertisingId",
3791
- "adId",
3792
- "deviceId"
3793
- ]) || void 0;
3794
- if (!contentUrl && !deviceId) continue;
3795
- var deviceIdType = readBridgeValue(source, [
3796
- "idtype",
3797
- "deviceIdType",
3798
- "advertisingIdType"
3799
- ]) || inferDeviceIdType();
3800
- var limitAdTracking = readBridgeBoolean(source, [
3801
- "is_lat",
3802
- "limitAdTracking",
3803
- "limitedAdTracking",
3804
- "lat"
3805
- ]);
3806
- return _object_spread({}, contentUrl ? {
3807
- contentUrl: contentUrl
3808
- } : {}, deviceId ? {
3809
- deviceId: deviceId
3810
- } : {}, deviceId && deviceIdType ? {
3811
- deviceIdType: deviceIdType
3812
- } : {}, deviceId && limitAdTracking != null ? {
3813
- limitAdTracking: limitAdTracking
3814
- } : {});
3815
- }
3816
- } catch (err) {
3817
- _didIteratorError = true;
3818
- _iteratorError = err;
3819
- } finally{
3820
- try {
3821
- if (!_iteratorNormalCompletion && _iterator.return != null) {
3822
- _iterator.return();
3823
- }
3824
- } finally{
3825
- if (_didIteratorError) {
3826
- throw _iteratorError;
3827
- }
3828
- }
3829
- }
3830
- return {};
3831
- }
3832
- function readBridgeValue(source, keys) {
3833
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3834
- try {
3835
- for(var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3836
- var key = _step.value;
3837
- var value = source === null || source === void 0 ? void 0 : source[key];
3838
- if (typeof value === "string" && value) {
3839
- return value;
3840
- }
3841
- if (typeof value === "function") {
3842
- try {
3843
- var result = value.call(source);
3844
- if (typeof result === "string" && result) {
3845
- return result;
3846
- }
3847
- } catch (unused) {}
3848
- }
3849
- }
3850
- } catch (err) {
3851
- _didIteratorError = true;
3852
- _iteratorError = err;
3853
- } finally{
3854
- try {
3855
- if (!_iteratorNormalCompletion && _iterator.return != null) {
3856
- _iterator.return();
3857
- }
3858
- } finally{
3859
- if (_didIteratorError) {
3860
- throw _iteratorError;
3861
- }
3862
- }
3863
- }
3864
- return void 0;
3865
- }
3866
- function readBridgeBoolean(source, keys) {
3867
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3868
- try {
3869
- for(var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3870
- var key = _step.value;
3871
- var value = source === null || source === void 0 ? void 0 : source[key];
3872
- var normalized = normalizeBoolean(value);
3873
- if (normalized != null) {
3874
- return normalized;
3875
- }
3876
- if (typeof value === "function") {
3877
- try {
3878
- var result = normalizeBoolean(value.call(source));
3879
- if (result != null) {
3880
- return result;
3881
- }
3882
- } catch (unused) {}
3883
- }
3884
- }
3885
- } catch (err) {
3886
- _didIteratorError = true;
3887
- _iteratorError = err;
3888
- } finally{
3889
- try {
3890
- if (!_iteratorNormalCompletion && _iterator.return != null) {
3891
- _iterator.return();
3892
- }
3893
- } finally{
3894
- if (_didIteratorError) {
3895
- throw _iteratorError;
3896
- }
3897
- }
3898
- }
3899
- return void 0;
3900
- }
3901
- function readStoredDeviceId() {
3902
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
3903
- try {
3904
- for(var _iterator = DEVICE_ID_STORAGE_KEYS[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
3905
- var key = _step.value;
3906
- var value = readStoredString(key);
3907
- if (value) {
3908
- return value;
3909
- }
3910
- }
3911
- } catch (err) {
3912
- _didIteratorError = true;
3913
- _iteratorError = err;
3914
- } finally{
3915
- try {
3916
- if (!_iteratorNormalCompletion && _iterator.return != null) {
3917
- _iterator.return();
3918
- }
3919
- } finally{
3920
- if (_didIteratorError) {
3921
- throw _iteratorError;
3922
- }
3923
- }
3924
- }
3925
- return void 0;
3926
- }
3927
- function readStoredString(key) {
3928
- if (typeof window === "undefined") {
3929
- return void 0;
3930
- }
3931
- try {
3932
- var _window_localStorage;
3933
- var value = (_window_localStorage = window.localStorage) === null || _window_localStorage === void 0 ? void 0 : _window_localStorage.getItem(key);
3934
- return value || void 0;
3935
- } catch (unused) {
3936
- return void 0;
3937
- }
3938
- }
3939
- function readStoredLimitAdTracking() {
3940
- return normalizeBoolean(readStoredString("limitAdTracking") || readStoredString("limitedAdTracking") || readStoredString("is_lat"));
3941
- }
3942
- function normalizeBoolean(value) {
3943
- if (typeof value === "boolean") {
3944
- return value;
3945
- }
3946
- if (typeof value === "number") {
3947
- return value === 1;
3948
- }
3949
- if (typeof value === "string") {
3950
- var normalized = value.toLowerCase();
3951
- if (normalized === "1" || normalized === "true" || normalized === "yes") {
3952
- return true;
3953
- }
3954
- if (normalized === "0" || normalized === "false" || normalized === "no") {
3955
- return false;
3956
- }
3957
- }
3958
- return void 0;
3959
- }
3960
- function inferDeviceIdType() {
3961
- if (typeof navigator === "undefined") {
3962
- return void 0;
3963
- }
3964
- var ua = navigator.userAgent;
3965
- if (/Roku/i.test(ua)) return "rida";
3966
- if (/Tizen|Samsung/i.test(ua)) return "tifa";
3967
- if (/AppleTV/i.test(ua)) return "tvOS";
3968
- if (/AFT|Fire TV|Amazon/i.test(ua)) return "afai";
3969
- if (/Web0S|webOS|LG/i.test(ua)) return "lgudid";
3970
- if (/Android|Google TV/i.test(ua)) return "aaid";
3971
- return void 0;
3972
- }
3973
- // src/player/VmapManager.ts
3974
- var VmapManager = /*#__PURE__*/ function() {
3975
- function VmapManager(config, video) {
3976
- _class_call_check(this, VmapManager);
4297
+ // src/player/AdConfigManager.ts
4298
+ var AdConfigManager = /*#__PURE__*/ function() {
4299
+ function AdConfigManager(config, video) {
4300
+ _class_call_check(this, AdConfigManager);
3977
4301
  this.vmapBreaks = [];
3978
4302
  this.consumedVmapBreakIds = /* @__PURE__ */ new Set();
3979
4303
  this.streamCorrelator = generateCorrelator();
@@ -3985,7 +4309,7 @@ var VmapManager = /*#__PURE__*/ function() {
3985
4309
  this.config = config;
3986
4310
  this.video = video;
3987
4311
  }
3988
- _create_class(VmapManager, [
4312
+ _create_class(AdConfigManager, [
3989
4313
  {
3990
4314
  key: "debug",
3991
4315
  get: function get() {
@@ -4003,7 +4327,7 @@ var VmapManager = /*#__PURE__*/ function() {
4003
4327
  key: "fetchAdConfiguration",
4004
4328
  value: function fetchAdConfiguration() {
4005
4329
  return _async_to_generator(function() {
4006
- var _data_response_ima_publisherdeskima, _data_response_ima, _data_response, _data_response_options_vast_cue_tones, _data_response_options_vast, _data_response_options, _data_response1, vastMode, vastEndpoint, apiUrl, headers, response, data, imaPayload, numberAds;
4330
+ var _data_response_ima_publisherdeskima, _data_response_ima, _data_response, _data_response_options_vast_cue_tones, _data_response_options_vast, _data_response_options, _data_response1, vastMode, vastEndpoint, apiUrl, headers, response, data, imaPayload, decodedPayload, numberAds;
4007
4331
  return _ts_generator(this, function(_state) {
4008
4332
  switch(_state.label){
4009
4333
  case 0:
@@ -4047,7 +4371,7 @@ var VmapManager = /*#__PURE__*/ function() {
4047
4371
  ];
4048
4372
  }
4049
4373
  if (this.config.vastTagUrl) {
4050
- this.apiVastTagUrl = this.config.vastTagUrl;
4374
+ this.apiVastTagUrl = normalizeVastTagUrl(this.config.vastTagUrl);
4051
4375
  if (this.debug) {
4052
4376
  console.log("[StormcloudVideoPlayer] Using custom VAST tag URL:", this.apiVastTagUrl);
4053
4377
  }
@@ -4087,9 +4411,16 @@ var VmapManager = /*#__PURE__*/ function() {
4087
4411
  data = _state.sent();
4088
4412
  imaPayload = (_data_response = data.response) === null || _data_response === void 0 ? void 0 : (_data_response_ima = _data_response.ima) === null || _data_response_ima === void 0 ? void 0 : (_data_response_ima_publisherdeskima = _data_response_ima["publisherdesk.ima"]) === null || _data_response_ima_publisherdeskima === void 0 ? void 0 : _data_response_ima_publisherdeskima.payload;
4089
4413
  if (imaPayload) {
4090
- this.apiVastTagUrl = decodeURIComponent(imaPayload);
4414
+ decodedPayload = imaPayload;
4415
+ try {
4416
+ decodedPayload = decodeURIComponent(imaPayload);
4417
+ } catch (unused) {
4418
+ console.warn("[StormcloudVideoPlayer] imaPayload was not URI-encoded; using as-is:", imaPayload);
4419
+ }
4420
+ console.log("[StormcloudVideoPlayer] Raw VAST tag URL (from API):", decodedPayload);
4421
+ this.apiVastTagUrl = normalizeVastTagUrl(decodedPayload);
4091
4422
  if (this.debug) {
4092
- console.log("[StormcloudVideoPlayer] Extracted VAST tag URL from /ads/web:", this.apiVastTagUrl);
4423
+ console.log("[StormcloudVideoPlayer] Normalized VAST tag URL:", this.apiVastTagUrl);
4093
4424
  }
4094
4425
  } else {
4095
4426
  if (this.debug) {
@@ -4402,28 +4733,30 @@ var VmapManager = /*#__PURE__*/ function() {
4402
4733
  for(var i = 0; i < count; i++){
4403
4734
  this.adRequestPositionInBreak++;
4404
4735
  var adWillPlayMuted = inAdBreak ? adPlayer.getOriginalMutedState() : this.video.muted;
4405
- var ctvSignals = this.config.ctvAdRequest ? resolveCtvVastSignals() : void 0;
4736
+ var envSignals = resolveVastEnvironmentSignals(!!this.config.ctvAdRequest);
4406
4737
  var urlWithMacros = applyVastMacros(baseUrl, {
4407
4738
  correlator: generateCorrelator(),
4408
4739
  streamCorrelator: this.streamCorrelator,
4409
4740
  pod: this.podCounter > 0 ? this.podCounter : void 0,
4410
4741
  adPosition: this.adRequestPositionInBreak,
4411
- isCtv: this.config.ctvAdRequest,
4412
- contentUrl: ctvSignals === null || ctvSignals === void 0 ? void 0 : ctvSignals.contentUrl,
4413
- pageUrl: !this.config.ctvAdRequest && typeof window !== "undefined" ? window.location.href : void 0,
4742
+ isCtv: envSignals.isCtv,
4743
+ contentUrl: envSignals.contentUrl,
4744
+ pageUrl: !envSignals.isCtv && typeof window !== "undefined" ? window.location.href : void 0,
4414
4745
  adWillPlayMuted: adWillPlayMuted,
4415
4746
  adWillAutoPlay: !!this.config.autoplay,
4416
- appId: ctvSignals === null || ctvSignals === void 0 ? void 0 : ctvSignals.appId,
4417
- appName: ctvSignals === null || ctvSignals === void 0 ? void 0 : ctvSignals.appName,
4418
- sessionId: ctvSignals === null || ctvSignals === void 0 ? void 0 : ctvSignals.sessionId,
4419
- deviceId: ctvSignals === null || ctvSignals === void 0 ? void 0 : ctvSignals.deviceId,
4420
- deviceIdType: ctvSignals === null || ctvSignals === void 0 ? void 0 : ctvSignals.deviceIdType,
4421
- limitAdTracking: ctvSignals === null || ctvSignals === void 0 ? void 0 : ctvSignals.limitAdTracking,
4422
- deviceTypeHint: ctvSignals === null || ctvSignals === void 0 ? void 0 : ctvSignals.deviceTypeHint,
4747
+ appId: envSignals.appId,
4748
+ appName: envSignals.appName,
4749
+ sessionId: envSignals.sessionId,
4750
+ deviceId: envSignals.deviceId,
4751
+ deviceIdType: envSignals.deviceIdType,
4752
+ limitAdTracking: envSignals.limitAdTracking,
4753
+ deviceTypeHint: envSignals.deviceTypeHint,
4423
4754
  adTest: this.config.adTest,
4424
4755
  consent: this.consentSignals
4425
4756
  });
4426
- urls.push(palNonce.injectNonce(urlWithMacros));
4757
+ var finalUrl = palNonce.injectNonce(urlWithMacros);
4758
+ console.log("[StormcloudVideoPlayer] Resolved ad request URL (pod=".concat(this.podCounter, ", pos=").concat(this.adRequestPositionInBreak, "):"), finalUrl);
4759
+ urls.push(finalUrl);
4427
4760
  }
4428
4761
  return urls;
4429
4762
  }
@@ -4472,7 +4805,7 @@ var VmapManager = /*#__PURE__*/ function() {
4472
4805
  }
4473
4806
  }
4474
4807
  ]);
4475
- return VmapManager;
4808
+ return AdConfigManager;
4476
4809
  }();
4477
4810
  // src/player/AdTimingService.ts
4478
4811
  var AdTimingService = /*#__PURE__*/ function() {
@@ -6199,7 +6532,7 @@ function resizePlayer(video, adPlayer, debug) {
6199
6532
  }
6200
6533
  // src/player/AdBreakOrchestrator.ts
6201
6534
  var AdBreakOrchestrator = /*#__PURE__*/ function() {
6202
- function AdBreakOrchestrator(host, timing, preloadPool, vmap, cueManager, placeholder) {
6535
+ function AdBreakOrchestrator(host, timing, preloadPool, adConfig, cueManager, placeholder) {
6203
6536
  _class_call_check(this, AdBreakOrchestrator);
6204
6537
  this.inAdBreak = false;
6205
6538
  this.showAds = false;
@@ -6214,7 +6547,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
6214
6547
  this.host = host;
6215
6548
  this.timing = timing;
6216
6549
  this.preloadPool = preloadPool;
6217
- this.vmap = vmap;
6550
+ this.adConfig = adConfig;
6218
6551
  this.cueManager = cueManager;
6219
6552
  this.placeholder = placeholder;
6220
6553
  }
@@ -6380,7 +6713,7 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
6380
6713
  }
6381
6714
  this.pendingAdBreak = null;
6382
6715
  this.cueManager.pendingScte35CueKey = void 0;
6383
- this.vmap.podAssignedByPrefetch = false;
6716
+ this.adConfig.podAssignedByPrefetch = false;
6384
6717
  }
6385
6718
  },
6386
6719
  {
@@ -6394,15 +6727,15 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
6394
6727
  return _ts_generator(this, function(_state) {
6395
6728
  switch(_state.label){
6396
6729
  case 0:
6397
- scheduled = this.vmap.findCurrentOrNextBreak(this.host.video.currentTime * 1e3);
6730
+ scheduled = this.adConfig.findCurrentOrNextBreak(this.host.video.currentTime * 1e3);
6398
6731
  if (scheduled) {
6399
- this.vmap.consumedVmapBreakIds.add(this.vmap.getAdBreakKey(scheduled));
6732
+ this.adConfig.consumedVmapBreakIds.add(this.adConfig.getAdBreakKey(scheduled));
6400
6733
  }
6401
- tags = this.vmap.selectVastTagsForBreak(scheduled);
6734
+ tags = this.adConfig.selectVastTagsForBreak(scheduled);
6402
6735
  if (tags && tags.length > 0 && tags[0]) {
6403
6736
  baseVastUrl = tags[0];
6404
- } else if (this.vmap.apiVastTagUrl) {
6405
- baseVastUrl = this.vmap.apiVastTagUrl;
6737
+ } else if (this.adConfig.apiVastTagUrl) {
6738
+ baseVastUrl = this.adConfig.apiVastTagUrl;
6406
6739
  } else {
6407
6740
  this.clearPendingAdBreak();
6408
6741
  return [
@@ -6420,10 +6753,10 @@ var AdBreakOrchestrator = /*#__PURE__*/ function() {
6420
6753
  this.continuousFetchingActive = true;
6421
6754
  this.isShowingPlaceholder = false;
6422
6755
  this.timing.totalAdRequestsInBreak = 0;
6423
- if (this.vmap.podAssignedByPrefetch) {
6424
- this.vmap.podAssignedByPrefetch = false;
6756
+ if (this.adConfig.podAssignedByPrefetch) {
6757
+ this.adConfig.podAssignedByPrefetch = false;
6425
6758
  } else {
6426
- this.vmap.beginNewAdPod();
6759
+ this.adConfig.beginNewAdPod();
6427
6760
  }
6428
6761
  currentMuted = this.host.video.muted;
6429
6762
  currentVolume = this.host.video.volume;
@@ -7695,7 +8028,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7695
8028
  return _this.adBreak.inAdBreak;
7696
8029
  }
7697
8030
  });
7698
- this.vmap = new VmapManager(this.config, this.video);
8031
+ this.adConfig = new AdConfigManager(this.config, this.video);
7699
8032
  this.timing = new AdTimingService(this.config, this.video, {
7700
8033
  onAdStopTimerFired: function onAdStopTimerFired() {
7701
8034
  return _this.onAdStopTimerFired();
@@ -7775,7 +8108,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7775
8108
  generateVastUrls: function generateVastUrls(base, count) {
7776
8109
  return _this.generateVastUrls(base, count);
7777
8110
  }
7778
- }, this.timing, this.preloadPool, this.vmap, this.cueManager, this.placeholder);
8111
+ }, this.timing, this.preloadPool, this.adConfig, this.cueManager, this.placeholder);
7779
8112
  }
7780
8113
  _create_class(StormcloudVideoPlayer, [
7781
8114
  {
@@ -7803,7 +8136,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7803
8136
  {
7804
8137
  key: "generateVastUrls",
7805
8138
  value: function generateVastUrls(baseUrl, count) {
7806
- return this.vmap.generateVastUrlsWithCorrelators(baseUrl, count, this.adPlayer, this.palNonce, this.adBreak.inAdBreak);
8139
+ return this.adConfig.generateVastUrlsWithCorrelators(baseUrl, count, this.adPlayer, this.palNonce, this.adBreak.inAdBreak);
7807
8140
  }
7808
8141
  },
7809
8142
  {
@@ -7831,7 +8164,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7831
8164
  ]);
7832
8165
  return [
7833
8166
  4,
7834
- this.vmap.fetchAdConfiguration()
8167
+ this.adConfig.fetchAdConfiguration()
7835
8168
  ];
7836
8169
  case 2:
7837
8170
  _state.sent();
@@ -7858,9 +8191,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7858
8191
  continuousPlayback: (_this_config_lowLatencyMode = this.config.lowLatencyMode) !== null && _this_config_lowLatencyMode !== void 0 ? _this_config_lowLatencyMode : false
7859
8192
  }).catch(function() {});
7860
8193
  fetchConsentSignals().then(function(signals) {
7861
- _this.vmap.consentSignals = signals;
8194
+ _this.adConfig.consentSignals = signals;
7862
8195
  }).catch(function() {});
7863
- this.vmap.initializeTracking();
8196
+ this.adConfig.initializeTracking();
7864
8197
  if (!this.hlsEngine.shouldUseNativeHls(function() {
7865
8198
  return _this.getStreamType();
7866
8199
  })) return [
@@ -7895,14 +8228,14 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
7895
8228
  return _async_to_generator(function() {
7896
8229
  var prerollKey, adBehavior;
7897
8230
  return _ts_generator(this, function(_state) {
7898
- if (!this.vmap.isVmapEnabled() && !isLive && this.vmap.vmapBreaks.length === 0 && this.vmap.apiVastTagUrl) {
8231
+ if (!this.adConfig.isVmapEnabled() && !isLive && this.adConfig.vmapBreaks.length === 0 && this.adConfig.apiVastTagUrl) {
7899
8232
  prerollKey = "synthetic-vod-preroll";
7900
- if (!this.vmap.consumedVmapBreakIds.has(prerollKey)) {
7901
- this.vmap.vmapBreaks = [
8233
+ if (!this.adConfig.consumedVmapBreakIds.has(prerollKey)) {
8234
+ this.adConfig.vmapBreaks = [
7902
8235
  {
7903
8236
  id: prerollKey,
7904
8237
  startTimeMs: 0,
7905
- vastTagUrl: this.vmap.apiVastTagUrl
8238
+ vastTagUrl: this.adConfig.apiVastTagUrl
7906
8239
  }
7907
8240
  ];
7908
8241
  if (this.debug) {
@@ -8169,19 +8502,19 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8169
8502
  key: "startAdPrefetch",
8170
8503
  value: function startAdPrefetch(marker, fragmentSn, cueKey) {
8171
8504
  if (this.adBreak.pendingAdBreak || this.adBreak.inAdBreak) return;
8172
- var scheduled = this.vmap.findCurrentOrNextBreak(this.video.currentTime * 1e3);
8173
- var tags = this.vmap.selectVastTagsForBreak(scheduled);
8505
+ var scheduled = this.adConfig.findCurrentOrNextBreak(this.video.currentTime * 1e3);
8506
+ var tags = this.adConfig.selectVastTagsForBreak(scheduled);
8174
8507
  var baseVastUrl;
8175
8508
  if (tags && tags.length > 0 && tags[0]) {
8176
8509
  baseVastUrl = tags[0];
8177
- } else if (this.vmap.apiVastTagUrl) {
8178
- baseVastUrl = this.vmap.apiVastTagUrl;
8510
+ } else if (this.adConfig.apiVastTagUrl) {
8511
+ baseVastUrl = this.adConfig.apiVastTagUrl;
8179
8512
  } else {
8180
8513
  if (this.debug) console.warn("[StormcloudVideoPlayer] No VAST URL available for prefetch");
8181
8514
  return;
8182
8515
  }
8183
- this.vmap.beginNewAdPod();
8184
- this.vmap.podAssignedByPrefetch = true;
8516
+ this.adConfig.beginNewAdPod();
8517
+ this.adConfig.podAssignedByPrefetch = true;
8185
8518
  var generatedUrls = this.generateVastUrls(baseVastUrl, 1);
8186
8519
  this.adBreak.pendingAdBreak = _object_spread_props(_object_spread({
8187
8520
  marker: marker
@@ -8216,10 +8549,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8216
8549
  key: "onTimeUpdate",
8217
8550
  value: function onTimeUpdate(currentTimeSec) {
8218
8551
  var _this = this;
8219
- if (!this.vmap.isVmapEnabled() || this.vmap.vmapBreaks.length === 0) return;
8552
+ if (!this.adConfig.isVmapEnabled() || this.adConfig.vmapBreaks.length === 0) return;
8220
8553
  if (this.adPlayer.isAdPlaying() || this.adBreak.inAdBreak) return;
8221
8554
  var nowMs = currentTimeSec * 1e3;
8222
- var breakToPlay = this.vmap.findBreakForTime(nowMs);
8555
+ var breakToPlay = this.adConfig.findBreakForTime(nowMs);
8223
8556
  if (breakToPlay) {
8224
8557
  void this.handleVmapAdBreak(breakToPlay, nowMs).catch(function(error) {
8225
8558
  if (_this.debug) {
@@ -8233,11 +8566,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8233
8566
  key: "onVideoEnded",
8234
8567
  value: function onVideoEnded() {
8235
8568
  var _this = this;
8236
- if (!this.vmap.isVmapEnabled() || this.vmap.vmapBreaks.length === 0) return;
8569
+ if (!this.adConfig.isVmapEnabled() || this.adConfig.vmapBreaks.length === 0) return;
8237
8570
  if (this.adPlayer.isAdPlaying() || this.adBreak.inAdBreak) return;
8238
8571
  var durationMs = Number.isFinite(this.video.duration) ? Math.floor(this.video.duration * 1e3) : 0;
8239
- var postroll = this.vmap.vmapBreaks.find(function(b) {
8240
- return b.startTimeMs === -1 && !_this.vmap.consumedVmapBreakIds.has(_this.vmap.getAdBreakKey(b));
8572
+ var postroll = this.adConfig.vmapBreaks.find(function(b) {
8573
+ return b.startTimeMs === -1 && !_this.adConfig.consumedVmapBreakIds.has(_this.adConfig.getAdBreakKey(b));
8241
8574
  });
8242
8575
  if (postroll) {
8243
8576
  void this.handleVmapAdBreak(postroll, durationMs).catch(function(error) {
@@ -8256,11 +8589,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8256
8589
  return _ts_generator(this, function(_state) {
8257
8590
  switch(_state.label){
8258
8591
  case 0:
8259
- key = this.vmap.getAdBreakKey(adBreak);
8260
- if (this.vmap.consumedVmapBreakIds.has(key)) return [
8592
+ key = this.adConfig.getAdBreakKey(adBreak);
8593
+ if (this.adConfig.consumedVmapBreakIds.has(key)) return [
8261
8594
  2
8262
8595
  ];
8263
- breakStartMs = this.vmap.resolveBreakStartMs(adBreak);
8596
+ breakStartMs = this.adConfig.resolveBreakStartMs(adBreak);
8264
8597
  if (breakStartMs == null) return [
8265
8598
  2
8266
8599
  ];
@@ -8271,8 +8604,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8271
8604
  3,
8272
8605
  4
8273
8606
  ];
8274
- this.vmap.consumedVmapBreakIds.add(key);
8275
- tags = this.vmap.selectVastTagsForBreak(adBreak);
8607
+ this.adConfig.consumedVmapBreakIds.add(key);
8608
+ tags = this.adConfig.selectVastTagsForBreak(adBreak);
8276
8609
  if (!tags || tags.length === 0) return [
8277
8610
  2
8278
8611
  ];
@@ -8464,7 +8797,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
8464
8797
  this.video.removeEventListener("emptied", this.emptiedHandler);
8465
8798
  delete this.emptiedHandler;
8466
8799
  }
8467
- this.vmap.destroyTracking();
8800
+ this.adConfig.destroyTracking();
8468
8801
  this.hlsEngine.destroy();
8469
8802
  (_this_adPlayer = this.adPlayer) === null || _this_adPlayer === void 0 ? void 0 : _this_adPlayer.destroy();
8470
8803
  if (this.palPlaybackStarted) {