stormcloud-video-player 0.3.12 → 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 +41 -25
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +41 -25
- package/lib/index.js.map +1 -1
- package/lib/player/StormcloudVideoPlayer.cjs +41 -25
- package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/players/HlsPlayer.cjs +41 -25
- package/lib/players/HlsPlayer.cjs.map +1 -1
- package/lib/players/index.cjs +41 -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 +41 -25
- package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1249,15 +1249,10 @@ function createHlsAdPlayer(contentVideo, options) {
|
|
|
1249
1249
|
setAdPlayingFlag(false);
|
|
1250
1250
|
emit("content_resume");
|
|
1251
1251
|
setTimeout(() => {
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
);
|
|
1257
|
-
if (adContainerEl) {
|
|
1258
|
-
adContainerEl.style.display = "flex";
|
|
1259
|
-
adContainerEl.style.pointerEvents = "auto";
|
|
1260
|
-
}
|
|
1252
|
+
if (!adPlaying && adContainerEl) {
|
|
1253
|
+
adContainerEl.style.display = "none";
|
|
1254
|
+
adContainerEl.style.pointerEvents = "none";
|
|
1255
|
+
console.log("[HlsAdPlayer] Ad container hidden after completion (waiting for next ad)");
|
|
1261
1256
|
}
|
|
1262
1257
|
}, 50);
|
|
1263
1258
|
}
|
|
@@ -3113,7 +3108,7 @@ var StormcloudVideoPlayer = class {
|
|
|
3113
3108
|
continue;
|
|
3114
3109
|
}
|
|
3115
3110
|
if (this.config.debugAdTiming) {
|
|
3116
|
-
console.log(`[CONTINUOUS-FETCH] \u{1F4E1} Attempting to fetch ad
|
|
3111
|
+
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)...`);
|
|
3117
3112
|
}
|
|
3118
3113
|
try {
|
|
3119
3114
|
const response = await fetch(newAdUrl, { mode: "cors" });
|
|
@@ -3129,7 +3124,8 @@ var StormcloudVideoPlayer = class {
|
|
|
3129
3124
|
console.log("[CONTINUOUS-FETCH] \u26A0\uFE0F VAST response has no media files, skipping");
|
|
3130
3125
|
}
|
|
3131
3126
|
this.failedVastUrls.add(newAdUrl);
|
|
3132
|
-
|
|
3127
|
+
const retryDelay = this.adRequestQueue.length > 0 ? 1e3 : 500;
|
|
3128
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
3133
3129
|
continue;
|
|
3134
3130
|
}
|
|
3135
3131
|
if (this.config.debugAdTiming) {
|
|
@@ -3137,17 +3133,19 @@ var StormcloudVideoPlayer = class {
|
|
|
3137
3133
|
}
|
|
3138
3134
|
this.adRequestQueue.push(newAdUrl);
|
|
3139
3135
|
this.totalAdsInBreak++;
|
|
3140
|
-
|
|
3136
|
+
const successDelay = this.adRequestQueue.length <= 1 ? 300 : 500;
|
|
3137
|
+
await new Promise((resolve) => setTimeout(resolve, successDelay));
|
|
3141
3138
|
} catch (error) {
|
|
3142
3139
|
if (this.config.debugAdTiming) {
|
|
3143
3140
|
console.log("[CONTINUOUS-FETCH] \u274C Ad fetch failed:", error.message);
|
|
3144
3141
|
}
|
|
3145
3142
|
this.failedVastUrls.add(newAdUrl);
|
|
3146
|
-
|
|
3143
|
+
const retryDelay = this.adRequestQueue.length > 0 ? 2e3 : 1e3;
|
|
3144
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
3147
3145
|
}
|
|
3148
3146
|
}
|
|
3149
3147
|
if (this.config.debugAdTiming) {
|
|
3150
|
-
console.log(
|
|
3148
|
+
console.log(`[CONTINUOUS-FETCH] \u{1F6D1} Continuous fetch loop ended (fetched ${this.successfulAdRequests.length} ads, ${this.adRequestQueue.length} in queue)`);
|
|
3151
3149
|
}
|
|
3152
3150
|
}
|
|
3153
3151
|
stopContinuousFetching() {
|
|
@@ -3185,20 +3183,27 @@ var StormcloudVideoPlayer = class {
|
|
|
3185
3183
|
return;
|
|
3186
3184
|
}
|
|
3187
3185
|
}
|
|
3188
|
-
const
|
|
3189
|
-
|
|
3186
|
+
const hasPlayedAtLeastOneAd = this.successfulAdRequests.length > 0;
|
|
3187
|
+
const maxRetries = hasPlayedAtLeastOneAd ? 10 : 5;
|
|
3188
|
+
const retryDelayMs = hasPlayedAtLeastOneAd ? 500 : 1e3;
|
|
3189
|
+
const minRemainingForRetry = 1e3;
|
|
3190
|
+
if (this.continuousFetchingActive && retryCount < maxRetries && remaining > minRemainingForRetry) {
|
|
3190
3191
|
if (this.config.debugAdTiming) {
|
|
3191
|
-
console.log(`[CONTINUOUS-FETCH] \u23F3 Queue empty but fetching active, waiting... (retry ${retryCount + 1}/${maxRetries})`);
|
|
3192
|
+
console.log(`[CONTINUOUS-FETCH] \u23F3 Queue empty but fetching active, waiting ${retryDelayMs}ms... (retry ${retryCount + 1}/${maxRetries}, remaining: ${remaining}ms)`);
|
|
3192
3193
|
}
|
|
3193
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
3194
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
|
|
3194
3195
|
await this.tryNextAvailableAd(retryCount + 1);
|
|
3195
3196
|
return;
|
|
3196
3197
|
}
|
|
3197
|
-
|
|
3198
|
+
const minTimeForPlaceholder = 3e3;
|
|
3199
|
+
if (!this.isShowingPlaceholder && remaining >= minTimeForPlaceholder && this.continuousFetchingActive) {
|
|
3200
|
+
if (this.config.debugAdTiming) {
|
|
3201
|
+
console.log(`[CONTINUOUS-FETCH] \u2B1B Last resort: showing placeholder (${remaining}ms remaining)`);
|
|
3202
|
+
}
|
|
3198
3203
|
this.showPlaceholderAndWaitForAds();
|
|
3199
3204
|
} else {
|
|
3200
3205
|
if (this.config.debugAdTiming) {
|
|
3201
|
-
console.log(
|
|
3206
|
+
console.log(`[CONTINUOUS-FETCH] \u23F9\uFE0F No more ads available or insufficient time remaining (${remaining}ms), ending ad break`);
|
|
3202
3207
|
}
|
|
3203
3208
|
this.handleAdPodComplete();
|
|
3204
3209
|
}
|
|
@@ -3206,26 +3211,36 @@ var StormcloudVideoPlayer = class {
|
|
|
3206
3211
|
async showPlaceholderAndWaitForAds() {
|
|
3207
3212
|
const remaining = this.getRemainingAdMs();
|
|
3208
3213
|
const waitTime = Math.min(this.maxPlaceholderDurationMs, remaining);
|
|
3209
|
-
if (waitTime <
|
|
3214
|
+
if (waitTime < 3e3) {
|
|
3215
|
+
if (this.config.debugAdTiming) {
|
|
3216
|
+
console.log(`[CONTINUOUS-FETCH] \u23F9\uFE0F Insufficient time for placeholder (${waitTime}ms), ending ad break`);
|
|
3217
|
+
}
|
|
3210
3218
|
this.handleAdPodComplete();
|
|
3211
3219
|
return;
|
|
3212
3220
|
}
|
|
3213
3221
|
if (this.config.debugAdTiming) {
|
|
3214
|
-
console.log(`[CONTINUOUS-FETCH] \u2B1B Showing black placeholder for ${waitTime}ms while waiting for ads`);
|
|
3222
|
+
console.log(`[CONTINUOUS-FETCH] \u2B1B Showing black placeholder for up to ${waitTime}ms while waiting for ads (last resort)`);
|
|
3215
3223
|
}
|
|
3216
3224
|
this.isShowingPlaceholder = true;
|
|
3217
3225
|
this.placeholderStartTimeMs = Date.now();
|
|
3218
3226
|
this.ima.showPlaceholder();
|
|
3219
|
-
const checkInterval =
|
|
3227
|
+
const checkInterval = 300;
|
|
3220
3228
|
const maxChecks = Math.floor(waitTime / checkInterval);
|
|
3221
3229
|
for (let i = 0; i < maxChecks; i++) {
|
|
3222
3230
|
await new Promise((resolve) => setTimeout(resolve, checkInterval));
|
|
3223
3231
|
if (!this.inAdBreak) {
|
|
3232
|
+
if (this.config.debugAdTiming) {
|
|
3233
|
+
console.log("[CONTINUOUS-FETCH] \u2139\uFE0F Ad break ended during placeholder wait");
|
|
3234
|
+
}
|
|
3235
|
+
this.isShowingPlaceholder = false;
|
|
3236
|
+
this.placeholderStartTimeMs = null;
|
|
3237
|
+
this.ima.hidePlaceholder();
|
|
3224
3238
|
return;
|
|
3225
3239
|
}
|
|
3226
3240
|
if (this.adRequestQueue.length > 0) {
|
|
3241
|
+
const elapsedInPlaceholder = Date.now() - (this.placeholderStartTimeMs || Date.now());
|
|
3227
3242
|
if (this.config.debugAdTiming) {
|
|
3228
|
-
console.log(
|
|
3243
|
+
console.log(`[CONTINUOUS-FETCH] \u2705 New ad became available during placeholder (after ${elapsedInPlaceholder}ms)`);
|
|
3229
3244
|
}
|
|
3230
3245
|
this.isShowingPlaceholder = false;
|
|
3231
3246
|
this.placeholderStartTimeMs = null;
|
|
@@ -3244,8 +3259,9 @@ var StormcloudVideoPlayer = class {
|
|
|
3244
3259
|
return;
|
|
3245
3260
|
}
|
|
3246
3261
|
}
|
|
3262
|
+
const totalPlaceholderTime = Date.now() - (this.placeholderStartTimeMs || Date.now());
|
|
3247
3263
|
if (this.config.debugAdTiming) {
|
|
3248
|
-
console.log(
|
|
3264
|
+
console.log(`[CONTINUOUS-FETCH] \u23F0 Placeholder timeout reached after ${totalPlaceholderTime}ms, no ads fetched`);
|
|
3249
3265
|
}
|
|
3250
3266
|
this.isShowingPlaceholder = false;
|
|
3251
3267
|
this.placeholderStartTimeMs = null;
|