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/players/index.cjs
CHANGED
|
@@ -1293,15 +1293,10 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
1293
1293
|
setAdPlayingFlag(false);
|
|
1294
1294
|
emit("content_resume");
|
|
1295
1295
|
setTimeout(() => {
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
);
|
|
1301
|
-
if (adContainerEl) {
|
|
1302
|
-
adContainerEl.style.display = "flex";
|
|
1303
|
-
adContainerEl.style.pointerEvents = "auto";
|
|
1304
|
-
}
|
|
1296
|
+
if (!adPlaying && adContainerEl) {
|
|
1297
|
+
adContainerEl.style.display = "none";
|
|
1298
|
+
adContainerEl.style.pointerEvents = "none";
|
|
1299
|
+
console.log("[HlsAdPlayer] Ad container hidden after completion (waiting for next ad)");
|
|
1305
1300
|
}
|
|
1306
1301
|
}, 50);
|
|
1307
1302
|
}
|
|
@@ -3157,7 +3152,7 @@ var StormcloudVideoPlayer = class {
|
|
|
3157
3152
|
continue;
|
|
3158
3153
|
}
|
|
3159
3154
|
if (this.config.debugAdTiming) {
|
|
3160
|
-
console.log(`[CONTINUOUS-FETCH] \u{1F4E1} Attempting to fetch ad
|
|
3155
|
+
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)...`);
|
|
3161
3156
|
}
|
|
3162
3157
|
try {
|
|
3163
3158
|
const response = await fetch(newAdUrl, { mode: "cors" });
|
|
@@ -3173,7 +3168,8 @@ var StormcloudVideoPlayer = class {
|
|
|
3173
3168
|
console.log("[CONTINUOUS-FETCH] \u26A0\uFE0F VAST response has no media files, skipping");
|
|
3174
3169
|
}
|
|
3175
3170
|
this.failedVastUrls.add(newAdUrl);
|
|
3176
|
-
|
|
3171
|
+
const retryDelay = this.adRequestQueue.length > 0 ? 1e3 : 500;
|
|
3172
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
3177
3173
|
continue;
|
|
3178
3174
|
}
|
|
3179
3175
|
if (this.config.debugAdTiming) {
|
|
@@ -3181,17 +3177,19 @@ var StormcloudVideoPlayer = class {
|
|
|
3181
3177
|
}
|
|
3182
3178
|
this.adRequestQueue.push(newAdUrl);
|
|
3183
3179
|
this.totalAdsInBreak++;
|
|
3184
|
-
|
|
3180
|
+
const successDelay = this.adRequestQueue.length <= 1 ? 300 : 500;
|
|
3181
|
+
await new Promise((resolve) => setTimeout(resolve, successDelay));
|
|
3185
3182
|
} catch (error) {
|
|
3186
3183
|
if (this.config.debugAdTiming) {
|
|
3187
3184
|
console.log("[CONTINUOUS-FETCH] \u274C Ad fetch failed:", error.message);
|
|
3188
3185
|
}
|
|
3189
3186
|
this.failedVastUrls.add(newAdUrl);
|
|
3190
|
-
|
|
3187
|
+
const retryDelay = this.adRequestQueue.length > 0 ? 2e3 : 1e3;
|
|
3188
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
3191
3189
|
}
|
|
3192
3190
|
}
|
|
3193
3191
|
if (this.config.debugAdTiming) {
|
|
3194
|
-
console.log(
|
|
3192
|
+
console.log(`[CONTINUOUS-FETCH] \u{1F6D1} Continuous fetch loop ended (fetched ${this.successfulAdRequests.length} ads, ${this.adRequestQueue.length} in queue)`);
|
|
3195
3193
|
}
|
|
3196
3194
|
}
|
|
3197
3195
|
stopContinuousFetching() {
|
|
@@ -3215,6 +3213,12 @@ var StormcloudVideoPlayer = class {
|
|
|
3215
3213
|
if (this.config.debugAdTiming) {
|
|
3216
3214
|
console.log(`[CONTINUOUS-FETCH] \u{1F3AC} Playing next queued ad (${this.currentAdIndex + 1}/${this.totalAdsInBreak}, ${this.adRequestQueue.length} remaining in queue)`);
|
|
3217
3215
|
}
|
|
3216
|
+
const currentMuted = this.video.muted;
|
|
3217
|
+
const currentVolume = this.video.volume;
|
|
3218
|
+
this.ima.updateOriginalMutedState(currentMuted, currentVolume);
|
|
3219
|
+
if (this.config.debugAdTiming) {
|
|
3220
|
+
console.log(`[CONTINUOUS-FETCH] \u{1F50A} Updated ad audio state: muted=${currentMuted}, volume=${currentVolume}`);
|
|
3221
|
+
}
|
|
3218
3222
|
this.currentAdIndex++;
|
|
3219
3223
|
this.successfulAdRequests.push(nextAdUrl);
|
|
3220
3224
|
await this.playSingleAd(nextAdUrl).catch(() => {
|
|
@@ -3223,20 +3227,27 @@ var StormcloudVideoPlayer = class {
|
|
|
3223
3227
|
return;
|
|
3224
3228
|
}
|
|
3225
3229
|
}
|
|
3226
|
-
const
|
|
3227
|
-
|
|
3230
|
+
const hasPlayedAtLeastOneAd = this.successfulAdRequests.length > 0;
|
|
3231
|
+
const maxRetries = hasPlayedAtLeastOneAd ? 10 : 5;
|
|
3232
|
+
const retryDelayMs = hasPlayedAtLeastOneAd ? 500 : 1e3;
|
|
3233
|
+
const minRemainingForRetry = 1e3;
|
|
3234
|
+
if (this.continuousFetchingActive && retryCount < maxRetries && remaining > minRemainingForRetry) {
|
|
3228
3235
|
if (this.config.debugAdTiming) {
|
|
3229
|
-
console.log(`[CONTINUOUS-FETCH] \u23F3 Queue empty but fetching active, waiting... (retry ${retryCount + 1}/${maxRetries})`);
|
|
3236
|
+
console.log(`[CONTINUOUS-FETCH] \u23F3 Queue empty but fetching active, waiting ${retryDelayMs}ms... (retry ${retryCount + 1}/${maxRetries}, remaining: ${remaining}ms)`);
|
|
3230
3237
|
}
|
|
3231
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
3238
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
|
|
3232
3239
|
await this.tryNextAvailableAd(retryCount + 1);
|
|
3233
3240
|
return;
|
|
3234
3241
|
}
|
|
3235
|
-
|
|
3242
|
+
const minTimeForPlaceholder = 3e3;
|
|
3243
|
+
if (!this.isShowingPlaceholder && remaining >= minTimeForPlaceholder && this.continuousFetchingActive) {
|
|
3244
|
+
if (this.config.debugAdTiming) {
|
|
3245
|
+
console.log(`[CONTINUOUS-FETCH] \u2B1B Last resort: showing placeholder (${remaining}ms remaining)`);
|
|
3246
|
+
}
|
|
3236
3247
|
this.showPlaceholderAndWaitForAds();
|
|
3237
3248
|
} else {
|
|
3238
3249
|
if (this.config.debugAdTiming) {
|
|
3239
|
-
console.log(
|
|
3250
|
+
console.log(`[CONTINUOUS-FETCH] \u23F9\uFE0F No more ads available or insufficient time remaining (${remaining}ms), ending ad break`);
|
|
3240
3251
|
}
|
|
3241
3252
|
this.handleAdPodComplete();
|
|
3242
3253
|
}
|
|
@@ -3244,33 +3255,47 @@ var StormcloudVideoPlayer = class {
|
|
|
3244
3255
|
async showPlaceholderAndWaitForAds() {
|
|
3245
3256
|
const remaining = this.getRemainingAdMs();
|
|
3246
3257
|
const waitTime = Math.min(this.maxPlaceholderDurationMs, remaining);
|
|
3247
|
-
if (waitTime <
|
|
3258
|
+
if (waitTime < 3e3) {
|
|
3259
|
+
if (this.config.debugAdTiming) {
|
|
3260
|
+
console.log(`[CONTINUOUS-FETCH] \u23F9\uFE0F Insufficient time for placeholder (${waitTime}ms), ending ad break`);
|
|
3261
|
+
}
|
|
3248
3262
|
this.handleAdPodComplete();
|
|
3249
3263
|
return;
|
|
3250
3264
|
}
|
|
3251
3265
|
if (this.config.debugAdTiming) {
|
|
3252
|
-
console.log(`[CONTINUOUS-FETCH] \u2B1B Showing black placeholder for ${waitTime}ms while waiting for ads`);
|
|
3266
|
+
console.log(`[CONTINUOUS-FETCH] \u2B1B Showing black placeholder for up to ${waitTime}ms while waiting for ads (last resort)`);
|
|
3253
3267
|
}
|
|
3254
3268
|
this.isShowingPlaceholder = true;
|
|
3255
3269
|
this.placeholderStartTimeMs = Date.now();
|
|
3256
3270
|
this.ima.showPlaceholder();
|
|
3257
|
-
const checkInterval =
|
|
3271
|
+
const checkInterval = 300;
|
|
3258
3272
|
const maxChecks = Math.floor(waitTime / checkInterval);
|
|
3259
3273
|
for (let i = 0; i < maxChecks; i++) {
|
|
3260
3274
|
await new Promise((resolve) => setTimeout(resolve, checkInterval));
|
|
3261
3275
|
if (!this.inAdBreak) {
|
|
3276
|
+
if (this.config.debugAdTiming) {
|
|
3277
|
+
console.log("[CONTINUOUS-FETCH] \u2139\uFE0F Ad break ended during placeholder wait");
|
|
3278
|
+
}
|
|
3279
|
+
this.isShowingPlaceholder = false;
|
|
3280
|
+
this.placeholderStartTimeMs = null;
|
|
3281
|
+
this.ima.hidePlaceholder();
|
|
3262
3282
|
return;
|
|
3263
3283
|
}
|
|
3264
3284
|
if (this.adRequestQueue.length > 0) {
|
|
3285
|
+
const elapsedInPlaceholder = Date.now() - (this.placeholderStartTimeMs || Date.now());
|
|
3265
3286
|
if (this.config.debugAdTiming) {
|
|
3266
|
-
console.log(
|
|
3287
|
+
console.log(`[CONTINUOUS-FETCH] \u2705 New ad became available during placeholder (after ${elapsedInPlaceholder}ms)`);
|
|
3267
3288
|
}
|
|
3268
3289
|
this.isShowingPlaceholder = false;
|
|
3269
3290
|
this.placeholderStartTimeMs = null;
|
|
3270
3291
|
this.ima.hidePlaceholder();
|
|
3292
|
+
const currentMuted = this.video.muted;
|
|
3293
|
+
const currentVolume = this.video.volume;
|
|
3294
|
+
this.ima.updateOriginalMutedState(currentMuted, currentVolume);
|
|
3271
3295
|
const nextAdUrl = this.adRequestQueue.shift();
|
|
3272
3296
|
if (nextAdUrl) {
|
|
3273
3297
|
this.currentAdIndex++;
|
|
3298
|
+
this.successfulAdRequests.push(nextAdUrl);
|
|
3274
3299
|
await this.playSingleAd(nextAdUrl).catch(() => {
|
|
3275
3300
|
this.tryNextAvailableAd();
|
|
3276
3301
|
});
|
|
@@ -3278,8 +3303,9 @@ var StormcloudVideoPlayer = class {
|
|
|
3278
3303
|
return;
|
|
3279
3304
|
}
|
|
3280
3305
|
}
|
|
3306
|
+
const totalPlaceholderTime = Date.now() - (this.placeholderStartTimeMs || Date.now());
|
|
3281
3307
|
if (this.config.debugAdTiming) {
|
|
3282
|
-
console.log(
|
|
3308
|
+
console.log(`[CONTINUOUS-FETCH] \u23F0 Placeholder timeout reached after ${totalPlaceholderTime}ms, no ads fetched`);
|
|
3283
3309
|
}
|
|
3284
3310
|
this.isShowingPlaceholder = false;
|
|
3285
3311
|
this.placeholderStartTimeMs = null;
|