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