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
|
@@ -3187,19 +3187,34 @@ var StormcloudVideoPlayer = class {
|
|
|
3187
3187
|
this.currentAdIndex = 0;
|
|
3188
3188
|
this.totalAdsInBreak = vastTagUrls.length;
|
|
3189
3189
|
this.adPodQueue = [...vastTagUrls];
|
|
3190
|
-
this.
|
|
3190
|
+
if (this.isAdaptiveMode) {
|
|
3191
3191
|
if (this.config.debugAdTiming) {
|
|
3192
|
-
console.
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
);
|
|
3192
|
+
console.log("[ADAPTIVE-POD] Waiting for sequential preloading to complete...");
|
|
3193
|
+
}
|
|
3194
|
+
try {
|
|
3195
|
+
await this.preloadAllAdsInBackground();
|
|
3196
|
+
if (this.config.debugAdTiming) {
|
|
3197
|
+
console.log("[ADAPTIVE-POD] Preloading complete, starting playback");
|
|
3198
|
+
}
|
|
3199
|
+
} catch (error) {
|
|
3200
|
+
if (this.config.debugAdTiming) {
|
|
3201
|
+
console.warn(
|
|
3202
|
+
"[ADAPTIVE-POD] Error in preloading:",
|
|
3203
|
+
error
|
|
3204
|
+
);
|
|
3205
|
+
}
|
|
3196
3206
|
}
|
|
3197
|
-
});
|
|
3198
|
-
try {
|
|
3199
3207
|
await this.playAdPod();
|
|
3200
|
-
}
|
|
3201
|
-
|
|
3202
|
-
|
|
3208
|
+
} else {
|
|
3209
|
+
this.preloadAllAdsInBackground().catch((error) => {
|
|
3210
|
+
if (this.config.debugAdTiming) {
|
|
3211
|
+
console.warn(
|
|
3212
|
+
"[StormcloudVideoPlayer] Error in background preloading:",
|
|
3213
|
+
error
|
|
3214
|
+
);
|
|
3215
|
+
}
|
|
3216
|
+
});
|
|
3217
|
+
await this.playAdPod();
|
|
3203
3218
|
}
|
|
3204
3219
|
}
|
|
3205
3220
|
if (this.expectedAdBreakDurationMs == null && (scheduled == null ? void 0 : scheduled.durationMs) != null) {
|
|
@@ -3213,21 +3228,38 @@ var StormcloudVideoPlayer = class {
|
|
|
3213
3228
|
console.log("[DEBUG-POD] \u26A0\uFE0F No ads in pod");
|
|
3214
3229
|
return;
|
|
3215
3230
|
}
|
|
3216
|
-
const waitTime = this.isAdaptiveMode ?
|
|
3231
|
+
const waitTime = this.isAdaptiveMode ? 100 : 500;
|
|
3217
3232
|
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
3233
|
+
if (this.config.debugAdTiming) {
|
|
3234
|
+
console.log(
|
|
3235
|
+
`[DEBUG-POD] \u{1F50D} Looking for preloaded ad in queue of ${this.adPodQueue.length} URLs`
|
|
3236
|
+
);
|
|
3237
|
+
}
|
|
3218
3238
|
const firstPreloaded = this.findNextPreloadedAd();
|
|
3219
3239
|
if (!firstPreloaded) {
|
|
3220
|
-
console.log("[DEBUG-POD] \u26A0\uFE0F No preloaded ads
|
|
3240
|
+
console.log("[DEBUG-POD] \u26A0\uFE0F No preloaded ads found, trying first ad from queue");
|
|
3221
3241
|
const firstAd = this.adPodQueue.shift();
|
|
3222
3242
|
if (firstAd) {
|
|
3223
3243
|
this.currentAdIndex++;
|
|
3224
|
-
|
|
3244
|
+
console.log(`[DEBUG-POD] \u{1F3AC} Attempting to play first ad (not preloaded): ${firstAd.substring(0, 60)}...`);
|
|
3245
|
+
try {
|
|
3246
|
+
await this.playSingleAd(firstAd);
|
|
3247
|
+
} catch (error) {
|
|
3248
|
+
console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
|
|
3249
|
+
return;
|
|
3250
|
+
}
|
|
3251
|
+
} else {
|
|
3252
|
+
console.log("[DEBUG-POD] \u274C No ads available in queue");
|
|
3225
3253
|
}
|
|
3226
3254
|
return;
|
|
3227
3255
|
}
|
|
3228
3256
|
this.currentAdIndex++;
|
|
3229
3257
|
console.log(`[DEBUG-POD] \u{1F680} Starting pod with ad ${this.currentAdIndex}/${this.totalAdsInBreak}`);
|
|
3230
|
-
|
|
3258
|
+
try {
|
|
3259
|
+
await this.playSingleAd(firstPreloaded);
|
|
3260
|
+
} catch (error) {
|
|
3261
|
+
console.log("[DEBUG-POD] \u26A0\uFE0F First ad failed, error handler will retry");
|
|
3262
|
+
}
|
|
3231
3263
|
}
|
|
3232
3264
|
findCurrentOrNextBreak(nowMs) {
|
|
3233
3265
|
var _a;
|
|
@@ -3436,6 +3468,13 @@ var StormcloudVideoPlayer = class {
|
|
|
3436
3468
|
console.log("[DEBUG-POD] \u274C handleAdFailure - skipping to next ad or ending break");
|
|
3437
3469
|
const remaining = this.getRemainingAdMs();
|
|
3438
3470
|
if (remaining > 500 && this.adPodQueue.length > 0) {
|
|
3471
|
+
if (this.isAdaptiveMode && this.currentAdIndex <= 1) {
|
|
3472
|
+
console.log("[ADAPTIVE-POD] \u23F3 First ad failed, waiting for sequential preload to catch up...");
|
|
3473
|
+
setTimeout(() => {
|
|
3474
|
+
this.tryNextAdWithRetry(0);
|
|
3475
|
+
}, 1500);
|
|
3476
|
+
return;
|
|
3477
|
+
}
|
|
3439
3478
|
const nextPreloaded = this.findNextPreloadedAd();
|
|
3440
3479
|
if (nextPreloaded) {
|
|
3441
3480
|
this.currentAdIndex++;
|
|
@@ -3449,6 +3488,42 @@ var StormcloudVideoPlayer = class {
|
|
|
3449
3488
|
console.log("[DEBUG-POD] \u23F9\uFE0F Ending ad break after failure");
|
|
3450
3489
|
this.handleAdPodComplete();
|
|
3451
3490
|
}
|
|
3491
|
+
tryNextAdWithRetry(retryCount) {
|
|
3492
|
+
const maxRetries = 3;
|
|
3493
|
+
const remaining = this.getRemainingAdMs();
|
|
3494
|
+
if (this.config.debugAdTiming) {
|
|
3495
|
+
console.log(
|
|
3496
|
+
`[ADAPTIVE-POD] \u{1F50D} Retry attempt ${retryCount}: remaining=${remaining}ms, queue=${this.adPodQueue.length}, totalAds=${this.totalAdsInBreak}`
|
|
3497
|
+
);
|
|
3498
|
+
}
|
|
3499
|
+
if (remaining <= 500 || this.adPodQueue.length === 0) {
|
|
3500
|
+
console.log("[ADAPTIVE-POD] \u23F9\uFE0F No more time or ads available");
|
|
3501
|
+
this.handleAdPodComplete();
|
|
3502
|
+
return;
|
|
3503
|
+
}
|
|
3504
|
+
const nextPreloaded = this.findNextPreloadedAd();
|
|
3505
|
+
if (nextPreloaded) {
|
|
3506
|
+
this.currentAdIndex++;
|
|
3507
|
+
console.log(
|
|
3508
|
+
`[ADAPTIVE-POD] \u2705 Found preloaded ad after retry ${retryCount}, playing (${this.currentAdIndex}/${this.totalAdsInBreak})`
|
|
3509
|
+
);
|
|
3510
|
+
this.playSingleAd(nextPreloaded).catch(() => {
|
|
3511
|
+
this.handleAdPodComplete();
|
|
3512
|
+
});
|
|
3513
|
+
} else if (retryCount < maxRetries) {
|
|
3514
|
+
console.log(
|
|
3515
|
+
`[ADAPTIVE-POD] \u23F3 No preloaded ads yet (queue has ${this.adPodQueue.length} URLs), retry ${retryCount + 1}/${maxRetries} in 1s...`
|
|
3516
|
+
);
|
|
3517
|
+
setTimeout(() => {
|
|
3518
|
+
this.tryNextAdWithRetry(retryCount + 1);
|
|
3519
|
+
}, 1e3);
|
|
3520
|
+
} else {
|
|
3521
|
+
console.log(
|
|
3522
|
+
`[ADAPTIVE-POD] \u274C Max retries reached, no preloaded ads available (queue=${this.adPodQueue.length} URLs)`
|
|
3523
|
+
);
|
|
3524
|
+
this.handleAdPodComplete();
|
|
3525
|
+
}
|
|
3526
|
+
}
|
|
3452
3527
|
startAdRequestWatchdog(token) {
|
|
3453
3528
|
var _a;
|
|
3454
3529
|
this.clearAdRequestWatchdog();
|
|
@@ -3713,22 +3788,30 @@ var StormcloudVideoPlayer = class {
|
|
|
3713
3788
|
if (this.isAdaptiveMode) {
|
|
3714
3789
|
if (this.config.debugAdTiming) {
|
|
3715
3790
|
console.log(
|
|
3716
|
-
`[ADAPTIVE-POD] Starting sequential preload of ${this.adPodAllUrls.length} initial ads`
|
|
3791
|
+
`[ADAPTIVE-POD] \u{1F504} Starting sequential preload of ${this.adPodAllUrls.length} initial ads`
|
|
3717
3792
|
);
|
|
3718
3793
|
}
|
|
3719
3794
|
const processedUrls = /* @__PURE__ */ new Set();
|
|
3720
3795
|
while (true) {
|
|
3721
3796
|
const nextUrl = this.adPodAllUrls.find((url) => !processedUrls.has(url));
|
|
3722
3797
|
if (!nextUrl) {
|
|
3798
|
+
if (this.config.debugAdTiming) {
|
|
3799
|
+
console.log(`[ADAPTIVE-POD] \u2705 All queued ads processed (${processedUrls.size} total)`);
|
|
3800
|
+
}
|
|
3723
3801
|
break;
|
|
3724
3802
|
}
|
|
3725
3803
|
processedUrls.add(nextUrl);
|
|
3804
|
+
if (this.config.debugAdTiming) {
|
|
3805
|
+
console.log(
|
|
3806
|
+
`[ADAPTIVE-POD] \u{1F4E5} Preloading ad ${processedUrls.size}/${this.adPodAllUrls.length}...`
|
|
3807
|
+
);
|
|
3808
|
+
}
|
|
3726
3809
|
try {
|
|
3727
3810
|
await this.preloadSingleAd(nextUrl);
|
|
3728
3811
|
} catch (error) {
|
|
3729
3812
|
if (this.config.debugAdTiming) {
|
|
3730
3813
|
console.warn(
|
|
3731
|
-
`[ADAPTIVE-POD] Preload failed for ${
|
|
3814
|
+
`[ADAPTIVE-POD] \u26A0\uFE0F Preload failed for ad ${processedUrls.size}:`,
|
|
3732
3815
|
error
|
|
3733
3816
|
);
|
|
3734
3817
|
}
|
|
@@ -3736,7 +3819,7 @@ var StormcloudVideoPlayer = class {
|
|
|
3736
3819
|
if (this.calculateAdditionalAdsNeeded() === 0) {
|
|
3737
3820
|
if (this.config.debugAdTiming) {
|
|
3738
3821
|
console.log(
|
|
3739
|
-
`[ADAPTIVE-POD] \u2705 Target duration reached, stopping
|
|
3822
|
+
`[ADAPTIVE-POD] \u2705 Target duration reached (${processedUrls.size} ads preloaded), stopping`
|
|
3740
3823
|
);
|
|
3741
3824
|
}
|
|
3742
3825
|
break;
|
|
@@ -3744,7 +3827,7 @@ var StormcloudVideoPlayer = class {
|
|
|
3744
3827
|
}
|
|
3745
3828
|
if (this.config.debugAdTiming) {
|
|
3746
3829
|
console.log(
|
|
3747
|
-
`[ADAPTIVE-POD] Sequential preloading completed (${processedUrls.size} ads
|
|
3830
|
+
`[ADAPTIVE-POD] \u2705 Sequential preloading completed (${processedUrls.size} ads ready)`
|
|
3748
3831
|
);
|
|
3749
3832
|
}
|
|
3750
3833
|
} else {
|
|
@@ -3841,17 +3924,26 @@ var StormcloudVideoPlayer = class {
|
|
|
3841
3924
|
}
|
|
3842
3925
|
findNextPreloadedAd() {
|
|
3843
3926
|
var _a, _b, _c;
|
|
3927
|
+
if (this.config.debugAdTiming) {
|
|
3928
|
+
console.log(
|
|
3929
|
+
`[DEBUG-POD] \u{1F50E} Searching for preloaded ad in queue (${this.adPodQueue.length} URLs, ${this.preloadedMediaUrls.size} media preloaded, ${this.vastToMediaUrlMap.size} VAST mappings)`
|
|
3930
|
+
);
|
|
3931
|
+
}
|
|
3844
3932
|
for (let i = 0; i < this.adPodQueue.length; i++) {
|
|
3845
3933
|
const vastTagUrl = this.adPodQueue[i];
|
|
3846
3934
|
if (!vastTagUrl) continue;
|
|
3847
3935
|
const hasImaPreload = (_c = (_b = (_a = this.ima).hasPreloadedAd) == null ? void 0 : _b.call(_a, vastTagUrl)) != null ? _c : false;
|
|
3848
3936
|
const mediaUrls = this.vastToMediaUrlMap.get(vastTagUrl);
|
|
3849
3937
|
const hasMediaPreload = mediaUrls && mediaUrls.length > 0 ? this.preloadedMediaUrls.has(mediaUrls[0]) : false;
|
|
3938
|
+
if (this.config.debugAdTiming) {
|
|
3939
|
+
console.log(
|
|
3940
|
+
`[DEBUG-POD] Ad ${i}: IMA=${hasImaPreload}, Media=${hasMediaPreload}, MediaURLs=${(mediaUrls == null ? void 0 : mediaUrls.length) || 0}, URL=${vastTagUrl.substring(0, 60)}...`
|
|
3941
|
+
);
|
|
3942
|
+
}
|
|
3850
3943
|
if (hasImaPreload || hasMediaPreload) {
|
|
3851
3944
|
if (this.config.debugAdTiming) {
|
|
3852
3945
|
console.log(
|
|
3853
|
-
`[
|
|
3854
|
-
{ hasImaPreload, hasMediaPreload }
|
|
3946
|
+
`[DEBUG-POD] \u2705 Found preloaded ad at index ${i}`
|
|
3855
3947
|
);
|
|
3856
3948
|
}
|
|
3857
3949
|
this.adPodQueue.splice(0, i + 1);
|
|
@@ -3860,7 +3952,7 @@ var StormcloudVideoPlayer = class {
|
|
|
3860
3952
|
}
|
|
3861
3953
|
if (this.config.debugAdTiming) {
|
|
3862
3954
|
console.log(
|
|
3863
|
-
|
|
3955
|
+
`[DEBUG-POD] \u274C No preloaded ads found in queue`
|
|
3864
3956
|
);
|
|
3865
3957
|
}
|
|
3866
3958
|
return void 0;
|