stormcloud-video-player 0.7.3 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/stormcloud-vp.min.js +1 -1
- package/lib/index.cjs +1320 -1203
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +60 -49
- package/lib/index.d.ts +60 -49
- package/lib/index.js +1318 -1197
- package/lib/index.js.map +1 -1
- package/lib/player/StormcloudVideoPlayer.cjs +1070 -1189
- package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/player/StormcloudVideoPlayer.d.cts +24 -2
- package/lib/players/HlsPlayer.cjs +1071 -1190
- package/lib/players/HlsPlayer.cjs.map +1 -1
- package/lib/players/HlsPlayer.d.cts +1 -1
- package/lib/players/index.cjs +1071 -1190
- package/lib/players/index.cjs.map +1 -1
- package/lib/sdk/adstormPlayer.cjs +1573 -0
- package/lib/sdk/adstormPlayer.cjs.map +1 -0
- package/lib/sdk/adstormPlayer.d.cts +22 -0
- package/lib/{types-BYwfSJb5.d.cts → types-BII_CKbE.d.cts} +27 -27
- package/lib/types-ClqQZM3U.d.cts +105 -0
- package/lib/ui/StormcloudVideoPlayer.cjs +1322 -1201
- package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/ui/StormcloudVideoPlayer.d.cts +1 -1
- package/lib/utils/tracking.d.cts +1 -1
- package/package.json +1 -1
- package/lib/sdk/vastAdLayer.cjs +0 -1595
- package/lib/sdk/vastAdLayer.cjs.map +0 -1
- package/lib/sdk/vastAdLayer.d.cts +0 -42
- package/lib/sdk/vastManager.cjs +0 -627
- package/lib/sdk/vastManager.cjs.map +0 -1
- package/lib/sdk/vastManager.d.cts +0 -8
package/lib/sdk/vastAdLayer.cjs
DELETED
|
@@ -1,1595 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
function _array_like_to_array(arr, len) {
|
|
3
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
4
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
5
|
-
return arr2;
|
|
6
|
-
}
|
|
7
|
-
function _array_with_holes(arr) {
|
|
8
|
-
if (Array.isArray(arr)) return arr;
|
|
9
|
-
}
|
|
10
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
11
|
-
try {
|
|
12
|
-
var info = gen[key](arg);
|
|
13
|
-
var value = info.value;
|
|
14
|
-
} catch (error) {
|
|
15
|
-
reject(error);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (info.done) {
|
|
19
|
-
resolve(value);
|
|
20
|
-
} else {
|
|
21
|
-
Promise.resolve(value).then(_next, _throw);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function _async_to_generator(fn) {
|
|
25
|
-
return function() {
|
|
26
|
-
var self = this, args = arguments;
|
|
27
|
-
return new Promise(function(resolve, reject) {
|
|
28
|
-
var gen = fn.apply(self, args);
|
|
29
|
-
function _next(value) {
|
|
30
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
31
|
-
}
|
|
32
|
-
function _throw(err) {
|
|
33
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
34
|
-
}
|
|
35
|
-
_next(undefined);
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
function _define_property(obj, key, value) {
|
|
40
|
-
if (key in obj) {
|
|
41
|
-
Object.defineProperty(obj, key, {
|
|
42
|
-
value: value,
|
|
43
|
-
enumerable: true,
|
|
44
|
-
configurable: true,
|
|
45
|
-
writable: true
|
|
46
|
-
});
|
|
47
|
-
} else {
|
|
48
|
-
obj[key] = value;
|
|
49
|
-
}
|
|
50
|
-
return obj;
|
|
51
|
-
}
|
|
52
|
-
function _iterable_to_array_limit(arr, i) {
|
|
53
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
54
|
-
if (_i == null) return;
|
|
55
|
-
var _arr = [];
|
|
56
|
-
var _n = true;
|
|
57
|
-
var _d = false;
|
|
58
|
-
var _s, _e;
|
|
59
|
-
try {
|
|
60
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
61
|
-
_arr.push(_s.value);
|
|
62
|
-
if (i && _arr.length === i) break;
|
|
63
|
-
}
|
|
64
|
-
} catch (err) {
|
|
65
|
-
_d = true;
|
|
66
|
-
_e = err;
|
|
67
|
-
} finally{
|
|
68
|
-
try {
|
|
69
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
70
|
-
} finally{
|
|
71
|
-
if (_d) throw _e;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return _arr;
|
|
75
|
-
}
|
|
76
|
-
function _non_iterable_rest() {
|
|
77
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
78
|
-
}
|
|
79
|
-
function _object_spread(target) {
|
|
80
|
-
for(var i = 1; i < arguments.length; i++){
|
|
81
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
82
|
-
var ownKeys = Object.keys(source);
|
|
83
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
84
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
85
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
86
|
-
}));
|
|
87
|
-
}
|
|
88
|
-
ownKeys.forEach(function(key) {
|
|
89
|
-
_define_property(target, key, source[key]);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
return target;
|
|
93
|
-
}
|
|
94
|
-
function _sliced_to_array(arr, i) {
|
|
95
|
-
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
96
|
-
}
|
|
97
|
-
function _type_of(obj) {
|
|
98
|
-
"@swc/helpers - typeof";
|
|
99
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
100
|
-
}
|
|
101
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
102
|
-
if (!o) return;
|
|
103
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
104
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
105
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
106
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
107
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
108
|
-
}
|
|
109
|
-
function _ts_generator(thisArg, body) {
|
|
110
|
-
var f, y, t, _ = {
|
|
111
|
-
label: 0,
|
|
112
|
-
sent: function() {
|
|
113
|
-
if (t[0] & 1) throw t[1];
|
|
114
|
-
return t[1];
|
|
115
|
-
},
|
|
116
|
-
trys: [],
|
|
117
|
-
ops: []
|
|
118
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
119
|
-
return d(g, "next", {
|
|
120
|
-
value: verb(0)
|
|
121
|
-
}), d(g, "throw", {
|
|
122
|
-
value: verb(1)
|
|
123
|
-
}), d(g, "return", {
|
|
124
|
-
value: verb(2)
|
|
125
|
-
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
126
|
-
value: function() {
|
|
127
|
-
return this;
|
|
128
|
-
}
|
|
129
|
-
}), g;
|
|
130
|
-
function verb(n) {
|
|
131
|
-
return function(v) {
|
|
132
|
-
return step([
|
|
133
|
-
n,
|
|
134
|
-
v
|
|
135
|
-
]);
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
function step(op) {
|
|
139
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
140
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
141
|
-
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;
|
|
142
|
-
if (y = 0, t) op = [
|
|
143
|
-
op[0] & 2,
|
|
144
|
-
t.value
|
|
145
|
-
];
|
|
146
|
-
switch(op[0]){
|
|
147
|
-
case 0:
|
|
148
|
-
case 1:
|
|
149
|
-
t = op;
|
|
150
|
-
break;
|
|
151
|
-
case 4:
|
|
152
|
-
_.label++;
|
|
153
|
-
return {
|
|
154
|
-
value: op[1],
|
|
155
|
-
done: false
|
|
156
|
-
};
|
|
157
|
-
case 5:
|
|
158
|
-
_.label++;
|
|
159
|
-
y = op[1];
|
|
160
|
-
op = [
|
|
161
|
-
0
|
|
162
|
-
];
|
|
163
|
-
continue;
|
|
164
|
-
case 7:
|
|
165
|
-
op = _.ops.pop();
|
|
166
|
-
_.trys.pop();
|
|
167
|
-
continue;
|
|
168
|
-
default:
|
|
169
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
170
|
-
_ = 0;
|
|
171
|
-
continue;
|
|
172
|
-
}
|
|
173
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
174
|
-
_.label = op[1];
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
178
|
-
_.label = t[1];
|
|
179
|
-
t = op;
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
if (t && _.label < t[2]) {
|
|
183
|
-
_.label = t[2];
|
|
184
|
-
_.ops.push(op);
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
if (t[2]) _.ops.pop();
|
|
188
|
-
_.trys.pop();
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
op = body.call(thisArg, _);
|
|
192
|
-
} catch (e) {
|
|
193
|
-
op = [
|
|
194
|
-
6,
|
|
195
|
-
e
|
|
196
|
-
];
|
|
197
|
-
y = 0;
|
|
198
|
-
} finally{
|
|
199
|
-
f = t = 0;
|
|
200
|
-
}
|
|
201
|
-
if (op[0] & 5) throw op[1];
|
|
202
|
-
return {
|
|
203
|
-
value: op[0] ? op[1] : void 0,
|
|
204
|
-
done: true
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
function _ts_values(o) {
|
|
209
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
210
|
-
if (m) return m.call(o);
|
|
211
|
-
if (o && typeof o.length === "number") return {
|
|
212
|
-
next: function() {
|
|
213
|
-
if (o && i >= o.length) o = void 0;
|
|
214
|
-
return {
|
|
215
|
-
value: o && o[i++],
|
|
216
|
-
done: !o
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
221
|
-
}
|
|
222
|
-
var __create = Object.create;
|
|
223
|
-
var __defProp = Object.defineProperty;
|
|
224
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
225
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
226
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
227
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
228
|
-
var __export = function __export(target, all) {
|
|
229
|
-
for(var name in all)__defProp(target, name, {
|
|
230
|
-
get: all[name],
|
|
231
|
-
enumerable: true
|
|
232
|
-
});
|
|
233
|
-
};
|
|
234
|
-
var __copyProps = function __copyProps(to, from, except, desc) {
|
|
235
|
-
if (from && (typeof from === "undefined" ? "undefined" : _type_of(from)) === "object" || typeof from === "function") {
|
|
236
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
237
|
-
try {
|
|
238
|
-
var _loop = function() {
|
|
239
|
-
var key = _step.value;
|
|
240
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
241
|
-
get: function get() {
|
|
242
|
-
return from[key];
|
|
243
|
-
},
|
|
244
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
245
|
-
});
|
|
246
|
-
};
|
|
247
|
-
for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
248
|
-
} catch (err) {
|
|
249
|
-
_didIteratorError = true;
|
|
250
|
-
_iteratorError = err;
|
|
251
|
-
} finally{
|
|
252
|
-
try {
|
|
253
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
254
|
-
_iterator.return();
|
|
255
|
-
}
|
|
256
|
-
} finally{
|
|
257
|
-
if (_didIteratorError) {
|
|
258
|
-
throw _iteratorError;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
return to;
|
|
264
|
-
};
|
|
265
|
-
var __toESM = function __toESM(mod, isNodeMode, target) {
|
|
266
|
-
return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
|
|
267
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
268
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
269
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
270
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
271
|
-
value: mod,
|
|
272
|
-
enumerable: true
|
|
273
|
-
}) : target, mod);
|
|
274
|
-
};
|
|
275
|
-
var __toCommonJS = function __toCommonJS(mod) {
|
|
276
|
-
return __copyProps(__defProp({}, "__esModule", {
|
|
277
|
-
value: true
|
|
278
|
-
}), mod);
|
|
279
|
-
};
|
|
280
|
-
// src/sdk/vastAdLayer.ts
|
|
281
|
-
var vastAdLayer_exports = {};
|
|
282
|
-
__export(vastAdLayer_exports, {
|
|
283
|
-
createVastAdLayer: function createVastAdLayer1() {
|
|
284
|
-
return createVastAdLayer;
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
module.exports = __toCommonJS(vastAdLayer_exports);
|
|
288
|
-
// src/sdk/vastParser.ts
|
|
289
|
-
function isHlsType(type) {
|
|
290
|
-
return type === "application/x-mpegURL" || type.includes("m3u8");
|
|
291
|
-
}
|
|
292
|
-
function isMp4Type(type) {
|
|
293
|
-
return type === "video/mp4" || type.includes("mp4");
|
|
294
|
-
}
|
|
295
|
-
function parseVastXml(xmlString) {
|
|
296
|
-
var filter = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "all", logPrefix = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "[VastParser]";
|
|
297
|
-
try {
|
|
298
|
-
var _xmlDoc_querySelector, _xmlDoc_querySelector1, _xmlDoc_querySelector_textContent, _xmlDoc_querySelector2;
|
|
299
|
-
var parser = new DOMParser();
|
|
300
|
-
var xmlDoc = parser.parseFromString(xmlString, "text/xml");
|
|
301
|
-
var parserError = xmlDoc.querySelector("parsererror");
|
|
302
|
-
if (parserError) {
|
|
303
|
-
console.error("".concat(logPrefix, " XML parsing error (malformed VAST XML):"), parserError.textContent);
|
|
304
|
-
return null;
|
|
305
|
-
}
|
|
306
|
-
var adElement = xmlDoc.querySelector("Ad");
|
|
307
|
-
if (!adElement) {
|
|
308
|
-
console.warn("".concat(logPrefix, " No Ad element found in VAST XML"));
|
|
309
|
-
return null;
|
|
310
|
-
}
|
|
311
|
-
var adId = adElement.getAttribute("id") || "unknown";
|
|
312
|
-
var title = ((_xmlDoc_querySelector = xmlDoc.querySelector("AdTitle")) === null || _xmlDoc_querySelector === void 0 ? void 0 : _xmlDoc_querySelector.textContent) || "Ad";
|
|
313
|
-
var isNoAdAvailable = adId === "empty" || title.toLowerCase().includes("no ad available") || title.toLowerCase() === "no ad available";
|
|
314
|
-
var durationText = ((_xmlDoc_querySelector1 = xmlDoc.querySelector("Duration")) === null || _xmlDoc_querySelector1 === void 0 ? void 0 : _xmlDoc_querySelector1.textContent) || "00:00:30";
|
|
315
|
-
var durationParts = durationText.split(":");
|
|
316
|
-
var duration = parseInt(durationParts[0] || "0", 10) * 3600 + parseInt(durationParts[1] || "0", 10) * 60 + Math.round(parseFloat(durationParts[2] || "0"));
|
|
317
|
-
var mediaFileElements = xmlDoc.querySelectorAll("MediaFile");
|
|
318
|
-
var mediaFiles = [];
|
|
319
|
-
console.log("".concat(logPrefix, " Found ").concat(mediaFileElements.length, " MediaFile element(s) in VAST XML"));
|
|
320
|
-
mediaFileElements.forEach(function(mf, index) {
|
|
321
|
-
var _mf_textContent;
|
|
322
|
-
var type = mf.getAttribute("type") || "";
|
|
323
|
-
var url = ((_mf_textContent = mf.textContent) === null || _mf_textContent === void 0 ? void 0 : _mf_textContent.trim()) || "";
|
|
324
|
-
var width = mf.getAttribute("width") || "";
|
|
325
|
-
var height = mf.getAttribute("height") || "";
|
|
326
|
-
console.log("".concat(logPrefix, " MediaFile ").concat(index, ': type="').concat(type, '", url="').concat(url.substring(0, 80), '...", width="').concat(width, '", height="').concat(height, '"'));
|
|
327
|
-
if (!url) {
|
|
328
|
-
console.warn("".concat(logPrefix, " MediaFile ").concat(index, " has empty URL"));
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
var isHls = isHlsType(type);
|
|
332
|
-
var isMp4 = isMp4Type(type);
|
|
333
|
-
var accepted = false;
|
|
334
|
-
if (filter === "hls-only") {
|
|
335
|
-
accepted = isHls;
|
|
336
|
-
} else if (filter === "mp4-first") {
|
|
337
|
-
accepted = isMp4 || isHls;
|
|
338
|
-
} else {
|
|
339
|
-
accepted = true;
|
|
340
|
-
}
|
|
341
|
-
if (!accepted) {
|
|
342
|
-
console.log("".concat(logPrefix, " MediaFile ").concat(index, ' ignored (type="').concat(type, '" not accepted by filter "').concat(filter, '")'));
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
var bitrateAttr = mf.getAttribute("bitrate");
|
|
346
|
-
var bitrateValue = bitrateAttr ? parseInt(bitrateAttr, 10) : void 0;
|
|
347
|
-
mediaFiles.push({
|
|
348
|
-
url: url,
|
|
349
|
-
type: type,
|
|
350
|
-
width: parseInt(width || "1920", 10),
|
|
351
|
-
height: parseInt(height || "1080", 10),
|
|
352
|
-
bitrate: bitrateValue && bitrateValue > 0 ? bitrateValue : void 0
|
|
353
|
-
});
|
|
354
|
-
console.log("".concat(logPrefix, ' Added MediaFile: type="').concat(type, '" url="').concat(url.substring(0, 80), '..."'));
|
|
355
|
-
});
|
|
356
|
-
if (filter === "mp4-first" && mediaFiles.length > 1) {
|
|
357
|
-
mediaFiles.sort(function(a, b) {
|
|
358
|
-
var aIsMp4 = isMp4Type(a.type) ? 0 : 1;
|
|
359
|
-
var bIsMp4 = isMp4Type(b.type) ? 0 : 1;
|
|
360
|
-
return aIsMp4 - bIsMp4;
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
if (mediaFiles.length === 0) {
|
|
364
|
-
if (isNoAdAvailable) {
|
|
365
|
-
console.warn("".concat(logPrefix, " No ads available (VAST response indicates no ads)"));
|
|
366
|
-
} else {
|
|
367
|
-
console.warn("".concat(logPrefix, " No compatible media files found in VAST XML"));
|
|
368
|
-
}
|
|
369
|
-
return null;
|
|
370
|
-
}
|
|
371
|
-
var trackingUrls = {
|
|
372
|
-
impression: [],
|
|
373
|
-
start: [],
|
|
374
|
-
firstQuartile: [],
|
|
375
|
-
midpoint: [],
|
|
376
|
-
thirdQuartile: [],
|
|
377
|
-
complete: [],
|
|
378
|
-
mute: [],
|
|
379
|
-
unmute: [],
|
|
380
|
-
pause: [],
|
|
381
|
-
resume: [],
|
|
382
|
-
fullscreen: [],
|
|
383
|
-
exitFullscreen: [],
|
|
384
|
-
skip: [],
|
|
385
|
-
error: []
|
|
386
|
-
};
|
|
387
|
-
xmlDoc.querySelectorAll("Impression").forEach(function(el) {
|
|
388
|
-
var _el_textContent;
|
|
389
|
-
var url = (_el_textContent = el.textContent) === null || _el_textContent === void 0 ? void 0 : _el_textContent.trim();
|
|
390
|
-
if (url) trackingUrls.impression.push(url);
|
|
391
|
-
});
|
|
392
|
-
xmlDoc.querySelectorAll("Tracking").forEach(function(el) {
|
|
393
|
-
var _el_textContent;
|
|
394
|
-
var event = el.getAttribute("event");
|
|
395
|
-
var url = (_el_textContent = el.textContent) === null || _el_textContent === void 0 ? void 0 : _el_textContent.trim();
|
|
396
|
-
if (event && url) {
|
|
397
|
-
var eventKey = event;
|
|
398
|
-
if (trackingUrls[eventKey]) {
|
|
399
|
-
trackingUrls[eventKey].push(url);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
var clickThrough = (_xmlDoc_querySelector2 = xmlDoc.querySelector("ClickThrough")) === null || _xmlDoc_querySelector2 === void 0 ? void 0 : (_xmlDoc_querySelector_textContent = _xmlDoc_querySelector2.textContent) === null || _xmlDoc_querySelector_textContent === void 0 ? void 0 : _xmlDoc_querySelector_textContent.trim();
|
|
404
|
-
return {
|
|
405
|
-
id: adId,
|
|
406
|
-
title: title,
|
|
407
|
-
duration: duration,
|
|
408
|
-
mediaFiles: mediaFiles,
|
|
409
|
-
trackingUrls: trackingUrls,
|
|
410
|
-
clickThrough: clickThrough
|
|
411
|
-
};
|
|
412
|
-
} catch (error) {
|
|
413
|
-
console.error("".concat(logPrefix, " Error parsing VAST XML:"), error);
|
|
414
|
-
return null;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
function fetchAndParseVastAd(vastTagUrl) {
|
|
418
|
-
var filter = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "all", logPrefix = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "[VastParser]";
|
|
419
|
-
return _async_to_generator(function() {
|
|
420
|
-
var response, vastXml;
|
|
421
|
-
return _ts_generator(this, function(_state) {
|
|
422
|
-
switch(_state.label){
|
|
423
|
-
case 0:
|
|
424
|
-
return [
|
|
425
|
-
4,
|
|
426
|
-
fetch(vastTagUrl, {
|
|
427
|
-
mode: "cors",
|
|
428
|
-
credentials: "include",
|
|
429
|
-
headers: {
|
|
430
|
-
Accept: "application/xml, text/xml, */*"
|
|
431
|
-
},
|
|
432
|
-
referrerPolicy: "no-referrer-when-downgrade"
|
|
433
|
-
})
|
|
434
|
-
];
|
|
435
|
-
case 1:
|
|
436
|
-
response = _state.sent();
|
|
437
|
-
if (!response.ok) {
|
|
438
|
-
throw new Error("Failed to fetch VAST: ".concat(response.statusText));
|
|
439
|
-
}
|
|
440
|
-
return [
|
|
441
|
-
4,
|
|
442
|
-
response.text()
|
|
443
|
-
];
|
|
444
|
-
case 2:
|
|
445
|
-
vastXml = _state.sent();
|
|
446
|
-
console.log("".concat(logPrefix, " VAST XML received"));
|
|
447
|
-
console.log("".concat(logPrefix, " VAST XML content (first 2000 chars):"), vastXml.substring(0, 2e3));
|
|
448
|
-
return [
|
|
449
|
-
2,
|
|
450
|
-
parseVastXml(vastXml, filter, logPrefix)
|
|
451
|
-
];
|
|
452
|
-
}
|
|
453
|
-
});
|
|
454
|
-
})();
|
|
455
|
-
}
|
|
456
|
-
function createEmptyTrackingState() {
|
|
457
|
-
return {
|
|
458
|
-
impression: false,
|
|
459
|
-
start: false,
|
|
460
|
-
firstQuartile: false,
|
|
461
|
-
midpoint: false,
|
|
462
|
-
thirdQuartile: false,
|
|
463
|
-
complete: false
|
|
464
|
-
};
|
|
465
|
-
}
|
|
466
|
-
function firePixelWithRetry(url) {
|
|
467
|
-
var retries = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 2, delayMs = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 500, logPrefix = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "[VastParser]";
|
|
468
|
-
return _async_to_generator(function() {
|
|
469
|
-
var _loop, attempt, _ret;
|
|
470
|
-
return _ts_generator(this, function(_state) {
|
|
471
|
-
switch(_state.label){
|
|
472
|
-
case 0:
|
|
473
|
-
_loop = function(attempt) {
|
|
474
|
-
var unused;
|
|
475
|
-
return _ts_generator(this, function(_state) {
|
|
476
|
-
switch(_state.label){
|
|
477
|
-
case 0:
|
|
478
|
-
_state.trys.push([
|
|
479
|
-
0,
|
|
480
|
-
2,
|
|
481
|
-
,
|
|
482
|
-
6
|
|
483
|
-
]);
|
|
484
|
-
return [
|
|
485
|
-
4,
|
|
486
|
-
fetch(url, {
|
|
487
|
-
method: "GET",
|
|
488
|
-
mode: "no-cors",
|
|
489
|
-
cache: "no-cache",
|
|
490
|
-
keepalive: true
|
|
491
|
-
})
|
|
492
|
-
];
|
|
493
|
-
case 1:
|
|
494
|
-
_state.sent();
|
|
495
|
-
return [
|
|
496
|
-
2,
|
|
497
|
-
{
|
|
498
|
-
v: void void 0
|
|
499
|
-
}
|
|
500
|
-
];
|
|
501
|
-
case 2:
|
|
502
|
-
unused = _state.sent();
|
|
503
|
-
if (!(attempt < retries)) return [
|
|
504
|
-
3,
|
|
505
|
-
4
|
|
506
|
-
];
|
|
507
|
-
return [
|
|
508
|
-
4,
|
|
509
|
-
new Promise(function(r) {
|
|
510
|
-
return setTimeout(r, delayMs * Math.pow(2, attempt));
|
|
511
|
-
})
|
|
512
|
-
];
|
|
513
|
-
case 3:
|
|
514
|
-
_state.sent();
|
|
515
|
-
return [
|
|
516
|
-
3,
|
|
517
|
-
5
|
|
518
|
-
];
|
|
519
|
-
case 4:
|
|
520
|
-
console.warn("".concat(logPrefix, " Tracking pixel failed after ").concat(retries + 1, " attempts: ").concat(url));
|
|
521
|
-
_state.label = 5;
|
|
522
|
-
case 5:
|
|
523
|
-
return [
|
|
524
|
-
3,
|
|
525
|
-
6
|
|
526
|
-
];
|
|
527
|
-
case 6:
|
|
528
|
-
return [
|
|
529
|
-
2
|
|
530
|
-
];
|
|
531
|
-
}
|
|
532
|
-
});
|
|
533
|
-
};
|
|
534
|
-
attempt = 0;
|
|
535
|
-
_state.label = 1;
|
|
536
|
-
case 1:
|
|
537
|
-
if (!(attempt <= retries)) return [
|
|
538
|
-
3,
|
|
539
|
-
4
|
|
540
|
-
];
|
|
541
|
-
return [
|
|
542
|
-
5,
|
|
543
|
-
_ts_values(_loop(attempt))
|
|
544
|
-
];
|
|
545
|
-
case 2:
|
|
546
|
-
_ret = _state.sent();
|
|
547
|
-
if (_type_of(_ret) === "object") return [
|
|
548
|
-
2,
|
|
549
|
-
_ret.v
|
|
550
|
-
];
|
|
551
|
-
_state.label = 3;
|
|
552
|
-
case 3:
|
|
553
|
-
attempt++;
|
|
554
|
-
return [
|
|
555
|
-
3,
|
|
556
|
-
1
|
|
557
|
-
];
|
|
558
|
-
case 4:
|
|
559
|
-
return [
|
|
560
|
-
2
|
|
561
|
-
];
|
|
562
|
-
}
|
|
563
|
-
});
|
|
564
|
-
})();
|
|
565
|
-
}
|
|
566
|
-
function fireTrackingPixels(urls, sessionId) {
|
|
567
|
-
var logPrefix = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "[VastParser]";
|
|
568
|
-
if (!urls || urls.length === 0) return;
|
|
569
|
-
urls.forEach(function(url) {
|
|
570
|
-
try {
|
|
571
|
-
var trackingUrl = url;
|
|
572
|
-
if (sessionId) {
|
|
573
|
-
trackingUrl = "".concat(trackingUrl).concat(trackingUrl.includes("?") ? "&" : "?", "session_id=").concat(sessionId);
|
|
574
|
-
}
|
|
575
|
-
if (typeof fetch !== "undefined") {
|
|
576
|
-
firePixelWithRetry(trackingUrl, 2, 500, logPrefix).catch(function() {});
|
|
577
|
-
} else {
|
|
578
|
-
var img = new Image(1, 1);
|
|
579
|
-
img.onerror = function() {};
|
|
580
|
-
img.src = trackingUrl;
|
|
581
|
-
}
|
|
582
|
-
console.log("".concat(logPrefix, " Fired tracking pixel: ").concat(trackingUrl));
|
|
583
|
-
} catch (error) {
|
|
584
|
-
console.warn("".concat(logPrefix, " Error firing tracking pixel:"), error);
|
|
585
|
-
}
|
|
586
|
-
});
|
|
587
|
-
}
|
|
588
|
-
// src/sdk/vastAdLayer.ts
|
|
589
|
-
var import_hls = __toESM(require("hls.js"), 1);
|
|
590
|
-
var LOG = "[VastAdLayer]";
|
|
591
|
-
function resolveBidToVastAd(winner, logPrefix) {
|
|
592
|
-
if (winner.vastXml) {
|
|
593
|
-
var ad = parseVastXml(winner.vastXml, "mp4-first", logPrefix);
|
|
594
|
-
return Promise.resolve(ad);
|
|
595
|
-
}
|
|
596
|
-
if (winner.vastUrl) {
|
|
597
|
-
return fetchAndParseVastAd(winner.vastUrl, "mp4-first", logPrefix);
|
|
598
|
-
}
|
|
599
|
-
return Promise.resolve(null);
|
|
600
|
-
}
|
|
601
|
-
function createVastAdLayer(contentVideo, options) {
|
|
602
|
-
var _ref, _ref1, _ref2, _ref3, _ref4;
|
|
603
|
-
var adPlaying = false;
|
|
604
|
-
var originalMutedState = false;
|
|
605
|
-
var originalVolume = Math.max(0, Math.min(1, contentVideo.volume || 1));
|
|
606
|
-
var listeners = /* @__PURE__ */ new Map();
|
|
607
|
-
var mainHlsInstance = options === null || options === void 0 ? void 0 : options.mainHlsInstance;
|
|
608
|
-
var continueLiveStreamDuringAds = (_ref = options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds) !== null && _ref !== void 0 ? _ref : false;
|
|
609
|
-
var smartTVMode = (_ref1 = options === null || options === void 0 ? void 0 : options.smartTVMode) !== null && _ref1 !== void 0 ? _ref1 : false;
|
|
610
|
-
var singleElementMode = (_ref2 = options === null || options === void 0 ? void 0 : options.singleElementMode) !== null && _ref2 !== void 0 ? _ref2 : false;
|
|
611
|
-
var forceMP4Ads = (_ref3 = options === null || options === void 0 ? void 0 : options.forceMP4Ads) !== null && _ref3 !== void 0 ? _ref3 : smartTVMode || singleElementMode;
|
|
612
|
-
var debug = (_ref4 = options === null || options === void 0 ? void 0 : options.debug) !== null && _ref4 !== void 0 ? _ref4 : false;
|
|
613
|
-
var adVideoElement;
|
|
614
|
-
var adHls;
|
|
615
|
-
var adContainerEl;
|
|
616
|
-
var currentAd;
|
|
617
|
-
var sessionId;
|
|
618
|
-
var destroyed = false;
|
|
619
|
-
var tornDown = false;
|
|
620
|
-
var trackingFired = createEmptyTrackingState();
|
|
621
|
-
var adStallTimerId;
|
|
622
|
-
var currentAdEventHandlers;
|
|
623
|
-
var preloadSlots = /* @__PURE__ */ new Map();
|
|
624
|
-
function emit(event, payload) {
|
|
625
|
-
var set = listeners.get(event);
|
|
626
|
-
if (!set) return;
|
|
627
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
628
|
-
try {
|
|
629
|
-
for(var _iterator = Array.from(set)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
630
|
-
var fn = _step.value;
|
|
631
|
-
try {
|
|
632
|
-
fn(payload);
|
|
633
|
-
} catch (error) {
|
|
634
|
-
console.warn("".concat(LOG, " Error in event listener for ").concat(event, ":"), error);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
} catch (err) {
|
|
638
|
-
_didIteratorError = true;
|
|
639
|
-
_iteratorError = err;
|
|
640
|
-
} finally{
|
|
641
|
-
try {
|
|
642
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
643
|
-
_iterator.return();
|
|
644
|
-
}
|
|
645
|
-
} finally{
|
|
646
|
-
if (_didIteratorError) {
|
|
647
|
-
throw _iteratorError;
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
function generateSessionId() {
|
|
653
|
-
return "session-".concat(Date.now(), "-").concat(Math.random().toString(36).substr(2, 9));
|
|
654
|
-
}
|
|
655
|
-
function fireTrackingPixels2(urls) {
|
|
656
|
-
fireTrackingPixels(urls, sessionId, LOG);
|
|
657
|
-
}
|
|
658
|
-
function getMainStreamQuality() {
|
|
659
|
-
if (!(mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.levels)) return null;
|
|
660
|
-
var currentLevel = mainHlsInstance.currentLevel;
|
|
661
|
-
if (currentLevel === -1 || !mainHlsInstance.levels[currentLevel]) {
|
|
662
|
-
var autoLevel = mainHlsInstance.loadLevel;
|
|
663
|
-
if (autoLevel !== -1 && mainHlsInstance.levels[autoLevel]) {
|
|
664
|
-
var level2 = mainHlsInstance.levels[autoLevel];
|
|
665
|
-
return {
|
|
666
|
-
width: level2.width || 1920,
|
|
667
|
-
height: level2.height || 1080,
|
|
668
|
-
bitrate: level2.bitrate || 5e6
|
|
669
|
-
};
|
|
670
|
-
}
|
|
671
|
-
return null;
|
|
672
|
-
}
|
|
673
|
-
var level = mainHlsInstance.levels[currentLevel];
|
|
674
|
-
return {
|
|
675
|
-
width: level.width || 1920,
|
|
676
|
-
height: level.height || 1080,
|
|
677
|
-
bitrate: level.bitrate || 5e6
|
|
678
|
-
};
|
|
679
|
-
}
|
|
680
|
-
function selectBestMediaFile(mediaFiles) {
|
|
681
|
-
var _ref;
|
|
682
|
-
var _scoredFiles_;
|
|
683
|
-
if (mediaFiles.length === 0) throw new Error("No media files available");
|
|
684
|
-
var candidates = mediaFiles;
|
|
685
|
-
if (forceMP4Ads) {
|
|
686
|
-
var mp4Only = candidates.filter(function(f) {
|
|
687
|
-
return !isHlsMediaFile(f);
|
|
688
|
-
});
|
|
689
|
-
if (mp4Only.length > 0) {
|
|
690
|
-
candidates = mp4Only;
|
|
691
|
-
if (debug) console.log("".concat(LOG, " forceMP4Ads: filtered to ").concat(mp4Only.length, " MP4-only file(s)"));
|
|
692
|
-
} else if (debug) {
|
|
693
|
-
console.warn("".concat(LOG, " forceMP4Ads: no MP4 files available, falling back to all media files"));
|
|
694
|
-
}
|
|
695
|
-
} else {
|
|
696
|
-
var mp4Only1 = candidates.filter(function(f) {
|
|
697
|
-
return !isHlsMediaFile(f);
|
|
698
|
-
});
|
|
699
|
-
if (mp4Only1.length > 0) {
|
|
700
|
-
candidates = mp4Only1;
|
|
701
|
-
if (debug) console.log("".concat(LOG, " Preferring ").concat(mp4Only1.length, " MP4 file(s) over HLS (mp4-first)"));
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
var firstFile = candidates[0];
|
|
705
|
-
if (candidates.length === 1) return firstFile;
|
|
706
|
-
var mainQuality = getMainStreamQuality();
|
|
707
|
-
if (!mainQuality) {
|
|
708
|
-
if (debug) console.log("".concat(LOG, " No main stream quality info, using first media file"));
|
|
709
|
-
return firstFile;
|
|
710
|
-
}
|
|
711
|
-
var scoredFiles = candidates.map(function(file) {
|
|
712
|
-
var widthDiff = Math.abs(file.width - mainQuality.width);
|
|
713
|
-
var heightDiff = Math.abs(file.height - mainQuality.height);
|
|
714
|
-
var resolutionDiff = widthDiff + heightDiff;
|
|
715
|
-
var fileBitrate = (file.bitrate || 5e3) * 1e3;
|
|
716
|
-
var bitrateDiff = Math.abs(fileBitrate - mainQuality.bitrate);
|
|
717
|
-
var score = resolutionDiff * 2 + bitrateDiff / 1e3;
|
|
718
|
-
return {
|
|
719
|
-
file: file,
|
|
720
|
-
score: score
|
|
721
|
-
};
|
|
722
|
-
});
|
|
723
|
-
scoredFiles.sort(function(a, b) {
|
|
724
|
-
return a.score - b.score;
|
|
725
|
-
});
|
|
726
|
-
return (_ref = (_scoredFiles_ = scoredFiles[0]) === null || _scoredFiles_ === void 0 ? void 0 : _scoredFiles_.file) !== null && _ref !== void 0 ? _ref : firstFile;
|
|
727
|
-
}
|
|
728
|
-
function isHlsMediaFile(file) {
|
|
729
|
-
return file.type === "application/x-mpegURL" || file.type.includes("m3u8");
|
|
730
|
-
}
|
|
731
|
-
function createAdVideoElement() {
|
|
732
|
-
var video = document.createElement("video");
|
|
733
|
-
video.style.position = "absolute";
|
|
734
|
-
video.style.left = "0";
|
|
735
|
-
video.style.top = "0";
|
|
736
|
-
video.style.width = "100%";
|
|
737
|
-
video.style.height = "100%";
|
|
738
|
-
video.style.objectFit = "contain";
|
|
739
|
-
video.style.backgroundColor = "#000";
|
|
740
|
-
video.playsInline = true;
|
|
741
|
-
video.muted = false;
|
|
742
|
-
video.volume = 1;
|
|
743
|
-
return video;
|
|
744
|
-
}
|
|
745
|
-
function clearAdStallTimer() {
|
|
746
|
-
if (adStallTimerId != null) {
|
|
747
|
-
clearTimeout(adStallTimerId);
|
|
748
|
-
adStallTimerId = void 0;
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
function removeAdEventListeners() {
|
|
752
|
-
clearAdStallTimer();
|
|
753
|
-
if (!currentAdEventHandlers || !adVideoElement) return;
|
|
754
|
-
var el = adVideoElement;
|
|
755
|
-
el.removeEventListener("timeupdate", currentAdEventHandlers.timeupdate);
|
|
756
|
-
el.removeEventListener("playing", currentAdEventHandlers.playing);
|
|
757
|
-
el.removeEventListener("ended", currentAdEventHandlers.ended);
|
|
758
|
-
el.removeEventListener("error", currentAdEventHandlers.error);
|
|
759
|
-
el.removeEventListener("volumechange", currentAdEventHandlers.volumechange);
|
|
760
|
-
el.removeEventListener("pause", currentAdEventHandlers.pause);
|
|
761
|
-
el.removeEventListener("play", currentAdEventHandlers.play);
|
|
762
|
-
el.removeEventListener("waiting", currentAdEventHandlers.waiting);
|
|
763
|
-
currentAdEventHandlers = void 0;
|
|
764
|
-
}
|
|
765
|
-
function setupAdEventListeners() {
|
|
766
|
-
if (!adVideoElement) return;
|
|
767
|
-
removeAdEventListeners();
|
|
768
|
-
var handlers = {
|
|
769
|
-
timeupdate: function timeupdate() {
|
|
770
|
-
var ad = currentAd;
|
|
771
|
-
if (!ad || !adVideoElement) return;
|
|
772
|
-
var progress = adVideoElement.currentTime / ad.duration;
|
|
773
|
-
if (progress >= 0.25 && !trackingFired.firstQuartile) {
|
|
774
|
-
trackingFired.firstQuartile = true;
|
|
775
|
-
fireTrackingPixels2(ad.trackingUrls.firstQuartile);
|
|
776
|
-
}
|
|
777
|
-
if (progress >= 0.5 && !trackingFired.midpoint) {
|
|
778
|
-
trackingFired.midpoint = true;
|
|
779
|
-
fireTrackingPixels2(ad.trackingUrls.midpoint);
|
|
780
|
-
}
|
|
781
|
-
if (progress >= 0.75 && !trackingFired.thirdQuartile) {
|
|
782
|
-
trackingFired.thirdQuartile = true;
|
|
783
|
-
fireTrackingPixels2(ad.trackingUrls.thirdQuartile);
|
|
784
|
-
}
|
|
785
|
-
},
|
|
786
|
-
playing: function playing() {
|
|
787
|
-
clearAdStallTimer();
|
|
788
|
-
var ad = currentAd;
|
|
789
|
-
if (!ad || trackingFired.start) return;
|
|
790
|
-
trackingFired.start = true;
|
|
791
|
-
fireTrackingPixels2(ad.trackingUrls.start);
|
|
792
|
-
if (debug) console.log("".concat(LOG, " Ad started playing"));
|
|
793
|
-
},
|
|
794
|
-
ended: function ended() {
|
|
795
|
-
if (tornDown || !currentAd || trackingFired.complete) return;
|
|
796
|
-
trackingFired.complete = true;
|
|
797
|
-
fireTrackingPixels2(currentAd.trackingUrls.complete);
|
|
798
|
-
if (debug) console.log("".concat(LOG, " Ad completed"));
|
|
799
|
-
handleAdComplete();
|
|
800
|
-
},
|
|
801
|
-
error: function error(e) {
|
|
802
|
-
if (tornDown) return;
|
|
803
|
-
console.error("".concat(LOG, " Ad video error:"), e);
|
|
804
|
-
if (currentAd) fireTrackingPixels2(currentAd.trackingUrls.error);
|
|
805
|
-
handleAdError();
|
|
806
|
-
},
|
|
807
|
-
volumechange: function volumechange() {
|
|
808
|
-
if (!currentAd || !adVideoElement) return;
|
|
809
|
-
if (adVideoElement.muted) {
|
|
810
|
-
fireTrackingPixels2(currentAd.trackingUrls.mute);
|
|
811
|
-
} else {
|
|
812
|
-
fireTrackingPixels2(currentAd.trackingUrls.unmute);
|
|
813
|
-
}
|
|
814
|
-
},
|
|
815
|
-
pause: function pause() {
|
|
816
|
-
if (currentAd && adVideoElement && !adVideoElement.ended) {
|
|
817
|
-
fireTrackingPixels2(currentAd.trackingUrls.pause);
|
|
818
|
-
}
|
|
819
|
-
},
|
|
820
|
-
play: function play() {
|
|
821
|
-
if (currentAd && adVideoElement && adVideoElement.currentTime > 0) {
|
|
822
|
-
fireTrackingPixels2(currentAd.trackingUrls.resume);
|
|
823
|
-
}
|
|
824
|
-
},
|
|
825
|
-
waiting: function waiting() {
|
|
826
|
-
clearAdStallTimer();
|
|
827
|
-
adStallTimerId = setTimeout(function() {
|
|
828
|
-
adStallTimerId = void 0;
|
|
829
|
-
if (adPlaying) {
|
|
830
|
-
if (debug) console.warn("".concat(LOG, " Ad video stalled for too long, treating as error"));
|
|
831
|
-
handleAdError();
|
|
832
|
-
}
|
|
833
|
-
}, 8e3);
|
|
834
|
-
}
|
|
835
|
-
};
|
|
836
|
-
adVideoElement.addEventListener("timeupdate", handlers.timeupdate);
|
|
837
|
-
adVideoElement.addEventListener("playing", handlers.playing);
|
|
838
|
-
adVideoElement.addEventListener("ended", handlers.ended);
|
|
839
|
-
adVideoElement.addEventListener("error", handlers.error);
|
|
840
|
-
adVideoElement.addEventListener("volumechange", handlers.volumechange);
|
|
841
|
-
adVideoElement.addEventListener("pause", handlers.pause);
|
|
842
|
-
adVideoElement.addEventListener("play", handlers.play);
|
|
843
|
-
adVideoElement.addEventListener("waiting", handlers.waiting);
|
|
844
|
-
currentAdEventHandlers = handlers;
|
|
845
|
-
}
|
|
846
|
-
function setAdPlayingFlag(isPlaying) {
|
|
847
|
-
if (isPlaying) {
|
|
848
|
-
contentVideo.dataset.stormcloudAdPlaying = "true";
|
|
849
|
-
} else {
|
|
850
|
-
delete contentVideo.dataset.stormcloudAdPlaying;
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
function handleAdComplete() {
|
|
854
|
-
if (tornDown) return;
|
|
855
|
-
clearAdStallTimer();
|
|
856
|
-
if (debug) console.log("".concat(LOG, " Handling ad completion"));
|
|
857
|
-
adPlaying = false;
|
|
858
|
-
setAdPlayingFlag(false);
|
|
859
|
-
if (adContainerEl) {
|
|
860
|
-
adContainerEl.style.display = "none";
|
|
861
|
-
adContainerEl.style.pointerEvents = "none";
|
|
862
|
-
}
|
|
863
|
-
emit("ad_impression");
|
|
864
|
-
emit("content_resume");
|
|
865
|
-
}
|
|
866
|
-
function handleAdError() {
|
|
867
|
-
if (tornDown) return;
|
|
868
|
-
if (!adPlaying) return;
|
|
869
|
-
clearAdStallTimer();
|
|
870
|
-
if (debug) console.log("".concat(LOG, " Handling ad error"));
|
|
871
|
-
adPlaying = false;
|
|
872
|
-
setAdPlayingFlag(false);
|
|
873
|
-
if (adContainerEl) {
|
|
874
|
-
adContainerEl.style.display = "none";
|
|
875
|
-
adContainerEl.style.pointerEvents = "none";
|
|
876
|
-
}
|
|
877
|
-
emit("ad_error");
|
|
878
|
-
}
|
|
879
|
-
function teardownCurrentPlayback() {
|
|
880
|
-
removeAdEventListeners();
|
|
881
|
-
if (adHls) {
|
|
882
|
-
adHls.destroy();
|
|
883
|
-
adHls = void 0;
|
|
884
|
-
}
|
|
885
|
-
if (adVideoElement) {
|
|
886
|
-
if (singleElementMode && adVideoElement === contentVideo) {
|
|
887
|
-
contentVideo.pause();
|
|
888
|
-
} else {
|
|
889
|
-
adVideoElement.pause();
|
|
890
|
-
adVideoElement.removeAttribute("src");
|
|
891
|
-
adVideoElement.load();
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
function startNativePlayback(mediaFile) {
|
|
896
|
-
if (!adVideoElement) return;
|
|
897
|
-
if (debug) console.log("".concat(LOG, " Starting native MP4 playback: ").concat(mediaFile.url));
|
|
898
|
-
adVideoElement.src = mediaFile.url;
|
|
899
|
-
adVideoElement.load();
|
|
900
|
-
adVideoElement.play().catch(function(error) {
|
|
901
|
-
console.error("".concat(LOG, " Error starting native ad playback:"), error);
|
|
902
|
-
handleAdError();
|
|
903
|
-
});
|
|
904
|
-
}
|
|
905
|
-
function startHlsPlayback(mediaFile) {
|
|
906
|
-
if (!adVideoElement) return;
|
|
907
|
-
if (debug) console.log("".concat(LOG, " Starting HLS playback: ").concat(mediaFile.url));
|
|
908
|
-
if (import_hls.default.isSupported()) {
|
|
909
|
-
if (adHls) {
|
|
910
|
-
adHls.destroy();
|
|
911
|
-
adHls = void 0;
|
|
912
|
-
}
|
|
913
|
-
adHls = new import_hls.default({
|
|
914
|
-
enableWorker: true,
|
|
915
|
-
lowLatencyMode: false
|
|
916
|
-
});
|
|
917
|
-
adHls.loadSource(mediaFile.url);
|
|
918
|
-
adHls.attachMedia(adVideoElement);
|
|
919
|
-
adHls.on(import_hls.default.Events.MANIFEST_PARSED, function() {
|
|
920
|
-
if (!adPlaying) return;
|
|
921
|
-
adVideoElement.play().catch(function(error) {
|
|
922
|
-
console.error("".concat(LOG, " Error starting HLS ad playback:"), error);
|
|
923
|
-
handleAdError();
|
|
924
|
-
});
|
|
925
|
-
});
|
|
926
|
-
var nonFatalNetworkErrors = 0;
|
|
927
|
-
adHls.on(import_hls.default.Events.ERROR, function(_event, data) {
|
|
928
|
-
if (data.fatal) {
|
|
929
|
-
handleAdError();
|
|
930
|
-
} else if (data.type === import_hls.default.ErrorTypes.NETWORK_ERROR) {
|
|
931
|
-
nonFatalNetworkErrors++;
|
|
932
|
-
if (nonFatalNetworkErrors >= 3) {
|
|
933
|
-
if (debug) console.warn("".concat(LOG, " Too many non-fatal HLS network errors (").concat(nonFatalNetworkErrors, "), treating as fatal"));
|
|
934
|
-
handleAdError();
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
});
|
|
938
|
-
} else if (adVideoElement.canPlayType("application/vnd.apple.mpegurl")) {
|
|
939
|
-
adVideoElement.src = mediaFile.url;
|
|
940
|
-
adVideoElement.play().catch(function(error) {
|
|
941
|
-
console.error("".concat(LOG, " Error starting native HLS ad playback:"), error);
|
|
942
|
-
handleAdError();
|
|
943
|
-
});
|
|
944
|
-
} else {
|
|
945
|
-
console.error("".concat(LOG, " HLS not supported on this platform"));
|
|
946
|
-
handleAdError();
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
function startPlayback(mediaFile) {
|
|
950
|
-
if (!adVideoElement) return;
|
|
951
|
-
if (singleElementMode && isHlsMediaFile(mediaFile)) {
|
|
952
|
-
var mp4Fallback = currentAd === null || currentAd === void 0 ? void 0 : currentAd.mediaFiles.find(function(f) {
|
|
953
|
-
return !isHlsMediaFile(f);
|
|
954
|
-
});
|
|
955
|
-
if (mp4Fallback) {
|
|
956
|
-
if (debug) console.log("".concat(LOG, " singleElementMode: HLS ad blocked, using MP4 fallback"));
|
|
957
|
-
startNativePlayback(mp4Fallback);
|
|
958
|
-
return;
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
if (isHlsMediaFile(mediaFile)) {
|
|
962
|
-
startHlsPlayback(mediaFile);
|
|
963
|
-
} else {
|
|
964
|
-
startNativePlayback(mediaFile);
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
function playAd(bids) {
|
|
968
|
-
return _async_to_generator(function() {
|
|
969
|
-
var winner, ad, contentVolume, adVolume2, mediaFile2, _contentVideo_parentElement, container, adVolume, mediaFile;
|
|
970
|
-
return _ts_generator(this, function(_state) {
|
|
971
|
-
switch(_state.label){
|
|
972
|
-
case 0:
|
|
973
|
-
if (destroyed) {
|
|
974
|
-
return [
|
|
975
|
-
2,
|
|
976
|
-
Promise.reject(new Error("Layer has been destroyed"))
|
|
977
|
-
];
|
|
978
|
-
}
|
|
979
|
-
if (bids.length === 0) {
|
|
980
|
-
return [
|
|
981
|
-
2,
|
|
982
|
-
Promise.reject(new Error("No bids provided"))
|
|
983
|
-
];
|
|
984
|
-
}
|
|
985
|
-
winner = bids[0];
|
|
986
|
-
if (debug) {
|
|
987
|
-
console.log("".concat(LOG, " Winning bid: ").concat(winner.bidder, " $").concat(winner.cpm.toFixed(2), " ").concat(winner.currency));
|
|
988
|
-
}
|
|
989
|
-
return [
|
|
990
|
-
4,
|
|
991
|
-
resolveBidToVastAd(winner, LOG)
|
|
992
|
-
];
|
|
993
|
-
case 1:
|
|
994
|
-
ad = _state.sent();
|
|
995
|
-
if (!ad) {
|
|
996
|
-
if (debug) console.warn("".concat(LOG, " Winning bid has no VAST URL or XML"));
|
|
997
|
-
emit("ad_error");
|
|
998
|
-
return [
|
|
999
|
-
2,
|
|
1000
|
-
Promise.reject(new Error("No VAST from bid"))
|
|
1001
|
-
];
|
|
1002
|
-
}
|
|
1003
|
-
if (debug) {
|
|
1004
|
-
console.log("".concat(LOG, " Ad parsed: ").concat(ad.title, ", duration: ").concat(ad.duration, "s, mediaFiles: ").concat(ad.mediaFiles.length));
|
|
1005
|
-
}
|
|
1006
|
-
sessionId = generateSessionId();
|
|
1007
|
-
currentAd = ad;
|
|
1008
|
-
trackingFired = _object_spread({}, createEmptyTrackingState());
|
|
1009
|
-
fireTrackingPixels2(ad.trackingUrls.impression);
|
|
1010
|
-
trackingFired.impression = true;
|
|
1011
|
-
contentVolume = contentVideo.volume;
|
|
1012
|
-
originalVolume = Math.max(0, Math.min(1, contentVolume || originalVolume));
|
|
1013
|
-
if (!singleElementMode) return [
|
|
1014
|
-
3,
|
|
1015
|
-
3
|
|
1016
|
-
];
|
|
1017
|
-
mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
|
|
1018
|
-
teardownCurrentPlayback();
|
|
1019
|
-
adVideoElement = contentVideo;
|
|
1020
|
-
adHls = void 0;
|
|
1021
|
-
adPlaying = true;
|
|
1022
|
-
setAdPlayingFlag(true);
|
|
1023
|
-
contentVideo.removeAttribute("src");
|
|
1024
|
-
contentVideo.load();
|
|
1025
|
-
if (!continueLiveStreamDuringAds) {
|
|
1026
|
-
contentVideo.pause();
|
|
1027
|
-
}
|
|
1028
|
-
contentVideo.muted = true;
|
|
1029
|
-
contentVideo.volume = 0;
|
|
1030
|
-
return [
|
|
1031
|
-
4,
|
|
1032
|
-
new Promise(function(resolve) {
|
|
1033
|
-
return setTimeout(resolve, 200);
|
|
1034
|
-
})
|
|
1035
|
-
];
|
|
1036
|
-
case 2:
|
|
1037
|
-
_state.sent();
|
|
1038
|
-
if (destroyed || tornDown) return [
|
|
1039
|
-
2
|
|
1040
|
-
];
|
|
1041
|
-
contentVideo.style.visibility = "visible";
|
|
1042
|
-
contentVideo.style.opacity = "1";
|
|
1043
|
-
emit("content_pause");
|
|
1044
|
-
setupAdEventListeners();
|
|
1045
|
-
adVolume2 = originalMutedState ? 1 : originalVolume;
|
|
1046
|
-
adVideoElement.volume = Math.max(0, Math.min(1, adVolume2));
|
|
1047
|
-
adVideoElement.muted = false;
|
|
1048
|
-
mediaFile2 = selectBestMediaFile(ad.mediaFiles);
|
|
1049
|
-
if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile2.url));
|
|
1050
|
-
startPlayback(mediaFile2);
|
|
1051
|
-
return [
|
|
1052
|
-
2
|
|
1053
|
-
];
|
|
1054
|
-
case 3:
|
|
1055
|
-
if (!adContainerEl) {
|
|
1056
|
-
;
|
|
1057
|
-
container = document.createElement("div");
|
|
1058
|
-
container.style.position = "absolute";
|
|
1059
|
-
container.style.left = "0";
|
|
1060
|
-
container.style.top = "0";
|
|
1061
|
-
container.style.right = "0";
|
|
1062
|
-
container.style.bottom = "0";
|
|
1063
|
-
container.style.display = "none";
|
|
1064
|
-
container.style.alignItems = "center";
|
|
1065
|
-
container.style.justifyContent = "center";
|
|
1066
|
-
container.style.pointerEvents = "none";
|
|
1067
|
-
container.style.zIndex = "10";
|
|
1068
|
-
container.style.backgroundColor = "#000";
|
|
1069
|
-
(_contentVideo_parentElement = contentVideo.parentElement) === null || _contentVideo_parentElement === void 0 ? void 0 : _contentVideo_parentElement.appendChild(container);
|
|
1070
|
-
adContainerEl = container;
|
|
1071
|
-
}
|
|
1072
|
-
if (!adVideoElement) {
|
|
1073
|
-
adVideoElement = createAdVideoElement();
|
|
1074
|
-
adContainerEl.appendChild(adVideoElement);
|
|
1075
|
-
setupAdEventListeners();
|
|
1076
|
-
} else {
|
|
1077
|
-
teardownCurrentPlayback();
|
|
1078
|
-
}
|
|
1079
|
-
if (!continueLiveStreamDuringAds) {
|
|
1080
|
-
contentVideo.pause();
|
|
1081
|
-
}
|
|
1082
|
-
contentVideo.muted = true;
|
|
1083
|
-
contentVideo.volume = 0;
|
|
1084
|
-
adPlaying = true;
|
|
1085
|
-
setAdPlayingFlag(true);
|
|
1086
|
-
adVolume = originalMutedState ? 1 : originalVolume;
|
|
1087
|
-
adVideoElement.volume = Math.max(0, Math.min(1, adVolume));
|
|
1088
|
-
adVideoElement.muted = false;
|
|
1089
|
-
if (adContainerEl) {
|
|
1090
|
-
adContainerEl.style.display = "flex";
|
|
1091
|
-
adContainerEl.style.pointerEvents = "auto";
|
|
1092
|
-
}
|
|
1093
|
-
emit("content_pause");
|
|
1094
|
-
mediaFile = selectBestMediaFile(ad.mediaFiles);
|
|
1095
|
-
if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile.url));
|
|
1096
|
-
startPlayback(mediaFile);
|
|
1097
|
-
return [
|
|
1098
|
-
2
|
|
1099
|
-
];
|
|
1100
|
-
}
|
|
1101
|
-
});
|
|
1102
|
-
})();
|
|
1103
|
-
}
|
|
1104
|
-
function ensureAdContainer() {
|
|
1105
|
-
if (!adContainerEl) {
|
|
1106
|
-
var _contentVideo_parentElement;
|
|
1107
|
-
var container = document.createElement("div");
|
|
1108
|
-
container.style.position = "absolute";
|
|
1109
|
-
container.style.left = "0";
|
|
1110
|
-
container.style.top = "0";
|
|
1111
|
-
container.style.right = "0";
|
|
1112
|
-
container.style.bottom = "0";
|
|
1113
|
-
container.style.display = "none";
|
|
1114
|
-
container.style.alignItems = "center";
|
|
1115
|
-
container.style.justifyContent = "center";
|
|
1116
|
-
container.style.pointerEvents = "none";
|
|
1117
|
-
container.style.zIndex = "10";
|
|
1118
|
-
container.style.backgroundColor = "#000";
|
|
1119
|
-
(_contentVideo_parentElement = contentVideo.parentElement) === null || _contentVideo_parentElement === void 0 ? void 0 : _contentVideo_parentElement.appendChild(container);
|
|
1120
|
-
adContainerEl = container;
|
|
1121
|
-
}
|
|
1122
|
-
return adContainerEl;
|
|
1123
|
-
}
|
|
1124
|
-
function preloadAd(bids, token) {
|
|
1125
|
-
return _async_to_generator(function() {
|
|
1126
|
-
var winner, ad, mediaFile, slot, videoEl, container, hls, slot1, slot2;
|
|
1127
|
-
return _ts_generator(this, function(_state) {
|
|
1128
|
-
switch(_state.label){
|
|
1129
|
-
case 0:
|
|
1130
|
-
if (destroyed) return [
|
|
1131
|
-
2
|
|
1132
|
-
];
|
|
1133
|
-
winner = bids[0];
|
|
1134
|
-
if (!winner) return [
|
|
1135
|
-
2
|
|
1136
|
-
];
|
|
1137
|
-
if (debug) console.log("".concat(LOG, " [preload] Resolving VAST for token=").concat(token));
|
|
1138
|
-
return [
|
|
1139
|
-
4,
|
|
1140
|
-
resolveBidToVastAd(winner, LOG)
|
|
1141
|
-
];
|
|
1142
|
-
case 1:
|
|
1143
|
-
ad = _state.sent();
|
|
1144
|
-
if (!ad || destroyed) return [
|
|
1145
|
-
2
|
|
1146
|
-
];
|
|
1147
|
-
mediaFile = selectBestMediaFile(ad.mediaFiles);
|
|
1148
|
-
if (!mediaFile) return [
|
|
1149
|
-
2
|
|
1150
|
-
];
|
|
1151
|
-
if (smartTVMode || singleElementMode) {
|
|
1152
|
-
slot = {
|
|
1153
|
-
bids: bids,
|
|
1154
|
-
ad: ad,
|
|
1155
|
-
mediaFile: mediaFile,
|
|
1156
|
-
videoEl: null,
|
|
1157
|
-
ready: true
|
|
1158
|
-
};
|
|
1159
|
-
preloadSlots.set(token, slot);
|
|
1160
|
-
if (debug) console.log("".concat(LOG, " [preload] Metadata-only preload (smartTV/singleElement), token=").concat(token, ", url=").concat(mediaFile.url));
|
|
1161
|
-
return [
|
|
1162
|
-
2
|
|
1163
|
-
];
|
|
1164
|
-
}
|
|
1165
|
-
videoEl = createAdVideoElement();
|
|
1166
|
-
videoEl.style.visibility = "hidden";
|
|
1167
|
-
videoEl.style.pointerEvents = "none";
|
|
1168
|
-
videoEl.preload = "auto";
|
|
1169
|
-
container = ensureAdContainer();
|
|
1170
|
-
container.appendChild(videoEl);
|
|
1171
|
-
if (isHlsMediaFile(mediaFile) && import_hls.default.isSupported()) {
|
|
1172
|
-
hls = new import_hls.default({
|
|
1173
|
-
enableWorker: true,
|
|
1174
|
-
lowLatencyMode: false
|
|
1175
|
-
});
|
|
1176
|
-
hls.loadSource(mediaFile.url);
|
|
1177
|
-
hls.attachMedia(videoEl);
|
|
1178
|
-
slot1 = {
|
|
1179
|
-
bids: bids,
|
|
1180
|
-
ad: ad,
|
|
1181
|
-
mediaFile: mediaFile,
|
|
1182
|
-
videoEl: videoEl,
|
|
1183
|
-
hlsInstance: hls,
|
|
1184
|
-
ready: false
|
|
1185
|
-
};
|
|
1186
|
-
preloadSlots.set(token, slot1);
|
|
1187
|
-
hls.on(import_hls.default.Events.MANIFEST_PARSED, function() {
|
|
1188
|
-
var s = preloadSlots.get(token);
|
|
1189
|
-
if (s) s.ready = true;
|
|
1190
|
-
if (debug) console.log("".concat(LOG, " [preload] HLS manifest parsed, token=").concat(token));
|
|
1191
|
-
});
|
|
1192
|
-
hls.on(import_hls.default.Events.ERROR, function(_evt, data) {
|
|
1193
|
-
if (!preloadSlots.has(token)) return;
|
|
1194
|
-
if (data.fatal) {
|
|
1195
|
-
if (debug) console.warn("".concat(LOG, " [preload] HLS error for token=").concat(token));
|
|
1196
|
-
preloadSlots.delete(token);
|
|
1197
|
-
hls.destroy();
|
|
1198
|
-
videoEl.remove();
|
|
1199
|
-
}
|
|
1200
|
-
});
|
|
1201
|
-
} else {
|
|
1202
|
-
videoEl.src = mediaFile.url;
|
|
1203
|
-
videoEl.load();
|
|
1204
|
-
slot2 = {
|
|
1205
|
-
bids: bids,
|
|
1206
|
-
ad: ad,
|
|
1207
|
-
mediaFile: mediaFile,
|
|
1208
|
-
videoEl: videoEl,
|
|
1209
|
-
ready: false
|
|
1210
|
-
};
|
|
1211
|
-
preloadSlots.set(token, slot2);
|
|
1212
|
-
videoEl.addEventListener("canplay", function() {
|
|
1213
|
-
var s = preloadSlots.get(token);
|
|
1214
|
-
if (s) s.ready = true;
|
|
1215
|
-
if (debug) console.log("".concat(LOG, " [preload] canplay fired, token=").concat(token));
|
|
1216
|
-
}, {
|
|
1217
|
-
once: true
|
|
1218
|
-
});
|
|
1219
|
-
}
|
|
1220
|
-
if (debug) console.log("".concat(LOG, " [preload] Started buffering token=").concat(token, ", url=").concat(mediaFile.url));
|
|
1221
|
-
return [
|
|
1222
|
-
2
|
|
1223
|
-
];
|
|
1224
|
-
}
|
|
1225
|
-
});
|
|
1226
|
-
})();
|
|
1227
|
-
}
|
|
1228
|
-
function playPreloaded(token) {
|
|
1229
|
-
return _async_to_generator(function() {
|
|
1230
|
-
var slot, contentVolume, adVolume2, videoEl, container2, adVolume21, nonFatalNetworkErrors, adVolume, container;
|
|
1231
|
-
return _ts_generator(this, function(_state) {
|
|
1232
|
-
switch(_state.label){
|
|
1233
|
-
case 0:
|
|
1234
|
-
if (destroyed) return [
|
|
1235
|
-
2,
|
|
1236
|
-
Promise.reject(new Error("Layer has been destroyed"))
|
|
1237
|
-
];
|
|
1238
|
-
slot = preloadSlots.get(token);
|
|
1239
|
-
if (!slot) {
|
|
1240
|
-
if (debug) console.warn("".concat(LOG, " [preload] No slot found for token=").concat(token, ", nothing to play"));
|
|
1241
|
-
return [
|
|
1242
|
-
2
|
|
1243
|
-
];
|
|
1244
|
-
}
|
|
1245
|
-
preloadSlots.delete(token);
|
|
1246
|
-
if (debug) console.log("".concat(LOG, " [preload] Playing preloaded ad, token=").concat(token, ", ready=").concat(slot.ready));
|
|
1247
|
-
contentVolume = contentVideo.volume;
|
|
1248
|
-
originalVolume = Math.max(0, Math.min(1, contentVolume || originalVolume));
|
|
1249
|
-
sessionId = generateSessionId();
|
|
1250
|
-
currentAd = slot.ad;
|
|
1251
|
-
trackingFired = _object_spread({}, createEmptyTrackingState());
|
|
1252
|
-
fireTrackingPixels2(slot.ad.trackingUrls.impression);
|
|
1253
|
-
trackingFired.impression = true;
|
|
1254
|
-
if (!singleElementMode) return [
|
|
1255
|
-
3,
|
|
1256
|
-
2
|
|
1257
|
-
];
|
|
1258
|
-
mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
|
|
1259
|
-
teardownCurrentPlayback();
|
|
1260
|
-
adVideoElement = contentVideo;
|
|
1261
|
-
adHls = void 0;
|
|
1262
|
-
adPlaying = true;
|
|
1263
|
-
setAdPlayingFlag(true);
|
|
1264
|
-
contentVideo.removeAttribute("src");
|
|
1265
|
-
contentVideo.load();
|
|
1266
|
-
contentVideo.muted = true;
|
|
1267
|
-
contentVideo.volume = 0;
|
|
1268
|
-
return [
|
|
1269
|
-
4,
|
|
1270
|
-
new Promise(function(resolve) {
|
|
1271
|
-
return setTimeout(resolve, 200);
|
|
1272
|
-
})
|
|
1273
|
-
];
|
|
1274
|
-
case 1:
|
|
1275
|
-
_state.sent();
|
|
1276
|
-
if (destroyed || tornDown) return [
|
|
1277
|
-
2
|
|
1278
|
-
];
|
|
1279
|
-
contentVideo.style.visibility = "visible";
|
|
1280
|
-
contentVideo.style.opacity = "1";
|
|
1281
|
-
emit("content_pause");
|
|
1282
|
-
setupAdEventListeners();
|
|
1283
|
-
adVolume2 = originalMutedState ? 1 : originalVolume;
|
|
1284
|
-
contentVideo.volume = Math.max(0, Math.min(1, adVolume2));
|
|
1285
|
-
contentVideo.muted = false;
|
|
1286
|
-
if (debug) console.log("".concat(LOG, " [preload] singleElementMode: attaching ad to contentVideo, url=").concat(slot.mediaFile.url));
|
|
1287
|
-
startPlayback(slot.mediaFile);
|
|
1288
|
-
return [
|
|
1289
|
-
2
|
|
1290
|
-
];
|
|
1291
|
-
case 2:
|
|
1292
|
-
if (smartTVMode && !slot.videoEl) {
|
|
1293
|
-
teardownCurrentPlayback();
|
|
1294
|
-
if (adVideoElement) {
|
|
1295
|
-
adVideoElement.remove();
|
|
1296
|
-
adVideoElement = void 0;
|
|
1297
|
-
}
|
|
1298
|
-
videoEl = createAdVideoElement();
|
|
1299
|
-
videoEl.style.visibility = "visible";
|
|
1300
|
-
videoEl.style.pointerEvents = "none";
|
|
1301
|
-
container2 = ensureAdContainer();
|
|
1302
|
-
container2.appendChild(videoEl);
|
|
1303
|
-
adVideoElement = videoEl;
|
|
1304
|
-
setupAdEventListeners();
|
|
1305
|
-
if (!continueLiveStreamDuringAds) {
|
|
1306
|
-
contentVideo.pause();
|
|
1307
|
-
}
|
|
1308
|
-
contentVideo.muted = true;
|
|
1309
|
-
contentVideo.volume = 0;
|
|
1310
|
-
adPlaying = true;
|
|
1311
|
-
setAdPlayingFlag(true);
|
|
1312
|
-
adVolume21 = originalMutedState ? 1 : originalVolume;
|
|
1313
|
-
adVideoElement.volume = Math.max(0, Math.min(1, adVolume21));
|
|
1314
|
-
adVideoElement.muted = false;
|
|
1315
|
-
container2.style.display = "flex";
|
|
1316
|
-
container2.style.pointerEvents = "auto";
|
|
1317
|
-
emit("content_pause");
|
|
1318
|
-
if (debug) console.log("".concat(LOG, " [preload] smartTVMode deferred: creating video element and loading, url=").concat(slot.mediaFile.url));
|
|
1319
|
-
startPlayback(slot.mediaFile);
|
|
1320
|
-
return [
|
|
1321
|
-
2
|
|
1322
|
-
];
|
|
1323
|
-
}
|
|
1324
|
-
teardownCurrentPlayback();
|
|
1325
|
-
if (adVideoElement && adVideoElement !== slot.videoEl) {
|
|
1326
|
-
adVideoElement.remove();
|
|
1327
|
-
}
|
|
1328
|
-
slot.videoEl.style.visibility = "visible";
|
|
1329
|
-
slot.videoEl.style.pointerEvents = "none";
|
|
1330
|
-
adVideoElement = slot.videoEl;
|
|
1331
|
-
adHls = slot.hlsInstance;
|
|
1332
|
-
if (adHls) {
|
|
1333
|
-
nonFatalNetworkErrors = 0;
|
|
1334
|
-
adHls.on(import_hls.default.Events.ERROR, function(_event, data) {
|
|
1335
|
-
if (!adPlaying) return;
|
|
1336
|
-
if (data.fatal) {
|
|
1337
|
-
handleAdError();
|
|
1338
|
-
} else if (data.type === import_hls.default.ErrorTypes.NETWORK_ERROR) {
|
|
1339
|
-
nonFatalNetworkErrors++;
|
|
1340
|
-
if (nonFatalNetworkErrors >= 3) {
|
|
1341
|
-
if (debug) console.warn("".concat(LOG, " [preload] Too many non-fatal HLS network errors during playback, treating as fatal"));
|
|
1342
|
-
handleAdError();
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
});
|
|
1346
|
-
}
|
|
1347
|
-
setupAdEventListeners();
|
|
1348
|
-
if (!continueLiveStreamDuringAds) {
|
|
1349
|
-
contentVideo.pause();
|
|
1350
|
-
}
|
|
1351
|
-
contentVideo.muted = true;
|
|
1352
|
-
contentVideo.volume = 0;
|
|
1353
|
-
adPlaying = true;
|
|
1354
|
-
setAdPlayingFlag(true);
|
|
1355
|
-
adVolume = originalMutedState ? 1 : originalVolume;
|
|
1356
|
-
adVideoElement.volume = Math.max(0, Math.min(1, adVolume));
|
|
1357
|
-
adVideoElement.muted = false;
|
|
1358
|
-
container = ensureAdContainer();
|
|
1359
|
-
container.style.display = "flex";
|
|
1360
|
-
container.style.pointerEvents = "auto";
|
|
1361
|
-
emit("content_pause");
|
|
1362
|
-
adVideoElement.play().catch(function(error) {
|
|
1363
|
-
console.error("".concat(LOG, " [preload] Error playing preloaded ad:"), error);
|
|
1364
|
-
handleAdError();
|
|
1365
|
-
});
|
|
1366
|
-
return [
|
|
1367
|
-
2
|
|
1368
|
-
];
|
|
1369
|
-
}
|
|
1370
|
-
});
|
|
1371
|
-
})();
|
|
1372
|
-
}
|
|
1373
|
-
function cancelPreload(token) {
|
|
1374
|
-
var slot = preloadSlots.get(token);
|
|
1375
|
-
if (!slot) return;
|
|
1376
|
-
preloadSlots.delete(token);
|
|
1377
|
-
if (slot.hlsInstance) {
|
|
1378
|
-
slot.hlsInstance.destroy();
|
|
1379
|
-
}
|
|
1380
|
-
if (slot.videoEl) {
|
|
1381
|
-
slot.videoEl.pause();
|
|
1382
|
-
slot.videoEl.removeAttribute("src");
|
|
1383
|
-
slot.videoEl.load();
|
|
1384
|
-
slot.videoEl.remove();
|
|
1385
|
-
}
|
|
1386
|
-
if (debug) console.log("".concat(LOG, " [preload] Cancelled and cleaned up token=").concat(token));
|
|
1387
|
-
}
|
|
1388
|
-
return {
|
|
1389
|
-
initialize: function initialize() {
|
|
1390
|
-
if (debug) console.log("".concat(LOG, " Initializing"));
|
|
1391
|
-
},
|
|
1392
|
-
updateOptions: function updateOptions(opts) {
|
|
1393
|
-
if (opts.continueLiveStreamDuringAds !== void 0) {
|
|
1394
|
-
continueLiveStreamDuringAds = opts.continueLiveStreamDuringAds;
|
|
1395
|
-
}
|
|
1396
|
-
if (opts.mainHlsInstance !== void 0) {
|
|
1397
|
-
var _opts_mainHlsInstance;
|
|
1398
|
-
mainHlsInstance = (_opts_mainHlsInstance = opts.mainHlsInstance) !== null && _opts_mainHlsInstance !== void 0 ? _opts_mainHlsInstance : void 0;
|
|
1399
|
-
}
|
|
1400
|
-
},
|
|
1401
|
-
playAd: playAd,
|
|
1402
|
-
preloadAd: preloadAd,
|
|
1403
|
-
playPreloaded: playPreloaded,
|
|
1404
|
-
hasPreloaded: function hasPreloaded(token) {
|
|
1405
|
-
return preloadSlots.has(token);
|
|
1406
|
-
},
|
|
1407
|
-
cancelPreload: cancelPreload,
|
|
1408
|
-
pause: function pause() {
|
|
1409
|
-
if (!adPlaying || !adVideoElement) return;
|
|
1410
|
-
try {
|
|
1411
|
-
if (!adVideoElement.paused) adVideoElement.pause();
|
|
1412
|
-
} catch (error) {
|
|
1413
|
-
if (debug) console.warn("".concat(LOG, " Error pausing ad:"), error);
|
|
1414
|
-
}
|
|
1415
|
-
},
|
|
1416
|
-
resume: function resume() {
|
|
1417
|
-
if (!adPlaying || !adVideoElement) return;
|
|
1418
|
-
try {
|
|
1419
|
-
if (adVideoElement.paused) adVideoElement.play().catch(function() {});
|
|
1420
|
-
} catch (error) {
|
|
1421
|
-
if (debug) console.warn("".concat(LOG, " Error resuming ad:"), error);
|
|
1422
|
-
}
|
|
1423
|
-
},
|
|
1424
|
-
stop: function stop() {
|
|
1425
|
-
return _async_to_generator(function() {
|
|
1426
|
-
return _ts_generator(this, function(_state) {
|
|
1427
|
-
tornDown = true;
|
|
1428
|
-
if (debug) console.log("".concat(LOG, " Stopping ad"));
|
|
1429
|
-
adPlaying = false;
|
|
1430
|
-
setAdPlayingFlag(false);
|
|
1431
|
-
contentVideo.muted = originalMutedState;
|
|
1432
|
-
contentVideo.volume = originalMutedState ? 0 : originalVolume;
|
|
1433
|
-
contentVideo.style.visibility = "visible";
|
|
1434
|
-
contentVideo.style.opacity = "1";
|
|
1435
|
-
if (singleElementMode) {
|
|
1436
|
-
teardownCurrentPlayback();
|
|
1437
|
-
contentVideo.removeAttribute("src");
|
|
1438
|
-
contentVideo.load();
|
|
1439
|
-
adVideoElement = void 0;
|
|
1440
|
-
} else {
|
|
1441
|
-
if (adContainerEl) {
|
|
1442
|
-
adContainerEl.style.display = "none";
|
|
1443
|
-
adContainerEl.style.pointerEvents = "none";
|
|
1444
|
-
}
|
|
1445
|
-
if (continueLiveStreamDuringAds) {
|
|
1446
|
-
contentVideo.play().catch(function() {});
|
|
1447
|
-
}
|
|
1448
|
-
teardownCurrentPlayback();
|
|
1449
|
-
if (adVideoElement) {
|
|
1450
|
-
adVideoElement.pause();
|
|
1451
|
-
adVideoElement.removeAttribute("src");
|
|
1452
|
-
adVideoElement.load();
|
|
1453
|
-
}
|
|
1454
|
-
}
|
|
1455
|
-
currentAd = void 0;
|
|
1456
|
-
tornDown = false;
|
|
1457
|
-
return [
|
|
1458
|
-
2
|
|
1459
|
-
];
|
|
1460
|
-
});
|
|
1461
|
-
})();
|
|
1462
|
-
},
|
|
1463
|
-
destroy: function destroy() {
|
|
1464
|
-
tornDown = true;
|
|
1465
|
-
if (debug) console.log("".concat(LOG, " Destroying"));
|
|
1466
|
-
destroyed = true;
|
|
1467
|
-
adPlaying = false;
|
|
1468
|
-
setAdPlayingFlag(false);
|
|
1469
|
-
contentVideo.muted = originalMutedState;
|
|
1470
|
-
contentVideo.volume = originalVolume;
|
|
1471
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1472
|
-
try {
|
|
1473
|
-
for(var _iterator = Array.from(preloadSlots.entries())[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1474
|
-
var _step_value = _sliced_to_array(_step.value, 1), token = _step_value[0];
|
|
1475
|
-
cancelPreload(token);
|
|
1476
|
-
}
|
|
1477
|
-
} catch (err) {
|
|
1478
|
-
_didIteratorError = true;
|
|
1479
|
-
_iteratorError = err;
|
|
1480
|
-
} finally{
|
|
1481
|
-
try {
|
|
1482
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1483
|
-
_iterator.return();
|
|
1484
|
-
}
|
|
1485
|
-
} finally{
|
|
1486
|
-
if (_didIteratorError) {
|
|
1487
|
-
throw _iteratorError;
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
teardownCurrentPlayback();
|
|
1492
|
-
if (adVideoElement) {
|
|
1493
|
-
if (singleElementMode && adVideoElement === contentVideo) {
|
|
1494
|
-
contentVideo.removeAttribute("src");
|
|
1495
|
-
contentVideo.load();
|
|
1496
|
-
} else {
|
|
1497
|
-
adVideoElement.pause();
|
|
1498
|
-
adVideoElement.removeAttribute("src");
|
|
1499
|
-
adVideoElement.remove();
|
|
1500
|
-
}
|
|
1501
|
-
adVideoElement = void 0;
|
|
1502
|
-
}
|
|
1503
|
-
if (adContainerEl === null || adContainerEl === void 0 ? void 0 : adContainerEl.parentElement) {
|
|
1504
|
-
adContainerEl.parentElement.removeChild(adContainerEl);
|
|
1505
|
-
}
|
|
1506
|
-
adContainerEl = void 0;
|
|
1507
|
-
currentAd = void 0;
|
|
1508
|
-
listeners.clear();
|
|
1509
|
-
},
|
|
1510
|
-
isAdPlaying: function isAdPlaying() {
|
|
1511
|
-
return adPlaying;
|
|
1512
|
-
},
|
|
1513
|
-
resize: function resize(width, height) {
|
|
1514
|
-
if (adContainerEl) {
|
|
1515
|
-
adContainerEl.style.width = "".concat(width, "px");
|
|
1516
|
-
adContainerEl.style.height = "".concat(height, "px");
|
|
1517
|
-
}
|
|
1518
|
-
if (adVideoElement) {
|
|
1519
|
-
adVideoElement.style.width = "".concat(width, "px");
|
|
1520
|
-
adVideoElement.style.height = "".concat(height, "px");
|
|
1521
|
-
}
|
|
1522
|
-
},
|
|
1523
|
-
on: function on(event, listener) {
|
|
1524
|
-
if (!listeners.has(event)) listeners.set(event, /* @__PURE__ */ new Set());
|
|
1525
|
-
listeners.get(event).add(listener);
|
|
1526
|
-
},
|
|
1527
|
-
off: function off(event, listener) {
|
|
1528
|
-
var _listeners_get;
|
|
1529
|
-
(_listeners_get = listeners.get(event)) === null || _listeners_get === void 0 ? void 0 : _listeners_get.delete(listener);
|
|
1530
|
-
},
|
|
1531
|
-
updateOriginalMutedState: function updateOriginalMutedState(muted, volume) {
|
|
1532
|
-
var nextVolume = typeof volume === "number" && !Number.isNaN(volume) ? Math.max(0, Math.min(1, volume)) : originalVolume;
|
|
1533
|
-
originalMutedState = muted;
|
|
1534
|
-
originalVolume = nextVolume;
|
|
1535
|
-
},
|
|
1536
|
-
getOriginalMutedState: function getOriginalMutedState() {
|
|
1537
|
-
return originalMutedState;
|
|
1538
|
-
},
|
|
1539
|
-
getOriginalVolume: function getOriginalVolume() {
|
|
1540
|
-
return originalVolume;
|
|
1541
|
-
},
|
|
1542
|
-
setAdVolume: function setAdVolume(volume) {
|
|
1543
|
-
if (adVideoElement && adPlaying) {
|
|
1544
|
-
adVideoElement.volume = Math.max(0, Math.min(1, volume));
|
|
1545
|
-
}
|
|
1546
|
-
},
|
|
1547
|
-
getAdVolume: function getAdVolume() {
|
|
1548
|
-
if (adVideoElement && adPlaying) {
|
|
1549
|
-
return adVideoElement.volume;
|
|
1550
|
-
}
|
|
1551
|
-
return 1;
|
|
1552
|
-
},
|
|
1553
|
-
showPlaceholder: function showPlaceholder() {
|
|
1554
|
-
if (singleElementMode) return;
|
|
1555
|
-
contentVideo.style.opacity = "0";
|
|
1556
|
-
contentVideo.style.visibility = "hidden";
|
|
1557
|
-
if (!adContainerEl) {
|
|
1558
|
-
var _contentVideo_parentElement;
|
|
1559
|
-
var container = document.createElement("div");
|
|
1560
|
-
container.style.position = "absolute";
|
|
1561
|
-
container.style.left = "0";
|
|
1562
|
-
container.style.top = "0";
|
|
1563
|
-
container.style.right = "0";
|
|
1564
|
-
container.style.bottom = "0";
|
|
1565
|
-
container.style.display = "none";
|
|
1566
|
-
container.style.alignItems = "center";
|
|
1567
|
-
container.style.justifyContent = "center";
|
|
1568
|
-
container.style.pointerEvents = "none";
|
|
1569
|
-
container.style.zIndex = "10";
|
|
1570
|
-
container.style.backgroundColor = "#000";
|
|
1571
|
-
(_contentVideo_parentElement = contentVideo.parentElement) === null || _contentVideo_parentElement === void 0 ? void 0 : _contentVideo_parentElement.appendChild(container);
|
|
1572
|
-
adContainerEl = container;
|
|
1573
|
-
}
|
|
1574
|
-
if (adContainerEl) {
|
|
1575
|
-
adContainerEl.style.display = "flex";
|
|
1576
|
-
adContainerEl.style.pointerEvents = "auto";
|
|
1577
|
-
}
|
|
1578
|
-
},
|
|
1579
|
-
hidePlaceholder: function hidePlaceholder() {
|
|
1580
|
-
if (adContainerEl) {
|
|
1581
|
-
adContainerEl.style.display = "none";
|
|
1582
|
-
adContainerEl.style.pointerEvents = "none";
|
|
1583
|
-
}
|
|
1584
|
-
if (!adPlaying) {
|
|
1585
|
-
contentVideo.style.visibility = "visible";
|
|
1586
|
-
contentVideo.style.opacity = "1";
|
|
1587
|
-
}
|
|
1588
|
-
}
|
|
1589
|
-
};
|
|
1590
|
-
}
|
|
1591
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1592
|
-
0 && (module.exports = {
|
|
1593
|
-
createVastAdLayer: createVastAdLayer
|
|
1594
|
-
});
|
|
1595
|
-
//# sourceMappingURL=vastAdLayer.cjs.map
|