stormcloud-video-player 0.8.16 → 0.8.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/stormcloud-vp.min.js +2 -2
- package/lib/index.cjs +4449 -4221
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +18 -195
- package/lib/index.d.ts +18 -195
- package/lib/index.js +4455 -4219
- package/lib/index.js.map +1 -1
- package/lib/player/AdBreakOrchestrator.cjs +2275 -0
- package/lib/player/AdBreakOrchestrator.cjs.map +1 -0
- package/lib/player/AdBreakOrchestrator.d.cts +62 -0
- package/lib/player/AdPreloadPool.cjs +673 -0
- package/lib/player/AdPreloadPool.cjs.map +1 -0
- package/lib/player/AdPreloadPool.d.cts +37 -0
- package/lib/player/AdTimingService.cjs +841 -0
- package/lib/player/AdTimingService.cjs.map +1 -0
- package/lib/player/AdTimingService.d.cts +88 -0
- package/lib/player/HlsEngine.cjs +1502 -0
- package/lib/player/HlsEngine.cjs.map +1 -0
- package/lib/player/HlsEngine.d.cts +38 -0
- package/lib/player/PlaceholderLayer.cjs +191 -0
- package/lib/player/PlaceholderLayer.cjs.map +1 -0
- package/lib/player/PlaceholderLayer.d.cts +12 -0
- package/lib/player/PlayerControls.cjs +225 -0
- package/lib/player/PlayerControls.cjs.map +1 -0
- package/lib/player/PlayerControls.d.cts +13 -0
- package/lib/player/Scte35CueManager.cjs +413 -0
- package/lib/player/Scte35CueManager.cjs.map +1 -0
- package/lib/player/Scte35CueManager.d.cts +43 -0
- package/lib/player/Scte35Parser.cjs +945 -0
- package/lib/player/Scte35Parser.cjs.map +1 -0
- package/lib/player/Scte35Parser.d.cts +23 -0
- package/lib/player/StormcloudVideoPlayer.cjs +4411 -4168
- package/lib/player/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/player/StormcloudVideoPlayer.d.cts +19 -196
- package/lib/player/VmapManager.cjs +1706 -0
- package/lib/player/VmapManager.cjs.map +1 -0
- package/lib/player/VmapManager.d.cts +38 -0
- package/lib/player/playerTypes.cjs +49 -0
- package/lib/player/playerTypes.cjs.map +1 -0
- package/lib/player/playerTypes.d.cts +20 -0
- package/lib/players/HlsPlayer.cjs +4411 -4169
- package/lib/players/HlsPlayer.cjs.map +1 -1
- package/lib/players/HlsPlayer.d.cts +1 -1
- package/lib/players/index.cjs +4411 -4169
- package/lib/players/index.cjs.map +1 -1
- package/lib/sdk/hlsAdPlayer.d.cts +1 -1
- package/lib/{types-CWWADkvd.d.cts → types-DNiBmPKK.d.cts} +18 -1
- package/lib/ui/StormcloudVideoPlayer.cjs +4449 -4221
- package/lib/ui/StormcloudVideoPlayer.cjs.map +1 -1
- package/lib/ui/StormcloudVideoPlayer.d.cts +1 -1
- package/lib/utils/tracking.d.cts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,1502 @@
|
|
|
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 _class_call_check(instance, Constructor) {
|
|
32
|
+
if (!(instance instanceof Constructor)) {
|
|
33
|
+
throw new TypeError("Cannot call a class as a function");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function _defineProperties(target, props) {
|
|
37
|
+
for(var i = 0; i < props.length; i++){
|
|
38
|
+
var descriptor = props[i];
|
|
39
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
40
|
+
descriptor.configurable = true;
|
|
41
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
42
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
46
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
47
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
48
|
+
return Constructor;
|
|
49
|
+
}
|
|
50
|
+
function _define_property(obj, key, value) {
|
|
51
|
+
if (key in obj) {
|
|
52
|
+
Object.defineProperty(obj, key, {
|
|
53
|
+
value: value,
|
|
54
|
+
enumerable: true,
|
|
55
|
+
configurable: true,
|
|
56
|
+
writable: true
|
|
57
|
+
});
|
|
58
|
+
} else {
|
|
59
|
+
obj[key] = value;
|
|
60
|
+
}
|
|
61
|
+
return obj;
|
|
62
|
+
}
|
|
63
|
+
function _instanceof(left, right) {
|
|
64
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
65
|
+
return !!right[Symbol.hasInstance](left);
|
|
66
|
+
} else {
|
|
67
|
+
return left instanceof right;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function _object_spread(target) {
|
|
71
|
+
for(var i = 1; i < arguments.length; i++){
|
|
72
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
73
|
+
var ownKeys = Object.keys(source);
|
|
74
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
75
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
76
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
ownKeys.forEach(function(key) {
|
|
80
|
+
_define_property(target, key, source[key]);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return target;
|
|
84
|
+
}
|
|
85
|
+
function ownKeys(object, enumerableOnly) {
|
|
86
|
+
var keys = Object.keys(object);
|
|
87
|
+
if (Object.getOwnPropertySymbols) {
|
|
88
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
89
|
+
if (enumerableOnly) {
|
|
90
|
+
symbols = symbols.filter(function(sym) {
|
|
91
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
keys.push.apply(keys, symbols);
|
|
95
|
+
}
|
|
96
|
+
return keys;
|
|
97
|
+
}
|
|
98
|
+
function _object_spread_props(target, source) {
|
|
99
|
+
source = source != null ? source : {};
|
|
100
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
101
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
102
|
+
} else {
|
|
103
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
104
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return target;
|
|
108
|
+
}
|
|
109
|
+
function _type_of(obj) {
|
|
110
|
+
"@swc/helpers - typeof";
|
|
111
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
112
|
+
}
|
|
113
|
+
function _ts_generator(thisArg, body) {
|
|
114
|
+
var f, y, t, _ = {
|
|
115
|
+
label: 0,
|
|
116
|
+
sent: function() {
|
|
117
|
+
if (t[0] & 1) throw t[1];
|
|
118
|
+
return t[1];
|
|
119
|
+
},
|
|
120
|
+
trys: [],
|
|
121
|
+
ops: []
|
|
122
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
123
|
+
return d(g, "next", {
|
|
124
|
+
value: verb(0)
|
|
125
|
+
}), d(g, "throw", {
|
|
126
|
+
value: verb(1)
|
|
127
|
+
}), d(g, "return", {
|
|
128
|
+
value: verb(2)
|
|
129
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
130
|
+
value: function() {
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
}), g;
|
|
134
|
+
function verb(n) {
|
|
135
|
+
return function(v) {
|
|
136
|
+
return step([
|
|
137
|
+
n,
|
|
138
|
+
v
|
|
139
|
+
]);
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function step(op) {
|
|
143
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
144
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
145
|
+
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;
|
|
146
|
+
if (y = 0, t) op = [
|
|
147
|
+
op[0] & 2,
|
|
148
|
+
t.value
|
|
149
|
+
];
|
|
150
|
+
switch(op[0]){
|
|
151
|
+
case 0:
|
|
152
|
+
case 1:
|
|
153
|
+
t = op;
|
|
154
|
+
break;
|
|
155
|
+
case 4:
|
|
156
|
+
_.label++;
|
|
157
|
+
return {
|
|
158
|
+
value: op[1],
|
|
159
|
+
done: false
|
|
160
|
+
};
|
|
161
|
+
case 5:
|
|
162
|
+
_.label++;
|
|
163
|
+
y = op[1];
|
|
164
|
+
op = [
|
|
165
|
+
0
|
|
166
|
+
];
|
|
167
|
+
continue;
|
|
168
|
+
case 7:
|
|
169
|
+
op = _.ops.pop();
|
|
170
|
+
_.trys.pop();
|
|
171
|
+
continue;
|
|
172
|
+
default:
|
|
173
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
174
|
+
_ = 0;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
178
|
+
_.label = op[1];
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
182
|
+
_.label = t[1];
|
|
183
|
+
t = op;
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
if (t && _.label < t[2]) {
|
|
187
|
+
_.label = t[2];
|
|
188
|
+
_.ops.push(op);
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
if (t[2]) _.ops.pop();
|
|
192
|
+
_.trys.pop();
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
op = body.call(thisArg, _);
|
|
196
|
+
} catch (e) {
|
|
197
|
+
op = [
|
|
198
|
+
6,
|
|
199
|
+
e
|
|
200
|
+
];
|
|
201
|
+
y = 0;
|
|
202
|
+
} finally{
|
|
203
|
+
f = t = 0;
|
|
204
|
+
}
|
|
205
|
+
if (op[0] & 5) throw op[1];
|
|
206
|
+
return {
|
|
207
|
+
value: op[0] ? op[1] : void 0,
|
|
208
|
+
done: true
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
var __create = Object.create;
|
|
213
|
+
var __defProp = Object.defineProperty;
|
|
214
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
215
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
216
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
217
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
218
|
+
var __export = function __export(target, all) {
|
|
219
|
+
for(var name in all)__defProp(target, name, {
|
|
220
|
+
get: all[name],
|
|
221
|
+
enumerable: true
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
var __copyProps = function __copyProps(to, from, except, desc) {
|
|
225
|
+
if (from && (typeof from === "undefined" ? "undefined" : _type_of(from)) === "object" || typeof from === "function") {
|
|
226
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
227
|
+
try {
|
|
228
|
+
var _loop = function() {
|
|
229
|
+
var key = _step.value;
|
|
230
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
231
|
+
get: function get() {
|
|
232
|
+
return from[key];
|
|
233
|
+
},
|
|
234
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
238
|
+
} catch (err) {
|
|
239
|
+
_didIteratorError = true;
|
|
240
|
+
_iteratorError = err;
|
|
241
|
+
} finally{
|
|
242
|
+
try {
|
|
243
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
244
|
+
_iterator.return();
|
|
245
|
+
}
|
|
246
|
+
} finally{
|
|
247
|
+
if (_didIteratorError) {
|
|
248
|
+
throw _iteratorError;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return to;
|
|
254
|
+
};
|
|
255
|
+
var __toESM = function __toESM(mod, isNodeMode, target) {
|
|
256
|
+
return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
|
|
257
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
258
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
259
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
260
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
261
|
+
value: mod,
|
|
262
|
+
enumerable: true
|
|
263
|
+
}) : target, mod);
|
|
264
|
+
};
|
|
265
|
+
var __toCommonJS = function __toCommonJS(mod) {
|
|
266
|
+
return __copyProps(__defProp({}, "__esModule", {
|
|
267
|
+
value: true
|
|
268
|
+
}), mod);
|
|
269
|
+
};
|
|
270
|
+
// src/player/HlsEngine.ts
|
|
271
|
+
var HlsEngine_exports = {};
|
|
272
|
+
__export(HlsEngine_exports, {
|
|
273
|
+
HlsEngine: function HlsEngine1() {
|
|
274
|
+
return HlsEngine;
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
module.exports = __toCommonJS(HlsEngine_exports);
|
|
278
|
+
var import_hls = __toESM(require("hls.js"), 1);
|
|
279
|
+
// src/player/Scte35Parser.ts
|
|
280
|
+
function parseCueOutDuration(value) {
|
|
281
|
+
var num = parseFloat(value.trim());
|
|
282
|
+
if (!Number.isNaN(num)) return num;
|
|
283
|
+
var match = value.match(/(?:^|[,\s])DURATION\s*=\s*([0-9.]+)/i) || value.match(/Duration\s*=\s*([0-9.]+)/i);
|
|
284
|
+
if (match && match[1] != null) {
|
|
285
|
+
var dStr = match[1];
|
|
286
|
+
var d = parseFloat(dStr);
|
|
287
|
+
return Number.isNaN(d) ? void 0 : d;
|
|
288
|
+
}
|
|
289
|
+
return void 0;
|
|
290
|
+
}
|
|
291
|
+
function parseCueOutCont(value) {
|
|
292
|
+
var res = {};
|
|
293
|
+
var elapsedMatch = value.match(/Elapsed\s*=\s*([0-9.]+)/i);
|
|
294
|
+
var durationMatch = value.match(/Duration\s*=\s*([0-9.]+)/i);
|
|
295
|
+
if (elapsedMatch && elapsedMatch[1] != null) {
|
|
296
|
+
var e = parseFloat(elapsedMatch[1]);
|
|
297
|
+
if (!Number.isNaN(e)) res.elapsed = e;
|
|
298
|
+
}
|
|
299
|
+
if (durationMatch && durationMatch[1] != null) {
|
|
300
|
+
var d = parseFloat(durationMatch[1]);
|
|
301
|
+
if (!Number.isNaN(d)) res.duration = d;
|
|
302
|
+
}
|
|
303
|
+
if (!("elapsed" in res) || !("duration" in res)) {
|
|
304
|
+
var slashMatch = value.match(/([0-9.]+)\s*\/\s*([0-9.]+)/);
|
|
305
|
+
if (slashMatch && slashMatch[1] && slashMatch[2]) {
|
|
306
|
+
var elapsed = parseFloat(slashMatch[1]);
|
|
307
|
+
var duration = parseFloat(slashMatch[2]);
|
|
308
|
+
if (!Number.isNaN(elapsed) && !("elapsed" in res)) res.elapsed = elapsed;
|
|
309
|
+
if (!Number.isNaN(duration) && !("duration" in res)) res.duration = duration;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if ("elapsed" in res || "duration" in res) return res;
|
|
313
|
+
return void 0;
|
|
314
|
+
}
|
|
315
|
+
function parseAttributeList(value) {
|
|
316
|
+
var attrs = {};
|
|
317
|
+
var regex = /([A-Z0-9-]+)=(("[^"]*")|([^",]*))(?:,|$)/gi;
|
|
318
|
+
var match;
|
|
319
|
+
while((match = regex.exec(value)) !== null){
|
|
320
|
+
var _match_, _ref, _match_1;
|
|
321
|
+
var key = (_match_ = match[1]) !== null && _match_ !== void 0 ? _match_ : "";
|
|
322
|
+
var rawVal = (_ref = (_match_1 = match[3]) !== null && _match_1 !== void 0 ? _match_1 : match[4]) !== null && _ref !== void 0 ? _ref : "";
|
|
323
|
+
if (rawVal.startsWith('"') && rawVal.endsWith('"')) {
|
|
324
|
+
rawVal = rawVal.slice(1, -1);
|
|
325
|
+
}
|
|
326
|
+
if (key) {
|
|
327
|
+
attrs[key] = rawVal;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return attrs;
|
|
331
|
+
}
|
|
332
|
+
function toNumber(val) {
|
|
333
|
+
if (val == null) return void 0;
|
|
334
|
+
var n = typeof val === "string" ? parseFloat(val) : Number(val);
|
|
335
|
+
return Number.isNaN(n) ? void 0 : n;
|
|
336
|
+
}
|
|
337
|
+
function decodeId3ValueToText(value) {
|
|
338
|
+
try {
|
|
339
|
+
if (typeof value === "string") return value;
|
|
340
|
+
var decoder = new TextDecoder("utf-8", {
|
|
341
|
+
fatal: false
|
|
342
|
+
});
|
|
343
|
+
var text = decoder.decode(value);
|
|
344
|
+
if (text && /[\x20-\x7E]/.test(text)) return text;
|
|
345
|
+
var out = "";
|
|
346
|
+
for(var i = 0; i < value.length; i++)out += String.fromCharCode(value[i]);
|
|
347
|
+
return out;
|
|
348
|
+
} catch (unused) {
|
|
349
|
+
return void 0;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
function getFragmentStartSeconds(frag) {
|
|
353
|
+
var candidates = [
|
|
354
|
+
frag === null || frag === void 0 ? void 0 : frag.start,
|
|
355
|
+
frag === null || frag === void 0 ? void 0 : frag.startPTS
|
|
356
|
+
];
|
|
357
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
358
|
+
try {
|
|
359
|
+
for(var _iterator = candidates[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
360
|
+
var candidate = _step.value;
|
|
361
|
+
if (typeof candidate === "number" && Number.isFinite(candidate)) {
|
|
362
|
+
return candidate;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
} catch (err) {
|
|
366
|
+
_didIteratorError = true;
|
|
367
|
+
_iteratorError = err;
|
|
368
|
+
} finally{
|
|
369
|
+
try {
|
|
370
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
371
|
+
_iterator.return();
|
|
372
|
+
}
|
|
373
|
+
} finally{
|
|
374
|
+
if (_didIteratorError) {
|
|
375
|
+
throw _iteratorError;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return void 0;
|
|
380
|
+
}
|
|
381
|
+
function parseScte35FromId3(tag) {
|
|
382
|
+
var text = decodeId3ValueToText(tag.value);
|
|
383
|
+
if (!text) return void 0;
|
|
384
|
+
var cueOutMatch = text.match(/EXT-X-CUE-OUT(?::([^\r\n]*))?/i) || text.match(/CUE-OUT(?::([^\r\n]*))?/i);
|
|
385
|
+
if (cueOutMatch) {
|
|
386
|
+
var _cueOutMatch_;
|
|
387
|
+
var arg = ((_cueOutMatch_ = cueOutMatch[1]) !== null && _cueOutMatch_ !== void 0 ? _cueOutMatch_ : "").trim();
|
|
388
|
+
var dur = parseCueOutDuration(arg);
|
|
389
|
+
var marker = _object_spread_props(_object_spread({
|
|
390
|
+
type: "start"
|
|
391
|
+
}, tag.ptsSeconds !== void 0 ? {
|
|
392
|
+
ptsSeconds: tag.ptsSeconds
|
|
393
|
+
} : {}, dur !== void 0 ? {
|
|
394
|
+
durationSeconds: dur
|
|
395
|
+
} : {}), {
|
|
396
|
+
raw: {
|
|
397
|
+
id3: text
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
return marker;
|
|
401
|
+
}
|
|
402
|
+
var cueOutContMatch = text.match(/EXT-X-CUE-OUT-CONT:([^\r\n]*)/i);
|
|
403
|
+
if (cueOutContMatch) {
|
|
404
|
+
var _cueOutContMatch_;
|
|
405
|
+
var arg1 = ((_cueOutContMatch_ = cueOutContMatch[1]) !== null && _cueOutContMatch_ !== void 0 ? _cueOutContMatch_ : "").trim();
|
|
406
|
+
var cont = parseCueOutCont(arg1);
|
|
407
|
+
var marker1 = _object_spread_props(_object_spread({
|
|
408
|
+
type: "progress"
|
|
409
|
+
}, tag.ptsSeconds !== void 0 ? {
|
|
410
|
+
ptsSeconds: tag.ptsSeconds
|
|
411
|
+
} : {}, (cont === null || cont === void 0 ? void 0 : cont.duration) !== void 0 ? {
|
|
412
|
+
durationSeconds: cont.duration
|
|
413
|
+
} : {}), {
|
|
414
|
+
raw: {
|
|
415
|
+
id3: text
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
return marker1;
|
|
419
|
+
}
|
|
420
|
+
var cueInMatch = text.match(/EXT-X-CUE-IN\b/i) || text.match(/CUE-IN\b/i);
|
|
421
|
+
if (cueInMatch) {
|
|
422
|
+
var marker2 = _object_spread_props(_object_spread({
|
|
423
|
+
type: "end"
|
|
424
|
+
}, tag.ptsSeconds !== void 0 ? {
|
|
425
|
+
ptsSeconds: tag.ptsSeconds
|
|
426
|
+
} : {}), {
|
|
427
|
+
raw: {
|
|
428
|
+
id3: text
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
return marker2;
|
|
432
|
+
}
|
|
433
|
+
var daterangeMatch = text.match(/EXT-X-DATERANGE:([^\r\n]*)/i);
|
|
434
|
+
if (daterangeMatch) {
|
|
435
|
+
var _daterangeMatch_, _attrs_CLASS;
|
|
436
|
+
var attrs = parseAttributeList((_daterangeMatch_ = daterangeMatch[1]) !== null && _daterangeMatch_ !== void 0 ? _daterangeMatch_ : "");
|
|
437
|
+
var hasScteOut = "SCTE35-OUT" in attrs || attrs["SCTE35-OUT"] !== void 0;
|
|
438
|
+
var hasScteIn = "SCTE35-IN" in attrs || attrs["SCTE35-IN"] !== void 0;
|
|
439
|
+
var klass = String((_attrs_CLASS = attrs["CLASS"]) !== null && _attrs_CLASS !== void 0 ? _attrs_CLASS : "");
|
|
440
|
+
var duration = toNumber(attrs["DURATION"]);
|
|
441
|
+
if (hasScteOut || /com\.apple\.hls\.cue/i.test(klass)) {
|
|
442
|
+
var marker3 = _object_spread_props(_object_spread({
|
|
443
|
+
type: "start"
|
|
444
|
+
}, tag.ptsSeconds !== void 0 ? {
|
|
445
|
+
ptsSeconds: tag.ptsSeconds
|
|
446
|
+
} : {}, duration !== void 0 ? {
|
|
447
|
+
durationSeconds: duration
|
|
448
|
+
} : {}), {
|
|
449
|
+
raw: {
|
|
450
|
+
id3: text,
|
|
451
|
+
attrs: attrs
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
return marker3;
|
|
455
|
+
}
|
|
456
|
+
if (hasScteIn) {
|
|
457
|
+
var marker4 = _object_spread_props(_object_spread({
|
|
458
|
+
type: "end"
|
|
459
|
+
}, tag.ptsSeconds !== void 0 ? {
|
|
460
|
+
ptsSeconds: tag.ptsSeconds
|
|
461
|
+
} : {}), {
|
|
462
|
+
raw: {
|
|
463
|
+
id3: text,
|
|
464
|
+
attrs: attrs
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
return marker4;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
if (/SCTE35-OUT/i.test(text)) {
|
|
471
|
+
var marker5 = _object_spread_props(_object_spread({
|
|
472
|
+
type: "start"
|
|
473
|
+
}, tag.ptsSeconds !== void 0 ? {
|
|
474
|
+
ptsSeconds: tag.ptsSeconds
|
|
475
|
+
} : {}), {
|
|
476
|
+
raw: {
|
|
477
|
+
id3: text
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
return marker5;
|
|
481
|
+
}
|
|
482
|
+
if (/SCTE35-IN/i.test(text)) {
|
|
483
|
+
var marker6 = _object_spread_props(_object_spread({
|
|
484
|
+
type: "end"
|
|
485
|
+
}, tag.ptsSeconds !== void 0 ? {
|
|
486
|
+
ptsSeconds: tag.ptsSeconds
|
|
487
|
+
} : {}), {
|
|
488
|
+
raw: {
|
|
489
|
+
id3: text
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
return marker6;
|
|
493
|
+
}
|
|
494
|
+
if (_instanceof(tag.value, Uint8Array)) {
|
|
495
|
+
var bin = parseScte35Binary(tag.value);
|
|
496
|
+
if (bin) return bin;
|
|
497
|
+
}
|
|
498
|
+
return void 0;
|
|
499
|
+
}
|
|
500
|
+
function normalizeFragmentPayload(payload) {
|
|
501
|
+
if (_instanceof(payload, Uint8Array)) {
|
|
502
|
+
return payload;
|
|
503
|
+
}
|
|
504
|
+
if (_instanceof(payload, ArrayBuffer)) {
|
|
505
|
+
return new Uint8Array(payload);
|
|
506
|
+
}
|
|
507
|
+
if (ArrayBuffer.isView(payload)) {
|
|
508
|
+
var view = payload;
|
|
509
|
+
return new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
|
|
510
|
+
}
|
|
511
|
+
return void 0;
|
|
512
|
+
}
|
|
513
|
+
function detectTsPacketFormat(data) {
|
|
514
|
+
var packetSizes = [
|
|
515
|
+
188,
|
|
516
|
+
192,
|
|
517
|
+
204
|
|
518
|
+
];
|
|
519
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
520
|
+
try {
|
|
521
|
+
for(var _iterator = packetSizes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
522
|
+
var packetSize = _step.value;
|
|
523
|
+
var tsPayloadOffset = packetSize === 192 ? 4 : 0;
|
|
524
|
+
for(var offset = 0; offset < packetSize; offset++){
|
|
525
|
+
var matchedPackets = 0;
|
|
526
|
+
for(var packetStart = offset; packetStart + tsPayloadOffset < data.length && matchedPackets < 5; packetStart += packetSize){
|
|
527
|
+
if (data[packetStart + tsPayloadOffset] !== 71) {
|
|
528
|
+
break;
|
|
529
|
+
}
|
|
530
|
+
matchedPackets++;
|
|
531
|
+
}
|
|
532
|
+
if (matchedPackets >= 2) {
|
|
533
|
+
return {
|
|
534
|
+
offset: offset,
|
|
535
|
+
packetSize: packetSize,
|
|
536
|
+
tsPayloadOffset: tsPayloadOffset
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
} catch (err) {
|
|
542
|
+
_didIteratorError = true;
|
|
543
|
+
_iteratorError = err;
|
|
544
|
+
} finally{
|
|
545
|
+
try {
|
|
546
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
547
|
+
_iterator.return();
|
|
548
|
+
}
|
|
549
|
+
} finally{
|
|
550
|
+
if (_didIteratorError) {
|
|
551
|
+
throw _iteratorError;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return void 0;
|
|
556
|
+
}
|
|
557
|
+
function getPsiSectionStart(payload, payloadUnitStart) {
|
|
558
|
+
if (!payloadUnitStart) {
|
|
559
|
+
return void 0;
|
|
560
|
+
}
|
|
561
|
+
var pointerField = payload[0];
|
|
562
|
+
if (pointerField == null) {
|
|
563
|
+
return void 0;
|
|
564
|
+
}
|
|
565
|
+
var sectionStart = 1 + pointerField;
|
|
566
|
+
return sectionStart < payload.length ? sectionStart : void 0;
|
|
567
|
+
}
|
|
568
|
+
function getPsiSectionLength(data, offset) {
|
|
569
|
+
var _data_, _data_1;
|
|
570
|
+
return (((_data_ = data[offset + 1]) !== null && _data_ !== void 0 ? _data_ : 0) & 15) << 8 | ((_data_1 = data[offset + 2]) !== null && _data_1 !== void 0 ? _data_1 : 0);
|
|
571
|
+
}
|
|
572
|
+
function parsePatSection(payload, payloadUnitStart, pmtPids) {
|
|
573
|
+
var sectionStart = getPsiSectionStart(payload, payloadUnitStart);
|
|
574
|
+
if (sectionStart == null || sectionStart + 8 >= payload.length) {
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
if (payload[sectionStart] !== 0) {
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
var sectionLength = getPsiSectionLength(payload, sectionStart);
|
|
581
|
+
var sectionEnd = Math.min(payload.length, sectionStart + 3 + sectionLength);
|
|
582
|
+
for(var offset = sectionStart + 8; offset + 4 <= sectionEnd - 4; offset += 4){
|
|
583
|
+
var _payload_offset, _payload_, _payload_1, _payload_2;
|
|
584
|
+
var programNumber = ((_payload_offset = payload[offset]) !== null && _payload_offset !== void 0 ? _payload_offset : 0) << 8 | ((_payload_ = payload[offset + 1]) !== null && _payload_ !== void 0 ? _payload_ : 0);
|
|
585
|
+
var pid = (((_payload_1 = payload[offset + 2]) !== null && _payload_1 !== void 0 ? _payload_1 : 0) & 31) << 8 | ((_payload_2 = payload[offset + 3]) !== null && _payload_2 !== void 0 ? _payload_2 : 0);
|
|
586
|
+
if (programNumber !== 0) {
|
|
587
|
+
pmtPids.add(pid);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
function descriptorsIdentifyScte35(data, start, end) {
|
|
592
|
+
var offset = start;
|
|
593
|
+
while(offset + 2 <= end){
|
|
594
|
+
var _data_offset, _data_, _data_descriptorStart, _data_1, _data_2, _data_3;
|
|
595
|
+
var tag = (_data_offset = data[offset]) !== null && _data_offset !== void 0 ? _data_offset : 0;
|
|
596
|
+
var length = (_data_ = data[offset + 1]) !== null && _data_ !== void 0 ? _data_ : 0;
|
|
597
|
+
var descriptorStart = offset + 2;
|
|
598
|
+
var descriptorEnd = descriptorStart + length;
|
|
599
|
+
if (descriptorEnd > end) {
|
|
600
|
+
return false;
|
|
601
|
+
}
|
|
602
|
+
var registration = length >= 4 ? String.fromCharCode((_data_descriptorStart = data[descriptorStart]) !== null && _data_descriptorStart !== void 0 ? _data_descriptorStart : 0, (_data_1 = data[descriptorStart + 1]) !== null && _data_1 !== void 0 ? _data_1 : 0, (_data_2 = data[descriptorStart + 2]) !== null && _data_2 !== void 0 ? _data_2 : 0, (_data_3 = data[descriptorStart + 3]) !== null && _data_3 !== void 0 ? _data_3 : 0) : "";
|
|
603
|
+
if (tag === 138 || registration === "CUEI" || registration === "SCTE") {
|
|
604
|
+
return true;
|
|
605
|
+
}
|
|
606
|
+
offset = descriptorEnd;
|
|
607
|
+
}
|
|
608
|
+
return false;
|
|
609
|
+
}
|
|
610
|
+
function parsePmtSection(payload, payloadUnitStart, tsScte35Pids) {
|
|
611
|
+
var _payload_, _payload_1;
|
|
612
|
+
var sectionStart = getPsiSectionStart(payload, payloadUnitStart);
|
|
613
|
+
if (sectionStart == null || sectionStart + 12 >= payload.length) {
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
if (payload[sectionStart] !== 2) {
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
var sectionLength = getPsiSectionLength(payload, sectionStart);
|
|
620
|
+
var sectionEnd = Math.min(payload.length, sectionStart + 3 + sectionLength);
|
|
621
|
+
var programInfoLength = (((_payload_ = payload[sectionStart + 10]) !== null && _payload_ !== void 0 ? _payload_ : 0) & 15) << 8 | ((_payload_1 = payload[sectionStart + 11]) !== null && _payload_1 !== void 0 ? _payload_1 : 0);
|
|
622
|
+
var offset = sectionStart + 12 + programInfoLength;
|
|
623
|
+
while(offset + 5 <= sectionEnd - 4){
|
|
624
|
+
var _payload_offset, _payload_2, _payload_3, _payload_4, _payload_5;
|
|
625
|
+
var streamType = (_payload_offset = payload[offset]) !== null && _payload_offset !== void 0 ? _payload_offset : 0;
|
|
626
|
+
var elementaryPid = (((_payload_2 = payload[offset + 1]) !== null && _payload_2 !== void 0 ? _payload_2 : 0) & 31) << 8 | ((_payload_3 = payload[offset + 2]) !== null && _payload_3 !== void 0 ? _payload_3 : 0);
|
|
627
|
+
var esInfoLength = (((_payload_4 = payload[offset + 3]) !== null && _payload_4 !== void 0 ? _payload_4 : 0) & 15) << 8 | ((_payload_5 = payload[offset + 4]) !== null && _payload_5 !== void 0 ? _payload_5 : 0);
|
|
628
|
+
var descriptorStart = offset + 5;
|
|
629
|
+
var descriptorEnd = Math.min(descriptorStart + esInfoLength, sectionEnd - 4);
|
|
630
|
+
if (streamType === 134 || streamType === 6 && descriptorsIdentifyScte35(payload, descriptorStart, descriptorEnd)) {
|
|
631
|
+
tsScte35Pids.add(elementaryPid);
|
|
632
|
+
}
|
|
633
|
+
offset = descriptorStart + esInfoLength;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
function hasProcessedTsScte35Section(section, processedSections) {
|
|
637
|
+
var checksum = 0;
|
|
638
|
+
for(var i = 0; i < section.length; i++){
|
|
639
|
+
var _section_i;
|
|
640
|
+
checksum = checksum * 31 + ((_section_i = section[i]) !== null && _section_i !== void 0 ? _section_i : 0) >>> 0;
|
|
641
|
+
}
|
|
642
|
+
var key = "".concat(section.length, ":").concat(checksum);
|
|
643
|
+
if (processedSections.has(key)) {
|
|
644
|
+
return true;
|
|
645
|
+
}
|
|
646
|
+
processedSections.add(key);
|
|
647
|
+
if (processedSections.size > 200) {
|
|
648
|
+
var firstKey = processedSections.values().next().value;
|
|
649
|
+
if (firstKey) {
|
|
650
|
+
processedSections.delete(firstKey);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return false;
|
|
654
|
+
}
|
|
655
|
+
function addScte35SectionMarker(section, markers, processedSections) {
|
|
656
|
+
if (section[0] !== 252 || hasProcessedTsScte35Section(section, processedSections)) {
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
var marker = parseScte35Binary(section);
|
|
660
|
+
if (!marker) {
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
marker.raw = _object_spread_props(_object_spread({}, _type_of(marker.raw) === "object" && marker.raw ? marker.raw : {}), {
|
|
664
|
+
source: "ts-packet"
|
|
665
|
+
});
|
|
666
|
+
markers.push(marker);
|
|
667
|
+
}
|
|
668
|
+
function appendScte35Bytes(pid, bytes, assemblers, markers, processedSections) {
|
|
669
|
+
var assembler = assemblers.get(pid);
|
|
670
|
+
if (!assembler) {
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
for(var i = 0; i < bytes.length && assembler.bytes.length < assembler.expectedLength; i++){
|
|
674
|
+
var _bytes_i;
|
|
675
|
+
assembler.bytes.push((_bytes_i = bytes[i]) !== null && _bytes_i !== void 0 ? _bytes_i : 0);
|
|
676
|
+
}
|
|
677
|
+
if (assembler.bytes.length >= assembler.expectedLength) {
|
|
678
|
+
assemblers.delete(pid);
|
|
679
|
+
addScte35SectionMarker(new Uint8Array(assembler.bytes), markers, processedSections);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
function collectScte35SectionsFromPayload(pid, payload, payloadUnitStart, assemblers, markers, processedSections) {
|
|
683
|
+
if (payload.length === 0) {
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
var offset = 0;
|
|
687
|
+
if (payloadUnitStart) {
|
|
688
|
+
var _payload_;
|
|
689
|
+
var pointerField = (_payload_ = payload[0]) !== null && _payload_ !== void 0 ? _payload_ : 0;
|
|
690
|
+
var previousAssembler = assemblers.get(pid);
|
|
691
|
+
if (previousAssembler && pointerField > 0) {
|
|
692
|
+
appendScte35Bytes(pid, payload.subarray(1, Math.min(1 + pointerField, payload.length)), assemblers, markers, processedSections);
|
|
693
|
+
}
|
|
694
|
+
assemblers.delete(pid);
|
|
695
|
+
offset = 1 + pointerField;
|
|
696
|
+
} else {
|
|
697
|
+
appendScte35Bytes(pid, payload, assemblers, markers, processedSections);
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
while(offset + 3 <= payload.length){
|
|
701
|
+
var tableId = payload[offset];
|
|
702
|
+
if (tableId == null || tableId === 255) {
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
var sectionLength = getPsiSectionLength(payload, offset);
|
|
706
|
+
var totalLength = 3 + sectionLength;
|
|
707
|
+
if (sectionLength <= 0 || totalLength <= 3) {
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
if (offset + totalLength <= payload.length) {
|
|
711
|
+
addScte35SectionMarker(payload.subarray(offset, offset + totalLength), markers, processedSections);
|
|
712
|
+
offset += totalLength;
|
|
713
|
+
} else {
|
|
714
|
+
assemblers.set(pid, {
|
|
715
|
+
bytes: Array.from(payload.subarray(offset)),
|
|
716
|
+
expectedLength: totalLength
|
|
717
|
+
});
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
function parseScte35FromTsPackets(data, tsScte35Pids, pmtPids, processedSections) {
|
|
723
|
+
var packetInfo = detectTsPacketFormat(data);
|
|
724
|
+
if (!packetInfo) {
|
|
725
|
+
return [];
|
|
726
|
+
}
|
|
727
|
+
var markers = [];
|
|
728
|
+
var sectionAssemblers = /* @__PURE__ */ new Map();
|
|
729
|
+
for(var packetStart = packetInfo.offset; packetStart + packetInfo.packetSize <= data.length; packetStart += packetInfo.packetSize){
|
|
730
|
+
var tsStart = packetStart + packetInfo.tsPayloadOffset;
|
|
731
|
+
if (data[tsStart] !== 71) {
|
|
732
|
+
continue;
|
|
733
|
+
}
|
|
734
|
+
var secondByte = data[tsStart + 1];
|
|
735
|
+
var thirdByte = data[tsStart + 2];
|
|
736
|
+
var fourthByte = data[tsStart + 3];
|
|
737
|
+
if (secondByte == null || thirdByte == null || fourthByte == null || (secondByte & 128) !== 0) {
|
|
738
|
+
continue;
|
|
739
|
+
}
|
|
740
|
+
var payloadUnitStart = (secondByte & 64) !== 0;
|
|
741
|
+
var pid = (secondByte & 31) << 8 | thirdByte;
|
|
742
|
+
var adaptationFieldControl = fourthByte >> 4 & 3;
|
|
743
|
+
var hasPayload = adaptationFieldControl === 1 || adaptationFieldControl === 3;
|
|
744
|
+
if (!hasPayload) {
|
|
745
|
+
continue;
|
|
746
|
+
}
|
|
747
|
+
var payloadStart = tsStart + 4;
|
|
748
|
+
if (adaptationFieldControl === 3) {
|
|
749
|
+
var adaptationLength = data[payloadStart];
|
|
750
|
+
if (adaptationLength == null) {
|
|
751
|
+
continue;
|
|
752
|
+
}
|
|
753
|
+
payloadStart += 1 + adaptationLength;
|
|
754
|
+
}
|
|
755
|
+
var payloadEnd = Math.min(tsStart + 188, data.length);
|
|
756
|
+
if (payloadStart >= payloadEnd || payloadStart >= data.length) {
|
|
757
|
+
continue;
|
|
758
|
+
}
|
|
759
|
+
var payload = data.subarray(payloadStart, payloadEnd);
|
|
760
|
+
if (pid === 0) {
|
|
761
|
+
parsePatSection(payload, payloadUnitStart, pmtPids);
|
|
762
|
+
} else if (pmtPids.has(pid)) {
|
|
763
|
+
parsePmtSection(payload, payloadUnitStart, tsScte35Pids);
|
|
764
|
+
} else if (tsScte35Pids.has(pid)) {
|
|
765
|
+
collectScte35SectionsFromPayload(pid, payload, payloadUnitStart, sectionAssemblers, markers, processedSections);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
return markers;
|
|
769
|
+
}
|
|
770
|
+
var BitReader = /*#__PURE__*/ function() {
|
|
771
|
+
function BitReader(buf) {
|
|
772
|
+
_class_call_check(this, BitReader);
|
|
773
|
+
this.buf = buf;
|
|
774
|
+
this.bytePos = 0;
|
|
775
|
+
this.bitPos = 0;
|
|
776
|
+
}
|
|
777
|
+
_create_class(BitReader, [
|
|
778
|
+
{
|
|
779
|
+
key: "readBits",
|
|
780
|
+
value: function readBits(numBits) {
|
|
781
|
+
var result = 0;
|
|
782
|
+
while(numBits > 0){
|
|
783
|
+
if (this.bytePos >= this.buf.length) return result;
|
|
784
|
+
var remainingInByte = 8 - this.bitPos;
|
|
785
|
+
var toRead = Math.min(numBits, remainingInByte);
|
|
786
|
+
var currentByte = this.buf[this.bytePos];
|
|
787
|
+
var shift = remainingInByte - toRead;
|
|
788
|
+
var mask = (1 << toRead) - 1 & 255;
|
|
789
|
+
var bits = currentByte >> shift & mask;
|
|
790
|
+
result = result << toRead | bits;
|
|
791
|
+
this.bitPos += toRead;
|
|
792
|
+
if (this.bitPos >= 8) {
|
|
793
|
+
this.bitPos = 0;
|
|
794
|
+
this.bytePos += 1;
|
|
795
|
+
}
|
|
796
|
+
numBits -= toRead;
|
|
797
|
+
}
|
|
798
|
+
return result >>> 0;
|
|
799
|
+
}
|
|
800
|
+
},
|
|
801
|
+
{
|
|
802
|
+
key: "skipBits",
|
|
803
|
+
value: function skipBits(n) {
|
|
804
|
+
this.readBits(n);
|
|
805
|
+
}
|
|
806
|
+
},
|
|
807
|
+
{
|
|
808
|
+
key: "bytePosition",
|
|
809
|
+
get: function get() {
|
|
810
|
+
return this.bitPos === 0 ? this.bytePos : this.bytePos + 1;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
]);
|
|
814
|
+
return BitReader;
|
|
815
|
+
}();
|
|
816
|
+
function readSpliceTime(r, ptsAdjustmentTicks) {
|
|
817
|
+
var timeSpecifiedFlag = r.readBits(1) === 1;
|
|
818
|
+
if (!timeSpecifiedFlag) {
|
|
819
|
+
r.readBits(7);
|
|
820
|
+
return void 0;
|
|
821
|
+
}
|
|
822
|
+
r.readBits(6);
|
|
823
|
+
var high = r.readBits(1);
|
|
824
|
+
var low = r.readBits(32);
|
|
825
|
+
var ptsTicks = (high * 4294967296 + low + ptsAdjustmentTicks) % 8589934592;
|
|
826
|
+
return ptsTicks / 9e4;
|
|
827
|
+
}
|
|
828
|
+
function markerTypeFromSegmentationTypeId(segmentationTypeId) {
|
|
829
|
+
switch(segmentationTypeId){
|
|
830
|
+
case 16:
|
|
831
|
+
case 34:
|
|
832
|
+
case 48:
|
|
833
|
+
case 50:
|
|
834
|
+
case 52:
|
|
835
|
+
case 54:
|
|
836
|
+
return "start";
|
|
837
|
+
case 17:
|
|
838
|
+
case 35:
|
|
839
|
+
case 49:
|
|
840
|
+
case 51:
|
|
841
|
+
case 53:
|
|
842
|
+
case 55:
|
|
843
|
+
return "end";
|
|
844
|
+
default:
|
|
845
|
+
return void 0;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
function parseScte35SegmentationDescriptor(descriptor) {
|
|
849
|
+
var _descriptor_, _descriptor_1, _descriptor_2, _descriptor_3, _descriptor_4, _descriptor_5, _descriptor_6, _descriptor_7, _descriptor_8, _descriptor_9, _descriptor_offset, _descriptor_offset1;
|
|
850
|
+
if (descriptor.length < 11) {
|
|
851
|
+
return void 0;
|
|
852
|
+
}
|
|
853
|
+
var identifier = String.fromCharCode((_descriptor_ = descriptor[0]) !== null && _descriptor_ !== void 0 ? _descriptor_ : 0, (_descriptor_1 = descriptor[1]) !== null && _descriptor_1 !== void 0 ? _descriptor_1 : 0, (_descriptor_2 = descriptor[2]) !== null && _descriptor_2 !== void 0 ? _descriptor_2 : 0, (_descriptor_3 = descriptor[3]) !== null && _descriptor_3 !== void 0 ? _descriptor_3 : 0);
|
|
854
|
+
if (identifier !== "CUEI") {
|
|
855
|
+
return void 0;
|
|
856
|
+
}
|
|
857
|
+
var segmentationEventId = ((_descriptor_4 = descriptor[4]) !== null && _descriptor_4 !== void 0 ? _descriptor_4 : 0) * 16777216 + (((_descriptor_5 = descriptor[5]) !== null && _descriptor_5 !== void 0 ? _descriptor_5 : 0) << 16) + (((_descriptor_6 = descriptor[6]) !== null && _descriptor_6 !== void 0 ? _descriptor_6 : 0) << 8) + ((_descriptor_7 = descriptor[7]) !== null && _descriptor_7 !== void 0 ? _descriptor_7 : 0);
|
|
858
|
+
var cancelIndicator = (((_descriptor_8 = descriptor[8]) !== null && _descriptor_8 !== void 0 ? _descriptor_8 : 0) & 128) !== 0;
|
|
859
|
+
if (cancelIndicator) {
|
|
860
|
+
return void 0;
|
|
861
|
+
}
|
|
862
|
+
var flags = (_descriptor_9 = descriptor[9]) !== null && _descriptor_9 !== void 0 ? _descriptor_9 : 0;
|
|
863
|
+
var programSegmentationFlag = (flags & 128) !== 0;
|
|
864
|
+
var segmentationDurationFlag = (flags & 64) !== 0;
|
|
865
|
+
var offset = 10;
|
|
866
|
+
if (!programSegmentationFlag) {
|
|
867
|
+
var _descriptor_offset2;
|
|
868
|
+
var componentCount = (_descriptor_offset2 = descriptor[offset]) !== null && _descriptor_offset2 !== void 0 ? _descriptor_offset2 : 0;
|
|
869
|
+
offset += 1 + componentCount * 6;
|
|
870
|
+
if (offset > descriptor.length) {
|
|
871
|
+
return void 0;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
var durationSeconds = void 0;
|
|
875
|
+
if (segmentationDurationFlag) {
|
|
876
|
+
var _descriptor_offset3, _descriptor_10, _descriptor_11, _descriptor_12, _descriptor_13;
|
|
877
|
+
if (offset + 5 > descriptor.length) {
|
|
878
|
+
return void 0;
|
|
879
|
+
}
|
|
880
|
+
var durationTicks = ((_descriptor_offset3 = descriptor[offset]) !== null && _descriptor_offset3 !== void 0 ? _descriptor_offset3 : 0) * 4294967296 + ((_descriptor_10 = descriptor[offset + 1]) !== null && _descriptor_10 !== void 0 ? _descriptor_10 : 0) * 16777216 + (((_descriptor_11 = descriptor[offset + 2]) !== null && _descriptor_11 !== void 0 ? _descriptor_11 : 0) << 16) + (((_descriptor_12 = descriptor[offset + 3]) !== null && _descriptor_12 !== void 0 ? _descriptor_12 : 0) << 8) + ((_descriptor_13 = descriptor[offset + 4]) !== null && _descriptor_13 !== void 0 ? _descriptor_13 : 0);
|
|
881
|
+
durationSeconds = durationTicks / 9e4;
|
|
882
|
+
offset += 5;
|
|
883
|
+
}
|
|
884
|
+
if (offset + 2 > descriptor.length) {
|
|
885
|
+
return void 0;
|
|
886
|
+
}
|
|
887
|
+
offset += 1;
|
|
888
|
+
var segmentationUpidLength = (_descriptor_offset = descriptor[offset]) !== null && _descriptor_offset !== void 0 ? _descriptor_offset : 0;
|
|
889
|
+
offset += 1 + segmentationUpidLength;
|
|
890
|
+
if (offset >= descriptor.length) {
|
|
891
|
+
return void 0;
|
|
892
|
+
}
|
|
893
|
+
var segmentationTypeId = (_descriptor_offset1 = descriptor[offset]) !== null && _descriptor_offset1 !== void 0 ? _descriptor_offset1 : 0;
|
|
894
|
+
var markerType = markerTypeFromSegmentationTypeId(segmentationTypeId);
|
|
895
|
+
if (!markerType) {
|
|
896
|
+
return void 0;
|
|
897
|
+
}
|
|
898
|
+
return _object_spread_props(_object_spread({
|
|
899
|
+
type: markerType
|
|
900
|
+
}, durationSeconds !== void 0 ? {
|
|
901
|
+
durationSeconds: durationSeconds
|
|
902
|
+
} : {}), {
|
|
903
|
+
segmentationEventId: segmentationEventId
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
function parseScte35SegmentationDescriptors(data, offset) {
|
|
907
|
+
var _data_offset, _data_;
|
|
908
|
+
if (offset + 2 > data.length) {
|
|
909
|
+
return void 0;
|
|
910
|
+
}
|
|
911
|
+
var descriptorLoopLength = ((_data_offset = data[offset]) !== null && _data_offset !== void 0 ? _data_offset : 0) << 8 | ((_data_ = data[offset + 1]) !== null && _data_ !== void 0 ? _data_ : 0);
|
|
912
|
+
var descriptorOffset = offset + 2;
|
|
913
|
+
var descriptorEnd = Math.min(data.length, descriptorOffset + descriptorLoopLength);
|
|
914
|
+
while(descriptorOffset + 2 <= descriptorEnd){
|
|
915
|
+
var _data_descriptorOffset, _data_1;
|
|
916
|
+
var descriptorTag = (_data_descriptorOffset = data[descriptorOffset]) !== null && _data_descriptorOffset !== void 0 ? _data_descriptorOffset : 0;
|
|
917
|
+
var descriptorLength = (_data_1 = data[descriptorOffset + 1]) !== null && _data_1 !== void 0 ? _data_1 : 0;
|
|
918
|
+
var descriptorDataStart = descriptorOffset + 2;
|
|
919
|
+
var descriptorDataEnd = descriptorDataStart + descriptorLength;
|
|
920
|
+
if (descriptorDataEnd > descriptorEnd) {
|
|
921
|
+
return void 0;
|
|
922
|
+
}
|
|
923
|
+
if (descriptorTag === 2) {
|
|
924
|
+
var descriptorMarker = parseScte35SegmentationDescriptor(data.subarray(descriptorDataStart, descriptorDataEnd));
|
|
925
|
+
if (descriptorMarker) {
|
|
926
|
+
return descriptorMarker;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
descriptorOffset = descriptorDataEnd;
|
|
930
|
+
}
|
|
931
|
+
return void 0;
|
|
932
|
+
}
|
|
933
|
+
function parseScte35Binary(data) {
|
|
934
|
+
var r = new BitReader(data);
|
|
935
|
+
var tableId = r.readBits(8);
|
|
936
|
+
if (tableId !== 252) return void 0;
|
|
937
|
+
r.readBits(1);
|
|
938
|
+
r.readBits(1);
|
|
939
|
+
r.readBits(2);
|
|
940
|
+
var sectionLength = r.readBits(12);
|
|
941
|
+
if (sectionLength <= 0 || data.length < 3 + sectionLength) {
|
|
942
|
+
return void 0;
|
|
943
|
+
}
|
|
944
|
+
r.readBits(8);
|
|
945
|
+
r.readBits(1);
|
|
946
|
+
r.readBits(6);
|
|
947
|
+
var ptsAdjHigh = r.readBits(1);
|
|
948
|
+
var ptsAdjLow = r.readBits(32);
|
|
949
|
+
var ptsAdjustmentTicks = ptsAdjHigh * 4294967296 + ptsAdjLow;
|
|
950
|
+
r.readBits(8);
|
|
951
|
+
r.readBits(12);
|
|
952
|
+
var spliceCommandLength = r.readBits(12);
|
|
953
|
+
var spliceCommandType = r.readBits(8);
|
|
954
|
+
var markerType;
|
|
955
|
+
var durationSeconds = void 0;
|
|
956
|
+
var ptsSeconds = void 0;
|
|
957
|
+
var spliceEventId = void 0;
|
|
958
|
+
var commandBodyStart = r.bytePosition;
|
|
959
|
+
if (spliceCommandType === 5) {
|
|
960
|
+
spliceEventId = r.readBits(32);
|
|
961
|
+
var cancel = r.readBits(1) === 1;
|
|
962
|
+
r.readBits(7);
|
|
963
|
+
if (cancel) return void 0;
|
|
964
|
+
var outOfNetwork = r.readBits(1) === 1;
|
|
965
|
+
var programSpliceFlag = r.readBits(1) === 1;
|
|
966
|
+
var durationFlag = r.readBits(1) === 1;
|
|
967
|
+
var spliceImmediateFlag = r.readBits(1) === 1;
|
|
968
|
+
r.readBits(4);
|
|
969
|
+
markerType = outOfNetwork ? "start" : "end";
|
|
970
|
+
if (programSpliceFlag && !spliceImmediateFlag) {
|
|
971
|
+
ptsSeconds = readSpliceTime(r, ptsAdjustmentTicks);
|
|
972
|
+
} else if (!programSpliceFlag) {
|
|
973
|
+
var componentCount = r.readBits(8);
|
|
974
|
+
for(var i = 0; i < componentCount; i++){
|
|
975
|
+
r.readBits(8);
|
|
976
|
+
if (!spliceImmediateFlag) {
|
|
977
|
+
var componentPtsSeconds = readSpliceTime(r, ptsAdjustmentTicks);
|
|
978
|
+
if (ptsSeconds === void 0) {
|
|
979
|
+
ptsSeconds = componentPtsSeconds;
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
if (durationFlag) {
|
|
985
|
+
r.readBits(6);
|
|
986
|
+
r.readBits(1);
|
|
987
|
+
var high = r.readBits(1);
|
|
988
|
+
var low = r.readBits(32);
|
|
989
|
+
var durationTicks = high * 4294967296 + low;
|
|
990
|
+
durationSeconds = durationTicks / 9e4;
|
|
991
|
+
}
|
|
992
|
+
r.readBits(16);
|
|
993
|
+
r.readBits(8);
|
|
994
|
+
r.readBits(8);
|
|
995
|
+
} else if (spliceCommandType === 6) {
|
|
996
|
+
ptsSeconds = readSpliceTime(r, ptsAdjustmentTicks);
|
|
997
|
+
} else {
|
|
998
|
+
return void 0;
|
|
999
|
+
}
|
|
1000
|
+
var expectedDescriptorOffset = spliceCommandLength === 4095 ? r.bytePosition : commandBodyStart + spliceCommandLength;
|
|
1001
|
+
var descriptorMarker = parseScte35SegmentationDescriptors(data, expectedDescriptorOffset);
|
|
1002
|
+
if (descriptorMarker) {
|
|
1003
|
+
markerType = descriptorMarker.type;
|
|
1004
|
+
if (durationSeconds === void 0) {
|
|
1005
|
+
durationSeconds = descriptorMarker.durationSeconds;
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
if (!markerType) {
|
|
1009
|
+
return void 0;
|
|
1010
|
+
}
|
|
1011
|
+
var marker = _object_spread_props(_object_spread({
|
|
1012
|
+
type: markerType
|
|
1013
|
+
}, ptsSeconds !== void 0 ? {
|
|
1014
|
+
ptsSeconds: ptsSeconds
|
|
1015
|
+
} : {}, durationSeconds !== void 0 ? {
|
|
1016
|
+
durationSeconds: durationSeconds
|
|
1017
|
+
} : {}), {
|
|
1018
|
+
raw: _object_spread({
|
|
1019
|
+
splice_command_type: spliceCommandType
|
|
1020
|
+
}, spliceEventId !== void 0 ? {
|
|
1021
|
+
splice_event_id: spliceEventId
|
|
1022
|
+
} : {}, (descriptorMarker === null || descriptorMarker === void 0 ? void 0 : descriptorMarker.segmentationEventId) !== void 0 ? {
|
|
1023
|
+
segmentation_event_id: descriptorMarker.segmentationEventId
|
|
1024
|
+
} : {})
|
|
1025
|
+
});
|
|
1026
|
+
return marker;
|
|
1027
|
+
}
|
|
1028
|
+
// src/player/HlsEngine.ts
|
|
1029
|
+
var HlsEngine = /*#__PURE__*/ function() {
|
|
1030
|
+
function HlsEngine(config, video, cueManager, timing, callbacks) {
|
|
1031
|
+
_class_call_check(this, HlsEngine);
|
|
1032
|
+
this.isLiveStream = false;
|
|
1033
|
+
this.nativeHlsMode = false;
|
|
1034
|
+
this.videoSrcProtection = null;
|
|
1035
|
+
this.bufferedSegmentsCount = 0;
|
|
1036
|
+
this.shouldAutoplayAfterBuffering = false;
|
|
1037
|
+
this.hasInitialBufferCompleted = false;
|
|
1038
|
+
this.config = config;
|
|
1039
|
+
this.video = video;
|
|
1040
|
+
this.cueManager = cueManager;
|
|
1041
|
+
this.timing = timing;
|
|
1042
|
+
this.callbacks = callbacks;
|
|
1043
|
+
}
|
|
1044
|
+
_create_class(HlsEngine, [
|
|
1045
|
+
{
|
|
1046
|
+
key: "debug",
|
|
1047
|
+
get: function get() {
|
|
1048
|
+
return !!this.config.debugAdTiming;
|
|
1049
|
+
}
|
|
1050
|
+
},
|
|
1051
|
+
{
|
|
1052
|
+
key: "shouldUseNativeHls",
|
|
1053
|
+
value: function shouldUseNativeHls(getStreamType) {
|
|
1054
|
+
var streamType = getStreamType();
|
|
1055
|
+
if (streamType === "other") {
|
|
1056
|
+
return true;
|
|
1057
|
+
}
|
|
1058
|
+
var canNative = this.video.canPlayType("application/vnd.apple.mpegurl");
|
|
1059
|
+
return !!(this.config.allowNativeHls && canNative);
|
|
1060
|
+
}
|
|
1061
|
+
},
|
|
1062
|
+
{
|
|
1063
|
+
key: "setupNativeHls",
|
|
1064
|
+
value: function setupNativeHls() {
|
|
1065
|
+
return _async_to_generator(function() {
|
|
1066
|
+
var _this_config_isLiveStream, _this_config_lowLatencyMode, _this_video_play;
|
|
1067
|
+
return _ts_generator(this, function(_state) {
|
|
1068
|
+
switch(_state.label){
|
|
1069
|
+
case 0:
|
|
1070
|
+
this.nativeHlsMode = true;
|
|
1071
|
+
this.videoSrcProtection = this.config.src;
|
|
1072
|
+
this.video.src = this.config.src;
|
|
1073
|
+
this.isLiveStream = (_this_config_isLiveStream = this.config.isLiveStream) !== null && _this_config_isLiveStream !== void 0 ? _this_config_isLiveStream : (_this_config_lowLatencyMode = this.config.lowLatencyMode) !== null && _this_config_lowLatencyMode !== void 0 ? _this_config_lowLatencyMode : false;
|
|
1074
|
+
if (this.debug) {
|
|
1075
|
+
console.log("[StormcloudVideoPlayer] Using native HLS playback - VOD mode:", {
|
|
1076
|
+
isLive: this.isLiveStream,
|
|
1077
|
+
allowNativeHls: this.config.allowNativeHls,
|
|
1078
|
+
adBehavior: "vod (main video pauses during ads)"
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
if (!this.config.autoplay) return [
|
|
1082
|
+
3,
|
|
1083
|
+
2
|
|
1084
|
+
];
|
|
1085
|
+
return [
|
|
1086
|
+
4,
|
|
1087
|
+
(_this_video_play = this.video.play()) === null || _this_video_play === void 0 ? void 0 : _this_video_play.catch(function() {})
|
|
1088
|
+
];
|
|
1089
|
+
case 1:
|
|
1090
|
+
_state.sent();
|
|
1091
|
+
_state.label = 2;
|
|
1092
|
+
case 2:
|
|
1093
|
+
return [
|
|
1094
|
+
2
|
|
1095
|
+
];
|
|
1096
|
+
}
|
|
1097
|
+
});
|
|
1098
|
+
}).call(this);
|
|
1099
|
+
}
|
|
1100
|
+
},
|
|
1101
|
+
{
|
|
1102
|
+
key: "setupHls",
|
|
1103
|
+
value: function setupHls() {
|
|
1104
|
+
var _this = this;
|
|
1105
|
+
this.hls = new import_hls.default(_object_spread_props(_object_spread({
|
|
1106
|
+
enableWorker: true,
|
|
1107
|
+
backBufferLength: 30,
|
|
1108
|
+
liveDurationInfinity: true,
|
|
1109
|
+
lowLatencyMode: !!this.config.lowLatencyMode,
|
|
1110
|
+
maxLiveSyncPlaybackRate: this.config.lowLatencyMode ? 1.5 : 1
|
|
1111
|
+
}, this.config.lowLatencyMode ? {
|
|
1112
|
+
liveSyncDuration: 2
|
|
1113
|
+
} : {}), {
|
|
1114
|
+
maxBufferLength: 30,
|
|
1115
|
+
maxMaxBufferLength: 600,
|
|
1116
|
+
maxBufferSize: 60 * 1e3 * 1e3,
|
|
1117
|
+
maxBufferHole: 0.5,
|
|
1118
|
+
highBufferWatchdogPeriod: 2,
|
|
1119
|
+
nudgeOffset: 0.1,
|
|
1120
|
+
nudgeMaxRetry: 3,
|
|
1121
|
+
startPosition: -1
|
|
1122
|
+
}));
|
|
1123
|
+
this.hls.on(import_hls.default.Events.MEDIA_ATTACHED, function() {
|
|
1124
|
+
var _this_hls;
|
|
1125
|
+
(_this_hls = _this.hls) === null || _this_hls === void 0 ? void 0 : _this_hls.loadSource(_this.config.src);
|
|
1126
|
+
});
|
|
1127
|
+
this.hls.on(import_hls.default.Events.MANIFEST_PARSED, function(_, _data) {
|
|
1128
|
+
return _async_to_generator(function() {
|
|
1129
|
+
var _this_config_isLiveStream, _ref, _this_config_minSegmentsBeforePlay, _this_hls_levels, _this_hls, minSegments, _this_video_play;
|
|
1130
|
+
return _ts_generator(this, function(_state) {
|
|
1131
|
+
switch(_state.label){
|
|
1132
|
+
case 0:
|
|
1133
|
+
this.isLiveStream = (_this_config_isLiveStream = this.config.isLiveStream) !== null && _this_config_isLiveStream !== void 0 ? _this_config_isLiveStream : (_ref = (_this_hls = this.hls) === null || _this_hls === void 0 ? void 0 : (_this_hls_levels = _this_hls.levels) === null || _this_hls_levels === void 0 ? void 0 : _this_hls_levels.some(function(level) {
|
|
1134
|
+
var _level_details, _level_details1;
|
|
1135
|
+
return (level === null || level === void 0 ? void 0 : (_level_details = level.details) === null || _level_details === void 0 ? void 0 : _level_details.live) === true || (level === null || level === void 0 ? void 0 : (_level_details1 = level.details) === null || _level_details1 === void 0 ? void 0 : _level_details1.type) === "LIVE";
|
|
1136
|
+
})) !== null && _ref !== void 0 ? _ref : false;
|
|
1137
|
+
return [
|
|
1138
|
+
4,
|
|
1139
|
+
this.callbacks.onManifestParsed(this.isLiveStream)
|
|
1140
|
+
];
|
|
1141
|
+
case 1:
|
|
1142
|
+
_state.sent();
|
|
1143
|
+
this.bufferedSegmentsCount = 0;
|
|
1144
|
+
this.hasInitialBufferCompleted = false;
|
|
1145
|
+
this.shouldAutoplayAfterBuffering = !!this.config.autoplay;
|
|
1146
|
+
minSegments = (_this_config_minSegmentsBeforePlay = this.config.minSegmentsBeforePlay) !== null && _this_config_minSegmentsBeforePlay !== void 0 ? _this_config_minSegmentsBeforePlay : 2;
|
|
1147
|
+
if (this.debug) {
|
|
1148
|
+
console.log("[StormcloudVideoPlayer] Waiting for", minSegments, "segments to buffer before playback");
|
|
1149
|
+
}
|
|
1150
|
+
if (!(minSegments === 0 || !this.config.autoplay)) return [
|
|
1151
|
+
3,
|
|
1152
|
+
3
|
|
1153
|
+
];
|
|
1154
|
+
this.hasInitialBufferCompleted = true;
|
|
1155
|
+
if (!this.config.autoplay) return [
|
|
1156
|
+
3,
|
|
1157
|
+
3
|
|
1158
|
+
];
|
|
1159
|
+
return [
|
|
1160
|
+
4,
|
|
1161
|
+
(_this_video_play = this.video.play()) === null || _this_video_play === void 0 ? void 0 : _this_video_play.catch(function() {})
|
|
1162
|
+
];
|
|
1163
|
+
case 2:
|
|
1164
|
+
_state.sent();
|
|
1165
|
+
_state.label = 3;
|
|
1166
|
+
case 3:
|
|
1167
|
+
return [
|
|
1168
|
+
2
|
|
1169
|
+
];
|
|
1170
|
+
}
|
|
1171
|
+
});
|
|
1172
|
+
}).call(_this);
|
|
1173
|
+
});
|
|
1174
|
+
this.hls.on(import_hls.default.Events.LEVEL_LOADED, function(_evt, data) {
|
|
1175
|
+
if (_this.callbacks.isInAdBreak() || _this.callbacks.hasPendingAdBreak()) {
|
|
1176
|
+
return;
|
|
1177
|
+
}
|
|
1178
|
+
var details = data === null || data === void 0 ? void 0 : data.details;
|
|
1179
|
+
if (!details || !details.fragments || details.fragments.length === 0) {
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
var fragmentsToScan = Math.min(5, details.fragments.length);
|
|
1183
|
+
for(var i = 0; i < fragmentsToScan; i++){
|
|
1184
|
+
var frag = details.fragments[i];
|
|
1185
|
+
var tagList = frag === null || frag === void 0 ? void 0 : frag.tagList;
|
|
1186
|
+
if (!Array.isArray(tagList)) continue;
|
|
1187
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1188
|
+
try {
|
|
1189
|
+
for(var _iterator = tagList[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1190
|
+
var entry = _step.value;
|
|
1191
|
+
var tag = "";
|
|
1192
|
+
var value = "";
|
|
1193
|
+
if (Array.isArray(entry)) {
|
|
1194
|
+
var _entry_, _entry_1;
|
|
1195
|
+
tag = String((_entry_ = entry[0]) !== null && _entry_ !== void 0 ? _entry_ : "");
|
|
1196
|
+
value = String((_entry_1 = entry[1]) !== null && _entry_1 !== void 0 ? _entry_1 : "");
|
|
1197
|
+
} else if (typeof entry === "string") {
|
|
1198
|
+
var idx = entry.indexOf(":");
|
|
1199
|
+
if (idx >= 0) {
|
|
1200
|
+
tag = entry.substring(0, idx);
|
|
1201
|
+
value = entry.substring(idx + 1);
|
|
1202
|
+
} else {
|
|
1203
|
+
tag = entry;
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
if (!tag) continue;
|
|
1207
|
+
if (tag.includes("EXT-X-CUE-OUT") || tag.includes("EXT-X-DATERANGE")) {
|
|
1208
|
+
var attrs = tag.includes("EXT-X-DATERANGE") ? parseAttributeList(value) : {};
|
|
1209
|
+
var hasScteOut = tag.includes("EXT-X-CUE-OUT") || "SCTE35-OUT" in attrs || attrs["SCTE35-OUT"] !== void 0;
|
|
1210
|
+
if (hasScteOut) {
|
|
1211
|
+
var durationSeconds = parseCueOutDuration(value);
|
|
1212
|
+
var marker = _object_spread_props(_object_spread({
|
|
1213
|
+
type: "start"
|
|
1214
|
+
}, durationSeconds !== void 0 ? {
|
|
1215
|
+
durationSeconds: durationSeconds
|
|
1216
|
+
} : {}), {
|
|
1217
|
+
raw: {
|
|
1218
|
+
tag: tag,
|
|
1219
|
+
value: value,
|
|
1220
|
+
earlyDetection: true
|
|
1221
|
+
}
|
|
1222
|
+
});
|
|
1223
|
+
if (_this.debug) {
|
|
1224
|
+
console.log("[StormcloudVideoPlayer] EARLY SCTE-35 DETECTION: Ad break marker found in fragment", i, "- starting pre-fetch (NOT playing yet)");
|
|
1225
|
+
}
|
|
1226
|
+
_this.callbacks.onScte35Cue(marker, _object_spread({}, _this.cueManager.createScte35CueContext("manifest", "early", frag)));
|
|
1227
|
+
return;
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
} catch (err) {
|
|
1232
|
+
_didIteratorError = true;
|
|
1233
|
+
_iteratorError = err;
|
|
1234
|
+
} finally{
|
|
1235
|
+
try {
|
|
1236
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1237
|
+
_iterator.return();
|
|
1238
|
+
}
|
|
1239
|
+
} finally{
|
|
1240
|
+
if (_didIteratorError) {
|
|
1241
|
+
throw _iteratorError;
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
});
|
|
1247
|
+
this.hls.on(import_hls.default.Events.FRAG_BUFFERED, function(_evt, _data) {
|
|
1248
|
+
return _async_to_generator(function() {
|
|
1249
|
+
var _this, _this_config_minSegmentsBeforePlay, minSegments, _this_video_play;
|
|
1250
|
+
return _ts_generator(this, function(_state) {
|
|
1251
|
+
switch(_state.label){
|
|
1252
|
+
case 0:
|
|
1253
|
+
_this = this;
|
|
1254
|
+
if (this.hasInitialBufferCompleted) {
|
|
1255
|
+
return [
|
|
1256
|
+
2
|
|
1257
|
+
];
|
|
1258
|
+
}
|
|
1259
|
+
this.bufferedSegmentsCount++;
|
|
1260
|
+
minSegments = (_this_config_minSegmentsBeforePlay = this.config.minSegmentsBeforePlay) !== null && _this_config_minSegmentsBeforePlay !== void 0 ? _this_config_minSegmentsBeforePlay : 2;
|
|
1261
|
+
if (this.debug) {
|
|
1262
|
+
console.log("[StormcloudVideoPlayer] Buffered segment ".concat(this.bufferedSegmentsCount, "/").concat(minSegments));
|
|
1263
|
+
}
|
|
1264
|
+
if (!(this.bufferedSegmentsCount >= minSegments)) return [
|
|
1265
|
+
3,
|
|
1266
|
+
2
|
|
1267
|
+
];
|
|
1268
|
+
this.hasInitialBufferCompleted = true;
|
|
1269
|
+
if (!this.shouldAutoplayAfterBuffering) return [
|
|
1270
|
+
3,
|
|
1271
|
+
2
|
|
1272
|
+
];
|
|
1273
|
+
if (this.debug) {
|
|
1274
|
+
console.log("[StormcloudVideoPlayer] Initial buffer complete (".concat(this.bufferedSegmentsCount, " segments). Starting playback."));
|
|
1275
|
+
}
|
|
1276
|
+
return [
|
|
1277
|
+
4,
|
|
1278
|
+
(_this_video_play = this.video.play()) === null || _this_video_play === void 0 ? void 0 : _this_video_play.catch(function(err) {
|
|
1279
|
+
if (_this.debug) {
|
|
1280
|
+
console.warn("[StormcloudVideoPlayer] Autoplay failed:", err);
|
|
1281
|
+
}
|
|
1282
|
+
})
|
|
1283
|
+
];
|
|
1284
|
+
case 1:
|
|
1285
|
+
_state.sent();
|
|
1286
|
+
_state.label = 2;
|
|
1287
|
+
case 2:
|
|
1288
|
+
return [
|
|
1289
|
+
2
|
|
1290
|
+
];
|
|
1291
|
+
}
|
|
1292
|
+
});
|
|
1293
|
+
}).call(_this);
|
|
1294
|
+
});
|
|
1295
|
+
this.hls.on(import_hls.default.Events.FRAG_PARSING_METADATA, function(_evt, data) {
|
|
1296
|
+
var id3Tags = ((data === null || data === void 0 ? void 0 : data.samples) || []).map(function(s) {
|
|
1297
|
+
return {
|
|
1298
|
+
key: "ID3",
|
|
1299
|
+
value: s === null || s === void 0 ? void 0 : s.data,
|
|
1300
|
+
ptsSeconds: s === null || s === void 0 ? void 0 : s.pts
|
|
1301
|
+
};
|
|
1302
|
+
});
|
|
1303
|
+
id3Tags.forEach(function(tag) {
|
|
1304
|
+
return _this.onId3Tag(tag);
|
|
1305
|
+
});
|
|
1306
|
+
});
|
|
1307
|
+
this.hls.on(import_hls.default.Events.FRAG_LOADED, function(_evt, data) {
|
|
1308
|
+
var _data_frag;
|
|
1309
|
+
_this.processFragmentScte35Payload(data === null || data === void 0 ? void 0 : data.payload, typeof (data === null || data === void 0 ? void 0 : (_data_frag = data.frag) === null || _data_frag === void 0 ? void 0 : _data_frag.sn) === "number" ? data.frag.sn : void 0, getFragmentStartSeconds(data === null || data === void 0 ? void 0 : data.frag));
|
|
1310
|
+
});
|
|
1311
|
+
this.hls.on(import_hls.default.Events.FRAG_DECRYPTED, function(_evt, data) {
|
|
1312
|
+
var _data_frag;
|
|
1313
|
+
_this.processFragmentScte35Payload(data === null || data === void 0 ? void 0 : data.payload, typeof (data === null || data === void 0 ? void 0 : (_data_frag = data.frag) === null || _data_frag === void 0 ? void 0 : _data_frag.sn) === "number" ? data.frag.sn : void 0, getFragmentStartSeconds(data === null || data === void 0 ? void 0 : data.frag));
|
|
1314
|
+
});
|
|
1315
|
+
this.hls.on(import_hls.default.Events.FRAG_CHANGED, function(_evt, data) {
|
|
1316
|
+
var frag = data === null || data === void 0 ? void 0 : data.frag;
|
|
1317
|
+
var tagList = frag === null || frag === void 0 ? void 0 : frag.tagList;
|
|
1318
|
+
if (!Array.isArray(tagList)) {
|
|
1319
|
+
_this.callbacks.activatePendingCuesForFragment(frag);
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
1323
|
+
try {
|
|
1324
|
+
for(var _iterator = tagList[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
1325
|
+
var entry = _step.value;
|
|
1326
|
+
var tag = "";
|
|
1327
|
+
var value = "";
|
|
1328
|
+
if (Array.isArray(entry)) {
|
|
1329
|
+
var _entry_, _entry_1;
|
|
1330
|
+
tag = String((_entry_ = entry[0]) !== null && _entry_ !== void 0 ? _entry_ : "");
|
|
1331
|
+
value = String((_entry_1 = entry[1]) !== null && _entry_1 !== void 0 ? _entry_1 : "");
|
|
1332
|
+
} else if (typeof entry === "string") {
|
|
1333
|
+
var idx = entry.indexOf(":");
|
|
1334
|
+
if (idx >= 0) {
|
|
1335
|
+
tag = entry.substring(0, idx);
|
|
1336
|
+
value = entry.substring(idx + 1);
|
|
1337
|
+
} else {
|
|
1338
|
+
tag = entry;
|
|
1339
|
+
value = "";
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
if (!tag) continue;
|
|
1343
|
+
if (tag.includes("EXT-X-CUE-OUT-CONT")) {
|
|
1344
|
+
var prog = parseCueOutCont(value);
|
|
1345
|
+
var marker = _object_spread_props(_object_spread({
|
|
1346
|
+
type: "progress"
|
|
1347
|
+
}, (prog === null || prog === void 0 ? void 0 : prog.duration) !== void 0 ? {
|
|
1348
|
+
durationSeconds: prog.duration
|
|
1349
|
+
} : {}, (prog === null || prog === void 0 ? void 0 : prog.elapsed) !== void 0 ? {
|
|
1350
|
+
ptsSeconds: prog.elapsed
|
|
1351
|
+
} : {}), {
|
|
1352
|
+
raw: {
|
|
1353
|
+
tag: tag,
|
|
1354
|
+
value: value
|
|
1355
|
+
}
|
|
1356
|
+
});
|
|
1357
|
+
_this.callbacks.onScte35Cue(marker, _object_spread({}, _this.cueManager.createScte35CueContext("manifest", "playback", frag)));
|
|
1358
|
+
} else if (tag.includes("EXT-X-CUE-OUT")) {
|
|
1359
|
+
var durationSeconds = parseCueOutDuration(value);
|
|
1360
|
+
var marker1 = _object_spread_props(_object_spread({
|
|
1361
|
+
type: "start"
|
|
1362
|
+
}, durationSeconds !== void 0 ? {
|
|
1363
|
+
durationSeconds: durationSeconds
|
|
1364
|
+
} : {}), {
|
|
1365
|
+
raw: {
|
|
1366
|
+
tag: tag,
|
|
1367
|
+
value: value
|
|
1368
|
+
}
|
|
1369
|
+
});
|
|
1370
|
+
_this.callbacks.onScte35Cue(marker1, _object_spread({}, _this.cueManager.createScte35CueContext("manifest", "playback", frag)));
|
|
1371
|
+
} else if (tag.includes("EXT-X-CUE-IN")) {
|
|
1372
|
+
_this.callbacks.onScte35Cue({
|
|
1373
|
+
type: "end",
|
|
1374
|
+
raw: {
|
|
1375
|
+
tag: tag,
|
|
1376
|
+
value: value
|
|
1377
|
+
}
|
|
1378
|
+
}, _object_spread({}, _this.cueManager.createScte35CueContext("manifest", "playback", frag)));
|
|
1379
|
+
} else if (tag.includes("EXT-X-DATERANGE")) {
|
|
1380
|
+
var _attrs_CLASS;
|
|
1381
|
+
var attrs = parseAttributeList(value);
|
|
1382
|
+
var hasScteOut = "SCTE35-OUT" in attrs || attrs["SCTE35-OUT"] !== void 0;
|
|
1383
|
+
var hasScteIn = "SCTE35-IN" in attrs || attrs["SCTE35-IN"] !== void 0;
|
|
1384
|
+
var klass = String((_attrs_CLASS = attrs["CLASS"]) !== null && _attrs_CLASS !== void 0 ? _attrs_CLASS : "");
|
|
1385
|
+
var duration = toNumber(attrs["DURATION"]);
|
|
1386
|
+
if (hasScteOut || /com\.apple\.hls\.cue/i.test(klass)) {
|
|
1387
|
+
var marker2 = _object_spread_props(_object_spread({
|
|
1388
|
+
type: "start"
|
|
1389
|
+
}, duration !== void 0 ? {
|
|
1390
|
+
durationSeconds: duration
|
|
1391
|
+
} : {}), {
|
|
1392
|
+
raw: {
|
|
1393
|
+
tag: tag,
|
|
1394
|
+
value: value,
|
|
1395
|
+
attrs: attrs
|
|
1396
|
+
}
|
|
1397
|
+
});
|
|
1398
|
+
_this.callbacks.onScte35Cue(marker2, _object_spread({}, _this.cueManager.createScte35CueContext("manifest", "playback", frag)));
|
|
1399
|
+
}
|
|
1400
|
+
if (hasScteIn) {
|
|
1401
|
+
_this.callbacks.onScte35Cue({
|
|
1402
|
+
type: "end",
|
|
1403
|
+
raw: {
|
|
1404
|
+
tag: tag,
|
|
1405
|
+
value: value,
|
|
1406
|
+
attrs: attrs
|
|
1407
|
+
}
|
|
1408
|
+
}, _object_spread({}, _this.cueManager.createScte35CueContext("manifest", "playback", frag)));
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
} catch (err) {
|
|
1413
|
+
_didIteratorError = true;
|
|
1414
|
+
_iteratorError = err;
|
|
1415
|
+
} finally{
|
|
1416
|
+
try {
|
|
1417
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
1418
|
+
_iterator.return();
|
|
1419
|
+
}
|
|
1420
|
+
} finally{
|
|
1421
|
+
if (_didIteratorError) {
|
|
1422
|
+
throw _iteratorError;
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
_this.callbacks.activatePendingCuesForFragment(frag);
|
|
1427
|
+
});
|
|
1428
|
+
this.hls.on(import_hls.default.Events.ERROR, function(_evt, data) {
|
|
1429
|
+
if (data === null || data === void 0 ? void 0 : data.fatal) {
|
|
1430
|
+
switch(data.type){
|
|
1431
|
+
case import_hls.default.ErrorTypes.NETWORK_ERROR:
|
|
1432
|
+
var _this_hls;
|
|
1433
|
+
(_this_hls = _this.hls) === null || _this_hls === void 0 ? void 0 : _this_hls.startLoad();
|
|
1434
|
+
break;
|
|
1435
|
+
case import_hls.default.ErrorTypes.MEDIA_ERROR:
|
|
1436
|
+
var _this_hls1;
|
|
1437
|
+
(_this_hls1 = _this.hls) === null || _this_hls1 === void 0 ? void 0 : _this_hls1.recoverMediaError();
|
|
1438
|
+
break;
|
|
1439
|
+
default:
|
|
1440
|
+
_this.callbacks.onFatalDestroy();
|
|
1441
|
+
break;
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
});
|
|
1445
|
+
this.hls.attachMedia(this.video);
|
|
1446
|
+
}
|
|
1447
|
+
},
|
|
1448
|
+
{
|
|
1449
|
+
key: "onId3Tag",
|
|
1450
|
+
value: function onId3Tag(tag) {
|
|
1451
|
+
if (typeof tag.ptsSeconds === "number") {
|
|
1452
|
+
this.timing.updatePtsDrift(tag.ptsSeconds);
|
|
1453
|
+
}
|
|
1454
|
+
var marker = parseScte35FromId3(tag);
|
|
1455
|
+
if (marker) {
|
|
1456
|
+
this.callbacks.onScte35Cue(marker, {
|
|
1457
|
+
source: "id3",
|
|
1458
|
+
readiness: "playback"
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
},
|
|
1463
|
+
{
|
|
1464
|
+
key: "processFragmentScte35Payload",
|
|
1465
|
+
value: function processFragmentScte35Payload(payloadData, fragmentSn, fragmentStartSeconds) {
|
|
1466
|
+
var _this = this;
|
|
1467
|
+
var payload = normalizeFragmentPayload(payloadData);
|
|
1468
|
+
if (!payload) {
|
|
1469
|
+
return;
|
|
1470
|
+
}
|
|
1471
|
+
var markers = parseScte35FromTsPackets(payload, this.cueManager.tsScte35Pids, this.cueManager.pmtPids, this.cueManager.processedTsScte35Sections);
|
|
1472
|
+
markers.forEach(function(marker) {
|
|
1473
|
+
var context = {
|
|
1474
|
+
source: "ts",
|
|
1475
|
+
readiness: "early"
|
|
1476
|
+
};
|
|
1477
|
+
if (fragmentSn !== void 0) {
|
|
1478
|
+
context.fragmentSn = fragmentSn;
|
|
1479
|
+
}
|
|
1480
|
+
if (fragmentStartSeconds !== void 0) {
|
|
1481
|
+
context.fragmentStartSeconds = fragmentStartSeconds;
|
|
1482
|
+
}
|
|
1483
|
+
_this.callbacks.onScte35Cue(marker, context);
|
|
1484
|
+
});
|
|
1485
|
+
}
|
|
1486
|
+
},
|
|
1487
|
+
{
|
|
1488
|
+
key: "destroy",
|
|
1489
|
+
value: function destroy() {
|
|
1490
|
+
var _this_hls;
|
|
1491
|
+
(_this_hls = this.hls) === null || _this_hls === void 0 ? void 0 : _this_hls.destroy();
|
|
1492
|
+
this.hls = void 0;
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
]);
|
|
1496
|
+
return HlsEngine;
|
|
1497
|
+
}();
|
|
1498
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1499
|
+
0 && (module.exports = {
|
|
1500
|
+
HlsEngine: HlsEngine
|
|
1501
|
+
});
|
|
1502
|
+
//# sourceMappingURL=HlsEngine.cjs.map
|