stormcloud-video-player 0.3.16 → 0.4.0
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/README.md +158 -112
- package/dist/stormcloud-vp.min.js +1 -10
- package/lib/index.cjs +3805 -6041
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +19 -102
- package/lib/index.d.ts +19 -102
- package/lib/index.js +3814 -6042
- package/lib/index.js.map +1 -1
- package/lib/player/StormcloudVideoPlayer.cjs +1497 -4885
- package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/player/StormcloudVideoPlayer.d.cts +9 -78
- package/lib/players/FilePlayer.cjs.map +1 -1
- package/lib/players/HlsPlayer.cjs +1497 -4885
- package/lib/players/HlsPlayer.cjs.map +1 -1
- package/lib/players/HlsPlayer.d.cts +1 -1
- package/lib/players/index.cjs +1499 -4887
- package/lib/players/index.cjs.map +1 -1
- package/lib/sdk/adstormPlayer.cjs +908 -0
- package/lib/sdk/adstormPlayer.cjs.map +1 -0
- package/lib/sdk/adstormPlayer.d.cts +9 -0
- package/lib/sdk/hlsAdPlayer.cjs +84 -74
- package/lib/sdk/hlsAdPlayer.cjs.map +1 -1
- package/lib/sdk/hlsAdPlayer.d.cts +2 -2
- package/lib/{types-CryTJVCC.d.cts → types-Ca4ZDaWw.d.cts} +3 -8
- package/lib/ui/StormcloudVideoPlayer.cjs +1499 -4895
- package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/ui/StormcloudVideoPlayer.d.cts +1 -1
- package/lib/utils/browserCompat.cjs +1 -52
- package/lib/utils/browserCompat.cjs.map +1 -1
- package/lib/utils/browserCompat.d.cts +1 -6
- package/lib/utils/polyfills.cjs.map +1 -1
- package/lib/utils/tracking.cjs.map +1 -1
- package/lib/utils/tracking.d.cts +1 -1
- package/package.json +5 -1
- package/rollup.config.js +22 -0
- package/lib/sdk/ima.cjs +0 -1100
- package/lib/sdk/ima.cjs.map +0 -1
- package/lib/sdk/ima.d.cts +0 -12
package/lib/sdk/ima.cjs
DELETED
|
@@ -1,1100 +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);
|
|
45
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
46
|
-
return this;
|
|
47
|
-
}), g;
|
|
48
|
-
function verb(n) {
|
|
49
|
-
return function(v) {
|
|
50
|
-
return step([
|
|
51
|
-
n,
|
|
52
|
-
v
|
|
53
|
-
]);
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
function step(op) {
|
|
57
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
58
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
59
|
-
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;
|
|
60
|
-
if (y = 0, t) op = [
|
|
61
|
-
op[0] & 2,
|
|
62
|
-
t.value
|
|
63
|
-
];
|
|
64
|
-
switch(op[0]){
|
|
65
|
-
case 0:
|
|
66
|
-
case 1:
|
|
67
|
-
t = op;
|
|
68
|
-
break;
|
|
69
|
-
case 4:
|
|
70
|
-
_.label++;
|
|
71
|
-
return {
|
|
72
|
-
value: op[1],
|
|
73
|
-
done: false
|
|
74
|
-
};
|
|
75
|
-
case 5:
|
|
76
|
-
_.label++;
|
|
77
|
-
y = op[1];
|
|
78
|
-
op = [
|
|
79
|
-
0
|
|
80
|
-
];
|
|
81
|
-
continue;
|
|
82
|
-
case 7:
|
|
83
|
-
op = _.ops.pop();
|
|
84
|
-
_.trys.pop();
|
|
85
|
-
continue;
|
|
86
|
-
default:
|
|
87
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
88
|
-
_ = 0;
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
92
|
-
_.label = op[1];
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
96
|
-
_.label = t[1];
|
|
97
|
-
t = op;
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
if (t && _.label < t[2]) {
|
|
101
|
-
_.label = t[2];
|
|
102
|
-
_.ops.push(op);
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
if (t[2]) _.ops.pop();
|
|
106
|
-
_.trys.pop();
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
op = body.call(thisArg, _);
|
|
110
|
-
} catch (e) {
|
|
111
|
-
op = [
|
|
112
|
-
6,
|
|
113
|
-
e
|
|
114
|
-
];
|
|
115
|
-
y = 0;
|
|
116
|
-
} finally{
|
|
117
|
-
f = t = 0;
|
|
118
|
-
}
|
|
119
|
-
if (op[0] & 5) throw op[1];
|
|
120
|
-
return {
|
|
121
|
-
value: op[0] ? op[1] : void 0,
|
|
122
|
-
done: true
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
var __defProp = Object.defineProperty;
|
|
127
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
128
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
129
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
130
|
-
var __export = function(target, all) {
|
|
131
|
-
for(var name in all)__defProp(target, name, {
|
|
132
|
-
get: all[name],
|
|
133
|
-
enumerable: true
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
var __copyProps = function(to, from, except, desc) {
|
|
137
|
-
if (from && (typeof from === "undefined" ? "undefined" : _type_of(from)) === "object" || typeof from === "function") {
|
|
138
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
139
|
-
try {
|
|
140
|
-
var _loop = function() {
|
|
141
|
-
var key = _step.value;
|
|
142
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
143
|
-
get: function() {
|
|
144
|
-
return from[key];
|
|
145
|
-
},
|
|
146
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
147
|
-
});
|
|
148
|
-
};
|
|
149
|
-
for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
150
|
-
} catch (err) {
|
|
151
|
-
_didIteratorError = true;
|
|
152
|
-
_iteratorError = err;
|
|
153
|
-
} finally{
|
|
154
|
-
try {
|
|
155
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
156
|
-
_iterator.return();
|
|
157
|
-
}
|
|
158
|
-
} finally{
|
|
159
|
-
if (_didIteratorError) {
|
|
160
|
-
throw _iteratorError;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return to;
|
|
166
|
-
};
|
|
167
|
-
var __toCommonJS = function(mod) {
|
|
168
|
-
return __copyProps(__defProp({}, "__esModule", {
|
|
169
|
-
value: true
|
|
170
|
-
}), mod);
|
|
171
|
-
};
|
|
172
|
-
// src/sdk/ima.ts
|
|
173
|
-
var ima_exports = {};
|
|
174
|
-
__export(ima_exports, {
|
|
175
|
-
createImaController: function() {
|
|
176
|
-
return createImaController;
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
module.exports = __toCommonJS(ima_exports);
|
|
180
|
-
// src/utils/browserCompat.ts
|
|
181
|
-
function getChromeVersion(ua) {
|
|
182
|
-
var match = ua.match(/Chrome\/(\d+)/);
|
|
183
|
-
return match && match[1] ? parseInt(match[1], 10) : 0;
|
|
184
|
-
}
|
|
185
|
-
function getWebKitVersion(ua) {
|
|
186
|
-
var match = ua.match(/AppleWebKit\/(\d+)/);
|
|
187
|
-
return match && match[1] ? parseInt(match[1], 10) : 0;
|
|
188
|
-
}
|
|
189
|
-
function getPlatform() {
|
|
190
|
-
var _navigator_userAgentData;
|
|
191
|
-
if ("userAgentData" in navigator && ((_navigator_userAgentData = navigator.userAgentData) === null || _navigator_userAgentData === void 0 ? void 0 : _navigator_userAgentData.platform)) {
|
|
192
|
-
return navigator.userAgentData.platform;
|
|
193
|
-
}
|
|
194
|
-
var ua = navigator.userAgent;
|
|
195
|
-
if (/Mac|iPhone|iPad|iPod/i.test(ua)) {
|
|
196
|
-
return /iPhone|iPad|iPod/i.test(ua) ? "iPhone" : "MacIntel";
|
|
197
|
-
}
|
|
198
|
-
if (/Win/i.test(ua)) {
|
|
199
|
-
return "Win32";
|
|
200
|
-
}
|
|
201
|
-
if (/Linux/i.test(ua)) {
|
|
202
|
-
return /Android/i.test(ua) ? "Linux armv8l" : "Linux x86_64";
|
|
203
|
-
}
|
|
204
|
-
if (/CrOS/i.test(ua)) {
|
|
205
|
-
return "CrOS";
|
|
206
|
-
}
|
|
207
|
-
return navigator.platform || "Unknown";
|
|
208
|
-
}
|
|
209
|
-
function detectBrowser() {
|
|
210
|
-
var ua = navigator.userAgent;
|
|
211
|
-
var platform = getPlatform();
|
|
212
|
-
var name = "Unknown";
|
|
213
|
-
var version = "0";
|
|
214
|
-
var majorVersion = 0;
|
|
215
|
-
var isSmartTV = false;
|
|
216
|
-
var isLegacyTV = false;
|
|
217
|
-
var supportsIMA = true;
|
|
218
|
-
var supportsModernJS = true;
|
|
219
|
-
var recommendedAdPlayer = "ima";
|
|
220
|
-
if (/Web0S|webOS/i.test(ua)) {
|
|
221
|
-
name = "LG WebOS";
|
|
222
|
-
isSmartTV = true;
|
|
223
|
-
var match = ua.match(/Web0S[/\s]*([\d.]+)/i);
|
|
224
|
-
version = match && match[1] ? match[1] : "Unknown";
|
|
225
|
-
if (version !== "Unknown") {
|
|
226
|
-
var parts = version.split(".");
|
|
227
|
-
majorVersion = parts[0] ? parseInt(parts[0], 10) : 0;
|
|
228
|
-
}
|
|
229
|
-
} else if (/Tizen/i.test(ua)) {
|
|
230
|
-
name = "Samsung Tizen";
|
|
231
|
-
isSmartTV = true;
|
|
232
|
-
var match1 = ua.match(/Tizen[/\s]*([\d.]+)/i);
|
|
233
|
-
version = match1 && match1[1] ? match1[1] : "Unknown";
|
|
234
|
-
if (version !== "Unknown") {
|
|
235
|
-
var parts1 = version.split(".");
|
|
236
|
-
majorVersion = parts1[0] ? parseInt(parts1[0], 10) : 0;
|
|
237
|
-
}
|
|
238
|
-
} else if (/SMART-TV|SmartTV/i.test(ua)) {
|
|
239
|
-
name = "Smart TV";
|
|
240
|
-
isSmartTV = true;
|
|
241
|
-
} else if (/NetCast/i.test(ua)) {
|
|
242
|
-
name = "LG NetCast";
|
|
243
|
-
isSmartTV = true;
|
|
244
|
-
isLegacyTV = true;
|
|
245
|
-
} else if (/BRAVIA/i.test(ua)) {
|
|
246
|
-
name = "Sony BRAVIA";
|
|
247
|
-
isSmartTV = true;
|
|
248
|
-
}
|
|
249
|
-
var chromeVersion = getChromeVersion(ua);
|
|
250
|
-
var webkitVersion = getWebKitVersion(ua);
|
|
251
|
-
if (chromeVersion > 0) {
|
|
252
|
-
if (!isSmartTV) {
|
|
253
|
-
name = "Chrome";
|
|
254
|
-
version = chromeVersion.toString();
|
|
255
|
-
majorVersion = chromeVersion;
|
|
256
|
-
}
|
|
257
|
-
if (chromeVersion < 50) {
|
|
258
|
-
supportsIMA = false;
|
|
259
|
-
supportsModernJS = false;
|
|
260
|
-
isLegacyTV = true;
|
|
261
|
-
recommendedAdPlayer = "hls";
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
if (webkitVersion > 0 && webkitVersion < 600) {
|
|
265
|
-
supportsModernJS = false;
|
|
266
|
-
if (isSmartTV) {
|
|
267
|
-
isLegacyTV = true;
|
|
268
|
-
supportsIMA = false;
|
|
269
|
-
recommendedAdPlayer = "hls";
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
if (typeof Promise === "undefined" || typeof Map === "undefined" || typeof Set === "undefined") {
|
|
273
|
-
supportsModernJS = false;
|
|
274
|
-
supportsIMA = false;
|
|
275
|
-
recommendedAdPlayer = "hls";
|
|
276
|
-
}
|
|
277
|
-
if (typeof URLSearchParams === "undefined") {
|
|
278
|
-
supportsModernJS = false;
|
|
279
|
-
}
|
|
280
|
-
return {
|
|
281
|
-
name: name,
|
|
282
|
-
version: version,
|
|
283
|
-
majorVersion: majorVersion,
|
|
284
|
-
isSmartTV: isSmartTV,
|
|
285
|
-
isLegacyTV: isLegacyTV,
|
|
286
|
-
platform: platform,
|
|
287
|
-
supportsIMA: supportsIMA,
|
|
288
|
-
supportsModernJS: supportsModernJS,
|
|
289
|
-
recommendedAdPlayer: recommendedAdPlayer
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
function supportsGoogleIMA() {
|
|
293
|
-
var browser = detectBrowser();
|
|
294
|
-
if (browser.isLegacyTV) {
|
|
295
|
-
return false;
|
|
296
|
-
}
|
|
297
|
-
if (typeof document === "undefined" || typeof document.createElement !== "function") {
|
|
298
|
-
return false;
|
|
299
|
-
}
|
|
300
|
-
try {
|
|
301
|
-
var video = document.createElement("video");
|
|
302
|
-
if (!video) {
|
|
303
|
-
return false;
|
|
304
|
-
}
|
|
305
|
-
} catch (e) {
|
|
306
|
-
return false;
|
|
307
|
-
}
|
|
308
|
-
if (typeof Promise === "undefined") {
|
|
309
|
-
return false;
|
|
310
|
-
}
|
|
311
|
-
return browser.supportsIMA;
|
|
312
|
-
}
|
|
313
|
-
// src/sdk/ima.ts
|
|
314
|
-
function createImaController(video, options) {
|
|
315
|
-
var adPlaying = false;
|
|
316
|
-
var contentVideoHidden = false;
|
|
317
|
-
var originalMutedState = false;
|
|
318
|
-
var originalVolume = typeof video.volume === "number" && !Number.isNaN(video.volume) ? Math.max(0, Math.min(1, video.volume)) : 1;
|
|
319
|
-
var listeners = /* @__PURE__ */ new Map();
|
|
320
|
-
var preloadedVast = /* @__PURE__ */ new Map();
|
|
321
|
-
var preloadingVast = /* @__PURE__ */ new Map();
|
|
322
|
-
var adVideoElement;
|
|
323
|
-
function setAdPlayingFlag(isPlaying) {
|
|
324
|
-
if (isPlaying) {
|
|
325
|
-
video.dataset.stormcloudAdPlaying = "true";
|
|
326
|
-
} else {
|
|
327
|
-
delete video.dataset.stormcloudAdPlaying;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
function hideContentVideo() {
|
|
331
|
-
if (!contentVideoHidden) {
|
|
332
|
-
video.style.transition = "opacity 0.3s ease-in-out";
|
|
333
|
-
video.style.opacity = "0";
|
|
334
|
-
setTimeout(function() {
|
|
335
|
-
video.style.visibility = "hidden";
|
|
336
|
-
}, 300);
|
|
337
|
-
video.muted = true;
|
|
338
|
-
video.volume = 0;
|
|
339
|
-
contentVideoHidden = true;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
function showContentVideo() {
|
|
343
|
-
if (contentVideoHidden) {
|
|
344
|
-
video.style.visibility = "visible";
|
|
345
|
-
video.style.transition = "opacity 0.3s ease-in-out";
|
|
346
|
-
video.offsetHeight;
|
|
347
|
-
video.style.opacity = "1";
|
|
348
|
-
video.muted = originalMutedState;
|
|
349
|
-
video.volume = originalVolume;
|
|
350
|
-
contentVideoHidden = false;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
function createAdVideoElement() {
|
|
354
|
-
var adVideo = document.createElement("video");
|
|
355
|
-
adVideo.style.position = "absolute";
|
|
356
|
-
adVideo.style.top = "0";
|
|
357
|
-
adVideo.style.left = "0";
|
|
358
|
-
adVideo.style.width = "100%";
|
|
359
|
-
adVideo.style.height = "100%";
|
|
360
|
-
adVideo.style.objectFit = "contain";
|
|
361
|
-
adVideo.style.backgroundColor = "transparent";
|
|
362
|
-
adVideo.style.zIndex = "15";
|
|
363
|
-
adVideo.playsInline = true;
|
|
364
|
-
adVideo.muted = false;
|
|
365
|
-
adVideo.volume = originalMutedState ? 0 : originalVolume;
|
|
366
|
-
adVideo.style.opacity = "0";
|
|
367
|
-
adVideo.addEventListener("canplay", function() {
|
|
368
|
-
adVideo.style.opacity = "1";
|
|
369
|
-
}, {
|
|
370
|
-
once: true
|
|
371
|
-
});
|
|
372
|
-
return adVideo;
|
|
373
|
-
}
|
|
374
|
-
function emit(event, payload) {
|
|
375
|
-
var set = listeners.get(event);
|
|
376
|
-
if (!set) return;
|
|
377
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
378
|
-
try {
|
|
379
|
-
for(var _iterator = Array.from(set)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
380
|
-
var fn = _step.value;
|
|
381
|
-
try {
|
|
382
|
-
fn(payload);
|
|
383
|
-
} catch (e) {}
|
|
384
|
-
}
|
|
385
|
-
} catch (err) {
|
|
386
|
-
_didIteratorError = true;
|
|
387
|
-
_iteratorError = err;
|
|
388
|
-
} finally{
|
|
389
|
-
try {
|
|
390
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
391
|
-
_iterator.return();
|
|
392
|
-
}
|
|
393
|
-
} finally{
|
|
394
|
-
if (_didIteratorError) {
|
|
395
|
-
throw _iteratorError;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
function ensureImaLoaded() {
|
|
401
|
-
var _window_google;
|
|
402
|
-
if (!supportsGoogleIMA()) {
|
|
403
|
-
console.warn("[IMA] Google IMA SDK is not supported on this browser. Please use HLS ad player instead.");
|
|
404
|
-
return Promise.reject(new Error("Google IMA SDK not supported on this browser"));
|
|
405
|
-
}
|
|
406
|
-
try {
|
|
407
|
-
var _frameEl_getAttribute;
|
|
408
|
-
var frameEl = window.frameElement;
|
|
409
|
-
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")) || "";
|
|
410
|
-
if (sandboxAttr) {
|
|
411
|
-
var tokens = new Set(sandboxAttr.split(/\s+/).map(function(t) {
|
|
412
|
-
return t.trim();
|
|
413
|
-
}).filter(function(t) {
|
|
414
|
-
return t.length > 0;
|
|
415
|
-
}));
|
|
416
|
-
var allowsScripts = tokens.has("allow-scripts");
|
|
417
|
-
if (!allowsScripts) {
|
|
418
|
-
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'.");
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
} catch (e) {}
|
|
422
|
-
if (typeof window !== "undefined" && ((_window_google = window.google) === null || _window_google === void 0 ? void 0 : _window_google.ima)) return Promise.resolve();
|
|
423
|
-
var existing = document.querySelector('script[data-ima="true"]');
|
|
424
|
-
if (existing) {
|
|
425
|
-
var _window_google1;
|
|
426
|
-
if ((_window_google1 = window.google) === null || _window_google1 === void 0 ? void 0 : _window_google1.ima) {
|
|
427
|
-
return Promise.resolve();
|
|
428
|
-
}
|
|
429
|
-
return new Promise(function(resolve, reject) {
|
|
430
|
-
var timeout = setTimeout(function() {
|
|
431
|
-
reject(new Error("IMA SDK load timeout"));
|
|
432
|
-
}, 1e4);
|
|
433
|
-
existing.addEventListener("load", function() {
|
|
434
|
-
clearTimeout(timeout);
|
|
435
|
-
resolve();
|
|
436
|
-
});
|
|
437
|
-
existing.addEventListener("error", function() {
|
|
438
|
-
clearTimeout(timeout);
|
|
439
|
-
reject(new Error("IMA SDK load failed"));
|
|
440
|
-
});
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
return new Promise(function(resolve, reject) {
|
|
444
|
-
var script = document.createElement("script");
|
|
445
|
-
script.src = "https://imasdk.googleapis.com/js/sdkloader/ima3.js";
|
|
446
|
-
script.async = true;
|
|
447
|
-
script.defer = true;
|
|
448
|
-
script.setAttribute("data-ima", "true");
|
|
449
|
-
script.onload = function() {
|
|
450
|
-
return resolve();
|
|
451
|
-
};
|
|
452
|
-
script.onerror = function() {
|
|
453
|
-
return reject(new Error("IMA SDK load failed"));
|
|
454
|
-
};
|
|
455
|
-
document.head.appendChild(script);
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
var adsManager;
|
|
459
|
-
var adsLoader;
|
|
460
|
-
var adDisplayContainer;
|
|
461
|
-
var adContainerEl;
|
|
462
|
-
var lastAdTagUrl;
|
|
463
|
-
var retryAttempts = 0;
|
|
464
|
-
var maxRetries = 2;
|
|
465
|
-
var backoffBaseMs = 500;
|
|
466
|
-
var adsLoadedPromise;
|
|
467
|
-
var adsLoadedResolve;
|
|
468
|
-
var adsLoadedReject;
|
|
469
|
-
function makeAdsRequest(google, vastTagUrl) {
|
|
470
|
-
var adsRequest = new google.ima.AdsRequest();
|
|
471
|
-
console.log("[IMA] \uD83D\uDCE1 Requesting VAST from URL (letting IMA fetch fresh)");
|
|
472
|
-
adsRequest.adTagUrl = vastTagUrl;
|
|
473
|
-
var videoWidth = video.offsetWidth || video.clientWidth || 640;
|
|
474
|
-
var videoHeight = video.offsetHeight || video.clientHeight || 360;
|
|
475
|
-
adsRequest.linearAdSlotWidth = videoWidth;
|
|
476
|
-
adsRequest.linearAdSlotHeight = videoHeight;
|
|
477
|
-
adsRequest.nonLinearAdSlotWidth = videoWidth;
|
|
478
|
-
adsRequest.nonLinearAdSlotHeight = videoHeight;
|
|
479
|
-
if (typeof adsRequest.setAdWillAutoPlay === "function") {
|
|
480
|
-
try {
|
|
481
|
-
var willAutoPlay = !video.paused || video.autoplay;
|
|
482
|
-
adsRequest.setAdWillAutoPlay(willAutoPlay);
|
|
483
|
-
} catch (error) {
|
|
484
|
-
console.warn("[IMA] Failed to call setAdWillAutoPlay:", error);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
if (typeof adsRequest.setAdWillPlayMuted === "function") {
|
|
488
|
-
try {
|
|
489
|
-
var willPlayMuted = video.muted || video.volume === 0;
|
|
490
|
-
adsRequest.setAdWillPlayMuted(willPlayMuted);
|
|
491
|
-
} catch (error) {
|
|
492
|
-
console.warn("[IMA] Failed to call setAdWillPlayMuted:", error);
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
adsRequest.vastLoadTimeout = 1e4;
|
|
496
|
-
adsLoader.requestAds(adsRequest);
|
|
497
|
-
}
|
|
498
|
-
function ensurePlaceholderContainer() {
|
|
499
|
-
var _video_parentElement;
|
|
500
|
-
if (adContainerEl) {
|
|
501
|
-
return;
|
|
502
|
-
}
|
|
503
|
-
var container = document.createElement("div");
|
|
504
|
-
container.style.position = "absolute";
|
|
505
|
-
container.style.left = "0";
|
|
506
|
-
container.style.top = "0";
|
|
507
|
-
container.style.right = "0";
|
|
508
|
-
container.style.bottom = "0";
|
|
509
|
-
container.style.display = "none";
|
|
510
|
-
container.style.alignItems = "center";
|
|
511
|
-
container.style.justifyContent = "center";
|
|
512
|
-
container.style.pointerEvents = "none";
|
|
513
|
-
container.style.zIndex = "10";
|
|
514
|
-
container.style.backgroundColor = "transparent";
|
|
515
|
-
container.style.transition = "opacity 0.3s ease-in-out, background-color 0.3s ease-in-out";
|
|
516
|
-
container.style.opacity = "0";
|
|
517
|
-
(_video_parentElement = video.parentElement) === null || _video_parentElement === void 0 ? void 0 : _video_parentElement.appendChild(container);
|
|
518
|
-
adContainerEl = container;
|
|
519
|
-
}
|
|
520
|
-
function fetchVastDocument(vastTagUrl) {
|
|
521
|
-
return _async_to_generator(function() {
|
|
522
|
-
var response;
|
|
523
|
-
return _ts_generator(this, function(_state) {
|
|
524
|
-
switch(_state.label){
|
|
525
|
-
case 0:
|
|
526
|
-
return [
|
|
527
|
-
4,
|
|
528
|
-
fetch(vastTagUrl, {
|
|
529
|
-
mode: "cors"
|
|
530
|
-
})
|
|
531
|
-
];
|
|
532
|
-
case 1:
|
|
533
|
-
response = _state.sent();
|
|
534
|
-
if (!response.ok) {
|
|
535
|
-
throw new Error("Failed to preload VAST: ".concat(response.status));
|
|
536
|
-
}
|
|
537
|
-
return [
|
|
538
|
-
2,
|
|
539
|
-
response.text()
|
|
540
|
-
];
|
|
541
|
-
}
|
|
542
|
-
});
|
|
543
|
-
})();
|
|
544
|
-
}
|
|
545
|
-
function destroyAdsManager() {
|
|
546
|
-
if (adsManager) {
|
|
547
|
-
try {
|
|
548
|
-
adsManager.destroy();
|
|
549
|
-
} catch (e) {}
|
|
550
|
-
adsManager = void 0;
|
|
551
|
-
}
|
|
552
|
-
if (adVideoElement) {
|
|
553
|
-
adVideoElement.style.opacity = "0";
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
return {
|
|
557
|
-
initialize: function initialize() {
|
|
558
|
-
ensureImaLoaded().then(function() {
|
|
559
|
-
var google = window.google;
|
|
560
|
-
ensurePlaceholderContainer();
|
|
561
|
-
if (!adDisplayContainer && adContainerEl) {
|
|
562
|
-
if (!adVideoElement) {
|
|
563
|
-
adVideoElement = createAdVideoElement();
|
|
564
|
-
adContainerEl.appendChild(adVideoElement);
|
|
565
|
-
}
|
|
566
|
-
adDisplayContainer = new google.ima.AdDisplayContainer(adContainerEl, adVideoElement);
|
|
567
|
-
try {
|
|
568
|
-
var _adDisplayContainer_initialize;
|
|
569
|
-
(_adDisplayContainer_initialize = adDisplayContainer.initialize) === null || _adDisplayContainer_initialize === void 0 ? void 0 : _adDisplayContainer_initialize.call(adDisplayContainer);
|
|
570
|
-
} catch (e) {}
|
|
571
|
-
}
|
|
572
|
-
}).catch(function() {});
|
|
573
|
-
},
|
|
574
|
-
requestAds: function requestAds(vastTagUrl) {
|
|
575
|
-
return _async_to_generator(function() {
|
|
576
|
-
var _$error, _$error1, currentReject, google, container, videoWidth, videoHeight, _$error2, adsLoaderCls, error;
|
|
577
|
-
return _ts_generator(this, function(_state) {
|
|
578
|
-
switch(_state.label){
|
|
579
|
-
case 0:
|
|
580
|
-
if (!vastTagUrl || vastTagUrl.trim() === "") {
|
|
581
|
-
_$error = new Error("VAST tag URL is empty or undefined");
|
|
582
|
-
console.warn("[IMA] \u274C", _$error.message);
|
|
583
|
-
return [
|
|
584
|
-
2,
|
|
585
|
-
Promise.reject(_$error)
|
|
586
|
-
];
|
|
587
|
-
}
|
|
588
|
-
try {
|
|
589
|
-
new URL(vastTagUrl);
|
|
590
|
-
} catch (e) {
|
|
591
|
-
_$error1 = new Error("Invalid VAST tag URL format: ".concat(vastTagUrl));
|
|
592
|
-
console.warn("[IMA] \u274C", _$error1.message);
|
|
593
|
-
return [
|
|
594
|
-
2,
|
|
595
|
-
Promise.reject(_$error1)
|
|
596
|
-
];
|
|
597
|
-
}
|
|
598
|
-
if (adPlaying) {
|
|
599
|
-
console.warn("[IMA] \u26A0\uFE0F Cannot request new ads while an ad is playing. Call stop() first.");
|
|
600
|
-
return [
|
|
601
|
-
2,
|
|
602
|
-
Promise.reject(new Error("Ad already playing - cannot request new ads"))
|
|
603
|
-
];
|
|
604
|
-
}
|
|
605
|
-
destroyAdsManager();
|
|
606
|
-
adsLoadedReject = void 0;
|
|
607
|
-
adsLoadedResolve = void 0;
|
|
608
|
-
adsLoadedPromise = new Promise(function(resolve, reject) {
|
|
609
|
-
adsLoadedResolve = resolve;
|
|
610
|
-
adsLoadedReject = reject;
|
|
611
|
-
currentReject = reject;
|
|
612
|
-
setTimeout(function() {
|
|
613
|
-
if (adsLoadedReject) {
|
|
614
|
-
adsLoadedReject(new Error("Ad request timeout"));
|
|
615
|
-
adsLoadedReject = void 0;
|
|
616
|
-
adsLoadedResolve = void 0;
|
|
617
|
-
}
|
|
618
|
-
}, 1e4);
|
|
619
|
-
});
|
|
620
|
-
_state.label = 1;
|
|
621
|
-
case 1:
|
|
622
|
-
_state.trys.push([
|
|
623
|
-
1,
|
|
624
|
-
3,
|
|
625
|
-
,
|
|
626
|
-
4
|
|
627
|
-
]);
|
|
628
|
-
return [
|
|
629
|
-
4,
|
|
630
|
-
ensureImaLoaded()
|
|
631
|
-
];
|
|
632
|
-
case 2:
|
|
633
|
-
_state.sent();
|
|
634
|
-
google = window.google;
|
|
635
|
-
lastAdTagUrl = vastTagUrl;
|
|
636
|
-
retryAttempts = 0;
|
|
637
|
-
if (!adDisplayContainer) {
|
|
638
|
-
container = document.createElement("div");
|
|
639
|
-
container.style.position = "absolute";
|
|
640
|
-
container.style.left = "0";
|
|
641
|
-
container.style.top = "0";
|
|
642
|
-
container.style.right = "0";
|
|
643
|
-
container.style.bottom = "0";
|
|
644
|
-
container.style.display = "none";
|
|
645
|
-
container.style.alignItems = "center";
|
|
646
|
-
container.style.justifyContent = "center";
|
|
647
|
-
container.style.pointerEvents = "none";
|
|
648
|
-
container.style.zIndex = "10";
|
|
649
|
-
container.style.backgroundColor = "transparent";
|
|
650
|
-
container.style.transition = "opacity 0.3s ease-in-out, background-color 0.3s ease-in-out";
|
|
651
|
-
container.style.opacity = "0";
|
|
652
|
-
if (!video.parentElement) {
|
|
653
|
-
throw new Error("Video element has no parent for ad container");
|
|
654
|
-
}
|
|
655
|
-
video.parentElement.appendChild(container);
|
|
656
|
-
adContainerEl = container;
|
|
657
|
-
if (!adVideoElement) {
|
|
658
|
-
adVideoElement = createAdVideoElement();
|
|
659
|
-
adContainerEl.appendChild(adVideoElement);
|
|
660
|
-
}
|
|
661
|
-
adDisplayContainer = new google.ima.AdDisplayContainer(container, adVideoElement);
|
|
662
|
-
}
|
|
663
|
-
videoWidth = video.offsetWidth || video.clientWidth;
|
|
664
|
-
videoHeight = video.offsetHeight || video.clientHeight;
|
|
665
|
-
if (!videoWidth || !videoHeight || videoWidth === 0 || videoHeight === 0) {
|
|
666
|
-
_$error2 = new Error("Invalid video dimensions: ".concat(videoWidth, "x").concat(videoHeight, ". Cannot initialize ads."));
|
|
667
|
-
console.warn("[IMA]", _$error2.message);
|
|
668
|
-
currentReject === null || currentReject === void 0 ? void 0 : currentReject(_$error2);
|
|
669
|
-
adsLoadedReject = void 0;
|
|
670
|
-
adsLoadedResolve = void 0;
|
|
671
|
-
return [
|
|
672
|
-
2,
|
|
673
|
-
Promise.reject(_$error2)
|
|
674
|
-
];
|
|
675
|
-
}
|
|
676
|
-
if (!adsLoader) {
|
|
677
|
-
adsLoaderCls = new google.ima.AdsLoader(adDisplayContainer);
|
|
678
|
-
adsLoader = adsLoaderCls;
|
|
679
|
-
adsLoader.addEventListener(google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED, function(evt) {
|
|
680
|
-
try {
|
|
681
|
-
var adsRenderingSettings = new google.ima.AdsRenderingSettings();
|
|
682
|
-
adsRenderingSettings.enablePreloading = true;
|
|
683
|
-
adsManager = evt.getAdsManager(video, adsRenderingSettings);
|
|
684
|
-
var AdEvent = google.ima.AdEvent.Type;
|
|
685
|
-
var AdErrorEvent = google.ima.AdErrorEvent.Type;
|
|
686
|
-
adsManager.addEventListener(AdErrorEvent.AD_ERROR, function(errorEvent) {
|
|
687
|
-
var _error_getMessage;
|
|
688
|
-
var _$error = errorEvent.getError();
|
|
689
|
-
console.error("[DEBUG-ERROR] \u274C AD_ERROR:", (_error_getMessage = _$error.getMessage) === null || _error_getMessage === void 0 ? void 0 : _error_getMessage.call(_$error));
|
|
690
|
-
destroyAdsManager();
|
|
691
|
-
adPlaying = false;
|
|
692
|
-
setAdPlayingFlag(false);
|
|
693
|
-
if (adContainerEl) {
|
|
694
|
-
adContainerEl.style.opacity = "0";
|
|
695
|
-
adContainerEl.style.backgroundColor = "transparent";
|
|
696
|
-
setTimeout(function() {
|
|
697
|
-
if (adContainerEl) {
|
|
698
|
-
adContainerEl.style.pointerEvents = "none";
|
|
699
|
-
adContainerEl.style.display = "none";
|
|
700
|
-
}
|
|
701
|
-
}, 300);
|
|
702
|
-
}
|
|
703
|
-
showContentVideo();
|
|
704
|
-
if (adsLoadedReject) {
|
|
705
|
-
adsLoadedReject(new Error("Ad playback error"));
|
|
706
|
-
adsLoadedReject = void 0;
|
|
707
|
-
adsLoadedResolve = void 0;
|
|
708
|
-
}
|
|
709
|
-
if (lastAdTagUrl && retryAttempts < maxRetries) {
|
|
710
|
-
var delay = backoffBaseMs * Math.pow(2, retryAttempts++);
|
|
711
|
-
window.setTimeout(function() {
|
|
712
|
-
try {
|
|
713
|
-
makeAdsRequest(google, lastAdTagUrl);
|
|
714
|
-
} catch (e) {}
|
|
715
|
-
}, delay);
|
|
716
|
-
} else {
|
|
717
|
-
emit("ad_error");
|
|
718
|
-
if (!(options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds)) {
|
|
719
|
-
if (video.paused) {
|
|
720
|
-
var _video_play;
|
|
721
|
-
(_video_play = video.play()) === null || _video_play === void 0 ? void 0 : _video_play.catch(function() {});
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
});
|
|
726
|
-
adsManager.addEventListener(AdEvent.CONTENT_PAUSE_REQUESTED, function() {
|
|
727
|
-
if (!(options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds)) {
|
|
728
|
-
video.pause();
|
|
729
|
-
}
|
|
730
|
-
adPlaying = true;
|
|
731
|
-
setAdPlayingFlag(true);
|
|
732
|
-
emit("content_pause");
|
|
733
|
-
});
|
|
734
|
-
adsManager.addEventListener(AdEvent.STARTED, function() {
|
|
735
|
-
setAdPlayingFlag(true);
|
|
736
|
-
hideContentVideo();
|
|
737
|
-
if (adVideoElement) {
|
|
738
|
-
adVideoElement.volume = originalMutedState ? 0 : originalVolume;
|
|
739
|
-
adVideoElement.muted = originalMutedState;
|
|
740
|
-
}
|
|
741
|
-
if (adContainerEl) {
|
|
742
|
-
adContainerEl.style.pointerEvents = "auto";
|
|
743
|
-
adContainerEl.style.display = "flex";
|
|
744
|
-
adContainerEl.style.backgroundColor = "#000";
|
|
745
|
-
adContainerEl.offsetHeight;
|
|
746
|
-
adContainerEl.style.opacity = "1";
|
|
747
|
-
}
|
|
748
|
-
});
|
|
749
|
-
adsManager.addEventListener(AdEvent.CONTENT_RESUME_REQUESTED, function() {
|
|
750
|
-
adPlaying = false;
|
|
751
|
-
setAdPlayingFlag(false);
|
|
752
|
-
emit("content_resume");
|
|
753
|
-
});
|
|
754
|
-
adsManager.addEventListener(AdEvent.ALL_ADS_COMPLETED, function() {
|
|
755
|
-
adPlaying = false;
|
|
756
|
-
setAdPlayingFlag(false);
|
|
757
|
-
if (adContainerEl) {
|
|
758
|
-
adContainerEl.style.opacity = "0";
|
|
759
|
-
adContainerEl.style.backgroundColor = "transparent";
|
|
760
|
-
setTimeout(function() {
|
|
761
|
-
if (adContainerEl) {
|
|
762
|
-
adContainerEl.style.pointerEvents = "none";
|
|
763
|
-
adContainerEl.style.display = "none";
|
|
764
|
-
}
|
|
765
|
-
}, 300);
|
|
766
|
-
}
|
|
767
|
-
showContentVideo();
|
|
768
|
-
if (!(options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds) && video.paused) {
|
|
769
|
-
video.play().catch(function() {});
|
|
770
|
-
}
|
|
771
|
-
emit("all_ads_completed");
|
|
772
|
-
});
|
|
773
|
-
if (adsLoadedResolve) {
|
|
774
|
-
adsLoadedResolve();
|
|
775
|
-
adsLoadedResolve = void 0;
|
|
776
|
-
adsLoadedReject = void 0;
|
|
777
|
-
}
|
|
778
|
-
} catch (e) {
|
|
779
|
-
console.error("[IMA] Error setting up ads manager:", e);
|
|
780
|
-
adPlaying = false;
|
|
781
|
-
setAdPlayingFlag(false);
|
|
782
|
-
if (adContainerEl) {
|
|
783
|
-
adContainerEl.style.opacity = "0";
|
|
784
|
-
adContainerEl.style.backgroundColor = "transparent";
|
|
785
|
-
setTimeout(function() {
|
|
786
|
-
if (adContainerEl) {
|
|
787
|
-
adContainerEl.style.pointerEvents = "none";
|
|
788
|
-
adContainerEl.style.display = "none";
|
|
789
|
-
}
|
|
790
|
-
}, 300);
|
|
791
|
-
}
|
|
792
|
-
showContentVideo();
|
|
793
|
-
if (!(options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds)) {
|
|
794
|
-
if (video.paused) {
|
|
795
|
-
video.play().catch(function() {});
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
if (adsLoadedReject) {
|
|
799
|
-
adsLoadedReject(new Error("Failed to setup ads manager"));
|
|
800
|
-
adsLoadedReject = void 0;
|
|
801
|
-
adsLoadedResolve = void 0;
|
|
802
|
-
}
|
|
803
|
-
emit("ad_error");
|
|
804
|
-
}
|
|
805
|
-
}, false);
|
|
806
|
-
adsLoader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, function(adErrorEvent) {
|
|
807
|
-
var _error_getMessage;
|
|
808
|
-
var _$error = adErrorEvent.getError();
|
|
809
|
-
console.error("[DEBUG-ERROR] \u274C ADS_LOADER ERROR:", (_error_getMessage = _$error.getMessage) === null || _error_getMessage === void 0 ? void 0 : _error_getMessage.call(_$error));
|
|
810
|
-
adPlaying = false;
|
|
811
|
-
setAdPlayingFlag(false);
|
|
812
|
-
if (adContainerEl) {
|
|
813
|
-
adContainerEl.style.opacity = "0";
|
|
814
|
-
adContainerEl.style.backgroundColor = "transparent";
|
|
815
|
-
setTimeout(function() {
|
|
816
|
-
if (adContainerEl) {
|
|
817
|
-
adContainerEl.style.pointerEvents = "none";
|
|
818
|
-
adContainerEl.style.display = "none";
|
|
819
|
-
}
|
|
820
|
-
}, 300);
|
|
821
|
-
}
|
|
822
|
-
showContentVideo();
|
|
823
|
-
if (!(options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds)) {
|
|
824
|
-
if (video.paused) {
|
|
825
|
-
video.play().catch(function() {});
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
if (adsLoadedReject) {
|
|
829
|
-
adsLoadedReject(new Error("Ads loader error"));
|
|
830
|
-
adsLoadedReject = void 0;
|
|
831
|
-
adsLoadedResolve = void 0;
|
|
832
|
-
}
|
|
833
|
-
emit("ad_error");
|
|
834
|
-
}, false);
|
|
835
|
-
}
|
|
836
|
-
makeAdsRequest(google, vastTagUrl);
|
|
837
|
-
return [
|
|
838
|
-
2,
|
|
839
|
-
adsLoadedPromise
|
|
840
|
-
];
|
|
841
|
-
case 3:
|
|
842
|
-
error = _state.sent();
|
|
843
|
-
console.error("[IMA] Failed to request ads:", error);
|
|
844
|
-
currentReject === null || currentReject === void 0 ? void 0 : currentReject(error);
|
|
845
|
-
adsLoadedReject = void 0;
|
|
846
|
-
adsLoadedResolve = void 0;
|
|
847
|
-
return [
|
|
848
|
-
2,
|
|
849
|
-
Promise.reject(error)
|
|
850
|
-
];
|
|
851
|
-
case 4:
|
|
852
|
-
return [
|
|
853
|
-
2
|
|
854
|
-
];
|
|
855
|
-
}
|
|
856
|
-
});
|
|
857
|
-
})();
|
|
858
|
-
},
|
|
859
|
-
preloadAds: function preloadAds(vastTagUrl) {
|
|
860
|
-
return _async_to_generator(function() {
|
|
861
|
-
var inflight, preloadPromise;
|
|
862
|
-
return _ts_generator(this, function(_state) {
|
|
863
|
-
if (!vastTagUrl || vastTagUrl.trim() === "") {
|
|
864
|
-
return [
|
|
865
|
-
2,
|
|
866
|
-
Promise.resolve()
|
|
867
|
-
];
|
|
868
|
-
}
|
|
869
|
-
if (preloadedVast.has(vastTagUrl)) {
|
|
870
|
-
return [
|
|
871
|
-
2,
|
|
872
|
-
Promise.resolve()
|
|
873
|
-
];
|
|
874
|
-
}
|
|
875
|
-
inflight = preloadingVast.get(vastTagUrl);
|
|
876
|
-
if (inflight) {
|
|
877
|
-
return [
|
|
878
|
-
2,
|
|
879
|
-
inflight
|
|
880
|
-
];
|
|
881
|
-
}
|
|
882
|
-
preloadPromise = fetchVastDocument(vastTagUrl).then(function(xml) {
|
|
883
|
-
preloadedVast.set(vastTagUrl, xml);
|
|
884
|
-
}).catch(function() {
|
|
885
|
-
preloadedVast.delete(vastTagUrl);
|
|
886
|
-
}).finally(function() {
|
|
887
|
-
preloadingVast.delete(vastTagUrl);
|
|
888
|
-
});
|
|
889
|
-
preloadingVast.set(vastTagUrl, preloadPromise);
|
|
890
|
-
return [
|
|
891
|
-
2,
|
|
892
|
-
preloadPromise
|
|
893
|
-
];
|
|
894
|
-
});
|
|
895
|
-
})();
|
|
896
|
-
},
|
|
897
|
-
hasPreloadedAd: function hasPreloadedAd(vastTagUrl) {
|
|
898
|
-
return preloadedVast.has(vastTagUrl);
|
|
899
|
-
},
|
|
900
|
-
play: function play() {
|
|
901
|
-
return _async_to_generator(function() {
|
|
902
|
-
var _window_google, width, height, adVolume, _video_play;
|
|
903
|
-
return _ts_generator(this, function(_state) {
|
|
904
|
-
if (!((_window_google = window.google) === null || _window_google === void 0 ? void 0 : _window_google.ima) || !adDisplayContainer) {
|
|
905
|
-
return [
|
|
906
|
-
2,
|
|
907
|
-
Promise.reject(new Error("IMA SDK not available"))
|
|
908
|
-
];
|
|
909
|
-
}
|
|
910
|
-
if (!adsManager) {
|
|
911
|
-
return [
|
|
912
|
-
2,
|
|
913
|
-
Promise.reject(new Error("No ads manager"))
|
|
914
|
-
];
|
|
915
|
-
}
|
|
916
|
-
try {
|
|
917
|
-
width = video.clientWidth || 640;
|
|
918
|
-
height = video.clientHeight || 360;
|
|
919
|
-
adsManager.init(width, height, window.google.ima.ViewMode.NORMAL);
|
|
920
|
-
adPlaying = true;
|
|
921
|
-
adVolume = originalMutedState ? 0 : originalVolume;
|
|
922
|
-
if (adVideoElement) {
|
|
923
|
-
adVideoElement.volume = adVolume;
|
|
924
|
-
adVideoElement.muted = originalMutedState;
|
|
925
|
-
}
|
|
926
|
-
try {
|
|
927
|
-
adsManager.setVolume(adVolume);
|
|
928
|
-
} catch (e) {}
|
|
929
|
-
adsManager.start();
|
|
930
|
-
return [
|
|
931
|
-
2,
|
|
932
|
-
Promise.resolve()
|
|
933
|
-
];
|
|
934
|
-
} catch (error) {
|
|
935
|
-
console.error("[IMA] \u274C Error starting ad:", error);
|
|
936
|
-
adPlaying = false;
|
|
937
|
-
setAdPlayingFlag(false);
|
|
938
|
-
if (!(options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds)) {
|
|
939
|
-
;
|
|
940
|
-
(_video_play = video.play()) === null || _video_play === void 0 ? void 0 : _video_play.catch(function() {});
|
|
941
|
-
}
|
|
942
|
-
return [
|
|
943
|
-
2,
|
|
944
|
-
Promise.reject(error)
|
|
945
|
-
];
|
|
946
|
-
}
|
|
947
|
-
return [
|
|
948
|
-
2
|
|
949
|
-
];
|
|
950
|
-
});
|
|
951
|
-
})();
|
|
952
|
-
},
|
|
953
|
-
stop: function stop() {
|
|
954
|
-
return _async_to_generator(function() {
|
|
955
|
-
var _adsManager_stop;
|
|
956
|
-
return _ts_generator(this, function(_state) {
|
|
957
|
-
adPlaying = false;
|
|
958
|
-
setAdPlayingFlag(false);
|
|
959
|
-
if (adContainerEl) {
|
|
960
|
-
adContainerEl.style.opacity = "0";
|
|
961
|
-
adContainerEl.style.backgroundColor = "transparent";
|
|
962
|
-
setTimeout(function() {
|
|
963
|
-
if (adContainerEl) {
|
|
964
|
-
adContainerEl.style.pointerEvents = "none";
|
|
965
|
-
adContainerEl.style.display = "none";
|
|
966
|
-
}
|
|
967
|
-
}, 300);
|
|
968
|
-
}
|
|
969
|
-
showContentVideo();
|
|
970
|
-
try {
|
|
971
|
-
;
|
|
972
|
-
adsManager === null || adsManager === void 0 ? void 0 : (_adsManager_stop = adsManager.stop) === null || _adsManager_stop === void 0 ? void 0 : _adsManager_stop.call(adsManager);
|
|
973
|
-
} catch (e) {}
|
|
974
|
-
destroyAdsManager();
|
|
975
|
-
return [
|
|
976
|
-
2
|
|
977
|
-
];
|
|
978
|
-
});
|
|
979
|
-
})();
|
|
980
|
-
},
|
|
981
|
-
destroy: function destroy() {
|
|
982
|
-
destroyAdsManager();
|
|
983
|
-
adPlaying = false;
|
|
984
|
-
setAdPlayingFlag(false);
|
|
985
|
-
if (adContainerEl) {
|
|
986
|
-
adContainerEl.style.opacity = "0";
|
|
987
|
-
adContainerEl.style.backgroundColor = "transparent";
|
|
988
|
-
setTimeout(function() {
|
|
989
|
-
if (adContainerEl) {
|
|
990
|
-
adContainerEl.style.pointerEvents = "none";
|
|
991
|
-
adContainerEl.style.display = "none";
|
|
992
|
-
if (adContainerEl.parentElement) {
|
|
993
|
-
adContainerEl.parentElement.removeChild(adContainerEl);
|
|
994
|
-
}
|
|
995
|
-
adContainerEl = void 0;
|
|
996
|
-
adVideoElement = void 0;
|
|
997
|
-
}
|
|
998
|
-
}, 300);
|
|
999
|
-
}
|
|
1000
|
-
showContentVideo();
|
|
1001
|
-
try {
|
|
1002
|
-
var _adsLoader_destroy;
|
|
1003
|
-
adsLoader === null || adsLoader === void 0 ? void 0 : (_adsLoader_destroy = adsLoader.destroy) === null || _adsLoader_destroy === void 0 ? void 0 : _adsLoader_destroy.call(adsLoader);
|
|
1004
|
-
} catch (e) {}
|
|
1005
|
-
adDisplayContainer = void 0;
|
|
1006
|
-
adsLoader = void 0;
|
|
1007
|
-
contentVideoHidden = false;
|
|
1008
|
-
preloadedVast.clear();
|
|
1009
|
-
preloadingVast.clear();
|
|
1010
|
-
},
|
|
1011
|
-
isAdPlaying: function isAdPlaying() {
|
|
1012
|
-
return adPlaying;
|
|
1013
|
-
},
|
|
1014
|
-
resize: function resize(width, height) {
|
|
1015
|
-
var _window_google;
|
|
1016
|
-
if (!adsManager || !((_window_google = window.google) === null || _window_google === void 0 ? void 0 : _window_google.ima)) {
|
|
1017
|
-
console.warn("[IMA] Cannot resize: No ads manager or IMA SDK available");
|
|
1018
|
-
return;
|
|
1019
|
-
}
|
|
1020
|
-
try {
|
|
1021
|
-
console.log("[IMA] Resizing ads manager to ".concat(width, "x").concat(height));
|
|
1022
|
-
adsManager.resize(width, height, window.google.ima.ViewMode.NORMAL);
|
|
1023
|
-
} catch (error) {
|
|
1024
|
-
console.warn("[IMA] Error resizing ads manager:", error);
|
|
1025
|
-
}
|
|
1026
|
-
},
|
|
1027
|
-
on: function on(event, listener) {
|
|
1028
|
-
if (!listeners.has(event)) listeners.set(event, /* @__PURE__ */ new Set());
|
|
1029
|
-
listeners.get(event).add(listener);
|
|
1030
|
-
},
|
|
1031
|
-
off: function off(event, listener) {
|
|
1032
|
-
var _listeners_get;
|
|
1033
|
-
(_listeners_get = listeners.get(event)) === null || _listeners_get === void 0 ? void 0 : _listeners_get.delete(listener);
|
|
1034
|
-
},
|
|
1035
|
-
updateOriginalMutedState: function updateOriginalMutedState(muted, volume) {
|
|
1036
|
-
var nextVolume = typeof volume === "number" && !Number.isNaN(volume) ? Math.max(0, Math.min(1, volume)) : originalVolume;
|
|
1037
|
-
originalMutedState = muted;
|
|
1038
|
-
originalVolume = nextVolume;
|
|
1039
|
-
},
|
|
1040
|
-
getOriginalMutedState: function getOriginalMutedState() {
|
|
1041
|
-
return originalMutedState;
|
|
1042
|
-
},
|
|
1043
|
-
getOriginalVolume: function getOriginalVolume() {
|
|
1044
|
-
return originalVolume;
|
|
1045
|
-
},
|
|
1046
|
-
setAdVolume: function setAdVolume(volume) {
|
|
1047
|
-
var clampedVolume = Math.max(0, Math.min(1, volume));
|
|
1048
|
-
if (adVideoElement && adPlaying) {
|
|
1049
|
-
adVideoElement.volume = clampedVolume;
|
|
1050
|
-
adVideoElement.muted = clampedVolume === 0;
|
|
1051
|
-
}
|
|
1052
|
-
if (adsManager && adPlaying) {
|
|
1053
|
-
try {
|
|
1054
|
-
adsManager.setVolume(clampedVolume);
|
|
1055
|
-
} catch (e) {}
|
|
1056
|
-
}
|
|
1057
|
-
},
|
|
1058
|
-
getAdVolume: function getAdVolume() {
|
|
1059
|
-
if (adVideoElement && adPlaying) {
|
|
1060
|
-
return adVideoElement.volume;
|
|
1061
|
-
}
|
|
1062
|
-
if (adsManager && adPlaying) {
|
|
1063
|
-
try {
|
|
1064
|
-
return adsManager.getVolume();
|
|
1065
|
-
} catch (error) {
|
|
1066
|
-
console.warn("[IMA] Failed to get ad volume:", error);
|
|
1067
|
-
return 1;
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
return 1;
|
|
1071
|
-
},
|
|
1072
|
-
showPlaceholder: function showPlaceholder() {
|
|
1073
|
-
ensurePlaceholderContainer();
|
|
1074
|
-
if (adContainerEl) {
|
|
1075
|
-
adContainerEl.style.display = "flex";
|
|
1076
|
-
adContainerEl.style.backgroundColor = "#000";
|
|
1077
|
-
adContainerEl.offsetHeight;
|
|
1078
|
-
adContainerEl.style.opacity = "1";
|
|
1079
|
-
adContainerEl.style.pointerEvents = "auto";
|
|
1080
|
-
}
|
|
1081
|
-
},
|
|
1082
|
-
hidePlaceholder: function hidePlaceholder() {
|
|
1083
|
-
if (adContainerEl) {
|
|
1084
|
-
adContainerEl.style.opacity = "0";
|
|
1085
|
-
adContainerEl.style.backgroundColor = "transparent";
|
|
1086
|
-
setTimeout(function() {
|
|
1087
|
-
if (adContainerEl) {
|
|
1088
|
-
adContainerEl.style.display = "none";
|
|
1089
|
-
adContainerEl.style.pointerEvents = "none";
|
|
1090
|
-
}
|
|
1091
|
-
}, 300);
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
};
|
|
1095
|
-
}
|
|
1096
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1097
|
-
0 && (module.exports = {
|
|
1098
|
-
createImaController: createImaController
|
|
1099
|
-
});
|
|
1100
|
-
//# sourceMappingURL=ima.cjs.map
|