stormcloud-video-player 0.3.20 → 0.3.21
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 +1 -1
- package/lib/index.cjs +17 -706
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +0 -17
- package/lib/index.d.ts +0 -17
- package/lib/index.js +17 -706
- package/lib/index.js.map +1 -1
- package/lib/player/StormcloudVideoPlayer.cjs +17 -718
- package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/player/StormcloudVideoPlayer.d.cts +0 -17
- package/lib/players/FilePlayer.cjs.map +1 -1
- package/lib/players/HlsPlayer.cjs +17 -706
- package/lib/players/HlsPlayer.cjs.map +1 -1
- package/lib/players/index.cjs +17 -706
- package/lib/players/index.cjs.map +1 -1
- package/lib/sdk/hlsAdPlayer.cjs.map +1 -1
- package/lib/sdk/ima.cjs +11 -4
- package/lib/sdk/ima.cjs.map +1 -1
- package/lib/ui/StormcloudVideoPlayer.cjs +17 -718
- package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/utils/browserCompat.cjs.map +1 -1
- package/lib/utils/polyfills.cjs.map +1 -1
- package/lib/utils/tracking.cjs.map +1 -1
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -866,10 +866,17 @@ function createImaController(video, options) {
|
|
|
866
866
|
var adsLoadedReject;
|
|
867
867
|
function makeAdsRequest(google, vastTagUrl) {
|
|
868
868
|
var adsRequest = new google.ima.AdsRequest();
|
|
869
|
-
|
|
870
|
-
|
|
869
|
+
var preloadedXml = preloadedVast.get(vastTagUrl);
|
|
870
|
+
if (preloadedXml) {
|
|
871
|
+
console.log("[IMA] \uD83D\uDCE6 Using preloaded VAST response");
|
|
872
|
+
adsRequest.adsResponse = preloadedXml;
|
|
873
|
+
preloadedVast.delete(vastTagUrl);
|
|
874
|
+
} else {
|
|
875
|
+
console.log("[IMA] \uD83D\uDCE1 Requesting VAST from URL (letting IMA fetch fresh)");
|
|
876
|
+
adsRequest.adTagUrl = vastTagUrl;
|
|
877
|
+
}
|
|
871
878
|
var videoWidth = video.offsetWidth || video.clientWidth || 640;
|
|
872
|
-
var videoHeight = video.offsetHeight || video.clientHeight ||
|
|
879
|
+
var videoHeight = video.offsetHeight || video.clientHeight || 480;
|
|
873
880
|
adsRequest.linearAdSlotWidth = videoWidth;
|
|
874
881
|
adsRequest.linearAdSlotHeight = videoHeight;
|
|
875
882
|
adsRequest.nonLinearAdSlotWidth = videoWidth;
|
|
@@ -1318,7 +1325,7 @@ function createImaController(video, options) {
|
|
|
1318
1325
|
}
|
|
1319
1326
|
try {
|
|
1320
1327
|
width = video.clientWidth || 640;
|
|
1321
|
-
height = video.clientHeight ||
|
|
1328
|
+
height = video.clientHeight || 480;
|
|
1322
1329
|
adsManager.init(width, height, window.google.ima.ViewMode.NORMAL);
|
|
1323
1330
|
adPlaying = true;
|
|
1324
1331
|
adVolume = originalMutedState ? 0 : originalVolume;
|
|
@@ -2946,18 +2953,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
2946
2953
|
this.bufferedSegmentsCount = 0;
|
|
2947
2954
|
this.shouldAutoplayAfterBuffering = false;
|
|
2948
2955
|
this.hasInitialBufferCompleted = false;
|
|
2949
|
-
this.adPodAllUrls = [];
|
|
2950
|
-
this.preloadingAdUrls = /* @__PURE__ */ new Set();
|
|
2951
|
-
this.vastToMediaUrlMap = /* @__PURE__ */ new Map();
|
|
2952
|
-
this.preloadedMediaUrls = /* @__PURE__ */ new Set();
|
|
2953
|
-
this.preloadingMediaUrls = /* @__PURE__ */ new Set();
|
|
2954
2956
|
this.adRequestTokenCounter = 0;
|
|
2955
2957
|
this.activeAdRequestToken = null;
|
|
2956
2958
|
this.adRequestWatchdogToken = null;
|
|
2957
2959
|
this.adFailsafeToken = null;
|
|
2958
|
-
this.fetchedAdDurations = /* @__PURE__ */ new Map();
|
|
2959
|
-
this.targetAdBreakDurationMs = null;
|
|
2960
|
-
this.isAdaptiveMode = false;
|
|
2961
2960
|
this.failedVastUrls = /* @__PURE__ */ new Set();
|
|
2962
2961
|
this.continuousFetchingActive = false;
|
|
2963
2962
|
this.adRequestQueue = [];
|
|
@@ -3462,25 +3461,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
3462
3461
|
}
|
|
3463
3462
|
});
|
|
3464
3463
|
this.ima.on("ad_error", function(errorPayload) {
|
|
3465
|
-
var remaining = _this.getRemainingAdMs();
|
|
3466
3464
|
console.error("[AD-ERROR] Ad playback failed", errorPayload || "");
|
|
3467
|
-
|
|
3468
|
-
if (remaining > 500 && _this.adPodQueue.length > 0) {
|
|
3469
|
-
var nextPreloaded = _this.findNextPreloadedAd();
|
|
3470
|
-
if (nextPreloaded) {
|
|
3471
|
-
_this.currentAdIndex++;
|
|
3472
|
-
_this.playSingleAd(nextPreloaded).catch(function() {
|
|
3473
|
-
_this.handleAdFailure();
|
|
3474
|
-
});
|
|
3475
|
-
} else {
|
|
3476
|
-
_this.handleAdFailure();
|
|
3477
|
-
}
|
|
3478
|
-
} else {
|
|
3479
|
-
_this.handleAdFailure();
|
|
3480
|
-
}
|
|
3481
|
-
} else {
|
|
3482
|
-
_this.handleAdFailure();
|
|
3483
|
-
}
|
|
3465
|
+
_this.handleAdFailure();
|
|
3484
3466
|
});
|
|
3485
3467
|
this.ima.on("content_pause", function() {
|
|
3486
3468
|
_this.clearAdFailsafeTimer();
|
|
@@ -4211,7 +4193,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4211
4193
|
key: "handleAdStart",
|
|
4212
4194
|
value: function handleAdStart(_marker) {
|
|
4213
4195
|
return _async_to_generator(function() {
|
|
4214
|
-
var scheduled, tags, baseVastUrl, adBreakDurationMs, currentMuted, currentVolume, firstAdUrlArray, firstAdUrl, error;
|
|
4196
|
+
var scheduled, tags, baseVastUrl, adBreakDurationMs, mode, currentMuted, currentVolume, firstAdUrlArray, firstAdUrl, error;
|
|
4215
4197
|
return _ts_generator(this, function(_state) {
|
|
4216
4198
|
switch(_state.label){
|
|
4217
4199
|
case 0:
|
|
@@ -4227,26 +4209,10 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4227
4209
|
];
|
|
4228
4210
|
}
|
|
4229
4211
|
adBreakDurationMs = _marker.durationSeconds != null ? _marker.durationSeconds * 1e3 : scheduled === null || scheduled === void 0 ? void 0 : scheduled.durationMs;
|
|
4230
|
-
if (this.
|
|
4231
|
-
this.
|
|
4232
|
-
|
|
4233
|
-
this.fetchedAdDurations.clear();
|
|
4234
|
-
if (this.config.debugAdTiming) {
|
|
4235
|
-
console.log("[CONTINUOUS-FETCH] \uD83D\uDCFA LIVE MODE: Target duration=".concat(adBreakDurationMs, "ms | Will continuously fetch ads during break"));
|
|
4236
|
-
}
|
|
4237
|
-
} else {
|
|
4238
|
-
this.isAdaptiveMode = false;
|
|
4239
|
-
this.targetAdBreakDurationMs = null;
|
|
4240
|
-
this.fetchedAdDurations.clear();
|
|
4241
|
-
if (this.config.debugAdTiming) {
|
|
4242
|
-
console.log("[CONTINUOUS-FETCH] \uD83C\uDFAC VOD MODE: Using fixed ad strategy");
|
|
4243
|
-
}
|
|
4212
|
+
if (this.config.debugAdTiming) {
|
|
4213
|
+
mode = this.isLiveStream ? "LIVE" : "VOD";
|
|
4214
|
+
console.log("[CONTINUOUS-FETCH] \uD83D\uDCFA ".concat(mode, " MODE: Target duration=").concat(adBreakDurationMs, "ms"));
|
|
4244
4215
|
}
|
|
4245
|
-
this.adPodAllUrls = [];
|
|
4246
|
-
this.preloadingAdUrls.clear();
|
|
4247
|
-
this.vastToMediaUrlMap.clear();
|
|
4248
|
-
this.preloadedMediaUrls.clear();
|
|
4249
|
-
this.preloadingMediaUrls.clear();
|
|
4250
4216
|
this.failedVastUrls.clear();
|
|
4251
4217
|
this.adRequestQueue = [];
|
|
4252
4218
|
this.successfulAdRequests = [];
|
|
@@ -5050,10 +5016,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
5050
5016
|
this.isShowingPlaceholder = false;
|
|
5051
5017
|
this.placeholderStartTimeMs = null;
|
|
5052
5018
|
}
|
|
5053
|
-
this.preloadingAdUrls.clear();
|
|
5054
|
-
this.vastToMediaUrlMap.clear();
|
|
5055
|
-
this.preloadedMediaUrls.clear();
|
|
5056
|
-
this.preloadingMediaUrls.clear();
|
|
5057
5019
|
this.adRequestQueue = [];
|
|
5058
5020
|
this.successfulAdRequests = [];
|
|
5059
5021
|
this.inAdBreak = false;
|
|
@@ -5062,7 +5024,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
5062
5024
|
this.clearAdStartTimer();
|
|
5063
5025
|
this.clearAdStopTimer();
|
|
5064
5026
|
this.adPodQueue = [];
|
|
5065
|
-
this.adPodAllUrls = [];
|
|
5066
5027
|
this.showAds = false;
|
|
5067
5028
|
this.currentAdIndex = 0;
|
|
5068
5029
|
this.totalAdsInBreak = 0;
|
|
@@ -5217,651 +5178,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
5217
5178
|
}, extra));
|
|
5218
5179
|
}
|
|
5219
5180
|
},
|
|
5220
|
-
{
|
|
5221
|
-
key: "fetchAndParseVastXml",
|
|
5222
|
-
value: function fetchAndParseVastXml(vastTagUrl) {
|
|
5223
|
-
return _async_to_generator(function() {
|
|
5224
|
-
var response, xmlText, error;
|
|
5225
|
-
return _ts_generator(this, function(_state) {
|
|
5226
|
-
switch(_state.label){
|
|
5227
|
-
case 0:
|
|
5228
|
-
_state.trys.push([
|
|
5229
|
-
0,
|
|
5230
|
-
3,
|
|
5231
|
-
,
|
|
5232
|
-
4
|
|
5233
|
-
]);
|
|
5234
|
-
return [
|
|
5235
|
-
4,
|
|
5236
|
-
fetch(vastTagUrl, {
|
|
5237
|
-
mode: "cors",
|
|
5238
|
-
credentials: "include",
|
|
5239
|
-
headers: {
|
|
5240
|
-
"Accept": "application/xml, text/xml, */*"
|
|
5241
|
-
},
|
|
5242
|
-
referrerPolicy: "no-referrer-when-downgrade"
|
|
5243
|
-
})
|
|
5244
|
-
];
|
|
5245
|
-
case 1:
|
|
5246
|
-
response = _state.sent();
|
|
5247
|
-
if (!response.ok) {
|
|
5248
|
-
throw new Error("Failed to fetch VAST: ".concat(response.status));
|
|
5249
|
-
}
|
|
5250
|
-
return [
|
|
5251
|
-
4,
|
|
5252
|
-
response.text()
|
|
5253
|
-
];
|
|
5254
|
-
case 2:
|
|
5255
|
-
xmlText = _state.sent();
|
|
5256
|
-
return [
|
|
5257
|
-
2,
|
|
5258
|
-
this.extractMediaUrlsFromVast(xmlText)
|
|
5259
|
-
];
|
|
5260
|
-
case 3:
|
|
5261
|
-
error = _state.sent();
|
|
5262
|
-
if (this.config.debugAdTiming) {
|
|
5263
|
-
console.warn("[StormcloudVideoPlayer] Failed to fetch/parse VAST XML: ".concat(vastTagUrl), error);
|
|
5264
|
-
}
|
|
5265
|
-
return [
|
|
5266
|
-
2,
|
|
5267
|
-
[]
|
|
5268
|
-
];
|
|
5269
|
-
case 4:
|
|
5270
|
-
return [
|
|
5271
|
-
2
|
|
5272
|
-
];
|
|
5273
|
-
}
|
|
5274
|
-
});
|
|
5275
|
-
}).call(this);
|
|
5276
|
-
}
|
|
5277
|
-
},
|
|
5278
|
-
{
|
|
5279
|
-
key: "extractMediaUrlsFromVast",
|
|
5280
|
-
value: function extractMediaUrlsFromVast(xmlText) {
|
|
5281
|
-
var mediaUrls = [];
|
|
5282
|
-
try {
|
|
5283
|
-
var parser = new DOMParser();
|
|
5284
|
-
var xmlDoc = parser.parseFromString(xmlText, "text/xml");
|
|
5285
|
-
var mediaFileElements = xmlDoc.querySelectorAll("MediaFile");
|
|
5286
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
5287
|
-
try {
|
|
5288
|
-
for(var _iterator = Array.from(mediaFileElements)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
5289
|
-
var mediaFile = _step.value;
|
|
5290
|
-
var _mediaFile_textContent;
|
|
5291
|
-
var url = (_mediaFile_textContent = mediaFile.textContent) === null || _mediaFile_textContent === void 0 ? void 0 : _mediaFile_textContent.trim();
|
|
5292
|
-
if (url) {
|
|
5293
|
-
var lowerUrl = url.toLowerCase();
|
|
5294
|
-
if (lowerUrl.endsWith(".mp4") || lowerUrl.endsWith(".webm") || lowerUrl.endsWith(".mov") || lowerUrl.endsWith(".avi") || lowerUrl.includes(".mp4?") || lowerUrl.includes(".webm?") || lowerUrl.includes("/mp4/") || lowerUrl.includes("type=video")) {
|
|
5295
|
-
mediaUrls.push(url);
|
|
5296
|
-
}
|
|
5297
|
-
}
|
|
5298
|
-
}
|
|
5299
|
-
} catch (err) {
|
|
5300
|
-
_didIteratorError = true;
|
|
5301
|
-
_iteratorError = err;
|
|
5302
|
-
} finally{
|
|
5303
|
-
try {
|
|
5304
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
5305
|
-
_iterator.return();
|
|
5306
|
-
}
|
|
5307
|
-
} finally{
|
|
5308
|
-
if (_didIteratorError) {
|
|
5309
|
-
throw _iteratorError;
|
|
5310
|
-
}
|
|
5311
|
-
}
|
|
5312
|
-
}
|
|
5313
|
-
if (this.config.debugAdTiming && mediaUrls.length > 0) {
|
|
5314
|
-
console.log("[StormcloudVideoPlayer] Extracted ".concat(mediaUrls.length, " media URLs from VAST:"), mediaUrls);
|
|
5315
|
-
}
|
|
5316
|
-
} catch (error) {
|
|
5317
|
-
if (this.config.debugAdTiming) {
|
|
5318
|
-
console.warn("[StormcloudVideoPlayer] Failed to parse VAST XML:", error);
|
|
5319
|
-
}
|
|
5320
|
-
}
|
|
5321
|
-
return mediaUrls;
|
|
5322
|
-
}
|
|
5323
|
-
},
|
|
5324
|
-
{
|
|
5325
|
-
key: "fetchVastDuration",
|
|
5326
|
-
value: function fetchVastDuration(vastTagUrl) {
|
|
5327
|
-
return _async_to_generator(function() {
|
|
5328
|
-
var _xmlDoc_querySelector, response, xmlText, parser, xmlDoc, durationText, durationParts, durationSeconds, error;
|
|
5329
|
-
return _ts_generator(this, function(_state) {
|
|
5330
|
-
switch(_state.label){
|
|
5331
|
-
case 0:
|
|
5332
|
-
_state.trys.push([
|
|
5333
|
-
0,
|
|
5334
|
-
3,
|
|
5335
|
-
,
|
|
5336
|
-
4
|
|
5337
|
-
]);
|
|
5338
|
-
return [
|
|
5339
|
-
4,
|
|
5340
|
-
fetch(vastTagUrl, {
|
|
5341
|
-
mode: "cors",
|
|
5342
|
-
credentials: "include",
|
|
5343
|
-
headers: {
|
|
5344
|
-
"Accept": "application/xml, text/xml, */*"
|
|
5345
|
-
},
|
|
5346
|
-
referrerPolicy: "no-referrer-when-downgrade"
|
|
5347
|
-
})
|
|
5348
|
-
];
|
|
5349
|
-
case 1:
|
|
5350
|
-
response = _state.sent();
|
|
5351
|
-
if (!response.ok) {
|
|
5352
|
-
if (this.config.debugAdTiming) {
|
|
5353
|
-
console.warn("[ADAPTIVE-POD] Failed to fetch VAST: ".concat(response.status));
|
|
5354
|
-
}
|
|
5355
|
-
return [
|
|
5356
|
-
2,
|
|
5357
|
-
null
|
|
5358
|
-
];
|
|
5359
|
-
}
|
|
5360
|
-
return [
|
|
5361
|
-
4,
|
|
5362
|
-
response.text()
|
|
5363
|
-
];
|
|
5364
|
-
case 2:
|
|
5365
|
-
xmlText = _state.sent();
|
|
5366
|
-
parser = new DOMParser();
|
|
5367
|
-
xmlDoc = parser.parseFromString(xmlText, "text/xml");
|
|
5368
|
-
durationText = (_xmlDoc_querySelector = xmlDoc.querySelector("Duration")) === null || _xmlDoc_querySelector === void 0 ? void 0 : _xmlDoc_querySelector.textContent;
|
|
5369
|
-
if (!durationText) {
|
|
5370
|
-
if (this.config.debugAdTiming) {
|
|
5371
|
-
console.warn("[ADAPTIVE-POD] No Duration element found in VAST");
|
|
5372
|
-
}
|
|
5373
|
-
return [
|
|
5374
|
-
2,
|
|
5375
|
-
null
|
|
5376
|
-
];
|
|
5377
|
-
}
|
|
5378
|
-
durationParts = durationText.split(":");
|
|
5379
|
-
durationSeconds = parseInt(durationParts[0] || "0", 10) * 3600 + parseInt(durationParts[1] || "0", 10) * 60 + parseInt(durationParts[2] || "0", 10);
|
|
5380
|
-
return [
|
|
5381
|
-
2,
|
|
5382
|
-
durationSeconds
|
|
5383
|
-
];
|
|
5384
|
-
case 3:
|
|
5385
|
-
error = _state.sent();
|
|
5386
|
-
if (this.config.debugAdTiming) {
|
|
5387
|
-
console.warn("[ADAPTIVE-POD] Error fetching VAST duration from ".concat(vastTagUrl, ":"), error);
|
|
5388
|
-
}
|
|
5389
|
-
return [
|
|
5390
|
-
2,
|
|
5391
|
-
null
|
|
5392
|
-
];
|
|
5393
|
-
case 4:
|
|
5394
|
-
return [
|
|
5395
|
-
2
|
|
5396
|
-
];
|
|
5397
|
-
}
|
|
5398
|
-
});
|
|
5399
|
-
}).call(this);
|
|
5400
|
-
}
|
|
5401
|
-
},
|
|
5402
|
-
{
|
|
5403
|
-
key: "calculateAdditionalAdsNeeded",
|
|
5404
|
-
value: function calculateAdditionalAdsNeeded() {
|
|
5405
|
-
if (!this.isAdaptiveMode || this.targetAdBreakDurationMs === null) {
|
|
5406
|
-
return 0;
|
|
5407
|
-
}
|
|
5408
|
-
var totalFetchedDurationMs = 0;
|
|
5409
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
5410
|
-
try {
|
|
5411
|
-
for(var _iterator = this.fetchedAdDurations.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
5412
|
-
var duration = _step.value;
|
|
5413
|
-
totalFetchedDurationMs += duration * 1e3;
|
|
5414
|
-
}
|
|
5415
|
-
} catch (err) {
|
|
5416
|
-
_didIteratorError = true;
|
|
5417
|
-
_iteratorError = err;
|
|
5418
|
-
} finally{
|
|
5419
|
-
try {
|
|
5420
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
5421
|
-
_iterator.return();
|
|
5422
|
-
}
|
|
5423
|
-
} finally{
|
|
5424
|
-
if (_didIteratorError) {
|
|
5425
|
-
throw _iteratorError;
|
|
5426
|
-
}
|
|
5427
|
-
}
|
|
5428
|
-
}
|
|
5429
|
-
var fetchedCount = this.fetchedAdDurations.size;
|
|
5430
|
-
var averageDurationMs = fetchedCount > 0 ? totalFetchedDurationMs / fetchedCount : 30 * 1e3;
|
|
5431
|
-
var queuedButNotFetched = this.adPodAllUrls.length - fetchedCount;
|
|
5432
|
-
var estimatedQueuedDurationMs = queuedButNotFetched * averageDurationMs;
|
|
5433
|
-
var estimatedTotalDurationMs = totalFetchedDurationMs + estimatedQueuedDurationMs;
|
|
5434
|
-
var remainingTimeMs = this.targetAdBreakDurationMs - estimatedTotalDurationMs;
|
|
5435
|
-
if (remainingTimeMs <= 0) {
|
|
5436
|
-
if (this.config.debugAdTiming) {
|
|
5437
|
-
console.log("[ADAPTIVE-POD] ✅ Target duration met: Fetched=".concat(totalFetchedDurationMs, "ms + Queued(").concat(queuedButNotFetched, " ads)=").concat(estimatedQueuedDurationMs, "ms = ").concat(estimatedTotalDurationMs, "ms / Target=").concat(this.targetAdBreakDurationMs, "ms"));
|
|
5438
|
-
}
|
|
5439
|
-
return 0;
|
|
5440
|
-
}
|
|
5441
|
-
var additionalAds = Math.ceil(remainingTimeMs / averageDurationMs);
|
|
5442
|
-
if (this.config.debugAdTiming) {
|
|
5443
|
-
console.log("[ADAPTIVE-POD] \uD83D\uDCCA Need ".concat(additionalAds, " more ads | Fetched: ").concat(totalFetchedDurationMs, "ms (").concat(fetchedCount, " ads) | Queued: ").concat(estimatedQueuedDurationMs, "ms (").concat(queuedButNotFetched, " ads) | Target: ").concat(this.targetAdBreakDurationMs, "ms | Remaining: ").concat(remainingTimeMs, "ms | Avg duration: ").concat(averageDurationMs, "ms"));
|
|
5444
|
-
}
|
|
5445
|
-
return additionalAds;
|
|
5446
|
-
}
|
|
5447
|
-
},
|
|
5448
|
-
{
|
|
5449
|
-
key: "addAdaptiveAdsToQueue",
|
|
5450
|
-
value: function addAdaptiveAdsToQueue() {
|
|
5451
|
-
return _async_to_generator(function() {
|
|
5452
|
-
var _this_adPodAllUrls, _this_adPodQueue, additionalAds, newUrls;
|
|
5453
|
-
return _ts_generator(this, function(_state) {
|
|
5454
|
-
if (!this.isAdaptiveMode || !this.apiVastTagUrl) {
|
|
5455
|
-
return [
|
|
5456
|
-
2
|
|
5457
|
-
];
|
|
5458
|
-
}
|
|
5459
|
-
additionalAds = this.calculateAdditionalAdsNeeded();
|
|
5460
|
-
if (additionalAds <= 0) {
|
|
5461
|
-
return [
|
|
5462
|
-
2
|
|
5463
|
-
];
|
|
5464
|
-
}
|
|
5465
|
-
newUrls = this.generateVastUrlsWithCorrelators(this.apiVastTagUrl, additionalAds);
|
|
5466
|
-
if (this.config.debugAdTiming) {
|
|
5467
|
-
console.log("[ADAPTIVE-POD] \uD83D\uDD04 Adding ".concat(newUrls.length, " additional VAST URLs to queue (will be preloaded sequentially)"));
|
|
5468
|
-
}
|
|
5469
|
-
(_this_adPodAllUrls = this.adPodAllUrls).push.apply(_this_adPodAllUrls, _to_consumable_array(newUrls));
|
|
5470
|
-
(_this_adPodQueue = this.adPodQueue).push.apply(_this_adPodQueue, _to_consumable_array(newUrls));
|
|
5471
|
-
this.totalAdsInBreak += newUrls.length;
|
|
5472
|
-
return [
|
|
5473
|
-
2
|
|
5474
|
-
];
|
|
5475
|
-
});
|
|
5476
|
-
}).call(this);
|
|
5477
|
-
}
|
|
5478
|
-
},
|
|
5479
|
-
{
|
|
5480
|
-
key: "preloadMediaFile",
|
|
5481
|
-
value: function preloadMediaFile(mediaUrl) {
|
|
5482
|
-
return _async_to_generator(function() {
|
|
5483
|
-
var response, error;
|
|
5484
|
-
return _ts_generator(this, function(_state) {
|
|
5485
|
-
switch(_state.label){
|
|
5486
|
-
case 0:
|
|
5487
|
-
if (this.preloadedMediaUrls.has(mediaUrl)) {
|
|
5488
|
-
return [
|
|
5489
|
-
2
|
|
5490
|
-
];
|
|
5491
|
-
}
|
|
5492
|
-
if (this.preloadingMediaUrls.has(mediaUrl)) {
|
|
5493
|
-
return [
|
|
5494
|
-
2
|
|
5495
|
-
];
|
|
5496
|
-
}
|
|
5497
|
-
this.preloadingMediaUrls.add(mediaUrl);
|
|
5498
|
-
_state.label = 1;
|
|
5499
|
-
case 1:
|
|
5500
|
-
_state.trys.push([
|
|
5501
|
-
1,
|
|
5502
|
-
3,
|
|
5503
|
-
4,
|
|
5504
|
-
5
|
|
5505
|
-
]);
|
|
5506
|
-
if (this.config.debugAdTiming) {
|
|
5507
|
-
console.log("[StormcloudVideoPlayer] Preloading video file: ".concat(mediaUrl));
|
|
5508
|
-
}
|
|
5509
|
-
return [
|
|
5510
|
-
4,
|
|
5511
|
-
fetch(mediaUrl, {
|
|
5512
|
-
mode: "cors",
|
|
5513
|
-
credentials: "include",
|
|
5514
|
-
method: "GET",
|
|
5515
|
-
headers: {
|
|
5516
|
-
Range: "bytes=0-1048576"
|
|
5517
|
-
},
|
|
5518
|
-
referrerPolicy: "no-referrer-when-downgrade"
|
|
5519
|
-
})
|
|
5520
|
-
];
|
|
5521
|
-
case 2:
|
|
5522
|
-
response = _state.sent();
|
|
5523
|
-
if (response.ok || response.status === 206) {
|
|
5524
|
-
this.preloadedMediaUrls.add(mediaUrl);
|
|
5525
|
-
if (this.config.debugAdTiming) {
|
|
5526
|
-
console.log("[StormcloudVideoPlayer] Successfully preloaded video file: ".concat(mediaUrl));
|
|
5527
|
-
}
|
|
5528
|
-
}
|
|
5529
|
-
return [
|
|
5530
|
-
3,
|
|
5531
|
-
5
|
|
5532
|
-
];
|
|
5533
|
-
case 3:
|
|
5534
|
-
error = _state.sent();
|
|
5535
|
-
if (this.config.debugAdTiming) {
|
|
5536
|
-
console.warn("[StormcloudVideoPlayer] Failed to preload video file: ".concat(mediaUrl), error);
|
|
5537
|
-
}
|
|
5538
|
-
return [
|
|
5539
|
-
3,
|
|
5540
|
-
5
|
|
5541
|
-
];
|
|
5542
|
-
case 4:
|
|
5543
|
-
this.preloadingMediaUrls.delete(mediaUrl);
|
|
5544
|
-
return [
|
|
5545
|
-
7
|
|
5546
|
-
];
|
|
5547
|
-
case 5:
|
|
5548
|
-
return [
|
|
5549
|
-
2
|
|
5550
|
-
];
|
|
5551
|
-
}
|
|
5552
|
-
});
|
|
5553
|
-
}).call(this);
|
|
5554
|
-
}
|
|
5555
|
-
},
|
|
5556
|
-
{
|
|
5557
|
-
key: "preloadAllAdsInBackground",
|
|
5558
|
-
value: function preloadAllAdsInBackground() {
|
|
5559
|
-
return _async_to_generator(function() {
|
|
5560
|
-
var _this, processedUrls, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, url, _this_ima_hasPreloadedAd, _this_ima, nextUrl, error, preloadPromises;
|
|
5561
|
-
return _ts_generator(this, function(_state) {
|
|
5562
|
-
switch(_state.label){
|
|
5563
|
-
case 0:
|
|
5564
|
-
_this = this;
|
|
5565
|
-
if (this.adPodAllUrls.length === 0) {
|
|
5566
|
-
return [
|
|
5567
|
-
2
|
|
5568
|
-
];
|
|
5569
|
-
}
|
|
5570
|
-
if (!this.isAdaptiveMode) return [
|
|
5571
|
-
3,
|
|
5572
|
-
7
|
|
5573
|
-
];
|
|
5574
|
-
if (this.config.debugAdTiming) {
|
|
5575
|
-
console.log("[ADAPTIVE-POD] \uD83D\uDD04 Starting sequential preload of remaining ads");
|
|
5576
|
-
}
|
|
5577
|
-
processedUrls = /* @__PURE__ */ new Set();
|
|
5578
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
5579
|
-
try {
|
|
5580
|
-
for(_iterator = this.adPodAllUrls[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
5581
|
-
url = _step.value;
|
|
5582
|
-
;
|
|
5583
|
-
if (((_this_ima_hasPreloadedAd = (_this_ima = this.ima).hasPreloadedAd) === null || _this_ima_hasPreloadedAd === void 0 ? void 0 : _this_ima_hasPreloadedAd.call(_this_ima, url)) || this.fetchedAdDurations.has(url)) {
|
|
5584
|
-
processedUrls.add(url);
|
|
5585
|
-
}
|
|
5586
|
-
}
|
|
5587
|
-
} catch (err) {
|
|
5588
|
-
_didIteratorError = true;
|
|
5589
|
-
_iteratorError = err;
|
|
5590
|
-
} finally{
|
|
5591
|
-
try {
|
|
5592
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
5593
|
-
_iterator.return();
|
|
5594
|
-
}
|
|
5595
|
-
} finally{
|
|
5596
|
-
if (_didIteratorError) {
|
|
5597
|
-
throw _iteratorError;
|
|
5598
|
-
}
|
|
5599
|
-
}
|
|
5600
|
-
}
|
|
5601
|
-
if (this.config.debugAdTiming && processedUrls.size > 0) {
|
|
5602
|
-
console.log("[ADAPTIVE-POD] \uD83D\uDCE6 Skipping ".concat(processedUrls.size, " already-preloaded ads"));
|
|
5603
|
-
}
|
|
5604
|
-
_state.label = 1;
|
|
5605
|
-
case 1:
|
|
5606
|
-
if (!true) return [
|
|
5607
|
-
3,
|
|
5608
|
-
6
|
|
5609
|
-
];
|
|
5610
|
-
nextUrl = this.adPodAllUrls.find(function(url) {
|
|
5611
|
-
return !processedUrls.has(url);
|
|
5612
|
-
});
|
|
5613
|
-
if (!nextUrl) {
|
|
5614
|
-
if (this.config.debugAdTiming) {
|
|
5615
|
-
console.log("[ADAPTIVE-POD] ✅ All queued ads processed (".concat(processedUrls.size, " total)"));
|
|
5616
|
-
}
|
|
5617
|
-
return [
|
|
5618
|
-
3,
|
|
5619
|
-
6
|
|
5620
|
-
];
|
|
5621
|
-
}
|
|
5622
|
-
processedUrls.add(nextUrl);
|
|
5623
|
-
if (this.config.debugAdTiming) {
|
|
5624
|
-
console.log("[ADAPTIVE-POD] \uD83D\uDCE5 Preloading ad ".concat(processedUrls.size, "/").concat(this.adPodAllUrls.length, "..."));
|
|
5625
|
-
}
|
|
5626
|
-
_state.label = 2;
|
|
5627
|
-
case 2:
|
|
5628
|
-
_state.trys.push([
|
|
5629
|
-
2,
|
|
5630
|
-
4,
|
|
5631
|
-
,
|
|
5632
|
-
5
|
|
5633
|
-
]);
|
|
5634
|
-
return [
|
|
5635
|
-
4,
|
|
5636
|
-
this.preloadSingleAd(nextUrl)
|
|
5637
|
-
];
|
|
5638
|
-
case 3:
|
|
5639
|
-
_state.sent();
|
|
5640
|
-
return [
|
|
5641
|
-
3,
|
|
5642
|
-
5
|
|
5643
|
-
];
|
|
5644
|
-
case 4:
|
|
5645
|
-
error = _state.sent();
|
|
5646
|
-
if (this.config.debugAdTiming) {
|
|
5647
|
-
console.warn("[ADAPTIVE-POD] ⚠️ Preload failed for ad ".concat(processedUrls.size, ":"), error);
|
|
5648
|
-
}
|
|
5649
|
-
return [
|
|
5650
|
-
3,
|
|
5651
|
-
5
|
|
5652
|
-
];
|
|
5653
|
-
case 5:
|
|
5654
|
-
if (this.calculateAdditionalAdsNeeded() === 0) {
|
|
5655
|
-
if (this.config.debugAdTiming) {
|
|
5656
|
-
console.log("[ADAPTIVE-POD] ✅ Target duration reached (".concat(processedUrls.size, " ads preloaded), stopping"));
|
|
5657
|
-
}
|
|
5658
|
-
return [
|
|
5659
|
-
3,
|
|
5660
|
-
6
|
|
5661
|
-
];
|
|
5662
|
-
}
|
|
5663
|
-
return [
|
|
5664
|
-
3,
|
|
5665
|
-
1
|
|
5666
|
-
];
|
|
5667
|
-
case 6:
|
|
5668
|
-
if (this.config.debugAdTiming) {
|
|
5669
|
-
console.log("[ADAPTIVE-POD] ✅ Sequential preloading completed (".concat(processedUrls.size, " ads ready)"));
|
|
5670
|
-
}
|
|
5671
|
-
return [
|
|
5672
|
-
3,
|
|
5673
|
-
9
|
|
5674
|
-
];
|
|
5675
|
-
case 7:
|
|
5676
|
-
if (this.config.debugAdTiming) {
|
|
5677
|
-
console.log("[StormcloudVideoPlayer] Starting parallel preload of ".concat(this.adPodAllUrls.length, " ads"));
|
|
5678
|
-
}
|
|
5679
|
-
preloadPromises = this.adPodAllUrls.map(function(vastTagUrl) {
|
|
5680
|
-
return _this.preloadSingleAd(vastTagUrl).catch(function(error) {
|
|
5681
|
-
if (_this.config.debugAdTiming) {
|
|
5682
|
-
console.warn("[StormcloudVideoPlayer] Preload failed for ".concat(vastTagUrl, ":"), error);
|
|
5683
|
-
}
|
|
5684
|
-
});
|
|
5685
|
-
});
|
|
5686
|
-
return [
|
|
5687
|
-
4,
|
|
5688
|
-
Promise.all(preloadPromises)
|
|
5689
|
-
];
|
|
5690
|
-
case 8:
|
|
5691
|
-
_state.sent();
|
|
5692
|
-
if (this.config.debugAdTiming) {
|
|
5693
|
-
console.log("[StormcloudVideoPlayer] Background preloading completed for all ads");
|
|
5694
|
-
}
|
|
5695
|
-
_state.label = 9;
|
|
5696
|
-
case 9:
|
|
5697
|
-
return [
|
|
5698
|
-
2
|
|
5699
|
-
];
|
|
5700
|
-
}
|
|
5701
|
-
});
|
|
5702
|
-
}).call(this);
|
|
5703
|
-
}
|
|
5704
|
-
},
|
|
5705
|
-
{
|
|
5706
|
-
key: "preloadSingleAd",
|
|
5707
|
-
value: function preloadSingleAd(vastTagUrl) {
|
|
5708
|
-
return _async_to_generator(function() {
|
|
5709
|
-
var _this, duration, mediaUrls, primaryMediaUrl, error;
|
|
5710
|
-
return _ts_generator(this, function(_state) {
|
|
5711
|
-
switch(_state.label){
|
|
5712
|
-
case 0:
|
|
5713
|
-
_this = this;
|
|
5714
|
-
if (!vastTagUrl) return [
|
|
5715
|
-
2
|
|
5716
|
-
];
|
|
5717
|
-
_state.label = 1;
|
|
5718
|
-
case 1:
|
|
5719
|
-
_state.trys.push([
|
|
5720
|
-
1,
|
|
5721
|
-
11,
|
|
5722
|
-
,
|
|
5723
|
-
12
|
|
5724
|
-
]);
|
|
5725
|
-
if (!(this.isAdaptiveMode && !this.fetchedAdDurations.has(vastTagUrl))) return [
|
|
5726
|
-
3,
|
|
5727
|
-
4
|
|
5728
|
-
];
|
|
5729
|
-
return [
|
|
5730
|
-
4,
|
|
5731
|
-
this.fetchVastDuration(vastTagUrl)
|
|
5732
|
-
];
|
|
5733
|
-
case 2:
|
|
5734
|
-
duration = _state.sent();
|
|
5735
|
-
if (!(duration !== null)) return [
|
|
5736
|
-
3,
|
|
5737
|
-
4
|
|
5738
|
-
];
|
|
5739
|
-
this.fetchedAdDurations.set(vastTagUrl, duration);
|
|
5740
|
-
if (this.config.debugAdTiming) {
|
|
5741
|
-
console.log("[ADAPTIVE-POD] ✓ Fetched ad duration: ".concat(duration, "s (").concat(this.fetchedAdDurations.size, " ads fetched so far)"));
|
|
5742
|
-
}
|
|
5743
|
-
return [
|
|
5744
|
-
4,
|
|
5745
|
-
this.addAdaptiveAdsToQueue()
|
|
5746
|
-
];
|
|
5747
|
-
case 3:
|
|
5748
|
-
_state.sent();
|
|
5749
|
-
_state.label = 4;
|
|
5750
|
-
case 4:
|
|
5751
|
-
if (!(this.ima.preloadAds && !this.ima.hasPreloadedAd(vastTagUrl))) return [
|
|
5752
|
-
3,
|
|
5753
|
-
6
|
|
5754
|
-
];
|
|
5755
|
-
if (!!this.preloadingAdUrls.has(vastTagUrl)) return [
|
|
5756
|
-
3,
|
|
5757
|
-
6
|
|
5758
|
-
];
|
|
5759
|
-
if (this.config.debugAdTiming) {
|
|
5760
|
-
console.log("[StormcloudVideoPlayer] Preloading VAST: ".concat(vastTagUrl));
|
|
5761
|
-
}
|
|
5762
|
-
this.preloadingAdUrls.add(vastTagUrl);
|
|
5763
|
-
return [
|
|
5764
|
-
4,
|
|
5765
|
-
this.ima.preloadAds(vastTagUrl).then(function() {
|
|
5766
|
-
if (_this.config.debugAdTiming) {
|
|
5767
|
-
console.log("[StormcloudVideoPlayer] IMA VAST preload complete: ".concat(vastTagUrl));
|
|
5768
|
-
}
|
|
5769
|
-
}).catch(function(error) {
|
|
5770
|
-
if (_this.config.debugAdTiming) {
|
|
5771
|
-
console.warn("[StormcloudVideoPlayer] IMA VAST preload failed: ".concat(vastTagUrl), error);
|
|
5772
|
-
}
|
|
5773
|
-
}).finally(function() {
|
|
5774
|
-
_this.preloadingAdUrls.delete(vastTagUrl);
|
|
5775
|
-
})
|
|
5776
|
-
];
|
|
5777
|
-
case 5:
|
|
5778
|
-
_state.sent();
|
|
5779
|
-
_state.label = 6;
|
|
5780
|
-
case 6:
|
|
5781
|
-
mediaUrls = this.vastToMediaUrlMap.get(vastTagUrl);
|
|
5782
|
-
if (!!mediaUrls) return [
|
|
5783
|
-
3,
|
|
5784
|
-
8
|
|
5785
|
-
];
|
|
5786
|
-
if (this.config.debugAdTiming) {
|
|
5787
|
-
console.log("[StormcloudVideoPlayer] Fetching and parsing VAST to extract media URLs: ".concat(vastTagUrl));
|
|
5788
|
-
}
|
|
5789
|
-
return [
|
|
5790
|
-
4,
|
|
5791
|
-
this.fetchAndParseVastXml(vastTagUrl)
|
|
5792
|
-
];
|
|
5793
|
-
case 7:
|
|
5794
|
-
mediaUrls = _state.sent();
|
|
5795
|
-
if (this.config.debugAdTiming) {
|
|
5796
|
-
console.log("[StormcloudVideoPlayer] Extracted ".concat(mediaUrls.length, " media URLs:"), mediaUrls);
|
|
5797
|
-
}
|
|
5798
|
-
if (mediaUrls.length > 0) {
|
|
5799
|
-
this.vastToMediaUrlMap.set(vastTagUrl, mediaUrls);
|
|
5800
|
-
}
|
|
5801
|
-
_state.label = 8;
|
|
5802
|
-
case 8:
|
|
5803
|
-
if (!(mediaUrls && mediaUrls.length > 0)) return [
|
|
5804
|
-
3,
|
|
5805
|
-
10
|
|
5806
|
-
];
|
|
5807
|
-
primaryMediaUrl = mediaUrls[0];
|
|
5808
|
-
if (!(primaryMediaUrl && !this.preloadedMediaUrls.has(primaryMediaUrl))) return [
|
|
5809
|
-
3,
|
|
5810
|
-
10
|
|
5811
|
-
];
|
|
5812
|
-
return [
|
|
5813
|
-
4,
|
|
5814
|
-
this.preloadMediaFile(primaryMediaUrl)
|
|
5815
|
-
];
|
|
5816
|
-
case 9:
|
|
5817
|
-
_state.sent();
|
|
5818
|
-
_state.label = 10;
|
|
5819
|
-
case 10:
|
|
5820
|
-
return [
|
|
5821
|
-
3,
|
|
5822
|
-
12
|
|
5823
|
-
];
|
|
5824
|
-
case 11:
|
|
5825
|
-
error = _state.sent();
|
|
5826
|
-
if (this.config.debugAdTiming) {
|
|
5827
|
-
console.warn("[StormcloudVideoPlayer] Failed to preload ad: ".concat(vastTagUrl), error);
|
|
5828
|
-
}
|
|
5829
|
-
return [
|
|
5830
|
-
3,
|
|
5831
|
-
12
|
|
5832
|
-
];
|
|
5833
|
-
case 12:
|
|
5834
|
-
return [
|
|
5835
|
-
2
|
|
5836
|
-
];
|
|
5837
|
-
}
|
|
5838
|
-
});
|
|
5839
|
-
}).call(this);
|
|
5840
|
-
}
|
|
5841
|
-
},
|
|
5842
|
-
{
|
|
5843
|
-
key: "findNextPreloadedAd",
|
|
5844
|
-
value: function findNextPreloadedAd() {
|
|
5845
|
-
for(var i = 0; i < this.adPodQueue.length; i++){
|
|
5846
|
-
var _this_ima_hasPreloadedAd, _this_ima;
|
|
5847
|
-
var vastTagUrl = this.adPodQueue[i];
|
|
5848
|
-
if (!vastTagUrl) continue;
|
|
5849
|
-
if (this.failedVastUrls.has(vastTagUrl)) {
|
|
5850
|
-
console.warn("[AD-ERROR] Skipping failed URL in queue");
|
|
5851
|
-
continue;
|
|
5852
|
-
}
|
|
5853
|
-
var _this_ima_hasPreloadedAd1;
|
|
5854
|
-
var hasImaPreload = (_this_ima_hasPreloadedAd1 = (_this_ima_hasPreloadedAd = (_this_ima = this.ima).hasPreloadedAd) === null || _this_ima_hasPreloadedAd === void 0 ? void 0 : _this_ima_hasPreloadedAd.call(_this_ima, vastTagUrl)) !== null && _this_ima_hasPreloadedAd1 !== void 0 ? _this_ima_hasPreloadedAd1 : false;
|
|
5855
|
-
var mediaUrls = this.vastToMediaUrlMap.get(vastTagUrl);
|
|
5856
|
-
var hasMediaPreload = mediaUrls && mediaUrls.length > 0 ? this.preloadedMediaUrls.has(mediaUrls[0]) : false;
|
|
5857
|
-
if (hasImaPreload || hasMediaPreload) {
|
|
5858
|
-
this.adPodQueue.splice(0, i + 1);
|
|
5859
|
-
return vastTagUrl;
|
|
5860
|
-
}
|
|
5861
|
-
}
|
|
5862
|
-
return void 0;
|
|
5863
|
-
}
|
|
5864
|
-
},
|
|
5865
5181
|
{
|
|
5866
5182
|
key: "getRemainingAdMs",
|
|
5867
5183
|
value: function getRemainingAdMs() {
|
|
@@ -6048,7 +5364,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
6048
5364
|
}
|
|
6049
5365
|
if (this.ima && this.ima.isAdPlaying()) {
|
|
6050
5366
|
var width = this.video.clientWidth || 640;
|
|
6051
|
-
var height = this.video.clientHeight ||
|
|
5367
|
+
var height = this.video.clientHeight || 480;
|
|
6052
5368
|
if (this.config.debugAdTiming) {
|
|
6053
5369
|
console.log("[StormcloudVideoPlayer] Resizing ads manager to ".concat(width, "x").concat(height));
|
|
6054
5370
|
}
|
|
@@ -6079,11 +5395,6 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
6079
5395
|
}
|
|
6080
5396
|
(_this_hls = this.hls) === null || _this_hls === void 0 ? void 0 : _this_hls.destroy();
|
|
6081
5397
|
(_this_ima = this.ima) === null || _this_ima === void 0 ? void 0 : _this_ima.destroy();
|
|
6082
|
-
this.preloadingAdUrls.clear();
|
|
6083
|
-
this.vastToMediaUrlMap.clear();
|
|
6084
|
-
this.preloadedMediaUrls.clear();
|
|
6085
|
-
this.preloadingMediaUrls.clear();
|
|
6086
|
-
this.adPodAllUrls = [];
|
|
6087
5398
|
this.adRequestQueue = [];
|
|
6088
5399
|
this.successfulAdRequests = [];
|
|
6089
5400
|
}
|