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.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() {
|
|
@@ -3171,6 +3169,12 @@ var StormcloudVideoPlayer = class {
|
|
|
3171
3169
|
if (this.config.debugAdTiming) {
|
|
3172
3170
|
console.log(`[CONTINUOUS-FETCH] \u{1F3AC} Playing next queued ad (${this.currentAdIndex + 1}/${this.totalAdsInBreak}, ${this.adRequestQueue.length} remaining in queue)`);
|
|
3173
3171
|
}
|
|
3172
|
+
const currentMuted = this.video.muted;
|
|
3173
|
+
const currentVolume = this.video.volume;
|
|
3174
|
+
this.ima.updateOriginalMutedState(currentMuted, currentVolume);
|
|
3175
|
+
if (this.config.debugAdTiming) {
|
|
3176
|
+
console.log(`[CONTINUOUS-FETCH] \u{1F50A} Updated ad audio state: muted=${currentMuted}, volume=${currentVolume}`);
|
|
3177
|
+
}
|
|
3174
3178
|
this.currentAdIndex++;
|
|
3175
3179
|
this.successfulAdRequests.push(nextAdUrl);
|
|
3176
3180
|
await this.playSingleAd(nextAdUrl).catch(() => {
|
|
@@ -3179,20 +3183,27 @@ var StormcloudVideoPlayer = class {
|
|
|
3179
3183
|
return;
|
|
3180
3184
|
}
|
|
3181
3185
|
}
|
|
3182
|
-
const
|
|
3183
|
-
|
|
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) {
|
|
3184
3191
|
if (this.config.debugAdTiming) {
|
|
3185
|
-
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)`);
|
|
3186
3193
|
}
|
|
3187
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
3194
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
|
|
3188
3195
|
await this.tryNextAvailableAd(retryCount + 1);
|
|
3189
3196
|
return;
|
|
3190
3197
|
}
|
|
3191
|
-
|
|
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
|
+
}
|
|
3192
3203
|
this.showPlaceholderAndWaitForAds();
|
|
3193
3204
|
} else {
|
|
3194
3205
|
if (this.config.debugAdTiming) {
|
|
3195
|
-
console.log(
|
|
3206
|
+
console.log(`[CONTINUOUS-FETCH] \u23F9\uFE0F No more ads available or insufficient time remaining (${remaining}ms), ending ad break`);
|
|
3196
3207
|
}
|
|
3197
3208
|
this.handleAdPodComplete();
|
|
3198
3209
|
}
|
|
@@ -3200,33 +3211,47 @@ var StormcloudVideoPlayer = class {
|
|
|
3200
3211
|
async showPlaceholderAndWaitForAds() {
|
|
3201
3212
|
const remaining = this.getRemainingAdMs();
|
|
3202
3213
|
const waitTime = Math.min(this.maxPlaceholderDurationMs, remaining);
|
|
3203
|
-
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
|
+
}
|
|
3204
3218
|
this.handleAdPodComplete();
|
|
3205
3219
|
return;
|
|
3206
3220
|
}
|
|
3207
3221
|
if (this.config.debugAdTiming) {
|
|
3208
|
-
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)`);
|
|
3209
3223
|
}
|
|
3210
3224
|
this.isShowingPlaceholder = true;
|
|
3211
3225
|
this.placeholderStartTimeMs = Date.now();
|
|
3212
3226
|
this.ima.showPlaceholder();
|
|
3213
|
-
const checkInterval =
|
|
3227
|
+
const checkInterval = 300;
|
|
3214
3228
|
const maxChecks = Math.floor(waitTime / checkInterval);
|
|
3215
3229
|
for (let i = 0; i < maxChecks; i++) {
|
|
3216
3230
|
await new Promise((resolve) => setTimeout(resolve, checkInterval));
|
|
3217
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();
|
|
3218
3238
|
return;
|
|
3219
3239
|
}
|
|
3220
3240
|
if (this.adRequestQueue.length > 0) {
|
|
3241
|
+
const elapsedInPlaceholder = Date.now() - (this.placeholderStartTimeMs || Date.now());
|
|
3221
3242
|
if (this.config.debugAdTiming) {
|
|
3222
|
-
console.log(
|
|
3243
|
+
console.log(`[CONTINUOUS-FETCH] \u2705 New ad became available during placeholder (after ${elapsedInPlaceholder}ms)`);
|
|
3223
3244
|
}
|
|
3224
3245
|
this.isShowingPlaceholder = false;
|
|
3225
3246
|
this.placeholderStartTimeMs = null;
|
|
3226
3247
|
this.ima.hidePlaceholder();
|
|
3248
|
+
const currentMuted = this.video.muted;
|
|
3249
|
+
const currentVolume = this.video.volume;
|
|
3250
|
+
this.ima.updateOriginalMutedState(currentMuted, currentVolume);
|
|
3227
3251
|
const nextAdUrl = this.adRequestQueue.shift();
|
|
3228
3252
|
if (nextAdUrl) {
|
|
3229
3253
|
this.currentAdIndex++;
|
|
3254
|
+
this.successfulAdRequests.push(nextAdUrl);
|
|
3230
3255
|
await this.playSingleAd(nextAdUrl).catch(() => {
|
|
3231
3256
|
this.tryNextAvailableAd();
|
|
3232
3257
|
});
|
|
@@ -3234,8 +3259,9 @@ var StormcloudVideoPlayer = class {
|
|
|
3234
3259
|
return;
|
|
3235
3260
|
}
|
|
3236
3261
|
}
|
|
3262
|
+
const totalPlaceholderTime = Date.now() - (this.placeholderStartTimeMs || Date.now());
|
|
3237
3263
|
if (this.config.debugAdTiming) {
|
|
3238
|
-
console.log(
|
|
3264
|
+
console.log(`[CONTINUOUS-FETCH] \u23F0 Placeholder timeout reached after ${totalPlaceholderTime}ms, no ads fetched`);
|
|
3239
3265
|
}
|
|
3240
3266
|
this.isShowingPlaceholder = false;
|
|
3241
3267
|
this.placeholderStartTimeMs = null;
|