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.cjs
CHANGED
|
@@ -3259,12 +3259,7 @@ var StormcloudVideoPlayer = class {
|
|
|
3259
3259
|
);
|
|
3260
3260
|
}
|
|
3261
3261
|
});
|
|
3262
|
-
|
|
3263
|
-
await this.playAdPod();
|
|
3264
|
-
} catch (error) {
|
|
3265
|
-
console.error("[DEBUG-POD] \u274C Pod playback failed:", error);
|
|
3266
|
-
this.handleAdFailure();
|
|
3267
|
-
}
|
|
3262
|
+
await this.playAdPod();
|
|
3268
3263
|
}
|
|
3269
3264
|
if (this.expectedAdBreakDurationMs == null && (scheduled == null ? void 0 : scheduled.durationMs) != null) {
|
|
3270
3265
|
this.expectedAdBreakDurationMs = scheduled.durationMs;
|
|
@@ -3277,20 +3272,30 @@ var StormcloudVideoPlayer = class {
|
|
|
3277
3272
|
console.log("[DEBUG-POD] \u26A0\uFE0F No ads in pod");
|
|
3278
3273
|
return;
|
|
3279
3274
|
}
|
|
3280
|
-
|
|
3275
|
+
const waitTime = this.isAdaptiveMode ? 1500 : 500;
|
|
3276
|
+
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
3281
3277
|
const firstPreloaded = this.findNextPreloadedAd();
|
|
3282
3278
|
if (!firstPreloaded) {
|
|
3283
3279
|
console.log("[DEBUG-POD] \u26A0\uFE0F No preloaded ads after wait, trying first ad");
|
|
3284
3280
|
const firstAd = this.adPodQueue.shift();
|
|
3285
3281
|
if (firstAd) {
|
|
3286
3282
|
this.currentAdIndex++;
|
|
3287
|
-
|
|
3283
|
+
try {
|
|
3284
|
+
await this.playSingleAd(firstAd);
|
|
3285
|
+
} catch (error) {
|
|
3286
|
+
console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
|
|
3287
|
+
return;
|
|
3288
|
+
}
|
|
3288
3289
|
}
|
|
3289
3290
|
return;
|
|
3290
3291
|
}
|
|
3291
3292
|
this.currentAdIndex++;
|
|
3292
3293
|
console.log(`[DEBUG-POD] \u{1F680} Starting pod with ad ${this.currentAdIndex}/${this.totalAdsInBreak}`);
|
|
3293
|
-
|
|
3294
|
+
try {
|
|
3295
|
+
await this.playSingleAd(firstPreloaded);
|
|
3296
|
+
} catch (error) {
|
|
3297
|
+
console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
|
|
3298
|
+
}
|
|
3294
3299
|
}
|
|
3295
3300
|
findCurrentOrNextBreak(nowMs) {
|
|
3296
3301
|
var _a;
|
|
@@ -3499,6 +3504,13 @@ var StormcloudVideoPlayer = class {
|
|
|
3499
3504
|
console.log("[DEBUG-POD] \u274C handleAdFailure - skipping to next ad or ending break");
|
|
3500
3505
|
const remaining = this.getRemainingAdMs();
|
|
3501
3506
|
if (remaining > 500 && this.adPodQueue.length > 0) {
|
|
3507
|
+
if (this.isAdaptiveMode && this.currentAdIndex <= 1) {
|
|
3508
|
+
console.log("[ADAPTIVE-POD] \u23F3 First ad failed, waiting for sequential preload to catch up...");
|
|
3509
|
+
setTimeout(() => {
|
|
3510
|
+
this.tryNextAdWithRetry(0);
|
|
3511
|
+
}, 1500);
|
|
3512
|
+
return;
|
|
3513
|
+
}
|
|
3502
3514
|
const nextPreloaded = this.findNextPreloadedAd();
|
|
3503
3515
|
if (nextPreloaded) {
|
|
3504
3516
|
this.currentAdIndex++;
|
|
@@ -3512,6 +3524,42 @@ var StormcloudVideoPlayer = class {
|
|
|
3512
3524
|
console.log("[DEBUG-POD] \u23F9\uFE0F Ending ad break after failure");
|
|
3513
3525
|
this.handleAdPodComplete();
|
|
3514
3526
|
}
|
|
3527
|
+
tryNextAdWithRetry(retryCount) {
|
|
3528
|
+
const maxRetries = 3;
|
|
3529
|
+
const remaining = this.getRemainingAdMs();
|
|
3530
|
+
if (this.config.debugAdTiming) {
|
|
3531
|
+
console.log(
|
|
3532
|
+
`[ADAPTIVE-POD] \u{1F50D} Retry attempt ${retryCount}: remaining=${remaining}ms, queue=${this.adPodQueue.length}, totalAds=${this.totalAdsInBreak}`
|
|
3533
|
+
);
|
|
3534
|
+
}
|
|
3535
|
+
if (remaining <= 500 || this.adPodQueue.length === 0) {
|
|
3536
|
+
console.log("[ADAPTIVE-POD] \u23F9\uFE0F No more time or ads available");
|
|
3537
|
+
this.handleAdPodComplete();
|
|
3538
|
+
return;
|
|
3539
|
+
}
|
|
3540
|
+
const nextPreloaded = this.findNextPreloadedAd();
|
|
3541
|
+
if (nextPreloaded) {
|
|
3542
|
+
this.currentAdIndex++;
|
|
3543
|
+
console.log(
|
|
3544
|
+
`[ADAPTIVE-POD] \u2705 Found preloaded ad after retry ${retryCount}, playing (${this.currentAdIndex}/${this.totalAdsInBreak})`
|
|
3545
|
+
);
|
|
3546
|
+
this.playSingleAd(nextPreloaded).catch(() => {
|
|
3547
|
+
this.handleAdPodComplete();
|
|
3548
|
+
});
|
|
3549
|
+
} else if (retryCount < maxRetries) {
|
|
3550
|
+
console.log(
|
|
3551
|
+
`[ADAPTIVE-POD] \u23F3 No preloaded ads yet (queue has ${this.adPodQueue.length} URLs), retry ${retryCount + 1}/${maxRetries} in 1s...`
|
|
3552
|
+
);
|
|
3553
|
+
setTimeout(() => {
|
|
3554
|
+
this.tryNextAdWithRetry(retryCount + 1);
|
|
3555
|
+
}, 1e3);
|
|
3556
|
+
} else {
|
|
3557
|
+
console.log(
|
|
3558
|
+
`[ADAPTIVE-POD] \u274C Max retries reached, no preloaded ads available (queue=${this.adPodQueue.length} URLs)`
|
|
3559
|
+
);
|
|
3560
|
+
this.handleAdPodComplete();
|
|
3561
|
+
}
|
|
3562
|
+
}
|
|
3515
3563
|
startAdRequestWatchdog(token) {
|
|
3516
3564
|
var _a;
|
|
3517
3565
|
this.clearAdRequestWatchdog();
|
|
@@ -3722,22 +3770,12 @@ var StormcloudVideoPlayer = class {
|
|
|
3722
3770
|
);
|
|
3723
3771
|
if (this.config.debugAdTiming) {
|
|
3724
3772
|
console.log(
|
|
3725
|
-
`[ADAPTIVE-POD] \u{1F504} Adding ${newUrls.length} additional VAST URLs to queue`
|
|
3773
|
+
`[ADAPTIVE-POD] \u{1F504} Adding ${newUrls.length} additional VAST URLs to queue (will be preloaded sequentially)`
|
|
3726
3774
|
);
|
|
3727
3775
|
}
|
|
3728
3776
|
this.adPodAllUrls.push(...newUrls);
|
|
3729
3777
|
this.adPodQueue.push(...newUrls);
|
|
3730
3778
|
this.totalAdsInBreak += newUrls.length;
|
|
3731
|
-
for (const url of newUrls) {
|
|
3732
|
-
this.preloadSingleAd(url).catch((error) => {
|
|
3733
|
-
if (this.config.debugAdTiming) {
|
|
3734
|
-
console.warn(
|
|
3735
|
-
`[ADAPTIVE-POD] Failed to preload adaptive ad:`,
|
|
3736
|
-
error
|
|
3737
|
-
);
|
|
3738
|
-
}
|
|
3739
|
-
});
|
|
3740
|
-
}
|
|
3741
3779
|
}
|
|
3742
3780
|
async preloadMediaFile(mediaUrl) {
|
|
3743
3781
|
if (this.preloadedMediaUrls.has(mediaUrl)) {
|
|
@@ -3783,26 +3821,73 @@ var StormcloudVideoPlayer = class {
|
|
|
3783
3821
|
if (this.adPodAllUrls.length === 0) {
|
|
3784
3822
|
return;
|
|
3785
3823
|
}
|
|
3786
|
-
if (this.
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3824
|
+
if (this.isAdaptiveMode) {
|
|
3825
|
+
if (this.config.debugAdTiming) {
|
|
3826
|
+
console.log(
|
|
3827
|
+
`[ADAPTIVE-POD] \u{1F504} Starting sequential preload of ${this.adPodAllUrls.length} initial ads`
|
|
3828
|
+
);
|
|
3829
|
+
}
|
|
3830
|
+
const processedUrls = /* @__PURE__ */ new Set();
|
|
3831
|
+
while (true) {
|
|
3832
|
+
const nextUrl = this.adPodAllUrls.find((url) => !processedUrls.has(url));
|
|
3833
|
+
if (!nextUrl) {
|
|
3834
|
+
if (this.config.debugAdTiming) {
|
|
3835
|
+
console.log(`[ADAPTIVE-POD] \u2705 All queued ads processed (${processedUrls.size} total)`);
|
|
3836
|
+
}
|
|
3837
|
+
break;
|
|
3838
|
+
}
|
|
3839
|
+
processedUrls.add(nextUrl);
|
|
3793
3840
|
if (this.config.debugAdTiming) {
|
|
3794
|
-
console.
|
|
3795
|
-
`[
|
|
3796
|
-
error
|
|
3841
|
+
console.log(
|
|
3842
|
+
`[ADAPTIVE-POD] \u{1F4E5} Preloading ad ${processedUrls.size}/${this.adPodAllUrls.length}...`
|
|
3797
3843
|
);
|
|
3798
3844
|
}
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3845
|
+
try {
|
|
3846
|
+
await this.preloadSingleAd(nextUrl);
|
|
3847
|
+
} catch (error) {
|
|
3848
|
+
if (this.config.debugAdTiming) {
|
|
3849
|
+
console.warn(
|
|
3850
|
+
`[ADAPTIVE-POD] \u26A0\uFE0F Preload failed for ad ${processedUrls.size}:`,
|
|
3851
|
+
error
|
|
3852
|
+
);
|
|
3853
|
+
}
|
|
3854
|
+
}
|
|
3855
|
+
if (this.calculateAdditionalAdsNeeded() === 0) {
|
|
3856
|
+
if (this.config.debugAdTiming) {
|
|
3857
|
+
console.log(
|
|
3858
|
+
`[ADAPTIVE-POD] \u2705 Target duration reached (${processedUrls.size} ads preloaded), stopping`
|
|
3859
|
+
);
|
|
3860
|
+
}
|
|
3861
|
+
break;
|
|
3862
|
+
}
|
|
3863
|
+
}
|
|
3864
|
+
if (this.config.debugAdTiming) {
|
|
3865
|
+
console.log(
|
|
3866
|
+
`[ADAPTIVE-POD] \u2705 Sequential preloading completed (${processedUrls.size} ads ready)`
|
|
3867
|
+
);
|
|
3868
|
+
}
|
|
3869
|
+
} else {
|
|
3870
|
+
if (this.config.debugAdTiming) {
|
|
3871
|
+
console.log(
|
|
3872
|
+
`[StormcloudVideoPlayer] Starting parallel preload of ${this.adPodAllUrls.length} ads`
|
|
3873
|
+
);
|
|
3874
|
+
}
|
|
3875
|
+
const preloadPromises = this.adPodAllUrls.map(
|
|
3876
|
+
(vastTagUrl) => this.preloadSingleAd(vastTagUrl).catch((error) => {
|
|
3877
|
+
if (this.config.debugAdTiming) {
|
|
3878
|
+
console.warn(
|
|
3879
|
+
`[StormcloudVideoPlayer] Preload failed for ${vastTagUrl}:`,
|
|
3880
|
+
error
|
|
3881
|
+
);
|
|
3882
|
+
}
|
|
3883
|
+
})
|
|
3805
3884
|
);
|
|
3885
|
+
await Promise.all(preloadPromises);
|
|
3886
|
+
if (this.config.debugAdTiming) {
|
|
3887
|
+
console.log(
|
|
3888
|
+
`[StormcloudVideoPlayer] Background preloading completed for all ads`
|
|
3889
|
+
);
|
|
3890
|
+
}
|
|
3806
3891
|
}
|
|
3807
3892
|
}
|
|
3808
3893
|
async preloadSingleAd(vastTagUrl) {
|