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
|
@@ -1254,15 +1254,10 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
1254
1254
|
setAdPlayingFlag(false);
|
|
1255
1255
|
emit("content_resume");
|
|
1256
1256
|
setTimeout(() => {
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
);
|
|
1262
|
-
if (adContainerEl) {
|
|
1263
|
-
adContainerEl.style.display = "flex";
|
|
1264
|
-
adContainerEl.style.pointerEvents = "auto";
|
|
1265
|
-
}
|
|
1257
|
+
if (!adPlaying && adContainerEl) {
|
|
1258
|
+
adContainerEl.style.display = "none";
|
|
1259
|
+
adContainerEl.style.pointerEvents = "none";
|
|
1260
|
+
console.log("[HlsAdPlayer] Ad container hidden after completion (waiting for next ad)");
|
|
1266
1261
|
}
|
|
1267
1262
|
}, 50);
|
|
1268
1263
|
}
|
|
@@ -3118,7 +3113,7 @@ var StormcloudVideoPlayer = class {
|
|
|
3118
3113
|
continue;
|
|
3119
3114
|
}
|
|
3120
3115
|
if (this.config.debugAdTiming) {
|
|
3121
|
-
console.log(`[CONTINUOUS-FETCH] \u{1F4E1} Attempting to fetch ad
|
|
3116
|
+
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)...`);
|
|
3122
3117
|
}
|
|
3123
3118
|
try {
|
|
3124
3119
|
const response = await fetch(newAdUrl, { mode: "cors" });
|
|
@@ -3134,7 +3129,8 @@ var StormcloudVideoPlayer = class {
|
|
|
3134
3129
|
console.log("[CONTINUOUS-FETCH] \u26A0\uFE0F VAST response has no media files, skipping");
|
|
3135
3130
|
}
|
|
3136
3131
|
this.failedVastUrls.add(newAdUrl);
|
|
3137
|
-
|
|
3132
|
+
const retryDelay = this.adRequestQueue.length > 0 ? 1e3 : 500;
|
|
3133
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
3138
3134
|
continue;
|
|
3139
3135
|
}
|
|
3140
3136
|
if (this.config.debugAdTiming) {
|
|
@@ -3142,17 +3138,19 @@ var StormcloudVideoPlayer = class {
|
|
|
3142
3138
|
}
|
|
3143
3139
|
this.adRequestQueue.push(newAdUrl);
|
|
3144
3140
|
this.totalAdsInBreak++;
|
|
3145
|
-
|
|
3141
|
+
const successDelay = this.adRequestQueue.length <= 1 ? 300 : 500;
|
|
3142
|
+
await new Promise((resolve) => setTimeout(resolve, successDelay));
|
|
3146
3143
|
} catch (error) {
|
|
3147
3144
|
if (this.config.debugAdTiming) {
|
|
3148
3145
|
console.log("[CONTINUOUS-FETCH] \u274C Ad fetch failed:", error.message);
|
|
3149
3146
|
}
|
|
3150
3147
|
this.failedVastUrls.add(newAdUrl);
|
|
3151
|
-
|
|
3148
|
+
const retryDelay = this.adRequestQueue.length > 0 ? 2e3 : 1e3;
|
|
3149
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
3152
3150
|
}
|
|
3153
3151
|
}
|
|
3154
3152
|
if (this.config.debugAdTiming) {
|
|
3155
|
-
console.log(
|
|
3153
|
+
console.log(`[CONTINUOUS-FETCH] \u{1F6D1} Continuous fetch loop ended (fetched ${this.successfulAdRequests.length} ads, ${this.adRequestQueue.length} in queue)`);
|
|
3156
3154
|
}
|
|
3157
3155
|
}
|
|
3158
3156
|
stopContinuousFetching() {
|
|
@@ -3176,6 +3174,12 @@ var StormcloudVideoPlayer = class {
|
|
|
3176
3174
|
if (this.config.debugAdTiming) {
|
|
3177
3175
|
console.log(`[CONTINUOUS-FETCH] \u{1F3AC} Playing next queued ad (${this.currentAdIndex + 1}/${this.totalAdsInBreak}, ${this.adRequestQueue.length} remaining in queue)`);
|
|
3178
3176
|
}
|
|
3177
|
+
const currentMuted = this.video.muted;
|
|
3178
|
+
const currentVolume = this.video.volume;
|
|
3179
|
+
this.ima.updateOriginalMutedState(currentMuted, currentVolume);
|
|
3180
|
+
if (this.config.debugAdTiming) {
|
|
3181
|
+
console.log(`[CONTINUOUS-FETCH] \u{1F50A} Updated ad audio state: muted=${currentMuted}, volume=${currentVolume}`);
|
|
3182
|
+
}
|
|
3179
3183
|
this.currentAdIndex++;
|
|
3180
3184
|
this.successfulAdRequests.push(nextAdUrl);
|
|
3181
3185
|
await this.playSingleAd(nextAdUrl).catch(() => {
|
|
@@ -3184,20 +3188,27 @@ var StormcloudVideoPlayer = class {
|
|
|
3184
3188
|
return;
|
|
3185
3189
|
}
|
|
3186
3190
|
}
|
|
3187
|
-
const
|
|
3188
|
-
|
|
3191
|
+
const hasPlayedAtLeastOneAd = this.successfulAdRequests.length > 0;
|
|
3192
|
+
const maxRetries = hasPlayedAtLeastOneAd ? 10 : 5;
|
|
3193
|
+
const retryDelayMs = hasPlayedAtLeastOneAd ? 500 : 1e3;
|
|
3194
|
+
const minRemainingForRetry = 1e3;
|
|
3195
|
+
if (this.continuousFetchingActive && retryCount < maxRetries && remaining > minRemainingForRetry) {
|
|
3189
3196
|
if (this.config.debugAdTiming) {
|
|
3190
|
-
console.log(`[CONTINUOUS-FETCH] \u23F3 Queue empty but fetching active, waiting... (retry ${retryCount + 1}/${maxRetries})`);
|
|
3197
|
+
console.log(`[CONTINUOUS-FETCH] \u23F3 Queue empty but fetching active, waiting ${retryDelayMs}ms... (retry ${retryCount + 1}/${maxRetries}, remaining: ${remaining}ms)`);
|
|
3191
3198
|
}
|
|
3192
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
3199
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
|
|
3193
3200
|
await this.tryNextAvailableAd(retryCount + 1);
|
|
3194
3201
|
return;
|
|
3195
3202
|
}
|
|
3196
|
-
|
|
3203
|
+
const minTimeForPlaceholder = 3e3;
|
|
3204
|
+
if (!this.isShowingPlaceholder && remaining >= minTimeForPlaceholder && this.continuousFetchingActive) {
|
|
3205
|
+
if (this.config.debugAdTiming) {
|
|
3206
|
+
console.log(`[CONTINUOUS-FETCH] \u2B1B Last resort: showing placeholder (${remaining}ms remaining)`);
|
|
3207
|
+
}
|
|
3197
3208
|
this.showPlaceholderAndWaitForAds();
|
|
3198
3209
|
} else {
|
|
3199
3210
|
if (this.config.debugAdTiming) {
|
|
3200
|
-
console.log(
|
|
3211
|
+
console.log(`[CONTINUOUS-FETCH] \u23F9\uFE0F No more ads available or insufficient time remaining (${remaining}ms), ending ad break`);
|
|
3201
3212
|
}
|
|
3202
3213
|
this.handleAdPodComplete();
|
|
3203
3214
|
}
|
|
@@ -3205,33 +3216,47 @@ var StormcloudVideoPlayer = class {
|
|
|
3205
3216
|
async showPlaceholderAndWaitForAds() {
|
|
3206
3217
|
const remaining = this.getRemainingAdMs();
|
|
3207
3218
|
const waitTime = Math.min(this.maxPlaceholderDurationMs, remaining);
|
|
3208
|
-
if (waitTime <
|
|
3219
|
+
if (waitTime < 3e3) {
|
|
3220
|
+
if (this.config.debugAdTiming) {
|
|
3221
|
+
console.log(`[CONTINUOUS-FETCH] \u23F9\uFE0F Insufficient time for placeholder (${waitTime}ms), ending ad break`);
|
|
3222
|
+
}
|
|
3209
3223
|
this.handleAdPodComplete();
|
|
3210
3224
|
return;
|
|
3211
3225
|
}
|
|
3212
3226
|
if (this.config.debugAdTiming) {
|
|
3213
|
-
console.log(`[CONTINUOUS-FETCH] \u2B1B Showing black placeholder for ${waitTime}ms while waiting for ads`);
|
|
3227
|
+
console.log(`[CONTINUOUS-FETCH] \u2B1B Showing black placeholder for up to ${waitTime}ms while waiting for ads (last resort)`);
|
|
3214
3228
|
}
|
|
3215
3229
|
this.isShowingPlaceholder = true;
|
|
3216
3230
|
this.placeholderStartTimeMs = Date.now();
|
|
3217
3231
|
this.ima.showPlaceholder();
|
|
3218
|
-
const checkInterval =
|
|
3232
|
+
const checkInterval = 300;
|
|
3219
3233
|
const maxChecks = Math.floor(waitTime / checkInterval);
|
|
3220
3234
|
for (let i = 0; i < maxChecks; i++) {
|
|
3221
3235
|
await new Promise((resolve) => setTimeout(resolve, checkInterval));
|
|
3222
3236
|
if (!this.inAdBreak) {
|
|
3237
|
+
if (this.config.debugAdTiming) {
|
|
3238
|
+
console.log("[CONTINUOUS-FETCH] \u2139\uFE0F Ad break ended during placeholder wait");
|
|
3239
|
+
}
|
|
3240
|
+
this.isShowingPlaceholder = false;
|
|
3241
|
+
this.placeholderStartTimeMs = null;
|
|
3242
|
+
this.ima.hidePlaceholder();
|
|
3223
3243
|
return;
|
|
3224
3244
|
}
|
|
3225
3245
|
if (this.adRequestQueue.length > 0) {
|
|
3246
|
+
const elapsedInPlaceholder = Date.now() - (this.placeholderStartTimeMs || Date.now());
|
|
3226
3247
|
if (this.config.debugAdTiming) {
|
|
3227
|
-
console.log(
|
|
3248
|
+
console.log(`[CONTINUOUS-FETCH] \u2705 New ad became available during placeholder (after ${elapsedInPlaceholder}ms)`);
|
|
3228
3249
|
}
|
|
3229
3250
|
this.isShowingPlaceholder = false;
|
|
3230
3251
|
this.placeholderStartTimeMs = null;
|
|
3231
3252
|
this.ima.hidePlaceholder();
|
|
3253
|
+
const currentMuted = this.video.muted;
|
|
3254
|
+
const currentVolume = this.video.volume;
|
|
3255
|
+
this.ima.updateOriginalMutedState(currentMuted, currentVolume);
|
|
3232
3256
|
const nextAdUrl = this.adRequestQueue.shift();
|
|
3233
3257
|
if (nextAdUrl) {
|
|
3234
3258
|
this.currentAdIndex++;
|
|
3259
|
+
this.successfulAdRequests.push(nextAdUrl);
|
|
3235
3260
|
await this.playSingleAd(nextAdUrl).catch(() => {
|
|
3236
3261
|
this.tryNextAvailableAd();
|
|
3237
3262
|
});
|
|
@@ -3239,8 +3264,9 @@ var StormcloudVideoPlayer = class {
|
|
|
3239
3264
|
return;
|
|
3240
3265
|
}
|
|
3241
3266
|
}
|
|
3267
|
+
const totalPlaceholderTime = Date.now() - (this.placeholderStartTimeMs || Date.now());
|
|
3242
3268
|
if (this.config.debugAdTiming) {
|
|
3243
|
-
console.log(
|
|
3269
|
+
console.log(`[CONTINUOUS-FETCH] \u23F0 Placeholder timeout reached after ${totalPlaceholderTime}ms, no ads fetched`);
|
|
3244
3270
|
}
|
|
3245
3271
|
this.isShowingPlaceholder = false;
|
|
3246
3272
|
this.placeholderStartTimeMs = null;
|