stormcloud-video-player 0.5.6 → 0.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -40
- package/dist/stormcloud-vp.min.js +1 -1
- package/lib/index.cjs +1537 -4636
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +7 -67
- package/lib/index.d.ts +7 -67
- package/lib/index.js +1540 -4623
- package/lib/index.js.map +1 -1
- package/lib/player/StormcloudVideoPlayer.cjs +811 -3880
- package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/player/StormcloudVideoPlayer.d.cts +3 -37
- package/lib/players/HlsPlayer.cjs +811 -3880
- package/lib/players/HlsPlayer.cjs.map +1 -1
- package/lib/players/HlsPlayer.d.cts +1 -1
- package/lib/players/index.cjs +811 -3880
- package/lib/players/index.cjs.map +1 -1
- package/lib/sdk/prebid.cjs +114 -43
- package/lib/sdk/prebid.cjs.map +1 -1
- package/lib/sdk/prebid.d.cts +1 -1
- package/lib/sdk/prebidController.cjs +123 -71
- package/lib/sdk/prebidController.cjs.map +1 -1
- package/lib/sdk/prebidController.d.cts +2 -2
- package/lib/{types-Bwp6-yys.d.cts → types-BOJiWNWa.d.cts} +4 -7
- package/lib/ui/StormcloudVideoPlayer.cjs +811 -3890
- package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/ui/StormcloudVideoPlayer.d.cts +1 -1
- package/lib/utils/browserCompat.cjs +0 -3
- package/lib/utils/browserCompat.cjs.map +1 -1
- package/lib/utils/browserCompat.d.cts +0 -1
- package/lib/utils/tracking.d.cts +1 -1
- package/package.json +1 -1
- package/lib/sdk/hlsAdPlayer.cjs +0 -1053
- package/lib/sdk/hlsAdPlayer.cjs.map +0 -1
- package/lib/sdk/hlsAdPlayer.d.cts +0 -10
- package/lib/sdk/ima.cjs +0 -1384
- package/lib/sdk/ima.cjs.map +0 -1
- package/lib/sdk/ima.d.cts +0 -12
package/lib/sdk/hlsAdPlayer.cjs
DELETED
|
@@ -1,1053 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
3
|
-
try {
|
|
4
|
-
var info = gen[key](arg);
|
|
5
|
-
var value = info.value;
|
|
6
|
-
} catch (error) {
|
|
7
|
-
reject(error);
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
if (info.done) {
|
|
11
|
-
resolve(value);
|
|
12
|
-
} else {
|
|
13
|
-
Promise.resolve(value).then(_next, _throw);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function _async_to_generator(fn) {
|
|
17
|
-
return function() {
|
|
18
|
-
var self = this, args = arguments;
|
|
19
|
-
return new Promise(function(resolve, reject) {
|
|
20
|
-
var gen = fn.apply(self, args);
|
|
21
|
-
function _next(value) {
|
|
22
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
23
|
-
}
|
|
24
|
-
function _throw(err) {
|
|
25
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
26
|
-
}
|
|
27
|
-
_next(undefined);
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function _type_of(obj) {
|
|
32
|
-
"@swc/helpers - typeof";
|
|
33
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
34
|
-
}
|
|
35
|
-
function _ts_generator(thisArg, body) {
|
|
36
|
-
var f, y, t, _ = {
|
|
37
|
-
label: 0,
|
|
38
|
-
sent: function() {
|
|
39
|
-
if (t[0] & 1) throw t[1];
|
|
40
|
-
return t[1];
|
|
41
|
-
},
|
|
42
|
-
trys: [],
|
|
43
|
-
ops: []
|
|
44
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
45
|
-
return d(g, "next", {
|
|
46
|
-
value: verb(0)
|
|
47
|
-
}), d(g, "throw", {
|
|
48
|
-
value: verb(1)
|
|
49
|
-
}), d(g, "return", {
|
|
50
|
-
value: verb(2)
|
|
51
|
-
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
52
|
-
value: function() {
|
|
53
|
-
return this;
|
|
54
|
-
}
|
|
55
|
-
}), g;
|
|
56
|
-
function verb(n) {
|
|
57
|
-
return function(v) {
|
|
58
|
-
return step([
|
|
59
|
-
n,
|
|
60
|
-
v
|
|
61
|
-
]);
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function step(op) {
|
|
65
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
66
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
67
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
68
|
-
if (y = 0, t) op = [
|
|
69
|
-
op[0] & 2,
|
|
70
|
-
t.value
|
|
71
|
-
];
|
|
72
|
-
switch(op[0]){
|
|
73
|
-
case 0:
|
|
74
|
-
case 1:
|
|
75
|
-
t = op;
|
|
76
|
-
break;
|
|
77
|
-
case 4:
|
|
78
|
-
_.label++;
|
|
79
|
-
return {
|
|
80
|
-
value: op[1],
|
|
81
|
-
done: false
|
|
82
|
-
};
|
|
83
|
-
case 5:
|
|
84
|
-
_.label++;
|
|
85
|
-
y = op[1];
|
|
86
|
-
op = [
|
|
87
|
-
0
|
|
88
|
-
];
|
|
89
|
-
continue;
|
|
90
|
-
case 7:
|
|
91
|
-
op = _.ops.pop();
|
|
92
|
-
_.trys.pop();
|
|
93
|
-
continue;
|
|
94
|
-
default:
|
|
95
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
96
|
-
_ = 0;
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
100
|
-
_.label = op[1];
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
104
|
-
_.label = t[1];
|
|
105
|
-
t = op;
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
if (t && _.label < t[2]) {
|
|
109
|
-
_.label = t[2];
|
|
110
|
-
_.ops.push(op);
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
if (t[2]) _.ops.pop();
|
|
114
|
-
_.trys.pop();
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
op = body.call(thisArg, _);
|
|
118
|
-
} catch (e) {
|
|
119
|
-
op = [
|
|
120
|
-
6,
|
|
121
|
-
e
|
|
122
|
-
];
|
|
123
|
-
y = 0;
|
|
124
|
-
} finally{
|
|
125
|
-
f = t = 0;
|
|
126
|
-
}
|
|
127
|
-
if (op[0] & 5) throw op[1];
|
|
128
|
-
return {
|
|
129
|
-
value: op[0] ? op[1] : void 0,
|
|
130
|
-
done: true
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
var __create = Object.create;
|
|
135
|
-
var __defProp = Object.defineProperty;
|
|
136
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
137
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
138
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
139
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
140
|
-
var __export = function __export(target, all) {
|
|
141
|
-
for(var name in all)__defProp(target, name, {
|
|
142
|
-
get: all[name],
|
|
143
|
-
enumerable: true
|
|
144
|
-
});
|
|
145
|
-
};
|
|
146
|
-
var __copyProps = function __copyProps(to, from, except, desc) {
|
|
147
|
-
if (from && (typeof from === "undefined" ? "undefined" : _type_of(from)) === "object" || typeof from === "function") {
|
|
148
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
149
|
-
try {
|
|
150
|
-
var _loop = function() {
|
|
151
|
-
var key = _step.value;
|
|
152
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
153
|
-
get: function get() {
|
|
154
|
-
return from[key];
|
|
155
|
-
},
|
|
156
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
157
|
-
});
|
|
158
|
-
};
|
|
159
|
-
for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
160
|
-
} catch (err) {
|
|
161
|
-
_didIteratorError = true;
|
|
162
|
-
_iteratorError = err;
|
|
163
|
-
} finally{
|
|
164
|
-
try {
|
|
165
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
166
|
-
_iterator.return();
|
|
167
|
-
}
|
|
168
|
-
} finally{
|
|
169
|
-
if (_didIteratorError) {
|
|
170
|
-
throw _iteratorError;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return to;
|
|
176
|
-
};
|
|
177
|
-
var __toESM = function __toESM(mod, isNodeMode, target) {
|
|
178
|
-
return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
|
|
179
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
180
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
181
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
182
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
183
|
-
value: mod,
|
|
184
|
-
enumerable: true
|
|
185
|
-
}) : target, mod);
|
|
186
|
-
};
|
|
187
|
-
var __toCommonJS = function __toCommonJS(mod) {
|
|
188
|
-
return __copyProps(__defProp({}, "__esModule", {
|
|
189
|
-
value: true
|
|
190
|
-
}), mod);
|
|
191
|
-
};
|
|
192
|
-
// src/sdk/hlsAdPlayer.ts
|
|
193
|
-
var hlsAdPlayer_exports = {};
|
|
194
|
-
__export(hlsAdPlayer_exports, {
|
|
195
|
-
createHlsAdPlayer: function createHlsAdPlayer1() {
|
|
196
|
-
return createHlsAdPlayer;
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
module.exports = __toCommonJS(hlsAdPlayer_exports);
|
|
200
|
-
// src/sdk/vastParser.ts
|
|
201
|
-
function isHlsType(type) {
|
|
202
|
-
return type === "application/x-mpegURL" || type.includes("m3u8");
|
|
203
|
-
}
|
|
204
|
-
function isMp4Type(type) {
|
|
205
|
-
return type === "video/mp4" || type.includes("mp4");
|
|
206
|
-
}
|
|
207
|
-
function parseVastXml(xmlString) {
|
|
208
|
-
var filter = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "all", logPrefix = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "[VastParser]";
|
|
209
|
-
try {
|
|
210
|
-
var _xmlDoc_querySelector, _xmlDoc_querySelector1, _xmlDoc_querySelector_textContent, _xmlDoc_querySelector2;
|
|
211
|
-
var parser = new DOMParser();
|
|
212
|
-
var xmlDoc = parser.parseFromString(xmlString, "text/xml");
|
|
213
|
-
var parserError = xmlDoc.querySelector("parsererror");
|
|
214
|
-
if (parserError) {
|
|
215
|
-
console.error("".concat(logPrefix, " XML parsing error (malformed VAST XML):"), parserError.textContent);
|
|
216
|
-
return null;
|
|
217
|
-
}
|
|
218
|
-
var adElement = xmlDoc.querySelector("Ad");
|
|
219
|
-
if (!adElement) {
|
|
220
|
-
console.warn("".concat(logPrefix, " No Ad element found in VAST XML"));
|
|
221
|
-
return null;
|
|
222
|
-
}
|
|
223
|
-
var adId = adElement.getAttribute("id") || "unknown";
|
|
224
|
-
var title = ((_xmlDoc_querySelector = xmlDoc.querySelector("AdTitle")) === null || _xmlDoc_querySelector === void 0 ? void 0 : _xmlDoc_querySelector.textContent) || "Ad";
|
|
225
|
-
var isNoAdAvailable = adId === "empty" || title.toLowerCase().includes("no ad available") || title.toLowerCase() === "no ad available";
|
|
226
|
-
var durationText = ((_xmlDoc_querySelector1 = xmlDoc.querySelector("Duration")) === null || _xmlDoc_querySelector1 === void 0 ? void 0 : _xmlDoc_querySelector1.textContent) || "00:00:30";
|
|
227
|
-
var durationParts = durationText.split(":");
|
|
228
|
-
var duration = parseInt(durationParts[0] || "0", 10) * 3600 + parseInt(durationParts[1] || "0", 10) * 60 + Math.round(parseFloat(durationParts[2] || "0"));
|
|
229
|
-
var mediaFileElements = xmlDoc.querySelectorAll("MediaFile");
|
|
230
|
-
var mediaFiles = [];
|
|
231
|
-
console.log("".concat(logPrefix, " Found ").concat(mediaFileElements.length, " MediaFile element(s) in VAST XML"));
|
|
232
|
-
mediaFileElements.forEach(function(mf, index) {
|
|
233
|
-
var _mf_textContent;
|
|
234
|
-
var type = mf.getAttribute("type") || "";
|
|
235
|
-
var url = ((_mf_textContent = mf.textContent) === null || _mf_textContent === void 0 ? void 0 : _mf_textContent.trim()) || "";
|
|
236
|
-
var width = mf.getAttribute("width") || "";
|
|
237
|
-
var height = mf.getAttribute("height") || "";
|
|
238
|
-
console.log("".concat(logPrefix, " MediaFile ").concat(index, ': type="').concat(type, '", url="').concat(url.substring(0, 80), '...", width="').concat(width, '", height="').concat(height, '"'));
|
|
239
|
-
if (!url) {
|
|
240
|
-
console.warn("".concat(logPrefix, " MediaFile ").concat(index, " has empty URL"));
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
var isHls = isHlsType(type);
|
|
244
|
-
var isMp4 = isMp4Type(type);
|
|
245
|
-
var accepted = false;
|
|
246
|
-
if (filter === "hls-only") {
|
|
247
|
-
accepted = isHls;
|
|
248
|
-
} else if (filter === "mp4-first") {
|
|
249
|
-
accepted = isMp4 || isHls;
|
|
250
|
-
} else {
|
|
251
|
-
accepted = true;
|
|
252
|
-
}
|
|
253
|
-
if (!accepted) {
|
|
254
|
-
console.log("".concat(logPrefix, " MediaFile ").concat(index, ' ignored (type="').concat(type, '" not accepted by filter "').concat(filter, '")'));
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
var bitrateAttr = mf.getAttribute("bitrate");
|
|
258
|
-
var bitrateValue = bitrateAttr ? parseInt(bitrateAttr, 10) : void 0;
|
|
259
|
-
mediaFiles.push({
|
|
260
|
-
url: url,
|
|
261
|
-
type: type,
|
|
262
|
-
width: parseInt(width || "1920", 10),
|
|
263
|
-
height: parseInt(height || "1080", 10),
|
|
264
|
-
bitrate: bitrateValue && bitrateValue > 0 ? bitrateValue : void 0
|
|
265
|
-
});
|
|
266
|
-
console.log("".concat(logPrefix, ' Added MediaFile: type="').concat(type, '" url="').concat(url.substring(0, 80), '..."'));
|
|
267
|
-
});
|
|
268
|
-
if (filter === "mp4-first" && mediaFiles.length > 1) {
|
|
269
|
-
mediaFiles.sort(function(a, b) {
|
|
270
|
-
var aIsMp4 = isMp4Type(a.type) ? 0 : 1;
|
|
271
|
-
var bIsMp4 = isMp4Type(b.type) ? 0 : 1;
|
|
272
|
-
return aIsMp4 - bIsMp4;
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
if (mediaFiles.length === 0) {
|
|
276
|
-
if (isNoAdAvailable) {
|
|
277
|
-
console.warn("".concat(logPrefix, " No ads available (VAST response indicates no ads)"));
|
|
278
|
-
} else {
|
|
279
|
-
console.warn("".concat(logPrefix, " No compatible media files found in VAST XML"));
|
|
280
|
-
}
|
|
281
|
-
return null;
|
|
282
|
-
}
|
|
283
|
-
var trackingUrls = {
|
|
284
|
-
impression: [],
|
|
285
|
-
start: [],
|
|
286
|
-
firstQuartile: [],
|
|
287
|
-
midpoint: [],
|
|
288
|
-
thirdQuartile: [],
|
|
289
|
-
complete: [],
|
|
290
|
-
mute: [],
|
|
291
|
-
unmute: [],
|
|
292
|
-
pause: [],
|
|
293
|
-
resume: [],
|
|
294
|
-
fullscreen: [],
|
|
295
|
-
exitFullscreen: [],
|
|
296
|
-
skip: [],
|
|
297
|
-
error: []
|
|
298
|
-
};
|
|
299
|
-
xmlDoc.querySelectorAll("Impression").forEach(function(el) {
|
|
300
|
-
var _el_textContent;
|
|
301
|
-
var url = (_el_textContent = el.textContent) === null || _el_textContent === void 0 ? void 0 : _el_textContent.trim();
|
|
302
|
-
if (url) trackingUrls.impression.push(url);
|
|
303
|
-
});
|
|
304
|
-
xmlDoc.querySelectorAll("Tracking").forEach(function(el) {
|
|
305
|
-
var _el_textContent;
|
|
306
|
-
var event = el.getAttribute("event");
|
|
307
|
-
var url = (_el_textContent = el.textContent) === null || _el_textContent === void 0 ? void 0 : _el_textContent.trim();
|
|
308
|
-
if (event && url) {
|
|
309
|
-
var eventKey = event;
|
|
310
|
-
if (trackingUrls[eventKey]) {
|
|
311
|
-
trackingUrls[eventKey].push(url);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
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();
|
|
316
|
-
return {
|
|
317
|
-
id: adId,
|
|
318
|
-
title: title,
|
|
319
|
-
duration: duration,
|
|
320
|
-
mediaFiles: mediaFiles,
|
|
321
|
-
trackingUrls: trackingUrls,
|
|
322
|
-
clickThrough: clickThrough
|
|
323
|
-
};
|
|
324
|
-
} catch (error) {
|
|
325
|
-
console.error("".concat(logPrefix, " Error parsing VAST XML:"), error);
|
|
326
|
-
return null;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
function fetchAndParseVastAd(vastTagUrl) {
|
|
330
|
-
var filter = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "all", logPrefix = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "[VastParser]";
|
|
331
|
-
return _async_to_generator(function() {
|
|
332
|
-
var response, vastXml;
|
|
333
|
-
return _ts_generator(this, function(_state) {
|
|
334
|
-
switch(_state.label){
|
|
335
|
-
case 0:
|
|
336
|
-
return [
|
|
337
|
-
4,
|
|
338
|
-
fetch(vastTagUrl, {
|
|
339
|
-
mode: "cors",
|
|
340
|
-
credentials: "include",
|
|
341
|
-
headers: {
|
|
342
|
-
Accept: "application/xml, text/xml, */*"
|
|
343
|
-
},
|
|
344
|
-
referrerPolicy: "no-referrer-when-downgrade"
|
|
345
|
-
})
|
|
346
|
-
];
|
|
347
|
-
case 1:
|
|
348
|
-
response = _state.sent();
|
|
349
|
-
if (!response.ok) {
|
|
350
|
-
throw new Error("Failed to fetch VAST: ".concat(response.statusText));
|
|
351
|
-
}
|
|
352
|
-
return [
|
|
353
|
-
4,
|
|
354
|
-
response.text()
|
|
355
|
-
];
|
|
356
|
-
case 2:
|
|
357
|
-
vastXml = _state.sent();
|
|
358
|
-
console.log("".concat(logPrefix, " VAST XML received"));
|
|
359
|
-
console.log("".concat(logPrefix, " VAST XML content (first 2000 chars):"), vastXml.substring(0, 2e3));
|
|
360
|
-
return [
|
|
361
|
-
2,
|
|
362
|
-
parseVastXml(vastXml, filter, logPrefix)
|
|
363
|
-
];
|
|
364
|
-
}
|
|
365
|
-
});
|
|
366
|
-
})();
|
|
367
|
-
}
|
|
368
|
-
function fireTrackingPixels(urls, sessionId, licenseKey) {
|
|
369
|
-
var logPrefix = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "[VastParser]";
|
|
370
|
-
if (!urls || urls.length === 0) return;
|
|
371
|
-
urls.forEach(function(url) {
|
|
372
|
-
try {
|
|
373
|
-
var trackingUrl = url;
|
|
374
|
-
if (sessionId) {
|
|
375
|
-
trackingUrl = "".concat(trackingUrl).concat(trackingUrl.includes("?") ? "&" : "?", "session_id=").concat(sessionId);
|
|
376
|
-
}
|
|
377
|
-
if (licenseKey) {
|
|
378
|
-
trackingUrl = "".concat(trackingUrl).concat(trackingUrl.includes("?") ? "&" : "?", "license_key=").concat(licenseKey);
|
|
379
|
-
}
|
|
380
|
-
var img = new Image(1, 1);
|
|
381
|
-
img.src = trackingUrl;
|
|
382
|
-
console.log("".concat(logPrefix, " Fired tracking pixel: ").concat(trackingUrl));
|
|
383
|
-
} catch (error) {
|
|
384
|
-
console.warn("".concat(logPrefix, " Error firing tracking pixel:"), error);
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
// src/sdk/hlsAdPlayer.ts
|
|
389
|
-
var import_hls = __toESM(require("hls.js"), 1);
|
|
390
|
-
function createHlsAdPlayer(contentVideo, options) {
|
|
391
|
-
var adPlaying = false;
|
|
392
|
-
var originalMutedState = false;
|
|
393
|
-
var originalVolume = Math.max(0, Math.min(1, contentVideo.volume || 1));
|
|
394
|
-
var listeners = /* @__PURE__ */ new Map();
|
|
395
|
-
var licenseKey = options === null || options === void 0 ? void 0 : options.licenseKey;
|
|
396
|
-
var mainHlsInstance = options === null || options === void 0 ? void 0 : options.mainHlsInstance;
|
|
397
|
-
var adVideoElement;
|
|
398
|
-
var adHls;
|
|
399
|
-
var adContainerEl;
|
|
400
|
-
var currentAd;
|
|
401
|
-
var sessionId;
|
|
402
|
-
var preloadedAds = /* @__PURE__ */ new Map();
|
|
403
|
-
var preloadingAds = /* @__PURE__ */ new Map();
|
|
404
|
-
var destroyed = false;
|
|
405
|
-
var pendingTimeouts = [];
|
|
406
|
-
var trackingFired = {
|
|
407
|
-
impression: false,
|
|
408
|
-
start: false,
|
|
409
|
-
firstQuartile: false,
|
|
410
|
-
midpoint: false,
|
|
411
|
-
thirdQuartile: false,
|
|
412
|
-
complete: false
|
|
413
|
-
};
|
|
414
|
-
function emit(event, payload) {
|
|
415
|
-
var set = listeners.get(event);
|
|
416
|
-
if (!set) return;
|
|
417
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
418
|
-
try {
|
|
419
|
-
for(var _iterator = Array.from(set)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
420
|
-
var fn = _step.value;
|
|
421
|
-
try {
|
|
422
|
-
fn(payload);
|
|
423
|
-
} catch (error) {
|
|
424
|
-
console.warn("[HlsAdPlayer] Error in event listener for ".concat(event, ":"), error);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
} catch (err) {
|
|
428
|
-
_didIteratorError = true;
|
|
429
|
-
_iteratorError = err;
|
|
430
|
-
} finally{
|
|
431
|
-
try {
|
|
432
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
433
|
-
_iterator.return();
|
|
434
|
-
}
|
|
435
|
-
} finally{
|
|
436
|
-
if (_didIteratorError) {
|
|
437
|
-
throw _iteratorError;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
function generateSessionId() {
|
|
443
|
-
return "session-".concat(Date.now(), "-").concat(Math.random().toString(36).substr(2, 9));
|
|
444
|
-
}
|
|
445
|
-
function fireTrackingPixels2(urls) {
|
|
446
|
-
fireTrackingPixels(urls, sessionId, licenseKey, "[HlsAdPlayer]");
|
|
447
|
-
}
|
|
448
|
-
function getMainStreamQuality() {
|
|
449
|
-
if (!mainHlsInstance || !mainHlsInstance.levels) {
|
|
450
|
-
return null;
|
|
451
|
-
}
|
|
452
|
-
var currentLevel = mainHlsInstance.currentLevel;
|
|
453
|
-
if (currentLevel === -1 || !mainHlsInstance.levels[currentLevel]) {
|
|
454
|
-
var autoLevel = mainHlsInstance.loadLevel;
|
|
455
|
-
if (autoLevel !== -1 && mainHlsInstance.levels[autoLevel]) {
|
|
456
|
-
var level2 = mainHlsInstance.levels[autoLevel];
|
|
457
|
-
return {
|
|
458
|
-
width: level2.width || 1920,
|
|
459
|
-
height: level2.height || 1080,
|
|
460
|
-
bitrate: level2.bitrate || 5e6
|
|
461
|
-
};
|
|
462
|
-
}
|
|
463
|
-
return null;
|
|
464
|
-
}
|
|
465
|
-
var level = mainHlsInstance.levels[currentLevel];
|
|
466
|
-
return {
|
|
467
|
-
width: level.width || 1920,
|
|
468
|
-
height: level.height || 1080,
|
|
469
|
-
bitrate: level.bitrate || 5e6
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
|
-
function selectBestMediaFile(mediaFiles) {
|
|
473
|
-
if (mediaFiles.length === 0) {
|
|
474
|
-
throw new Error("No media files available");
|
|
475
|
-
}
|
|
476
|
-
var firstFile = mediaFiles[0];
|
|
477
|
-
if (!firstFile) {
|
|
478
|
-
throw new Error("No media files available");
|
|
479
|
-
}
|
|
480
|
-
if (mediaFiles.length === 1) {
|
|
481
|
-
return firstFile;
|
|
482
|
-
}
|
|
483
|
-
var mainQuality = getMainStreamQuality();
|
|
484
|
-
if (!mainQuality) {
|
|
485
|
-
console.log("[HlsAdPlayer] No main stream quality info, using first media file");
|
|
486
|
-
return firstFile;
|
|
487
|
-
}
|
|
488
|
-
console.log("[HlsAdPlayer] Main stream quality:", mainQuality);
|
|
489
|
-
var scoredFiles = mediaFiles.map(function(file) {
|
|
490
|
-
var widthDiff = Math.abs(file.width - mainQuality.width);
|
|
491
|
-
var heightDiff = Math.abs(file.height - mainQuality.height);
|
|
492
|
-
var resolutionDiff = widthDiff + heightDiff;
|
|
493
|
-
var fileBitrate = (file.bitrate || 5e3) * 1e3;
|
|
494
|
-
var bitrateDiff = Math.abs(fileBitrate - mainQuality.bitrate);
|
|
495
|
-
var score = resolutionDiff * 2 + bitrateDiff / 1e3;
|
|
496
|
-
return {
|
|
497
|
-
file: file,
|
|
498
|
-
score: score,
|
|
499
|
-
resolutionDiff: resolutionDiff,
|
|
500
|
-
bitrateDiff: bitrateDiff
|
|
501
|
-
};
|
|
502
|
-
});
|
|
503
|
-
scoredFiles.sort(function(a, b) {
|
|
504
|
-
return a.score - b.score;
|
|
505
|
-
});
|
|
506
|
-
var bestMatch = scoredFiles[0];
|
|
507
|
-
if (!bestMatch) {
|
|
508
|
-
console.log("[HlsAdPlayer] No best match found, using first media file");
|
|
509
|
-
return firstFile;
|
|
510
|
-
}
|
|
511
|
-
console.log("[HlsAdPlayer] Selected media file:", {
|
|
512
|
-
url: bestMatch.file.url,
|
|
513
|
-
resolution: "".concat(bestMatch.file.width, "x").concat(bestMatch.file.height),
|
|
514
|
-
bitrate: bestMatch.file.bitrate,
|
|
515
|
-
score: bestMatch.score,
|
|
516
|
-
resolutionDiff: bestMatch.resolutionDiff,
|
|
517
|
-
bitrateDiff: bestMatch.bitrateDiff
|
|
518
|
-
});
|
|
519
|
-
return bestMatch.file;
|
|
520
|
-
}
|
|
521
|
-
function fetchAndParseVastAdLocal(vastTagUrl) {
|
|
522
|
-
return _async_to_generator(function() {
|
|
523
|
-
return _ts_generator(this, function(_state) {
|
|
524
|
-
return [
|
|
525
|
-
2,
|
|
526
|
-
fetchAndParseVastAd(vastTagUrl, "hls-only", "[HlsAdPlayer]")
|
|
527
|
-
];
|
|
528
|
-
});
|
|
529
|
-
})();
|
|
530
|
-
}
|
|
531
|
-
function createAdVideoElement() {
|
|
532
|
-
var video = document.createElement("video");
|
|
533
|
-
video.style.position = "absolute";
|
|
534
|
-
video.style.left = "0";
|
|
535
|
-
video.style.top = "0";
|
|
536
|
-
video.style.width = "100%";
|
|
537
|
-
video.style.height = "100%";
|
|
538
|
-
video.style.objectFit = "contain";
|
|
539
|
-
video.style.backgroundColor = "#000";
|
|
540
|
-
video.playsInline = true;
|
|
541
|
-
video.muted = false;
|
|
542
|
-
video.volume = 1;
|
|
543
|
-
console.log("[HlsAdPlayer] Created ad video element with volume ".concat(video.volume));
|
|
544
|
-
return video;
|
|
545
|
-
}
|
|
546
|
-
function setupAdEventListeners() {
|
|
547
|
-
if (!adVideoElement || !currentAd) return;
|
|
548
|
-
adVideoElement.addEventListener("timeupdate", function() {
|
|
549
|
-
if (!currentAd || !adVideoElement) return;
|
|
550
|
-
var progress = adVideoElement.currentTime / currentAd.duration;
|
|
551
|
-
if (progress >= 0.25 && !trackingFired.firstQuartile) {
|
|
552
|
-
trackingFired.firstQuartile = true;
|
|
553
|
-
fireTrackingPixels2(currentAd.trackingUrls.firstQuartile);
|
|
554
|
-
}
|
|
555
|
-
if (progress >= 0.5 && !trackingFired.midpoint) {
|
|
556
|
-
trackingFired.midpoint = true;
|
|
557
|
-
fireTrackingPixels2(currentAd.trackingUrls.midpoint);
|
|
558
|
-
}
|
|
559
|
-
if (progress >= 0.75 && !trackingFired.thirdQuartile) {
|
|
560
|
-
trackingFired.thirdQuartile = true;
|
|
561
|
-
fireTrackingPixels2(currentAd.trackingUrls.thirdQuartile);
|
|
562
|
-
}
|
|
563
|
-
});
|
|
564
|
-
adVideoElement.addEventListener("playing", function() {
|
|
565
|
-
if (!currentAd || trackingFired.start) return;
|
|
566
|
-
trackingFired.start = true;
|
|
567
|
-
fireTrackingPixels2(currentAd.trackingUrls.start);
|
|
568
|
-
console.log("[HlsAdPlayer] Ad started playing");
|
|
569
|
-
});
|
|
570
|
-
adVideoElement.addEventListener("ended", function() {
|
|
571
|
-
if (!currentAd || trackingFired.complete) return;
|
|
572
|
-
trackingFired.complete = true;
|
|
573
|
-
fireTrackingPixels2(currentAd.trackingUrls.complete);
|
|
574
|
-
console.log("[HlsAdPlayer] Ad completed");
|
|
575
|
-
handleAdComplete();
|
|
576
|
-
});
|
|
577
|
-
adVideoElement.addEventListener("error", function(e) {
|
|
578
|
-
console.error("[HlsAdPlayer] Ad video error:", e);
|
|
579
|
-
if (currentAd) {
|
|
580
|
-
fireTrackingPixels2(currentAd.trackingUrls.error);
|
|
581
|
-
}
|
|
582
|
-
handleAdError();
|
|
583
|
-
});
|
|
584
|
-
adVideoElement.addEventListener("volumechange", function() {
|
|
585
|
-
if (!currentAd) return;
|
|
586
|
-
if (adVideoElement.muted) {
|
|
587
|
-
fireTrackingPixels2(currentAd.trackingUrls.mute);
|
|
588
|
-
} else {
|
|
589
|
-
fireTrackingPixels2(currentAd.trackingUrls.unmute);
|
|
590
|
-
}
|
|
591
|
-
});
|
|
592
|
-
adVideoElement.addEventListener("pause", function() {
|
|
593
|
-
if (currentAd && !adVideoElement.ended) {
|
|
594
|
-
fireTrackingPixels2(currentAd.trackingUrls.pause);
|
|
595
|
-
}
|
|
596
|
-
});
|
|
597
|
-
adVideoElement.addEventListener("play", function() {
|
|
598
|
-
if (currentAd && adVideoElement.currentTime > 0) {
|
|
599
|
-
fireTrackingPixels2(currentAd.trackingUrls.resume);
|
|
600
|
-
}
|
|
601
|
-
});
|
|
602
|
-
}
|
|
603
|
-
function setAdPlayingFlag(isPlaying) {
|
|
604
|
-
if (isPlaying) {
|
|
605
|
-
contentVideo.dataset.stormcloudAdPlaying = "true";
|
|
606
|
-
} else {
|
|
607
|
-
delete contentVideo.dataset.stormcloudAdPlaying;
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
function handleAdComplete() {
|
|
611
|
-
console.log("[HlsAdPlayer] Handling ad completion");
|
|
612
|
-
adPlaying = false;
|
|
613
|
-
setAdPlayingFlag(false);
|
|
614
|
-
contentVideo.muted = true;
|
|
615
|
-
contentVideo.volume = 0;
|
|
616
|
-
if (adContainerEl) {
|
|
617
|
-
adContainerEl.style.display = "none";
|
|
618
|
-
adContainerEl.style.pointerEvents = "none";
|
|
619
|
-
}
|
|
620
|
-
if (options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds) {
|
|
621
|
-
if (contentVideo.paused) {
|
|
622
|
-
console.log("[HlsAdPlayer] Content video paused in live mode, resuming playback");
|
|
623
|
-
} else {
|
|
624
|
-
console.log("[HlsAdPlayer] Content video already playing in live mode");
|
|
625
|
-
}
|
|
626
|
-
contentVideo.play().catch(function() {});
|
|
627
|
-
}
|
|
628
|
-
emit("ad_impression");
|
|
629
|
-
emit("content_resume");
|
|
630
|
-
}
|
|
631
|
-
function handleAdError() {
|
|
632
|
-
console.log("[HlsAdPlayer] Handling ad error");
|
|
633
|
-
adPlaying = false;
|
|
634
|
-
setAdPlayingFlag(false);
|
|
635
|
-
contentVideo.muted = true;
|
|
636
|
-
contentVideo.volume = 0;
|
|
637
|
-
if (adContainerEl) {
|
|
638
|
-
adContainerEl.style.display = "none";
|
|
639
|
-
adContainerEl.style.pointerEvents = "none";
|
|
640
|
-
}
|
|
641
|
-
emit("ad_error");
|
|
642
|
-
}
|
|
643
|
-
return {
|
|
644
|
-
initialize: function initialize() {
|
|
645
|
-
console.log("[HlsAdPlayer] Initializing");
|
|
646
|
-
if (!adContainerEl) {
|
|
647
|
-
var _contentVideo_parentElement;
|
|
648
|
-
var container = document.createElement("div");
|
|
649
|
-
container.style.position = "absolute";
|
|
650
|
-
container.style.left = "0";
|
|
651
|
-
container.style.top = "0";
|
|
652
|
-
container.style.right = "0";
|
|
653
|
-
container.style.bottom = "0";
|
|
654
|
-
container.style.display = "none";
|
|
655
|
-
container.style.alignItems = "center";
|
|
656
|
-
container.style.justifyContent = "center";
|
|
657
|
-
container.style.pointerEvents = "none";
|
|
658
|
-
container.style.zIndex = "10";
|
|
659
|
-
container.style.backgroundColor = "#000";
|
|
660
|
-
(_contentVideo_parentElement = contentVideo.parentElement) === null || _contentVideo_parentElement === void 0 ? void 0 : _contentVideo_parentElement.appendChild(container);
|
|
661
|
-
adContainerEl = container;
|
|
662
|
-
}
|
|
663
|
-
},
|
|
664
|
-
requestAds: function requestAds(vastTagUrl) {
|
|
665
|
-
return _async_to_generator(function() {
|
|
666
|
-
var ad, error;
|
|
667
|
-
return _ts_generator(this, function(_state) {
|
|
668
|
-
switch(_state.label){
|
|
669
|
-
case 0:
|
|
670
|
-
if (destroyed) {
|
|
671
|
-
return [
|
|
672
|
-
2,
|
|
673
|
-
Promise.reject(new Error("Controller has been destroyed"))
|
|
674
|
-
];
|
|
675
|
-
}
|
|
676
|
-
console.log("[HlsAdPlayer] Requesting ads:", vastTagUrl);
|
|
677
|
-
if (adPlaying) {
|
|
678
|
-
console.warn("[HlsAdPlayer] Cannot request new ads while an ad is playing");
|
|
679
|
-
return [
|
|
680
|
-
2,
|
|
681
|
-
Promise.reject(new Error("Ad already playing"))
|
|
682
|
-
];
|
|
683
|
-
}
|
|
684
|
-
_state.label = 1;
|
|
685
|
-
case 1:
|
|
686
|
-
_state.trys.push([
|
|
687
|
-
1,
|
|
688
|
-
5,
|
|
689
|
-
,
|
|
690
|
-
6
|
|
691
|
-
]);
|
|
692
|
-
sessionId = generateSessionId();
|
|
693
|
-
if (!preloadedAds.has(vastTagUrl)) return [
|
|
694
|
-
3,
|
|
695
|
-
2
|
|
696
|
-
];
|
|
697
|
-
ad = preloadedAds.get(vastTagUrl);
|
|
698
|
-
preloadedAds.delete(vastTagUrl);
|
|
699
|
-
console.log("[HlsAdPlayer] Using preloaded VAST response:", vastTagUrl);
|
|
700
|
-
return [
|
|
701
|
-
3,
|
|
702
|
-
4
|
|
703
|
-
];
|
|
704
|
-
case 2:
|
|
705
|
-
return [
|
|
706
|
-
4,
|
|
707
|
-
fetchAndParseVastAdLocal(vastTagUrl)
|
|
708
|
-
];
|
|
709
|
-
case 3:
|
|
710
|
-
ad = _state.sent();
|
|
711
|
-
_state.label = 4;
|
|
712
|
-
case 4:
|
|
713
|
-
if (!ad) {
|
|
714
|
-
console.warn("[HlsAdPlayer] No ads available from VAST response");
|
|
715
|
-
emit("ad_error");
|
|
716
|
-
return [
|
|
717
|
-
2,
|
|
718
|
-
Promise.reject(new Error("No ads available from VAST response"))
|
|
719
|
-
];
|
|
720
|
-
}
|
|
721
|
-
currentAd = ad;
|
|
722
|
-
console.log("[HlsAdPlayer] Ad parsed: ".concat(ad.title, ", duration: ").concat(ad.duration, "s"));
|
|
723
|
-
fireTrackingPixels2(ad.trackingUrls.impression);
|
|
724
|
-
trackingFired.impression = true;
|
|
725
|
-
return [
|
|
726
|
-
2,
|
|
727
|
-
Promise.resolve()
|
|
728
|
-
];
|
|
729
|
-
case 5:
|
|
730
|
-
error = _state.sent();
|
|
731
|
-
console.error("[HlsAdPlayer] Error requesting ads:", error);
|
|
732
|
-
emit("ad_error");
|
|
733
|
-
return [
|
|
734
|
-
2,
|
|
735
|
-
Promise.reject(error)
|
|
736
|
-
];
|
|
737
|
-
case 6:
|
|
738
|
-
return [
|
|
739
|
-
2
|
|
740
|
-
];
|
|
741
|
-
}
|
|
742
|
-
});
|
|
743
|
-
})();
|
|
744
|
-
},
|
|
745
|
-
play: function play() {
|
|
746
|
-
return _async_to_generator(function() {
|
|
747
|
-
var contentVolume, adVolume, mediaFile;
|
|
748
|
-
return _ts_generator(this, function(_state) {
|
|
749
|
-
if (destroyed) {
|
|
750
|
-
return [
|
|
751
|
-
2,
|
|
752
|
-
Promise.reject(new Error("Controller has been destroyed"))
|
|
753
|
-
];
|
|
754
|
-
}
|
|
755
|
-
if (!currentAd) {
|
|
756
|
-
console.warn("[HlsAdPlayer] Cannot play: No ad loaded (no ads available)");
|
|
757
|
-
return [
|
|
758
|
-
2,
|
|
759
|
-
Promise.reject(new Error("No ad loaded"))
|
|
760
|
-
];
|
|
761
|
-
}
|
|
762
|
-
console.log("[HlsAdPlayer] Starting ad playback");
|
|
763
|
-
try {
|
|
764
|
-
if (!adVideoElement) {
|
|
765
|
-
adVideoElement = createAdVideoElement();
|
|
766
|
-
adContainerEl === null || adContainerEl === void 0 ? void 0 : adContainerEl.appendChild(adVideoElement);
|
|
767
|
-
setupAdEventListeners();
|
|
768
|
-
}
|
|
769
|
-
trackingFired = {
|
|
770
|
-
impression: trackingFired.impression,
|
|
771
|
-
start: false,
|
|
772
|
-
firstQuartile: false,
|
|
773
|
-
midpoint: false,
|
|
774
|
-
thirdQuartile: false,
|
|
775
|
-
complete: false
|
|
776
|
-
};
|
|
777
|
-
contentVolume = contentVideo.volume;
|
|
778
|
-
originalVolume = Math.max(0, Math.min(1, contentVolume || originalVolume));
|
|
779
|
-
if (!(options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds)) {
|
|
780
|
-
contentVideo.pause();
|
|
781
|
-
console.log("[HlsAdPlayer] Content paused (VOD mode)");
|
|
782
|
-
} else {
|
|
783
|
-
console.log("[HlsAdPlayer] Content continues (Live mode)");
|
|
784
|
-
}
|
|
785
|
-
console.log("[HlsAdPlayer] FORCE MUTING main video");
|
|
786
|
-
contentVideo.muted = true;
|
|
787
|
-
contentVideo.volume = 0;
|
|
788
|
-
adPlaying = true;
|
|
789
|
-
setAdPlayingFlag(true);
|
|
790
|
-
if (adVideoElement) {
|
|
791
|
-
adVolume = originalMutedState ? 0 : originalVolume;
|
|
792
|
-
adVideoElement.volume = Math.max(0, Math.min(1, adVolume));
|
|
793
|
-
adVideoElement.muted = false;
|
|
794
|
-
console.log("[HlsAdPlayer] Set ad video volume to ".concat(adVideoElement.volume, ", muted: ").concat(adVideoElement.muted, ", originalMutedState: ").concat(originalMutedState, ", contentVolume: ").concat(contentVolume));
|
|
795
|
-
}
|
|
796
|
-
if (adContainerEl) {
|
|
797
|
-
adContainerEl.style.display = "flex";
|
|
798
|
-
adContainerEl.style.pointerEvents = "auto";
|
|
799
|
-
}
|
|
800
|
-
emit("content_pause");
|
|
801
|
-
mediaFile = selectBestMediaFile(currentAd.mediaFiles);
|
|
802
|
-
if (!mediaFile) {
|
|
803
|
-
throw new Error("No media file available for ad");
|
|
804
|
-
}
|
|
805
|
-
console.log("[HlsAdPlayer] Loading ad from: ".concat(mediaFile.url));
|
|
806
|
-
if (import_hls.default.isSupported()) {
|
|
807
|
-
if (adHls) {
|
|
808
|
-
adHls.destroy();
|
|
809
|
-
}
|
|
810
|
-
adHls = new import_hls.default({
|
|
811
|
-
enableWorker: true,
|
|
812
|
-
lowLatencyMode: false
|
|
813
|
-
});
|
|
814
|
-
adHls.loadSource(mediaFile.url);
|
|
815
|
-
adHls.attachMedia(adVideoElement);
|
|
816
|
-
adHls.on(import_hls.default.Events.MANIFEST_PARSED, function() {
|
|
817
|
-
console.log("[HlsAdPlayer] HLS manifest parsed, starting playback");
|
|
818
|
-
adVideoElement.play().catch(function(error) {
|
|
819
|
-
console.error("[HlsAdPlayer] Error starting ad playback:", error);
|
|
820
|
-
handleAdError();
|
|
821
|
-
});
|
|
822
|
-
});
|
|
823
|
-
adHls.on(import_hls.default.Events.ERROR, function(event, data) {
|
|
824
|
-
console.error("[HlsAdPlayer] HLS error:", data);
|
|
825
|
-
if (data.fatal) {
|
|
826
|
-
handleAdError();
|
|
827
|
-
}
|
|
828
|
-
});
|
|
829
|
-
} else if (adVideoElement.canPlayType("application/vnd.apple.mpegurl")) {
|
|
830
|
-
adVideoElement.src = mediaFile.url;
|
|
831
|
-
adVideoElement.play().catch(function(error) {
|
|
832
|
-
console.error("[HlsAdPlayer] Error starting ad playback:", error);
|
|
833
|
-
handleAdError();
|
|
834
|
-
});
|
|
835
|
-
} else {
|
|
836
|
-
throw new Error("HLS not supported");
|
|
837
|
-
}
|
|
838
|
-
return [
|
|
839
|
-
2,
|
|
840
|
-
Promise.resolve()
|
|
841
|
-
];
|
|
842
|
-
} catch (error) {
|
|
843
|
-
console.error("[HlsAdPlayer] Error playing ad:", error);
|
|
844
|
-
handleAdError();
|
|
845
|
-
return [
|
|
846
|
-
2,
|
|
847
|
-
Promise.reject(error)
|
|
848
|
-
];
|
|
849
|
-
}
|
|
850
|
-
return [
|
|
851
|
-
2
|
|
852
|
-
];
|
|
853
|
-
});
|
|
854
|
-
})();
|
|
855
|
-
},
|
|
856
|
-
pause: function pause() {
|
|
857
|
-
if (!adPlaying || !adVideoElement) {
|
|
858
|
-
return;
|
|
859
|
-
}
|
|
860
|
-
try {
|
|
861
|
-
if (adVideoElement && !adVideoElement.paused) {
|
|
862
|
-
adVideoElement.pause();
|
|
863
|
-
}
|
|
864
|
-
} catch (error) {
|
|
865
|
-
console.warn("[HlsAdPlayer] Error pausing ad:", error);
|
|
866
|
-
}
|
|
867
|
-
},
|
|
868
|
-
resume: function resume() {
|
|
869
|
-
if (!adPlaying || !adVideoElement) {
|
|
870
|
-
return;
|
|
871
|
-
}
|
|
872
|
-
try {
|
|
873
|
-
if (adVideoElement && adVideoElement.paused) {
|
|
874
|
-
adVideoElement.play().catch(function() {});
|
|
875
|
-
}
|
|
876
|
-
} catch (error) {
|
|
877
|
-
console.warn("[HlsAdPlayer] Error resuming ad:", error);
|
|
878
|
-
}
|
|
879
|
-
},
|
|
880
|
-
stop: function stop() {
|
|
881
|
-
return _async_to_generator(function() {
|
|
882
|
-
var previousMutedState;
|
|
883
|
-
return _ts_generator(this, function(_state) {
|
|
884
|
-
console.log("[HlsAdPlayer] Stopping ad");
|
|
885
|
-
adPlaying = false;
|
|
886
|
-
setAdPlayingFlag(false);
|
|
887
|
-
previousMutedState = contentVideo.muted;
|
|
888
|
-
contentVideo.muted = originalMutedState;
|
|
889
|
-
contentVideo.volume = originalMutedState ? 0 : originalVolume;
|
|
890
|
-
console.log("[HlsAdPlayer] Restored mute state on stop: ".concat(previousMutedState, " -> ").concat(originalMutedState));
|
|
891
|
-
if (adContainerEl) {
|
|
892
|
-
adContainerEl.style.display = "none";
|
|
893
|
-
adContainerEl.style.pointerEvents = "none";
|
|
894
|
-
}
|
|
895
|
-
contentVideo.style.visibility = "visible";
|
|
896
|
-
contentVideo.style.opacity = "1";
|
|
897
|
-
if (options === null || options === void 0 ? void 0 : options.continueLiveStreamDuringAds) {
|
|
898
|
-
if (contentVideo.paused) {
|
|
899
|
-
console.log("[HlsAdPlayer] Content video paused in live mode, resuming playback on stop");
|
|
900
|
-
}
|
|
901
|
-
contentVideo.play().catch(function() {});
|
|
902
|
-
}
|
|
903
|
-
if (adHls) {
|
|
904
|
-
adHls.destroy();
|
|
905
|
-
adHls = void 0;
|
|
906
|
-
}
|
|
907
|
-
if (adVideoElement) {
|
|
908
|
-
adVideoElement.pause();
|
|
909
|
-
adVideoElement.src = "";
|
|
910
|
-
adVideoElement.remove();
|
|
911
|
-
adVideoElement = void 0;
|
|
912
|
-
}
|
|
913
|
-
currentAd = void 0;
|
|
914
|
-
return [
|
|
915
|
-
2
|
|
916
|
-
];
|
|
917
|
-
});
|
|
918
|
-
})();
|
|
919
|
-
},
|
|
920
|
-
destroy: function destroy() {
|
|
921
|
-
console.log("[HlsAdPlayer] Destroying");
|
|
922
|
-
destroyed = true;
|
|
923
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
924
|
-
try {
|
|
925
|
-
for(var _iterator = pendingTimeouts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
926
|
-
var timeoutId = _step.value;
|
|
927
|
-
clearTimeout(timeoutId);
|
|
928
|
-
}
|
|
929
|
-
} catch (err) {
|
|
930
|
-
_didIteratorError = true;
|
|
931
|
-
_iteratorError = err;
|
|
932
|
-
} finally{
|
|
933
|
-
try {
|
|
934
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
935
|
-
_iterator.return();
|
|
936
|
-
}
|
|
937
|
-
} finally{
|
|
938
|
-
if (_didIteratorError) {
|
|
939
|
-
throw _iteratorError;
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
pendingTimeouts = [];
|
|
944
|
-
adPlaying = false;
|
|
945
|
-
setAdPlayingFlag(false);
|
|
946
|
-
contentVideo.muted = originalMutedState;
|
|
947
|
-
contentVideo.volume = originalMutedState ? 0 : originalVolume;
|
|
948
|
-
if (adHls) {
|
|
949
|
-
adHls.destroy();
|
|
950
|
-
adHls = void 0;
|
|
951
|
-
}
|
|
952
|
-
if (adVideoElement) {
|
|
953
|
-
adVideoElement.pause();
|
|
954
|
-
adVideoElement.src = "";
|
|
955
|
-
adVideoElement.remove();
|
|
956
|
-
adVideoElement = void 0;
|
|
957
|
-
}
|
|
958
|
-
if (adContainerEl === null || adContainerEl === void 0 ? void 0 : adContainerEl.parentElement) {
|
|
959
|
-
adContainerEl.parentElement.removeChild(adContainerEl);
|
|
960
|
-
}
|
|
961
|
-
adContainerEl = void 0;
|
|
962
|
-
currentAd = void 0;
|
|
963
|
-
listeners.clear();
|
|
964
|
-
preloadedAds.clear();
|
|
965
|
-
preloadingAds.clear();
|
|
966
|
-
},
|
|
967
|
-
isAdPlaying: function isAdPlaying() {
|
|
968
|
-
return adPlaying;
|
|
969
|
-
},
|
|
970
|
-
resize: function resize(width, height) {
|
|
971
|
-
console.log("[HlsAdPlayer] Resizing to ".concat(width, "x").concat(height));
|
|
972
|
-
if (adContainerEl) {
|
|
973
|
-
adContainerEl.style.width = "".concat(width, "px");
|
|
974
|
-
adContainerEl.style.height = "".concat(height, "px");
|
|
975
|
-
}
|
|
976
|
-
if (adVideoElement) {
|
|
977
|
-
adVideoElement.style.width = "".concat(width, "px");
|
|
978
|
-
adVideoElement.style.height = "".concat(height, "px");
|
|
979
|
-
}
|
|
980
|
-
},
|
|
981
|
-
on: function on(event, listener) {
|
|
982
|
-
if (!listeners.has(event)) listeners.set(event, /* @__PURE__ */ new Set());
|
|
983
|
-
listeners.get(event).add(listener);
|
|
984
|
-
},
|
|
985
|
-
off: function off(event, listener) {
|
|
986
|
-
var _listeners_get;
|
|
987
|
-
(_listeners_get = listeners.get(event)) === null || _listeners_get === void 0 ? void 0 : _listeners_get.delete(listener);
|
|
988
|
-
},
|
|
989
|
-
updateOriginalMutedState: function updateOriginalMutedState(muted, volume) {
|
|
990
|
-
var nextVolume = typeof volume === "number" && !Number.isNaN(volume) ? Math.max(0, Math.min(1, volume)) : originalVolume;
|
|
991
|
-
console.log("[HlsAdPlayer] updateOriginalMutedState called: { muted: ".concat(originalMutedState, " -> ").concat(muted, ", volume: ").concat(originalVolume, " -> ").concat(nextVolume, " }"));
|
|
992
|
-
originalMutedState = muted;
|
|
993
|
-
originalVolume = nextVolume;
|
|
994
|
-
},
|
|
995
|
-
getOriginalMutedState: function getOriginalMutedState() {
|
|
996
|
-
return originalMutedState;
|
|
997
|
-
},
|
|
998
|
-
getOriginalVolume: function getOriginalVolume() {
|
|
999
|
-
return originalVolume;
|
|
1000
|
-
},
|
|
1001
|
-
setAdVolume: function setAdVolume(volume) {
|
|
1002
|
-
if (adVideoElement && adPlaying) {
|
|
1003
|
-
adVideoElement.volume = Math.max(0, Math.min(1, volume));
|
|
1004
|
-
}
|
|
1005
|
-
},
|
|
1006
|
-
getAdVolume: function getAdVolume() {
|
|
1007
|
-
if (adVideoElement && adPlaying) {
|
|
1008
|
-
return adVideoElement.volume;
|
|
1009
|
-
}
|
|
1010
|
-
return 1;
|
|
1011
|
-
},
|
|
1012
|
-
showPlaceholder: function showPlaceholder() {
|
|
1013
|
-
contentVideo.style.opacity = "0";
|
|
1014
|
-
contentVideo.style.visibility = "hidden";
|
|
1015
|
-
if (!adContainerEl) {
|
|
1016
|
-
var _contentVideo_parentElement;
|
|
1017
|
-
var container = document.createElement("div");
|
|
1018
|
-
container.style.position = "absolute";
|
|
1019
|
-
container.style.left = "0";
|
|
1020
|
-
container.style.top = "0";
|
|
1021
|
-
container.style.right = "0";
|
|
1022
|
-
container.style.bottom = "0";
|
|
1023
|
-
container.style.display = "none";
|
|
1024
|
-
container.style.alignItems = "center";
|
|
1025
|
-
container.style.justifyContent = "center";
|
|
1026
|
-
container.style.pointerEvents = "none";
|
|
1027
|
-
container.style.zIndex = "10";
|
|
1028
|
-
container.style.backgroundColor = "#000";
|
|
1029
|
-
(_contentVideo_parentElement = contentVideo.parentElement) === null || _contentVideo_parentElement === void 0 ? void 0 : _contentVideo_parentElement.appendChild(container);
|
|
1030
|
-
adContainerEl = container;
|
|
1031
|
-
}
|
|
1032
|
-
if (adContainerEl) {
|
|
1033
|
-
adContainerEl.style.display = "flex";
|
|
1034
|
-
adContainerEl.style.pointerEvents = "auto";
|
|
1035
|
-
}
|
|
1036
|
-
},
|
|
1037
|
-
hidePlaceholder: function hidePlaceholder() {
|
|
1038
|
-
if (adContainerEl) {
|
|
1039
|
-
adContainerEl.style.display = "none";
|
|
1040
|
-
adContainerEl.style.pointerEvents = "none";
|
|
1041
|
-
}
|
|
1042
|
-
if (!adPlaying) {
|
|
1043
|
-
contentVideo.style.visibility = "visible";
|
|
1044
|
-
contentVideo.style.opacity = "1";
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
};
|
|
1048
|
-
}
|
|
1049
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1050
|
-
0 && (module.exports = {
|
|
1051
|
-
createHlsAdPlayer: createHlsAdPlayer
|
|
1052
|
-
});
|
|
1053
|
-
//# sourceMappingURL=hlsAdPlayer.cjs.map
|