stormcloud-video-player 0.3.1 → 0.3.3
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 +113 -21
- 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 +113 -21
- package/lib/index.js.map +1 -1
- package/lib/player/StormcloudVideoPlayer.cjs +113 -21
- package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/player/StormcloudVideoPlayer.d.cts +1 -0
- package/lib/players/HlsPlayer.cjs +113 -21
- package/lib/players/HlsPlayer.cjs.map +1 -1
- package/lib/players/index.cjs +113 -21
- package/lib/players/index.cjs.map +1 -1
- package/lib/ui/StormcloudVideoPlayer.cjs +113 -21
- package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -3251,19 +3251,34 @@ var StormcloudVideoPlayer = class {
|
|
|
3251
3251
|
this.currentAdIndex = 0;
|
|
3252
3252
|
this.totalAdsInBreak = vastTagUrls.length;
|
|
3253
3253
|
this.adPodQueue = [...vastTagUrls];
|
|
3254
|
-
this.
|
|
3254
|
+
if (this.isAdaptiveMode) {
|
|
3255
3255
|
if (this.config.debugAdTiming) {
|
|
3256
|
-
console.
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
);
|
|
3256
|
+
console.log("[ADAPTIVE-POD] Waiting for sequential preloading to complete...");
|
|
3257
|
+
}
|
|
3258
|
+
try {
|
|
3259
|
+
await this.preloadAllAdsInBackground();
|
|
3260
|
+
if (this.config.debugAdTiming) {
|
|
3261
|
+
console.log("[ADAPTIVE-POD] Preloading complete, starting playback");
|
|
3262
|
+
}
|
|
3263
|
+
} catch (error) {
|
|
3264
|
+
if (this.config.debugAdTiming) {
|
|
3265
|
+
console.warn(
|
|
3266
|
+
"[ADAPTIVE-POD] Error in preloading:",
|
|
3267
|
+
error
|
|
3268
|
+
);
|
|
3269
|
+
}
|
|
3260
3270
|
}
|
|
3261
|
-
});
|
|
3262
|
-
try {
|
|
3263
3271
|
await this.playAdPod();
|
|
3264
|
-
}
|
|
3265
|
-
|
|
3266
|
-
|
|
3272
|
+
} else {
|
|
3273
|
+
this.preloadAllAdsInBackground().catch((error) => {
|
|
3274
|
+
if (this.config.debugAdTiming) {
|
|
3275
|
+
console.warn(
|
|
3276
|
+
"[StormcloudVideoPlayer] Error in background preloading:",
|
|
3277
|
+
error
|
|
3278
|
+
);
|
|
3279
|
+
}
|
|
3280
|
+
});
|
|
3281
|
+
await this.playAdPod();
|
|
3267
3282
|
}
|
|
3268
3283
|
}
|
|
3269
3284
|
if (this.expectedAdBreakDurationMs == null && (scheduled == null ? void 0 : scheduled.durationMs) != null) {
|
|
@@ -3277,21 +3292,38 @@ var StormcloudVideoPlayer = class {
|
|
|
3277
3292
|
console.log("[DEBUG-POD] \u26A0\uFE0F No ads in pod");
|
|
3278
3293
|
return;
|
|
3279
3294
|
}
|
|
3280
|
-
const waitTime = this.isAdaptiveMode ?
|
|
3295
|
+
const waitTime = this.isAdaptiveMode ? 100 : 500;
|
|
3281
3296
|
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
3297
|
+
if (this.config.debugAdTiming) {
|
|
3298
|
+
console.log(
|
|
3299
|
+
`[DEBUG-POD] \u{1F50D} Looking for preloaded ad in queue of ${this.adPodQueue.length} URLs`
|
|
3300
|
+
);
|
|
3301
|
+
}
|
|
3282
3302
|
const firstPreloaded = this.findNextPreloadedAd();
|
|
3283
3303
|
if (!firstPreloaded) {
|
|
3284
|
-
console.log("[DEBUG-POD] \u26A0\uFE0F No preloaded ads
|
|
3304
|
+
console.log("[DEBUG-POD] \u26A0\uFE0F No preloaded ads found, trying first ad from queue");
|
|
3285
3305
|
const firstAd = this.adPodQueue.shift();
|
|
3286
3306
|
if (firstAd) {
|
|
3287
3307
|
this.currentAdIndex++;
|
|
3288
|
-
|
|
3308
|
+
console.log(`[DEBUG-POD] \u{1F3AC} Attempting to play first ad (not preloaded): ${firstAd.substring(0, 60)}...`);
|
|
3309
|
+
try {
|
|
3310
|
+
await this.playSingleAd(firstAd);
|
|
3311
|
+
} catch (error) {
|
|
3312
|
+
console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
|
|
3313
|
+
return;
|
|
3314
|
+
}
|
|
3315
|
+
} else {
|
|
3316
|
+
console.log("[DEBUG-POD] \u274C No ads available in queue");
|
|
3289
3317
|
}
|
|
3290
3318
|
return;
|
|
3291
3319
|
}
|
|
3292
3320
|
this.currentAdIndex++;
|
|
3293
3321
|
console.log(`[DEBUG-POD] \u{1F680} Starting pod with ad ${this.currentAdIndex}/${this.totalAdsInBreak}`);
|
|
3294
|
-
|
|
3322
|
+
try {
|
|
3323
|
+
await this.playSingleAd(firstPreloaded);
|
|
3324
|
+
} catch (error) {
|
|
3325
|
+
console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
|
|
3326
|
+
}
|
|
3295
3327
|
}
|
|
3296
3328
|
findCurrentOrNextBreak(nowMs) {
|
|
3297
3329
|
var _a;
|
|
@@ -3500,6 +3532,13 @@ var StormcloudVideoPlayer = class {
|
|
|
3500
3532
|
console.log("[DEBUG-POD] \u274C handleAdFailure - skipping to next ad or ending break");
|
|
3501
3533
|
const remaining = this.getRemainingAdMs();
|
|
3502
3534
|
if (remaining > 500 && this.adPodQueue.length > 0) {
|
|
3535
|
+
if (this.isAdaptiveMode && this.currentAdIndex <= 1) {
|
|
3536
|
+
console.log("[ADAPTIVE-POD] \u23F3 First ad failed, waiting for sequential preload to catch up...");
|
|
3537
|
+
setTimeout(() => {
|
|
3538
|
+
this.tryNextAdWithRetry(0);
|
|
3539
|
+
}, 1500);
|
|
3540
|
+
return;
|
|
3541
|
+
}
|
|
3503
3542
|
const nextPreloaded = this.findNextPreloadedAd();
|
|
3504
3543
|
if (nextPreloaded) {
|
|
3505
3544
|
this.currentAdIndex++;
|
|
@@ -3513,6 +3552,42 @@ var StormcloudVideoPlayer = class {
|
|
|
3513
3552
|
console.log("[DEBUG-POD] \u23F9\uFE0F Ending ad break after failure");
|
|
3514
3553
|
this.handleAdPodComplete();
|
|
3515
3554
|
}
|
|
3555
|
+
tryNextAdWithRetry(retryCount) {
|
|
3556
|
+
const maxRetries = 3;
|
|
3557
|
+
const remaining = this.getRemainingAdMs();
|
|
3558
|
+
if (this.config.debugAdTiming) {
|
|
3559
|
+
console.log(
|
|
3560
|
+
`[ADAPTIVE-POD] \u{1F50D} Retry attempt ${retryCount}: remaining=${remaining}ms, queue=${this.adPodQueue.length}, totalAds=${this.totalAdsInBreak}`
|
|
3561
|
+
);
|
|
3562
|
+
}
|
|
3563
|
+
if (remaining <= 500 || this.adPodQueue.length === 0) {
|
|
3564
|
+
console.log("[ADAPTIVE-POD] \u23F9\uFE0F No more time or ads available");
|
|
3565
|
+
this.handleAdPodComplete();
|
|
3566
|
+
return;
|
|
3567
|
+
}
|
|
3568
|
+
const nextPreloaded = this.findNextPreloadedAd();
|
|
3569
|
+
if (nextPreloaded) {
|
|
3570
|
+
this.currentAdIndex++;
|
|
3571
|
+
console.log(
|
|
3572
|
+
`[ADAPTIVE-POD] \u2705 Found preloaded ad after retry ${retryCount}, playing (${this.currentAdIndex}/${this.totalAdsInBreak})`
|
|
3573
|
+
);
|
|
3574
|
+
this.playSingleAd(nextPreloaded).catch(() => {
|
|
3575
|
+
this.handleAdPodComplete();
|
|
3576
|
+
});
|
|
3577
|
+
} else if (retryCount < maxRetries) {
|
|
3578
|
+
console.log(
|
|
3579
|
+
`[ADAPTIVE-POD] \u23F3 No preloaded ads yet (queue has ${this.adPodQueue.length} URLs), retry ${retryCount + 1}/${maxRetries} in 1s...`
|
|
3580
|
+
);
|
|
3581
|
+
setTimeout(() => {
|
|
3582
|
+
this.tryNextAdWithRetry(retryCount + 1);
|
|
3583
|
+
}, 1e3);
|
|
3584
|
+
} else {
|
|
3585
|
+
console.log(
|
|
3586
|
+
`[ADAPTIVE-POD] \u274C Max retries reached, no preloaded ads available (queue=${this.adPodQueue.length} URLs)`
|
|
3587
|
+
);
|
|
3588
|
+
this.handleAdPodComplete();
|
|
3589
|
+
}
|
|
3590
|
+
}
|
|
3516
3591
|
startAdRequestWatchdog(token) {
|
|
3517
3592
|
var _a;
|
|
3518
3593
|
this.clearAdRequestWatchdog();
|
|
@@ -3777,22 +3852,30 @@ var StormcloudVideoPlayer = class {
|
|
|
3777
3852
|
if (this.isAdaptiveMode) {
|
|
3778
3853
|
if (this.config.debugAdTiming) {
|
|
3779
3854
|
console.log(
|
|
3780
|
-
`[ADAPTIVE-POD] Starting sequential preload of ${this.adPodAllUrls.length} initial ads`
|
|
3855
|
+
`[ADAPTIVE-POD] \u{1F504} Starting sequential preload of ${this.adPodAllUrls.length} initial ads`
|
|
3781
3856
|
);
|
|
3782
3857
|
}
|
|
3783
3858
|
const processedUrls = /* @__PURE__ */ new Set();
|
|
3784
3859
|
while (true) {
|
|
3785
3860
|
const nextUrl = this.adPodAllUrls.find((url) => !processedUrls.has(url));
|
|
3786
3861
|
if (!nextUrl) {
|
|
3862
|
+
if (this.config.debugAdTiming) {
|
|
3863
|
+
console.log(`[ADAPTIVE-POD] \u2705 All queued ads processed (${processedUrls.size} total)`);
|
|
3864
|
+
}
|
|
3787
3865
|
break;
|
|
3788
3866
|
}
|
|
3789
3867
|
processedUrls.add(nextUrl);
|
|
3868
|
+
if (this.config.debugAdTiming) {
|
|
3869
|
+
console.log(
|
|
3870
|
+
`[ADAPTIVE-POD] \u{1F4E5} Preloading ad ${processedUrls.size}/${this.adPodAllUrls.length}...`
|
|
3871
|
+
);
|
|
3872
|
+
}
|
|
3790
3873
|
try {
|
|
3791
3874
|
await this.preloadSingleAd(nextUrl);
|
|
3792
3875
|
} catch (error) {
|
|
3793
3876
|
if (this.config.debugAdTiming) {
|
|
3794
3877
|
console.warn(
|
|
3795
|
-
`[ADAPTIVE-POD] Preload failed for ${
|
|
3878
|
+
`[ADAPTIVE-POD] \u26A0\uFE0F Preload failed for ad ${processedUrls.size}:`,
|
|
3796
3879
|
error
|
|
3797
3880
|
);
|
|
3798
3881
|
}
|
|
@@ -3800,7 +3883,7 @@ var StormcloudVideoPlayer = class {
|
|
|
3800
3883
|
if (this.calculateAdditionalAdsNeeded() === 0) {
|
|
3801
3884
|
if (this.config.debugAdTiming) {
|
|
3802
3885
|
console.log(
|
|
3803
|
-
`[ADAPTIVE-POD] \u2705 Target duration reached, stopping
|
|
3886
|
+
`[ADAPTIVE-POD] \u2705 Target duration reached (${processedUrls.size} ads preloaded), stopping`
|
|
3804
3887
|
);
|
|
3805
3888
|
}
|
|
3806
3889
|
break;
|
|
@@ -3808,7 +3891,7 @@ var StormcloudVideoPlayer = class {
|
|
|
3808
3891
|
}
|
|
3809
3892
|
if (this.config.debugAdTiming) {
|
|
3810
3893
|
console.log(
|
|
3811
|
-
`[ADAPTIVE-POD] Sequential preloading completed (${processedUrls.size} ads
|
|
3894
|
+
`[ADAPTIVE-POD] \u2705 Sequential preloading completed (${processedUrls.size} ads ready)`
|
|
3812
3895
|
);
|
|
3813
3896
|
}
|
|
3814
3897
|
} else {
|
|
@@ -3905,17 +3988,26 @@ var StormcloudVideoPlayer = class {
|
|
|
3905
3988
|
}
|
|
3906
3989
|
findNextPreloadedAd() {
|
|
3907
3990
|
var _a, _b, _c;
|
|
3991
|
+
if (this.config.debugAdTiming) {
|
|
3992
|
+
console.log(
|
|
3993
|
+
`[DEBUG-POD] \u{1F50E} Searching for preloaded ad in queue (${this.adPodQueue.length} URLs, ${this.preloadedMediaUrls.size} media preloaded, ${this.vastToMediaUrlMap.size} VAST mappings)`
|
|
3994
|
+
);
|
|
3995
|
+
}
|
|
3908
3996
|
for (let i = 0; i < this.adPodQueue.length; i++) {
|
|
3909
3997
|
const vastTagUrl = this.adPodQueue[i];
|
|
3910
3998
|
if (!vastTagUrl) continue;
|
|
3911
3999
|
const hasImaPreload = (_c = (_b = (_a = this.ima).hasPreloadedAd) == null ? void 0 : _b.call(_a, vastTagUrl)) != null ? _c : false;
|
|
3912
4000
|
const mediaUrls = this.vastToMediaUrlMap.get(vastTagUrl);
|
|
3913
4001
|
const hasMediaPreload = mediaUrls && mediaUrls.length > 0 ? this.preloadedMediaUrls.has(mediaUrls[0]) : false;
|
|
4002
|
+
if (this.config.debugAdTiming) {
|
|
4003
|
+
console.log(
|
|
4004
|
+
`[DEBUG-POD] Ad ${i}: IMA=${hasImaPreload}, Media=${hasMediaPreload}, MediaURLs=${(mediaUrls == null ? void 0 : mediaUrls.length) || 0}, URL=${vastTagUrl.substring(0, 60)}...`
|
|
4005
|
+
);
|
|
4006
|
+
}
|
|
3914
4007
|
if (hasImaPreload || hasMediaPreload) {
|
|
3915
4008
|
if (this.config.debugAdTiming) {
|
|
3916
4009
|
console.log(
|
|
3917
|
-
`[
|
|
3918
|
-
{ hasImaPreload, hasMediaPreload }
|
|
4010
|
+
`[DEBUG-POD] \u2705 Found preloaded ad at index ${i}`
|
|
3919
4011
|
);
|
|
3920
4012
|
}
|
|
3921
4013
|
this.adPodQueue.splice(0, i + 1);
|
|
@@ -3924,7 +4016,7 @@ var StormcloudVideoPlayer = class {
|
|
|
3924
4016
|
}
|
|
3925
4017
|
if (this.config.debugAdTiming) {
|
|
3926
4018
|
console.log(
|
|
3927
|
-
|
|
4019
|
+
`[DEBUG-POD] \u274C No preloaded ads found in queue`
|
|
3928
4020
|
);
|
|
3929
4021
|
}
|
|
3930
4022
|
return void 0;
|