stormcloud-video-player 0.3.11 → 0.3.13
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 +2 -2
- package/lib/index.cjs +51 -25
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +51 -25
- package/lib/index.js.map +1 -1
- package/lib/player/StormcloudVideoPlayer.cjs +51 -25
- package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/players/HlsPlayer.cjs +51 -25
- package/lib/players/HlsPlayer.cjs.map +1 -1
- package/lib/players/index.cjs +51 -25
- package/lib/players/index.cjs.map +1 -1
- package/lib/sdk/hlsAdPlayer.cjs +4 -9
- package/lib/sdk/hlsAdPlayer.cjs.map +1 -1
- package/lib/ui/StormcloudVideoPlayer.cjs +51 -25
- package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -1318,15 +1318,10 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
1318
1318
|
setAdPlayingFlag(false);
|
|
1319
1319
|
emit("content_resume");
|
|
1320
1320
|
setTimeout(() => {
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
);
|
|
1326
|
-
if (adContainerEl) {
|
|
1327
|
-
adContainerEl.style.display = "flex";
|
|
1328
|
-
adContainerEl.style.pointerEvents = "auto";
|
|
1329
|
-
}
|
|
1321
|
+
if (!adPlaying && adContainerEl) {
|
|
1322
|
+
adContainerEl.style.display = "none";
|
|
1323
|
+
adContainerEl.style.pointerEvents = "none";
|
|
1324
|
+
console.log("[HlsAdPlayer] Ad container hidden after completion (waiting for next ad)");
|
|
1330
1325
|
}
|
|
1331
1326
|
}, 50);
|
|
1332
1327
|
}
|
|
@@ -3182,7 +3177,7 @@ var StormcloudVideoPlayer = class {
|
|
|
3182
3177
|
continue;
|
|
3183
3178
|
}
|
|
3184
3179
|
if (this.config.debugAdTiming) {
|
|
3185
|
-
console.log(`[CONTINUOUS-FETCH] \u{1F4E1} Attempting to fetch ad
|
|
3180
|
+
console.log(`[CONTINUOUS-FETCH] \u{1F4E1} Attempting to fetch ad #${this.successfulAdRequests.length + this.adRequestQueue.length + 1} (queue: ${this.adRequestQueue.length}, remaining: ${Math.round(remaining / 1e3)}s)...`);
|
|
3186
3181
|
}
|
|
3187
3182
|
try {
|
|
3188
3183
|
const response = await fetch(newAdUrl, { mode: "cors" });
|
|
@@ -3198,7 +3193,8 @@ var StormcloudVideoPlayer = class {
|
|
|
3198
3193
|
console.log("[CONTINUOUS-FETCH] \u26A0\uFE0F VAST response has no media files, skipping");
|
|
3199
3194
|
}
|
|
3200
3195
|
this.failedVastUrls.add(newAdUrl);
|
|
3201
|
-
|
|
3196
|
+
const retryDelay = this.adRequestQueue.length > 0 ? 1e3 : 500;
|
|
3197
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
3202
3198
|
continue;
|
|
3203
3199
|
}
|
|
3204
3200
|
if (this.config.debugAdTiming) {
|
|
@@ -3206,17 +3202,19 @@ var StormcloudVideoPlayer = class {
|
|
|
3206
3202
|
}
|
|
3207
3203
|
this.adRequestQueue.push(newAdUrl);
|
|
3208
3204
|
this.totalAdsInBreak++;
|
|
3209
|
-
|
|
3205
|
+
const successDelay = this.adRequestQueue.length <= 1 ? 300 : 500;
|
|
3206
|
+
await new Promise((resolve) => setTimeout(resolve, successDelay));
|
|
3210
3207
|
} catch (error) {
|
|
3211
3208
|
if (this.config.debugAdTiming) {
|
|
3212
3209
|
console.log("[CONTINUOUS-FETCH] \u274C Ad fetch failed:", error.message);
|
|
3213
3210
|
}
|
|
3214
3211
|
this.failedVastUrls.add(newAdUrl);
|
|
3215
|
-
|
|
3212
|
+
const retryDelay = this.adRequestQueue.length > 0 ? 2e3 : 1e3;
|
|
3213
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
3216
3214
|
}
|
|
3217
3215
|
}
|
|
3218
3216
|
if (this.config.debugAdTiming) {
|
|
3219
|
-
console.log(
|
|
3217
|
+
console.log(`[CONTINUOUS-FETCH] \u{1F6D1} Continuous fetch loop ended (fetched ${this.successfulAdRequests.length} ads, ${this.adRequestQueue.length} in queue)`);
|
|
3220
3218
|
}
|
|
3221
3219
|
}
|
|
3222
3220
|
stopContinuousFetching() {
|
|
@@ -3240,6 +3238,12 @@ var StormcloudVideoPlayer = class {
|
|
|
3240
3238
|
if (this.config.debugAdTiming) {
|
|
3241
3239
|
console.log(`[CONTINUOUS-FETCH] \u{1F3AC} Playing next queued ad (${this.currentAdIndex + 1}/${this.totalAdsInBreak}, ${this.adRequestQueue.length} remaining in queue)`);
|
|
3242
3240
|
}
|
|
3241
|
+
const currentMuted = this.video.muted;
|
|
3242
|
+
const currentVolume = this.video.volume;
|
|
3243
|
+
this.ima.updateOriginalMutedState(currentMuted, currentVolume);
|
|
3244
|
+
if (this.config.debugAdTiming) {
|
|
3245
|
+
console.log(`[CONTINUOUS-FETCH] \u{1F50A} Updated ad audio state: muted=${currentMuted}, volume=${currentVolume}`);
|
|
3246
|
+
}
|
|
3243
3247
|
this.currentAdIndex++;
|
|
3244
3248
|
this.successfulAdRequests.push(nextAdUrl);
|
|
3245
3249
|
await this.playSingleAd(nextAdUrl).catch(() => {
|
|
@@ -3248,20 +3252,27 @@ var StormcloudVideoPlayer = class {
|
|
|
3248
3252
|
return;
|
|
3249
3253
|
}
|
|
3250
3254
|
}
|
|
3251
|
-
const
|
|
3252
|
-
|
|
3255
|
+
const hasPlayedAtLeastOneAd = this.successfulAdRequests.length > 0;
|
|
3256
|
+
const maxRetries = hasPlayedAtLeastOneAd ? 10 : 5;
|
|
3257
|
+
const retryDelayMs = hasPlayedAtLeastOneAd ? 500 : 1e3;
|
|
3258
|
+
const minRemainingForRetry = 1e3;
|
|
3259
|
+
if (this.continuousFetchingActive && retryCount < maxRetries && remaining > minRemainingForRetry) {
|
|
3253
3260
|
if (this.config.debugAdTiming) {
|
|
3254
|
-
console.log(`[CONTINUOUS-FETCH] \u23F3 Queue empty but fetching active, waiting... (retry ${retryCount + 1}/${maxRetries})`);
|
|
3261
|
+
console.log(`[CONTINUOUS-FETCH] \u23F3 Queue empty but fetching active, waiting ${retryDelayMs}ms... (retry ${retryCount + 1}/${maxRetries}, remaining: ${remaining}ms)`);
|
|
3255
3262
|
}
|
|
3256
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
3263
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
|
|
3257
3264
|
await this.tryNextAvailableAd(retryCount + 1);
|
|
3258
3265
|
return;
|
|
3259
3266
|
}
|
|
3260
|
-
|
|
3267
|
+
const minTimeForPlaceholder = 3e3;
|
|
3268
|
+
if (!this.isShowingPlaceholder && remaining >= minTimeForPlaceholder && this.continuousFetchingActive) {
|
|
3269
|
+
if (this.config.debugAdTiming) {
|
|
3270
|
+
console.log(`[CONTINUOUS-FETCH] \u2B1B Last resort: showing placeholder (${remaining}ms remaining)`);
|
|
3271
|
+
}
|
|
3261
3272
|
this.showPlaceholderAndWaitForAds();
|
|
3262
3273
|
} else {
|
|
3263
3274
|
if (this.config.debugAdTiming) {
|
|
3264
|
-
console.log(
|
|
3275
|
+
console.log(`[CONTINUOUS-FETCH] \u23F9\uFE0F No more ads available or insufficient time remaining (${remaining}ms), ending ad break`);
|
|
3265
3276
|
}
|
|
3266
3277
|
this.handleAdPodComplete();
|
|
3267
3278
|
}
|
|
@@ -3269,33 +3280,47 @@ var StormcloudVideoPlayer = class {
|
|
|
3269
3280
|
async showPlaceholderAndWaitForAds() {
|
|
3270
3281
|
const remaining = this.getRemainingAdMs();
|
|
3271
3282
|
const waitTime = Math.min(this.maxPlaceholderDurationMs, remaining);
|
|
3272
|
-
if (waitTime <
|
|
3283
|
+
if (waitTime < 3e3) {
|
|
3284
|
+
if (this.config.debugAdTiming) {
|
|
3285
|
+
console.log(`[CONTINUOUS-FETCH] \u23F9\uFE0F Insufficient time for placeholder (${waitTime}ms), ending ad break`);
|
|
3286
|
+
}
|
|
3273
3287
|
this.handleAdPodComplete();
|
|
3274
3288
|
return;
|
|
3275
3289
|
}
|
|
3276
3290
|
if (this.config.debugAdTiming) {
|
|
3277
|
-
console.log(`[CONTINUOUS-FETCH] \u2B1B Showing black placeholder for ${waitTime}ms while waiting for ads`);
|
|
3291
|
+
console.log(`[CONTINUOUS-FETCH] \u2B1B Showing black placeholder for up to ${waitTime}ms while waiting for ads (last resort)`);
|
|
3278
3292
|
}
|
|
3279
3293
|
this.isShowingPlaceholder = true;
|
|
3280
3294
|
this.placeholderStartTimeMs = Date.now();
|
|
3281
3295
|
this.ima.showPlaceholder();
|
|
3282
|
-
const checkInterval =
|
|
3296
|
+
const checkInterval = 300;
|
|
3283
3297
|
const maxChecks = Math.floor(waitTime / checkInterval);
|
|
3284
3298
|
for (let i = 0; i < maxChecks; i++) {
|
|
3285
3299
|
await new Promise((resolve) => setTimeout(resolve, checkInterval));
|
|
3286
3300
|
if (!this.inAdBreak) {
|
|
3301
|
+
if (this.config.debugAdTiming) {
|
|
3302
|
+
console.log("[CONTINUOUS-FETCH] \u2139\uFE0F Ad break ended during placeholder wait");
|
|
3303
|
+
}
|
|
3304
|
+
this.isShowingPlaceholder = false;
|
|
3305
|
+
this.placeholderStartTimeMs = null;
|
|
3306
|
+
this.ima.hidePlaceholder();
|
|
3287
3307
|
return;
|
|
3288
3308
|
}
|
|
3289
3309
|
if (this.adRequestQueue.length > 0) {
|
|
3310
|
+
const elapsedInPlaceholder = Date.now() - (this.placeholderStartTimeMs || Date.now());
|
|
3290
3311
|
if (this.config.debugAdTiming) {
|
|
3291
|
-
console.log(
|
|
3312
|
+
console.log(`[CONTINUOUS-FETCH] \u2705 New ad became available during placeholder (after ${elapsedInPlaceholder}ms)`);
|
|
3292
3313
|
}
|
|
3293
3314
|
this.isShowingPlaceholder = false;
|
|
3294
3315
|
this.placeholderStartTimeMs = null;
|
|
3295
3316
|
this.ima.hidePlaceholder();
|
|
3317
|
+
const currentMuted = this.video.muted;
|
|
3318
|
+
const currentVolume = this.video.volume;
|
|
3319
|
+
this.ima.updateOriginalMutedState(currentMuted, currentVolume);
|
|
3296
3320
|
const nextAdUrl = this.adRequestQueue.shift();
|
|
3297
3321
|
if (nextAdUrl) {
|
|
3298
3322
|
this.currentAdIndex++;
|
|
3323
|
+
this.successfulAdRequests.push(nextAdUrl);
|
|
3299
3324
|
await this.playSingleAd(nextAdUrl).catch(() => {
|
|
3300
3325
|
this.tryNextAvailableAd();
|
|
3301
3326
|
});
|
|
@@ -3303,8 +3328,9 @@ var StormcloudVideoPlayer = class {
|
|
|
3303
3328
|
return;
|
|
3304
3329
|
}
|
|
3305
3330
|
}
|
|
3331
|
+
const totalPlaceholderTime = Date.now() - (this.placeholderStartTimeMs || Date.now());
|
|
3306
3332
|
if (this.config.debugAdTiming) {
|
|
3307
|
-
console.log(
|
|
3333
|
+
console.log(`[CONTINUOUS-FETCH] \u23F0 Placeholder timeout reached after ${totalPlaceholderTime}ms, no ads fetched`);
|
|
3308
3334
|
}
|
|
3309
3335
|
this.isShowingPlaceholder = false;
|
|
3310
3336
|
this.placeholderStartTimeMs = null;
|