stormcloud-video-player 0.3.0 → 0.3.2
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/dist/stormcloud-vp.min.js +1 -1
- package/lib/index.cjs +121 -36
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +121 -36
- package/lib/index.js.map +1 -1
- package/lib/player/StormcloudVideoPlayer.cjs +121 -36
- package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/player/StormcloudVideoPlayer.d.cts +1 -0
- package/lib/players/HlsPlayer.cjs +121 -36
- package/lib/players/HlsPlayer.cjs.map +1 -1
- package/lib/players/index.cjs +121 -36
- package/lib/players/index.cjs.map +1 -1
- package/lib/ui/StormcloudVideoPlayer.cjs +121 -36
- package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
- package/package.json +1 -1
package/lib/index.d.cts
CHANGED
|
@@ -181,6 +181,7 @@ declare class StormcloudVideoPlayer {
|
|
|
181
181
|
private playSingleAd;
|
|
182
182
|
private handleAdPodComplete;
|
|
183
183
|
private handleAdFailure;
|
|
184
|
+
private tryNextAdWithRetry;
|
|
184
185
|
private startAdRequestWatchdog;
|
|
185
186
|
private clearAdRequestWatchdog;
|
|
186
187
|
private startAdFailsafeTimer;
|
package/lib/index.d.ts
CHANGED
|
@@ -181,6 +181,7 @@ declare class StormcloudVideoPlayer {
|
|
|
181
181
|
private playSingleAd;
|
|
182
182
|
private handleAdPodComplete;
|
|
183
183
|
private handleAdFailure;
|
|
184
|
+
private tryNextAdWithRetry;
|
|
184
185
|
private startAdRequestWatchdog;
|
|
185
186
|
private clearAdRequestWatchdog;
|
|
186
187
|
private startAdFailsafeTimer;
|
package/lib/index.js
CHANGED
|
@@ -3190,12 +3190,7 @@ var StormcloudVideoPlayer = class {
|
|
|
3190
3190
|
);
|
|
3191
3191
|
}
|
|
3192
3192
|
});
|
|
3193
|
-
|
|
3194
|
-
await this.playAdPod();
|
|
3195
|
-
} catch (error) {
|
|
3196
|
-
console.error("[DEBUG-POD] \u274C Pod playback failed:", error);
|
|
3197
|
-
this.handleAdFailure();
|
|
3198
|
-
}
|
|
3193
|
+
await this.playAdPod();
|
|
3199
3194
|
}
|
|
3200
3195
|
if (this.expectedAdBreakDurationMs == null && (scheduled == null ? void 0 : scheduled.durationMs) != null) {
|
|
3201
3196
|
this.expectedAdBreakDurationMs = scheduled.durationMs;
|
|
@@ -3208,20 +3203,30 @@ var StormcloudVideoPlayer = class {
|
|
|
3208
3203
|
console.log("[DEBUG-POD] \u26A0\uFE0F No ads in pod");
|
|
3209
3204
|
return;
|
|
3210
3205
|
}
|
|
3211
|
-
|
|
3206
|
+
const waitTime = this.isAdaptiveMode ? 1500 : 500;
|
|
3207
|
+
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
3212
3208
|
const firstPreloaded = this.findNextPreloadedAd();
|
|
3213
3209
|
if (!firstPreloaded) {
|
|
3214
3210
|
console.log("[DEBUG-POD] \u26A0\uFE0F No preloaded ads after wait, trying first ad");
|
|
3215
3211
|
const firstAd = this.adPodQueue.shift();
|
|
3216
3212
|
if (firstAd) {
|
|
3217
3213
|
this.currentAdIndex++;
|
|
3218
|
-
|
|
3214
|
+
try {
|
|
3215
|
+
await this.playSingleAd(firstAd);
|
|
3216
|
+
} catch (error) {
|
|
3217
|
+
console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
|
|
3218
|
+
return;
|
|
3219
|
+
}
|
|
3219
3220
|
}
|
|
3220
3221
|
return;
|
|
3221
3222
|
}
|
|
3222
3223
|
this.currentAdIndex++;
|
|
3223
3224
|
console.log(`[DEBUG-POD] \u{1F680} Starting pod with ad ${this.currentAdIndex}/${this.totalAdsInBreak}`);
|
|
3224
|
-
|
|
3225
|
+
try {
|
|
3226
|
+
await this.playSingleAd(firstPreloaded);
|
|
3227
|
+
} catch (error) {
|
|
3228
|
+
console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
|
|
3229
|
+
}
|
|
3225
3230
|
}
|
|
3226
3231
|
findCurrentOrNextBreak(nowMs) {
|
|
3227
3232
|
var _a;
|
|
@@ -3430,6 +3435,13 @@ var StormcloudVideoPlayer = class {
|
|
|
3430
3435
|
console.log("[DEBUG-POD] \u274C handleAdFailure - skipping to next ad or ending break");
|
|
3431
3436
|
const remaining = this.getRemainingAdMs();
|
|
3432
3437
|
if (remaining > 500 && this.adPodQueue.length > 0) {
|
|
3438
|
+
if (this.isAdaptiveMode && this.currentAdIndex <= 1) {
|
|
3439
|
+
console.log("[ADAPTIVE-POD] \u23F3 First ad failed, waiting for sequential preload to catch up...");
|
|
3440
|
+
setTimeout(() => {
|
|
3441
|
+
this.tryNextAdWithRetry(0);
|
|
3442
|
+
}, 1500);
|
|
3443
|
+
return;
|
|
3444
|
+
}
|
|
3433
3445
|
const nextPreloaded = this.findNextPreloadedAd();
|
|
3434
3446
|
if (nextPreloaded) {
|
|
3435
3447
|
this.currentAdIndex++;
|
|
@@ -3443,6 +3455,42 @@ var StormcloudVideoPlayer = class {
|
|
|
3443
3455
|
console.log("[DEBUG-POD] \u23F9\uFE0F Ending ad break after failure");
|
|
3444
3456
|
this.handleAdPodComplete();
|
|
3445
3457
|
}
|
|
3458
|
+
tryNextAdWithRetry(retryCount) {
|
|
3459
|
+
const maxRetries = 3;
|
|
3460
|
+
const remaining = this.getRemainingAdMs();
|
|
3461
|
+
if (this.config.debugAdTiming) {
|
|
3462
|
+
console.log(
|
|
3463
|
+
`[ADAPTIVE-POD] \u{1F50D} Retry attempt ${retryCount}: remaining=${remaining}ms, queue=${this.adPodQueue.length}, totalAds=${this.totalAdsInBreak}`
|
|
3464
|
+
);
|
|
3465
|
+
}
|
|
3466
|
+
if (remaining <= 500 || this.adPodQueue.length === 0) {
|
|
3467
|
+
console.log("[ADAPTIVE-POD] \u23F9\uFE0F No more time or ads available");
|
|
3468
|
+
this.handleAdPodComplete();
|
|
3469
|
+
return;
|
|
3470
|
+
}
|
|
3471
|
+
const nextPreloaded = this.findNextPreloadedAd();
|
|
3472
|
+
if (nextPreloaded) {
|
|
3473
|
+
this.currentAdIndex++;
|
|
3474
|
+
console.log(
|
|
3475
|
+
`[ADAPTIVE-POD] \u2705 Found preloaded ad after retry ${retryCount}, playing (${this.currentAdIndex}/${this.totalAdsInBreak})`
|
|
3476
|
+
);
|
|
3477
|
+
this.playSingleAd(nextPreloaded).catch(() => {
|
|
3478
|
+
this.handleAdPodComplete();
|
|
3479
|
+
});
|
|
3480
|
+
} else if (retryCount < maxRetries) {
|
|
3481
|
+
console.log(
|
|
3482
|
+
`[ADAPTIVE-POD] \u23F3 No preloaded ads yet (queue has ${this.adPodQueue.length} URLs), retry ${retryCount + 1}/${maxRetries} in 1s...`
|
|
3483
|
+
);
|
|
3484
|
+
setTimeout(() => {
|
|
3485
|
+
this.tryNextAdWithRetry(retryCount + 1);
|
|
3486
|
+
}, 1e3);
|
|
3487
|
+
} else {
|
|
3488
|
+
console.log(
|
|
3489
|
+
`[ADAPTIVE-POD] \u274C Max retries reached, no preloaded ads available (queue=${this.adPodQueue.length} URLs)`
|
|
3490
|
+
);
|
|
3491
|
+
this.handleAdPodComplete();
|
|
3492
|
+
}
|
|
3493
|
+
}
|
|
3446
3494
|
startAdRequestWatchdog(token) {
|
|
3447
3495
|
var _a;
|
|
3448
3496
|
this.clearAdRequestWatchdog();
|
|
@@ -3653,22 +3701,12 @@ var StormcloudVideoPlayer = class {
|
|
|
3653
3701
|
);
|
|
3654
3702
|
if (this.config.debugAdTiming) {
|
|
3655
3703
|
console.log(
|
|
3656
|
-
`[ADAPTIVE-POD] \u{1F504} Adding ${newUrls.length} additional VAST URLs to queue`
|
|
3704
|
+
`[ADAPTIVE-POD] \u{1F504} Adding ${newUrls.length} additional VAST URLs to queue (will be preloaded sequentially)`
|
|
3657
3705
|
);
|
|
3658
3706
|
}
|
|
3659
3707
|
this.adPodAllUrls.push(...newUrls);
|
|
3660
3708
|
this.adPodQueue.push(...newUrls);
|
|
3661
3709
|
this.totalAdsInBreak += newUrls.length;
|
|
3662
|
-
for (const url of newUrls) {
|
|
3663
|
-
this.preloadSingleAd(url).catch((error) => {
|
|
3664
|
-
if (this.config.debugAdTiming) {
|
|
3665
|
-
console.warn(
|
|
3666
|
-
`[ADAPTIVE-POD] Failed to preload adaptive ad:`,
|
|
3667
|
-
error
|
|
3668
|
-
);
|
|
3669
|
-
}
|
|
3670
|
-
});
|
|
3671
|
-
}
|
|
3672
3710
|
}
|
|
3673
3711
|
async preloadMediaFile(mediaUrl) {
|
|
3674
3712
|
if (this.preloadedMediaUrls.has(mediaUrl)) {
|
|
@@ -3714,26 +3752,73 @@ var StormcloudVideoPlayer = class {
|
|
|
3714
3752
|
if (this.adPodAllUrls.length === 0) {
|
|
3715
3753
|
return;
|
|
3716
3754
|
}
|
|
3717
|
-
if (this.
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3755
|
+
if (this.isAdaptiveMode) {
|
|
3756
|
+
if (this.config.debugAdTiming) {
|
|
3757
|
+
console.log(
|
|
3758
|
+
`[ADAPTIVE-POD] \u{1F504} Starting sequential preload of ${this.adPodAllUrls.length} initial ads`
|
|
3759
|
+
);
|
|
3760
|
+
}
|
|
3761
|
+
const processedUrls = /* @__PURE__ */ new Set();
|
|
3762
|
+
while (true) {
|
|
3763
|
+
const nextUrl = this.adPodAllUrls.find((url) => !processedUrls.has(url));
|
|
3764
|
+
if (!nextUrl) {
|
|
3765
|
+
if (this.config.debugAdTiming) {
|
|
3766
|
+
console.log(`[ADAPTIVE-POD] \u2705 All queued ads processed (${processedUrls.size} total)`);
|
|
3767
|
+
}
|
|
3768
|
+
break;
|
|
3769
|
+
}
|
|
3770
|
+
processedUrls.add(nextUrl);
|
|
3724
3771
|
if (this.config.debugAdTiming) {
|
|
3725
|
-
console.
|
|
3726
|
-
`[
|
|
3727
|
-
error
|
|
3772
|
+
console.log(
|
|
3773
|
+
`[ADAPTIVE-POD] \u{1F4E5} Preloading ad ${processedUrls.size}/${this.adPodAllUrls.length}...`
|
|
3728
3774
|
);
|
|
3729
3775
|
}
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3776
|
+
try {
|
|
3777
|
+
await this.preloadSingleAd(nextUrl);
|
|
3778
|
+
} catch (error) {
|
|
3779
|
+
if (this.config.debugAdTiming) {
|
|
3780
|
+
console.warn(
|
|
3781
|
+
`[ADAPTIVE-POD] \u26A0\uFE0F Preload failed for ad ${processedUrls.size}:`,
|
|
3782
|
+
error
|
|
3783
|
+
);
|
|
3784
|
+
}
|
|
3785
|
+
}
|
|
3786
|
+
if (this.calculateAdditionalAdsNeeded() === 0) {
|
|
3787
|
+
if (this.config.debugAdTiming) {
|
|
3788
|
+
console.log(
|
|
3789
|
+
`[ADAPTIVE-POD] \u2705 Target duration reached (${processedUrls.size} ads preloaded), stopping`
|
|
3790
|
+
);
|
|
3791
|
+
}
|
|
3792
|
+
break;
|
|
3793
|
+
}
|
|
3794
|
+
}
|
|
3795
|
+
if (this.config.debugAdTiming) {
|
|
3796
|
+
console.log(
|
|
3797
|
+
`[ADAPTIVE-POD] \u2705 Sequential preloading completed (${processedUrls.size} ads ready)`
|
|
3798
|
+
);
|
|
3799
|
+
}
|
|
3800
|
+
} else {
|
|
3801
|
+
if (this.config.debugAdTiming) {
|
|
3802
|
+
console.log(
|
|
3803
|
+
`[StormcloudVideoPlayer] Starting parallel preload of ${this.adPodAllUrls.length} ads`
|
|
3804
|
+
);
|
|
3805
|
+
}
|
|
3806
|
+
const preloadPromises = this.adPodAllUrls.map(
|
|
3807
|
+
(vastTagUrl) => this.preloadSingleAd(vastTagUrl).catch((error) => {
|
|
3808
|
+
if (this.config.debugAdTiming) {
|
|
3809
|
+
console.warn(
|
|
3810
|
+
`[StormcloudVideoPlayer] Preload failed for ${vastTagUrl}:`,
|
|
3811
|
+
error
|
|
3812
|
+
);
|
|
3813
|
+
}
|
|
3814
|
+
})
|
|
3736
3815
|
);
|
|
3816
|
+
await Promise.all(preloadPromises);
|
|
3817
|
+
if (this.config.debugAdTiming) {
|
|
3818
|
+
console.log(
|
|
3819
|
+
`[StormcloudVideoPlayer] Background preloading completed for all ads`
|
|
3820
|
+
);
|
|
3821
|
+
}
|
|
3737
3822
|
}
|
|
3738
3823
|
}
|
|
3739
3824
|
async preloadSingleAd(vastTagUrl) {
|