stormcloud-video-player 0.5.6 → 0.5.7

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.
Files changed (37) hide show
  1. package/README.md +28 -40
  2. package/dist/stormcloud-vp.min.js +1 -1
  3. package/lib/index.cjs +1537 -4636
  4. package/lib/index.cjs.map +1 -1
  5. package/lib/index.d.cts +7 -67
  6. package/lib/index.d.ts +7 -67
  7. package/lib/index.js +1540 -4623
  8. package/lib/index.js.map +1 -1
  9. package/lib/player/StormcloudVideoPlayer.cjs +811 -3880
  10. package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
  11. package/lib/player/StormcloudVideoPlayer.d.cts +3 -37
  12. package/lib/players/HlsPlayer.cjs +811 -3880
  13. package/lib/players/HlsPlayer.cjs.map +1 -1
  14. package/lib/players/HlsPlayer.d.cts +1 -1
  15. package/lib/players/index.cjs +811 -3880
  16. package/lib/players/index.cjs.map +1 -1
  17. package/lib/sdk/prebid.cjs +114 -43
  18. package/lib/sdk/prebid.cjs.map +1 -1
  19. package/lib/sdk/prebid.d.cts +1 -1
  20. package/lib/sdk/prebidController.cjs +123 -71
  21. package/lib/sdk/prebidController.cjs.map +1 -1
  22. package/lib/sdk/prebidController.d.cts +2 -2
  23. package/lib/{types-Bwp6-yys.d.cts → types-BOJiWNWa.d.cts} +4 -7
  24. package/lib/ui/StormcloudVideoPlayer.cjs +811 -3890
  25. package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
  26. package/lib/ui/StormcloudVideoPlayer.d.cts +1 -1
  27. package/lib/utils/browserCompat.cjs +0 -3
  28. package/lib/utils/browserCompat.cjs.map +1 -1
  29. package/lib/utils/browserCompat.d.cts +0 -1
  30. package/lib/utils/tracking.d.cts +1 -1
  31. package/package.json +1 -1
  32. package/lib/sdk/hlsAdPlayer.cjs +0 -1053
  33. package/lib/sdk/hlsAdPlayer.cjs.map +0 -1
  34. package/lib/sdk/hlsAdPlayer.d.cts +0 -10
  35. package/lib/sdk/ima.cjs +0 -1384
  36. package/lib/sdk/ima.cjs.map +0 -1
  37. package/lib/sdk/ima.d.cts +0 -12
package/lib/sdk/ima.cjs DELETED
@@ -1,1384 +0,0 @@
1
- "use strict";
2
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
3
- try {
4
- var info = gen[key](arg);
5
- var value = info.value;
6
- } catch (error) {
7
- reject(error);
8
- return;
9
- }
10
- if (info.done) {
11
- resolve(value);
12
- } else {
13
- Promise.resolve(value).then(_next, _throw);
14
- }
15
- }
16
- function _async_to_generator(fn) {
17
- return function() {
18
- var self = this, args = arguments;
19
- return new Promise(function(resolve, reject) {
20
- var gen = fn.apply(self, args);
21
- function _next(value) {
22
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
23
- }
24
- function _throw(err) {
25
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
26
- }
27
- _next(undefined);
28
- });
29
- };
30
- }
31
- function _type_of(obj) {
32
- "@swc/helpers - typeof";
33
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
34
- }
35
- function _ts_generator(thisArg, body) {
36
- var f, y, t, _ = {
37
- label: 0,
38
- sent: function() {
39
- if (t[0] & 1) throw t[1];
40
- return t[1];
41
- },
42
- trys: [],
43
- ops: []
44
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
45
- return d(g, "next", {
46
- value: verb(0)
47
- }), d(g, "throw", {
48
- value: verb(1)
49
- }), d(g, "return", {
50
- value: verb(2)
51
- }), typeof Symbol === "function" && d(g, Symbol.iterator, {
52
- value: function() {
53
- return this;
54
- }
55
- }), g;
56
- function verb(n) {
57
- return function(v) {
58
- return step([
59
- n,
60
- v
61
- ]);
62
- };
63
- }
64
- function step(op) {
65
- if (f) throw new TypeError("Generator is already executing.");
66
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
67
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
68
- if (y = 0, t) op = [
69
- op[0] & 2,
70
- t.value
71
- ];
72
- switch(op[0]){
73
- case 0:
74
- case 1:
75
- t = op;
76
- break;
77
- case 4:
78
- _.label++;
79
- return {
80
- value: op[1],
81
- done: false
82
- };
83
- case 5:
84
- _.label++;
85
- y = op[1];
86
- op = [
87
- 0
88
- ];
89
- continue;
90
- case 7:
91
- op = _.ops.pop();
92
- _.trys.pop();
93
- continue;
94
- default:
95
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
96
- _ = 0;
97
- continue;
98
- }
99
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
100
- _.label = op[1];
101
- break;
102
- }
103
- if (op[0] === 6 && _.label < t[1]) {
104
- _.label = t[1];
105
- t = op;
106
- break;
107
- }
108
- if (t && _.label < t[2]) {
109
- _.label = t[2];
110
- _.ops.push(op);
111
- break;
112
- }
113
- if (t[2]) _.ops.pop();
114
- _.trys.pop();
115
- continue;
116
- }
117
- op = body.call(thisArg, _);
118
- } catch (e) {
119
- op = [
120
- 6,
121
- e
122
- ];
123
- y = 0;
124
- } finally{
125
- f = t = 0;
126
- }
127
- if (op[0] & 5) throw op[1];
128
- return {
129
- value: op[0] ? op[1] : void 0,
130
- done: true
131
- };
132
- }
133
- }
134
- var __defProp = Object.defineProperty;
135
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
136
- var __getOwnPropNames = Object.getOwnPropertyNames;
137
- var __hasOwnProp = Object.prototype.hasOwnProperty;
138
- var __export = function __export(target, all) {
139
- for(var name in all)__defProp(target, name, {
140
- get: all[name],
141
- enumerable: true
142
- });
143
- };
144
- var __copyProps = function __copyProps(to, from, except, desc) {
145
- if (from && (typeof from === "undefined" ? "undefined" : _type_of(from)) === "object" || typeof from === "function") {
146
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
147
- try {
148
- var _loop = function() {
149
- var key = _step.value;
150
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
151
- get: function get() {
152
- return from[key];
153
- },
154
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
155
- });
156
- };
157
- for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
158
- } catch (err) {
159
- _didIteratorError = true;
160
- _iteratorError = err;
161
- } finally{
162
- try {
163
- if (!_iteratorNormalCompletion && _iterator.return != null) {
164
- _iterator.return();
165
- }
166
- } finally{
167
- if (_didIteratorError) {
168
- throw _iteratorError;
169
- }
170
- }
171
- }
172
- }
173
- return to;
174
- };
175
- var __toCommonJS = function __toCommonJS(mod) {
176
- return __copyProps(__defProp({}, "__esModule", {
177
- value: true
178
- }), mod);
179
- };
180
- // src/sdk/ima.ts
181
- var ima_exports = {};
182
- __export(ima_exports, {
183
- createImaController: function createImaController1() {
184
- return createImaController;
185
- }
186
- });
187
- module.exports = __toCommonJS(ima_exports);
188
- // src/utils/browserCompat.ts
189
- function getChromeVersion(ua) {
190
- var match = ua.match(/Chrome\/(\d+)/);
191
- return match && match[1] ? parseInt(match[1], 10) : 0;
192
- }
193
- function getWebKitVersion(ua) {
194
- var match = ua.match(/AppleWebKit\/(\d+)/);
195
- return match && match[1] ? parseInt(match[1], 10) : 0;
196
- }
197
- function getPlatform() {
198
- var _navigator_userAgentData;
199
- if ("userAgentData" in navigator && ((_navigator_userAgentData = navigator.userAgentData) === null || _navigator_userAgentData === void 0 ? void 0 : _navigator_userAgentData.platform)) {
200
- return navigator.userAgentData.platform;
201
- }
202
- var ua = navigator.userAgent;
203
- if (/Mac|iPhone|iPad|iPod/i.test(ua)) {
204
- return /iPhone|iPad|iPod/i.test(ua) ? "iPhone" : "MacIntel";
205
- }
206
- if (/Win/i.test(ua)) {
207
- return "Win32";
208
- }
209
- if (/Linux/i.test(ua)) {
210
- return /Android/i.test(ua) ? "Linux armv8l" : "Linux x86_64";
211
- }
212
- if (/CrOS/i.test(ua)) {
213
- return "CrOS";
214
- }
215
- return navigator.platform || "Unknown";
216
- }
217
- function detectBrowser() {
218
- var ua = navigator.userAgent;
219
- var platform = getPlatform();
220
- var name = "Unknown";
221
- var version = "0";
222
- var majorVersion = 0;
223
- var isSmartTV = false;
224
- var isLegacyTV = false;
225
- var supportsIMA = true;
226
- var supportsModernJS = true;
227
- var recommendedAdPlayer = "ima";
228
- var webOSVersion;
229
- var tizenVersion;
230
- var chromeVersionNum;
231
- var chromeVersion = getChromeVersion(ua);
232
- var webkitVersion = getWebKitVersion(ua);
233
- chromeVersionNum = chromeVersion > 0 ? chromeVersion : void 0;
234
- if (/Web0S|webOS|LG Browser|LGSTB/i.test(ua)) {
235
- name = "LG WebOS";
236
- isSmartTV = true;
237
- var match = ua.match(/Web0S[/\s]*([\d.]+)/i) || ua.match(/webOS[/\s]*([\d.]+)/i);
238
- if (!match || !match[1]) {
239
- match = ua.match(/webOSTV[/\s-]*([\d.]+)/i) || ua.match(/webOS\.TV[/\s-]*([\d.]+)/i);
240
- }
241
- if (match && match[1]) {
242
- version = match[1];
243
- var parts = version.split(".");
244
- majorVersion = parts[0] ? parseInt(parts[0], 10) : 0;
245
- webOSVersion = majorVersion;
246
- } else if (chromeVersion > 0) {
247
- if (chromeVersion >= 79) {
248
- webOSVersion = 6;
249
- version = "6.0";
250
- majorVersion = 6;
251
- } else if (chromeVersion >= 68) {
252
- webOSVersion = 5;
253
- version = "5.0";
254
- majorVersion = 5;
255
- } else if (chromeVersion >= 53) {
256
- webOSVersion = 4;
257
- version = "4.0";
258
- majorVersion = 4;
259
- } else if (chromeVersion >= 38) {
260
- webOSVersion = 3;
261
- version = "3.0";
262
- majorVersion = 3;
263
- } else {
264
- webOSVersion = 2;
265
- version = "2.0";
266
- majorVersion = 2;
267
- }
268
- } else {
269
- version = "Unknown";
270
- webOSVersion = void 0;
271
- }
272
- if (webOSVersion !== void 0 && webOSVersion >= 4) {
273
- supportsIMA = true;
274
- recommendedAdPlayer = "ima";
275
- isLegacyTV = false;
276
- } else if (webOSVersion !== void 0 && webOSVersion >= 3) {
277
- if (chromeVersion >= 53) {
278
- supportsIMA = true;
279
- recommendedAdPlayer = "ima";
280
- isLegacyTV = false;
281
- } else {
282
- supportsIMA = false;
283
- recommendedAdPlayer = "hls";
284
- isLegacyTV = true;
285
- }
286
- } else if (chromeVersion >= 53) {
287
- supportsIMA = true;
288
- recommendedAdPlayer = "ima";
289
- isLegacyTV = false;
290
- } else {
291
- supportsIMA = false;
292
- recommendedAdPlayer = "hls";
293
- isLegacyTV = true;
294
- }
295
- } else if (/Tizen/i.test(ua)) {
296
- name = "Samsung Tizen";
297
- isSmartTV = true;
298
- var match1 = ua.match(/Tizen[/\s]*([\d.]+)/i);
299
- version = match1 && match1[1] ? match1[1] : "Unknown";
300
- if (version !== "Unknown") {
301
- var parts1 = version.split(".");
302
- majorVersion = parts1[0] ? parseInt(parts1[0], 10) : 0;
303
- tizenVersion = majorVersion;
304
- }
305
- if (tizenVersion !== void 0 && tizenVersion >= 4) {
306
- supportsIMA = true;
307
- recommendedAdPlayer = "ima";
308
- isLegacyTV = false;
309
- } else if (tizenVersion !== void 0 && tizenVersion >= 3 && chromeVersion >= 47) {
310
- supportsIMA = true;
311
- recommendedAdPlayer = "ima";
312
- isLegacyTV = false;
313
- } else if (chromeVersion >= 53) {
314
- supportsIMA = true;
315
- recommendedAdPlayer = "ima";
316
- isLegacyTV = false;
317
- } else {
318
- supportsIMA = false;
319
- recommendedAdPlayer = "hls";
320
- isLegacyTV = true;
321
- }
322
- } else if (/SMART-TV|SmartTV/i.test(ua)) {
323
- name = "Smart TV";
324
- isSmartTV = true;
325
- if (chromeVersion >= 53) {
326
- supportsIMA = true;
327
- recommendedAdPlayer = "ima";
328
- } else {
329
- supportsIMA = false;
330
- recommendedAdPlayer = "hls";
331
- isLegacyTV = true;
332
- }
333
- } else if (/NetCast/i.test(ua)) {
334
- name = "LG NetCast";
335
- isSmartTV = true;
336
- isLegacyTV = true;
337
- supportsIMA = false;
338
- recommendedAdPlayer = "hls";
339
- } else if (/BRAVIA/i.test(ua)) {
340
- name = "Sony BRAVIA";
341
- isSmartTV = true;
342
- if (chromeVersion >= 53) {
343
- supportsIMA = true;
344
- recommendedAdPlayer = "ima";
345
- } else {
346
- supportsIMA = false;
347
- recommendedAdPlayer = "hls";
348
- isLegacyTV = true;
349
- }
350
- } else {
351
- if (chromeVersion > 0) {
352
- name = "Chrome";
353
- version = chromeVersion.toString();
354
- majorVersion = chromeVersion;
355
- if (chromeVersion < 50) {
356
- supportsIMA = false;
357
- supportsModernJS = false;
358
- recommendedAdPlayer = "hls";
359
- }
360
- }
361
- if (webkitVersion > 0 && webkitVersion < 600) {
362
- supportsModernJS = false;
363
- if (chromeVersion < 50) {
364
- supportsIMA = false;
365
- recommendedAdPlayer = "hls";
366
- }
367
- }
368
- }
369
- if (typeof Promise === "undefined" || typeof Map === "undefined" || typeof Set === "undefined") {
370
- supportsModernJS = false;
371
- supportsIMA = false;
372
- recommendedAdPlayer = "hls";
373
- }
374
- if (typeof URLSearchParams === "undefined") {
375
- supportsModernJS = false;
376
- }
377
- return {
378
- name: name,
379
- version: version,
380
- majorVersion: majorVersion,
381
- isSmartTV: isSmartTV,
382
- isLegacyTV: isLegacyTV,
383
- platform: platform,
384
- supportsIMA: supportsIMA,
385
- supportsModernJS: supportsModernJS,
386
- recommendedAdPlayer: recommendedAdPlayer,
387
- webOSVersion: webOSVersion,
388
- tizenVersion: tizenVersion,
389
- chromeVersion: chromeVersionNum
390
- };
391
- }
392
- function supportsGoogleIMA() {
393
- var browser = detectBrowser();
394
- if (browser.isLegacyTV) {
395
- return false;
396
- }
397
- if (typeof document === "undefined" || typeof document.createElement !== "function") {
398
- return false;
399
- }
400
- try {
401
- var video = document.createElement("video");
402
- if (!video) {
403
- return false;
404
- }
405
- } catch (e) {
406
- return false;
407
- }
408
- if (typeof Promise === "undefined") {
409
- return false;
410
- }
411
- return browser.supportsIMA;
412
- }
413
- // src/sdk/ima.ts
414
- function createImaController(video, options) {
415
- var adPlaying = false;
416
- var contentVideoHidden = false;
417
- var originalMutedState = false;
418
- var originalVolume = typeof video.volume === "number" && !Number.isNaN(video.volume) ? Math.max(0, Math.min(1, video.volume)) : 1;
419
- var listeners = /* @__PURE__ */ new Map();
420
- var adVideoElement;
421
- function setAdPlayingFlag(isPlaying) {
422
- if (isPlaying) {
423
- video.dataset.stormcloudAdPlaying = "true";
424
- } else {
425
- delete video.dataset.stormcloudAdPlaying;
426
- }
427
- }
428
- function hideContentVideo() {
429
- if (!contentVideoHidden) {
430
- video.style.transition = "opacity 0.3s ease-in-out";
431
- video.style.opacity = "0";
432
- setTimeout(function() {
433
- video.style.visibility = "hidden";
434
- }, 300);
435
- video.muted = true;
436
- video.volume = 0;
437
- contentVideoHidden = true;
438
- }
439
- }
440
- function showContentVideo() {
441
- if (contentVideoHidden) {
442
- video.style.visibility = "visible";
443
- video.style.transition = "opacity 0.3s ease-in-out";
444
- video.offsetHeight;
445
- video.style.opacity = "1";
446
- video.muted = originalMutedState;
447
- video.volume = originalVolume;
448
- contentVideoHidden = false;
449
- }
450
- }
451
- function createAdVideoElement() {
452
- var adVideo = document.createElement("video");
453
- adVideo.style.position = "absolute";
454
- adVideo.style.top = "0";
455
- adVideo.style.left = "0";
456
- adVideo.style.width = "100%";
457
- adVideo.style.height = "100%";
458
- adVideo.style.objectFit = "contain";
459
- adVideo.style.backgroundColor = "transparent";
460
- adVideo.style.zIndex = "15";
461
- adVideo.playsInline = true;
462
- adVideo.volume = originalVolume;
463
- adVideo.muted = originalMutedState;
464
- adVideo.style.opacity = "0";
465
- adVideo.addEventListener("canplay", function() {
466
- adVideo.style.opacity = "1";
467
- }, {
468
- once: true
469
- });
470
- return adVideo;
471
- }
472
- function emit(event, payload) {
473
- var set = listeners.get(event);
474
- if (!set) return;
475
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
476
- try {
477
- for(var _iterator = Array.from(set)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
478
- var fn = _step.value;
479
- try {
480
- fn(payload);
481
- } catch (unused) {}
482
- }
483
- } catch (err) {
484
- _didIteratorError = true;
485
- _iteratorError = err;
486
- } finally{
487
- try {
488
- if (!_iteratorNormalCompletion && _iterator.return != null) {
489
- _iterator.return();
490
- }
491
- } finally{
492
- if (_didIteratorError) {
493
- throw _iteratorError;
494
- }
495
- }
496
- }
497
- }
498
- function ensureImaLoaded() {
499
- var _window_google;
500
- if (!supportsGoogleIMA()) {
501
- console.warn("[IMA] Google IMA SDK is not supported on this browser. Please use HLS ad player instead.");
502
- return Promise.reject(new Error("Google IMA SDK not supported on this browser"));
503
- }
504
- try {
505
- var _frameEl_getAttribute;
506
- var frameEl = window.frameElement;
507
- var sandboxAttr = (frameEl === null || frameEl === void 0 ? void 0 : (_frameEl_getAttribute = frameEl.getAttribute) === null || _frameEl_getAttribute === void 0 ? void 0 : _frameEl_getAttribute.call(frameEl, "sandbox")) || "";
508
- if (sandboxAttr) {
509
- var tokens = new Set(sandboxAttr.split(/\s+/).map(function(t) {
510
- return t.trim();
511
- }).filter(function(t) {
512
- return t.length > 0;
513
- }));
514
- var allowsScripts = tokens.has("allow-scripts");
515
- if (!allowsScripts) {
516
- console.error("StormcloudVideoPlayer: The host page is inside a sandboxed iframe without 'allow-scripts'. Google IMA cannot run ads within sandboxed frames. Remove the sandbox attribute or include 'allow-scripts allow-same-origin'.");
517
- }
518
- }
519
- } catch (unused) {}
520
- if (typeof window !== "undefined" && ((_window_google = window.google) === null || _window_google === void 0 ? void 0 : _window_google.ima)) return Promise.resolve();
521
- var existing = document.querySelector('script[data-ima="true"]');
522
- if (existing) {
523
- var _window_google1;
524
- if ((_window_google1 = window.google) === null || _window_google1 === void 0 ? void 0 : _window_google1.ima) {
525
- return Promise.resolve();
526
- }
527
- return new Promise(function(resolve, reject) {
528
- var timeout = setTimeout(function() {
529
- reject(new Error("IMA SDK load timeout"));
530
- }, 1e4);
531
- existing.addEventListener("load", function() {
532
- clearTimeout(timeout);
533
- resolve();
534
- });
535
- existing.addEventListener("error", function() {
536
- clearTimeout(timeout);
537
- reject(new Error("IMA SDK load failed"));
538
- });
539
- });
540
- }
541
- return new Promise(function(resolve, reject) {
542
- var script = document.createElement("script");
543
- script.src = "https://imasdk.googleapis.com/js/sdkloader/ima3.js";
544
- script.async = true;
545
- script.defer = true;
546
- script.setAttribute("data-ima", "true");
547
- script.onload = function() {
548
- return resolve();
549
- };
550
- script.onerror = function() {
551
- return reject(new Error("IMA SDK load failed"));
552
- };
553
- document.head.appendChild(script);
554
- });
555
- }
556
- var adsManager;
557
- var adsLoader;
558
- var adDisplayContainer;
559
- var adContainerEl;
560
- var lastAdTagUrl;
561
- var retryAttempts = 0;
562
- var maxRetries = 2;
563
- var backoffBaseMs = 500;
564
- var adsLoadedPromise;
565
- var adsLoadedResolve;
566
- var adsLoadedReject;
567
- function makeAdsRequest(google, vastTagUrl) {
568
- var adsRequest = new google.ima.AdsRequest();
569
- var companionSizes = [
570
- {
571
- width: 728,
572
- height: 90
573
- },
574
- {
575
- width: 300,
576
- height: 250
577
- },
578
- {
579
- width: 180,
580
- height: 150
581
- },
582
- {
583
- width: 120,
584
- height: 60
585
- },
586
- {
587
- width: 88,
588
- height: 31
589
- },
590
- {
591
- width: 300,
592
- height: 60
593
- },
594
- {
595
- width: 300,
596
- height: 100
597
- },
598
- {
599
- width: 320,
600
- height: 50
601
- },
602
- {
603
- width: 468,
604
- height: 60
605
- },
606
- {
607
- width: 300,
608
- height: 600
609
- },
610
- {
611
- width: 160,
612
- height: 600
613
- }
614
- ];
615
- var ciuSzsValue = companionSizes.map(function(size) {
616
- return "fluid|".concat(size.width, "x").concat(size.height);
617
- }).join(",");
618
- var currentLocation = typeof window !== "undefined" ? window.location : null;
619
- var topLocation = typeof window !== "undefined" && window.top ? window.top.location : currentLocation;
620
- var currentUrl = (currentLocation === null || currentLocation === void 0 ? void 0 : currentLocation.href) || "";
621
- var topUrl = (topLocation === null || topLocation === void 0 ? void 0 : topLocation.href) || currentUrl;
622
- var currentDomain = (currentLocation === null || currentLocation === void 0 ? void 0 : currentLocation.hostname) || "";
623
- var modifiedVastTagUrl = vastTagUrl;
624
- try {
625
- var url = new URL(vastTagUrl);
626
- url.searchParams.set("ciu_szs", ciuSzsValue);
627
- if (!url.searchParams.has("mpt")) {
628
- url.searchParams.set("mpt", "h5_vsi");
629
- }
630
- if (!url.searchParams.has("ctv")) {
631
- url.searchParams.set("ctv", "0");
632
- }
633
- if (!url.searchParams.has("gdpr")) {
634
- url.searchParams.set("gdpr", "0");
635
- }
636
- if (!url.searchParams.has("top") && topUrl) {
637
- url.searchParams.set("top", topUrl);
638
- }
639
- if (!url.searchParams.has("loc") && currentUrl) {
640
- url.searchParams.set("loc", currentUrl);
641
- }
642
- if (!url.searchParams.has("cdm") && currentDomain) {
643
- url.searchParams.set("cdm", currentDomain);
644
- }
645
- if (!url.searchParams.has("eoidce")) {
646
- url.searchParams.set("eoidce", "1");
647
- }
648
- if (!url.searchParams.has("fbidx")) {
649
- url.searchParams.set("fbidx", "0");
650
- }
651
- modifiedVastTagUrl = url.toString();
652
- } catch (e) {
653
- var baseUrl = vastTagUrl;
654
- var paramsToRemove = [
655
- "ciu_szs",
656
- "mpt",
657
- "ctv",
658
- "gdpr",
659
- "top",
660
- "loc",
661
- "cdm",
662
- "eoidce",
663
- "fbidx"
664
- ];
665
- paramsToRemove.forEach(function(param) {
666
- if (baseUrl.includes("".concat(param, "="))) {
667
- baseUrl = baseUrl.replace(new RegExp("[?&]".concat(param, "=[^&]*"), "g"), "");
668
- }
669
- });
670
- baseUrl = baseUrl.replace(/[?&]$/, "");
671
- var params = new URLSearchParams();
672
- params.set("ciu_szs", ciuSzsValue);
673
- params.set("mpt", "h5_vsi");
674
- params.set("ctv", "0");
675
- params.set("gdpr", "0");
676
- if (topUrl) params.set("top", topUrl);
677
- if (currentUrl) params.set("loc", currentUrl);
678
- if (currentDomain) params.set("cdm", currentDomain);
679
- params.set("eoidce", "1");
680
- params.set("fbidx", "0");
681
- var separator = baseUrl.includes("?") ? "&" : "?";
682
- modifiedVastTagUrl = "".concat(baseUrl).concat(separator).concat(params.toString());
683
- }
684
- adsRequest.adTagUrl = modifiedVastTagUrl;
685
- var videoWidth = video.offsetWidth || video.clientWidth || 640;
686
- var videoHeight = video.offsetHeight || video.clientHeight || 480;
687
- adsRequest.linearAdSlotWidth = videoWidth;
688
- adsRequest.linearAdSlotHeight = videoHeight;
689
- adsRequest.nonLinearAdSlotWidth = videoWidth;
690
- adsRequest.nonLinearAdSlotHeight = videoHeight;
691
- if (typeof adsRequest.setCompanionSlots === "function") {
692
- try {
693
- var companionSlots = [];
694
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
695
- try {
696
- for(var _iterator = companionSizes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
697
- var size = _step.value;
698
- var slot = new google.ima.CompanionAdSlot();
699
- slot.width = size.width;
700
- slot.height = size.height;
701
- companionSlots.push(slot);
702
- }
703
- } catch (err) {
704
- _didIteratorError = true;
705
- _iteratorError = err;
706
- } finally{
707
- try {
708
- if (!_iteratorNormalCompletion && _iterator.return != null) {
709
- _iterator.return();
710
- }
711
- } finally{
712
- if (_didIteratorError) {
713
- throw _iteratorError;
714
- }
715
- }
716
- }
717
- adsRequest.setCompanionSlots(companionSlots);
718
- } catch (error) {
719
- console.warn("[IMA] Failed to set companion slots:", error);
720
- }
721
- }
722
- if (typeof adsRequest.setAdWillAutoPlay === "function") {
723
- try {
724
- var willAutoPlay = !video.paused || video.autoplay;
725
- adsRequest.setAdWillAutoPlay(willAutoPlay);
726
- } catch (error) {
727
- console.warn("[IMA] Failed to call setAdWillAutoPlay:", error);
728
- }
729
- }
730
- if (typeof adsRequest.setAdWillPlayMuted === "function") {
731
- try {
732
- var willPlayMuted = video.muted || video.volume === 0;
733
- adsRequest.setAdWillPlayMuted(willPlayMuted);
734
- } catch (error) {
735
- console.warn("[IMA] Failed to call setAdWillPlayMuted:", error);
736
- }
737
- }
738
- adsRequest.vastLoadTimeout = 1e4;
739
- adsLoader.requestAds(adsRequest);
740
- }
741
- function ensurePlaceholderContainer() {
742
- var _video_parentElement;
743
- if (adContainerEl) {
744
- return;
745
- }
746
- var container = document.createElement("div");
747
- container.style.position = "absolute";
748
- container.style.left = "0";
749
- container.style.top = "0";
750
- container.style.right = "0";
751
- container.style.bottom = "0";
752
- container.style.display = "none";
753
- container.style.alignItems = "center";
754
- container.style.justifyContent = "center";
755
- container.style.pointerEvents = "none";
756
- container.style.zIndex = "10";
757
- container.style.backgroundColor = "#000";
758
- container.style.transition = "opacity 0.3s ease-in-out";
759
- container.style.opacity = "0";
760
- (_video_parentElement = video.parentElement) === null || _video_parentElement === void 0 ? void 0 : _video_parentElement.appendChild(container);
761
- adContainerEl = container;
762
- }
763
- function destroyAdsManager() {
764
- if (adsManager) {
765
- try {
766
- adsManager.destroy();
767
- } catch (unused) {}
768
- adsManager = void 0;
769
- }
770
- if (adVideoElement) {
771
- adVideoElement.style.opacity = "0";
772
- }
773
- }
774
- function destroyAdsLoader() {
775
- if (adsLoader) {
776
- try {
777
- adsLoader.destroy();
778
- } catch (unused) {}
779
- adsLoader = void 0;
780
- }
781
- }
782
- return {
783
- initialize: function initialize() {
784
- ensureImaLoaded().then(function() {
785
- var google = window.google;
786
- ensurePlaceholderContainer();
787
- if (!adDisplayContainer && adContainerEl) {
788
- if (!adVideoElement) {
789
- adVideoElement = createAdVideoElement();
790
- adContainerEl.appendChild(adVideoElement);
791
- }
792
- adDisplayContainer = new google.ima.AdDisplayContainer(adContainerEl, adVideoElement);
793
- try {
794
- var _adDisplayContainer_initialize;
795
- (_adDisplayContainer_initialize = adDisplayContainer.initialize) === null || _adDisplayContainer_initialize === void 0 ? void 0 : _adDisplayContainer_initialize.call(adDisplayContainer);
796
- } catch (unused) {}
797
- }
798
- }).catch(function() {});
799
- },
800
- requestAds: function requestAds(vastTagUrl) {
801
- return _async_to_generator(function() {
802
- var _$error, _$error1, currentReject, google, container, videoWidth, videoHeight, _$error2, adsLoaderCls, error;
803
- return _ts_generator(this, function(_state) {
804
- switch(_state.label){
805
- case 0:
806
- if (!vastTagUrl || vastTagUrl.trim() === "") {
807
- _$error = new Error("VAST tag URL is empty or undefined");
808
- return [
809
- 2,
810
- Promise.reject(_$error)
811
- ];
812
- }
813
- try {
814
- new URL(vastTagUrl);
815
- } catch (e) {
816
- _$error1 = new Error("Invalid VAST tag URL format: ".concat(vastTagUrl));
817
- return [
818
- 2,
819
- Promise.reject(_$error1)
820
- ];
821
- }
822
- if (adPlaying) {
823
- return [
824
- 2,
825
- Promise.reject(new Error("Ad already playing - cannot request new ads"))
826
- ];
827
- }
828
- destroyAdsManager();
829
- destroyAdsLoader();
830
- adsLoadedReject = void 0;
831
- adsLoadedResolve = void 0;
832
- adsLoadedPromise = new Promise(function(resolve, reject) {
833
- adsLoadedResolve = resolve;
834
- adsLoadedReject = reject;
835
- currentReject = reject;
836
- setTimeout(function() {
837
- if (adsLoadedReject) {
838
- adsLoadedReject(new Error("Ad request timeout"));
839
- adsLoadedReject = void 0;
840
- adsLoadedResolve = void 0;
841
- }
842
- }, 1e4);
843
- });
844
- _state.label = 1;
845
- case 1:
846
- _state.trys.push([
847
- 1,
848
- 3,
849
- ,
850
- 4
851
- ]);
852
- return [
853
- 4,
854
- ensureImaLoaded()
855
- ];
856
- case 2:
857
- _state.sent();
858
- google = window.google;
859
- lastAdTagUrl = vastTagUrl;
860
- retryAttempts = 0;
861
- if (!adDisplayContainer) {
862
- container = document.createElement("div");
863
- container.style.position = "absolute";
864
- container.style.left = "0";
865
- container.style.top = "0";
866
- container.style.right = "0";
867
- container.style.bottom = "0";
868
- container.style.display = "none";
869
- container.style.alignItems = "center";
870
- container.style.justifyContent = "center";
871
- container.style.pointerEvents = "none";
872
- container.style.zIndex = "10";
873
- container.style.backgroundColor = "transparent";
874
- container.style.transition = "opacity 0.3s ease-in-out, background-color 0.3s ease-in-out";
875
- container.style.opacity = "0";
876
- if (!video.parentElement) {
877
- throw new Error("Video element has no parent for ad container");
878
- }
879
- video.parentElement.appendChild(container);
880
- adContainerEl = container;
881
- if (!adVideoElement) {
882
- adVideoElement = createAdVideoElement();
883
- adContainerEl.appendChild(adVideoElement);
884
- }
885
- adDisplayContainer = new google.ima.AdDisplayContainer(container, adVideoElement);
886
- }
887
- videoWidth = video.offsetWidth || video.clientWidth;
888
- videoHeight = video.offsetHeight || video.clientHeight;
889
- if (!videoWidth || !videoHeight || videoWidth === 0 || videoHeight === 0) {
890
- _$error2 = new Error("Invalid video dimensions: ".concat(videoWidth, "x").concat(videoHeight, ". Cannot initialize ads."));
891
- currentReject === null || currentReject === void 0 ? void 0 : currentReject(_$error2);
892
- adsLoadedReject = void 0;
893
- adsLoadedResolve = void 0;
894
- return [
895
- 2,
896
- Promise.reject(_$error2)
897
- ];
898
- }
899
- if (!adsLoader) {
900
- adsLoaderCls = new google.ima.AdsLoader(adDisplayContainer);
901
- adsLoader = adsLoaderCls;
902
- adsLoader.addEventListener(google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, function(evt) {
903
- try {
904
- var adsRenderingSettings = new google.ima.AdsRenderingSettings();
905
- adsRenderingSettings.enablePreloading = true;
906
- adsManager = evt.getAdsManager(video, adsRenderingSettings);
907
- var AdEvent = google.ima.AdEvent.Type;
908
- var AdErrorEvent = google.ima.AdErrorEvent.Type;
909
- adsManager.addEventListener(AdErrorEvent.AD_ERROR, function(errorEvent) {
910
- var _error_getErrorCode, _error_getVastErrorCode, _error_getMessage;
911
- var _$error = errorEvent.getError();
912
- var errorCode = ((_error_getErrorCode = _$error.getErrorCode) === null || _error_getErrorCode === void 0 ? void 0 : _error_getErrorCode.call(_$error)) || "unknown";
913
- var vastErrorCode = ((_error_getVastErrorCode = _$error.getVastErrorCode) === null || _error_getVastErrorCode === void 0 ? void 0 : _error_getVastErrorCode.call(_$error)) || "N/A";
914
- var errorMessage = ((_error_getMessage = _$error.getMessage) === null || _error_getMessage === void 0 ? void 0 : _error_getMessage.call(_$error)) || "Unknown error";
915
- var innerError;
916
- try {
917
- if (typeof _$error.getInnerError === "function") {
918
- var inner = _$error.getInnerError();
919
- if (inner) {
920
- innerError = typeof inner === "string" ? inner : inner.message || String(inner);
921
- }
922
- }
923
- if (!innerError && _$error.cause) {
924
- innerError = typeof _$error.cause === "string" ? _$error.cause : _$error.cause.message || String(_$error.cause);
925
- }
926
- if (!innerError && _$error.innerError) {
927
- innerError = typeof _$error.innerError === "string" ? _$error.innerError : _$error.innerError.message || String(_$error.innerError);
928
- }
929
- } catch (e) {}
930
- var isNoFill = errorCode === 303 || vastErrorCode === 303;
931
- destroyAdsManager();
932
- adPlaying = false;
933
- setAdPlayingFlag(false);
934
- if (adContainerEl) {
935
- adContainerEl.style.opacity = "0";
936
- adContainerEl.style.backgroundColor = "transparent";
937
- setTimeout(function() {
938
- if (adContainerEl) {
939
- adContainerEl.style.pointerEvents = "none";
940
- adContainerEl.style.display = "none";
941
- }
942
- }, 300);
943
- }
944
- hideContentVideo();
945
- if (adsLoadedReject) {
946
- adsLoadedReject(new Error("Ad playback error"));
947
- adsLoadedReject = void 0;
948
- adsLoadedResolve = void 0;
949
- }
950
- if (lastAdTagUrl && retryAttempts < maxRetries && !isNoFill) {
951
- var delay = backoffBaseMs * Math.pow(2, retryAttempts++);
952
- window.setTimeout(function() {
953
- try {
954
- makeAdsRequest(google, lastAdTagUrl);
955
- } catch (unused) {}
956
- }, delay);
957
- } else {
958
- emit("ad_error", {
959
- code: errorCode,
960
- vastErrorCode: vastErrorCode,
961
- message: errorMessage,
962
- cause: innerError,
963
- isNoFill: isNoFill
964
- });
965
- if (!(options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds)) {
966
- if (video.paused) {
967
- var _video_play;
968
- (_video_play = video.play()) === null || _video_play === void 0 ? void 0 : _video_play.catch(function() {});
969
- }
970
- }
971
- }
972
- });
973
- adsManager.addEventListener(AdEvent.CONTENT_PAUSE_REQUESTED, function() {
974
- if (!(options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds)) {
975
- video.pause();
976
- }
977
- adPlaying = true;
978
- setAdPlayingFlag(true);
979
- var adVolume = originalMutedState ? 0 : originalVolume;
980
- if (adVideoElement) {
981
- adVideoElement.volume = originalVolume;
982
- adVideoElement.muted = originalMutedState;
983
- }
984
- if (adsManager) {
985
- try {
986
- adsManager.setVolume(adVolume);
987
- } catch (unused) {}
988
- }
989
- emit("content_pause");
990
- });
991
- adsManager.addEventListener(AdEvent.STARTED, function() {
992
- setAdPlayingFlag(true);
993
- hideContentVideo();
994
- if (adVideoElement) {
995
- var adVolume = originalVolume;
996
- adVideoElement.volume = adVolume;
997
- adVideoElement.muted = originalMutedState;
998
- if (adsManager) {
999
- try {
1000
- adsManager.setVolume(originalMutedState ? 0 : adVolume);
1001
- } catch (unused) {}
1002
- }
1003
- }
1004
- if (adContainerEl) {
1005
- adContainerEl.style.pointerEvents = "auto";
1006
- adContainerEl.style.display = "flex";
1007
- adContainerEl.style.backgroundColor = "#000";
1008
- adContainerEl.offsetHeight;
1009
- adContainerEl.style.opacity = "1";
1010
- }
1011
- emit("ad_impression");
1012
- });
1013
- adsManager.addEventListener(AdEvent.CONTENT_RESUME_REQUESTED, function() {
1014
- adPlaying = false;
1015
- setAdPlayingFlag(false);
1016
- hideContentVideo();
1017
- emit("content_resume");
1018
- });
1019
- adsManager.addEventListener(AdEvent.ALL_ADS_COMPLETED, function() {
1020
- adPlaying = false;
1021
- setAdPlayingFlag(false);
1022
- if (adContainerEl) {
1023
- adContainerEl.style.opacity = "0";
1024
- adContainerEl.style.backgroundColor = "transparent";
1025
- setTimeout(function() {
1026
- if (adContainerEl) {
1027
- adContainerEl.style.pointerEvents = "none";
1028
- adContainerEl.style.display = "none";
1029
- }
1030
- }, 300);
1031
- }
1032
- hideContentVideo();
1033
- emit("all_ads_completed");
1034
- });
1035
- if (adsLoadedResolve) {
1036
- adsLoadedResolve();
1037
- adsLoadedResolve = void 0;
1038
- adsLoadedReject = void 0;
1039
- }
1040
- } catch (e) {
1041
- console.error("[IMA] Error setting up ads manager:", e);
1042
- adPlaying = false;
1043
- setAdPlayingFlag(false);
1044
- if (adContainerEl) {
1045
- adContainerEl.style.opacity = "0";
1046
- adContainerEl.style.backgroundColor = "transparent";
1047
- setTimeout(function() {
1048
- if (adContainerEl) {
1049
- adContainerEl.style.pointerEvents = "none";
1050
- adContainerEl.style.display = "none";
1051
- }
1052
- }, 300);
1053
- }
1054
- hideContentVideo();
1055
- if (adsLoadedReject) {
1056
- adsLoadedReject(new Error("Failed to setup ads manager"));
1057
- adsLoadedReject = void 0;
1058
- adsLoadedResolve = void 0;
1059
- }
1060
- emit("ad_error");
1061
- }
1062
- }, false);
1063
- adsLoader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, function(adErrorEvent) {
1064
- var _error_getErrorCode, _error_getVastErrorCode, _error_getMessage;
1065
- var _$error = adErrorEvent.getError();
1066
- var errorCode = ((_error_getErrorCode = _$error.getErrorCode) === null || _error_getErrorCode === void 0 ? void 0 : _error_getErrorCode.call(_$error)) || "unknown";
1067
- var vastErrorCode = ((_error_getVastErrorCode = _$error.getVastErrorCode) === null || _error_getVastErrorCode === void 0 ? void 0 : _error_getVastErrorCode.call(_$error)) || "N/A";
1068
- var errorMessage = ((_error_getMessage = _$error.getMessage) === null || _error_getMessage === void 0 ? void 0 : _error_getMessage.call(_$error)) || "Unknown error";
1069
- var innerError;
1070
- try {
1071
- if (typeof _$error.getInnerError === "function") {
1072
- var inner = _$error.getInnerError();
1073
- if (inner) {
1074
- innerError = typeof inner === "string" ? inner : inner.message || String(inner);
1075
- }
1076
- }
1077
- if (!innerError && _$error.cause) {
1078
- innerError = typeof _$error.cause === "string" ? _$error.cause : _$error.cause.message || String(_$error.cause);
1079
- }
1080
- if (!innerError && _$error.innerError) {
1081
- innerError = typeof _$error.innerError === "string" ? _$error.innerError : _$error.innerError.message || String(_$error.innerError);
1082
- }
1083
- } catch (e) {}
1084
- var isNoFill = errorCode === 303 || vastErrorCode === 303;
1085
- adPlaying = false;
1086
- setAdPlayingFlag(false);
1087
- if (adContainerEl) {
1088
- adContainerEl.style.opacity = "0";
1089
- adContainerEl.style.backgroundColor = "transparent";
1090
- setTimeout(function() {
1091
- if (adContainerEl) {
1092
- adContainerEl.style.pointerEvents = "none";
1093
- adContainerEl.style.display = "none";
1094
- }
1095
- }, 300);
1096
- }
1097
- hideContentVideo();
1098
- if (adsLoadedReject) {
1099
- adsLoadedReject(new Error(isNoFill ? "No ads available" : "Ads loader error"));
1100
- adsLoadedReject = void 0;
1101
- adsLoadedResolve = void 0;
1102
- }
1103
- emit("ad_error", {
1104
- code: errorCode,
1105
- vastErrorCode: vastErrorCode,
1106
- message: errorMessage,
1107
- isNoFill: isNoFill,
1108
- cause: innerError
1109
- });
1110
- }, false);
1111
- }
1112
- makeAdsRequest(google, vastTagUrl);
1113
- return [
1114
- 2,
1115
- adsLoadedPromise
1116
- ];
1117
- case 3:
1118
- error = _state.sent();
1119
- console.error("[IMA] Failed to request ads:", error);
1120
- currentReject === null || currentReject === void 0 ? void 0 : currentReject(error);
1121
- adsLoadedReject = void 0;
1122
- adsLoadedResolve = void 0;
1123
- return [
1124
- 2,
1125
- Promise.reject(error)
1126
- ];
1127
- case 4:
1128
- return [
1129
- 2
1130
- ];
1131
- }
1132
- });
1133
- })();
1134
- },
1135
- play: function play() {
1136
- return _async_to_generator(function() {
1137
- var _window_google, width, height, adVolume, _video_play;
1138
- return _ts_generator(this, function(_state) {
1139
- if (!((_window_google = window.google) === null || _window_google === void 0 ? void 0 : _window_google.ima) || !adDisplayContainer) {
1140
- return [
1141
- 2,
1142
- Promise.reject(new Error("IMA SDK not available"))
1143
- ];
1144
- }
1145
- if (!adsManager) {
1146
- return [
1147
- 2,
1148
- Promise.reject(new Error("No ads manager"))
1149
- ];
1150
- }
1151
- try {
1152
- width = video.clientWidth || 640;
1153
- height = video.clientHeight || 480;
1154
- adsManager.init(width, height, window.google.ima.ViewMode.NORMAL);
1155
- adPlaying = true;
1156
- adVolume = originalVolume;
1157
- if (adVideoElement) {
1158
- adVideoElement.volume = adVolume;
1159
- adVideoElement.muted = originalMutedState;
1160
- }
1161
- try {
1162
- adsManager.setVolume(originalMutedState ? 0 : adVolume);
1163
- } catch (unused) {}
1164
- adsManager.start();
1165
- return [
1166
- 2,
1167
- Promise.resolve()
1168
- ];
1169
- } catch (error) {
1170
- adPlaying = false;
1171
- setAdPlayingFlag(false);
1172
- if (!(options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds)) {
1173
- ;
1174
- (_video_play = video.play()) === null || _video_play === void 0 ? void 0 : _video_play.catch(function() {});
1175
- }
1176
- return [
1177
- 2,
1178
- Promise.reject(error)
1179
- ];
1180
- }
1181
- return [
1182
- 2
1183
- ];
1184
- });
1185
- })();
1186
- },
1187
- pause: function pause() {
1188
- if (!adsManager || !adPlaying) {
1189
- return;
1190
- }
1191
- try {
1192
- if (adVideoElement && !adVideoElement.paused) {
1193
- adVideoElement.pause();
1194
- }
1195
- if (adsManager && typeof adsManager.pause === "function") {
1196
- adsManager.pause();
1197
- }
1198
- } catch (error) {
1199
- console.warn("[IMA] Error pausing ad:", error);
1200
- }
1201
- },
1202
- resume: function resume() {
1203
- if (!adsManager || !adPlaying) {
1204
- return;
1205
- }
1206
- try {
1207
- if (adVideoElement && adVideoElement.paused) {
1208
- adVideoElement.play().catch(function() {});
1209
- }
1210
- if (adsManager && typeof adsManager.resume === "function") {
1211
- adsManager.resume();
1212
- }
1213
- } catch (error) {
1214
- console.warn("[IMA] Error resuming ad:", error);
1215
- }
1216
- },
1217
- stop: function stop() {
1218
- return _async_to_generator(function() {
1219
- var _adsManager_stop;
1220
- return _ts_generator(this, function(_state) {
1221
- adPlaying = false;
1222
- setAdPlayingFlag(false);
1223
- if (adContainerEl) {
1224
- adContainerEl.style.opacity = "0";
1225
- adContainerEl.style.backgroundColor = "transparent";
1226
- setTimeout(function() {
1227
- if (adContainerEl) {
1228
- adContainerEl.style.pointerEvents = "none";
1229
- adContainerEl.style.display = "none";
1230
- }
1231
- }, 300);
1232
- }
1233
- showContentVideo();
1234
- if (options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds) {
1235
- if (video.paused) {
1236
- console.log("[IMA] Content video paused in live mode on stop, resuming playback");
1237
- video.play().catch(function() {});
1238
- }
1239
- } else if (video.paused) {
1240
- video.play().catch(function() {});
1241
- }
1242
- try {
1243
- ;
1244
- adsManager === null || adsManager === void 0 ? void 0 : (_adsManager_stop = adsManager.stop) === null || _adsManager_stop === void 0 ? void 0 : _adsManager_stop.call(adsManager);
1245
- } catch (unused) {}
1246
- destroyAdsManager();
1247
- return [
1248
- 2
1249
- ];
1250
- });
1251
- })();
1252
- },
1253
- destroy: function destroy() {
1254
- destroyAdsManager();
1255
- adPlaying = false;
1256
- setAdPlayingFlag(false);
1257
- if (adContainerEl) {
1258
- adContainerEl.style.backgroundColor = "#000";
1259
- adContainerEl.style.opacity = "1";
1260
- adContainerEl.style.pointerEvents = "none";
1261
- setTimeout(function() {
1262
- if (adContainerEl) {
1263
- adContainerEl.style.display = "none";
1264
- if (adContainerEl.parentElement) {
1265
- adContainerEl.parentElement.removeChild(adContainerEl);
1266
- }
1267
- adContainerEl = void 0;
1268
- adVideoElement = void 0;
1269
- }
1270
- }, 500);
1271
- }
1272
- showContentVideo();
1273
- try {
1274
- var _adsLoader_destroy;
1275
- adsLoader === null || adsLoader === void 0 ? void 0 : (_adsLoader_destroy = adsLoader.destroy) === null || _adsLoader_destroy === void 0 ? void 0 : _adsLoader_destroy.call(adsLoader);
1276
- } catch (unused) {}
1277
- adDisplayContainer = void 0;
1278
- adsLoader = void 0;
1279
- contentVideoHidden = false;
1280
- },
1281
- isAdPlaying: function isAdPlaying() {
1282
- return adPlaying;
1283
- },
1284
- resize: function resize(width, height) {
1285
- var _window_google;
1286
- if (!adsManager || !((_window_google = window.google) === null || _window_google === void 0 ? void 0 : _window_google.ima)) {
1287
- console.warn("[IMA] Cannot resize: No ads manager or IMA SDK available");
1288
- return;
1289
- }
1290
- try {
1291
- console.log("[IMA] Resizing ads manager to ".concat(width, "x").concat(height));
1292
- adsManager.resize(width, height, window.google.ima.ViewMode.NORMAL);
1293
- } catch (error) {
1294
- console.warn("[IMA] Error resizing ads manager:", error);
1295
- }
1296
- },
1297
- on: function on(event, listener) {
1298
- if (!listeners.has(event)) listeners.set(event, /* @__PURE__ */ new Set());
1299
- listeners.get(event).add(listener);
1300
- },
1301
- off: function off(event, listener) {
1302
- var _listeners_get;
1303
- (_listeners_get = listeners.get(event)) === null || _listeners_get === void 0 ? void 0 : _listeners_get.delete(listener);
1304
- },
1305
- updateOriginalMutedState: function updateOriginalMutedState(muted, volume) {
1306
- var nextVolume = typeof volume === "number" && !Number.isNaN(volume) ? Math.max(0, Math.min(1, volume)) : originalVolume;
1307
- originalMutedState = muted;
1308
- originalVolume = nextVolume;
1309
- },
1310
- getOriginalMutedState: function getOriginalMutedState() {
1311
- return originalMutedState;
1312
- },
1313
- getOriginalVolume: function getOriginalVolume() {
1314
- return originalVolume;
1315
- },
1316
- setAdVolume: function setAdVolume(volume) {
1317
- var clampedVolume = Math.max(0, Math.min(1, volume));
1318
- if (adVideoElement && adPlaying) {
1319
- adVideoElement.volume = clampedVolume;
1320
- adVideoElement.muted = clampedVolume === 0;
1321
- }
1322
- if (adsManager && adPlaying) {
1323
- try {
1324
- adsManager.setVolume(clampedVolume);
1325
- } catch (unused) {}
1326
- }
1327
- },
1328
- getAdVolume: function getAdVolume() {
1329
- if (adVideoElement && adPlaying) {
1330
- return adVideoElement.volume;
1331
- }
1332
- if (adsManager && adPlaying) {
1333
- try {
1334
- return adsManager.getVolume();
1335
- } catch (error) {
1336
- console.warn("[IMA] Failed to get ad volume:", error);
1337
- return 1;
1338
- }
1339
- }
1340
- return 1;
1341
- },
1342
- showPlaceholder: function showPlaceholder() {
1343
- ensurePlaceholderContainer();
1344
- hideContentVideo();
1345
- if (adContainerEl) {
1346
- var wasHidden = adContainerEl.style.display === "none" || adContainerEl.style.opacity === "0";
1347
- if (wasHidden) {
1348
- adContainerEl.style.transition = "none";
1349
- } else {
1350
- adContainerEl.style.transition = "opacity 0.3s ease-in-out";
1351
- }
1352
- adContainerEl.style.backgroundColor = "#000";
1353
- adContainerEl.style.display = "flex";
1354
- adContainerEl.offsetHeight;
1355
- adContainerEl.style.opacity = "1";
1356
- adContainerEl.style.pointerEvents = "auto";
1357
- if (wasHidden) {
1358
- requestAnimationFrame(function() {
1359
- if (adContainerEl) {
1360
- adContainerEl.style.transition = "opacity 0.3s ease-in-out";
1361
- }
1362
- });
1363
- }
1364
- }
1365
- },
1366
- hidePlaceholder: function hidePlaceholder() {
1367
- if (adContainerEl) {
1368
- adContainerEl.style.opacity = "0";
1369
- setTimeout(function() {
1370
- if (adContainerEl) {
1371
- adContainerEl.style.display = "none";
1372
- adContainerEl.style.pointerEvents = "none";
1373
- adContainerEl.style.backgroundColor = "#000";
1374
- }
1375
- }, 300);
1376
- }
1377
- }
1378
- };
1379
- }
1380
- // Annotate the CommonJS export names for ESM import in node:
1381
- 0 && (module.exports = {
1382
- createImaController: createImaController
1383
- });
1384
- //# sourceMappingURL=ima.cjs.map