@volcengine/veplayer-plugin 2.4.0-rc.3 → 2.4.0-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.development.js +133 -43
- package/esm/index.production.js +3 -3
- package/esm/veplayer.plugin.abr.development.js +14994 -0
- package/esm/veplayer.plugin.abr.production.js +2 -0
- package/esm/veplayer.plugin.drm.development.js +1580 -0
- package/esm/veplayer.plugin.drm.production.js +2 -0
- package/esm/veplayer.plugin.flv.development.js +21 -7
- package/esm/veplayer.plugin.flv.production.js +1 -1
- package/esm/veplayer.plugin.hls.development.js +104 -28
- package/esm/veplayer.plugin.hls.production.js +1 -1
- package/esm/veplayer.plugin.mp4.development.js +38042 -0
- package/esm/veplayer.plugin.mp4.production.js +2 -0
- package/esm/veplayer.plugin.rtm.development.js +5790 -0
- package/esm/veplayer.plugin.rtm.production.js +2 -0
- package/esm/veplayer.plugin.shaka.development.js +15976 -0
- package/esm/veplayer.plugin.shaka.production.js +20 -0
- package/esm/veplayer.plugin.time.shift.development.css +63 -0
- package/esm/veplayer.plugin.time.shift.development.js +339 -0
- package/esm/veplayer.plugin.time.shift.production.css +1 -0
- package/esm/veplayer.plugin.time.shift.production.js +2 -0
- package/esm/veplayer.plugin.xgvideo.development.js +19097 -0
- package/esm/veplayer.plugin.xgvideo.production.js +2 -0
- package/package.json +1 -1
- package/umd/veplayer.plugin.abr.development.js +14996 -0
- package/umd/veplayer.plugin.abr.production.js +1 -0
- package/umd/veplayer.plugin.drm.development.js +1582 -0
- package/umd/veplayer.plugin.drm.production.js +1 -0
- package/umd/veplayer.plugin.flv.development.js +21 -7
- package/umd/veplayer.plugin.flv.production.js +1 -1
- package/umd/veplayer.plugin.hls.development.js +104 -28
- package/umd/veplayer.plugin.hls.production.js +1 -1
- package/umd/veplayer.plugin.mp4.development.js +38046 -0
- package/umd/veplayer.plugin.mp4.production.js +1 -0
- package/umd/veplayer.plugin.rtm.development.js +5792 -0
- package/umd/veplayer.plugin.rtm.production.js +1 -0
- package/umd/veplayer.plugin.shaka.development.js +15980 -0
- package/umd/veplayer.plugin.shaka.production.js +1 -0
- package/umd/veplayer.plugin.time.shift.development.css +63 -0
- package/umd/veplayer.plugin.time.shift.development.js +342 -0
- package/umd/veplayer.plugin.time.shift.production.css +1 -0
- package/umd/veplayer.plugin.time.shift.production.js +1 -0
- package/umd/veplayer.plugin.xgvideo.development.js +19099 -0
- package/umd/veplayer.plugin.xgvideo.production.js +1 -0
|
@@ -0,0 +1,1580 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) {
|
|
2
|
+
var keys = Object.keys(object);
|
|
3
|
+
if (Object.getOwnPropertySymbols) {
|
|
4
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
5
|
+
enumerableOnly && (symbols = symbols.filter(function(sym) {
|
|
6
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
7
|
+
})), keys.push.apply(keys, symbols);
|
|
8
|
+
}
|
|
9
|
+
return keys;
|
|
10
|
+
}
|
|
11
|
+
function _objectSpread2(target) {
|
|
12
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
13
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
14
|
+
i % 2 ? ownKeys(Object(source), true).forEach(function(key) {
|
|
15
|
+
_defineProperty(target, key, source[key]);
|
|
16
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
|
|
17
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return target;
|
|
21
|
+
}
|
|
22
|
+
function _typeof(obj) {
|
|
23
|
+
"@babel/helpers - typeof";
|
|
24
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
|
|
25
|
+
return typeof obj2;
|
|
26
|
+
} : function(obj2) {
|
|
27
|
+
return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
|
|
28
|
+
}, _typeof(obj);
|
|
29
|
+
}
|
|
30
|
+
function _classCallCheck(instance, Constructor) {
|
|
31
|
+
if (!(instance instanceof Constructor)) {
|
|
32
|
+
throw new TypeError("Cannot call a class as a function");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function _defineProperties(target, props) {
|
|
36
|
+
for (var i = 0; i < props.length; i++) {
|
|
37
|
+
var descriptor = props[i];
|
|
38
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
39
|
+
descriptor.configurable = true;
|
|
40
|
+
if ("value" in descriptor)
|
|
41
|
+
descriptor.writable = true;
|
|
42
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
46
|
+
if (protoProps)
|
|
47
|
+
_defineProperties(Constructor.prototype, protoProps);
|
|
48
|
+
if (staticProps)
|
|
49
|
+
_defineProperties(Constructor, staticProps);
|
|
50
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
51
|
+
writable: false
|
|
52
|
+
});
|
|
53
|
+
return Constructor;
|
|
54
|
+
}
|
|
55
|
+
function _defineProperty(obj, key, value) {
|
|
56
|
+
key = _toPropertyKey(key);
|
|
57
|
+
if (key in obj) {
|
|
58
|
+
Object.defineProperty(obj, key, {
|
|
59
|
+
value,
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: true,
|
|
62
|
+
writable: true
|
|
63
|
+
});
|
|
64
|
+
} else {
|
|
65
|
+
obj[key] = value;
|
|
66
|
+
}
|
|
67
|
+
return obj;
|
|
68
|
+
}
|
|
69
|
+
function _toConsumableArray(arr) {
|
|
70
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
71
|
+
}
|
|
72
|
+
function _arrayWithoutHoles(arr) {
|
|
73
|
+
if (Array.isArray(arr))
|
|
74
|
+
return _arrayLikeToArray(arr);
|
|
75
|
+
}
|
|
76
|
+
function _iterableToArray(iter) {
|
|
77
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null)
|
|
78
|
+
return Array.from(iter);
|
|
79
|
+
}
|
|
80
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
81
|
+
if (!o)
|
|
82
|
+
return;
|
|
83
|
+
if (typeof o === "string")
|
|
84
|
+
return _arrayLikeToArray(o, minLen);
|
|
85
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
86
|
+
if (n === "Object" && o.constructor)
|
|
87
|
+
n = o.constructor.name;
|
|
88
|
+
if (n === "Map" || n === "Set")
|
|
89
|
+
return Array.from(o);
|
|
90
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
91
|
+
return _arrayLikeToArray(o, minLen);
|
|
92
|
+
}
|
|
93
|
+
function _arrayLikeToArray(arr, len) {
|
|
94
|
+
if (len == null || len > arr.length)
|
|
95
|
+
len = arr.length;
|
|
96
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
97
|
+
arr2[i] = arr[i];
|
|
98
|
+
return arr2;
|
|
99
|
+
}
|
|
100
|
+
function _nonIterableSpread() {
|
|
101
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
102
|
+
}
|
|
103
|
+
function _toPrimitive(input, hint) {
|
|
104
|
+
if (typeof input !== "object" || input === null)
|
|
105
|
+
return input;
|
|
106
|
+
var prim = input[Symbol.toPrimitive];
|
|
107
|
+
if (prim !== void 0) {
|
|
108
|
+
var res = prim.call(input, hint || "default");
|
|
109
|
+
if (typeof res !== "object")
|
|
110
|
+
return res;
|
|
111
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
112
|
+
}
|
|
113
|
+
return (hint === "string" ? String : Number)(input);
|
|
114
|
+
}
|
|
115
|
+
function _toPropertyKey(arg) {
|
|
116
|
+
var key = _toPrimitive(arg, "string");
|
|
117
|
+
return typeof key === "symbol" ? key : String(key);
|
|
118
|
+
}
|
|
119
|
+
var XG_DEBUG_OPEN = typeof window !== "undefined" && window.location && window.location.href.indexOf("xgplayerdebugger=1") > -1;
|
|
120
|
+
var STYLE = {
|
|
121
|
+
info: "color: #525252; background-color: #90ee90;",
|
|
122
|
+
error: "color: #525252; background-color: red;",
|
|
123
|
+
warn: "color: #525252; background-color: yellow; "
|
|
124
|
+
};
|
|
125
|
+
var XGTAG = "%c[xgplayer]";
|
|
126
|
+
var XG_DEBUG = {
|
|
127
|
+
config: {
|
|
128
|
+
debug: XG_DEBUG_OPEN ? 3 : 0
|
|
129
|
+
},
|
|
130
|
+
logInfo: function logInfo(message) {
|
|
131
|
+
var _console;
|
|
132
|
+
for (var _len = arguments.length, optionalParams = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
133
|
+
optionalParams[_key - 1] = arguments[_key];
|
|
134
|
+
}
|
|
135
|
+
this.config.debug >= 3 && (_console = console).log.apply(_console, [XGTAG, STYLE.info, message].concat(optionalParams));
|
|
136
|
+
},
|
|
137
|
+
logWarn: function logWarn(message) {
|
|
138
|
+
var _console2;
|
|
139
|
+
for (var _len2 = arguments.length, optionalParams = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
140
|
+
optionalParams[_key2 - 1] = arguments[_key2];
|
|
141
|
+
}
|
|
142
|
+
this.config.debug >= 1 && (_console2 = console).warn.apply(_console2, [XGTAG, STYLE.warn, message].concat(optionalParams));
|
|
143
|
+
},
|
|
144
|
+
logError: function logError(message) {
|
|
145
|
+
var _console3;
|
|
146
|
+
if (this.config.debug < 1) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
var _fun = this.config.debug >= 2 ? "trace" : "error";
|
|
150
|
+
for (var _len3 = arguments.length, optionalParams = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
151
|
+
optionalParams[_key3 - 1] = arguments[_key3];
|
|
152
|
+
}
|
|
153
|
+
(_console3 = console)[_fun].apply(_console3, [XGTAG, STYLE.error, message].concat(optionalParams));
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
var XgplayerTimeRange = /* @__PURE__ */ function() {
|
|
157
|
+
function XgplayerTimeRange2(bufferedList) {
|
|
158
|
+
_classCallCheck(this, XgplayerTimeRange2);
|
|
159
|
+
this.bufferedList = bufferedList;
|
|
160
|
+
}
|
|
161
|
+
_createClass(XgplayerTimeRange2, [{
|
|
162
|
+
key: "start",
|
|
163
|
+
value: function start(index) {
|
|
164
|
+
return this.bufferedList[index].start;
|
|
165
|
+
}
|
|
166
|
+
}, {
|
|
167
|
+
key: "end",
|
|
168
|
+
value: function end(index) {
|
|
169
|
+
return this.bufferedList[index].end;
|
|
170
|
+
}
|
|
171
|
+
}, {
|
|
172
|
+
key: "length",
|
|
173
|
+
get: function get() {
|
|
174
|
+
return this.bufferedList.length;
|
|
175
|
+
}
|
|
176
|
+
}]);
|
|
177
|
+
return XgplayerTimeRange2;
|
|
178
|
+
}();
|
|
179
|
+
var util = {};
|
|
180
|
+
util.createDom = function() {
|
|
181
|
+
var el = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "div";
|
|
182
|
+
var tpl = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
|
|
183
|
+
var attrs = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
184
|
+
var cname = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "";
|
|
185
|
+
var dom = document.createElement(el);
|
|
186
|
+
dom.className = cname;
|
|
187
|
+
dom.innerHTML = tpl;
|
|
188
|
+
Object.keys(attrs).forEach(function(item) {
|
|
189
|
+
var key = item;
|
|
190
|
+
var value = attrs[item];
|
|
191
|
+
if (el === "video" || el === "audio" || el === "live-video") {
|
|
192
|
+
if (value) {
|
|
193
|
+
dom.setAttribute(key, value);
|
|
194
|
+
}
|
|
195
|
+
} else {
|
|
196
|
+
dom.setAttribute(key, value);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
return dom;
|
|
200
|
+
};
|
|
201
|
+
util.createDomFromHtml = function(html) {
|
|
202
|
+
var attrs = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
203
|
+
var classname = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "";
|
|
204
|
+
try {
|
|
205
|
+
var doc = document.createElement("div");
|
|
206
|
+
doc.innerHTML = html;
|
|
207
|
+
var dom = doc.children;
|
|
208
|
+
doc = null;
|
|
209
|
+
if (dom.length > 0) {
|
|
210
|
+
dom = dom[0];
|
|
211
|
+
classname && util.addClass(dom, classname);
|
|
212
|
+
if (attrs) {
|
|
213
|
+
Object.keys(attrs).forEach(function(key) {
|
|
214
|
+
dom.setAttribute(key, attrs[key]);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
return dom;
|
|
218
|
+
}
|
|
219
|
+
return null;
|
|
220
|
+
} catch (err) {
|
|
221
|
+
XG_DEBUG.logError("util.createDomFromHtml", err);
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
util.hasClass = function(el, className) {
|
|
226
|
+
if (!el || !className) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
return Array.prototype.some.call(el.classList, function(item) {
|
|
231
|
+
return item === className;
|
|
232
|
+
});
|
|
233
|
+
} catch (e) {
|
|
234
|
+
var orgClassName = el.className && _typeof(el.className) === "object" ? el.getAttribute("class") : el.className;
|
|
235
|
+
return orgClassName && !!orgClassName.match(new RegExp("(\\s|^)" + className + "(\\s|$)"));
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
util.addClass = function(el, className) {
|
|
239
|
+
if (!el || !className) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
try {
|
|
243
|
+
className.replace(/(^\s+|\s+$)/g, "").split(/\s+/g).forEach(function(item) {
|
|
244
|
+
item && el.classList.add(item);
|
|
245
|
+
});
|
|
246
|
+
} catch (e) {
|
|
247
|
+
if (!util.hasClass(el, className)) {
|
|
248
|
+
if (el.className && _typeof(el.className) === "object") {
|
|
249
|
+
el.setAttribute("class", el.getAttribute("class") + " " + className);
|
|
250
|
+
} else {
|
|
251
|
+
el.className += " " + className;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
util.removeClass = function(el, className) {
|
|
257
|
+
if (!el || !className) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
try {
|
|
261
|
+
className.replace(/(^\s+|\s+$)/g, "").split(/\s+/g).forEach(function(item) {
|
|
262
|
+
item && el.classList.remove(item);
|
|
263
|
+
});
|
|
264
|
+
} catch (e) {
|
|
265
|
+
if (util.hasClass(el, className)) {
|
|
266
|
+
className.split(/\s+/g).forEach(function(item) {
|
|
267
|
+
var reg = new RegExp("(\\s|^)" + item + "(\\s|$)");
|
|
268
|
+
if (el.className && _typeof(el.className) === "object") {
|
|
269
|
+
el.setAttribute("class", el.getAttribute("class").replace(reg, " "));
|
|
270
|
+
} else {
|
|
271
|
+
el.className = el.className.replace(reg, " ");
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
util.toggleClass = function(el, className) {
|
|
278
|
+
if (!el) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
className.split(/\s+/g).forEach(function(item) {
|
|
282
|
+
if (util.hasClass(el, item)) {
|
|
283
|
+
util.removeClass(el, item);
|
|
284
|
+
} else {
|
|
285
|
+
util.addClass(el, item);
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
util.classNames = function() {
|
|
290
|
+
var _arguments = arguments;
|
|
291
|
+
var classname = [];
|
|
292
|
+
var _loop = function _loop2(i2) {
|
|
293
|
+
if (util.typeOf(_arguments[i2]) === "String") {
|
|
294
|
+
classname.push(_arguments[i2]);
|
|
295
|
+
} else if (util.typeOf(_arguments[i2]) === "Object") {
|
|
296
|
+
Object.keys(_arguments[i2]).map(function(key) {
|
|
297
|
+
if (_arguments[i2][key]) {
|
|
298
|
+
classname.push(key);
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
304
|
+
_loop(i);
|
|
305
|
+
}
|
|
306
|
+
return classname.join(" ");
|
|
307
|
+
};
|
|
308
|
+
util.findDom = function() {
|
|
309
|
+
var el = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : document;
|
|
310
|
+
var sel = arguments.length > 1 ? arguments[1] : void 0;
|
|
311
|
+
var dom;
|
|
312
|
+
try {
|
|
313
|
+
dom = el.querySelector(sel);
|
|
314
|
+
} catch (e) {
|
|
315
|
+
XG_DEBUG.logError("util.findDom", e);
|
|
316
|
+
if (sel.indexOf("#") === 0) {
|
|
317
|
+
dom = el.getElementById(sel.slice(1));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return dom;
|
|
321
|
+
};
|
|
322
|
+
util.getCss = function(dom, key) {
|
|
323
|
+
return dom.currentStyle ? dom.currentStyle[key] : document.defaultView.getComputedStyle(dom, false)[key];
|
|
324
|
+
};
|
|
325
|
+
util.padStart = function(str, length, pad) {
|
|
326
|
+
var charstr = String(pad);
|
|
327
|
+
var len = length >> 0;
|
|
328
|
+
var maxlen = Math.ceil(len / charstr.length);
|
|
329
|
+
var chars = [];
|
|
330
|
+
var r = String(str);
|
|
331
|
+
while (maxlen--) {
|
|
332
|
+
chars.push(charstr);
|
|
333
|
+
}
|
|
334
|
+
return chars.join("").substring(0, len - r.length) + r;
|
|
335
|
+
};
|
|
336
|
+
util.format = function(time) {
|
|
337
|
+
if (window.isNaN(time)) {
|
|
338
|
+
return "";
|
|
339
|
+
}
|
|
340
|
+
time = Math.round(time);
|
|
341
|
+
var hour = util.padStart(Math.floor(time / 3600), 2, 0);
|
|
342
|
+
var minute = util.padStart(Math.floor((time - hour * 3600) / 60), 2, 0);
|
|
343
|
+
var second = util.padStart(Math.floor(time - hour * 3600 - minute * 60), 2, 0);
|
|
344
|
+
return (hour === "00" ? [minute, second] : [hour, minute, second]).join(":");
|
|
345
|
+
};
|
|
346
|
+
util.event = function(e) {
|
|
347
|
+
if (e.touches) {
|
|
348
|
+
var touch = e.touches[0] || e.changedTouches[0];
|
|
349
|
+
e.clientX = touch.clientX || 0;
|
|
350
|
+
e.clientY = touch.clientY || 0;
|
|
351
|
+
e.offsetX = touch.pageX - touch.target.offsetLeft;
|
|
352
|
+
e.offsetY = touch.pageY - touch.target.offsetTop;
|
|
353
|
+
}
|
|
354
|
+
e._target = e.target || e.srcElement;
|
|
355
|
+
};
|
|
356
|
+
util.typeOf = function(obj) {
|
|
357
|
+
return Object.prototype.toString.call(obj).match(/([^\s.*]+)(?=]$)/g)[0];
|
|
358
|
+
};
|
|
359
|
+
util.deepCopy = function(dst, src) {
|
|
360
|
+
if (util.typeOf(src) === "Object" && util.typeOf(dst) === "Object") {
|
|
361
|
+
Object.keys(src).forEach(function(key) {
|
|
362
|
+
if (util.typeOf(src[key]) === "Object" && !(src[key] instanceof Node)) {
|
|
363
|
+
if (dst[key] === void 0 || dst[key] === void 0) {
|
|
364
|
+
dst[key] = src[key];
|
|
365
|
+
} else {
|
|
366
|
+
util.deepCopy(dst[key], src[key]);
|
|
367
|
+
}
|
|
368
|
+
} else if (util.typeOf(src[key]) === "Array") {
|
|
369
|
+
dst[key] = util.typeOf(dst[key]) === "Array" ? dst[key].concat(src[key]) : src[key];
|
|
370
|
+
} else {
|
|
371
|
+
dst[key] = src[key];
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
return dst;
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
util.deepMerge = function(dst, src) {
|
|
378
|
+
Object.keys(src).map(function(key) {
|
|
379
|
+
if (util.typeOf(src[key]) === "Array" && util.typeOf(dst[key]) === "Array") {
|
|
380
|
+
if (util.typeOf(dst[key]) === "Array") {
|
|
381
|
+
var _dst$key;
|
|
382
|
+
(_dst$key = dst[key]).push.apply(_dst$key, _toConsumableArray(src[key]));
|
|
383
|
+
}
|
|
384
|
+
} else if (util.typeOf(dst[key]) === util.typeOf(src[key]) && dst[key] !== null && util.typeOf(dst[key]) === "Object" && !(src[key] instanceof window.Node)) {
|
|
385
|
+
util.deepMerge(dst[key], src[key]);
|
|
386
|
+
} else {
|
|
387
|
+
src[key] !== null && (dst[key] = src[key]);
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
return dst;
|
|
391
|
+
};
|
|
392
|
+
util.getBgImage = function(el) {
|
|
393
|
+
var url = (el.currentStyle || window.getComputedStyle(el, null)).backgroundImage;
|
|
394
|
+
if (!url || url === "none") {
|
|
395
|
+
return "";
|
|
396
|
+
}
|
|
397
|
+
var a = document.createElement("a");
|
|
398
|
+
a.href = url.replace(/url\("|"\)/g, "");
|
|
399
|
+
return a.href;
|
|
400
|
+
};
|
|
401
|
+
util.copyDom = function(dom) {
|
|
402
|
+
if (dom && dom.nodeType === 1) {
|
|
403
|
+
var back = document.createElement(dom.tagName);
|
|
404
|
+
Array.prototype.forEach.call(dom.attributes, function(node) {
|
|
405
|
+
back.setAttribute(node.name, node.value);
|
|
406
|
+
});
|
|
407
|
+
if (dom.innerHTML) {
|
|
408
|
+
back.innerHTML = dom.innerHTML;
|
|
409
|
+
}
|
|
410
|
+
return back;
|
|
411
|
+
} else {
|
|
412
|
+
return "";
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
util.setInterval = function(context, eventName, intervalFunc, frequency) {
|
|
416
|
+
if (!context._interval[eventName]) {
|
|
417
|
+
context._interval[eventName] = window.setInterval(intervalFunc.bind(context), frequency);
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
util.clearInterval = function(context, eventName) {
|
|
421
|
+
clearInterval(context._interval[eventName]);
|
|
422
|
+
context._interval[eventName] = null;
|
|
423
|
+
};
|
|
424
|
+
util.setTimeout = function(context, fun, time) {
|
|
425
|
+
if (!context._timers) {
|
|
426
|
+
context._timers = [];
|
|
427
|
+
}
|
|
428
|
+
var id = setTimeout(function() {
|
|
429
|
+
fun();
|
|
430
|
+
util.clearTimeout(context, id);
|
|
431
|
+
}, time);
|
|
432
|
+
context._timers.push(id);
|
|
433
|
+
return id;
|
|
434
|
+
};
|
|
435
|
+
util.clearTimeout = function(context, id) {
|
|
436
|
+
var _timers = context._timers;
|
|
437
|
+
if (util.typeOf(_timers) === "Array") {
|
|
438
|
+
for (var i = 0; i < _timers.length; i++) {
|
|
439
|
+
if (_timers[i] === id) {
|
|
440
|
+
_timers.splice(i, 1);
|
|
441
|
+
clearTimeout(id);
|
|
442
|
+
break;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
} else {
|
|
446
|
+
clearTimeout(id);
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
util.clearAllTimers = function(context) {
|
|
450
|
+
var _timers = context._timers;
|
|
451
|
+
if (util.typeOf(_timers) === "Array") {
|
|
452
|
+
_timers.map(function(item) {
|
|
453
|
+
clearTimeout(item);
|
|
454
|
+
});
|
|
455
|
+
context._timerIds = [];
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
util.createImgBtn = function(name, imgUrl, width, height) {
|
|
459
|
+
var btn = util.createDom("xg-".concat(name), "", {}, "xgplayer-".concat(name, "-img"));
|
|
460
|
+
btn.style.backgroundImage = 'url("'.concat(imgUrl, '")');
|
|
461
|
+
if (width && height) {
|
|
462
|
+
var w, h, unit;
|
|
463
|
+
["px", "rem", "em", "pt", "dp", "vw", "vh", "vm", "%"].every(function(item) {
|
|
464
|
+
if (width.indexOf(item) > -1 && height.indexOf(item) > -1) {
|
|
465
|
+
w = parseFloat(width.slice(0, width.indexOf(item)).trim());
|
|
466
|
+
h = parseFloat(height.slice(0, height.indexOf(item)).trim());
|
|
467
|
+
unit = item;
|
|
468
|
+
return false;
|
|
469
|
+
} else {
|
|
470
|
+
return true;
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
btn.style.width = "".concat(w).concat(unit);
|
|
474
|
+
btn.style.height = "".concat(h).concat(unit);
|
|
475
|
+
btn.style.backgroundSize = "".concat(w).concat(unit, " ").concat(h).concat(unit);
|
|
476
|
+
if (name === "start") {
|
|
477
|
+
btn.style.margin = "-".concat(h / 2).concat(unit, " auto auto -").concat(w / 2).concat(unit);
|
|
478
|
+
} else {
|
|
479
|
+
btn.style.margin = "auto 5px auto 5px";
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return btn;
|
|
483
|
+
};
|
|
484
|
+
util.Hex2RGBA = function(hex, alpha) {
|
|
485
|
+
var rgb = [];
|
|
486
|
+
if (/^\#[0-9A-F]{3}$/i.test(hex)) {
|
|
487
|
+
var sixHex = "#";
|
|
488
|
+
hex.replace(/[0-9A-F]/ig, function(kw) {
|
|
489
|
+
sixHex += kw + kw;
|
|
490
|
+
});
|
|
491
|
+
hex = sixHex;
|
|
492
|
+
}
|
|
493
|
+
if (/^#[0-9A-F]{6}$/i.test(hex)) {
|
|
494
|
+
hex.replace(/[0-9A-F]{2}/ig, function(kw) {
|
|
495
|
+
rgb.push(parseInt(kw, 16));
|
|
496
|
+
});
|
|
497
|
+
return "rgba(".concat(rgb.join(","), ", ").concat(alpha, ")");
|
|
498
|
+
} else {
|
|
499
|
+
return "rgba(255, 255, 255, 0.1)";
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
util.getFullScreenEl = function() {
|
|
503
|
+
return document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement;
|
|
504
|
+
};
|
|
505
|
+
util.checkIsFunction = function(fun) {
|
|
506
|
+
return fun && typeof fun === "function";
|
|
507
|
+
};
|
|
508
|
+
util.checkIsObject = function(obj) {
|
|
509
|
+
return obj !== null && _typeof(obj) === "object";
|
|
510
|
+
};
|
|
511
|
+
util.hide = function(dom) {
|
|
512
|
+
dom.style.display = "none";
|
|
513
|
+
};
|
|
514
|
+
util.show = function(dom, display) {
|
|
515
|
+
dom.style.display = display || "block";
|
|
516
|
+
};
|
|
517
|
+
util.isUndefined = function(val) {
|
|
518
|
+
if (typeof val === "undefined" || val === null) {
|
|
519
|
+
return true;
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
util.isNotNull = function(val) {
|
|
523
|
+
return !(val === void 0 || val === null);
|
|
524
|
+
};
|
|
525
|
+
util.setStyleFromCsstext = function(dom, text) {
|
|
526
|
+
if (!text) {
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
if (util.typeOf(text) === "String") {
|
|
530
|
+
var styleArr = text.replace(/\s+/g, "").split(";");
|
|
531
|
+
styleArr.map(function(item) {
|
|
532
|
+
if (item) {
|
|
533
|
+
var arr = item.split(":");
|
|
534
|
+
if (arr.length > 1) {
|
|
535
|
+
dom.style[arr[0]] = arr[1];
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
} else {
|
|
540
|
+
Object.keys(text).map(function(key) {
|
|
541
|
+
dom.style[key] = text[key];
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
function checkIsIn(key, list) {
|
|
546
|
+
for (var i = 0, len = list.length; i < len; i++) {
|
|
547
|
+
if (key.indexOf(list[i]) > -1) {
|
|
548
|
+
return true;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
return false;
|
|
552
|
+
}
|
|
553
|
+
util.filterStyleFromText = function(dom) {
|
|
554
|
+
var list = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : ["width", "height", "top", "left", "bottom", "right", "position", "z-index", "padding", "margin", "transform"];
|
|
555
|
+
var _cssText = dom.style.cssText;
|
|
556
|
+
if (!_cssText) {
|
|
557
|
+
return {};
|
|
558
|
+
}
|
|
559
|
+
var styleArr = _cssText.replace(/\s+/g, "").split(";");
|
|
560
|
+
var ret = {};
|
|
561
|
+
var remain = {};
|
|
562
|
+
styleArr.map(function(item) {
|
|
563
|
+
if (item) {
|
|
564
|
+
var arr = item.split(":");
|
|
565
|
+
if (arr.length > 1) {
|
|
566
|
+
if (checkIsIn(arr[0], list)) {
|
|
567
|
+
ret[arr[0]] = arr[1];
|
|
568
|
+
} else {
|
|
569
|
+
remain[arr[0]] = arr[1];
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
dom.setAttribute("style", "");
|
|
575
|
+
Object.keys(remain).map(function(key) {
|
|
576
|
+
dom.style[key] = remain[key];
|
|
577
|
+
});
|
|
578
|
+
return ret;
|
|
579
|
+
};
|
|
580
|
+
util.getStyleFromCsstext = function(dom) {
|
|
581
|
+
var _cssText = dom.style.cssText;
|
|
582
|
+
if (!_cssText) {
|
|
583
|
+
return {};
|
|
584
|
+
}
|
|
585
|
+
var styleArr = _cssText.replace(/\s+/g, "").split(";");
|
|
586
|
+
var ret = {};
|
|
587
|
+
styleArr.map(function(item) {
|
|
588
|
+
if (item) {
|
|
589
|
+
var arr = item.split(":");
|
|
590
|
+
if (arr.length > 1) {
|
|
591
|
+
ret[arr[0]] = arr[1];
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
return ret;
|
|
596
|
+
};
|
|
597
|
+
util.preloadImg = function(url) {
|
|
598
|
+
var onload = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : function() {
|
|
599
|
+
};
|
|
600
|
+
var onerror = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : function() {
|
|
601
|
+
};
|
|
602
|
+
if (!url) {
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
var img = new window.Image();
|
|
606
|
+
img.onload = function(e) {
|
|
607
|
+
img = null;
|
|
608
|
+
onload && onload(e);
|
|
609
|
+
};
|
|
610
|
+
img.onerror = function(e) {
|
|
611
|
+
img = null;
|
|
612
|
+
onerror && onerror(e);
|
|
613
|
+
};
|
|
614
|
+
img.src = url;
|
|
615
|
+
};
|
|
616
|
+
util.stopPropagation = function(e) {
|
|
617
|
+
if (e) {
|
|
618
|
+
e.stopPropagation();
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
util.scrollTop = function() {
|
|
622
|
+
return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
|
|
623
|
+
};
|
|
624
|
+
util.scrollLeft = function() {
|
|
625
|
+
return window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0;
|
|
626
|
+
};
|
|
627
|
+
util.checkTouchSupport = function() {
|
|
628
|
+
return "ontouchstart" in window;
|
|
629
|
+
};
|
|
630
|
+
util.getBuffered2 = function(vbuffered) {
|
|
631
|
+
var maxHoleDuration = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0.5;
|
|
632
|
+
var buffered = [];
|
|
633
|
+
for (var i = 0; i < vbuffered.length; i++) {
|
|
634
|
+
buffered.push({
|
|
635
|
+
start: vbuffered.start(i) < 0.5 ? 0 : vbuffered.start(i),
|
|
636
|
+
end: vbuffered.end(i)
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
buffered.sort(function(a, b) {
|
|
640
|
+
var diff = a.start - b.start;
|
|
641
|
+
if (diff) {
|
|
642
|
+
return diff;
|
|
643
|
+
} else {
|
|
644
|
+
return b.end - a.end;
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
var buffered2 = [];
|
|
648
|
+
if (maxHoleDuration) {
|
|
649
|
+
for (var _i = 0; _i < buffered.length; _i++) {
|
|
650
|
+
var buf2len = buffered2.length;
|
|
651
|
+
if (buf2len) {
|
|
652
|
+
var buf2end = buffered2[buf2len - 1].end;
|
|
653
|
+
if (buffered[_i].start - buf2end < maxHoleDuration) {
|
|
654
|
+
if (buffered[_i].end > buf2end) {
|
|
655
|
+
buffered2[buf2len - 1].end = buffered[_i].end;
|
|
656
|
+
}
|
|
657
|
+
} else {
|
|
658
|
+
buffered2.push(buffered[_i]);
|
|
659
|
+
}
|
|
660
|
+
} else {
|
|
661
|
+
buffered2.push(buffered[_i]);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
} else {
|
|
665
|
+
buffered2 = buffered;
|
|
666
|
+
}
|
|
667
|
+
return new XgplayerTimeRange(buffered2);
|
|
668
|
+
};
|
|
669
|
+
util.getEventPos = function(e) {
|
|
670
|
+
var zoom = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
|
|
671
|
+
if (e.touches && e.touches.length > 0) {
|
|
672
|
+
e = e.touches[0];
|
|
673
|
+
}
|
|
674
|
+
return {
|
|
675
|
+
x: e.x / zoom,
|
|
676
|
+
y: e.y / zoom,
|
|
677
|
+
clientX: e.clientX / zoom,
|
|
678
|
+
clientY: e.clientY / zoom,
|
|
679
|
+
offsetX: e.offsetX / zoom,
|
|
680
|
+
offsetY: e.offsetY / zoom,
|
|
681
|
+
pageX: e.pageX / zoom,
|
|
682
|
+
pageY: e.pageY / zoom
|
|
683
|
+
};
|
|
684
|
+
};
|
|
685
|
+
util.requestAnimationFrame = function(callback) {
|
|
686
|
+
var _fun = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame;
|
|
687
|
+
if (_fun) {
|
|
688
|
+
return _fun(callback);
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
util.getHostFromUrl = function(url) {
|
|
692
|
+
if (util.typeOf(url) !== "String") {
|
|
693
|
+
return "";
|
|
694
|
+
}
|
|
695
|
+
var results = url.split("/");
|
|
696
|
+
var domain = "";
|
|
697
|
+
if (results.length > 3 && results[2]) {
|
|
698
|
+
domain = results[2];
|
|
699
|
+
}
|
|
700
|
+
return domain;
|
|
701
|
+
};
|
|
702
|
+
util.cancelAnimationFrame = function(frameId) {
|
|
703
|
+
var _fun = window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.cancelRequestAnimationFrame;
|
|
704
|
+
_fun && _fun(frameId);
|
|
705
|
+
};
|
|
706
|
+
util.isMSE = function(video) {
|
|
707
|
+
if (video.media) {
|
|
708
|
+
video = video.media;
|
|
709
|
+
}
|
|
710
|
+
if (!video || !(video instanceof HTMLMediaElement)) {
|
|
711
|
+
return false;
|
|
712
|
+
}
|
|
713
|
+
return /^blob/.test(video.currentSrc) || /^blob/.test(video.src);
|
|
714
|
+
};
|
|
715
|
+
util.isBlob = function(url) {
|
|
716
|
+
return typeof url === "string" && /^blob/.test(url);
|
|
717
|
+
};
|
|
718
|
+
util.generateSessionId = function() {
|
|
719
|
+
var did = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
|
|
720
|
+
var d = (/* @__PURE__ */ new Date()).getTime();
|
|
721
|
+
try {
|
|
722
|
+
did = parseInt(did);
|
|
723
|
+
} catch (e) {
|
|
724
|
+
did = 0;
|
|
725
|
+
}
|
|
726
|
+
d += did;
|
|
727
|
+
if (window.performance && typeof window.performance.now === "function") {
|
|
728
|
+
d += parseInt(window.performance.now());
|
|
729
|
+
}
|
|
730
|
+
var uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
731
|
+
var r = (d + Math.random() * 16) % 16 | 0;
|
|
732
|
+
d = Math.floor(d / 16);
|
|
733
|
+
return (c === "x" ? r : r & 3 | 8).toString(16);
|
|
734
|
+
});
|
|
735
|
+
return uuid;
|
|
736
|
+
};
|
|
737
|
+
util.createEvent = function(eventName) {
|
|
738
|
+
var event;
|
|
739
|
+
if (typeof window.Event === "function") {
|
|
740
|
+
event = new Event(eventName);
|
|
741
|
+
} else {
|
|
742
|
+
event = document.createEvent("Event");
|
|
743
|
+
event.initEvent(eventName, true, true);
|
|
744
|
+
}
|
|
745
|
+
return event;
|
|
746
|
+
};
|
|
747
|
+
util.adjustTimeByDuration = function(time, duration, isEnded) {
|
|
748
|
+
if (!duration || !time) {
|
|
749
|
+
return time;
|
|
750
|
+
}
|
|
751
|
+
if (time > duration || isEnded && time < duration) {
|
|
752
|
+
return duration;
|
|
753
|
+
}
|
|
754
|
+
return time;
|
|
755
|
+
};
|
|
756
|
+
util.createPositionBar = function(className, root) {
|
|
757
|
+
var dom = util.createDom("xg-bar", "", {
|
|
758
|
+
"data-index": -1
|
|
759
|
+
}, className);
|
|
760
|
+
root.appendChild(dom);
|
|
761
|
+
return dom;
|
|
762
|
+
};
|
|
763
|
+
util.getTransformStyle = function() {
|
|
764
|
+
var pos = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
|
|
765
|
+
x: 0,
|
|
766
|
+
y: 0,
|
|
767
|
+
scale: 1,
|
|
768
|
+
rotate: 0
|
|
769
|
+
};
|
|
770
|
+
var transformValue = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
|
|
771
|
+
var styles = {
|
|
772
|
+
scale: "".concat(pos.scale || 1),
|
|
773
|
+
translate: "".concat(pos.x || 0, "%, ").concat(pos.y || 0, "%"),
|
|
774
|
+
rotate: "".concat(pos.rotate || 0, "deg")
|
|
775
|
+
};
|
|
776
|
+
var stylesKeys = Object.keys(styles);
|
|
777
|
+
stylesKeys.forEach(function(key) {
|
|
778
|
+
var reg = new RegExp("".concat(key, "\\([^\\(]+\\)"), "g");
|
|
779
|
+
var fn = "".concat(key, "(").concat(styles[key], ")");
|
|
780
|
+
if (reg.test(transformValue)) {
|
|
781
|
+
reg.lastIndex = -1;
|
|
782
|
+
transformValue = transformValue.replace(reg, fn);
|
|
783
|
+
} else {
|
|
784
|
+
transformValue += "".concat(fn, " ");
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
return transformValue;
|
|
788
|
+
};
|
|
789
|
+
util.convertDeg = function(val) {
|
|
790
|
+
if (Math.abs(val) <= 1) {
|
|
791
|
+
return val * 360;
|
|
792
|
+
}
|
|
793
|
+
return val % 360;
|
|
794
|
+
};
|
|
795
|
+
util.getIndexByTime = function(time, segments) {
|
|
796
|
+
var _len = segments.length;
|
|
797
|
+
var _index = -1;
|
|
798
|
+
if (_len < 1) {
|
|
799
|
+
return _index;
|
|
800
|
+
}
|
|
801
|
+
if (time <= segments[0].end || _len < 2) {
|
|
802
|
+
_index = 0;
|
|
803
|
+
} else if (time > segments[_len - 1].end) {
|
|
804
|
+
_index = _len - 1;
|
|
805
|
+
} else {
|
|
806
|
+
for (var i = 1; i < _len; i++) {
|
|
807
|
+
if (time > segments[i - 1].end && time <= segments[i].end) {
|
|
808
|
+
_index = i;
|
|
809
|
+
break;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
return _index;
|
|
814
|
+
};
|
|
815
|
+
util.getOffsetCurrentTime = function(currentTime, segments) {
|
|
816
|
+
var index = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : -1;
|
|
817
|
+
var _index = -1;
|
|
818
|
+
if (index >= 0 && index < segments.length) {
|
|
819
|
+
_index = index;
|
|
820
|
+
} else {
|
|
821
|
+
_index = util.getIndexByTime(currentTime, segments);
|
|
822
|
+
}
|
|
823
|
+
if (_index < 0) {
|
|
824
|
+
return -1;
|
|
825
|
+
}
|
|
826
|
+
var _len = segments.length;
|
|
827
|
+
var _segments$_index = segments[_index], start = _segments$_index.start, end = _segments$_index.end, cTime = _segments$_index.cTime, offset = _segments$_index.offset;
|
|
828
|
+
if (currentTime < start) {
|
|
829
|
+
return cTime;
|
|
830
|
+
} else if (currentTime >= start && currentTime <= end) {
|
|
831
|
+
return currentTime - offset;
|
|
832
|
+
} else if (currentTime > end && _index >= _len - 1) {
|
|
833
|
+
return end;
|
|
834
|
+
}
|
|
835
|
+
return -1;
|
|
836
|
+
};
|
|
837
|
+
util.getCurrentTimeByOffset = function(offsetTime, segments) {
|
|
838
|
+
var _index = -1;
|
|
839
|
+
if (!segments || segments.length < 0) {
|
|
840
|
+
return offsetTime;
|
|
841
|
+
}
|
|
842
|
+
for (var i = 0; i < segments.length; i++) {
|
|
843
|
+
if (offsetTime <= segments[i].duration) {
|
|
844
|
+
_index = i;
|
|
845
|
+
break;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
if (_index !== -1) {
|
|
849
|
+
var start = segments[_index].start;
|
|
850
|
+
if (_index - 1 < 0) {
|
|
851
|
+
return start + offsetTime;
|
|
852
|
+
} else {
|
|
853
|
+
return start + (offsetTime - segments[_index - 1].duration);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
return offsetTime;
|
|
857
|
+
};
|
|
858
|
+
function callHandler(obj, handler, next) {
|
|
859
|
+
for (var _len = arguments.length, args = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
|
|
860
|
+
args[_key - 3] = arguments[_key];
|
|
861
|
+
}
|
|
862
|
+
var ret = handler.call.apply(handler, [obj].concat(args));
|
|
863
|
+
if (!next || typeof next !== "function") {
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
if (ret && ret.then) {
|
|
867
|
+
ret.then(function() {
|
|
868
|
+
for (var _len2 = arguments.length, args2 = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
869
|
+
args2[_key2] = arguments[_key2];
|
|
870
|
+
}
|
|
871
|
+
next.call.apply(next, [obj].concat(args2));
|
|
872
|
+
});
|
|
873
|
+
} else {
|
|
874
|
+
next.call.apply(next, [obj].concat(args));
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
function hook(hookName, handler) {
|
|
878
|
+
var preset = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {
|
|
879
|
+
pre: null,
|
|
880
|
+
next: null
|
|
881
|
+
};
|
|
882
|
+
if (!this.__hooks) {
|
|
883
|
+
this.__hooks = {};
|
|
884
|
+
}
|
|
885
|
+
!this.__hooks[hookName] && (this.__hooks[hookName] = null);
|
|
886
|
+
return function() {
|
|
887
|
+
var _arguments = arguments, _this = this;
|
|
888
|
+
if (preset.pre) {
|
|
889
|
+
try {
|
|
890
|
+
var _preset$pre;
|
|
891
|
+
(_preset$pre = preset.pre).call.apply(_preset$pre, [this].concat(Array.prototype.slice.call(arguments)));
|
|
892
|
+
} catch (e) {
|
|
893
|
+
e.message = "[pluginName: ".concat(this.pluginName, ":").concat(hookName, ":pre error] >> ").concat(e.message);
|
|
894
|
+
throw e;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
if (this.__hooks && this.__hooks[hookName]) {
|
|
898
|
+
try {
|
|
899
|
+
var _this$__hooks$hookNam;
|
|
900
|
+
var preRet = (_this$__hooks$hookNam = this.__hooks[hookName]).call.apply(_this$__hooks$hookNam, [this, this].concat(Array.prototype.slice.call(arguments)));
|
|
901
|
+
if (preRet) {
|
|
902
|
+
if (preRet.then) {
|
|
903
|
+
preRet.then(function(isContinue) {
|
|
904
|
+
if (isContinue !== false) {
|
|
905
|
+
callHandler.apply(void 0, [_this, handler, preset.next].concat(_toConsumableArray(_arguments)));
|
|
906
|
+
}
|
|
907
|
+
}).catch(function(e) {
|
|
908
|
+
throw e;
|
|
909
|
+
});
|
|
910
|
+
} else {
|
|
911
|
+
callHandler.apply(void 0, [this, handler, preset.next].concat(Array.prototype.slice.call(arguments)));
|
|
912
|
+
}
|
|
913
|
+
} else if (preRet === void 0) {
|
|
914
|
+
callHandler.apply(void 0, [this, handler, preset.next].concat(Array.prototype.slice.call(arguments)));
|
|
915
|
+
}
|
|
916
|
+
} catch (e) {
|
|
917
|
+
e.message = "[pluginName: ".concat(this.pluginName, ":").concat(hookName, "] >> ").concat(e.message);
|
|
918
|
+
throw e;
|
|
919
|
+
}
|
|
920
|
+
} else {
|
|
921
|
+
callHandler.apply(void 0, [this, handler, preset.next].concat(Array.prototype.slice.call(arguments)));
|
|
922
|
+
}
|
|
923
|
+
}.bind(this);
|
|
924
|
+
}
|
|
925
|
+
function useHooks(hookName, handler) {
|
|
926
|
+
var __hooks = this.__hooks;
|
|
927
|
+
if (!__hooks) {
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
if (!__hooks.hasOwnProperty(hookName)) {
|
|
931
|
+
console.warn("has no supported hook which name [".concat(hookName, "]"));
|
|
932
|
+
return false;
|
|
933
|
+
}
|
|
934
|
+
__hooks && (__hooks[hookName] = handler);
|
|
935
|
+
return true;
|
|
936
|
+
}
|
|
937
|
+
function removeHooks(hookName, handler) {
|
|
938
|
+
var __hooks = this.__hooks;
|
|
939
|
+
if (!__hooks) {
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
delete __hooks[hookName];
|
|
943
|
+
}
|
|
944
|
+
function hooksDescriptor(instance) {
|
|
945
|
+
var presetHooks = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
946
|
+
instance.__hooks = {};
|
|
947
|
+
presetHooks && presetHooks.map(function(item) {
|
|
948
|
+
instance.__hooks[item] = null;
|
|
949
|
+
});
|
|
950
|
+
Object.defineProperty(instance, "hooks", {
|
|
951
|
+
get: function get() {
|
|
952
|
+
return instance.__hooks && Object.keys(instance.__hooks).map(function(key) {
|
|
953
|
+
if (instance.__hooks[key]) {
|
|
954
|
+
return key;
|
|
955
|
+
}
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
function delHooksDescriptor(instance) {
|
|
961
|
+
instance.__hooks = null;
|
|
962
|
+
}
|
|
963
|
+
function showErrorMsg(pluginName, msg) {
|
|
964
|
+
XG_DEBUG.logError("[".concat(pluginName, "] event or callback cant be undefined or null when call ").concat(msg));
|
|
965
|
+
}
|
|
966
|
+
var BasePlugin = /* @__PURE__ */ function() {
|
|
967
|
+
function BasePlugin2(args) {
|
|
968
|
+
_classCallCheck(this, BasePlugin2);
|
|
969
|
+
if (util.checkIsFunction(this.beforeCreate)) {
|
|
970
|
+
this.beforeCreate(args);
|
|
971
|
+
}
|
|
972
|
+
hooksDescriptor(this);
|
|
973
|
+
this.__args = args;
|
|
974
|
+
this.__events = {};
|
|
975
|
+
this.__onceEvents = {};
|
|
976
|
+
this.config = args.config || {};
|
|
977
|
+
this.player = null;
|
|
978
|
+
this.playerConfig = {};
|
|
979
|
+
this.pluginName = "";
|
|
980
|
+
this.__init(args);
|
|
981
|
+
}
|
|
982
|
+
_createClass(BasePlugin2, [{
|
|
983
|
+
key: "beforeCreate",
|
|
984
|
+
value: function beforeCreate(args) {
|
|
985
|
+
}
|
|
986
|
+
}, {
|
|
987
|
+
key: "afterCreate",
|
|
988
|
+
value: function afterCreate() {
|
|
989
|
+
}
|
|
990
|
+
}, {
|
|
991
|
+
key: "beforePlayerInit",
|
|
992
|
+
value: function beforePlayerInit() {
|
|
993
|
+
}
|
|
994
|
+
}, {
|
|
995
|
+
key: "onPluginsReady",
|
|
996
|
+
value: function onPluginsReady() {
|
|
997
|
+
}
|
|
998
|
+
}, {
|
|
999
|
+
key: "afterPlayerInit",
|
|
1000
|
+
value: function afterPlayerInit() {
|
|
1001
|
+
}
|
|
1002
|
+
}, {
|
|
1003
|
+
key: "destroy",
|
|
1004
|
+
value: function destroy() {
|
|
1005
|
+
}
|
|
1006
|
+
}, {
|
|
1007
|
+
key: "__init",
|
|
1008
|
+
value: function __init(args) {
|
|
1009
|
+
this.player = args.player;
|
|
1010
|
+
this.playerConfig = args.player && args.player.config;
|
|
1011
|
+
this.pluginName = args.pluginName ? args.pluginName.toLowerCase() : this.constructor.pluginName.toLowerCase();
|
|
1012
|
+
this.logger = args.player && args.player.logger;
|
|
1013
|
+
}
|
|
1014
|
+
}, {
|
|
1015
|
+
key: "updateLang",
|
|
1016
|
+
value: function updateLang(lang) {
|
|
1017
|
+
if (!lang) {
|
|
1018
|
+
lang = this.lang;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
}, {
|
|
1022
|
+
key: "lang",
|
|
1023
|
+
get: function get() {
|
|
1024
|
+
return this.player.lang;
|
|
1025
|
+
}
|
|
1026
|
+
}, {
|
|
1027
|
+
key: "i18n",
|
|
1028
|
+
get: function get() {
|
|
1029
|
+
return this.player.i18n;
|
|
1030
|
+
}
|
|
1031
|
+
}, {
|
|
1032
|
+
key: "i18nKeys",
|
|
1033
|
+
get: function get() {
|
|
1034
|
+
return this.player.i18nKeys;
|
|
1035
|
+
}
|
|
1036
|
+
}, {
|
|
1037
|
+
key: "domEventType",
|
|
1038
|
+
get: function get() {
|
|
1039
|
+
var _e = util.checkTouchSupport() ? "touch" : "mouse";
|
|
1040
|
+
if (this.playerConfig && (this.playerConfig.domEventType === "touch" || this.playerConfig.domEventType === "mouse")) {
|
|
1041
|
+
_e = this.playerConfig.domEventType;
|
|
1042
|
+
}
|
|
1043
|
+
return _e;
|
|
1044
|
+
}
|
|
1045
|
+
}, {
|
|
1046
|
+
key: "on",
|
|
1047
|
+
value: function on(event, callback) {
|
|
1048
|
+
var _this = this;
|
|
1049
|
+
if (!event || !callback || !this.player) {
|
|
1050
|
+
showErrorMsg(this.pluginName, "plugin.on(event, callback)");
|
|
1051
|
+
return;
|
|
1052
|
+
}
|
|
1053
|
+
if (typeof event === "string") {
|
|
1054
|
+
this.__events[event] = callback;
|
|
1055
|
+
this.player.on(event, callback);
|
|
1056
|
+
} else if (Array.isArray(event)) {
|
|
1057
|
+
event.forEach(function(item) {
|
|
1058
|
+
_this.__events[item] = callback;
|
|
1059
|
+
_this.player.on(item, callback);
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
}, {
|
|
1064
|
+
key: "once",
|
|
1065
|
+
value: function once(event, callback) {
|
|
1066
|
+
var _this2 = this;
|
|
1067
|
+
if (!event || !callback || !this.player) {
|
|
1068
|
+
showErrorMsg(this.pluginName, "plugin.once(event, callback)");
|
|
1069
|
+
return;
|
|
1070
|
+
}
|
|
1071
|
+
if (typeof event === "string") {
|
|
1072
|
+
this.__onceEvents[event] = callback;
|
|
1073
|
+
this.player.once(event, callback);
|
|
1074
|
+
} else if (Array.isArray(event)) {
|
|
1075
|
+
event.forEach(function(item) {
|
|
1076
|
+
_this2.__onceEvents[item] = callback;
|
|
1077
|
+
_this2.player.once(event, callback);
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
}, {
|
|
1082
|
+
key: "off",
|
|
1083
|
+
value: function off(event, callback) {
|
|
1084
|
+
var _this3 = this;
|
|
1085
|
+
if (!event || !callback || !this.player) {
|
|
1086
|
+
showErrorMsg(this.pluginName, "plugin.off(event, callback)");
|
|
1087
|
+
return;
|
|
1088
|
+
}
|
|
1089
|
+
if (typeof event === "string") {
|
|
1090
|
+
delete this.__events[event];
|
|
1091
|
+
this.player.off(event, callback);
|
|
1092
|
+
} else if (Array.isArray(event)) {
|
|
1093
|
+
event.forEach(function(item) {
|
|
1094
|
+
delete _this3.__events[event];
|
|
1095
|
+
_this3.player.off(item, callback);
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
}, {
|
|
1100
|
+
key: "offAll",
|
|
1101
|
+
value: function offAll() {
|
|
1102
|
+
var _this4 = this;
|
|
1103
|
+
["__events", "__onceEvents"].forEach(function(key) {
|
|
1104
|
+
Object.keys(_this4[key]).forEach(function(item) {
|
|
1105
|
+
_this4[key][item] && _this4.off(item, _this4[key][item]);
|
|
1106
|
+
item && delete _this4[key][item];
|
|
1107
|
+
});
|
|
1108
|
+
});
|
|
1109
|
+
this.__events = {};
|
|
1110
|
+
this.__onceEvents = {};
|
|
1111
|
+
}
|
|
1112
|
+
}, {
|
|
1113
|
+
key: "emit",
|
|
1114
|
+
value: function emit(event) {
|
|
1115
|
+
var _this$player;
|
|
1116
|
+
if (!this.player) {
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
for (var _len = arguments.length, res = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1120
|
+
res[_key - 1] = arguments[_key];
|
|
1121
|
+
}
|
|
1122
|
+
(_this$player = this.player).emit.apply(_this$player, [event].concat(res));
|
|
1123
|
+
}
|
|
1124
|
+
}, {
|
|
1125
|
+
key: "emitUserAction",
|
|
1126
|
+
value: function emitUserAction(event, action) {
|
|
1127
|
+
var params = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
1128
|
+
if (!this.player) {
|
|
1129
|
+
return;
|
|
1130
|
+
}
|
|
1131
|
+
var nParams = _objectSpread2(_objectSpread2({}, params), {}, {
|
|
1132
|
+
pluginName: this.pluginName
|
|
1133
|
+
});
|
|
1134
|
+
this.player.emitUserAction(event, action, nParams);
|
|
1135
|
+
}
|
|
1136
|
+
}, {
|
|
1137
|
+
key: "hook",
|
|
1138
|
+
value: function hook$1(hookName, handler) {
|
|
1139
|
+
return hook.call.apply(hook, [this].concat(Array.prototype.slice.call(arguments)));
|
|
1140
|
+
}
|
|
1141
|
+
}, {
|
|
1142
|
+
key: "useHooks",
|
|
1143
|
+
value: function useHooks$1(hookName, handler) {
|
|
1144
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
1145
|
+
args[_key2 - 2] = arguments[_key2];
|
|
1146
|
+
}
|
|
1147
|
+
return useHooks.call.apply(useHooks, [this].concat(Array.prototype.slice.call(arguments)));
|
|
1148
|
+
}
|
|
1149
|
+
}, {
|
|
1150
|
+
key: "removeHooks",
|
|
1151
|
+
value: function removeHooks$1(hookName, handler) {
|
|
1152
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
1153
|
+
args[_key3 - 2] = arguments[_key3];
|
|
1154
|
+
}
|
|
1155
|
+
return removeHooks.call.apply(removeHooks, [this].concat(Array.prototype.slice.call(arguments)));
|
|
1156
|
+
}
|
|
1157
|
+
}, {
|
|
1158
|
+
key: "registerPlugin",
|
|
1159
|
+
value: function registerPlugin(plugin) {
|
|
1160
|
+
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
1161
|
+
var name = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "";
|
|
1162
|
+
if (!this.player) {
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1165
|
+
name && (options.pluginName = name);
|
|
1166
|
+
return this.player.registerPlugin({
|
|
1167
|
+
plugin,
|
|
1168
|
+
options
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
}, {
|
|
1172
|
+
key: "getPlugin",
|
|
1173
|
+
value: function getPlugin(name) {
|
|
1174
|
+
return this.player ? this.player.getPlugin(name) : null;
|
|
1175
|
+
}
|
|
1176
|
+
}, {
|
|
1177
|
+
key: "__destroy",
|
|
1178
|
+
value: function __destroy() {
|
|
1179
|
+
var _this5 = this;
|
|
1180
|
+
var player = this.player;
|
|
1181
|
+
var pluginName = this.pluginName;
|
|
1182
|
+
this.offAll();
|
|
1183
|
+
util.clearAllTimers(this);
|
|
1184
|
+
if (util.checkIsFunction(this.destroy)) {
|
|
1185
|
+
this.destroy();
|
|
1186
|
+
}
|
|
1187
|
+
["player", "playerConfig", "pluginName", "logger", "__args", "__hooks"].map(function(item) {
|
|
1188
|
+
_this5[item] = null;
|
|
1189
|
+
});
|
|
1190
|
+
player.unRegisterPlugin(pluginName);
|
|
1191
|
+
delHooksDescriptor(this);
|
|
1192
|
+
}
|
|
1193
|
+
}], [{
|
|
1194
|
+
key: "defineGetterOrSetter",
|
|
1195
|
+
value: function defineGetterOrSetter(Obj, map) {
|
|
1196
|
+
for (var key in map) {
|
|
1197
|
+
if (Object.prototype.hasOwnProperty.call(map, key)) {
|
|
1198
|
+
Object.defineProperty(Obj, key, map[key]);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
}, {
|
|
1203
|
+
key: "defaultConfig",
|
|
1204
|
+
get: function get() {
|
|
1205
|
+
return {};
|
|
1206
|
+
}
|
|
1207
|
+
}, {
|
|
1208
|
+
key: "pluginName",
|
|
1209
|
+
get: function get() {
|
|
1210
|
+
return "pluginName";
|
|
1211
|
+
}
|
|
1212
|
+
}]);
|
|
1213
|
+
return BasePlugin2;
|
|
1214
|
+
}();
|
|
1215
|
+
var KeySystem = /* @__PURE__ */ ((KeySystem2) => {
|
|
1216
|
+
KeySystem2["widevine"] = "com.widevine.alpha";
|
|
1217
|
+
KeySystem2["fairplay"] = "com.apple.fps.1_0";
|
|
1218
|
+
KeySystem2["playready"] = "com.microsoft.playready";
|
|
1219
|
+
return KeySystem2;
|
|
1220
|
+
})(KeySystem || {});
|
|
1221
|
+
function selectKeySystem() {
|
|
1222
|
+
const options = [
|
|
1223
|
+
{
|
|
1224
|
+
initDataTypes: ["keyids", "webm"],
|
|
1225
|
+
audioCapabilities: [{ contentType: 'audio/mp4; codecs="mp4a.40.2"' }],
|
|
1226
|
+
videoCapabilities: [
|
|
1227
|
+
{ contentType: 'video/mp4; codecs="avc1.42c01e"' },
|
|
1228
|
+
{ contentType: 'video/mp4; codecs="hev1.1.6.L120.90"' },
|
|
1229
|
+
{ contentType: 'video/webm; codecs="vp8"' }
|
|
1230
|
+
]
|
|
1231
|
+
}
|
|
1232
|
+
];
|
|
1233
|
+
return new Promise((resolve, reject) => {
|
|
1234
|
+
navigator.requestMediaKeySystemAccess(KeySystem.fairplay, options).then((access) => {
|
|
1235
|
+
resolve({
|
|
1236
|
+
access,
|
|
1237
|
+
system: KeySystem.fairplay
|
|
1238
|
+
});
|
|
1239
|
+
}).catch(() => {
|
|
1240
|
+
if (globalThis.WebKitMediaKeys && globalThis.WebKitMediaKeys.isTypeSupported(
|
|
1241
|
+
KeySystem.fairplay,
|
|
1242
|
+
"video/mp4"
|
|
1243
|
+
)) {
|
|
1244
|
+
resolve({
|
|
1245
|
+
access: null,
|
|
1246
|
+
system: KeySystem.fairplay
|
|
1247
|
+
});
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1250
|
+
navigator.requestMediaKeySystemAccess(KeySystem.widevine, options).then((access) => {
|
|
1251
|
+
resolve({
|
|
1252
|
+
access,
|
|
1253
|
+
system: KeySystem.widevine
|
|
1254
|
+
});
|
|
1255
|
+
}).catch(() => {
|
|
1256
|
+
navigator.requestMediaKeySystemAccess(KeySystem.playready, options).then((access) => {
|
|
1257
|
+
resolve({
|
|
1258
|
+
access,
|
|
1259
|
+
system: KeySystem.playready
|
|
1260
|
+
});
|
|
1261
|
+
}).catch(reject);
|
|
1262
|
+
});
|
|
1263
|
+
});
|
|
1264
|
+
});
|
|
1265
|
+
}
|
|
1266
|
+
function arrayToString(array) {
|
|
1267
|
+
var uint16array = new Uint16Array(array.buffer);
|
|
1268
|
+
return String.fromCharCode.apply(null, uint16array);
|
|
1269
|
+
}
|
|
1270
|
+
function stringToArray(string) {
|
|
1271
|
+
var buffer = new ArrayBuffer(string.length * 2);
|
|
1272
|
+
var array = new Uint16Array(buffer);
|
|
1273
|
+
for (var i = 0, strLen = string.length; i < strLen; i++) {
|
|
1274
|
+
array[i] = string.charCodeAt(i);
|
|
1275
|
+
}
|
|
1276
|
+
return array;
|
|
1277
|
+
}
|
|
1278
|
+
class Mobile extends BasePlugin {
|
|
1279
|
+
constructor(options) {
|
|
1280
|
+
super(options);
|
|
1281
|
+
this.unsupported = false;
|
|
1282
|
+
this.unRecord = true;
|
|
1283
|
+
this.needKeyed = false;
|
|
1284
|
+
this.onNeedKey = (event) => {
|
|
1285
|
+
if (this.needKeyed)
|
|
1286
|
+
return;
|
|
1287
|
+
if (this.unsupported)
|
|
1288
|
+
return;
|
|
1289
|
+
this.needKeyed = true;
|
|
1290
|
+
event.target;
|
|
1291
|
+
let initData = event.initData;
|
|
1292
|
+
const initDataType = event.initDataType;
|
|
1293
|
+
const contentId = this.extractContentId(initData);
|
|
1294
|
+
if (this.keySystem === KeySystem.fairplay && !this.certificate) {
|
|
1295
|
+
return this.suspend = () => {
|
|
1296
|
+
this.afterInitDate(initData, contentId, initDataType);
|
|
1297
|
+
};
|
|
1298
|
+
}
|
|
1299
|
+
this.afterInitDate(initData, contentId, initDataType);
|
|
1300
|
+
};
|
|
1301
|
+
this.licenseRequestReady = (event) => {
|
|
1302
|
+
if (!this.serverProcessSPCPath) {
|
|
1303
|
+
this.emitError("lack serverProcessSPCPath");
|
|
1304
|
+
return;
|
|
1305
|
+
}
|
|
1306
|
+
const message = event.message;
|
|
1307
|
+
const request = new XMLHttpRequest();
|
|
1308
|
+
request.responseType = "arraybuffer";
|
|
1309
|
+
request.addEventListener("load", this.licenseRequestLoaded, false);
|
|
1310
|
+
request.addEventListener("error", this.licenseRequestFailed(event), false);
|
|
1311
|
+
var params = new Uint8Array(message);
|
|
1312
|
+
request.open("POST", this.serverProcessSPCPath, true);
|
|
1313
|
+
if (this.keySystem === KeySystem.playready) {
|
|
1314
|
+
request.setRequestHeader("Content-type", "text/xml");
|
|
1315
|
+
} else {
|
|
1316
|
+
request.setRequestHeader("Content-type", "application/octet-stream");
|
|
1317
|
+
}
|
|
1318
|
+
request.send(params);
|
|
1319
|
+
};
|
|
1320
|
+
this.licenseRequestLoaded = (event) => {
|
|
1321
|
+
const request = event.target;
|
|
1322
|
+
const arrayBuffer = request.response;
|
|
1323
|
+
let license;
|
|
1324
|
+
if (this.keySystem === KeySystem.playready) {
|
|
1325
|
+
license = this.parseServerResponse(arrayBuffer);
|
|
1326
|
+
} else {
|
|
1327
|
+
license = new Uint8Array(arrayBuffer);
|
|
1328
|
+
}
|
|
1329
|
+
if (license) {
|
|
1330
|
+
this.keySession.update(license);
|
|
1331
|
+
} else {
|
|
1332
|
+
this.emitError(
|
|
1333
|
+
`The license response no array buffer, licence: ${license}`
|
|
1334
|
+
);
|
|
1335
|
+
}
|
|
1336
|
+
};
|
|
1337
|
+
this.licenseRequestFailed = (event1) => (event) => {
|
|
1338
|
+
if (this.licenseRetryTime > 0) {
|
|
1339
|
+
this.licenseRequestReady(event1);
|
|
1340
|
+
this.licenseRetryTime--;
|
|
1341
|
+
} else {
|
|
1342
|
+
const request = event.target;
|
|
1343
|
+
this.emitError(
|
|
1344
|
+
`The license request fail, status: ${request.status}, statusText: ${request.statusText}`
|
|
1345
|
+
);
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
this.onKeyError = () => {
|
|
1349
|
+
this.emitError("A decryption key error was encountered");
|
|
1350
|
+
};
|
|
1351
|
+
this.loadCertificate = () => {
|
|
1352
|
+
if (!this.serverCertificatePath) {
|
|
1353
|
+
this.emitError("lack serverCertificatePath");
|
|
1354
|
+
return;
|
|
1355
|
+
}
|
|
1356
|
+
const request = new XMLHttpRequest();
|
|
1357
|
+
request.responseType = "arraybuffer";
|
|
1358
|
+
request.addEventListener("load", this.onCertificateLoaded, false);
|
|
1359
|
+
request.addEventListener("error", this.onCertificateError, false);
|
|
1360
|
+
request.open("GET", this.serverCertificatePath, true);
|
|
1361
|
+
request.send();
|
|
1362
|
+
};
|
|
1363
|
+
this.emitError = (message) => {
|
|
1364
|
+
this.emit("error", {
|
|
1365
|
+
errorCode: 7100,
|
|
1366
|
+
message,
|
|
1367
|
+
drm_sdk_version: "0.0.0-alpha.5"
|
|
1368
|
+
});
|
|
1369
|
+
};
|
|
1370
|
+
this.onCertificateLoaded = (event) => {
|
|
1371
|
+
const request = event.target;
|
|
1372
|
+
this.certificate = new Uint8Array(request.response);
|
|
1373
|
+
this.suspend && this.suspend();
|
|
1374
|
+
};
|
|
1375
|
+
this.onCertificateError = (event) => {
|
|
1376
|
+
if (this.certRetryTime > 0) {
|
|
1377
|
+
this.loadCertificate();
|
|
1378
|
+
this.certRetryTime--;
|
|
1379
|
+
} else {
|
|
1380
|
+
const request = event.target;
|
|
1381
|
+
this.emitError(
|
|
1382
|
+
`get cert fail, status: ${request.status}, statusText: ${request.statusText}`
|
|
1383
|
+
);
|
|
1384
|
+
}
|
|
1385
|
+
};
|
|
1386
|
+
this.restart = () => {
|
|
1387
|
+
this.reset();
|
|
1388
|
+
};
|
|
1389
|
+
this.reset();
|
|
1390
|
+
const config = options.config || {};
|
|
1391
|
+
this.serverCertificatePath = config.serverCertificatePath;
|
|
1392
|
+
this.serverProcessSPCPath = config.serverProcessSPCPath;
|
|
1393
|
+
if (typeof config.unRecord === "boolean") {
|
|
1394
|
+
this.unRecord = config.unRecord;
|
|
1395
|
+
}
|
|
1396
|
+
this.checkUnrecord();
|
|
1397
|
+
}
|
|
1398
|
+
static get pluginName() {
|
|
1399
|
+
return "drm";
|
|
1400
|
+
}
|
|
1401
|
+
set serverCertificatePath(x) {
|
|
1402
|
+
if (!x || this._serverCertificatePath === x)
|
|
1403
|
+
return;
|
|
1404
|
+
this._serverCertificatePath = x;
|
|
1405
|
+
if (this.keySystem === KeySystem.fairplay) {
|
|
1406
|
+
this.certificate = void 0;
|
|
1407
|
+
this.suspend = () => {
|
|
1408
|
+
};
|
|
1409
|
+
this.loadCertificate();
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
get serverCertificatePath() {
|
|
1413
|
+
return this._serverCertificatePath;
|
|
1414
|
+
}
|
|
1415
|
+
afterCreate() {
|
|
1416
|
+
this.media = this.player.video;
|
|
1417
|
+
this.media.addEventListener("webkitneedkey", this.onNeedKey, false);
|
|
1418
|
+
this.media.addEventListener("needkey", this.onNeedKey, false);
|
|
1419
|
+
this.media.addEventListener("encrypted", this.onNeedKey);
|
|
1420
|
+
this.player.on("urlchange", this.restart);
|
|
1421
|
+
}
|
|
1422
|
+
async checkUnrecord() {
|
|
1423
|
+
if (this.unRecord) {
|
|
1424
|
+
try {
|
|
1425
|
+
const { powerEfficient } = await navigator.mediaCapabilities.decodingInfo({
|
|
1426
|
+
type: "file",
|
|
1427
|
+
video: {
|
|
1428
|
+
contentType: 'video/mp4; codecs="avc1.42c01e"',
|
|
1429
|
+
width: 426,
|
|
1430
|
+
height: 238,
|
|
1431
|
+
bitrate: 1e3,
|
|
1432
|
+
framerate: 30
|
|
1433
|
+
}
|
|
1434
|
+
});
|
|
1435
|
+
this.unsupported = !powerEfficient;
|
|
1436
|
+
} catch (error) {
|
|
1437
|
+
this.emitError(`check powerEfficient failed, ${error.message}`);
|
|
1438
|
+
this.unsupported = true;
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
if (this.unsupported)
|
|
1442
|
+
return;
|
|
1443
|
+
selectKeySystem().then(({ access, system }) => {
|
|
1444
|
+
this.keySystem = system;
|
|
1445
|
+
if (system === KeySystem.fairplay) {
|
|
1446
|
+
this.loadCertificate();
|
|
1447
|
+
}
|
|
1448
|
+
if (access) {
|
|
1449
|
+
this.keySystemAccess = access;
|
|
1450
|
+
}
|
|
1451
|
+
}).catch((error) => {
|
|
1452
|
+
this.emitError(error.message);
|
|
1453
|
+
this.unsupported = true;
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
afterInitDate(initData, contentId, initDataType) {
|
|
1457
|
+
if (!this.keySystemAccess) {
|
|
1458
|
+
const mediaKeys = new globalThis.WebKitMediaKeys(this.keySystem);
|
|
1459
|
+
this.media.webkitSetMediaKeys(mediaKeys);
|
|
1460
|
+
if (!this.media.webkitKeys) {
|
|
1461
|
+
this.emitError("Could not create MediaKeys");
|
|
1462
|
+
return;
|
|
1463
|
+
}
|
|
1464
|
+
const keySession = mediaKeys.createSession(
|
|
1465
|
+
"video/mp4",
|
|
1466
|
+
this.concatInitDataIdAndCertificate(initData, contentId)
|
|
1467
|
+
);
|
|
1468
|
+
this.keySession = keySession;
|
|
1469
|
+
if (!keySession) {
|
|
1470
|
+
this.emitError("Could not create key session");
|
|
1471
|
+
return;
|
|
1472
|
+
}
|
|
1473
|
+
keySession.addEventListener("webkitkeymessage", this.licenseRequestReady);
|
|
1474
|
+
keySession.addEventListener("webkitkeyerror", this.onKeyError);
|
|
1475
|
+
} else {
|
|
1476
|
+
this.keySystemAccess.createMediaKeys().then((mediaKeys) => {
|
|
1477
|
+
this.media.setMediaKeys(mediaKeys);
|
|
1478
|
+
if (this.media.mediaKeys) {
|
|
1479
|
+
this.emitError("Could not create MediaKeys");
|
|
1480
|
+
return;
|
|
1481
|
+
}
|
|
1482
|
+
const keySession = mediaKeys.createSession();
|
|
1483
|
+
this.keySession = keySession;
|
|
1484
|
+
if (!keySession) {
|
|
1485
|
+
this.emitError("Could not create key session");
|
|
1486
|
+
return;
|
|
1487
|
+
}
|
|
1488
|
+
keySession.addEventListener("message", this.licenseRequestReady);
|
|
1489
|
+
keySession.generateRequest(initDataType, initData).catch((error) => {
|
|
1490
|
+
this.emitError(
|
|
1491
|
+
`generateRequest failed, code: ${error.errorCode}, message: ${error.message}`
|
|
1492
|
+
);
|
|
1493
|
+
});
|
|
1494
|
+
}).catch(() => {
|
|
1495
|
+
throw "Could not create MediaKeys";
|
|
1496
|
+
});
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
parseServerResponse(serverResponse) {
|
|
1500
|
+
const soap = "http://schemas.xmlsoap.org/soap/envelope/";
|
|
1501
|
+
if (DOMParser) {
|
|
1502
|
+
const stringResponse = this.uintToString(serverResponse);
|
|
1503
|
+
const parser = new DOMParser();
|
|
1504
|
+
const xmlDoc = parser.parseFromString(stringResponse, "text/xml");
|
|
1505
|
+
const envelope = xmlDoc ? xmlDoc.getElementsByTagNameNS(soap, "Envelope")[0] : null;
|
|
1506
|
+
const body = envelope ? envelope.getElementsByTagNameNS(soap, "Body")[0] : null;
|
|
1507
|
+
const fault = body ? body.getElementsByTagNameNS(soap, "Fault")[0] : null;
|
|
1508
|
+
if (fault) {
|
|
1509
|
+
return null;
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
return serverResponse;
|
|
1513
|
+
}
|
|
1514
|
+
uintToString(arrayBuffer) {
|
|
1515
|
+
const encodedString = String.fromCharCode.apply(
|
|
1516
|
+
null,
|
|
1517
|
+
new Uint8Array(arrayBuffer)
|
|
1518
|
+
);
|
|
1519
|
+
const decodedString = decodeURIComponent(escape(encodedString));
|
|
1520
|
+
return decodedString;
|
|
1521
|
+
}
|
|
1522
|
+
extractContentId(initData) {
|
|
1523
|
+
const contentId = arrayToString(initData);
|
|
1524
|
+
var link = document.createElement("a");
|
|
1525
|
+
link.href = contentId;
|
|
1526
|
+
return link.hostname;
|
|
1527
|
+
}
|
|
1528
|
+
concatInitDataIdAndCertificate(initData, id) {
|
|
1529
|
+
if (typeof id == "string")
|
|
1530
|
+
id = stringToArray(id);
|
|
1531
|
+
let offset = 0;
|
|
1532
|
+
let buffer;
|
|
1533
|
+
const cert = this.certificate;
|
|
1534
|
+
if (cert) {
|
|
1535
|
+
buffer = new ArrayBuffer(
|
|
1536
|
+
initData.byteLength + 4 + id.byteLength + 4 + cert.byteLength
|
|
1537
|
+
);
|
|
1538
|
+
} else {
|
|
1539
|
+
buffer = new ArrayBuffer(initData.byteLength + 4 + id.byteLength);
|
|
1540
|
+
}
|
|
1541
|
+
var dataView = new DataView(buffer);
|
|
1542
|
+
var initDataArray = new Uint8Array(buffer, offset, initData.byteLength);
|
|
1543
|
+
initDataArray.set(initData);
|
|
1544
|
+
offset += initData.byteLength;
|
|
1545
|
+
dataView.setUint32(offset, id.byteLength, true);
|
|
1546
|
+
offset += 4;
|
|
1547
|
+
var idArray = new Uint16Array(buffer, offset, id.length);
|
|
1548
|
+
idArray.set(id);
|
|
1549
|
+
offset += idArray.byteLength;
|
|
1550
|
+
if (cert) {
|
|
1551
|
+
dataView.setUint32(offset, cert.byteLength, true);
|
|
1552
|
+
offset += 4;
|
|
1553
|
+
var certArray = new Uint8Array(buffer, offset, cert.byteLength);
|
|
1554
|
+
certArray.set(cert);
|
|
1555
|
+
}
|
|
1556
|
+
return new Uint8Array(buffer, 0, buffer.byteLength);
|
|
1557
|
+
}
|
|
1558
|
+
reset() {
|
|
1559
|
+
this.certRetryTime = 2;
|
|
1560
|
+
this.licenseRetryTime = 2;
|
|
1561
|
+
this.suspend = void 0;
|
|
1562
|
+
this.keySession = void 0;
|
|
1563
|
+
this.needKeyed = false;
|
|
1564
|
+
}
|
|
1565
|
+
destroy() {
|
|
1566
|
+
this.player.off("urlchange", this.restart);
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
class DrmPlugin extends Mobile {
|
|
1570
|
+
updateDrmConfig(data) {
|
|
1571
|
+
data.serverProcessSPCPath && (this.serverProcessSPCPath = data.serverProcessSPCPath);
|
|
1572
|
+
data.serverCertificatePath && (this.serverCertificatePath = data.serverCertificatePath);
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
const DynamicModule = window["VePlayer"].DynamicModule;
|
|
1576
|
+
const __PLUGIN_NAME__ = DynamicModule.PluginDrm;
|
|
1577
|
+
export {
|
|
1578
|
+
DrmPlugin,
|
|
1579
|
+
__PLUGIN_NAME__
|
|
1580
|
+
};
|