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/players/index.cjs
CHANGED
|
@@ -3234,12 +3234,7 @@ var StormcloudVideoPlayer = class {
|
|
|
3234
3234
|
);
|
|
3235
3235
|
}
|
|
3236
3236
|
});
|
|
3237
|
-
|
|
3238
|
-
await this.playAdPod();
|
|
3239
|
-
} catch (error) {
|
|
3240
|
-
console.error("[DEBUG-POD] \u274C Pod playback failed:", error);
|
|
3241
|
-
this.handleAdFailure();
|
|
3242
|
-
}
|
|
3237
|
+
await this.playAdPod();
|
|
3243
3238
|
}
|
|
3244
3239
|
if (this.expectedAdBreakDurationMs == null && (scheduled == null ? void 0 : scheduled.durationMs) != null) {
|
|
3245
3240
|
this.expectedAdBreakDurationMs = scheduled.durationMs;
|
|
@@ -3252,20 +3247,30 @@ var StormcloudVideoPlayer = class {
|
|
|
3252
3247
|
console.log("[DEBUG-POD] \u26A0\uFE0F No ads in pod");
|
|
3253
3248
|
return;
|
|
3254
3249
|
}
|
|
3255
|
-
|
|
3250
|
+
const waitTime = this.isAdaptiveMode ? 1500 : 500;
|
|
3251
|
+
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
3256
3252
|
const firstPreloaded = this.findNextPreloadedAd();
|
|
3257
3253
|
if (!firstPreloaded) {
|
|
3258
3254
|
console.log("[DEBUG-POD] \u26A0\uFE0F No preloaded ads after wait, trying first ad");
|
|
3259
3255
|
const firstAd = this.adPodQueue.shift();
|
|
3260
3256
|
if (firstAd) {
|
|
3261
3257
|
this.currentAdIndex++;
|
|
3262
|
-
|
|
3258
|
+
try {
|
|
3259
|
+
await this.playSingleAd(firstAd);
|
|
3260
|
+
} catch (error) {
|
|
3261
|
+
console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
|
|
3262
|
+
return;
|
|
3263
|
+
}
|
|
3263
3264
|
}
|
|
3264
3265
|
return;
|
|
3265
3266
|
}
|
|
3266
3267
|
this.currentAdIndex++;
|
|
3267
3268
|
console.log(`[DEBUG-POD] \u{1F680} Starting pod with ad ${this.currentAdIndex}/${this.totalAdsInBreak}`);
|
|
3268
|
-
|
|
3269
|
+
try {
|
|
3270
|
+
await this.playSingleAd(firstPreloaded);
|
|
3271
|
+
} catch (error) {
|
|
3272
|
+
console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
|
|
3273
|
+
}
|
|
3269
3274
|
}
|
|
3270
3275
|
findCurrentOrNextBreak(nowMs) {
|
|
3271
3276
|
var _a;
|
|
@@ -3474,6 +3479,13 @@ var StormcloudVideoPlayer = class {
|
|
|
3474
3479
|
console.log("[DEBUG-POD] \u274C handleAdFailure - skipping to next ad or ending break");
|
|
3475
3480
|
const remaining = this.getRemainingAdMs();
|
|
3476
3481
|
if (remaining > 500 && this.adPodQueue.length > 0) {
|
|
3482
|
+
if (this.isAdaptiveMode && this.currentAdIndex <= 1) {
|
|
3483
|
+
console.log("[ADAPTIVE-POD] \u23F3 First ad failed, waiting for sequential preload to catch up...");
|
|
3484
|
+
setTimeout(() => {
|
|
3485
|
+
this.tryNextAdWithRetry(0);
|
|
3486
|
+
}, 1500);
|
|
3487
|
+
return;
|
|
3488
|
+
}
|
|
3477
3489
|
const nextPreloaded = this.findNextPreloadedAd();
|
|
3478
3490
|
if (nextPreloaded) {
|
|
3479
3491
|
this.currentAdIndex++;
|
|
@@ -3487,6 +3499,42 @@ var StormcloudVideoPlayer = class {
|
|
|
3487
3499
|
console.log("[DEBUG-POD] \u23F9\uFE0F Ending ad break after failure");
|
|
3488
3500
|
this.handleAdPodComplete();
|
|
3489
3501
|
}
|
|
3502
|
+
tryNextAdWithRetry(retryCount) {
|
|
3503
|
+
const maxRetries = 3;
|
|
3504
|
+
const remaining = this.getRemainingAdMs();
|
|
3505
|
+
if (this.config.debugAdTiming) {
|
|
3506
|
+
console.log(
|
|
3507
|
+
`[ADAPTIVE-POD] \u{1F50D} Retry attempt ${retryCount}: remaining=${remaining}ms, queue=${this.adPodQueue.length}, totalAds=${this.totalAdsInBreak}`
|
|
3508
|
+
);
|
|
3509
|
+
}
|
|
3510
|
+
if (remaining <= 500 || this.adPodQueue.length === 0) {
|
|
3511
|
+
console.log("[ADAPTIVE-POD] \u23F9\uFE0F No more time or ads available");
|
|
3512
|
+
this.handleAdPodComplete();
|
|
3513
|
+
return;
|
|
3514
|
+
}
|
|
3515
|
+
const nextPreloaded = this.findNextPreloadedAd();
|
|
3516
|
+
if (nextPreloaded) {
|
|
3517
|
+
this.currentAdIndex++;
|
|
3518
|
+
console.log(
|
|
3519
|
+
`[ADAPTIVE-POD] \u2705 Found preloaded ad after retry ${retryCount}, playing (${this.currentAdIndex}/${this.totalAdsInBreak})`
|
|
3520
|
+
);
|
|
3521
|
+
this.playSingleAd(nextPreloaded).catch(() => {
|
|
3522
|
+
this.handleAdPodComplete();
|
|
3523
|
+
});
|
|
3524
|
+
} else if (retryCount < maxRetries) {
|
|
3525
|
+
console.log(
|
|
3526
|
+
`[ADAPTIVE-POD] \u23F3 No preloaded ads yet (queue has ${this.adPodQueue.length} URLs), retry ${retryCount + 1}/${maxRetries} in 1s...`
|
|
3527
|
+
);
|
|
3528
|
+
setTimeout(() => {
|
|
3529
|
+
this.tryNextAdWithRetry(retryCount + 1);
|
|
3530
|
+
}, 1e3);
|
|
3531
|
+
} else {
|
|
3532
|
+
console.log(
|
|
3533
|
+
`[ADAPTIVE-POD] \u274C Max retries reached, no preloaded ads available (queue=${this.adPodQueue.length} URLs)`
|
|
3534
|
+
);
|
|
3535
|
+
this.handleAdPodComplete();
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3490
3538
|
startAdRequestWatchdog(token) {
|
|
3491
3539
|
var _a;
|
|
3492
3540
|
this.clearAdRequestWatchdog();
|
|
@@ -3697,22 +3745,12 @@ var StormcloudVideoPlayer = class {
|
|
|
3697
3745
|
);
|
|
3698
3746
|
if (this.config.debugAdTiming) {
|
|
3699
3747
|
console.log(
|
|
3700
|
-
`[ADAPTIVE-POD] \u{1F504} Adding ${newUrls.length} additional VAST URLs to queue`
|
|
3748
|
+
`[ADAPTIVE-POD] \u{1F504} Adding ${newUrls.length} additional VAST URLs to queue (will be preloaded sequentially)`
|
|
3701
3749
|
);
|
|
3702
3750
|
}
|
|
3703
3751
|
this.adPodAllUrls.push(...newUrls);
|
|
3704
3752
|
this.adPodQueue.push(...newUrls);
|
|
3705
3753
|
this.totalAdsInBreak += newUrls.length;
|
|
3706
|
-
for (const url of newUrls) {
|
|
3707
|
-
this.preloadSingleAd(url).catch((error) => {
|
|
3708
|
-
if (this.config.debugAdTiming) {
|
|
3709
|
-
console.warn(
|
|
3710
|
-
`[ADAPTIVE-POD] Failed to preload adaptive ad:`,
|
|
3711
|
-
error
|
|
3712
|
-
);
|
|
3713
|
-
}
|
|
3714
|
-
});
|
|
3715
|
-
}
|
|
3716
3754
|
}
|
|
3717
3755
|
async preloadMediaFile(mediaUrl) {
|
|
3718
3756
|
if (this.preloadedMediaUrls.has(mediaUrl)) {
|
|
@@ -3758,26 +3796,73 @@ var StormcloudVideoPlayer = class {
|
|
|
3758
3796
|
if (this.adPodAllUrls.length === 0) {
|
|
3759
3797
|
return;
|
|
3760
3798
|
}
|
|
3761
|
-
if (this.
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3799
|
+
if (this.isAdaptiveMode) {
|
|
3800
|
+
if (this.config.debugAdTiming) {
|
|
3801
|
+
console.log(
|
|
3802
|
+
`[ADAPTIVE-POD] \u{1F504} Starting sequential preload of ${this.adPodAllUrls.length} initial ads`
|
|
3803
|
+
);
|
|
3804
|
+
}
|
|
3805
|
+
const processedUrls = /* @__PURE__ */ new Set();
|
|
3806
|
+
while (true) {
|
|
3807
|
+
const nextUrl = this.adPodAllUrls.find((url) => !processedUrls.has(url));
|
|
3808
|
+
if (!nextUrl) {
|
|
3809
|
+
if (this.config.debugAdTiming) {
|
|
3810
|
+
console.log(`[ADAPTIVE-POD] \u2705 All queued ads processed (${processedUrls.size} total)`);
|
|
3811
|
+
}
|
|
3812
|
+
break;
|
|
3813
|
+
}
|
|
3814
|
+
processedUrls.add(nextUrl);
|
|
3768
3815
|
if (this.config.debugAdTiming) {
|
|
3769
|
-
console.
|
|
3770
|
-
`[
|
|
3771
|
-
error
|
|
3816
|
+
console.log(
|
|
3817
|
+
`[ADAPTIVE-POD] \u{1F4E5} Preloading ad ${processedUrls.size}/${this.adPodAllUrls.length}...`
|
|
3772
3818
|
);
|
|
3773
3819
|
}
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3820
|
+
try {
|
|
3821
|
+
await this.preloadSingleAd(nextUrl);
|
|
3822
|
+
} catch (error) {
|
|
3823
|
+
if (this.config.debugAdTiming) {
|
|
3824
|
+
console.warn(
|
|
3825
|
+
`[ADAPTIVE-POD] \u26A0\uFE0F Preload failed for ad ${processedUrls.size}:`,
|
|
3826
|
+
error
|
|
3827
|
+
);
|
|
3828
|
+
}
|
|
3829
|
+
}
|
|
3830
|
+
if (this.calculateAdditionalAdsNeeded() === 0) {
|
|
3831
|
+
if (this.config.debugAdTiming) {
|
|
3832
|
+
console.log(
|
|
3833
|
+
`[ADAPTIVE-POD] \u2705 Target duration reached (${processedUrls.size} ads preloaded), stopping`
|
|
3834
|
+
);
|
|
3835
|
+
}
|
|
3836
|
+
break;
|
|
3837
|
+
}
|
|
3838
|
+
}
|
|
3839
|
+
if (this.config.debugAdTiming) {
|
|
3840
|
+
console.log(
|
|
3841
|
+
`[ADAPTIVE-POD] \u2705 Sequential preloading completed (${processedUrls.size} ads ready)`
|
|
3842
|
+
);
|
|
3843
|
+
}
|
|
3844
|
+
} else {
|
|
3845
|
+
if (this.config.debugAdTiming) {
|
|
3846
|
+
console.log(
|
|
3847
|
+
`[StormcloudVideoPlayer] Starting parallel preload of ${this.adPodAllUrls.length} ads`
|
|
3848
|
+
);
|
|
3849
|
+
}
|
|
3850
|
+
const preloadPromises = this.adPodAllUrls.map(
|
|
3851
|
+
(vastTagUrl) => this.preloadSingleAd(vastTagUrl).catch((error) => {
|
|
3852
|
+
if (this.config.debugAdTiming) {
|
|
3853
|
+
console.warn(
|
|
3854
|
+
`[StormcloudVideoPlayer] Preload failed for ${vastTagUrl}:`,
|
|
3855
|
+
error
|
|
3856
|
+
);
|
|
3857
|
+
}
|
|
3858
|
+
})
|
|
3780
3859
|
);
|
|
3860
|
+
await Promise.all(preloadPromises);
|
|
3861
|
+
if (this.config.debugAdTiming) {
|
|
3862
|
+
console.log(
|
|
3863
|
+
`[StormcloudVideoPlayer] Background preloading completed for all ads`
|
|
3864
|
+
);
|
|
3865
|
+
}
|
|
3781
3866
|
}
|
|
3782
3867
|
}
|
|
3783
3868
|
async preloadSingleAd(vastTagUrl) {
|