stormcloud-video-player 0.2.7 → 0.2.9

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.
@@ -282,7 +282,9 @@ function createImaController(video, options) {
282
282
  AdEvent.CONTENT_PAUSE_REQUESTED,
283
283
  () => {
284
284
  console.log("[IMA] Content pause requested");
285
- originalMutedState = video.muted;
285
+ if (!adPlaying) {
286
+ originalMutedState = video.muted;
287
+ }
286
288
  video.muted = true;
287
289
  if (!options?.continueLiveStreamDuringAds) {
288
290
  video.pause();
@@ -404,14 +406,6 @@ function createImaController(video, options) {
404
406
  const height = video.clientHeight || 360;
405
407
  console.log(`[IMA] Initializing ads manager (${width}x${height})`);
406
408
  adsManager.init(width, height, window.google.ima.ViewMode.NORMAL);
407
- if (!options?.continueLiveStreamDuringAds) {
408
- console.log("[IMA] Pausing video for ad playback (VOD mode)");
409
- video.pause();
410
- } else {
411
- console.log(
412
- "[IMA] Keeping video playing but muted for ad playback (Live mode)"
413
- );
414
- }
415
409
  adPlaying = true;
416
410
  console.log("[IMA] Starting ad playback");
417
411
  adsManager.start();
@@ -510,6 +504,7 @@ function createImaController(video, options) {
510
504
  }
511
505
 
512
506
  // src/utils/tracking.ts
507
+ var cachedBrowserId = null;
513
508
  function getClientInfo() {
514
509
  const ua = navigator.userAgent;
515
510
  const platform = navigator.platform;
@@ -652,20 +647,24 @@ function getClientInfo() {
652
647
  };
653
648
  }
654
649
  async function getBrowserID(clientInfo) {
650
+ if (cachedBrowserId) {
651
+ return cachedBrowserId;
652
+ }
655
653
  const fingerprintString = JSON.stringify(clientInfo);
656
654
  if (typeof crypto !== "undefined" && crypto.subtle && crypto.subtle.digest) {
657
655
  try {
656
+ await crypto.subtle.digest("SHA-256", new Uint8Array([1, 2, 3]));
658
657
  const hashBuffer = await crypto.subtle.digest(
659
658
  "SHA-256",
660
659
  new TextEncoder().encode(fingerprintString)
661
660
  );
662
661
  const hashArray = Array.from(new Uint8Array(hashBuffer));
663
662
  const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
663
+ cachedBrowserId = hashHex;
664
664
  return hashHex;
665
665
  } catch (error) {
666
666
  console.warn(
667
- "[StormcloudVideoPlayer] crypto.subtle.digest failed, using fallback hash:",
668
- error
667
+ "[StormcloudVideoPlayer] crypto.subtle.digest not supported, using fallback hash"
669
668
  );
670
669
  }
671
670
  }
@@ -678,7 +677,8 @@ async function getBrowserID(clientInfo) {
678
677
  const fallbackHash = Math.abs(hash).toString(16).padStart(8, "0");
679
678
  const timestamp = Date.now().toString(16).padStart(12, "0");
680
679
  const random = Math.random().toString(16).substring(2, 14).padStart(12, "0");
681
- return (fallbackHash + timestamp + random).padEnd(64, "0");
680
+ cachedBrowserId = (fallbackHash + timestamp + random).padEnd(64, "0");
681
+ return cachedBrowserId;
682
682
  }
683
683
  async function sendInitialTracking(licenseKey) {
684
684
  try {
@@ -1367,17 +1367,21 @@ var StormcloudVideoPlayer = class {
1367
1367
  return void 0;
1368
1368
  }
1369
1369
  initializeTracking() {
1370
- sendInitialTracking(this.config.licenseKey).catch((error) => {
1370
+ sendInitialTracking(this.config.licenseKey).then(() => {
1371
+ this.heartbeatInterval = window.setInterval(() => {
1372
+ this.sendHeartbeatIfNeeded();
1373
+ }, 5e3);
1374
+ }).catch((error) => {
1371
1375
  if (this.config.debugAdTiming) {
1372
1376
  console.warn(
1373
1377
  "[StormcloudVideoPlayer] Failed to send initial tracking:",
1374
1378
  error
1375
1379
  );
1376
1380
  }
1381
+ this.heartbeatInterval = window.setInterval(() => {
1382
+ this.sendHeartbeatIfNeeded();
1383
+ }, 5e3);
1377
1384
  });
1378
- this.heartbeatInterval = window.setInterval(() => {
1379
- this.sendHeartbeatIfNeeded();
1380
- }, 5e3);
1381
1385
  }
1382
1386
  sendHeartbeatIfNeeded() {
1383
1387
  const now = Date.now();
@@ -1612,6 +1616,18 @@ var StormcloudVideoPlayer = class {
1612
1616
  if (this.config.debugAdTiming) {
1613
1617
  console.log("[StormcloudVideoPlayer] Attempting to play ad:", vastTagUrl);
1614
1618
  }
1619
+ this.ima.updateOriginalMutedState(this.video.muted);
1620
+ if (!this.shouldContinueLiveStreamDuringAds()) {
1621
+ if (this.config.debugAdTiming) {
1622
+ console.log("[StormcloudVideoPlayer] Pausing video immediately for ad (VOD mode)");
1623
+ }
1624
+ this.video.pause();
1625
+ } else {
1626
+ if (this.config.debugAdTiming) {
1627
+ console.log("[StormcloudVideoPlayer] Muting video for ad (Live mode)");
1628
+ }
1629
+ this.video.muted = true;
1630
+ }
1615
1631
  this.startAdFailsafeTimer();
1616
1632
  try {
1617
1633
  await this.ima.requestAds(vastTagUrl);