stormcloud-video-player 0.8.25 → 0.8.27

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/dist/stormcloud-vp.min.js +1 -1
  2. package/lib/index.cjs +714 -128
  3. package/lib/index.cjs.map +1 -1
  4. package/lib/index.d.cts +7 -0
  5. package/lib/index.d.ts +7 -0
  6. package/lib/index.js +714 -128
  7. package/lib/index.js.map +1 -1
  8. package/lib/player/AdBreakOrchestrator.cjs +278 -49
  9. package/lib/player/AdBreakOrchestrator.cjs.map +1 -1
  10. package/lib/player/AdBreakOrchestrator.d.cts +4 -1
  11. package/lib/player/AdConfigManager.cjs +144 -14
  12. package/lib/player/AdConfigManager.cjs.map +1 -1
  13. package/lib/player/AdConfigManager.d.cts +12 -1
  14. package/lib/player/AdPreloadPool.d.cts +1 -1
  15. package/lib/player/AdTimingService.cjs +7 -0
  16. package/lib/player/AdTimingService.cjs.map +1 -1
  17. package/lib/player/AdTimingService.d.cts +2 -1
  18. package/lib/player/HlsEngine.d.cts +1 -1
  19. package/lib/player/PlayerControls.d.cts +1 -1
  20. package/lib/player/Scte35CueManager.d.cts +1 -1
  21. package/lib/player/Scte35Parser.d.cts +1 -1
  22. package/lib/player/StormcloudVideoPlayer.cjs +714 -128
  23. package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
  24. package/lib/player/StormcloudVideoPlayer.d.cts +2 -1
  25. package/lib/player/playerTypes.d.cts +1 -1
  26. package/lib/players/HlsPlayer.cjs +714 -128
  27. package/lib/players/HlsPlayer.cjs.map +1 -1
  28. package/lib/players/HlsPlayer.d.cts +1 -1
  29. package/lib/players/index.cjs +714 -128
  30. package/lib/players/index.cjs.map +1 -1
  31. package/lib/sdk/hlsAdPlayer.cjs +343 -71
  32. package/lib/sdk/hlsAdPlayer.cjs.map +1 -1
  33. package/lib/sdk/hlsAdPlayer.d.cts +1 -1
  34. package/lib/{types-Bz4aRmzc.d.cts → types-Xgz2_W1C.d.cts} +6 -0
  35. package/lib/ui/StormcloudVideoPlayer.cjs +714 -128
  36. package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
  37. package/lib/ui/StormcloudVideoPlayer.d.cts +1 -1
  38. package/lib/utils/ctvVastSignals.cjs +80 -8
  39. package/lib/utils/ctvVastSignals.cjs.map +1 -1
  40. package/lib/utils/tracking.cjs +80 -8
  41. package/lib/utils/tracking.cjs.map +1 -1
  42. package/lib/utils/tracking.d.cts +1 -1
  43. package/lib/utils/vastEnvironmentSignals.cjs +83 -13
  44. package/lib/utils/vastEnvironmentSignals.cjs.map +1 -1
  45. package/lib/utils/vastMacros.cjs +15 -1
  46. package/lib/utils/vastMacros.cjs.map +1 -1
  47. package/lib/utils/vastMacros.d.cts +3 -0
  48. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { S as Scte35Marker, a as StormcloudVideoPlayerConfig, A as AdController } from '../types-Bz4aRmzc.cjs';
1
+ import { S as Scte35Marker, a as StormcloudVideoPlayerConfig, A as AdController } from '../types-Xgz2_W1C.cjs';
2
2
  import { AdTimingService } from './AdTimingService.cjs';
3
3
  import { AdPreloadPool } from './AdPreloadPool.cjs';
4
4
  import { AdConfigManager } from './AdConfigManager.cjs';
@@ -17,6 +17,7 @@ interface AdBreakOrchestratorHost {
17
17
  shouldContinueLiveStreamDuringAds(): boolean;
18
18
  getLiveSyncPosition(): number | undefined;
19
19
  generateVastUrls(baseUrl: string, count: number): string[];
20
+ generatePodVastUrl(baseUrl: string, breakDurationMs?: number): string;
20
21
  }
21
22
  declare class AdBreakOrchestrator {
22
23
  inAdBreak: boolean;
@@ -45,10 +46,12 @@ declare class AdBreakOrchestrator {
45
46
  constructor(host: AdBreakOrchestratorHost, timing: AdTimingService, preloadPool: AdPreloadPool, adConfig: AdConfigManager, cueManager: Scte35CueManager, placeholder: PlaceholderLayer);
46
47
  private get debug();
47
48
  private get analyticsContext();
49
+ private get optimizedPodsEnabled();
48
50
  attachImaEventListeners(): void;
49
51
  recreateAdController(): void;
50
52
  clearPendingAdBreak(): void;
51
53
  handleAdStart(_marker: Scte35Marker): Promise<void>;
54
+ private startOptimizedPod;
52
55
  private swapToPreloadedAdPlayer;
53
56
  private startContinuousFetching;
54
57
  private continuousFetchLoop;
@@ -441,38 +441,108 @@ function getOrCreateStoredUuid(storageKey) {
441
441
  if (typeof window === "undefined") {
442
442
  return void 0;
443
443
  }
444
- var existing = readStoredString(storageKey);
444
+ var existing = readPersistentId(storageKey);
445
445
  if (existing) {
446
+ writePersistentId(storageKey, existing);
446
447
  return existing;
447
448
  }
448
449
  var id = createUuid();
449
- try {
450
- var _window_localStorage;
451
- (_window_localStorage = window.localStorage) === null || _window_localStorage === void 0 ? void 0 : _window_localStorage.setItem(storageKey, id);
452
- } catch (unused) {}
450
+ writePersistentId(storageKey, id);
453
451
  return id;
454
452
  }
455
453
  function getOrCreateCtvSessionId() {
456
- var existing = readStoredString(CTV_SESSION_STORAGE_KEY);
454
+ var existing = readPersistentId(CTV_SESSION_STORAGE_KEY);
457
455
  if (existing) {
456
+ writePersistentId(CTV_SESSION_STORAGE_KEY, existing);
458
457
  return existing;
459
458
  }
460
459
  var sessionId = createUuid();
460
+ writePersistentId(CTV_SESSION_STORAGE_KEY, sessionId);
461
+ return sessionId;
462
+ }
463
+ function readPersistentId(storageKey) {
464
+ return readStoredString(storageKey) || readCookie(storageKey);
465
+ }
466
+ function writePersistentId(storageKey, value) {
461
467
  try {
462
468
  var _window_localStorage;
463
- (_window_localStorage = window.localStorage) === null || _window_localStorage === void 0 ? void 0 : _window_localStorage.setItem(CTV_SESSION_STORAGE_KEY, sessionId);
469
+ (_window_localStorage = window.localStorage) === null || _window_localStorage === void 0 ? void 0 : _window_localStorage.setItem(storageKey, value);
470
+ } catch (unused) {}
471
+ writeCookie(storageKey, value);
472
+ }
473
+ var PERSISTENT_ID_COOKIE_MAX_AGE = 60 * 60 * 24 * 365 * 5;
474
+ function readCookie(name) {
475
+ if (typeof document === "undefined") {
476
+ return void 0;
477
+ }
478
+ try {
479
+ var prefix = encodeURIComponent(name) + "=";
480
+ var parts = document.cookie ? document.cookie.split(";") : [];
481
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
482
+ try {
483
+ for(var _iterator = parts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
484
+ var part = _step.value;
485
+ var entry = part.trim();
486
+ if (entry.startsWith(prefix)) {
487
+ return decodeURIComponent(entry.slice(prefix.length)) || void 0;
488
+ }
489
+ }
490
+ } catch (err) {
491
+ _didIteratorError = true;
492
+ _iteratorError = err;
493
+ } finally{
494
+ try {
495
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
496
+ _iterator.return();
497
+ }
498
+ } finally{
499
+ if (_didIteratorError) {
500
+ throw _iteratorError;
501
+ }
502
+ }
503
+ }
504
+ } catch (unused) {}
505
+ return void 0;
506
+ }
507
+ function writeCookie(name, value) {
508
+ if (typeof document === "undefined") {
509
+ return;
510
+ }
511
+ try {
512
+ document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + ";path=/;max-age=" + PERSISTENT_ID_COOKIE_MAX_AGE + ";SameSite=Lax";
464
513
  } catch (unused) {}
465
- return sessionId;
466
514
  }
467
515
  function createUuid() {
516
+ var _bytes_, _bytes_1;
468
517
  if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
469
518
  return crypto.randomUUID();
470
519
  }
471
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(char) {
472
- var value = Math.floor(Math.random() * 16);
473
- var nibble = char === "x" ? value : value & 3 | 8;
474
- return nibble.toString(16);
475
- });
520
+ var bytes = new Uint8Array(16);
521
+ if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
522
+ crypto.getRandomValues(bytes);
523
+ } else {
524
+ var seed = Date.now() ^ Math.floor(performanceNow() * 1e3);
525
+ for(var i = 0; i < 16; i++){
526
+ seed = seed * 1103515245 + 12345 & 2147483647;
527
+ bytes[i] = (seed ^ Math.floor(Math.random() * 256)) & 255;
528
+ }
529
+ }
530
+ bytes[6] = ((_bytes_ = bytes[6]) !== null && _bytes_ !== void 0 ? _bytes_ : 0) & 15 | 64;
531
+ bytes[8] = ((_bytes_1 = bytes[8]) !== null && _bytes_1 !== void 0 ? _bytes_1 : 0) & 63 | 128;
532
+ var hex = "";
533
+ for(var i1 = 0; i1 < 16; i1++){
534
+ var _bytes_i;
535
+ hex += ((_bytes_i = bytes[i1]) !== null && _bytes_i !== void 0 ? _bytes_i : 0).toString(16).padStart(2, "0");
536
+ }
537
+ return hex.slice(0, 8) + "-" + hex.slice(8, 12) + "-" + hex.slice(12, 16) + "-" + hex.slice(16, 20) + "-" + hex.slice(20, 32);
538
+ }
539
+ function performanceNow() {
540
+ try {
541
+ if (typeof performance !== "undefined" && typeof performance.now === "function") {
542
+ return performance.now();
543
+ }
544
+ } catch (unused) {}
545
+ return 0;
476
546
  }
477
547
  function readPlatformNativeDeviceId() {
478
548
  if (typeof window === "undefined") return {};
@@ -1085,7 +1155,20 @@ function applyVastMacros(baseUrl, ctx) {
1085
1155
  if (ctx.pod != null) {
1086
1156
  params.set("pod", String(ctx.pod));
1087
1157
  }
1088
- if (ctx.adPosition != null) {
1158
+ var optimizedPodMode = ctx.podMaxAds != null || ctx.podMinDurationMs != null || ctx.podMaxDurationMs != null;
1159
+ if (optimizedPodMode) {
1160
+ params.delete("ppos");
1161
+ params.delete("lip");
1162
+ if (ctx.podMinDurationMs != null) {
1163
+ params.set("pmnd", String(Math.max(0, Math.round(ctx.podMinDurationMs))));
1164
+ }
1165
+ if (ctx.podMaxDurationMs != null) {
1166
+ params.set("pmxd", String(Math.max(0, Math.round(ctx.podMaxDurationMs))));
1167
+ }
1168
+ if (ctx.podMaxAds != null) {
1169
+ params.set("pmad", String(Math.max(1, Math.round(ctx.podMaxAds))));
1170
+ }
1171
+ } else if (ctx.adPosition != null) {
1089
1172
  params.set("ppos", String(ctx.adPosition));
1090
1173
  }
1091
1174
  var requestUrl = ctx.contentUrl || ctx.pageUrl;
@@ -1689,6 +1772,7 @@ var AdConfigManager = /*#__PURE__*/ function() {
1689
1772
  this.podAssignedByPrefetch = false;
1690
1773
  this.adRequestPositionInBreak = 0;
1691
1774
  this.lastHeartbeatTime = 0;
1775
+ this.defaultPodMaxAds = 6;
1692
1776
  this.config = config;
1693
1777
  this.video = video;
1694
1778
  }
@@ -2144,6 +2228,52 @@ var AdConfigManager = /*#__PURE__*/ function() {
2144
2228
  return urls;
2145
2229
  }
2146
2230
  },
2231
+ {
2232
+ key: "resolvePodParams",
2233
+ value: function resolvePodParams(breakDurationMs) {
2234
+ var maxDurationMs = breakDurationMs != null && breakDurationMs > 0 ? breakDurationMs : this.config.podMaxDurationMs;
2235
+ var maxAds = this.config.podMaxAds && this.config.podMaxAds > 0 ? this.config.podMaxAds : this.apiNumberAds && this.apiNumberAds > 0 ? this.apiNumberAds : this.defaultPodMaxAds;
2236
+ var minDurationMs = this.config.podExactDuration && maxDurationMs != null ? maxDurationMs : 0;
2237
+ return {
2238
+ maxAds: maxAds,
2239
+ minDurationMs: minDurationMs,
2240
+ maxDurationMs: maxDurationMs
2241
+ };
2242
+ }
2243
+ },
2244
+ {
2245
+ key: "generatePodVastUrl",
2246
+ value: function generatePodVastUrl(baseUrl, podParams, adPlayer, palNonce, inAdBreak) {
2247
+ var _podParams_maxDurationMs;
2248
+ var adWillPlayMuted = inAdBreak ? adPlayer.getOriginalMutedState() : this.video.muted;
2249
+ var envSignals = resolveVastEnvironmentSignals(!!this.config.ctvAdRequest);
2250
+ var urlWithMacros = applyVastMacros(baseUrl, {
2251
+ correlator: generateCorrelator(),
2252
+ streamCorrelator: this.streamCorrelator,
2253
+ pod: this.podCounter > 0 ? this.podCounter : void 0,
2254
+ podMaxAds: podParams.maxAds,
2255
+ podMinDurationMs: podParams.minDurationMs,
2256
+ podMaxDurationMs: podParams.maxDurationMs,
2257
+ isCtv: envSignals.isCtv,
2258
+ contentUrl: envSignals.contentUrl,
2259
+ pageUrl: !envSignals.isCtv && typeof window !== "undefined" ? window.location.href : void 0,
2260
+ adWillPlayMuted: adWillPlayMuted,
2261
+ adWillAutoPlay: !!this.config.autoplay,
2262
+ appId: envSignals.appId,
2263
+ appName: envSignals.appName,
2264
+ sessionId: envSignals.sessionId,
2265
+ deviceId: envSignals.deviceId,
2266
+ deviceIdType: envSignals.deviceIdType,
2267
+ limitAdTracking: envSignals.limitAdTracking,
2268
+ deviceTypeHint: envSignals.deviceTypeHint,
2269
+ adTest: this.config.adTest,
2270
+ consent: this.consentSignals
2271
+ });
2272
+ var finalUrl = palNonce.injectNonce(urlWithMacros);
2273
+ console.log("[StormcloudVideoPlayer] Resolved optimized-pod request URL (pod=".concat(this.podCounter, ", pmad=").concat(podParams.maxAds, ", pmnd=").concat(podParams.minDurationMs, ", pmxd=").concat((_podParams_maxDurationMs = podParams.maxDurationMs) !== null && _podParams_maxDurationMs !== void 0 ? _podParams_maxDurationMs : "?", "):"), finalUrl);
2274
+ return finalUrl;
2275
+ }
2276
+ },
2147
2277
  {
2148
2278
  // --- Tracking ---
2149
2279
  key: "initializeTracking",