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/players/index.cjs
CHANGED
|
@@ -3226,19 +3226,34 @@ var StormcloudVideoPlayer = class {
|
|
|
3226
3226
|
this.currentAdIndex = 0;
|
|
3227
3227
|
this.totalAdsInBreak = vastTagUrls.length;
|
|
3228
3228
|
this.adPodQueue = [...vastTagUrls];
|
|
3229
|
-
this.
|
|
3229
|
+
if (this.isAdaptiveMode) {
|
|
3230
3230
|
if (this.config.debugAdTiming) {
|
|
3231
|
-
console.
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
);
|
|
3231
|
+
console.log("[ADAPTIVE-POD] Waiting for sequential preloading to complete...");
|
|
3232
|
+
}
|
|
3233
|
+
try {
|
|
3234
|
+
await this.preloadAllAdsInBackground();
|
|
3235
|
+
if (this.config.debugAdTiming) {
|
|
3236
|
+
console.log("[ADAPTIVE-POD] Preloading complete, starting playback");
|
|
3237
|
+
}
|
|
3238
|
+
} catch (error) {
|
|
3239
|
+
if (this.config.debugAdTiming) {
|
|
3240
|
+
console.warn(
|
|
3241
|
+
"[ADAPTIVE-POD] Error in preloading:",
|
|
3242
|
+
error
|
|
3243
|
+
);
|
|
3244
|
+
}
|
|
3235
3245
|
}
|
|
3236
|
-
});
|
|
3237
|
-
try {
|
|
3238
3246
|
await this.playAdPod();
|
|
3239
|
-
}
|
|
3240
|
-
|
|
3241
|
-
|
|
3247
|
+
} else {
|
|
3248
|
+
this.preloadAllAdsInBackground().catch((error) => {
|
|
3249
|
+
if (this.config.debugAdTiming) {
|
|
3250
|
+
console.warn(
|
|
3251
|
+
"[StormcloudVideoPlayer] Error in background preloading:",
|
|
3252
|
+
error
|
|
3253
|
+
);
|
|
3254
|
+
}
|
|
3255
|
+
});
|
|
3256
|
+
await this.playAdPod();
|
|
3242
3257
|
}
|
|
3243
3258
|
}
|
|
3244
3259
|
if (this.expectedAdBreakDurationMs == null && (scheduled == null ? void 0 : scheduled.durationMs) != null) {
|
|
@@ -3252,21 +3267,38 @@ var StormcloudVideoPlayer = class {
|
|
|
3252
3267
|
console.log("[DEBUG-POD] \u26A0\uFE0F No ads in pod");
|
|
3253
3268
|
return;
|
|
3254
3269
|
}
|
|
3255
|
-
const waitTime = this.isAdaptiveMode ?
|
|
3270
|
+
const waitTime = this.isAdaptiveMode ? 100 : 500;
|
|
3256
3271
|
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
3272
|
+
if (this.config.debugAdTiming) {
|
|
3273
|
+
console.log(
|
|
3274
|
+
`[DEBUG-POD] \u{1F50D} Looking for preloaded ad in queue of ${this.adPodQueue.length} URLs`
|
|
3275
|
+
);
|
|
3276
|
+
}
|
|
3257
3277
|
const firstPreloaded = this.findNextPreloadedAd();
|
|
3258
3278
|
if (!firstPreloaded) {
|
|
3259
|
-
console.log("[DEBUG-POD] \u26A0\uFE0F No preloaded ads
|
|
3279
|
+
console.log("[DEBUG-POD] \u26A0\uFE0F No preloaded ads found, trying first ad from queue");
|
|
3260
3280
|
const firstAd = this.adPodQueue.shift();
|
|
3261
3281
|
if (firstAd) {
|
|
3262
3282
|
this.currentAdIndex++;
|
|
3263
|
-
|
|
3283
|
+
console.log(`[DEBUG-POD] \u{1F3AC} Attempting to play first ad (not preloaded): ${firstAd.substring(0, 60)}...`);
|
|
3284
|
+
try {
|
|
3285
|
+
await this.playSingleAd(firstAd);
|
|
3286
|
+
} catch (error) {
|
|
3287
|
+
console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
|
|
3288
|
+
return;
|
|
3289
|
+
}
|
|
3290
|
+
} else {
|
|
3291
|
+
console.log("[DEBUG-POD] \u274C No ads available in queue");
|
|
3264
3292
|
}
|
|
3265
3293
|
return;
|
|
3266
3294
|
}
|
|
3267
3295
|
this.currentAdIndex++;
|
|
3268
3296
|
console.log(`[DEBUG-POD] \u{1F680} Starting pod with ad ${this.currentAdIndex}/${this.totalAdsInBreak}`);
|
|
3269
|
-
|
|
3297
|
+
try {
|
|
3298
|
+
await this.playSingleAd(firstPreloaded);
|
|
3299
|
+
} catch (error) {
|
|
3300
|
+
console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
|
|
3301
|
+
}
|
|
3270
3302
|
}
|
|
3271
3303
|
findCurrentOrNextBreak(nowMs) {
|
|
3272
3304
|
var _a;
|
|
@@ -3475,6 +3507,13 @@ var StormcloudVideoPlayer = class {
|
|
|
3475
3507
|
console.log("[DEBUG-POD] \u274C handleAdFailure - skipping to next ad or ending break");
|
|
3476
3508
|
const remaining = this.getRemainingAdMs();
|
|
3477
3509
|
if (remaining > 500 && this.adPodQueue.length > 0) {
|
|
3510
|
+
if (this.isAdaptiveMode && this.currentAdIndex <= 1) {
|
|
3511
|
+
console.log("[ADAPTIVE-POD] \u23F3 First ad failed, waiting for sequential preload to catch up...");
|
|
3512
|
+
setTimeout(() => {
|
|
3513
|
+
this.tryNextAdWithRetry(0);
|
|
3514
|
+
}, 1500);
|
|
3515
|
+
return;
|
|
3516
|
+
}
|
|
3478
3517
|
const nextPreloaded = this.findNextPreloadedAd();
|
|
3479
3518
|
if (nextPreloaded) {
|
|
3480
3519
|
this.currentAdIndex++;
|
|
@@ -3488,6 +3527,42 @@ var StormcloudVideoPlayer = class {
|
|
|
3488
3527
|
console.log("[DEBUG-POD] \u23F9\uFE0F Ending ad break after failure");
|
|
3489
3528
|
this.handleAdPodComplete();
|
|
3490
3529
|
}
|
|
3530
|
+
tryNextAdWithRetry(retryCount) {
|
|
3531
|
+
const maxRetries = 3;
|
|
3532
|
+
const remaining = this.getRemainingAdMs();
|
|
3533
|
+
if (this.config.debugAdTiming) {
|
|
3534
|
+
console.log(
|
|
3535
|
+
`[ADAPTIVE-POD] \u{1F50D} Retry attempt ${retryCount}: remaining=${remaining}ms, queue=${this.adPodQueue.length}, totalAds=${this.totalAdsInBreak}`
|
|
3536
|
+
);
|
|
3537
|
+
}
|
|
3538
|
+
if (remaining <= 500 || this.adPodQueue.length === 0) {
|
|
3539
|
+
console.log("[ADAPTIVE-POD] \u23F9\uFE0F No more time or ads available");
|
|
3540
|
+
this.handleAdPodComplete();
|
|
3541
|
+
return;
|
|
3542
|
+
}
|
|
3543
|
+
const nextPreloaded = this.findNextPreloadedAd();
|
|
3544
|
+
if (nextPreloaded) {
|
|
3545
|
+
this.currentAdIndex++;
|
|
3546
|
+
console.log(
|
|
3547
|
+
`[ADAPTIVE-POD] \u2705 Found preloaded ad after retry ${retryCount}, playing (${this.currentAdIndex}/${this.totalAdsInBreak})`
|
|
3548
|
+
);
|
|
3549
|
+
this.playSingleAd(nextPreloaded).catch(() => {
|
|
3550
|
+
this.handleAdPodComplete();
|
|
3551
|
+
});
|
|
3552
|
+
} else if (retryCount < maxRetries) {
|
|
3553
|
+
console.log(
|
|
3554
|
+
`[ADAPTIVE-POD] \u23F3 No preloaded ads yet (queue has ${this.adPodQueue.length} URLs), retry ${retryCount + 1}/${maxRetries} in 1s...`
|
|
3555
|
+
);
|
|
3556
|
+
setTimeout(() => {
|
|
3557
|
+
this.tryNextAdWithRetry(retryCount + 1);
|
|
3558
|
+
}, 1e3);
|
|
3559
|
+
} else {
|
|
3560
|
+
console.log(
|
|
3561
|
+
`[ADAPTIVE-POD] \u274C Max retries reached, no preloaded ads available (queue=${this.adPodQueue.length} URLs)`
|
|
3562
|
+
);
|
|
3563
|
+
this.handleAdPodComplete();
|
|
3564
|
+
}
|
|
3565
|
+
}
|
|
3491
3566
|
startAdRequestWatchdog(token) {
|
|
3492
3567
|
var _a;
|
|
3493
3568
|
this.clearAdRequestWatchdog();
|
|
@@ -3752,22 +3827,30 @@ var StormcloudVideoPlayer = class {
|
|
|
3752
3827
|
if (this.isAdaptiveMode) {
|
|
3753
3828
|
if (this.config.debugAdTiming) {
|
|
3754
3829
|
console.log(
|
|
3755
|
-
`[ADAPTIVE-POD] Starting sequential preload of ${this.adPodAllUrls.length} initial ads`
|
|
3830
|
+
`[ADAPTIVE-POD] \u{1F504} Starting sequential preload of ${this.adPodAllUrls.length} initial ads`
|
|
3756
3831
|
);
|
|
3757
3832
|
}
|
|
3758
3833
|
const processedUrls = /* @__PURE__ */ new Set();
|
|
3759
3834
|
while (true) {
|
|
3760
3835
|
const nextUrl = this.adPodAllUrls.find((url) => !processedUrls.has(url));
|
|
3761
3836
|
if (!nextUrl) {
|
|
3837
|
+
if (this.config.debugAdTiming) {
|
|
3838
|
+
console.log(`[ADAPTIVE-POD] \u2705 All queued ads processed (${processedUrls.size} total)`);
|
|
3839
|
+
}
|
|
3762
3840
|
break;
|
|
3763
3841
|
}
|
|
3764
3842
|
processedUrls.add(nextUrl);
|
|
3843
|
+
if (this.config.debugAdTiming) {
|
|
3844
|
+
console.log(
|
|
3845
|
+
`[ADAPTIVE-POD] \u{1F4E5} Preloading ad ${processedUrls.size}/${this.adPodAllUrls.length}...`
|
|
3846
|
+
);
|
|
3847
|
+
}
|
|
3765
3848
|
try {
|
|
3766
3849
|
await this.preloadSingleAd(nextUrl);
|
|
3767
3850
|
} catch (error) {
|
|
3768
3851
|
if (this.config.debugAdTiming) {
|
|
3769
3852
|
console.warn(
|
|
3770
|
-
`[ADAPTIVE-POD] Preload failed for ${
|
|
3853
|
+
`[ADAPTIVE-POD] \u26A0\uFE0F Preload failed for ad ${processedUrls.size}:`,
|
|
3771
3854
|
error
|
|
3772
3855
|
);
|
|
3773
3856
|
}
|
|
@@ -3775,7 +3858,7 @@ var StormcloudVideoPlayer = class {
|
|
|
3775
3858
|
if (this.calculateAdditionalAdsNeeded() === 0) {
|
|
3776
3859
|
if (this.config.debugAdTiming) {
|
|
3777
3860
|
console.log(
|
|
3778
|
-
`[ADAPTIVE-POD] \u2705 Target duration reached, stopping
|
|
3861
|
+
`[ADAPTIVE-POD] \u2705 Target duration reached (${processedUrls.size} ads preloaded), stopping`
|
|
3779
3862
|
);
|
|
3780
3863
|
}
|
|
3781
3864
|
break;
|
|
@@ -3783,7 +3866,7 @@ var StormcloudVideoPlayer = class {
|
|
|
3783
3866
|
}
|
|
3784
3867
|
if (this.config.debugAdTiming) {
|
|
3785
3868
|
console.log(
|
|
3786
|
-
`[ADAPTIVE-POD] Sequential preloading completed (${processedUrls.size} ads
|
|
3869
|
+
`[ADAPTIVE-POD] \u2705 Sequential preloading completed (${processedUrls.size} ads ready)`
|
|
3787
3870
|
);
|
|
3788
3871
|
}
|
|
3789
3872
|
} else {
|
|
@@ -3880,17 +3963,26 @@ var StormcloudVideoPlayer = class {
|
|
|
3880
3963
|
}
|
|
3881
3964
|
findNextPreloadedAd() {
|
|
3882
3965
|
var _a, _b, _c;
|
|
3966
|
+
if (this.config.debugAdTiming) {
|
|
3967
|
+
console.log(
|
|
3968
|
+
`[DEBUG-POD] \u{1F50E} Searching for preloaded ad in queue (${this.adPodQueue.length} URLs, ${this.preloadedMediaUrls.size} media preloaded, ${this.vastToMediaUrlMap.size} VAST mappings)`
|
|
3969
|
+
);
|
|
3970
|
+
}
|
|
3883
3971
|
for (let i = 0; i < this.adPodQueue.length; i++) {
|
|
3884
3972
|
const vastTagUrl = this.adPodQueue[i];
|
|
3885
3973
|
if (!vastTagUrl) continue;
|
|
3886
3974
|
const hasImaPreload = (_c = (_b = (_a = this.ima).hasPreloadedAd) == null ? void 0 : _b.call(_a, vastTagUrl)) != null ? _c : false;
|
|
3887
3975
|
const mediaUrls = this.vastToMediaUrlMap.get(vastTagUrl);
|
|
3888
3976
|
const hasMediaPreload = mediaUrls && mediaUrls.length > 0 ? this.preloadedMediaUrls.has(mediaUrls[0]) : false;
|
|
3977
|
+
if (this.config.debugAdTiming) {
|
|
3978
|
+
console.log(
|
|
3979
|
+
`[DEBUG-POD] Ad ${i}: IMA=${hasImaPreload}, Media=${hasMediaPreload}, MediaURLs=${(mediaUrls == null ? void 0 : mediaUrls.length) || 0}, URL=${vastTagUrl.substring(0, 60)}...`
|
|
3980
|
+
);
|
|
3981
|
+
}
|
|
3889
3982
|
if (hasImaPreload || hasMediaPreload) {
|
|
3890
3983
|
if (this.config.debugAdTiming) {
|
|
3891
3984
|
console.log(
|
|
3892
|
-
`[
|
|
3893
|
-
{ hasImaPreload, hasMediaPreload }
|
|
3985
|
+
`[DEBUG-POD] \u2705 Found preloaded ad at index ${i}`
|
|
3894
3986
|
);
|
|
3895
3987
|
}
|
|
3896
3988
|
this.adPodQueue.splice(0, i + 1);
|
|
@@ -3899,7 +3991,7 @@ var StormcloudVideoPlayer = class {
|
|
|
3899
3991
|
}
|
|
3900
3992
|
if (this.config.debugAdTiming) {
|
|
3901
3993
|
console.log(
|
|
3902
|
-
|
|
3994
|
+
`[DEBUG-POD] \u274C No preloaded ads found in queue`
|
|
3903
3995
|
);
|
|
3904
3996
|
}
|
|
3905
3997
|
return void 0;
|