stormcloud-video-player 0.1.6 → 0.1.7

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.
package/lib/index.d.cts CHANGED
@@ -27,6 +27,7 @@ interface StormcloudVideoPlayerConfig {
27
27
  onVolumeToggle?: () => void;
28
28
  onFullscreenToggle?: () => void;
29
29
  onControlClick?: () => void;
30
+ licenseKey?: string;
30
31
  }
31
32
  interface ClientInfo {
32
33
  brand: string;
@@ -141,12 +142,13 @@ type StormcloudVideoPlayerProps = Omit<StormcloudVideoPlayerConfig, "videoElemen
141
142
  onReady?: (player: StormcloudVideoPlayer) => void;
142
143
  wrapperClassName?: string;
143
144
  wrapperStyle?: React.CSSProperties;
145
+ licenseKey?: string;
144
146
  };
145
147
  declare const StormcloudVideoPlayerComponent: React.FC<StormcloudVideoPlayerProps>;
146
148
 
147
149
  declare function getClientInfo(): ClientInfo;
148
150
  declare function getBrowserID(clientInfo: ClientInfo): Promise<string>;
149
- declare function sendInitialTracking(): Promise<void>;
150
- declare function sendHeartbeat(): Promise<void>;
151
+ declare function sendInitialTracking(licenseKey?: string): Promise<void>;
152
+ declare function sendHeartbeat(licenseKey?: string): Promise<void>;
151
153
 
152
154
  export { type AdBreak, type AdSchedule, type ClientInfo, type HeartbeatData, type LateJoinPolicy, StormcloudVideoPlayer, StormcloudVideoPlayerComponent, type StormcloudVideoPlayerConfig, type StormcloudVideoPlayerProps, type TrackingData, getBrowserID, getClientInfo, sendHeartbeat, sendInitialTracking };
package/lib/index.d.ts CHANGED
@@ -27,6 +27,7 @@ interface StormcloudVideoPlayerConfig {
27
27
  onVolumeToggle?: () => void;
28
28
  onFullscreenToggle?: () => void;
29
29
  onControlClick?: () => void;
30
+ licenseKey?: string;
30
31
  }
31
32
  interface ClientInfo {
32
33
  brand: string;
@@ -141,12 +142,13 @@ type StormcloudVideoPlayerProps = Omit<StormcloudVideoPlayerConfig, "videoElemen
141
142
  onReady?: (player: StormcloudVideoPlayer) => void;
142
143
  wrapperClassName?: string;
143
144
  wrapperStyle?: React.CSSProperties;
145
+ licenseKey?: string;
144
146
  };
145
147
  declare const StormcloudVideoPlayerComponent: React.FC<StormcloudVideoPlayerProps>;
146
148
 
147
149
  declare function getClientInfo(): ClientInfo;
148
150
  declare function getBrowserID(clientInfo: ClientInfo): Promise<string>;
149
- declare function sendInitialTracking(): Promise<void>;
150
- declare function sendHeartbeat(): Promise<void>;
151
+ declare function sendInitialTracking(licenseKey?: string): Promise<void>;
152
+ declare function sendHeartbeat(licenseKey?: string): Promise<void>;
151
153
 
152
154
  export { type AdBreak, type AdSchedule, type ClientInfo, type HeartbeatData, type LateJoinPolicy, StormcloudVideoPlayer, StormcloudVideoPlayerComponent, type StormcloudVideoPlayerConfig, type StormcloudVideoPlayerProps, type TrackingData, getBrowserID, getClientInfo, sendHeartbeat, sendInitialTracking };
package/lib/index.js CHANGED
@@ -490,7 +490,7 @@ async function getBrowserID(clientInfo) {
490
490
  const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
491
491
  return hashHex;
492
492
  }
493
- async function sendInitialTracking() {
493
+ async function sendInitialTracking(licenseKey) {
494
494
  try {
495
495
  const clientInfo = getClientInfo();
496
496
  const browserId = await getBrowserID(clientInfo);
@@ -498,11 +498,15 @@ async function sendInitialTracking() {
498
498
  browserId,
499
499
  ...clientInfo
500
500
  };
501
+ const headers = { "Content-Type": "application/json" };
502
+ if (licenseKey) {
503
+ headers["Authorization"] = `Bearer ${licenseKey}`;
504
+ }
501
505
  const response = await fetch(
502
506
  "https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/track",
503
507
  {
504
508
  method: "POST",
505
- headers: { "Content-Type": "application/json" },
509
+ headers,
506
510
  body: JSON.stringify(trackingData)
507
511
  }
508
512
  );
@@ -521,7 +525,7 @@ async function sendInitialTracking() {
521
525
  );
522
526
  }
523
527
  }
524
- async function sendHeartbeat() {
528
+ async function sendHeartbeat(licenseKey) {
525
529
  try {
526
530
  const clientInfo = getClientInfo();
527
531
  const browserId = await getBrowserID(clientInfo);
@@ -529,11 +533,15 @@ async function sendHeartbeat() {
529
533
  browserId,
530
534
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
531
535
  };
536
+ const headers = { "Content-Type": "application/json" };
537
+ if (licenseKey) {
538
+ headers["Authorization"] = `Bearer ${licenseKey}`;
539
+ }
532
540
  const response = await fetch(
533
541
  "https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/heartbeat",
534
542
  {
535
543
  method: "POST",
536
- headers: { "Content-Type": "application/json" },
544
+ headers,
537
545
  body: JSON.stringify(heartbeatData)
538
546
  }
539
547
  );
@@ -1143,7 +1151,7 @@ var StormcloudVideoPlayer = class {
1143
1151
  return void 0;
1144
1152
  }
1145
1153
  initializeTracking() {
1146
- sendInitialTracking().catch((error) => {
1154
+ sendInitialTracking(this.config.licenseKey).catch((error) => {
1147
1155
  if (this.config.debugAdTiming) {
1148
1156
  console.warn(
1149
1157
  "[StormcloudVideoPlayer] Failed to send initial tracking:",
@@ -1159,7 +1167,7 @@ var StormcloudVideoPlayer = class {
1159
1167
  const now = Date.now();
1160
1168
  if (!this.lastHeartbeatTime || now - this.lastHeartbeatTime > 1e4) {
1161
1169
  this.lastHeartbeatTime = now;
1162
- sendHeartbeat().catch((error) => {
1170
+ sendHeartbeat(this.config.licenseKey).catch((error) => {
1163
1171
  if (this.config.debugAdTiming) {
1164
1172
  console.warn(
1165
1173
  "[StormcloudVideoPlayer] Failed to send heartbeat:",
@@ -1177,7 +1185,11 @@ var StormcloudVideoPlayer = class {
1177
1185
  apiUrl
1178
1186
  );
1179
1187
  }
1180
- const response = await fetch(apiUrl);
1188
+ const headers = {};
1189
+ if (this.config.licenseKey) {
1190
+ headers["Authorization"] = `Bearer ${this.config.licenseKey}`;
1191
+ }
1192
+ const response = await fetch(apiUrl, { headers });
1181
1193
  if (!response.ok) {
1182
1194
  throw new Error(`Failed to fetch ad configuration: ${response.status}`);
1183
1195
  }
@@ -1522,6 +1534,7 @@ var StormcloudVideoPlayerComponent = (props) => {
1522
1534
  preload,
1523
1535
  poster,
1524
1536
  children,
1537
+ licenseKey,
1525
1538
  ...restVideoAttrs
1526
1539
  } = props;
1527
1540
  const videoRef = useRef(null);
@@ -1558,6 +1571,7 @@ var StormcloudVideoPlayerComponent = (props) => {
1558
1571
  if (onFullscreenToggle !== void 0)
1559
1572
  cfg.onFullscreenToggle = onFullscreenToggle;
1560
1573
  if (onControlClick !== void 0) cfg.onControlClick = onControlClick;
1574
+ if (licenseKey !== void 0) cfg.licenseKey = licenseKey;
1561
1575
  const player = new StormcloudVideoPlayer(cfg);
1562
1576
  playerRef.current = player;
1563
1577
  player.load().then(() => {
@@ -1586,7 +1600,8 @@ var StormcloudVideoPlayerComponent = (props) => {
1586
1600
  onVolumeToggle,
1587
1601
  onFullscreenToggle,
1588
1602
  onControlClick,
1589
- onReady
1603
+ onReady,
1604
+ licenseKey
1590
1605
  ]);
1591
1606
  useEffect(() => {
1592
1607
  if (!playerRef.current) return;