stormcloud-video-player 0.5.26 → 0.6.1
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 +660 -554
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +20 -17
- package/lib/index.d.ts +20 -17
- package/lib/index.js +653 -547
- package/lib/index.js.map +1 -1
- package/lib/player/StormcloudVideoPlayer.cjs +647 -541
- package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/player/StormcloudVideoPlayer.d.cts +2 -2
- package/lib/players/HlsPlayer.cjs +648 -542
- package/lib/players/HlsPlayer.cjs.map +1 -1
- package/lib/players/HlsPlayer.d.cts +1 -1
- package/lib/players/index.cjs +648 -542
- package/lib/players/index.cjs.map +1 -1
- package/lib/sdk/{prebidAdLayer.cjs → vastAdLayer.cjs} +264 -139
- package/lib/sdk/vastAdLayer.cjs.map +1 -0
- package/lib/sdk/{prebidAdLayer.d.cts → vastAdLayer.d.cts} +11 -9
- package/lib/sdk/{prebid.cjs → vastManager.cjs} +205 -171
- package/lib/sdk/vastManager.cjs.map +1 -0
- package/lib/sdk/vastManager.d.cts +8 -0
- package/lib/{types-BA1uZjfj.d.cts → types-CwDRIvJm.d.cts} +9 -8
- package/lib/ui/StormcloudVideoPlayer.cjs +650 -544
- package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/ui/StormcloudVideoPlayer.d.cts +1 -1
- package/lib/utils/tracking.d.cts +1 -1
- package/package.json +1 -1
- package/lib/sdk/prebid.cjs.map +0 -1
- package/lib/sdk/prebid.d.cts +0 -8
- package/lib/sdk/prebidAdLayer.cjs.map +0 -1
|
@@ -386,362 +386,6 @@ module.exports = __toCommonJS(StormcloudVideoPlayer_exports);
|
|
|
386
386
|
var import_react = __toESM(require("react"), 1);
|
|
387
387
|
// src/player/StormcloudVideoPlayer.ts
|
|
388
388
|
var import_hls2 = __toESM(require("hls.js"), 1);
|
|
389
|
-
// src/sdk/prebid.ts
|
|
390
|
-
var DEFAULT_TIMEOUT_MS = 3e3;
|
|
391
|
-
var AUCTION_URL = "https://sspproxy.adstorm.co/openrtb2/auction/adstorm";
|
|
392
|
-
function createPrebidManager() {
|
|
393
|
-
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
394
|
-
var _options_debug;
|
|
395
|
-
var initialized = false;
|
|
396
|
-
var debug = (_options_debug = options.debug) !== null && _options_debug !== void 0 ? _options_debug : false;
|
|
397
|
-
function log() {
|
|
398
|
-
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
399
|
-
args[_key] = arguments[_key];
|
|
400
|
-
}
|
|
401
|
-
if (debug) {
|
|
402
|
-
var _console;
|
|
403
|
-
(_console = console).log.apply(_console, [
|
|
404
|
-
"[Prebid]"
|
|
405
|
-
].concat(_to_consumable_array(args)));
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
function warn() {
|
|
409
|
-
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
410
|
-
args[_key] = arguments[_key];
|
|
411
|
-
}
|
|
412
|
-
var _console;
|
|
413
|
-
(_console = console).warn.apply(_console, [
|
|
414
|
-
"[Prebid]"
|
|
415
|
-
].concat(_to_consumable_array(args)));
|
|
416
|
-
}
|
|
417
|
-
function parseResponse(data) {
|
|
418
|
-
var bids = [];
|
|
419
|
-
var seatbids = (data === null || data === void 0 ? void 0 : data.seatbid) || [];
|
|
420
|
-
var currency = (data === null || data === void 0 ? void 0 : data.cur) || "USD";
|
|
421
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
422
|
-
try {
|
|
423
|
-
for(var _iterator = seatbids[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
424
|
-
var seatbid = _step.value;
|
|
425
|
-
var seat = seatbid.seat || "unknown";
|
|
426
|
-
var bidArray = seatbid.bid || [];
|
|
427
|
-
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
428
|
-
try {
|
|
429
|
-
for(var _iterator1 = bidArray[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
430
|
-
var bid = _step1.value;
|
|
431
|
-
var _bid_ext_prebid_cache_vastXml, _bid_ext_prebid_cache, _bid_ext_prebid, _bid_ext;
|
|
432
|
-
var cacheUrl = (_bid_ext = bid.ext) === null || _bid_ext === void 0 ? void 0 : (_bid_ext_prebid = _bid_ext.prebid) === null || _bid_ext_prebid === void 0 ? void 0 : (_bid_ext_prebid_cache = _bid_ext_prebid.cache) === null || _bid_ext_prebid_cache === void 0 ? void 0 : (_bid_ext_prebid_cache_vastXml = _bid_ext_prebid_cache.vastXml) === null || _bid_ext_prebid_cache_vastXml === void 0 ? void 0 : _bid_ext_prebid_cache_vastXml.url;
|
|
433
|
-
var vastXml = bid.adm || void 0;
|
|
434
|
-
var bidResponse = {
|
|
435
|
-
bidder: seat,
|
|
436
|
-
cpm: bid.price || 0,
|
|
437
|
-
width: bid.w || 0,
|
|
438
|
-
height: bid.h || 0,
|
|
439
|
-
adId: bid.id || "",
|
|
440
|
-
impId: bid.impid || "",
|
|
441
|
-
creativeId: bid.crid || "",
|
|
442
|
-
currency: currency
|
|
443
|
-
};
|
|
444
|
-
if (cacheUrl) bidResponse.vastUrl = cacheUrl;
|
|
445
|
-
if (vastXml) bidResponse.vastXml = vastXml;
|
|
446
|
-
if (bid.adomain) bidResponse.adomain = bid.adomain;
|
|
447
|
-
bids.push(bidResponse);
|
|
448
|
-
}
|
|
449
|
-
} catch (err) {
|
|
450
|
-
_didIteratorError1 = true;
|
|
451
|
-
_iteratorError1 = err;
|
|
452
|
-
} finally{
|
|
453
|
-
try {
|
|
454
|
-
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
455
|
-
_iterator1.return();
|
|
456
|
-
}
|
|
457
|
-
} finally{
|
|
458
|
-
if (_didIteratorError1) {
|
|
459
|
-
throw _iteratorError1;
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
} catch (err) {
|
|
465
|
-
_didIteratorError = true;
|
|
466
|
-
_iteratorError = err;
|
|
467
|
-
} finally{
|
|
468
|
-
try {
|
|
469
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
470
|
-
_iterator.return();
|
|
471
|
-
}
|
|
472
|
-
} finally{
|
|
473
|
-
if (_didIteratorError) {
|
|
474
|
-
throw _iteratorError;
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
bids.sort(function(a, b) {
|
|
479
|
-
return b.cpm - a.cpm;
|
|
480
|
-
});
|
|
481
|
-
return bids;
|
|
482
|
-
}
|
|
483
|
-
function initialize() {
|
|
484
|
-
return _async_to_generator(function() {
|
|
485
|
-
return _ts_generator(this, function(_state) {
|
|
486
|
-
if (initialized) return [
|
|
487
|
-
2
|
|
488
|
-
];
|
|
489
|
-
initialized = true;
|
|
490
|
-
log("Initialized, auction URL:", AUCTION_URL);
|
|
491
|
-
return [
|
|
492
|
-
2
|
|
493
|
-
];
|
|
494
|
-
});
|
|
495
|
-
})();
|
|
496
|
-
}
|
|
497
|
-
function requestBids(context) {
|
|
498
|
-
return _async_to_generator(function() {
|
|
499
|
-
var timeout, controller, timeoutId, _data_ext, _data_ext1, fetchOptions, body, response, body1, data, bids, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, b, error;
|
|
500
|
-
return _ts_generator(this, function(_state) {
|
|
501
|
-
switch(_state.label){
|
|
502
|
-
case 0:
|
|
503
|
-
if (!initialized) {
|
|
504
|
-
throw new Error("Prebid not initialized. Call initialize() first.");
|
|
505
|
-
}
|
|
506
|
-
timeout = DEFAULT_TIMEOUT_MS;
|
|
507
|
-
log("Fetching auction response from:", AUCTION_URL);
|
|
508
|
-
controller = typeof AbortController !== "undefined" ? new AbortController() : null;
|
|
509
|
-
timeoutId = setTimeout(function() {
|
|
510
|
-
controller === null || controller === void 0 ? void 0 : controller.abort();
|
|
511
|
-
}, timeout + 2e3);
|
|
512
|
-
_state.label = 1;
|
|
513
|
-
case 1:
|
|
514
|
-
_state.trys.push([
|
|
515
|
-
1,
|
|
516
|
-
6,
|
|
517
|
-
,
|
|
518
|
-
7
|
|
519
|
-
]);
|
|
520
|
-
fetchOptions = {
|
|
521
|
-
method: "POST"
|
|
522
|
-
};
|
|
523
|
-
if (controller) {
|
|
524
|
-
fetchOptions.signal = controller.signal;
|
|
525
|
-
}
|
|
526
|
-
if ((context === null || context === void 0 ? void 0 : context.remainingBreakSec) != null) {
|
|
527
|
-
body = {
|
|
528
|
-
imp: [
|
|
529
|
-
{
|
|
530
|
-
video: {
|
|
531
|
-
maxduration: Math.floor(context.remainingBreakSec)
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
]
|
|
535
|
-
};
|
|
536
|
-
fetchOptions.body = JSON.stringify(body);
|
|
537
|
-
fetchOptions.headers = {
|
|
538
|
-
"Content-Type": "application/json"
|
|
539
|
-
};
|
|
540
|
-
log("Sending context to auction: maxduration=", Math.floor(context.remainingBreakSec));
|
|
541
|
-
}
|
|
542
|
-
return [
|
|
543
|
-
4,
|
|
544
|
-
fetch(AUCTION_URL, fetchOptions)
|
|
545
|
-
];
|
|
546
|
-
case 2:
|
|
547
|
-
response = _state.sent();
|
|
548
|
-
clearTimeout(timeoutId);
|
|
549
|
-
if (!!response.ok) return [
|
|
550
|
-
3,
|
|
551
|
-
4
|
|
552
|
-
];
|
|
553
|
-
return [
|
|
554
|
-
4,
|
|
555
|
-
response.text().catch(function() {
|
|
556
|
-
return "";
|
|
557
|
-
})
|
|
558
|
-
];
|
|
559
|
-
case 3:
|
|
560
|
-
body1 = _state.sent();
|
|
561
|
-
throw new Error("Prebid Server returned HTTP ".concat(response.status, ": ").concat(body1.slice(0, 200)));
|
|
562
|
-
case 4:
|
|
563
|
-
return [
|
|
564
|
-
4,
|
|
565
|
-
response.json()
|
|
566
|
-
];
|
|
567
|
-
case 5:
|
|
568
|
-
data = _state.sent();
|
|
569
|
-
if (debug && (data === null || data === void 0 ? void 0 : (_data_ext = data.ext) === null || _data_ext === void 0 ? void 0 : _data_ext.responsetimemillis)) {
|
|
570
|
-
log("Bidder response times:", data.ext.responsetimemillis);
|
|
571
|
-
}
|
|
572
|
-
if (debug && (data === null || data === void 0 ? void 0 : (_data_ext1 = data.ext) === null || _data_ext1 === void 0 ? void 0 : _data_ext1.errors)) {
|
|
573
|
-
warn("Auction errors:", data.ext.errors);
|
|
574
|
-
}
|
|
575
|
-
bids = parseResponse(data);
|
|
576
|
-
log("Received ".concat(bids.length, " bid(s)"));
|
|
577
|
-
if (debug) {
|
|
578
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
579
|
-
try {
|
|
580
|
-
for(_iterator = bids[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
581
|
-
b = _step.value;
|
|
582
|
-
log(" ".concat(b.bidder, ": $").concat(b.cpm.toFixed(2), " ").concat(b.currency, " ").concat(b.width, "x").concat(b.height) + (b.vastUrl ? " [cached VAST]" : "") + (b.vastXml && !b.vastUrl ? " [VAST XML]" : ""));
|
|
583
|
-
}
|
|
584
|
-
} catch (err) {
|
|
585
|
-
_didIteratorError = true;
|
|
586
|
-
_iteratorError = err;
|
|
587
|
-
} finally{
|
|
588
|
-
try {
|
|
589
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
590
|
-
_iterator.return();
|
|
591
|
-
}
|
|
592
|
-
} finally{
|
|
593
|
-
if (_didIteratorError) {
|
|
594
|
-
throw _iteratorError;
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
return [
|
|
600
|
-
2,
|
|
601
|
-
bids
|
|
602
|
-
];
|
|
603
|
-
case 6:
|
|
604
|
-
error = _state.sent();
|
|
605
|
-
clearTimeout(timeoutId);
|
|
606
|
-
if ((error === null || error === void 0 ? void 0 : error.name) === "AbortError") {
|
|
607
|
-
warn("Auction request timed out after ".concat(timeout + 2e3, "ms"));
|
|
608
|
-
return [
|
|
609
|
-
2,
|
|
610
|
-
[]
|
|
611
|
-
];
|
|
612
|
-
}
|
|
613
|
-
throw error;
|
|
614
|
-
case 7:
|
|
615
|
-
return [
|
|
616
|
-
2
|
|
617
|
-
];
|
|
618
|
-
}
|
|
619
|
-
});
|
|
620
|
-
})();
|
|
621
|
-
}
|
|
622
|
-
var REQUEST_BIDS_MAX_RETRIES = 3;
|
|
623
|
-
var REQUEST_BIDS_BACKOFF_MS = 1500;
|
|
624
|
-
function requestBidsUntilResponse(context) {
|
|
625
|
-
return _async_to_generator(function() {
|
|
626
|
-
var _loop, lastError, attempt, _ret;
|
|
627
|
-
return _ts_generator(this, function(_state) {
|
|
628
|
-
switch(_state.label){
|
|
629
|
-
case 0:
|
|
630
|
-
_loop = function(attempt) {
|
|
631
|
-
var bids, err, delay;
|
|
632
|
-
return _ts_generator(this, function(_state) {
|
|
633
|
-
switch(_state.label){
|
|
634
|
-
case 0:
|
|
635
|
-
_state.trys.push([
|
|
636
|
-
0,
|
|
637
|
-
2,
|
|
638
|
-
,
|
|
639
|
-
3
|
|
640
|
-
]);
|
|
641
|
-
return [
|
|
642
|
-
4,
|
|
643
|
-
requestBids(context)
|
|
644
|
-
];
|
|
645
|
-
case 1:
|
|
646
|
-
bids = _state.sent();
|
|
647
|
-
if (bids.length > 0) {
|
|
648
|
-
log("requestBidsUntilResponse: got ".concat(bids.length, " bid(s) on attempt ").concat(attempt));
|
|
649
|
-
return [
|
|
650
|
-
2,
|
|
651
|
-
{
|
|
652
|
-
v: bids
|
|
653
|
-
}
|
|
654
|
-
];
|
|
655
|
-
}
|
|
656
|
-
log("requestBidsUntilResponse: no bids on attempt ".concat(attempt, "/").concat(REQUEST_BIDS_MAX_RETRIES));
|
|
657
|
-
return [
|
|
658
|
-
3,
|
|
659
|
-
3
|
|
660
|
-
];
|
|
661
|
-
case 2:
|
|
662
|
-
err = _state.sent();
|
|
663
|
-
lastError = err;
|
|
664
|
-
warn("requestBidsUntilResponse: attempt ".concat(attempt, "/").concat(REQUEST_BIDS_MAX_RETRIES, " failed:"), err);
|
|
665
|
-
return [
|
|
666
|
-
3,
|
|
667
|
-
3
|
|
668
|
-
];
|
|
669
|
-
case 3:
|
|
670
|
-
if (!(attempt < REQUEST_BIDS_MAX_RETRIES)) return [
|
|
671
|
-
3,
|
|
672
|
-
5
|
|
673
|
-
];
|
|
674
|
-
delay = REQUEST_BIDS_BACKOFF_MS * attempt;
|
|
675
|
-
log("requestBidsUntilResponse: waiting ".concat(delay, "ms before retry"));
|
|
676
|
-
return [
|
|
677
|
-
4,
|
|
678
|
-
new Promise(function(resolve) {
|
|
679
|
-
return setTimeout(resolve, delay);
|
|
680
|
-
})
|
|
681
|
-
];
|
|
682
|
-
case 4:
|
|
683
|
-
_state.sent();
|
|
684
|
-
_state.label = 5;
|
|
685
|
-
case 5:
|
|
686
|
-
return [
|
|
687
|
-
2
|
|
688
|
-
];
|
|
689
|
-
}
|
|
690
|
-
});
|
|
691
|
-
};
|
|
692
|
-
if (!initialized) {
|
|
693
|
-
throw new Error("Prebid not initialized. Call initialize() first.");
|
|
694
|
-
}
|
|
695
|
-
attempt = 1;
|
|
696
|
-
_state.label = 1;
|
|
697
|
-
case 1:
|
|
698
|
-
if (!(attempt <= REQUEST_BIDS_MAX_RETRIES)) return [
|
|
699
|
-
3,
|
|
700
|
-
4
|
|
701
|
-
];
|
|
702
|
-
return [
|
|
703
|
-
5,
|
|
704
|
-
_ts_values(_loop(attempt))
|
|
705
|
-
];
|
|
706
|
-
case 2:
|
|
707
|
-
_ret = _state.sent();
|
|
708
|
-
if (_type_of(_ret) === "object") return [
|
|
709
|
-
2,
|
|
710
|
-
_ret.v
|
|
711
|
-
];
|
|
712
|
-
_state.label = 3;
|
|
713
|
-
case 3:
|
|
714
|
-
attempt++;
|
|
715
|
-
return [
|
|
716
|
-
3,
|
|
717
|
-
1
|
|
718
|
-
];
|
|
719
|
-
case 4:
|
|
720
|
-
if (_instanceof(lastError, Error)) {
|
|
721
|
-
throw lastError;
|
|
722
|
-
}
|
|
723
|
-
return [
|
|
724
|
-
2,
|
|
725
|
-
[]
|
|
726
|
-
];
|
|
727
|
-
}
|
|
728
|
-
});
|
|
729
|
-
})();
|
|
730
|
-
}
|
|
731
|
-
function destroy() {
|
|
732
|
-
initialized = false;
|
|
733
|
-
log("Destroyed");
|
|
734
|
-
}
|
|
735
|
-
return {
|
|
736
|
-
initialize: initialize,
|
|
737
|
-
requestBids: requestBids,
|
|
738
|
-
requestBidsUntilResponse: requestBidsUntilResponse,
|
|
739
|
-
destroy: destroy,
|
|
740
|
-
get isInitialized () {
|
|
741
|
-
return initialized;
|
|
742
|
-
}
|
|
743
|
-
};
|
|
744
|
-
}
|
|
745
389
|
// src/sdk/vastParser.ts
|
|
746
390
|
function isHlsType(type) {
|
|
747
391
|
return type === "application/x-mpegURL" || type.includes("m3u8");
|
|
@@ -1040,11 +684,271 @@ function fireTrackingPixels(urls, sessionId) {
|
|
|
1040
684
|
} catch (error) {
|
|
1041
685
|
console.warn("".concat(logPrefix, " Error firing tracking pixel:"), error);
|
|
1042
686
|
}
|
|
1043
|
-
});
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
// src/sdk/vastManager.ts
|
|
690
|
+
var VAST_TAG_URL = "https://pubads.g.doubleclick.net/gampad/ads?iu=/21821455290/Airy-Android&description_url=http%3A%2F%2Fairy.tv&tfcd=0&npa=0&sz=1x1%7C300x250%7C400x300%7C640x480&gdfp_req=1&unviewed_position_start=1&correlator=[placeholder]&vpos=preroll&output=vast&env=vp&vpmute=0&vpa=click";
|
|
691
|
+
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
692
|
+
var MAX_RETRIES = 3;
|
|
693
|
+
var RETRY_BACKOFF_MS = 1500;
|
|
694
|
+
function createVastManager() {
|
|
695
|
+
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
696
|
+
var _options_debug;
|
|
697
|
+
var initialized = false;
|
|
698
|
+
var debug = (_options_debug = options.debug) !== null && _options_debug !== void 0 ? _options_debug : false;
|
|
699
|
+
function log() {
|
|
700
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
701
|
+
args[_key] = arguments[_key];
|
|
702
|
+
}
|
|
703
|
+
if (debug) {
|
|
704
|
+
var _console;
|
|
705
|
+
(_console = console).log.apply(_console, [
|
|
706
|
+
"[VastManager]"
|
|
707
|
+
].concat(_to_consumable_array(args)));
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
function warn() {
|
|
711
|
+
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
|
712
|
+
args[_key] = arguments[_key];
|
|
713
|
+
}
|
|
714
|
+
var _console;
|
|
715
|
+
(_console = console).warn.apply(_console, [
|
|
716
|
+
"[VastManager]"
|
|
717
|
+
].concat(_to_consumable_array(args)));
|
|
718
|
+
}
|
|
719
|
+
function initialize() {
|
|
720
|
+
return _async_to_generator(function() {
|
|
721
|
+
return _ts_generator(this, function(_state) {
|
|
722
|
+
if (initialized) return [
|
|
723
|
+
2
|
|
724
|
+
];
|
|
725
|
+
initialized = true;
|
|
726
|
+
log("Initialized, VAST tag URL:", VAST_TAG_URL.split("?")[0]);
|
|
727
|
+
return [
|
|
728
|
+
2
|
|
729
|
+
];
|
|
730
|
+
});
|
|
731
|
+
})();
|
|
732
|
+
}
|
|
733
|
+
function requestBids(_context) {
|
|
734
|
+
return _async_to_generator(function() {
|
|
735
|
+
var correlator, url, controller, timeoutId, _ref, _ref1, _vastAd_mediaFiles_, _vastAd_mediaFiles_1, fetchOptions, response, vastXml, vastAd, bid, error;
|
|
736
|
+
return _ts_generator(this, function(_state) {
|
|
737
|
+
switch(_state.label){
|
|
738
|
+
case 0:
|
|
739
|
+
if (!initialized) {
|
|
740
|
+
throw new Error("VastManager not initialized. Call initialize() first.");
|
|
741
|
+
}
|
|
742
|
+
correlator = Math.floor(Math.random() * 1e12).toString();
|
|
743
|
+
url = VAST_TAG_URL.replace("[placeholder]", correlator);
|
|
744
|
+
log("Fetching VAST tag, correlator:", correlator);
|
|
745
|
+
controller = typeof AbortController !== "undefined" ? new AbortController() : null;
|
|
746
|
+
timeoutId = setTimeout(function() {
|
|
747
|
+
return controller === null || controller === void 0 ? void 0 : controller.abort();
|
|
748
|
+
}, DEFAULT_TIMEOUT_MS);
|
|
749
|
+
_state.label = 1;
|
|
750
|
+
case 1:
|
|
751
|
+
_state.trys.push([
|
|
752
|
+
1,
|
|
753
|
+
4,
|
|
754
|
+
,
|
|
755
|
+
5
|
|
756
|
+
]);
|
|
757
|
+
fetchOptions = {
|
|
758
|
+
method: "GET",
|
|
759
|
+
mode: "cors",
|
|
760
|
+
credentials: "omit",
|
|
761
|
+
headers: {
|
|
762
|
+
Accept: "application/xml, text/xml, */*"
|
|
763
|
+
},
|
|
764
|
+
referrerPolicy: "no-referrer-when-downgrade"
|
|
765
|
+
};
|
|
766
|
+
if (controller) fetchOptions.signal = controller.signal;
|
|
767
|
+
return [
|
|
768
|
+
4,
|
|
769
|
+
fetch(url, fetchOptions)
|
|
770
|
+
];
|
|
771
|
+
case 2:
|
|
772
|
+
response = _state.sent();
|
|
773
|
+
clearTimeout(timeoutId);
|
|
774
|
+
if (!response.ok) {
|
|
775
|
+
throw new Error("VAST request returned HTTP ".concat(response.status));
|
|
776
|
+
}
|
|
777
|
+
return [
|
|
778
|
+
4,
|
|
779
|
+
response.text()
|
|
780
|
+
];
|
|
781
|
+
case 3:
|
|
782
|
+
vastXml = _state.sent();
|
|
783
|
+
log("VAST XML received, length:", vastXml.length);
|
|
784
|
+
vastAd = parseVastXml(vastXml, "mp4-first", "[VastManager]");
|
|
785
|
+
if (!vastAd) {
|
|
786
|
+
log("VAST parsed but no usable ad found");
|
|
787
|
+
return [
|
|
788
|
+
2,
|
|
789
|
+
[]
|
|
790
|
+
];
|
|
791
|
+
}
|
|
792
|
+
log("Ad parsed: id=".concat(vastAd.id, ", duration=").concat(vastAd.duration, "s, mediaFiles=").concat(vastAd.mediaFiles.length));
|
|
793
|
+
bid = {
|
|
794
|
+
bidder: "vast-direct",
|
|
795
|
+
cpm: 0,
|
|
796
|
+
vastXml: vastXml,
|
|
797
|
+
width: (_ref = (_vastAd_mediaFiles_ = vastAd.mediaFiles[0]) === null || _vastAd_mediaFiles_ === void 0 ? void 0 : _vastAd_mediaFiles_.width) !== null && _ref !== void 0 ? _ref : 0,
|
|
798
|
+
height: (_ref1 = (_vastAd_mediaFiles_1 = vastAd.mediaFiles[0]) === null || _vastAd_mediaFiles_1 === void 0 ? void 0 : _vastAd_mediaFiles_1.height) !== null && _ref1 !== void 0 ? _ref1 : 0,
|
|
799
|
+
adId: vastAd.id,
|
|
800
|
+
impId: correlator,
|
|
801
|
+
creativeId: vastAd.id,
|
|
802
|
+
currency: "USD",
|
|
803
|
+
durationSec: vastAd.duration
|
|
804
|
+
};
|
|
805
|
+
return [
|
|
806
|
+
2,
|
|
807
|
+
[
|
|
808
|
+
bid
|
|
809
|
+
]
|
|
810
|
+
];
|
|
811
|
+
case 4:
|
|
812
|
+
error = _state.sent();
|
|
813
|
+
clearTimeout(timeoutId);
|
|
814
|
+
if ((error === null || error === void 0 ? void 0 : error.name) === "AbortError") {
|
|
815
|
+
warn("VAST request timed out after ".concat(DEFAULT_TIMEOUT_MS, "ms"));
|
|
816
|
+
return [
|
|
817
|
+
2,
|
|
818
|
+
[]
|
|
819
|
+
];
|
|
820
|
+
}
|
|
821
|
+
throw error;
|
|
822
|
+
case 5:
|
|
823
|
+
return [
|
|
824
|
+
2
|
|
825
|
+
];
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
})();
|
|
829
|
+
}
|
|
830
|
+
function requestBidsUntilResponse(context) {
|
|
831
|
+
return _async_to_generator(function() {
|
|
832
|
+
var _loop, lastError, attempt, _ret;
|
|
833
|
+
return _ts_generator(this, function(_state) {
|
|
834
|
+
switch(_state.label){
|
|
835
|
+
case 0:
|
|
836
|
+
_loop = function(attempt) {
|
|
837
|
+
var bids, err, delay;
|
|
838
|
+
return _ts_generator(this, function(_state) {
|
|
839
|
+
switch(_state.label){
|
|
840
|
+
case 0:
|
|
841
|
+
_state.trys.push([
|
|
842
|
+
0,
|
|
843
|
+
2,
|
|
844
|
+
,
|
|
845
|
+
3
|
|
846
|
+
]);
|
|
847
|
+
return [
|
|
848
|
+
4,
|
|
849
|
+
requestBids(context)
|
|
850
|
+
];
|
|
851
|
+
case 1:
|
|
852
|
+
bids = _state.sent();
|
|
853
|
+
if (bids.length > 0) {
|
|
854
|
+
log("requestBidsUntilResponse: got ".concat(bids.length, " ad(s) on attempt ").concat(attempt));
|
|
855
|
+
return [
|
|
856
|
+
2,
|
|
857
|
+
{
|
|
858
|
+
v: bids
|
|
859
|
+
}
|
|
860
|
+
];
|
|
861
|
+
}
|
|
862
|
+
log("requestBidsUntilResponse: no ads on attempt ".concat(attempt, "/").concat(MAX_RETRIES));
|
|
863
|
+
return [
|
|
864
|
+
3,
|
|
865
|
+
3
|
|
866
|
+
];
|
|
867
|
+
case 2:
|
|
868
|
+
err = _state.sent();
|
|
869
|
+
lastError = err;
|
|
870
|
+
warn("requestBidsUntilResponse: attempt ".concat(attempt, "/").concat(MAX_RETRIES, " failed:"), err);
|
|
871
|
+
return [
|
|
872
|
+
3,
|
|
873
|
+
3
|
|
874
|
+
];
|
|
875
|
+
case 3:
|
|
876
|
+
if (!(attempt < MAX_RETRIES)) return [
|
|
877
|
+
3,
|
|
878
|
+
5
|
|
879
|
+
];
|
|
880
|
+
delay = RETRY_BACKOFF_MS * attempt;
|
|
881
|
+
log("requestBidsUntilResponse: waiting ".concat(delay, "ms before retry"));
|
|
882
|
+
return [
|
|
883
|
+
4,
|
|
884
|
+
new Promise(function(resolve) {
|
|
885
|
+
return setTimeout(resolve, delay);
|
|
886
|
+
})
|
|
887
|
+
];
|
|
888
|
+
case 4:
|
|
889
|
+
_state.sent();
|
|
890
|
+
_state.label = 5;
|
|
891
|
+
case 5:
|
|
892
|
+
return [
|
|
893
|
+
2
|
|
894
|
+
];
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
};
|
|
898
|
+
if (!initialized) {
|
|
899
|
+
throw new Error("VastManager not initialized. Call initialize() first.");
|
|
900
|
+
}
|
|
901
|
+
attempt = 1;
|
|
902
|
+
_state.label = 1;
|
|
903
|
+
case 1:
|
|
904
|
+
if (!(attempt <= MAX_RETRIES)) return [
|
|
905
|
+
3,
|
|
906
|
+
4
|
|
907
|
+
];
|
|
908
|
+
return [
|
|
909
|
+
5,
|
|
910
|
+
_ts_values(_loop(attempt))
|
|
911
|
+
];
|
|
912
|
+
case 2:
|
|
913
|
+
_ret = _state.sent();
|
|
914
|
+
if (_type_of(_ret) === "object") return [
|
|
915
|
+
2,
|
|
916
|
+
_ret.v
|
|
917
|
+
];
|
|
918
|
+
_state.label = 3;
|
|
919
|
+
case 3:
|
|
920
|
+
attempt++;
|
|
921
|
+
return [
|
|
922
|
+
3,
|
|
923
|
+
1
|
|
924
|
+
];
|
|
925
|
+
case 4:
|
|
926
|
+
if (_instanceof(lastError, Error)) throw lastError;
|
|
927
|
+
return [
|
|
928
|
+
2,
|
|
929
|
+
[]
|
|
930
|
+
];
|
|
931
|
+
}
|
|
932
|
+
});
|
|
933
|
+
})();
|
|
934
|
+
}
|
|
935
|
+
function destroy() {
|
|
936
|
+
initialized = false;
|
|
937
|
+
log("Destroyed");
|
|
938
|
+
}
|
|
939
|
+
return {
|
|
940
|
+
initialize: initialize,
|
|
941
|
+
requestBids: requestBids,
|
|
942
|
+
requestBidsUntilResponse: requestBidsUntilResponse,
|
|
943
|
+
destroy: destroy,
|
|
944
|
+
get isInitialized () {
|
|
945
|
+
return initialized;
|
|
946
|
+
}
|
|
947
|
+
};
|
|
1044
948
|
}
|
|
1045
|
-
// src/sdk/
|
|
949
|
+
// src/sdk/vastAdLayer.ts
|
|
1046
950
|
var import_hls = __toESM(require("hls.js"), 1);
|
|
1047
|
-
var LOG = "[
|
|
951
|
+
var LOG = "[VastAdLayer]";
|
|
1048
952
|
function resolveBidToVastAd(winner, logPrefix) {
|
|
1049
953
|
if (winner.vastXml) {
|
|
1050
954
|
var ad = parseVastXml(winner.vastXml, "mp4-first", logPrefix);
|
|
@@ -1055,15 +959,17 @@ function resolveBidToVastAd(winner, logPrefix) {
|
|
|
1055
959
|
}
|
|
1056
960
|
return Promise.resolve(null);
|
|
1057
961
|
}
|
|
1058
|
-
function
|
|
1059
|
-
var _ref, _ref1;
|
|
962
|
+
function createVastAdLayer(contentVideo, options) {
|
|
963
|
+
var _ref, _ref1, _ref2, _ref3;
|
|
1060
964
|
var adPlaying = false;
|
|
1061
965
|
var originalMutedState = false;
|
|
1062
966
|
var originalVolume = Math.max(0, Math.min(1, contentVideo.volume || 1));
|
|
1063
967
|
var listeners = /* @__PURE__ */ new Map();
|
|
1064
968
|
var mainHlsInstance = options === null || options === void 0 ? void 0 : options.mainHlsInstance;
|
|
1065
969
|
var continueLiveStreamDuringAds = (_ref = options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds) !== null && _ref !== void 0 ? _ref : false;
|
|
1066
|
-
var
|
|
970
|
+
var smartTVMode = (_ref1 = options === null || options === void 0 ? void 0 : options.smartTVMode) !== null && _ref1 !== void 0 ? _ref1 : false;
|
|
971
|
+
var singleElementMode = (_ref2 = options === null || options === void 0 ? void 0 : options.singleElementMode) !== null && _ref2 !== void 0 ? _ref2 : false;
|
|
972
|
+
var debug = (_ref3 = options === null || options === void 0 ? void 0 : options.debug) !== null && _ref3 !== void 0 ? _ref3 : false;
|
|
1067
973
|
var adVideoElement;
|
|
1068
974
|
var adHls;
|
|
1069
975
|
var adContainerEl;
|
|
@@ -1072,6 +978,7 @@ function createPrebidAdLayer(contentVideo, options) {
|
|
|
1072
978
|
var destroyed = false;
|
|
1073
979
|
var tornDown = false;
|
|
1074
980
|
var trackingFired = createEmptyTrackingState();
|
|
981
|
+
var currentAdEventHandlers;
|
|
1075
982
|
var preloadSlots = /* @__PURE__ */ new Map();
|
|
1076
983
|
function emit(event, payload) {
|
|
1077
984
|
var set = listeners.get(event);
|
|
@@ -1174,63 +1081,86 @@ function createPrebidAdLayer(contentVideo, options) {
|
|
|
1174
1081
|
video.volume = 1;
|
|
1175
1082
|
return video;
|
|
1176
1083
|
}
|
|
1084
|
+
function removeAdEventListeners() {
|
|
1085
|
+
if (!currentAdEventHandlers || !adVideoElement) return;
|
|
1086
|
+
var el = adVideoElement;
|
|
1087
|
+
el.removeEventListener("timeupdate", currentAdEventHandlers.timeupdate);
|
|
1088
|
+
el.removeEventListener("playing", currentAdEventHandlers.playing);
|
|
1089
|
+
el.removeEventListener("ended", currentAdEventHandlers.ended);
|
|
1090
|
+
el.removeEventListener("error", currentAdEventHandlers.error);
|
|
1091
|
+
el.removeEventListener("volumechange", currentAdEventHandlers.volumechange);
|
|
1092
|
+
el.removeEventListener("pause", currentAdEventHandlers.pause);
|
|
1093
|
+
el.removeEventListener("play", currentAdEventHandlers.play);
|
|
1094
|
+
currentAdEventHandlers = void 0;
|
|
1095
|
+
}
|
|
1177
1096
|
function setupAdEventListeners() {
|
|
1178
1097
|
if (!adVideoElement) return;
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1098
|
+
removeAdEventListeners();
|
|
1099
|
+
var handlers = {
|
|
1100
|
+
timeupdate: function timeupdate() {
|
|
1101
|
+
var ad = currentAd;
|
|
1102
|
+
if (!ad || !adVideoElement) return;
|
|
1103
|
+
var progress = adVideoElement.currentTime / ad.duration;
|
|
1104
|
+
if (progress >= 0.25 && !trackingFired.firstQuartile) {
|
|
1105
|
+
trackingFired.firstQuartile = true;
|
|
1106
|
+
fireTrackingPixels2(ad.trackingUrls.firstQuartile);
|
|
1107
|
+
}
|
|
1108
|
+
if (progress >= 0.5 && !trackingFired.midpoint) {
|
|
1109
|
+
trackingFired.midpoint = true;
|
|
1110
|
+
fireTrackingPixels2(ad.trackingUrls.midpoint);
|
|
1111
|
+
}
|
|
1112
|
+
if (progress >= 0.75 && !trackingFired.thirdQuartile) {
|
|
1113
|
+
trackingFired.thirdQuartile = true;
|
|
1114
|
+
fireTrackingPixels2(ad.trackingUrls.thirdQuartile);
|
|
1115
|
+
}
|
|
1116
|
+
},
|
|
1117
|
+
playing: function playing() {
|
|
1118
|
+
var ad = currentAd;
|
|
1119
|
+
if (!ad || trackingFired.start) return;
|
|
1120
|
+
trackingFired.start = true;
|
|
1121
|
+
fireTrackingPixels2(ad.trackingUrls.start);
|
|
1122
|
+
if (debug) console.log("".concat(LOG, " Ad started playing"));
|
|
1123
|
+
},
|
|
1124
|
+
ended: function ended() {
|
|
1125
|
+
if (tornDown || !currentAd || trackingFired.complete) return;
|
|
1126
|
+
trackingFired.complete = true;
|
|
1127
|
+
fireTrackingPixels2(currentAd.trackingUrls.complete);
|
|
1128
|
+
if (debug) console.log("".concat(LOG, " Ad completed"));
|
|
1129
|
+
handleAdComplete();
|
|
1130
|
+
},
|
|
1131
|
+
error: function error(e) {
|
|
1132
|
+
if (tornDown) return;
|
|
1133
|
+
console.error("".concat(LOG, " Ad video error:"), e);
|
|
1134
|
+
if (currentAd) fireTrackingPixels2(currentAd.trackingUrls.error);
|
|
1135
|
+
handleAdError();
|
|
1136
|
+
},
|
|
1137
|
+
volumechange: function volumechange() {
|
|
1138
|
+
if (!currentAd || !adVideoElement) return;
|
|
1139
|
+
if (adVideoElement.muted) {
|
|
1140
|
+
fireTrackingPixels2(currentAd.trackingUrls.mute);
|
|
1141
|
+
} else {
|
|
1142
|
+
fireTrackingPixels2(currentAd.trackingUrls.unmute);
|
|
1143
|
+
}
|
|
1144
|
+
},
|
|
1145
|
+
pause: function pause() {
|
|
1146
|
+
if (currentAd && adVideoElement && !adVideoElement.ended) {
|
|
1147
|
+
fireTrackingPixels2(currentAd.trackingUrls.pause);
|
|
1148
|
+
}
|
|
1149
|
+
},
|
|
1150
|
+
play: function play() {
|
|
1151
|
+
if (currentAd && adVideoElement && adVideoElement.currentTime > 0) {
|
|
1152
|
+
fireTrackingPixels2(currentAd.trackingUrls.resume);
|
|
1153
|
+
}
|
|
1232
1154
|
}
|
|
1233
|
-
}
|
|
1155
|
+
};
|
|
1156
|
+
adVideoElement.addEventListener("timeupdate", handlers.timeupdate);
|
|
1157
|
+
adVideoElement.addEventListener("playing", handlers.playing);
|
|
1158
|
+
adVideoElement.addEventListener("ended", handlers.ended);
|
|
1159
|
+
adVideoElement.addEventListener("error", handlers.error);
|
|
1160
|
+
adVideoElement.addEventListener("volumechange", handlers.volumechange);
|
|
1161
|
+
adVideoElement.addEventListener("pause", handlers.pause);
|
|
1162
|
+
adVideoElement.addEventListener("play", handlers.play);
|
|
1163
|
+
currentAdEventHandlers = handlers;
|
|
1234
1164
|
}
|
|
1235
1165
|
function setAdPlayingFlag(isPlaying) {
|
|
1236
1166
|
if (isPlaying) {
|
|
@@ -1253,6 +1183,7 @@ function createPrebidAdLayer(contentVideo, options) {
|
|
|
1253
1183
|
}
|
|
1254
1184
|
function handleAdError() {
|
|
1255
1185
|
if (tornDown) return;
|
|
1186
|
+
if (!adPlaying) return;
|
|
1256
1187
|
if (debug) console.log("".concat(LOG, " Handling ad error"));
|
|
1257
1188
|
adPlaying = false;
|
|
1258
1189
|
setAdPlayingFlag(false);
|
|
@@ -1263,14 +1194,19 @@ function createPrebidAdLayer(contentVideo, options) {
|
|
|
1263
1194
|
emit("ad_error");
|
|
1264
1195
|
}
|
|
1265
1196
|
function teardownCurrentPlayback() {
|
|
1197
|
+
removeAdEventListeners();
|
|
1266
1198
|
if (adHls) {
|
|
1267
1199
|
adHls.destroy();
|
|
1268
1200
|
adHls = void 0;
|
|
1269
1201
|
}
|
|
1270
1202
|
if (adVideoElement) {
|
|
1271
|
-
adVideoElement
|
|
1272
|
-
|
|
1273
|
-
|
|
1203
|
+
if (singleElementMode && adVideoElement === contentVideo) {
|
|
1204
|
+
contentVideo.pause();
|
|
1205
|
+
} else {
|
|
1206
|
+
adVideoElement.pause();
|
|
1207
|
+
adVideoElement.removeAttribute("src");
|
|
1208
|
+
adVideoElement.load();
|
|
1209
|
+
}
|
|
1274
1210
|
}
|
|
1275
1211
|
}
|
|
1276
1212
|
function startNativePlayback(mediaFile) {
|
|
@@ -1303,8 +1239,17 @@ function createPrebidAdLayer(contentVideo, options) {
|
|
|
1303
1239
|
handleAdError();
|
|
1304
1240
|
});
|
|
1305
1241
|
});
|
|
1242
|
+
var nonFatalNetworkErrors = 0;
|
|
1306
1243
|
adHls.on(import_hls.default.Events.ERROR, function(_event, data) {
|
|
1307
|
-
if (data.fatal)
|
|
1244
|
+
if (data.fatal) {
|
|
1245
|
+
handleAdError();
|
|
1246
|
+
} else if (data.type === import_hls.default.ErrorTypes.NETWORK_ERROR) {
|
|
1247
|
+
nonFatalNetworkErrors++;
|
|
1248
|
+
if (nonFatalNetworkErrors >= 3) {
|
|
1249
|
+
if (debug) console.warn("".concat(LOG, " Too many non-fatal HLS network errors (").concat(nonFatalNetworkErrors, "), treating as fatal"));
|
|
1250
|
+
handleAdError();
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1308
1253
|
});
|
|
1309
1254
|
} else if (adVideoElement.canPlayType("application/vnd.apple.mpegurl")) {
|
|
1310
1255
|
adVideoElement.src = mediaFile.url;
|
|
@@ -1327,7 +1272,7 @@ function createPrebidAdLayer(contentVideo, options) {
|
|
|
1327
1272
|
}
|
|
1328
1273
|
function playAd(bids) {
|
|
1329
1274
|
return _async_to_generator(function() {
|
|
1330
|
-
var winner, ad, _contentVideo_parentElement, container,
|
|
1275
|
+
var winner, ad, contentVolume, _contentVideo_parentElement, container, adVolume, mediaFile;
|
|
1331
1276
|
return _ts_generator(this, function(_state) {
|
|
1332
1277
|
switch(_state.label){
|
|
1333
1278
|
case 0:
|
|
@@ -1369,32 +1314,40 @@ function createPrebidAdLayer(contentVideo, options) {
|
|
|
1369
1314
|
trackingFired = _object_spread({}, createEmptyTrackingState());
|
|
1370
1315
|
fireTrackingPixels2(ad.trackingUrls.impression);
|
|
1371
1316
|
trackingFired.impression = true;
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
container.style.bottom = "0";
|
|
1380
|
-
container.style.display = "none";
|
|
1381
|
-
container.style.alignItems = "center";
|
|
1382
|
-
container.style.justifyContent = "center";
|
|
1383
|
-
container.style.pointerEvents = "none";
|
|
1384
|
-
container.style.zIndex = "10";
|
|
1385
|
-
container.style.backgroundColor = "#000";
|
|
1386
|
-
(_contentVideo_parentElement = contentVideo.parentElement) === null || _contentVideo_parentElement === void 0 ? void 0 : _contentVideo_parentElement.appendChild(container);
|
|
1387
|
-
adContainerEl = container;
|
|
1388
|
-
}
|
|
1389
|
-
if (!adVideoElement) {
|
|
1390
|
-
adVideoElement = createAdVideoElement();
|
|
1391
|
-
adContainerEl.appendChild(adVideoElement);
|
|
1317
|
+
contentVolume = contentVideo.volume;
|
|
1318
|
+
originalVolume = Math.max(0, Math.min(1, contentVolume || originalVolume));
|
|
1319
|
+
if (singleElementMode) {
|
|
1320
|
+
mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
|
|
1321
|
+
teardownCurrentPlayback();
|
|
1322
|
+
adVideoElement = contentVideo;
|
|
1323
|
+
adHls = void 0;
|
|
1392
1324
|
setupAdEventListeners();
|
|
1393
1325
|
} else {
|
|
1394
|
-
|
|
1326
|
+
if (!adContainerEl) {
|
|
1327
|
+
;
|
|
1328
|
+
container = document.createElement("div");
|
|
1329
|
+
container.style.position = "absolute";
|
|
1330
|
+
container.style.left = "0";
|
|
1331
|
+
container.style.top = "0";
|
|
1332
|
+
container.style.right = "0";
|
|
1333
|
+
container.style.bottom = "0";
|
|
1334
|
+
container.style.display = "none";
|
|
1335
|
+
container.style.alignItems = "center";
|
|
1336
|
+
container.style.justifyContent = "center";
|
|
1337
|
+
container.style.pointerEvents = "none";
|
|
1338
|
+
container.style.zIndex = "10";
|
|
1339
|
+
container.style.backgroundColor = "#000";
|
|
1340
|
+
(_contentVideo_parentElement = contentVideo.parentElement) === null || _contentVideo_parentElement === void 0 ? void 0 : _contentVideo_parentElement.appendChild(container);
|
|
1341
|
+
adContainerEl = container;
|
|
1342
|
+
}
|
|
1343
|
+
if (!adVideoElement) {
|
|
1344
|
+
adVideoElement = createAdVideoElement();
|
|
1345
|
+
adContainerEl.appendChild(adVideoElement);
|
|
1346
|
+
setupAdEventListeners();
|
|
1347
|
+
} else {
|
|
1348
|
+
teardownCurrentPlayback();
|
|
1349
|
+
}
|
|
1395
1350
|
}
|
|
1396
|
-
contentVolume = contentVideo.volume;
|
|
1397
|
-
originalVolume = Math.max(0, Math.min(1, contentVolume || originalVolume));
|
|
1398
1351
|
if (!continueLiveStreamDuringAds) {
|
|
1399
1352
|
contentVideo.pause();
|
|
1400
1353
|
}
|
|
@@ -1405,7 +1358,7 @@ function createPrebidAdLayer(contentVideo, options) {
|
|
|
1405
1358
|
adVolume = originalMutedState ? 1 : originalVolume;
|
|
1406
1359
|
adVideoElement.volume = Math.max(0, Math.min(1, adVolume));
|
|
1407
1360
|
adVideoElement.muted = false;
|
|
1408
|
-
if (adContainerEl) {
|
|
1361
|
+
if (!singleElementMode && adContainerEl) {
|
|
1409
1362
|
adContainerEl.style.display = "flex";
|
|
1410
1363
|
adContainerEl.style.pointerEvents = "auto";
|
|
1411
1364
|
}
|
|
@@ -1442,7 +1395,7 @@ function createPrebidAdLayer(contentVideo, options) {
|
|
|
1442
1395
|
}
|
|
1443
1396
|
function preloadAd(bids, token) {
|
|
1444
1397
|
return _async_to_generator(function() {
|
|
1445
|
-
var winner, ad, mediaFile, videoEl, container, hls,
|
|
1398
|
+
var winner, ad, mediaFile, slot, videoEl, container, hls, slot1, slot2;
|
|
1446
1399
|
return _ts_generator(this, function(_state) {
|
|
1447
1400
|
switch(_state.label){
|
|
1448
1401
|
case 0:
|
|
@@ -1467,6 +1420,20 @@ function createPrebidAdLayer(contentVideo, options) {
|
|
|
1467
1420
|
if (!mediaFile) return [
|
|
1468
1421
|
2
|
|
1469
1422
|
];
|
|
1423
|
+
if (smartTVMode || singleElementMode) {
|
|
1424
|
+
slot = {
|
|
1425
|
+
bids: bids,
|
|
1426
|
+
ad: ad,
|
|
1427
|
+
mediaFile: mediaFile,
|
|
1428
|
+
videoEl: null,
|
|
1429
|
+
ready: true
|
|
1430
|
+
};
|
|
1431
|
+
preloadSlots.set(token, slot);
|
|
1432
|
+
if (debug) console.log("".concat(LOG, " [preload] Metadata-only preload (smartTV/singleElement), token=").concat(token, ", url=").concat(mediaFile.url));
|
|
1433
|
+
return [
|
|
1434
|
+
2
|
|
1435
|
+
];
|
|
1436
|
+
}
|
|
1470
1437
|
videoEl = createAdVideoElement();
|
|
1471
1438
|
videoEl.style.visibility = "hidden";
|
|
1472
1439
|
videoEl.style.pointerEvents = "none";
|
|
@@ -1480,7 +1447,7 @@ function createPrebidAdLayer(contentVideo, options) {
|
|
|
1480
1447
|
});
|
|
1481
1448
|
hls.loadSource(mediaFile.url);
|
|
1482
1449
|
hls.attachMedia(videoEl);
|
|
1483
|
-
|
|
1450
|
+
slot1 = {
|
|
1484
1451
|
bids: bids,
|
|
1485
1452
|
ad: ad,
|
|
1486
1453
|
mediaFile: mediaFile,
|
|
@@ -1488,7 +1455,7 @@ function createPrebidAdLayer(contentVideo, options) {
|
|
|
1488
1455
|
hlsInstance: hls,
|
|
1489
1456
|
ready: false
|
|
1490
1457
|
};
|
|
1491
|
-
preloadSlots.set(token,
|
|
1458
|
+
preloadSlots.set(token, slot1);
|
|
1492
1459
|
hls.on(import_hls.default.Events.MANIFEST_PARSED, function() {
|
|
1493
1460
|
var s = preloadSlots.get(token);
|
|
1494
1461
|
if (s) s.ready = true;
|
|
@@ -1505,14 +1472,14 @@ function createPrebidAdLayer(contentVideo, options) {
|
|
|
1505
1472
|
} else {
|
|
1506
1473
|
videoEl.src = mediaFile.url;
|
|
1507
1474
|
videoEl.load();
|
|
1508
|
-
|
|
1475
|
+
slot2 = {
|
|
1509
1476
|
bids: bids,
|
|
1510
1477
|
ad: ad,
|
|
1511
1478
|
mediaFile: mediaFile,
|
|
1512
1479
|
videoEl: videoEl,
|
|
1513
1480
|
ready: false
|
|
1514
1481
|
};
|
|
1515
|
-
preloadSlots.set(token,
|
|
1482
|
+
preloadSlots.set(token, slot2);
|
|
1516
1483
|
videoEl.addEventListener("canplay", function() {
|
|
1517
1484
|
var s = preloadSlots.get(token);
|
|
1518
1485
|
if (s) s.ready = true;
|
|
@@ -1531,7 +1498,7 @@ function createPrebidAdLayer(contentVideo, options) {
|
|
|
1531
1498
|
}
|
|
1532
1499
|
function playPreloaded(token) {
|
|
1533
1500
|
return _async_to_generator(function() {
|
|
1534
|
-
var slot, contentVolume, adVolume, container;
|
|
1501
|
+
var slot, contentVolume, adVolume2, videoEl, container2, adVolume21, adVolume, container;
|
|
1535
1502
|
return _ts_generator(this, function(_state) {
|
|
1536
1503
|
if (destroyed) return [
|
|
1537
1504
|
2,
|
|
@@ -1546,6 +1513,68 @@ function createPrebidAdLayer(contentVideo, options) {
|
|
|
1546
1513
|
}
|
|
1547
1514
|
preloadSlots.delete(token);
|
|
1548
1515
|
if (debug) console.log("".concat(LOG, " [preload] Playing preloaded ad, token=").concat(token, ", ready=").concat(slot.ready));
|
|
1516
|
+
contentVolume = contentVideo.volume;
|
|
1517
|
+
originalVolume = Math.max(0, Math.min(1, contentVolume || originalVolume));
|
|
1518
|
+
sessionId = generateSessionId();
|
|
1519
|
+
currentAd = slot.ad;
|
|
1520
|
+
trackingFired = _object_spread({}, createEmptyTrackingState());
|
|
1521
|
+
fireTrackingPixels2(slot.ad.trackingUrls.impression);
|
|
1522
|
+
trackingFired.impression = true;
|
|
1523
|
+
if (singleElementMode) {
|
|
1524
|
+
mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
|
|
1525
|
+
teardownCurrentPlayback();
|
|
1526
|
+
adVideoElement = contentVideo;
|
|
1527
|
+
adHls = void 0;
|
|
1528
|
+
setupAdEventListeners();
|
|
1529
|
+
if (!continueLiveStreamDuringAds) {
|
|
1530
|
+
contentVideo.pause();
|
|
1531
|
+
}
|
|
1532
|
+
contentVideo.muted = true;
|
|
1533
|
+
contentVideo.volume = 0;
|
|
1534
|
+
adPlaying = true;
|
|
1535
|
+
setAdPlayingFlag(true);
|
|
1536
|
+
adVolume2 = originalMutedState ? 1 : originalVolume;
|
|
1537
|
+
contentVideo.volume = Math.max(0, Math.min(1, adVolume2));
|
|
1538
|
+
contentVideo.muted = false;
|
|
1539
|
+
emit("content_pause");
|
|
1540
|
+
if (debug) console.log("".concat(LOG, " [preload] singleElementMode: attaching ad to contentVideo, url=").concat(slot.mediaFile.url));
|
|
1541
|
+
startPlayback(slot.mediaFile);
|
|
1542
|
+
return [
|
|
1543
|
+
2
|
|
1544
|
+
];
|
|
1545
|
+
}
|
|
1546
|
+
if (smartTVMode && !slot.videoEl) {
|
|
1547
|
+
teardownCurrentPlayback();
|
|
1548
|
+
if (adVideoElement) {
|
|
1549
|
+
adVideoElement.remove();
|
|
1550
|
+
adVideoElement = void 0;
|
|
1551
|
+
}
|
|
1552
|
+
videoEl = createAdVideoElement();
|
|
1553
|
+
videoEl.style.visibility = "visible";
|
|
1554
|
+
videoEl.style.pointerEvents = "none";
|
|
1555
|
+
container2 = ensureAdContainer();
|
|
1556
|
+
container2.appendChild(videoEl);
|
|
1557
|
+
adVideoElement = videoEl;
|
|
1558
|
+
setupAdEventListeners();
|
|
1559
|
+
if (!continueLiveStreamDuringAds) {
|
|
1560
|
+
contentVideo.pause();
|
|
1561
|
+
}
|
|
1562
|
+
contentVideo.muted = true;
|
|
1563
|
+
contentVideo.volume = 0;
|
|
1564
|
+
adPlaying = true;
|
|
1565
|
+
setAdPlayingFlag(true);
|
|
1566
|
+
adVolume21 = originalMutedState ? 1 : originalVolume;
|
|
1567
|
+
adVideoElement.volume = Math.max(0, Math.min(1, adVolume21));
|
|
1568
|
+
adVideoElement.muted = false;
|
|
1569
|
+
container2.style.display = "flex";
|
|
1570
|
+
container2.style.pointerEvents = "auto";
|
|
1571
|
+
emit("content_pause");
|
|
1572
|
+
if (debug) console.log("".concat(LOG, " [preload] smartTVMode deferred: creating video element and loading, url=").concat(slot.mediaFile.url));
|
|
1573
|
+
startPlayback(slot.mediaFile);
|
|
1574
|
+
return [
|
|
1575
|
+
2
|
|
1576
|
+
];
|
|
1577
|
+
}
|
|
1549
1578
|
teardownCurrentPlayback();
|
|
1550
1579
|
if (adVideoElement && adVideoElement !== slot.videoEl) {
|
|
1551
1580
|
adVideoElement.remove();
|
|
@@ -1555,13 +1584,6 @@ function createPrebidAdLayer(contentVideo, options) {
|
|
|
1555
1584
|
adVideoElement = slot.videoEl;
|
|
1556
1585
|
adHls = slot.hlsInstance;
|
|
1557
1586
|
setupAdEventListeners();
|
|
1558
|
-
sessionId = generateSessionId();
|
|
1559
|
-
currentAd = slot.ad;
|
|
1560
|
-
trackingFired = _object_spread({}, createEmptyTrackingState());
|
|
1561
|
-
fireTrackingPixels2(slot.ad.trackingUrls.impression);
|
|
1562
|
-
trackingFired.impression = true;
|
|
1563
|
-
contentVolume = contentVideo.volume;
|
|
1564
|
-
originalVolume = Math.max(0, Math.min(1, contentVolume || originalVolume));
|
|
1565
1587
|
if (!continueLiveStreamDuringAds) {
|
|
1566
1588
|
contentVideo.pause();
|
|
1567
1589
|
}
|
|
@@ -1576,17 +1598,10 @@ function createPrebidAdLayer(contentVideo, options) {
|
|
|
1576
1598
|
container.style.display = "flex";
|
|
1577
1599
|
container.style.pointerEvents = "auto";
|
|
1578
1600
|
emit("content_pause");
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
});
|
|
1584
|
-
} else {
|
|
1585
|
-
adVideoElement.play().catch(function(error) {
|
|
1586
|
-
console.error("".concat(LOG, " [preload] Error playing preloaded ad:"), error);
|
|
1587
|
-
handleAdError();
|
|
1588
|
-
});
|
|
1589
|
-
}
|
|
1601
|
+
adVideoElement.play().catch(function(error) {
|
|
1602
|
+
console.error("".concat(LOG, " [preload] Error playing preloaded ad:"), error);
|
|
1603
|
+
handleAdError();
|
|
1604
|
+
});
|
|
1590
1605
|
return [
|
|
1591
1606
|
2
|
|
1592
1607
|
];
|
|
@@ -1600,10 +1615,12 @@ function createPrebidAdLayer(contentVideo, options) {
|
|
|
1600
1615
|
if (slot.hlsInstance) {
|
|
1601
1616
|
slot.hlsInstance.destroy();
|
|
1602
1617
|
}
|
|
1603
|
-
slot.videoEl
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1618
|
+
if (slot.videoEl) {
|
|
1619
|
+
slot.videoEl.pause();
|
|
1620
|
+
slot.videoEl.removeAttribute("src");
|
|
1621
|
+
slot.videoEl.load();
|
|
1622
|
+
slot.videoEl.remove();
|
|
1623
|
+
}
|
|
1607
1624
|
if (debug) console.log("".concat(LOG, " [preload] Cancelled and cleaned up token=").concat(token));
|
|
1608
1625
|
}
|
|
1609
1626
|
return {
|
|
@@ -1651,20 +1668,27 @@ function createPrebidAdLayer(contentVideo, options) {
|
|
|
1651
1668
|
setAdPlayingFlag(false);
|
|
1652
1669
|
contentVideo.muted = originalMutedState;
|
|
1653
1670
|
contentVideo.volume = originalMutedState ? 0 : originalVolume;
|
|
1654
|
-
if (adContainerEl) {
|
|
1655
|
-
adContainerEl.style.display = "none";
|
|
1656
|
-
adContainerEl.style.pointerEvents = "none";
|
|
1657
|
-
}
|
|
1658
1671
|
contentVideo.style.visibility = "visible";
|
|
1659
1672
|
contentVideo.style.opacity = "1";
|
|
1660
|
-
if (
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1673
|
+
if (singleElementMode) {
|
|
1674
|
+
teardownCurrentPlayback();
|
|
1675
|
+
contentVideo.removeAttribute("src");
|
|
1676
|
+
contentVideo.load();
|
|
1677
|
+
adVideoElement = void 0;
|
|
1678
|
+
} else {
|
|
1679
|
+
if (adContainerEl) {
|
|
1680
|
+
adContainerEl.style.display = "none";
|
|
1681
|
+
adContainerEl.style.pointerEvents = "none";
|
|
1682
|
+
}
|
|
1683
|
+
if (continueLiveStreamDuringAds) {
|
|
1684
|
+
contentVideo.play().catch(function() {});
|
|
1685
|
+
}
|
|
1686
|
+
teardownCurrentPlayback();
|
|
1687
|
+
if (adVideoElement) {
|
|
1688
|
+
adVideoElement.pause();
|
|
1689
|
+
adVideoElement.removeAttribute("src");
|
|
1690
|
+
adVideoElement.load();
|
|
1691
|
+
}
|
|
1668
1692
|
}
|
|
1669
1693
|
currentAd = void 0;
|
|
1670
1694
|
tornDown = false;
|
|
@@ -1704,9 +1728,14 @@ function createPrebidAdLayer(contentVideo, options) {
|
|
|
1704
1728
|
}
|
|
1705
1729
|
teardownCurrentPlayback();
|
|
1706
1730
|
if (adVideoElement) {
|
|
1707
|
-
adVideoElement
|
|
1708
|
-
|
|
1709
|
-
|
|
1731
|
+
if (singleElementMode && adVideoElement === contentVideo) {
|
|
1732
|
+
contentVideo.removeAttribute("src");
|
|
1733
|
+
contentVideo.load();
|
|
1734
|
+
} else {
|
|
1735
|
+
adVideoElement.pause();
|
|
1736
|
+
adVideoElement.removeAttribute("src");
|
|
1737
|
+
adVideoElement.remove();
|
|
1738
|
+
}
|
|
1710
1739
|
adVideoElement = void 0;
|
|
1711
1740
|
}
|
|
1712
1741
|
if (adContainerEl === null || adContainerEl === void 0 ? void 0 : adContainerEl.parentElement) {
|
|
@@ -2901,11 +2930,14 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
2901
2930
|
this.video = config.videoElement;
|
|
2902
2931
|
this.adTransitionGapMs = (_this_config_adTransitionGapMs = this.config.adTransitionGapMs) !== null && _this_config_adTransitionGapMs !== void 0 ? _this_config_adTransitionGapMs : 100;
|
|
2903
2932
|
logBrowserInfo(config.debugAdTiming);
|
|
2904
|
-
this.
|
|
2933
|
+
this.vastManager = createVastManager(config.debugAdTiming !== void 0 ? {
|
|
2905
2934
|
debug: !!config.debugAdTiming
|
|
2906
2935
|
} : {});
|
|
2907
|
-
|
|
2936
|
+
var browserForAdLayer = detectBrowser();
|
|
2937
|
+
this.adLayer = createVastAdLayer(this.video, {
|
|
2908
2938
|
continueLiveStreamDuringAds: false,
|
|
2939
|
+
smartTVMode: browserForAdLayer.isSmartTV,
|
|
2940
|
+
singleElementMode: browserForAdLayer.isSmartTV,
|
|
2909
2941
|
debug: !!config.debugAdTiming
|
|
2910
2942
|
});
|
|
2911
2943
|
}
|
|
@@ -2917,19 +2949,19 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
2917
2949
|
return _ts_generator(this, function(_state) {
|
|
2918
2950
|
switch(_state.label){
|
|
2919
2951
|
case 0:
|
|
2920
|
-
if (this.config.
|
|
2952
|
+
if (this.config.disableAds) return [
|
|
2921
2953
|
2,
|
|
2922
2954
|
[]
|
|
2923
2955
|
];
|
|
2924
2956
|
return [
|
|
2925
2957
|
4,
|
|
2926
|
-
this.
|
|
2958
|
+
this.vastManager.initialize()
|
|
2927
2959
|
];
|
|
2928
2960
|
case 1:
|
|
2929
2961
|
_state.sent();
|
|
2930
2962
|
return [
|
|
2931
2963
|
2,
|
|
2932
|
-
this.
|
|
2964
|
+
this.vastManager.requestBidsUntilResponse(context)
|
|
2933
2965
|
];
|
|
2934
2966
|
}
|
|
2935
2967
|
});
|
|
@@ -2964,7 +2996,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
2964
2996
|
adBehavior: "vod (main video pauses during ads)"
|
|
2965
2997
|
});
|
|
2966
2998
|
}
|
|
2967
|
-
if (!this.config.
|
|
2999
|
+
if (!this.config.disableAds) {
|
|
2968
3000
|
this.adLayer.updateOptions({
|
|
2969
3001
|
continueLiveStreamDuringAds: false,
|
|
2970
3002
|
mainHlsInstance: null
|
|
@@ -3032,7 +3064,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
3032
3064
|
adBehavior: adBehavior
|
|
3033
3065
|
});
|
|
3034
3066
|
}
|
|
3035
|
-
if (!this.config.
|
|
3067
|
+
if (!this.config.disableAds) {
|
|
3036
3068
|
;
|
|
3037
3069
|
this.adLayer.updateOptions({
|
|
3038
3070
|
continueLiveStreamDuringAds: this.shouldContinueLiveStreamDuringAds(),
|
|
@@ -3353,7 +3385,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
3353
3385
|
{
|
|
3354
3386
|
key: "getAdSource",
|
|
3355
3387
|
value: function getAdSource() {
|
|
3356
|
-
return "
|
|
3388
|
+
return "vast";
|
|
3357
3389
|
}
|
|
3358
3390
|
},
|
|
3359
3391
|
{
|
|
@@ -3599,7 +3631,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
3599
3631
|
this.attached = true;
|
|
3600
3632
|
this.video.autoplay = !!this.config.autoplay;
|
|
3601
3633
|
this.video.muted = !!this.config.muted;
|
|
3602
|
-
if (!this.config.
|
|
3634
|
+
if (!this.config.disableAds) {
|
|
3603
3635
|
this.adLayer.initialize();
|
|
3604
3636
|
if (!this.config.disableFiller) {
|
|
3605
3637
|
this.ensureFillerVideo();
|
|
@@ -3795,7 +3827,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
3795
3827
|
key: "onScte35Marker",
|
|
3796
3828
|
value: function onScte35Marker(marker) {
|
|
3797
3829
|
var _this = this;
|
|
3798
|
-
if (this.config.
|
|
3830
|
+
if (this.config.disableAds) return;
|
|
3799
3831
|
if (this.config.debugAdTiming) {
|
|
3800
3832
|
console.log("[StormcloudVideoPlayer] SCTE-35 marker detected:", {
|
|
3801
3833
|
type: marker.type,
|
|
@@ -4267,13 +4299,17 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4267
4299
|
if (!this.isLiveStream) {
|
|
4268
4300
|
return false;
|
|
4269
4301
|
}
|
|
4302
|
+
var browser = detectBrowser();
|
|
4303
|
+
if (browser.isSmartTV) {
|
|
4304
|
+
return false;
|
|
4305
|
+
}
|
|
4270
4306
|
return true;
|
|
4271
4307
|
}
|
|
4272
4308
|
},
|
|
4273
4309
|
{
|
|
4274
4310
|
key: "startAdPrefetch",
|
|
4275
4311
|
value: function startAdPrefetch(marker, fragmentSn) {
|
|
4276
|
-
if (this.config.
|
|
4312
|
+
if (this.config.disableAds) return;
|
|
4277
4313
|
if (this.pendingAdBreak || this.inAdBreak) {
|
|
4278
4314
|
return;
|
|
4279
4315
|
}
|
|
@@ -4295,25 +4331,75 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4295
4331
|
key: "runAdPrefetch",
|
|
4296
4332
|
value: function runAdPrefetch(marker) {
|
|
4297
4333
|
return _async_to_generator(function() {
|
|
4298
|
-
var _this, _marker_durationSeconds, durSec, estimatedCount,
|
|
4334
|
+
var _this, _marker_durationSeconds, _ref, _firstBids_, durSec, context, firstBids, unused, adDurationSec, estimatedCount, firstToken, remaining, results, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, result, token;
|
|
4299
4335
|
return _ts_generator(this, function(_state) {
|
|
4300
4336
|
switch(_state.label){
|
|
4301
4337
|
case 0:
|
|
4302
4338
|
_this = this;
|
|
4303
4339
|
durSec = (_marker_durationSeconds = marker.durationSeconds) !== null && _marker_durationSeconds !== void 0 ? _marker_durationSeconds : 60;
|
|
4304
|
-
estimatedCount = Math.min(4, Math.max(1, Math.ceil(durSec / 30)));
|
|
4305
|
-
if (this.config.debugAdTiming) {
|
|
4306
|
-
console.log("[PREFETCH] Firing ".concat(estimatedCount, " parallel bid request(s) for ").concat(durSec, "s break"));
|
|
4307
|
-
}
|
|
4308
4340
|
context = {
|
|
4309
4341
|
breakDurationSec: durSec,
|
|
4310
4342
|
remainingBreakSec: durSec
|
|
4311
4343
|
};
|
|
4312
|
-
|
|
4313
|
-
|
|
4344
|
+
_state.label = 1;
|
|
4345
|
+
case 1:
|
|
4346
|
+
_state.trys.push([
|
|
4347
|
+
1,
|
|
4348
|
+
3,
|
|
4349
|
+
,
|
|
4350
|
+
4
|
|
4351
|
+
]);
|
|
4352
|
+
return [
|
|
4353
|
+
4,
|
|
4354
|
+
this.adRequest(_object_spread_props(_object_spread({}, context), {
|
|
4355
|
+
adIndex: 1
|
|
4356
|
+
}))
|
|
4357
|
+
];
|
|
4358
|
+
case 2:
|
|
4359
|
+
firstBids = _state.sent();
|
|
4360
|
+
return [
|
|
4361
|
+
3,
|
|
4362
|
+
4
|
|
4363
|
+
];
|
|
4364
|
+
case 3:
|
|
4365
|
+
unused = _state.sent();
|
|
4366
|
+
firstBids = [];
|
|
4367
|
+
return [
|
|
4368
|
+
3,
|
|
4369
|
+
4
|
|
4370
|
+
];
|
|
4371
|
+
case 4:
|
|
4372
|
+
if (this.inAdBreak) return [
|
|
4373
|
+
2
|
|
4374
|
+
];
|
|
4375
|
+
if (firstBids.length === 0) {
|
|
4376
|
+
if (this.config.debugAdTiming) {
|
|
4377
|
+
console.log("[PREFETCH] First VAST request returned no ad, aborting prefetch");
|
|
4378
|
+
}
|
|
4379
|
+
return [
|
|
4380
|
+
2
|
|
4381
|
+
];
|
|
4382
|
+
}
|
|
4383
|
+
adDurationSec = (_ref = (_firstBids_ = firstBids[0]) === null || _firstBids_ === void 0 ? void 0 : _firstBids_.durationSec) !== null && _ref !== void 0 ? _ref : 30;
|
|
4384
|
+
estimatedCount = Math.max(1, Math.ceil(durSec / adDurationSec));
|
|
4385
|
+
if (this.config.debugAdTiming) {
|
|
4386
|
+
console.log("[PREFETCH] Ad duration=".concat(adDurationSec, "s, break=").concat(durSec, "s → ").concat(estimatedCount, " ad(s) needed"));
|
|
4387
|
+
}
|
|
4388
|
+
firstToken = "preload_".concat(Date.now(), "_").concat(Math.random().toString(36).slice(2, 7));
|
|
4389
|
+
this.preloadedTokens.push(firstToken);
|
|
4390
|
+
void this.adLayer.preloadAd(firstBids, firstToken);
|
|
4391
|
+
if (this.config.debugAdTiming) {
|
|
4392
|
+
console.log("[PREFETCH] First ad preloading, token=".concat(firstToken));
|
|
4393
|
+
}
|
|
4394
|
+
if (!(estimatedCount > 1)) return [
|
|
4395
|
+
3,
|
|
4396
|
+
6
|
|
4397
|
+
];
|
|
4398
|
+
remaining = Array.from({
|
|
4399
|
+
length: estimatedCount - 1
|
|
4314
4400
|
}, function(_, i) {
|
|
4315
4401
|
return _this.adRequest(_object_spread_props(_object_spread({}, context), {
|
|
4316
|
-
adIndex: i +
|
|
4402
|
+
adIndex: i + 2
|
|
4317
4403
|
})).then(function(bids) {
|
|
4318
4404
|
return {
|
|
4319
4405
|
ok: true,
|
|
@@ -4327,9 +4413,9 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4327
4413
|
});
|
|
4328
4414
|
return [
|
|
4329
4415
|
4,
|
|
4330
|
-
Promise.all(
|
|
4416
|
+
Promise.all(remaining)
|
|
4331
4417
|
];
|
|
4332
|
-
case
|
|
4418
|
+
case 5:
|
|
4333
4419
|
results = _state.sent();
|
|
4334
4420
|
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
4335
4421
|
try {
|
|
@@ -4341,7 +4427,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4341
4427
|
this.preloadedTokens.push(token);
|
|
4342
4428
|
void this.adLayer.preloadAd(result.value, token);
|
|
4343
4429
|
if (this.config.debugAdTiming) {
|
|
4344
|
-
console.log("[PREFETCH]
|
|
4430
|
+
console.log("[PREFETCH] Additional ad preloading, token=".concat(token));
|
|
4345
4431
|
}
|
|
4346
4432
|
}
|
|
4347
4433
|
}
|
|
@@ -4359,6 +4445,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4359
4445
|
}
|
|
4360
4446
|
}
|
|
4361
4447
|
}
|
|
4448
|
+
_state.label = 6;
|
|
4449
|
+
case 6:
|
|
4362
4450
|
if (this.config.debugAdTiming) {
|
|
4363
4451
|
console.log("[PREFETCH] Pre-fetch complete: ".concat(this.preloadedTokens.length, " ad(s) queued"));
|
|
4364
4452
|
}
|
|
@@ -4422,7 +4510,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4422
4510
|
switch(_state.label){
|
|
4423
4511
|
case 0:
|
|
4424
4512
|
_loop = function() {
|
|
4425
|
-
var remaining, prefetchContext, bids, err, bids1, remainingNow, delay, elapsed, remaining1, context, bids2, remainingNow1, err1;
|
|
4513
|
+
var remaining, prefetchContext, bids, err, bids1, remainingNow, urgentNeedAd, delay, elapsed, remaining1, context, bids2, remainingNow1, err1, sleepMs;
|
|
4426
4514
|
return _ts_generator(this, function(_state) {
|
|
4427
4515
|
switch(_state.label){
|
|
4428
4516
|
case 0:
|
|
@@ -4473,6 +4561,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4473
4561
|
if (bids.length > 0) {
|
|
4474
4562
|
_this.consecutiveFailures = 0;
|
|
4475
4563
|
_this.pendingNextAdBids = bids;
|
|
4564
|
+
_this.totalAdsInBreak = Math.max(_this.totalAdsInBreak, _this.currentAdIndex + _this.preloadedTokens.length + 1);
|
|
4476
4565
|
if (_this.config.debugAdTiming) {
|
|
4477
4566
|
console.log("[CONTINUOUS-FETCH] Pre-fetched next ad stored as pending");
|
|
4478
4567
|
}
|
|
@@ -4557,7 +4646,8 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4557
4646
|
"continue"
|
|
4558
4647
|
];
|
|
4559
4648
|
case 12:
|
|
4560
|
-
|
|
4649
|
+
urgentNeedAd = _this.inAdBreak && !_this.adLayer.isAdPlaying();
|
|
4650
|
+
delay = _this.lastAdRequestTime ? _this.minAdRequestIntervalMs + (!urgentNeedAd && _this.consecutiveFailures > 0 ? backoffMs() : 0) : 0;
|
|
4561
4651
|
elapsed = Date.now() - _this.lastAdRequestTime;
|
|
4562
4652
|
if (!(elapsed < delay && _this.lastAdRequestTime > 0)) return [
|
|
4563
4653
|
3,
|
|
@@ -4612,6 +4702,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4612
4702
|
17
|
|
4613
4703
|
];
|
|
4614
4704
|
_this.pendingNextAdBids = bids2;
|
|
4705
|
+
_this.totalAdsInBreak = Math.max(_this.totalAdsInBreak, _this.currentAdIndex + _this.preloadedTokens.length + 1);
|
|
4615
4706
|
if (_this.config.debugAdTiming) {
|
|
4616
4707
|
console.log("[CONTINUOUS-FETCH] Next ad response stored (ad currently playing or in transition)");
|
|
4617
4708
|
}
|
|
@@ -4675,10 +4766,11 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4675
4766
|
24
|
|
4676
4767
|
];
|
|
4677
4768
|
case 24:
|
|
4769
|
+
sleepMs = _this.inAdBreak && !_this.adLayer.isAdPlaying() ? 0 : backoffMs();
|
|
4678
4770
|
return [
|
|
4679
4771
|
4,
|
|
4680
4772
|
new Promise(function(r) {
|
|
4681
|
-
return setTimeout(r,
|
|
4773
|
+
return setTimeout(r, sleepMs);
|
|
4682
4774
|
})
|
|
4683
4775
|
];
|
|
4684
4776
|
case 25:
|
|
@@ -4765,7 +4857,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4765
4857
|
this.inAdBreak = true;
|
|
4766
4858
|
this.currentAdBreakStartWallClockMs = Date.now();
|
|
4767
4859
|
this.currentAdIndex = 0;
|
|
4768
|
-
this.totalAdsInBreak = 1;
|
|
4860
|
+
this.totalAdsInBreak = Math.max(1, this.preloadedTokens.length);
|
|
4769
4861
|
this.adPodQueue = [];
|
|
4770
4862
|
if (!this.config.disableFiller) this.showAds = true;
|
|
4771
4863
|
if (adBreakDurationMs != null) {
|
|
@@ -4990,6 +5082,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
4990
5082
|
3
|
|
4991
5083
|
];
|
|
4992
5084
|
this.pendingNextAdBids = bids;
|
|
5085
|
+
this.totalAdsInBreak = Math.max(this.totalAdsInBreak, this.currentAdIndex + this.preloadedTokens.length);
|
|
4993
5086
|
return [
|
|
4994
5087
|
3,
|
|
4995
5088
|
5
|
|
@@ -5358,40 +5451,45 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
5358
5451
|
var browser = detectBrowser();
|
|
5359
5452
|
var isSmartTV = browser.tizenVersion !== void 0 || browser.webOSVersion !== void 0;
|
|
5360
5453
|
if (isSmartTV && this.hls) {
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
}
|
|
5454
|
+
var hlsRef = this.hls;
|
|
5455
|
+
var savedMuted = restoredMuted;
|
|
5456
|
+
var savedVolume = restoredVolume;
|
|
5457
|
+
var onManifestParsedRestore = function onManifestParsedRestore1() {
|
|
5458
|
+
hlsRef.off(import_hls2.default.Events.MANIFEST_PARSED, onManifestParsedRestore);
|
|
5459
|
+
if (!_this.inAdBreak && !_this.adLayer.isAdPlaying()) {
|
|
5460
|
+
var _this_video_play;
|
|
5461
|
+
if (_this.video.muted !== savedMuted) _this.video.muted = savedMuted;
|
|
5462
|
+
if (Math.abs(_this.video.volume - savedVolume) > 0.01) _this.video.volume = savedVolume;
|
|
5463
|
+
if (_this.config.debugAdTiming) {
|
|
5464
|
+
console.log("[StormcloudVideoPlayer] Smart TV: audio state restored on MANIFEST_PARSED after re-attach");
|
|
5373
5465
|
}
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5466
|
+
hlsRef.startLoad(-1);
|
|
5467
|
+
(_this_video_play = _this.video.play()) === null || _this_video_play === void 0 ? void 0 : _this_video_play.catch(function() {});
|
|
5468
|
+
if (_this.config.debugAdTiming) {
|
|
5469
|
+
console.log("[StormcloudVideoPlayer] Smart TV: seeking to live edge and resuming playback after re-attach");
|
|
5470
|
+
}
|
|
5471
|
+
}
|
|
5472
|
+
};
|
|
5473
|
+
hlsRef.on(import_hls2.default.Events.MANIFEST_PARSED, onManifestParsedRestore);
|
|
5377
5474
|
this.hls.attachMedia(this.video);
|
|
5378
5475
|
if (this.config.debugAdTiming) {
|
|
5379
5476
|
console.log("[StormcloudVideoPlayer] Smart TV: re-attached HLS to video element after ad break to restore media pipeline");
|
|
5380
5477
|
}
|
|
5381
|
-
}
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5478
|
+
} else {
|
|
5479
|
+
if (this.shouldContinueLiveStreamDuringAds()) {
|
|
5480
|
+
var _this_video_play;
|
|
5481
|
+
if (this.config.debugAdTiming) {
|
|
5482
|
+
if (this.video.paused) {
|
|
5483
|
+
console.log("[StormcloudVideoPlayer] Content video paused in live mode after ads, resuming playback");
|
|
5484
|
+
} else {
|
|
5485
|
+
console.log("[StormcloudVideoPlayer] Content video already playing in live mode after ads");
|
|
5486
|
+
}
|
|
5389
5487
|
}
|
|
5488
|
+
(_this_video_play = this.video.play()) === null || _this_video_play === void 0 ? void 0 : _this_video_play.catch(function() {});
|
|
5489
|
+
} else if (this.video.paused) {
|
|
5490
|
+
var _this_video_play1;
|
|
5491
|
+
(_this_video_play1 = this.video.play()) === null || _this_video_play1 === void 0 ? void 0 : _this_video_play1.catch(function() {});
|
|
5390
5492
|
}
|
|
5391
|
-
(_this_video_play = this.video.play()) === null || _this_video_play === void 0 ? void 0 : _this_video_play.catch(function() {});
|
|
5392
|
-
} else if (this.video.paused) {
|
|
5393
|
-
var _this_video_play1;
|
|
5394
|
-
(_this_video_play1 = this.video.play()) === null || _this_video_play1 === void 0 ? void 0 : _this_video_play1.catch(function() {});
|
|
5395
5493
|
}
|
|
5396
5494
|
this.syncMainContentAudioWhenVisible();
|
|
5397
5495
|
if (!restoredMuted) {
|
|
@@ -5442,6 +5540,14 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
|
|
|
5442
5540
|
console.log("[CONTINUOUS-FETCH] \uD83D\uDED1 Max consecutive failures reached (".concat(this.consecutiveFailures, "), ending ad break gracefully"));
|
|
5443
5541
|
}
|
|
5444
5542
|
this.handleAdPodComplete();
|
|
5543
|
+
return;
|
|
5544
|
+
}
|
|
5545
|
+
if (this.inAdBreak && !this.config.disableFiller) {
|
|
5546
|
+
if (this.config.debugAdTiming) {
|
|
5547
|
+
console.log("[CONTINUOUS-FETCH] Ad failure in active break \u2014 showing filler while awaiting next ad");
|
|
5548
|
+
}
|
|
5549
|
+
this.showPlaceholderLayer();
|
|
5550
|
+
this.adLayer.showPlaceholder();
|
|
5445
5551
|
}
|
|
5446
5552
|
}
|
|
5447
5553
|
},
|
|
@@ -5781,7 +5887,7 @@ var CRITICAL_PROPS = [
|
|
|
5781
5887
|
];
|
|
5782
5888
|
var CONTROLS_HIDE_DELAY = 3e3;
|
|
5783
5889
|
var StormcloudVideoPlayerComponent = import_react.default.memo(function(props) {
|
|
5784
|
-
var src = props.src, autoplay = props.autoplay, muted = props.muted, lowLatencyMode = props.lowLatencyMode, allowNativeHls = props.allowNativeHls, driftToleranceMs = props.driftToleranceMs, immediateManifestAds = props.immediateManifestAds, debugAdTiming = props.debugAdTiming, showCustomControls = props.showCustomControls, hideLoadingIndicator = props.hideLoadingIndicator, onVolumeToggle = props.onVolumeToggle, onFullscreenToggle = props.onFullscreenToggle, onControlClick = props.onControlClick, onReady = props.onReady, wrapperClassName = props.wrapperClassName, wrapperStyle = props.wrapperStyle, className = props.className, style = props.style, controls = props.controls, playsInline = props.playsInline, preload = props.preload, poster = props.poster, children = props.children, licenseKey = props.licenseKey, minSegmentsBeforePlay = props.minSegmentsBeforePlay,
|
|
5890
|
+
var src = props.src, autoplay = props.autoplay, muted = props.muted, lowLatencyMode = props.lowLatencyMode, allowNativeHls = props.allowNativeHls, driftToleranceMs = props.driftToleranceMs, immediateManifestAds = props.immediateManifestAds, debugAdTiming = props.debugAdTiming, showCustomControls = props.showCustomControls, hideLoadingIndicator = props.hideLoadingIndicator, onVolumeToggle = props.onVolumeToggle, onFullscreenToggle = props.onFullscreenToggle, onControlClick = props.onControlClick, onReady = props.onReady, wrapperClassName = props.wrapperClassName, wrapperStyle = props.wrapperStyle, className = props.className, style = props.style, controls = props.controls, playsInline = props.playsInline, preload = props.preload, poster = props.poster, children = props.children, licenseKey = props.licenseKey, minSegmentsBeforePlay = props.minSegmentsBeforePlay, disableAds = props.disableAds, disableFiller = props.disableFiller, restVideoAttrs = _object_without_properties(props, [
|
|
5785
5891
|
"src",
|
|
5786
5892
|
"autoplay",
|
|
5787
5893
|
"muted",
|
|
@@ -5807,7 +5913,7 @@ var StormcloudVideoPlayerComponent = import_react.default.memo(function(props) {
|
|
|
5807
5913
|
"children",
|
|
5808
5914
|
"licenseKey",
|
|
5809
5915
|
"minSegmentsBeforePlay",
|
|
5810
|
-
"
|
|
5916
|
+
"disableAds",
|
|
5811
5917
|
"disableFiller"
|
|
5812
5918
|
]);
|
|
5813
5919
|
var videoRef = (0, import_react.useRef)(null);
|
|
@@ -5965,7 +6071,7 @@ var StormcloudVideoPlayerComponent = import_react.default.memo(function(props) {
|
|
|
5965
6071
|
if (onControlClick !== void 0) cfg.onControlClick = onControlClick;
|
|
5966
6072
|
if (licenseKey !== void 0) cfg.licenseKey = licenseKey;
|
|
5967
6073
|
if (minSegmentsBeforePlay !== void 0) cfg.minSegmentsBeforePlay = minSegmentsBeforePlay;
|
|
5968
|
-
if (
|
|
6074
|
+
if (disableAds !== void 0) cfg.disableAds = disableAds;
|
|
5969
6075
|
cfg.disableFiller = disableFiller !== null && disableFiller !== void 0 ? disableFiller : true;
|
|
5970
6076
|
var player = new StormcloudVideoPlayer(cfg);
|
|
5971
6077
|
playerRef.current = player;
|