stormcloud-video-player 0.2.8 → 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.
@@ -243,7 +243,9 @@ function createImaController(video, options) {
243
243
  AdEvent.CONTENT_PAUSE_REQUESTED,
244
244
  () => {
245
245
  console.log("[IMA] Content pause requested");
246
- originalMutedState = video.muted;
246
+ if (!adPlaying) {
247
+ originalMutedState = video.muted;
248
+ }
247
249
  video.muted = true;
248
250
  if (!options?.continueLiveStreamDuringAds) {
249
251
  video.pause();
@@ -365,14 +367,6 @@ function createImaController(video, options) {
365
367
  const height = video.clientHeight || 360;
366
368
  console.log(`[IMA] Initializing ads manager (${width}x${height})`);
367
369
  adsManager.init(width, height, window.google.ima.ViewMode.NORMAL);
368
- if (!options?.continueLiveStreamDuringAds) {
369
- console.log("[IMA] Pausing video for ad playback (VOD mode)");
370
- video.pause();
371
- } else {
372
- console.log(
373
- "[IMA] Keeping video playing but muted for ad playback (Live mode)"
374
- );
375
- }
376
370
  adPlaying = true;
377
371
  console.log("[IMA] Starting ad playback");
378
372
  adsManager.start();
@@ -471,6 +465,7 @@ function createImaController(video, options) {
471
465
  }
472
466
 
473
467
  // src/utils/tracking.ts
468
+ var cachedBrowserId = null;
474
469
  function getClientInfo() {
475
470
  const ua = navigator.userAgent;
476
471
  const platform = navigator.platform;
@@ -613,6 +608,9 @@ function getClientInfo() {
613
608
  };
614
609
  }
615
610
  async function getBrowserID(clientInfo) {
611
+ if (cachedBrowserId) {
612
+ return cachedBrowserId;
613
+ }
616
614
  const fingerprintString = JSON.stringify(clientInfo);
617
615
  if (typeof crypto !== "undefined" && crypto.subtle && crypto.subtle.digest) {
618
616
  try {
@@ -623,6 +621,7 @@ async function getBrowserID(clientInfo) {
623
621
  );
624
622
  const hashArray = Array.from(new Uint8Array(hashBuffer));
625
623
  const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
624
+ cachedBrowserId = hashHex;
626
625
  return hashHex;
627
626
  } catch (error) {
628
627
  console.warn(
@@ -639,7 +638,8 @@ async function getBrowserID(clientInfo) {
639
638
  const fallbackHash = Math.abs(hash).toString(16).padStart(8, "0");
640
639
  const timestamp = Date.now().toString(16).padStart(12, "0");
641
640
  const random = Math.random().toString(16).substring(2, 14).padStart(12, "0");
642
- return (fallbackHash + timestamp + random).padEnd(64, "0");
641
+ cachedBrowserId = (fallbackHash + timestamp + random).padEnd(64, "0");
642
+ return cachedBrowserId;
643
643
  }
644
644
  async function sendInitialTracking(licenseKey) {
645
645
  try {
@@ -1328,17 +1328,21 @@ var StormcloudVideoPlayer = class {
1328
1328
  return void 0;
1329
1329
  }
1330
1330
  initializeTracking() {
1331
- sendInitialTracking(this.config.licenseKey).catch((error) => {
1331
+ sendInitialTracking(this.config.licenseKey).then(() => {
1332
+ this.heartbeatInterval = window.setInterval(() => {
1333
+ this.sendHeartbeatIfNeeded();
1334
+ }, 5e3);
1335
+ }).catch((error) => {
1332
1336
  if (this.config.debugAdTiming) {
1333
1337
  console.warn(
1334
1338
  "[StormcloudVideoPlayer] Failed to send initial tracking:",
1335
1339
  error
1336
1340
  );
1337
1341
  }
1342
+ this.heartbeatInterval = window.setInterval(() => {
1343
+ this.sendHeartbeatIfNeeded();
1344
+ }, 5e3);
1338
1345
  });
1339
- this.heartbeatInterval = window.setInterval(() => {
1340
- this.sendHeartbeatIfNeeded();
1341
- }, 5e3);
1342
1346
  }
1343
1347
  sendHeartbeatIfNeeded() {
1344
1348
  const now = Date.now();
@@ -1573,6 +1577,18 @@ var StormcloudVideoPlayer = class {
1573
1577
  if (this.config.debugAdTiming) {
1574
1578
  console.log("[StormcloudVideoPlayer] Attempting to play ad:", vastTagUrl);
1575
1579
  }
1580
+ this.ima.updateOriginalMutedState(this.video.muted);
1581
+ if (!this.shouldContinueLiveStreamDuringAds()) {
1582
+ if (this.config.debugAdTiming) {
1583
+ console.log("[StormcloudVideoPlayer] Pausing video immediately for ad (VOD mode)");
1584
+ }
1585
+ this.video.pause();
1586
+ } else {
1587
+ if (this.config.debugAdTiming) {
1588
+ console.log("[StormcloudVideoPlayer] Muting video for ad (Live mode)");
1589
+ }
1590
+ this.video.muted = true;
1591
+ }
1576
1592
  this.startAdFailsafeTimer();
1577
1593
  try {
1578
1594
  await this.ima.requestAds(vastTagUrl);