stormcloud-video-player 0.3.14 → 0.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/stormcloud-vp.min.js +9 -9
- package/lib/index.cjs +8282 -6531
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +2 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +8112 -6495
- package/lib/index.js.map +1 -1
- package/lib/player/StormcloudVideoPlayer.cjs +5575 -3981
- package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/player/StormcloudVideoPlayer.d.cts +1 -1
- package/lib/players/FilePlayer.cjs +556 -225
- package/lib/players/FilePlayer.cjs.map +1 -1
- package/lib/players/HlsPlayer.cjs +5845 -4163
- package/lib/players/HlsPlayer.cjs.map +1 -1
- package/lib/players/HlsPlayer.d.cts +1 -1
- package/lib/players/index.cjs +6142 -4371
- package/lib/players/index.cjs.map +1 -1
- package/lib/sdk/hlsAdPlayer.cjs +954 -699
- package/lib/sdk/hlsAdPlayer.cjs.map +1 -1
- package/lib/sdk/hlsAdPlayer.d.cts +1 -1
- package/lib/sdk/ima.cjs +1034 -809
- package/lib/sdk/ima.cjs.map +1 -1
- package/lib/sdk/ima.d.cts +1 -1
- package/lib/{types-t9jEJXZy.d.cts → types-CryTJVCC.d.cts} +1 -0
- package/lib/ui/StormcloudVideoPlayer.cjs +6992 -5561
- package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/ui/StormcloudVideoPlayer.d.cts +1 -1
- package/lib/utils/browserCompat.cjs +241 -194
- package/lib/utils/browserCompat.cjs.map +1 -1
- package/lib/utils/polyfills.cjs +379 -214
- package/lib/utils/polyfills.cjs.map +1 -1
- package/lib/utils/tracking.cjs +559 -257
- package/lib/utils/tracking.cjs.map +1 -1
- package/lib/utils/tracking.d.cts +1 -1
- package/package.json +2 -1
package/lib/sdk/ima.cjs
CHANGED
|
@@ -1,875 +1,1100 @@
|
|
|
1
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
|
+
}
|
|
2
126
|
var __defProp = Object.defineProperty;
|
|
3
127
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
128
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
129
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all)
|
|
7
|
-
|
|
8
|
-
|
|
130
|
+
var __export = function(target, all) {
|
|
131
|
+
for(var name in all)__defProp(target, name, {
|
|
132
|
+
get: all[name],
|
|
133
|
+
enumerable: true
|
|
134
|
+
});
|
|
9
135
|
};
|
|
10
|
-
var __copyProps = (to, from, except, desc)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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);
|
|
17
171
|
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
172
|
// src/sdk/ima.ts
|
|
21
173
|
var ima_exports = {};
|
|
22
174
|
__export(ima_exports, {
|
|
23
|
-
|
|
175
|
+
createImaController: function() {
|
|
176
|
+
return createImaController;
|
|
177
|
+
}
|
|
24
178
|
});
|
|
25
179
|
module.exports = __toCommonJS(ima_exports);
|
|
26
|
-
|
|
27
180
|
// src/utils/browserCompat.ts
|
|
28
181
|
function getChromeVersion(ua) {
|
|
29
|
-
|
|
30
|
-
|
|
182
|
+
var match = ua.match(/Chrome\/(\d+)/);
|
|
183
|
+
return match && match[1] ? parseInt(match[1], 10) : 0;
|
|
31
184
|
}
|
|
32
185
|
function getWebKitVersion(ua) {
|
|
33
|
-
|
|
34
|
-
|
|
186
|
+
var match = ua.match(/AppleWebKit\/(\d+)/);
|
|
187
|
+
return match && match[1] ? parseInt(match[1], 10) : 0;
|
|
35
188
|
}
|
|
36
189
|
function getPlatform() {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
const ua = navigator.userAgent;
|
|
42
|
-
if (/Mac|iPhone|iPad|iPod/i.test(ua)) {
|
|
43
|
-
return /iPhone|iPad|iPod/i.test(ua) ? "iPhone" : "MacIntel";
|
|
44
|
-
}
|
|
45
|
-
if (/Win/i.test(ua)) {
|
|
46
|
-
return "Win32";
|
|
47
|
-
}
|
|
48
|
-
if (/Linux/i.test(ua)) {
|
|
49
|
-
return /Android/i.test(ua) ? "Linux armv8l" : "Linux x86_64";
|
|
50
|
-
}
|
|
51
|
-
if (/CrOS/i.test(ua)) {
|
|
52
|
-
return "CrOS";
|
|
53
|
-
}
|
|
54
|
-
return navigator.platform || "Unknown";
|
|
55
|
-
}
|
|
56
|
-
function detectBrowser() {
|
|
57
|
-
const ua = navigator.userAgent;
|
|
58
|
-
const platform = getPlatform();
|
|
59
|
-
let name = "Unknown";
|
|
60
|
-
let version = "0";
|
|
61
|
-
let majorVersion = 0;
|
|
62
|
-
let isSmartTV = false;
|
|
63
|
-
let isLegacyTV = false;
|
|
64
|
-
let supportsIMA = true;
|
|
65
|
-
let supportsModernJS = true;
|
|
66
|
-
let recommendedAdPlayer = "ima";
|
|
67
|
-
if (/Web0S|webOS/i.test(ua)) {
|
|
68
|
-
name = "LG WebOS";
|
|
69
|
-
isSmartTV = true;
|
|
70
|
-
const match = ua.match(/Web0S[/\s]*([\d.]+)/i);
|
|
71
|
-
version = match && match[1] ? match[1] : "Unknown";
|
|
72
|
-
if (version !== "Unknown") {
|
|
73
|
-
const parts = version.split(".");
|
|
74
|
-
majorVersion = parts[0] ? parseInt(parts[0], 10) : 0;
|
|
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;
|
|
75
193
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const match = ua.match(/Tizen[/\s]*([\d.]+)/i);
|
|
80
|
-
version = match && match[1] ? match[1] : "Unknown";
|
|
81
|
-
if (version !== "Unknown") {
|
|
82
|
-
const parts = version.split(".");
|
|
83
|
-
majorVersion = parts[0] ? parseInt(parts[0], 10) : 0;
|
|
194
|
+
var ua = navigator.userAgent;
|
|
195
|
+
if (/Mac|iPhone|iPad|iPod/i.test(ua)) {
|
|
196
|
+
return /iPhone|iPad|iPod/i.test(ua) ? "iPhone" : "MacIntel";
|
|
84
197
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
isSmartTV = true;
|
|
88
|
-
} else if (/NetCast/i.test(ua)) {
|
|
89
|
-
name = "LG NetCast";
|
|
90
|
-
isSmartTV = true;
|
|
91
|
-
isLegacyTV = true;
|
|
92
|
-
} else if (/BRAVIA/i.test(ua)) {
|
|
93
|
-
name = "Sony BRAVIA";
|
|
94
|
-
isSmartTV = true;
|
|
95
|
-
}
|
|
96
|
-
const chromeVersion = getChromeVersion(ua);
|
|
97
|
-
const webkitVersion = getWebKitVersion(ua);
|
|
98
|
-
if (chromeVersion > 0) {
|
|
99
|
-
if (!isSmartTV) {
|
|
100
|
-
name = "Chrome";
|
|
101
|
-
version = chromeVersion.toString();
|
|
102
|
-
majorVersion = chromeVersion;
|
|
198
|
+
if (/Win/i.test(ua)) {
|
|
199
|
+
return "Win32";
|
|
103
200
|
}
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
supportsModernJS = false;
|
|
107
|
-
isLegacyTV = true;
|
|
108
|
-
recommendedAdPlayer = "hls";
|
|
201
|
+
if (/Linux/i.test(ua)) {
|
|
202
|
+
return /Android/i.test(ua) ? "Linux armv8l" : "Linux x86_64";
|
|
109
203
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
supportsModernJS = false;
|
|
113
|
-
if (isSmartTV) {
|
|
114
|
-
isLegacyTV = true;
|
|
115
|
-
supportsIMA = false;
|
|
116
|
-
recommendedAdPlayer = "hls";
|
|
204
|
+
if (/CrOS/i.test(ua)) {
|
|
205
|
+
return "CrOS";
|
|
117
206
|
}
|
|
118
|
-
|
|
119
|
-
if (typeof Promise === "undefined" || typeof Map === "undefined" || typeof Set === "undefined") {
|
|
120
|
-
supportsModernJS = false;
|
|
121
|
-
supportsIMA = false;
|
|
122
|
-
recommendedAdPlayer = "hls";
|
|
123
|
-
}
|
|
124
|
-
if (typeof URLSearchParams === "undefined") {
|
|
125
|
-
supportsModernJS = false;
|
|
126
|
-
}
|
|
127
|
-
return {
|
|
128
|
-
name,
|
|
129
|
-
version,
|
|
130
|
-
majorVersion,
|
|
131
|
-
isSmartTV,
|
|
132
|
-
isLegacyTV,
|
|
133
|
-
platform,
|
|
134
|
-
supportsIMA,
|
|
135
|
-
supportsModernJS,
|
|
136
|
-
recommendedAdPlayer
|
|
137
|
-
};
|
|
207
|
+
return navigator.platform || "Unknown";
|
|
138
208
|
}
|
|
139
|
-
function
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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;
|
|
151
248
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
} else {
|
|
175
|
-
delete video.dataset.stormcloudAdPlaying;
|
|
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
|
+
}
|
|
176
271
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
video.style.opacity = "0";
|
|
182
|
-
setTimeout(() => {
|
|
183
|
-
video.style.visibility = "hidden";
|
|
184
|
-
}, 300);
|
|
185
|
-
video.muted = true;
|
|
186
|
-
video.volume = 0;
|
|
187
|
-
contentVideoHidden = true;
|
|
272
|
+
if (typeof Promise === "undefined" || typeof Map === "undefined" || typeof Set === "undefined") {
|
|
273
|
+
supportsModernJS = false;
|
|
274
|
+
supportsIMA = false;
|
|
275
|
+
recommendedAdPlayer = "hls";
|
|
188
276
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (contentVideoHidden) {
|
|
192
|
-
video.style.visibility = "visible";
|
|
193
|
-
video.style.transition = "opacity 0.3s ease-in-out";
|
|
194
|
-
video.offsetHeight;
|
|
195
|
-
video.style.opacity = "1";
|
|
196
|
-
video.muted = originalMutedState;
|
|
197
|
-
video.volume = originalVolume;
|
|
198
|
-
contentVideoHidden = false;
|
|
277
|
+
if (typeof URLSearchParams === "undefined") {
|
|
278
|
+
supportsModernJS = false;
|
|
199
279
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
"canplay",
|
|
217
|
-
() => {
|
|
218
|
-
adVideo.style.opacity = "1";
|
|
219
|
-
},
|
|
220
|
-
{ once: true }
|
|
221
|
-
);
|
|
222
|
-
return adVideo;
|
|
223
|
-
}
|
|
224
|
-
function emit(event, payload) {
|
|
225
|
-
const set = listeners.get(event);
|
|
226
|
-
if (!set) return;
|
|
227
|
-
for (const fn of Array.from(set)) {
|
|
228
|
-
try {
|
|
229
|
-
fn(payload);
|
|
230
|
-
} catch {
|
|
231
|
-
}
|
|
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;
|
|
232
296
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
var _a, _b, _c;
|
|
236
|
-
if (!supportsGoogleIMA()) {
|
|
237
|
-
console.warn(
|
|
238
|
-
"[IMA] Google IMA SDK is not supported on this browser. Please use HLS ad player instead."
|
|
239
|
-
);
|
|
240
|
-
return Promise.reject(
|
|
241
|
-
new Error("Google IMA SDK not supported on this browser")
|
|
242
|
-
);
|
|
297
|
+
if (typeof document === "undefined" || typeof document.createElement !== "function") {
|
|
298
|
+
return false;
|
|
243
299
|
}
|
|
244
300
|
try {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const tokens = new Set(
|
|
249
|
-
sandboxAttr.split(/\s+/).map((t) => t.trim()).filter((t) => t.length > 0)
|
|
250
|
-
);
|
|
251
|
-
const allowsScripts = tokens.has("allow-scripts");
|
|
252
|
-
if (!allowsScripts) {
|
|
253
|
-
console.error(
|
|
254
|
-
"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'."
|
|
255
|
-
);
|
|
301
|
+
var video = document.createElement("video");
|
|
302
|
+
if (!video) {
|
|
303
|
+
return false;
|
|
256
304
|
}
|
|
257
|
-
|
|
258
|
-
|
|
305
|
+
} catch (e) {
|
|
306
|
+
return false;
|
|
259
307
|
}
|
|
260
|
-
if (typeof
|
|
261
|
-
|
|
262
|
-
const existing = document.querySelector(
|
|
263
|
-
'script[data-ima="true"]'
|
|
264
|
-
);
|
|
265
|
-
if (existing) {
|
|
266
|
-
if ((_c = window.google) == null ? void 0 : _c.ima) {
|
|
267
|
-
return Promise.resolve();
|
|
268
|
-
}
|
|
269
|
-
return new Promise((resolve, reject) => {
|
|
270
|
-
const timeout = setTimeout(() => {
|
|
271
|
-
reject(new Error("IMA SDK load timeout"));
|
|
272
|
-
}, 1e4);
|
|
273
|
-
existing.addEventListener("load", () => {
|
|
274
|
-
clearTimeout(timeout);
|
|
275
|
-
resolve();
|
|
276
|
-
});
|
|
277
|
-
existing.addEventListener("error", () => {
|
|
278
|
-
clearTimeout(timeout);
|
|
279
|
-
reject(new Error("IMA SDK load failed"));
|
|
280
|
-
});
|
|
281
|
-
});
|
|
308
|
+
if (typeof Promise === "undefined") {
|
|
309
|
+
return false;
|
|
282
310
|
}
|
|
283
|
-
return
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
const backoffBaseMs = 500;
|
|
302
|
-
let adsLoadedPromise;
|
|
303
|
-
let adsLoadedResolve;
|
|
304
|
-
let adsLoadedReject;
|
|
305
|
-
function makeAdsRequest(google, vastTagUrl) {
|
|
306
|
-
const adsRequest = new google.ima.AdsRequest();
|
|
307
|
-
console.log("[IMA] \u{1F4E1} Requesting VAST from URL (letting IMA fetch fresh)");
|
|
308
|
-
adsRequest.adTagUrl = vastTagUrl;
|
|
309
|
-
const videoWidth = video.offsetWidth || video.clientWidth || 640;
|
|
310
|
-
const videoHeight = video.offsetHeight || video.clientHeight || 360;
|
|
311
|
-
adsRequest.linearAdSlotWidth = videoWidth;
|
|
312
|
-
adsRequest.linearAdSlotHeight = videoHeight;
|
|
313
|
-
adsRequest.nonLinearAdSlotWidth = videoWidth;
|
|
314
|
-
adsRequest.nonLinearAdSlotHeight = videoHeight;
|
|
315
|
-
if (typeof adsRequest.setAdWillAutoPlay === "function") {
|
|
316
|
-
try {
|
|
317
|
-
const willAutoPlay = !video.paused || video.autoplay;
|
|
318
|
-
adsRequest.setAdWillAutoPlay(willAutoPlay);
|
|
319
|
-
} catch (error) {
|
|
320
|
-
console.warn("[IMA] Failed to call setAdWillAutoPlay:", error);
|
|
321
|
-
}
|
|
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
|
+
}
|
|
322
329
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
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
|
+
}
|
|
330
341
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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
|
+
}
|
|
338
352
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
throw new Error(`Failed to preload VAST: ${response.status}`);
|
|
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;
|
|
360
373
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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
|
+
}
|
|
370
399
|
}
|
|
371
|
-
|
|
372
|
-
|
|
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
|
+
});
|
|
373
457
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
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
|
+
}
|
|
394
486
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
return Promise.reject(error);
|
|
403
|
-
}
|
|
404
|
-
try {
|
|
405
|
-
new URL(vastTagUrl);
|
|
406
|
-
} catch (e) {
|
|
407
|
-
const error = new Error(`Invalid VAST tag URL format: ${vastTagUrl}`);
|
|
408
|
-
console.warn("[IMA] \u274C", error.message);
|
|
409
|
-
return Promise.reject(error);
|
|
410
|
-
}
|
|
411
|
-
if (adPlaying) {
|
|
412
|
-
console.warn(
|
|
413
|
-
"[IMA] \u26A0\uFE0F Cannot request new ads while an ad is playing. Call stop() first."
|
|
414
|
-
);
|
|
415
|
-
return Promise.reject(
|
|
416
|
-
new Error("Ad already playing - cannot request new ads")
|
|
417
|
-
);
|
|
418
|
-
}
|
|
419
|
-
destroyAdsManager();
|
|
420
|
-
adsLoadedReject = void 0;
|
|
421
|
-
adsLoadedResolve = void 0;
|
|
422
|
-
let currentReject;
|
|
423
|
-
adsLoadedPromise = new Promise((resolve, reject) => {
|
|
424
|
-
adsLoadedResolve = resolve;
|
|
425
|
-
adsLoadedReject = reject;
|
|
426
|
-
currentReject = reject;
|
|
427
|
-
setTimeout(() => {
|
|
428
|
-
if (adsLoadedReject) {
|
|
429
|
-
adsLoadedReject(new Error("Ad request timeout"));
|
|
430
|
-
adsLoadedReject = void 0;
|
|
431
|
-
adsLoadedResolve = void 0;
|
|
432
|
-
}
|
|
433
|
-
}, 1e4);
|
|
434
|
-
});
|
|
435
|
-
try {
|
|
436
|
-
await ensureImaLoaded();
|
|
437
|
-
const google = window.google;
|
|
438
|
-
lastAdTagUrl = vastTagUrl;
|
|
439
|
-
retryAttempts = 0;
|
|
440
|
-
if (!adDisplayContainer) {
|
|
441
|
-
const container = document.createElement("div");
|
|
442
|
-
container.style.position = "absolute";
|
|
443
|
-
container.style.left = "0";
|
|
444
|
-
container.style.top = "0";
|
|
445
|
-
container.style.right = "0";
|
|
446
|
-
container.style.bottom = "0";
|
|
447
|
-
container.style.display = "none";
|
|
448
|
-
container.style.alignItems = "center";
|
|
449
|
-
container.style.justifyContent = "center";
|
|
450
|
-
container.style.pointerEvents = "none";
|
|
451
|
-
container.style.zIndex = "10";
|
|
452
|
-
container.style.backgroundColor = "transparent";
|
|
453
|
-
container.style.transition = "opacity 0.3s ease-in-out, background-color 0.3s ease-in-out";
|
|
454
|
-
container.style.opacity = "0";
|
|
455
|
-
if (!video.parentElement) {
|
|
456
|
-
throw new Error("Video element has no parent for ad container");
|
|
457
|
-
}
|
|
458
|
-
video.parentElement.appendChild(container);
|
|
459
|
-
adContainerEl = container;
|
|
460
|
-
if (!adVideoElement) {
|
|
461
|
-
adVideoElement = createAdVideoElement();
|
|
462
|
-
adContainerEl.appendChild(adVideoElement);
|
|
463
|
-
}
|
|
464
|
-
adDisplayContainer = new google.ima.AdDisplayContainer(
|
|
465
|
-
container,
|
|
466
|
-
adVideoElement
|
|
467
|
-
);
|
|
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
|
+
}
|
|
468
494
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
currentReject == null ? void 0 : currentReject(error);
|
|
477
|
-
adsLoadedReject = void 0;
|
|
478
|
-
adsLoadedResolve = void 0;
|
|
479
|
-
return Promise.reject(error);
|
|
495
|
+
adsRequest.vastLoadTimeout = 1e4;
|
|
496
|
+
adsLoader.requestAds(adsRequest);
|
|
497
|
+
}
|
|
498
|
+
function ensurePlaceholderContainer() {
|
|
499
|
+
var _video_parentElement;
|
|
500
|
+
if (adContainerEl) {
|
|
501
|
+
return;
|
|
480
502
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
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));
|
|
509
536
|
}
|
|
510
|
-
|
|
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);
|
|
511
565
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
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
|
+
];
|
|
517
855
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
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;
|
|
524
925
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
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() {});
|
|
532
941
|
}
|
|
533
|
-
|
|
942
|
+
return [
|
|
943
|
+
2,
|
|
944
|
+
Promise.reject(error)
|
|
945
|
+
];
|
|
534
946
|
}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
AdEvent.CONTENT_PAUSE_REQUESTED,
|
|
539
|
-
() => {
|
|
540
|
-
if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
|
|
541
|
-
video.pause();
|
|
542
|
-
}
|
|
543
|
-
adPlaying = true;
|
|
544
|
-
setAdPlayingFlag(true);
|
|
545
|
-
emit("content_pause");
|
|
546
|
-
}
|
|
547
|
-
);
|
|
548
|
-
adsManager.addEventListener(AdEvent.STARTED, () => {
|
|
549
|
-
setAdPlayingFlag(true);
|
|
550
|
-
hideContentVideo();
|
|
551
|
-
if (adVideoElement) {
|
|
552
|
-
adVideoElement.volume = originalMutedState ? 0 : originalVolume;
|
|
553
|
-
adVideoElement.muted = originalMutedState;
|
|
554
|
-
}
|
|
555
|
-
if (adContainerEl) {
|
|
556
|
-
adContainerEl.style.pointerEvents = "auto";
|
|
557
|
-
adContainerEl.style.display = "flex";
|
|
558
|
-
adContainerEl.style.backgroundColor = "#000";
|
|
559
|
-
adContainerEl.offsetHeight;
|
|
560
|
-
adContainerEl.style.opacity = "1";
|
|
561
|
-
}
|
|
947
|
+
return [
|
|
948
|
+
2
|
|
949
|
+
];
|
|
562
950
|
});
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
951
|
+
})();
|
|
952
|
+
},
|
|
953
|
+
stop: function stop() {
|
|
954
|
+
return _async_to_generator(function() {
|
|
955
|
+
var _adsManager_stop;
|
|
956
|
+
return _ts_generator(this, function(_state) {
|
|
566
957
|
adPlaying = false;
|
|
567
958
|
setAdPlayingFlag(false);
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
});
|
|
588
|
-
}
|
|
589
|
-
emit("all_ads_completed");
|
|
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
|
+
];
|
|
590
978
|
});
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
adContainerEl.style.opacity = "0";
|
|
602
|
-
adContainerEl.style.backgroundColor = "transparent";
|
|
603
|
-
setTimeout(() => {
|
|
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() {
|
|
604
989
|
if (adContainerEl) {
|
|
605
|
-
|
|
606
|
-
|
|
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;
|
|
607
997
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
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;
|
|
621
1068
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
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) {
|
|
636
1084
|
adContainerEl.style.opacity = "0";
|
|
637
1085
|
adContainerEl.style.backgroundColor = "transparent";
|
|
638
|
-
setTimeout(()
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
1086
|
+
setTimeout(function() {
|
|
1087
|
+
if (adContainerEl) {
|
|
1088
|
+
adContainerEl.style.display = "none";
|
|
1089
|
+
adContainerEl.style.pointerEvents = "none";
|
|
1090
|
+
}
|
|
643
1091
|
}, 300);
|
|
644
|
-
}
|
|
645
|
-
showContentVideo();
|
|
646
|
-
if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
|
|
647
|
-
if (video.paused) {
|
|
648
|
-
video.play().catch(() => {
|
|
649
|
-
});
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
if (adsLoadedReject) {
|
|
653
|
-
adsLoadedReject(new Error("Ads loader error"));
|
|
654
|
-
adsLoadedReject = void 0;
|
|
655
|
-
adsLoadedResolve = void 0;
|
|
656
|
-
}
|
|
657
|
-
emit("ad_error");
|
|
658
|
-
},
|
|
659
|
-
false
|
|
660
|
-
);
|
|
661
|
-
}
|
|
662
|
-
makeAdsRequest(google, vastTagUrl);
|
|
663
|
-
return adsLoadedPromise;
|
|
664
|
-
} catch (error) {
|
|
665
|
-
console.error("[IMA] Failed to request ads:", error);
|
|
666
|
-
currentReject == null ? void 0 : currentReject(error);
|
|
667
|
-
adsLoadedReject = void 0;
|
|
668
|
-
adsLoadedResolve = void 0;
|
|
669
|
-
return Promise.reject(error);
|
|
670
|
-
}
|
|
671
|
-
},
|
|
672
|
-
async preloadAds(vastTagUrl) {
|
|
673
|
-
if (!vastTagUrl || vastTagUrl.trim() === "") {
|
|
674
|
-
return Promise.resolve();
|
|
675
|
-
}
|
|
676
|
-
if (preloadedVast.has(vastTagUrl)) {
|
|
677
|
-
return Promise.resolve();
|
|
678
|
-
}
|
|
679
|
-
const inflight = preloadingVast.get(vastTagUrl);
|
|
680
|
-
if (inflight) {
|
|
681
|
-
return inflight;
|
|
682
|
-
}
|
|
683
|
-
const preloadPromise = fetchVastDocument(vastTagUrl).then((xml) => {
|
|
684
|
-
preloadedVast.set(vastTagUrl, xml);
|
|
685
|
-
}).catch(() => {
|
|
686
|
-
preloadedVast.delete(vastTagUrl);
|
|
687
|
-
}).finally(() => {
|
|
688
|
-
preloadingVast.delete(vastTagUrl);
|
|
689
|
-
});
|
|
690
|
-
preloadingVast.set(vastTagUrl, preloadPromise);
|
|
691
|
-
return preloadPromise;
|
|
692
|
-
},
|
|
693
|
-
hasPreloadedAd(vastTagUrl) {
|
|
694
|
-
return preloadedVast.has(vastTagUrl);
|
|
695
|
-
},
|
|
696
|
-
async play() {
|
|
697
|
-
var _a, _b;
|
|
698
|
-
if (!((_a = window.google) == null ? void 0 : _a.ima) || !adDisplayContainer) {
|
|
699
|
-
return Promise.reject(new Error("IMA SDK not available"));
|
|
700
|
-
}
|
|
701
|
-
if (!adsManager) {
|
|
702
|
-
return Promise.reject(new Error("No ads manager"));
|
|
703
|
-
}
|
|
704
|
-
try {
|
|
705
|
-
const width = video.clientWidth || 640;
|
|
706
|
-
const height = video.clientHeight || 360;
|
|
707
|
-
adsManager.init(width, height, window.google.ima.ViewMode.NORMAL);
|
|
708
|
-
adPlaying = true;
|
|
709
|
-
const adVolume = originalMutedState ? 0 : originalVolume;
|
|
710
|
-
if (adVideoElement) {
|
|
711
|
-
adVideoElement.volume = adVolume;
|
|
712
|
-
adVideoElement.muted = originalMutedState;
|
|
713
|
-
}
|
|
714
|
-
try {
|
|
715
|
-
adsManager.setVolume(adVolume);
|
|
716
|
-
} catch {
|
|
717
|
-
}
|
|
718
|
-
adsManager.start();
|
|
719
|
-
return Promise.resolve();
|
|
720
|
-
} catch (error) {
|
|
721
|
-
console.error("[IMA] \u274C Error starting ad:", error);
|
|
722
|
-
adPlaying = false;
|
|
723
|
-
setAdPlayingFlag(false);
|
|
724
|
-
if (!(options == null ? void 0 : options.continueLiveStreamDuringAds)) {
|
|
725
|
-
(_b = video.play()) == null ? void 0 : _b.catch(() => {
|
|
726
|
-
});
|
|
727
|
-
}
|
|
728
|
-
return Promise.reject(error);
|
|
729
|
-
}
|
|
730
|
-
},
|
|
731
|
-
async stop() {
|
|
732
|
-
var _a;
|
|
733
|
-
adPlaying = false;
|
|
734
|
-
setAdPlayingFlag(false);
|
|
735
|
-
if (adContainerEl) {
|
|
736
|
-
adContainerEl.style.opacity = "0";
|
|
737
|
-
adContainerEl.style.backgroundColor = "transparent";
|
|
738
|
-
setTimeout(() => {
|
|
739
|
-
if (adContainerEl) {
|
|
740
|
-
adContainerEl.style.pointerEvents = "none";
|
|
741
|
-
adContainerEl.style.display = "none";
|
|
742
|
-
}
|
|
743
|
-
}, 300);
|
|
744
|
-
}
|
|
745
|
-
showContentVideo();
|
|
746
|
-
try {
|
|
747
|
-
(_a = adsManager == null ? void 0 : adsManager.stop) == null ? void 0 : _a.call(adsManager);
|
|
748
|
-
} catch {
|
|
749
|
-
}
|
|
750
|
-
destroyAdsManager();
|
|
751
|
-
},
|
|
752
|
-
destroy() {
|
|
753
|
-
var _a;
|
|
754
|
-
destroyAdsManager();
|
|
755
|
-
adPlaying = false;
|
|
756
|
-
setAdPlayingFlag(false);
|
|
757
|
-
if (adContainerEl) {
|
|
758
|
-
adContainerEl.style.opacity = "0";
|
|
759
|
-
adContainerEl.style.backgroundColor = "transparent";
|
|
760
|
-
setTimeout(() => {
|
|
761
|
-
if (adContainerEl) {
|
|
762
|
-
adContainerEl.style.pointerEvents = "none";
|
|
763
|
-
adContainerEl.style.display = "none";
|
|
764
|
-
if (adContainerEl.parentElement) {
|
|
765
|
-
adContainerEl.parentElement.removeChild(adContainerEl);
|
|
766
1092
|
}
|
|
767
|
-
adContainerEl = void 0;
|
|
768
|
-
adVideoElement = void 0;
|
|
769
|
-
}
|
|
770
|
-
}, 300);
|
|
771
|
-
}
|
|
772
|
-
showContentVideo();
|
|
773
|
-
try {
|
|
774
|
-
(_a = adsLoader == null ? void 0 : adsLoader.destroy) == null ? void 0 : _a.call(adsLoader);
|
|
775
|
-
} catch {
|
|
776
|
-
}
|
|
777
|
-
adDisplayContainer = void 0;
|
|
778
|
-
adsLoader = void 0;
|
|
779
|
-
contentVideoHidden = false;
|
|
780
|
-
preloadedVast.clear();
|
|
781
|
-
preloadingVast.clear();
|
|
782
|
-
},
|
|
783
|
-
isAdPlaying() {
|
|
784
|
-
return adPlaying;
|
|
785
|
-
},
|
|
786
|
-
resize(width, height) {
|
|
787
|
-
var _a;
|
|
788
|
-
if (!adsManager || !((_a = window.google) == null ? void 0 : _a.ima)) {
|
|
789
|
-
console.warn(
|
|
790
|
-
"[IMA] Cannot resize: No ads manager or IMA SDK available"
|
|
791
|
-
);
|
|
792
|
-
return;
|
|
793
|
-
}
|
|
794
|
-
try {
|
|
795
|
-
console.log(`[IMA] Resizing ads manager to ${width}x${height}`);
|
|
796
|
-
adsManager.resize(width, height, window.google.ima.ViewMode.NORMAL);
|
|
797
|
-
} catch (error) {
|
|
798
|
-
console.warn("[IMA] Error resizing ads manager:", error);
|
|
799
|
-
}
|
|
800
|
-
},
|
|
801
|
-
on(event, listener) {
|
|
802
|
-
if (!listeners.has(event)) listeners.set(event, /* @__PURE__ */ new Set());
|
|
803
|
-
listeners.get(event).add(listener);
|
|
804
|
-
},
|
|
805
|
-
off(event, listener) {
|
|
806
|
-
var _a;
|
|
807
|
-
(_a = listeners.get(event)) == null ? void 0 : _a.delete(listener);
|
|
808
|
-
},
|
|
809
|
-
updateOriginalMutedState(muted, volume) {
|
|
810
|
-
const nextVolume = typeof volume === "number" && !Number.isNaN(volume) ? Math.max(0, Math.min(1, volume)) : originalVolume;
|
|
811
|
-
originalMutedState = muted;
|
|
812
|
-
originalVolume = nextVolume;
|
|
813
|
-
},
|
|
814
|
-
getOriginalMutedState() {
|
|
815
|
-
return originalMutedState;
|
|
816
|
-
},
|
|
817
|
-
getOriginalVolume() {
|
|
818
|
-
return originalVolume;
|
|
819
|
-
},
|
|
820
|
-
setAdVolume(volume) {
|
|
821
|
-
const clampedVolume = Math.max(0, Math.min(1, volume));
|
|
822
|
-
if (adVideoElement && adPlaying) {
|
|
823
|
-
adVideoElement.volume = clampedVolume;
|
|
824
|
-
adVideoElement.muted = clampedVolume === 0;
|
|
825
|
-
}
|
|
826
|
-
if (adsManager && adPlaying) {
|
|
827
|
-
try {
|
|
828
|
-
adsManager.setVolume(clampedVolume);
|
|
829
|
-
} catch {
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
|
-
},
|
|
833
|
-
getAdVolume() {
|
|
834
|
-
if (adVideoElement && adPlaying) {
|
|
835
|
-
return adVideoElement.volume;
|
|
836
|
-
}
|
|
837
|
-
if (adsManager && adPlaying) {
|
|
838
|
-
try {
|
|
839
|
-
return adsManager.getVolume();
|
|
840
|
-
} catch (error) {
|
|
841
|
-
console.warn("[IMA] Failed to get ad volume:", error);
|
|
842
|
-
return 1;
|
|
843
1093
|
}
|
|
844
|
-
|
|
845
|
-
return 1;
|
|
846
|
-
},
|
|
847
|
-
showPlaceholder() {
|
|
848
|
-
ensurePlaceholderContainer();
|
|
849
|
-
if (adContainerEl) {
|
|
850
|
-
adContainerEl.style.display = "flex";
|
|
851
|
-
adContainerEl.style.backgroundColor = "#000";
|
|
852
|
-
adContainerEl.offsetHeight;
|
|
853
|
-
adContainerEl.style.opacity = "1";
|
|
854
|
-
adContainerEl.style.pointerEvents = "auto";
|
|
855
|
-
}
|
|
856
|
-
},
|
|
857
|
-
hidePlaceholder() {
|
|
858
|
-
if (adContainerEl) {
|
|
859
|
-
adContainerEl.style.opacity = "0";
|
|
860
|
-
adContainerEl.style.backgroundColor = "transparent";
|
|
861
|
-
setTimeout(() => {
|
|
862
|
-
if (adContainerEl) {
|
|
863
|
-
adContainerEl.style.display = "none";
|
|
864
|
-
adContainerEl.style.pointerEvents = "none";
|
|
865
|
-
}
|
|
866
|
-
}, 300);
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
};
|
|
1094
|
+
};
|
|
870
1095
|
}
|
|
871
1096
|
// Annotate the CommonJS export names for ESM import in node:
|
|
872
1097
|
0 && (module.exports = {
|
|
873
|
-
|
|
1098
|
+
createImaController: createImaController
|
|
874
1099
|
});
|
|
875
1100
|
//# sourceMappingURL=ima.cjs.map
|