@volcengine/veplayer 1.6.5-rc.0 → 2.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +3 -45
  2. package/esm/index.d.ts +1405 -0
  3. package/esm/veplayer.biz.live.development.css +41 -0
  4. package/esm/veplayer.biz.live.development.js +3157 -0
  5. package/esm/veplayer.biz.live.production.css +1 -0
  6. package/esm/veplayer.biz.live.production.js +2 -0
  7. package/esm/veplayer.biz.vod.development.js +13 -0
  8. package/esm/veplayer.biz.vod.production.js +2 -0
  9. package/esm/veplayer.d.ts +3071 -0
  10. package/esm/veplayer.development.css +743 -0
  11. package/esm/veplayer.development.js +21023 -0
  12. package/esm/veplayer.live.d.ts +3074 -0
  13. package/esm/veplayer.live.development.css +743 -0
  14. package/esm/veplayer.live.development.js +21022 -0
  15. package/esm/veplayer.live.production.css +1 -0
  16. package/esm/veplayer.live.production.js +11 -0
  17. package/esm/veplayer.production.css +1 -0
  18. package/esm/veplayer.production.js +11 -0
  19. package/esm/veplayer.vod.d.ts +1405 -0
  20. package/esm/veplayer.vod.development.css +702 -0
  21. package/esm/veplayer.vod.development.js +13104 -0
  22. package/esm/veplayer.vod.production.css +1 -0
  23. package/esm/veplayer.vod.production.js +11 -0
  24. package/package.json +78 -6
  25. package/umd/index.d.ts +1405 -0
  26. package/umd/veplayer.biz.live.development.css +41 -0
  27. package/umd/veplayer.biz.live.development.js +3169 -0
  28. package/umd/veplayer.biz.live.production.css +1 -0
  29. package/umd/veplayer.biz.live.production.js +1 -0
  30. package/umd/veplayer.biz.vod.development.js +29 -0
  31. package/umd/veplayer.biz.vod.production.js +1 -0
  32. package/umd/veplayer.d.ts +3071 -0
  33. package/umd/veplayer.development.css +743 -0
  34. package/umd/veplayer.development.js +21026 -0
  35. package/umd/veplayer.live.d.ts +3074 -0
  36. package/umd/veplayer.live.development.css +743 -0
  37. package/umd/veplayer.live.development.js +21034 -0
  38. package/umd/veplayer.live.production.css +1 -0
  39. package/umd/veplayer.live.production.js +1 -0
  40. package/umd/veplayer.production.css +1 -0
  41. package/umd/veplayer.production.js +1 -0
  42. package/umd/veplayer.vod.d.ts +1405 -0
  43. package/umd/veplayer.vod.development.css +702 -0
  44. package/umd/veplayer.vod.development.js +13119 -0
  45. package/umd/veplayer.vod.production.css +1 -0
  46. package/umd/veplayer.vod.production.js +1 -0
  47. package/index.d.ts +0 -3256
  48. package/index.min.css +0 -1
  49. package/index.min.js +0 -2
@@ -0,0 +1,3169 @@
1
+ (function(global2, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self, factory(global2.__VEPLAYER_BIZ_LIVE__ = {}));
3
+ })(this, function(exports2) {
4
+ "use strict";var __defProp = Object.defineProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __publicField = (obj, key, value) => {
7
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
+ return value;
9
+ };
10
+
11
+ const error = window["VePlayer"].error;
12
+ const { VeError } = error;
13
+ var LiveErrorCode = /* @__PURE__ */ ((LiveErrorCode2) => {
14
+ LiveErrorCode2[LiveErrorCode2["INVALID_PARAMETER"] = 200] = "INVALID_PARAMETER";
15
+ return LiveErrorCode2;
16
+ })(LiveErrorCode || {});
17
+ error.Level;
18
+ const ErrorCode = {
19
+ ...LiveErrorCode,
20
+ ...error.ErrorCode
21
+ };
22
+ const ERRORS = {
23
+ ...error.ERROR_INFO,
24
+ [
25
+ 200
26
+ /* INVALID_PARAMETER */
27
+ ]: {
28
+ messageTextKey: "INVALID_PARAMETER",
29
+ level: error.Level.Fatal
30
+ }
31
+ };
32
+ function create(errorCode, i18n) {
33
+ return new VeError(ERRORS[errorCode], i18n);
34
+ }
35
+ const strategy$1 = window["VePlayer"].strategy;
36
+ const util$3 = window["VePlayer"].util;
37
+ const DynamicModule$1 = window["VePlayer"].DynamicModule;
38
+ const load$1 = window["VePlayer"].load;
39
+ const Codec$1 = window["VePlayer"].Codec;
40
+ const Sniffer$2 = window["VePlayer"].Sniffer;
41
+ const rtmStrategy = {
42
+ options: {},
43
+ module: DynamicModule$1.PluginRtm
44
+ };
45
+ const getRtmStrategy = async (options) => {
46
+ var _a;
47
+ let backupStrategy;
48
+ const { fallbackUrl, ...ret } = options.rtm || {};
49
+ const backupType = fallbackUrl && util$3.getStreamType(fallbackUrl);
50
+ if (backupType === "flv" && util$3.isMseSupported(Codec$1.H264)) {
51
+ backupStrategy = strategy$1.createFlvMseStrategy(options);
52
+ } else if (backupType === "hls" && (Sniffer$2.device !== "mobile" || ((_a = options == null ? void 0 : options.hls) == null ? void 0 : _a.enableMSE)) && util$3.isMseSupported(Codec$1.H264)) {
53
+ backupStrategy = strategy$1.createHlsMseStrategy(options);
54
+ }
55
+ const [rtmCdn, backupCdn] = await Promise.all([
56
+ load$1(rtmStrategy.module).catch(() => void 0),
57
+ backupStrategy && load$1(backupStrategy.module).catch(() => void 0)
58
+ ]);
59
+ return {
60
+ options: {
61
+ ...(backupStrategy == null ? void 0 : backupStrategy.options) || {},
62
+ rts: {
63
+ retryCount: 0,
64
+ ...ret,
65
+ backupURL: fallbackUrl,
66
+ backupConstruct: backupCdn
67
+ }
68
+ },
69
+ plugins: rtmCdn ? [rtmCdn] : []
70
+ };
71
+ };
72
+ var RTMCodec = /* @__PURE__ */ ((RTMCodec2) => {
73
+ RTMCodec2["H264"] = "h264";
74
+ return RTMCodec2;
75
+ })(RTMCodec || {});
76
+ const isRTMSupported = async () => {
77
+ const Rtm = await load$1(DynamicModule$1.PluginRtm);
78
+ return Rtm.isSupported();
79
+ };
80
+ const isRTMSupportCodec = async (codec = "h264", options) => {
81
+ const Rtm = await load$1(DynamicModule$1.PluginRtm);
82
+ if (codec === "h264")
83
+ return Rtm.isSupportedH264(options == null ? void 0 : options.targetProfileLevel);
84
+ };
85
+ const util$2 = window["VePlayer"].util;
86
+ const strategy = window["VePlayer"].strategy;
87
+ const getTypeStrategy = async (options) => {
88
+ const type = options.url ? util$2.getStreamType(options.url) : "";
89
+ if (!type || type === "unknown") {
90
+ return { options: {}, plugins: [] };
91
+ }
92
+ if (type === "rtm") {
93
+ return await getRtmStrategy(options);
94
+ }
95
+ if (type === "flv") {
96
+ return await strategy.getFlvStrategy(options);
97
+ }
98
+ if (type === "hls") {
99
+ return await strategy.getHlsStrategy(options);
100
+ }
101
+ return { options: {}, plugins: [] };
102
+ };
103
+ var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
104
+ function getDefaultExportFromCjs(x2) {
105
+ return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
106
+ }
107
+ var FUNC_ERROR_TEXT = "Expected a function";
108
+ var NAN = 0 / 0;
109
+ var symbolTag = "[object Symbol]";
110
+ var reTrim = /^\s+|\s+$/g;
111
+ var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
112
+ var reIsBinary = /^0b[01]+$/i;
113
+ var reIsOctal = /^0o[0-7]+$/i;
114
+ var freeParseInt = parseInt;
115
+ var freeGlobal = typeof commonjsGlobal == "object" && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
116
+ var freeSelf = typeof self == "object" && self && self.Object === Object && self;
117
+ var root = freeGlobal || freeSelf || Function("return this")();
118
+ var objectProto = Object.prototype;
119
+ var objectToString = objectProto.toString;
120
+ var nativeMax = Math.max, nativeMin = Math.min;
121
+ var now = function() {
122
+ return root.Date.now();
123
+ };
124
+ function debounce(func, wait, options) {
125
+ var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
126
+ if (typeof func != "function") {
127
+ throw new TypeError(FUNC_ERROR_TEXT);
128
+ }
129
+ wait = toNumber(wait) || 0;
130
+ if (isObject(options)) {
131
+ leading = !!options.leading;
132
+ maxing = "maxWait" in options;
133
+ maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
134
+ trailing = "trailing" in options ? !!options.trailing : trailing;
135
+ }
136
+ function invokeFunc(time) {
137
+ var args = lastArgs, thisArg = lastThis;
138
+ lastArgs = lastThis = void 0;
139
+ lastInvokeTime = time;
140
+ result = func.apply(thisArg, args);
141
+ return result;
142
+ }
143
+ function leadingEdge(time) {
144
+ lastInvokeTime = time;
145
+ timerId = setTimeout(timerExpired, wait);
146
+ return leading ? invokeFunc(time) : result;
147
+ }
148
+ function remainingWait(time) {
149
+ var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime, result2 = wait - timeSinceLastCall;
150
+ return maxing ? nativeMin(result2, maxWait - timeSinceLastInvoke) : result2;
151
+ }
152
+ function shouldInvoke(time) {
153
+ var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime;
154
+ return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
155
+ }
156
+ function timerExpired() {
157
+ var time = now();
158
+ if (shouldInvoke(time)) {
159
+ return trailingEdge(time);
160
+ }
161
+ timerId = setTimeout(timerExpired, remainingWait(time));
162
+ }
163
+ function trailingEdge(time) {
164
+ timerId = void 0;
165
+ if (trailing && lastArgs) {
166
+ return invokeFunc(time);
167
+ }
168
+ lastArgs = lastThis = void 0;
169
+ return result;
170
+ }
171
+ function cancel() {
172
+ if (timerId !== void 0) {
173
+ clearTimeout(timerId);
174
+ }
175
+ lastInvokeTime = 0;
176
+ lastArgs = lastCallTime = lastThis = timerId = void 0;
177
+ }
178
+ function flush() {
179
+ return timerId === void 0 ? result : trailingEdge(now());
180
+ }
181
+ function debounced() {
182
+ var time = now(), isInvoking = shouldInvoke(time);
183
+ lastArgs = arguments;
184
+ lastThis = this;
185
+ lastCallTime = time;
186
+ if (isInvoking) {
187
+ if (timerId === void 0) {
188
+ return leadingEdge(lastCallTime);
189
+ }
190
+ if (maxing) {
191
+ timerId = setTimeout(timerExpired, wait);
192
+ return invokeFunc(lastCallTime);
193
+ }
194
+ }
195
+ if (timerId === void 0) {
196
+ timerId = setTimeout(timerExpired, wait);
197
+ }
198
+ return result;
199
+ }
200
+ debounced.cancel = cancel;
201
+ debounced.flush = flush;
202
+ return debounced;
203
+ }
204
+ function isObject(value) {
205
+ var type = typeof value;
206
+ return !!value && (type == "object" || type == "function");
207
+ }
208
+ function isObjectLike(value) {
209
+ return !!value && typeof value == "object";
210
+ }
211
+ function isSymbol(value) {
212
+ return typeof value == "symbol" || isObjectLike(value) && objectToString.call(value) == symbolTag;
213
+ }
214
+ function toNumber(value) {
215
+ if (typeof value == "number") {
216
+ return value;
217
+ }
218
+ if (isSymbol(value)) {
219
+ return NAN;
220
+ }
221
+ if (isObject(value)) {
222
+ var other = typeof value.valueOf == "function" ? value.valueOf() : value;
223
+ value = isObject(other) ? other + "" : other;
224
+ }
225
+ if (typeof value != "string") {
226
+ return value === 0 ? value : +value;
227
+ }
228
+ value = value.replace(reTrim, "");
229
+ var isBinary = reIsBinary.test(value);
230
+ return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
231
+ }
232
+ var lodash_debounce = debounce;
233
+ var debounce$1 = /* @__PURE__ */ getDefaultExportFromCjs(lodash_debounce);
234
+ const event = window["VePlayer"].event;
235
+ const Events = {
236
+ ...event.Events,
237
+ // 直播的Events
238
+ TIME_SHIFT_CHANGE: "time_shift_change",
239
+ // 切换时移状态
240
+ REFRESH_CLICK: "refresh_click"
241
+ // 触发刷新
242
+ };
243
+ function RefreshIcon() {
244
+ return new DOMParser().parseFromString('<svg width="20" height="20" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M10 2.488a7.48 7.48 0 00-4.154 1.253.908.908 0 101.005 1.512 5.695 5.695 0 018.844 4.746h-.908a.33.33 0 00-.264.528l1.816 2.422a.33.33 0 00.529 0l1.815-2.422A.33.33 0 0018.42 10h-.908A7.511 7.511 0 0010 2.49zM2.489 10a7.511 7.511 0 0011.665 6.26.908.908 0 00-1.005-1.513A5.695 5.695 0 014.305 10h.908a.33.33 0 00.264-.528L3.66 7.05a.33.33 0 00-.528 0L1.317 9.47a.33.33 0 00.264.53h.908z" fill="#fff"/></svg>', "image/svg+xml").firstChild;
245
+ }
246
+ var refresh = "";
247
+ const Plugin$3 = window["VePlayer"].Plugin;
248
+ const Sniffer$1 = window["VePlayer"].Sniffer;
249
+ const XGEvents = window["VePlayer"].XGEvents;
250
+ const { POSITIONS: POSITIONS$1 } = Plugin$3;
251
+ class Refresh extends Plugin$3 {
252
+ static get pluginName() {
253
+ return "refresh";
254
+ }
255
+ static get defaultConfig() {
256
+ return {
257
+ position: POSITIONS$1.CONTROLS_LEFT,
258
+ index: 1,
259
+ disable: false
260
+ };
261
+ }
262
+ afterCreate() {
263
+ if (this.config.disable) {
264
+ return;
265
+ }
266
+ this.appendChild(".xgplayer-icon", this.icons.refresh);
267
+ this._initEvents();
268
+ }
269
+ registerIcons() {
270
+ return {
271
+ refresh: {
272
+ icon: RefreshIcon,
273
+ class: "xgplayer-refresh-svg"
274
+ }
275
+ };
276
+ }
277
+ destroy() {
278
+ this.unbind(["touchend", "click"], this._handleRefresh);
279
+ }
280
+ render() {
281
+ const i18nManager = this.player.config.i18nManager;
282
+ return `
283
+ <xg-icon class="veplayer-refresh">
284
+ <div class="xgplayer-icon">
285
+ </div>
286
+ <div class="xg-tips" lang-key="refresh">${i18nManager.getText(
287
+ "REFRESH"
288
+ )}</div>
289
+ </xg-icon>
290
+ `;
291
+ }
292
+ _handleRefresh(e2) {
293
+ var _a, _b, _c;
294
+ const { player } = this;
295
+ if (!player)
296
+ return;
297
+ e2.preventDefault();
298
+ e2.stopPropagation();
299
+ player.addClass("xgplayer-is-enter");
300
+ player.pause();
301
+ if (player) {
302
+ player.emit(Events.REFRESH_CLICK);
303
+ (_c = (_b = (_a = this.player) == null ? void 0 : _a.config) == null ? void 0 : _b.veplayer) == null ? void 0 : _c.retry();
304
+ }
305
+ player.once(XGEvents.CANPLAY, () => {
306
+ player.removeClass("xgplayer-is-enter");
307
+ });
308
+ }
309
+ _initEvents() {
310
+ this._handleRefresh = debounce$1(this._handleRefresh.bind(this), 200);
311
+ const event2 = Sniffer$1.device === "mobile" ? "touchend" : "click";
312
+ this.bind(event2, this._handleRefresh);
313
+ this.show();
314
+ }
315
+ }
316
+ function _defineProperties(target, props) {
317
+ for (var i2 = 0; i2 < props.length; i2++) {
318
+ var descriptor = props[i2];
319
+ descriptor.enumerable = descriptor.enumerable || false;
320
+ descriptor.configurable = true;
321
+ if ("value" in descriptor)
322
+ descriptor.writable = true;
323
+ Object.defineProperty(target, descriptor.key, descriptor);
324
+ }
325
+ }
326
+ function _createClass(Constructor, protoProps, staticProps) {
327
+ if (protoProps)
328
+ _defineProperties(Constructor.prototype, protoProps);
329
+ if (staticProps)
330
+ _defineProperties(Constructor, staticProps);
331
+ return Constructor;
332
+ }
333
+ function _defineProperty(obj, key, value) {
334
+ if (key in obj) {
335
+ Object.defineProperty(obj, key, {
336
+ value,
337
+ enumerable: true,
338
+ configurable: true,
339
+ writable: true
340
+ });
341
+ } else {
342
+ obj[key] = value;
343
+ }
344
+ return obj;
345
+ }
346
+ function ownKeys(object, enumerableOnly) {
347
+ var keys = Object.keys(object);
348
+ if (Object.getOwnPropertySymbols) {
349
+ var symbols = Object.getOwnPropertySymbols(object);
350
+ if (enumerableOnly)
351
+ symbols = symbols.filter(function(sym) {
352
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
353
+ });
354
+ keys.push.apply(keys, symbols);
355
+ }
356
+ return keys;
357
+ }
358
+ function _objectSpread2(target) {
359
+ for (var i2 = 1; i2 < arguments.length; i2++) {
360
+ var source = arguments[i2] != null ? arguments[i2] : {};
361
+ if (i2 % 2) {
362
+ ownKeys(Object(source), true).forEach(function(key) {
363
+ _defineProperty(target, key, source[key]);
364
+ });
365
+ } else if (Object.getOwnPropertyDescriptors) {
366
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
367
+ } else {
368
+ ownKeys(Object(source)).forEach(function(key) {
369
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
370
+ });
371
+ }
372
+ }
373
+ return target;
374
+ }
375
+ var device_id_key = "xgplayer_device_id";
376
+ var user_id_key = "xgplayer_user_id";
377
+ var getCookie = function getCookie2(key) {
378
+ if (!document.cookie) {
379
+ return null;
380
+ }
381
+ var cookieKVPairs = document.cookie.split(";");
382
+ for (var i2 = 0, len = cookieKVPairs.length; i2 < len; i2++) {
383
+ var pair = cookieKVPairs[i2];
384
+ if (cookieKVPairs[i2].indexOf(key) >= 0) {
385
+ var value = pair.split("=")[1];
386
+ return value || null;
387
+ }
388
+ }
389
+ };
390
+ var genRandomID$1 = function genRandomID2(length) {
391
+ return String(Math.floor(Math.random() * Math.pow(10, length)));
392
+ };
393
+ var getDeviceID$1 = function getDeviceID2() {
394
+ var did = getCookie(device_id_key);
395
+ if (did) {
396
+ return did;
397
+ }
398
+ var newDid = genRandomID$1(11);
399
+ document.cookie = device_id_key + "=" + newDid + ";max-age=31536000;path=/";
400
+ return newDid;
401
+ };
402
+ var getUserId$1 = function getUserId2() {
403
+ var uid = getCookie(user_id_key);
404
+ if (uid) {
405
+ return uid;
406
+ }
407
+ var newUid = genRandomID$1(12);
408
+ document.cookie = user_id_key + "=" + newUid + ";max-age=31536000;path=/";
409
+ return newUid;
410
+ };
411
+ var getLogId = function getLogId2() {
412
+ return genRandomID$1(12);
413
+ };
414
+ function getBrowser() {
415
+ var UserAgent = navigator.userAgent.toLowerCase();
416
+ var browserInfo = {};
417
+ var browserArray = {
418
+ IE: window.ActiveXObject || "ActiveXObject" in window,
419
+ // IE
420
+ Chrome: UserAgent.indexOf("chrome") > -1 && UserAgent.indexOf("safari") > -1,
421
+ // Chrome浏览器
422
+ Firefox: UserAgent.indexOf("firefox") > -1,
423
+ // 火狐浏览器
424
+ Opera: UserAgent.indexOf("opera") > -1,
425
+ // Opera浏览器
426
+ Safari: UserAgent.indexOf("safari") > -1 && UserAgent.indexOf("chrome") == -1,
427
+ // safari浏览器
428
+ Edge: UserAgent.indexOf("edge") > -1,
429
+ // Edge浏览器
430
+ QQBrowser: /qqbrowser/.test(UserAgent),
431
+ // qq浏览器
432
+ WeixinBrowser: /MicroMessenger/i.test(UserAgent)
433
+ // 微信浏览器
434
+ };
435
+ for (var i2 in browserArray) {
436
+ if (browserArray[i2]) {
437
+ var versions = "";
438
+ if (i2 === "IE") {
439
+ versions = UserAgent.match(/(msie\s|trident.*rv:)([\w.]+)/)[2];
440
+ } else if (i2 === "Chrome") {
441
+ for (var mt in navigator.mimeTypes) {
442
+ if (navigator.mimeTypes[mt]["type"] === "application/360softmgrplugin") {
443
+ i2 = "360";
444
+ }
445
+ }
446
+ var match = UserAgent.match(/chrome\/([\d.]+)/);
447
+ versions = match ? match[1] : "-1";
448
+ } else if (i2 === "Firefox") {
449
+ var _match = UserAgent.match(/firefox\/([\d.]+)/);
450
+ versions = _match ? _match[1] : "-1";
451
+ } else if (i2 === "Opera") {
452
+ var _match2 = UserAgent.match(/opera\/([\d.]+)/);
453
+ versions = _match2 ? _match2[1] : "-1";
454
+ } else if (i2 === "Safari") {
455
+ var _match3 = UserAgent.match(/version\/([\d.]+)/);
456
+ versions = _match3 ? _match3[1] : "-1";
457
+ } else if (i2 === "Edge") {
458
+ var _match4 = UserAgent.match(/edge\/([\d.]+)/);
459
+ versions = _match4 ? _match4[1] : "-1";
460
+ } else if (i2 === "QQBrowser") {
461
+ var _match5 = UserAgent.match(/qqbrowser\/([\d.]+)/);
462
+ versions = _match5 ? _match5[1] : "-1";
463
+ }
464
+ browserInfo.type = i2;
465
+ browserInfo.versions = parseInt(versions);
466
+ }
467
+ }
468
+ return browserInfo;
469
+ }
470
+ var sniffer = {
471
+ get device() {
472
+ var r2 = sniffer.os;
473
+ return r2.isPc ? "pc" : "mobile";
474
+ },
475
+ get browser() {
476
+ var _getBrowser = getBrowser(), type = _getBrowser.type, versions = _getBrowser.versions;
477
+ return type + "_" + versions;
478
+ },
479
+ get os() {
480
+ var ua = navigator.userAgent;
481
+ navigator.platform.toLowerCase();
482
+ var isWindowsPhone = /(?:Windows Phone)/.test(ua);
483
+ var isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone;
484
+ var isAndroid = /(?:Android)/.test(ua);
485
+ var isFireFox = /(?:Firefox)/.test(ua);
486
+ var isTablet = /(?:iPad|PlayBook)/.test(ua) || isAndroid && !/(?:Mobile)/.test(ua) || isFireFox && /(?:Tablet)/.test(ua);
487
+ var isPhone = /(?:iPhone)/.test(ua) && !isTablet;
488
+ var isPc = !isPhone && !isAndroid && !isSymbian && !isTablet;
489
+ return {
490
+ isTablet,
491
+ isPhone,
492
+ isAndroid,
493
+ isPc,
494
+ isSymbian,
495
+ isWindowsPhone,
496
+ isFireFox
497
+ };
498
+ },
499
+ get operation_os() {
500
+ var userAgent = navigator.userAgent;
501
+ var clientOpts = [{
502
+ s: "windows",
503
+ r: /(Windows 10.0|Windows NT 10.0|Windows NT 10.1|Windows 8.1|Windows NT 6.3|Windows 8|Windows NT 6.2|Windows 7|Windows NT 6.1)/
504
+ }, {
505
+ s: "android",
506
+ r: /Android/
507
+ }, {
508
+ s: "linux",
509
+ r: /(Linux|X11)/
510
+ }, {
511
+ s: "ios",
512
+ r: /(iPhone|iPad|iPod)/
513
+ }, {
514
+ s: "mac",
515
+ r: /Mac OS X/
516
+ }, {
517
+ s: "mac",
518
+ r: /(MacPPC|MacIntel|Mac_PowerPC|Macintosh)/
519
+ }];
520
+ for (var i2 = 0; i2 < clientOpts.length; i2++) {
521
+ var cs = clientOpts[i2];
522
+ if (cs.r.test(userAgent)) {
523
+ return cs.s;
524
+ }
525
+ }
526
+ return "unknown";
527
+ }
528
+ };
529
+ function getCurrentTime() {
530
+ return Date.now();
531
+ }
532
+ function getPlayFormat(url) {
533
+ var unKnownVal = "unknown";
534
+ if (typeof url !== "string")
535
+ return unKnownVal;
536
+ if (url.indexOf(".flv") > -1)
537
+ return "flv";
538
+ if (url.indexOf(".m3u8") > -1)
539
+ return "m3u8";
540
+ if (url.indexOf(".mp4") > -1)
541
+ return "mp4";
542
+ if (url.indexOf(".sdp") > -1)
543
+ return "rts";
544
+ return unKnownVal;
545
+ }
546
+ function isCodecSupport(codec) {
547
+ return typeof MediaSource !== "undefined" ? +MediaSource.isTypeSupported("video/mp4; codecs=" + codec) : 0;
548
+ }
549
+ function getUrlQuery(url, key) {
550
+ var x2 = new URLSearchParams(url.split("?")[1]);
551
+ return x2.get(key);
552
+ }
553
+ function getDeviceInfo() {
554
+ var res = {
555
+ cpu_core_number: -1,
556
+ memory_usage: -1,
557
+ network_downlink: -1
558
+ };
559
+ try {
560
+ res.cpu_core_number = navigator.hardwareConcurrency || -1;
561
+ res.memory_usage = navigator.deviceMemory || -1;
562
+ res.network_downlink = navigator.connection && navigator.connection.downlink;
563
+ if (res.network_downlink == void 0) {
564
+ res.network_downlink = -1;
565
+ }
566
+ } catch (error2) {
567
+ }
568
+ return res;
569
+ }
570
+ function getPlayerCore(player) {
571
+ if (player.plugins) {
572
+ if (player.plugins.flv) {
573
+ return player.plugins.flv;
574
+ } else if (player.plugins.hls) {
575
+ return player.plugins.hls;
576
+ } else if (player.plugins.rts) {
577
+ return player.plugins.rts;
578
+ } else if (player.plugins.flvlive) {
579
+ return player.plugins.flvlive;
580
+ } else if (player.plugins.hlslive) {
581
+ return player.plugins.hlslive;
582
+ } else if (player.plugins.hlsvod) {
583
+ return player.plugins.hlsvod;
584
+ } else if (player.plugins.hlslivemobile) {
585
+ return player.plugins.hlslivemobile;
586
+ } else if (player.plugins.flvlivemobile) {
587
+ return player.plugins.flvlivemobile;
588
+ }
589
+ }
590
+ return player.newHls || player.newFlv || player.__core__ || player.flv;
591
+ }
592
+ function getDefaultOptions(options) {
593
+ return {
594
+ device_id: options.device_id || getDeviceID$1(),
595
+ user_id: options.user_id || getUserId$1(),
596
+ error_report_stop: !!options.error_report_stop,
597
+ project_key: options.project_key || "live",
598
+ product_line: options.product_line || "live",
599
+ onReport: options.onReport || function() {
600
+ }
601
+ // report 事件回调
602
+ };
603
+ }
604
+ function getDefaultLog() {
605
+ return {
606
+ // 开始播放(以player.play为基准)
607
+ start_play: {
608
+ start_play_time: 0,
609
+ // play 调用时间戳
610
+ event_key: "start_play"
611
+ },
612
+ // 首帧成功
613
+ first_frame: {
614
+ start: 0,
615
+ // 调用播放时间点
616
+ first_frame_view: 0,
617
+ event_key: "first_frame",
618
+ first_sei_delay: 0,
619
+ ntp_sync: 0,
620
+ ntp_delta: 0,
621
+ ttfb: -1,
622
+ // 从开始拉流到返回首字节
623
+ ttdb: -1,
624
+ // 从首字节到渲染出首帧
625
+ ttfb_end: 0
626
+ // 返回首字节unix时间戳
627
+ },
628
+ // 首帧失败
629
+ first_frame_failed: {
630
+ code: void 0,
631
+ msg: "",
632
+ event_key: "first_frame_failed"
633
+ },
634
+ // 卡顿开始
635
+ stall_start: {
636
+ ready_state: -1,
637
+ stall_start_time: 0,
638
+ event_key: "stall_start"
639
+ },
640
+ stalling: {
641
+ // 卡顿中
642
+ event_key: "stalling"
643
+ },
644
+ // 卡顿
645
+ stall: {
646
+ reason: 0,
647
+ // 0,网络卡顿; 1,解码卡顿
648
+ stall_start: 0,
649
+ // 卡顿开始时间戳
650
+ stall_end: 0,
651
+ // 卡顿结束时间戳
652
+ ready_state: 0,
653
+ event_key: "stall"
654
+ },
655
+ // 播放结束
656
+ play_stop: {
657
+ code: 0,
658
+ stop_time: 0,
659
+ // 关闭播放的时间戳, 用户离开页面
660
+ drop_percent: 0,
661
+ is_stream_received: 0,
662
+ // 1,拉到流;0,没有拉到流
663
+ stall_count: 0,
664
+ // 播放中卡顿次数
665
+ stall_time: 0,
666
+ // 播放中卡顿总时长
667
+ // play_time_on_no_frame: 0, //play_stop - start_play的时间
668
+ retry_count: 0,
669
+ // 播放过程中重试总次数
670
+ // first_frame_render_end: 0, //首帧渲染结束时间
671
+ duration: 0,
672
+ stall_count_per_100sec: 0,
673
+ stall_time_per_100sec: 0,
674
+ event_key: "play_stop",
675
+ dns_parse_time: -1,
676
+ redirect: -1,
677
+ ttfb: -1,
678
+ buffered: [],
679
+ is_firstframe_received: 0,
680
+ // 1, 拉到关键帧;0,没拉到关键帧
681
+ meta: null
682
+ },
683
+ // 播放过程中的心跳
684
+ playing: {
685
+ index: 0,
686
+ // playing 发出的第几条日志
687
+ stall_count: 0,
688
+ // 当前playing上报时间间隔卡顿总次数(如果卡顿跨分钟,则按照两次计算)
689
+ stall_time: 0,
690
+ // 当前playing上报时间间隔卡顿总时长
691
+ play_time: 1e4,
692
+ // 当前playing上报时间间隔 计算
693
+ retry_count: 0,
694
+ // 当前playing上报时间间隔重试总次数
695
+ is_last: 0,
696
+ // 调用了play_stop前的最后一个playing,is_last为1. 其他的playing事件时,is_last为0,一分钟上报一次
697
+ video_buffer_time: 0,
698
+ // 播放过程中视频缓冲时长(已经缓冲完成的)
699
+ audio_buffer_time: 0,
700
+ // 与视频相同
701
+ speed_switch_count: 0,
702
+ // 播放速度切换次数
703
+ speed_switch_info: "none",
704
+ // 播放速度切换具体信息
705
+ // sei_delay: 500, // 待处理 端到端延迟
706
+ download_speed: 0,
707
+ // 码率
708
+ // render_fps: this.render_fps, //帧率
709
+ decode_fps: 0,
710
+ render_fps: 0,
711
+ drop_count: 0,
712
+ // 丢帧数
713
+ drop_percent: 0,
714
+ // 丢帧率
715
+ sei_source: "",
716
+ sei_delay: 0,
717
+ ntp_sync: 0,
718
+ ntp_delta: 0,
719
+ // video_download_size: '', //下载大小 flv视频可获取
720
+ // video_play_size: '', // 播放大小 flv视频可获取
721
+ event_key: "playing",
722
+ // ios上部分统计不到play_stop。这里上报play_stop的参数, 以相同live_id最后一次playing统计stop相关数据
723
+ stop_time: 0,
724
+ // 关闭播放的时间戳, 用户离开页面
725
+ // is_stream_received: 1, // 1,拉到流;0,没有拉到流
726
+ duration: 0,
727
+ stall_count_per_100sec: 0,
728
+ stall_time_per_100sec: 0
729
+ // dns_parse_time: -1,
730
+ // redirect: -1,
731
+ // ttfb: -1,
732
+ // buffered: []
733
+ },
734
+ // 播放错误
735
+ play_error: {
736
+ code: void 0,
737
+ info: "",
738
+ event_key: "play_error"
739
+ },
740
+ // (软解) 解码效率低
741
+ play_low_decode: {
742
+ fps: -1,
743
+ decode_fps: -1,
744
+ bitrate: -1,
745
+ url: -1,
746
+ msg: "",
747
+ event_key: "play_low_decode"
748
+ },
749
+ // (软解)音画不同步,常见于丢帧
750
+ play_av_unsync: {
751
+ aDts: -1,
752
+ vDts: -1,
753
+ frameLength: -1,
754
+ currentTime: -1,
755
+ duration: 0,
756
+ event_key: "play_av_unsync"
757
+ },
758
+ // 拉流请求
759
+ play_loadstream: {
760
+ loadstream_url: "",
761
+ event_key: "play_loadstream"
762
+ },
763
+ // 拉到流
764
+ play_stream_loaded: {
765
+ event_key: "play_stream_loaded"
766
+ },
767
+ // 解析到音/视频的meta信息
768
+ play_metadata_loaded: {
769
+ metadata_type: "",
770
+ event_key: "play_metadata_loaded"
771
+ },
772
+ // 流异常,包括时间戳不连续等
773
+ stream_exception: {
774
+ event_key: "stream_exception"
775
+ },
776
+ // 暂停播放
777
+ pause: {
778
+ event_key: "pause"
779
+ },
780
+ // 切换播放链接url
781
+ play_url_change: {
782
+ event_key: "play_url_change"
783
+ },
784
+ // source open事件
785
+ source_opened: {
786
+ event_key: "source_opened"
787
+ },
788
+ // source updated end
789
+ source_updateend: {
790
+ event_key: "source_updateend"
791
+ },
792
+ // 是否起播
793
+ play_result: {
794
+ event_key: "play_result",
795
+ result: 0,
796
+ threshold: 15e3,
797
+ // ms
798
+ is_threshold: 0
799
+ },
800
+ // rts降级
801
+ degrade: {
802
+ event_key: "degrade",
803
+ payload: {}
804
+ },
805
+ // rts state change
806
+ rtcstatechange: {
807
+ event_key: "rtcstatechange"
808
+ }
809
+ };
810
+ }
811
+ function getCommonLog(options) {
812
+ var player = options.player;
813
+ var mediaType = player.config.mediaType;
814
+ return _objectSpread2({
815
+ project_key: options.project_key,
816
+ live_sdk_version: getPlayerCore(player) || player.hlsOps ? "2" : "-1",
817
+ player_sdk_version: player.version,
818
+ // eslint-disable-next-line no-undef
819
+ logger_version: "1.1.0-alpha.5",
820
+ // 由rollup 在编译时注入
821
+ report_version: "5",
822
+ product_line: options.product_line,
823
+ user_id: options.user_id,
824
+ device_id: options.device_id,
825
+ logger_id: getLogId(),
826
+ app_name: options.app_name,
827
+ cdn_ip: options.cdn_ip,
828
+ is_wasm: +(!!mediaType && mediaType !== "video"),
829
+ review_is_live: player.config.isLive ? 2 : 1,
830
+ aid: options.aid,
831
+ live_id: options.live_id || options.aid + "-" + options.user_id + "-" + Date.now(),
832
+ is_preview: options.is_preview ? 1 : 0,
833
+ codec_type: options.codec_type || "h264",
834
+ width: Math.floor(player.config.width),
835
+ height: Math.floor(player.config.height),
836
+ browser: sniffer.browser,
837
+ ua: navigator.userAgent,
838
+ href: window.location.href,
839
+ timestamp: 0,
840
+ fps: -1,
841
+ logger_init_time: Date.now(),
842
+ play_current_time: 0,
843
+ // 播放器播放时刻
844
+ cdn_play_url: player.config.url && player.config.url.startsWith("//") ? window.location.protocol + player.config.url : player.config.url,
845
+ play_format: getPlayFormat(player.config.url),
846
+ codec_support: -1
847
+ }, options.ext);
848
+ }
849
+ function Utf8ArrayToStr(array) {
850
+ var out, i2, len, c2;
851
+ var char2, char3;
852
+ out = "";
853
+ len = array.length;
854
+ i2 = 0;
855
+ while (i2 < len) {
856
+ c2 = array[i2++];
857
+ switch (c2 >> 4) {
858
+ case 0:
859
+ case 1:
860
+ case 2:
861
+ case 3:
862
+ case 4:
863
+ case 5:
864
+ case 6:
865
+ case 7:
866
+ out += String.fromCharCode(c2);
867
+ break;
868
+ case 12:
869
+ case 13:
870
+ char2 = array[i2++];
871
+ out += String.fromCharCode((c2 & 31) << 6 | char2 & 63);
872
+ break;
873
+ case 14:
874
+ char2 = array[i2++];
875
+ char3 = array[i2++];
876
+ out += String.fromCharCode((c2 & 15) << 12 | (char2 & 63) << 6 | (char3 & 63) << 0);
877
+ break;
878
+ }
879
+ }
880
+ return out;
881
+ }
882
+ var getResourceTiming = function getResourceTiming2(url) {
883
+ var founds = performance.getEntriesByType("resource").filter(function(t2) {
884
+ return t2.name === url;
885
+ });
886
+ if (founds.length) {
887
+ var first = founds[0];
888
+ var last = founds[founds.length - 1];
889
+ return {
890
+ dns_parse_time: Number.parseInt(first.domainLookupEnd - first.domainLookupStart),
891
+ redirect: Number.parseInt(first.redirectEnd - first.redirectStart),
892
+ ttfb: Number.parseInt(last.responseStart - last.requestStart)
893
+ };
894
+ } else {
895
+ return {
896
+ dns_parse_time: -1,
897
+ redirect: -1,
898
+ ttfb: -1
899
+ };
900
+ }
901
+ };
902
+ var video_error = {
903
+ "1": "MEDIA_ERR_ABORTED",
904
+ "2": "MEDIA_ERR_NETWORK",
905
+ "3": "MEDIA_ERR_DECODE",
906
+ "4": "MEDIA_ERR_SRC_NOT_SUPPORTED"
907
+ };
908
+ var Manage = /* @__PURE__ */ function() {
909
+ _createClass(Manage2, [{
910
+ key: "videoSize",
911
+ get: function get() {
912
+ if (!this._player || !this._player.video) {
913
+ return {
914
+ width: 0,
915
+ height: 0
916
+ };
917
+ }
918
+ return {
919
+ width: this._player.video.videoWidth,
920
+ height: this._player.video.videoHeight
921
+ };
922
+ }
923
+ }]);
924
+ function Manage2(logOptions) {
925
+ var Tea = logOptions.Tea;
926
+ if (!Tea) {
927
+ throw new Error("lack Tea option");
928
+ }
929
+ if (Tea.event) {
930
+ this.Tea = Tea.event.bind(Tea);
931
+ } else {
932
+ this.Tea = Tea;
933
+ }
934
+ this.logOptions = logOptions;
935
+ this._player = logOptions.player;
936
+ }
937
+ var _proto = Manage2.prototype;
938
+ _proto.push = function push(log) {
939
+ var url = this._player.config.url;
940
+ if (this._player.video) {
941
+ log.play_current_time = this._player.currentTime;
942
+ }
943
+ log.cdn_play_url = url && url.startsWith("//") ? window.location.protocol + url : url;
944
+ log.live_stream_session_id = getUrlQuery(url, "session_id");
945
+ log.play_format = getPlayFormat(url);
946
+ log.timestamp = getCurrentTime();
947
+ var _getDeviceInfo = getDeviceInfo(), cpu_core_number = _getDeviceInfo.cpu_core_number, memory_usage = _getDeviceInfo.memory_usage, network_downlink = _getDeviceInfo.network_downlink;
948
+ log.cpu_core_number = cpu_core_number;
949
+ log.memory_usage = memory_usage;
950
+ log.network_downlink = network_downlink;
951
+ Object.assign(log, _objectSpread2({}, this.videoSize));
952
+ this.send(log);
953
+ };
954
+ _proto.send = function send(log) {
955
+ if (log.event_key) {
956
+ if (this.logOptions.onReport) {
957
+ this.logOptions.onReport(log.event_key, log);
958
+ }
959
+ this.Tea(log.event_key, _objectSpread2({}, log));
960
+ }
961
+ };
962
+ return Manage2;
963
+ }();
964
+ var navgatorOnlineSupported = function navgatorOnlineSupported2() {
965
+ return typeof navigator.onLine !== "undefined";
966
+ };
967
+ var navigatorConnectionType = function navigatorConnectionType2() {
968
+ var _navigator = navigator, connection = _navigator.connection;
969
+ return connection && (connection.effectiveType || connection.type);
970
+ };
971
+ var getNetStat = function getNetStat2() {
972
+ if (navgatorOnlineSupported()) {
973
+ if (navigator.onLine) {
974
+ return navigatorConnectionType() || sniffer.device;
975
+ } else {
976
+ return "none";
977
+ }
978
+ }
979
+ return "unknown";
980
+ };
981
+ var videoEvts = ["play", "playing", "pause", "ended", "error", "seeking", "seeked", "timeupdate", "waiting", "canplay", "canplaythrough", "durationchange", "ratechange", "volumechange", "loadeddata"];
982
+ var LoggerControl = /* @__PURE__ */ function() {
983
+ function LoggerControl2(options) {
984
+ this.options = options;
985
+ this.logger = new XgLiveLogger(options);
986
+ this.restart = this.restart.bind(this);
987
+ this.bindUrlChange();
988
+ sniffer.browser.includes("Chrome");
989
+ }
990
+ var _proto = LoggerControl2.prototype;
991
+ _proto.restart = function restart(report_stop) {
992
+ this.destroy(typeof report_stop === "string" ? false : Boolean(report_stop));
993
+ this.logger = new XgLiveLogger(this.options);
994
+ this.bindUrlChange();
995
+ this.logger.reportStartPlay();
996
+ this.logger.handlePlayerComlete();
997
+ };
998
+ _proto.bindUrlChange = function bindUrlChange() {
999
+ if (this.options && this.options.player && !this.options.manual_restart) {
1000
+ this.options.player.on("urlchange", this.restart);
1001
+ }
1002
+ };
1003
+ _proto.setNTP = function setNTP(ntp) {
1004
+ this.logger.setNTP(ntp);
1005
+ };
1006
+ _proto.updateExt = function updateExt(ext) {
1007
+ this.options.ext = Object.assign(this.options.ext || {}, ext);
1008
+ if (this.logger) {
1009
+ this.logger.updateExt(ext);
1010
+ }
1011
+ };
1012
+ _proto.destroy = function destroy(report_stop) {
1013
+ this.logger.destroy(report_stop);
1014
+ this.logger = null;
1015
+ if (this.options && this.options.player && !this.options.manual_restart) {
1016
+ this.options.player.off("urlchange", this.restart);
1017
+ }
1018
+ };
1019
+ return LoggerControl2;
1020
+ }();
1021
+ var XgLiveLogger = /* @__PURE__ */ function() {
1022
+ _createClass(XgLiveLogger2, [{
1023
+ key: "videoSize",
1024
+ get: function get() {
1025
+ if (!this.player) {
1026
+ return {
1027
+ width: 0,
1028
+ height: 0
1029
+ };
1030
+ }
1031
+ return {
1032
+ width: this.player.video.videoWidth,
1033
+ height: this.player.video.videoHeight
1034
+ };
1035
+ }
1036
+ }, {
1037
+ key: "player",
1038
+ get: function get() {
1039
+ return this._player;
1040
+ }
1041
+ }, {
1042
+ key: "logmanager",
1043
+ get: function get() {
1044
+ return this._logmanager;
1045
+ }
1046
+ }, {
1047
+ key: "ntpTime",
1048
+ get: function get() {
1049
+ return Date.now() - this.ntpDelta;
1050
+ }
1051
+ }]);
1052
+ function XgLiveLogger2(options) {
1053
+ if (!options.player) {
1054
+ throw new Error("option player is necessary");
1055
+ }
1056
+ this.options = Object.assign({}, options, getDefaultOptions(options));
1057
+ this._player = this.options.player;
1058
+ this._url = this._player.config.url;
1059
+ this.project_key = options.project_key || "live";
1060
+ this.product_line = options.product_line || "live";
1061
+ this.ntpDelta = this.options.ntp ? Date.now() - this.options.ntp : 0;
1062
+ this.inWaitingStart = 0;
1063
+ this.errorNumber = 0;
1064
+ this.tempDroppedFrameCount = 0;
1065
+ this.tempTotalFrameCount = 0;
1066
+ this._logmanager = new Manage(this.options);
1067
+ this.init();
1068
+ this.started = false;
1069
+ this.destroyed = false;
1070
+ this.completed = false;
1071
+ this.firstFrameViewed = false;
1072
+ this.cacheRtcStats = {};
1073
+ }
1074
+ var _proto2 = XgLiveLogger2.prototype;
1075
+ _proto2.setNTP = function setNTP(ntp) {
1076
+ if (this.options) {
1077
+ this.options.ntp = ntp;
1078
+ this.ntpDelta = Date.now() - this.options.ntp;
1079
+ }
1080
+ };
1081
+ _proto2.init = function init() {
1082
+ this.bindCtx();
1083
+ this.initLog();
1084
+ this.initEvt();
1085
+ };
1086
+ _proto2.bindCtx = function bindCtx() {
1087
+ this.handlePlayerComlete = this.handlePlayerComlete.bind(this);
1088
+ this.handlePlayerPlaying = this.handlePlayerPlaying.bind(this);
1089
+ this.destroyFunc = this.destroyFunc.bind(this);
1090
+ this.handleUserLeave = this.handleUserLeave.bind(this);
1091
+ this.handlePlayerError = this.handlePlayerError.bind(this);
1092
+ this.handlePlayerReady = this.handlePlayerReady.bind(this);
1093
+ this.handlePlayerWaiting = this.handlePlayerWaiting.bind(this);
1094
+ this.handleAVUnsync = this.handleAVUnsync.bind(this);
1095
+ this.handlePlayerPause = this.handlePlayerPause.bind(this);
1096
+ this.handleTTFB = this.handleTTFB.bind(this);
1097
+ this.handleUrlChange = this.handleUrlChange.bind(this);
1098
+ this.handleKeyframe = this.handleKeyframe.bind(this);
1099
+ this.handleSourceOpen = this.handleSourceOpen.bind(this);
1100
+ this.handleBufferAppend = this.handleBufferAppend.bind(this);
1101
+ this.handleCoreEvent = this.handleCoreEvent.bind(this);
1102
+ this.handleDegrade = this.handleDegrade.bind(this);
1103
+ };
1104
+ _proto2.initLog = function initLog() {
1105
+ var _this = this;
1106
+ var options = this.options;
1107
+ var player = options.player;
1108
+ var isHLS = player.hlsOps !== void 0;
1109
+ this.commonParams = _objectSpread2({
1110
+ os: sniffer.operation_os
1111
+ }, getCommonLog(options));
1112
+ this.log = Object.assign({}, getDefaultLog());
1113
+ var self2 = this;
1114
+ for (var logKey in this.log) {
1115
+ var _loop = function _loop2(commonKey2) {
1116
+ Object.defineProperty(_this.log[logKey], commonKey2, {
1117
+ get: function get() {
1118
+ if (this["_" + commonKey2] == void 0)
1119
+ return self2.commonParams[commonKey2];
1120
+ return this["_" + commonKey2];
1121
+ },
1122
+ set: function set(val) {
1123
+ this["_" + commonKey2] = val;
1124
+ },
1125
+ enumerable: true
1126
+ });
1127
+ };
1128
+ for (var commonKey in this.commonParams) {
1129
+ _loop(commonKey);
1130
+ }
1131
+ if (isHLS) {
1132
+ Object.defineProperty(this.log[logKey], "m3u8", {
1133
+ get: function get() {
1134
+ if (player.__core__) {
1135
+ var m3u8Text = player.__core__.m3u8Text;
1136
+ if (m3u8Text) {
1137
+ return m3u8Text.slice(0, 500 * 500);
1138
+ }
1139
+ return "";
1140
+ }
1141
+ return "";
1142
+ },
1143
+ enumerable: true
1144
+ });
1145
+ }
1146
+ Object.defineProperty(this.log[logKey], "volume", {
1147
+ get: function get() {
1148
+ if (!player || !player.video)
1149
+ return;
1150
+ return player.volume || 0;
1151
+ },
1152
+ enumerable: true
1153
+ });
1154
+ Object.defineProperty(this.log[logKey], "access", {
1155
+ get: function get() {
1156
+ return getNetStat();
1157
+ },
1158
+ enumerable: true
1159
+ });
1160
+ }
1161
+ };
1162
+ _proto2.updateExt = function updateExt(ext) {
1163
+ for (var logKey in this.log) {
1164
+ for (var extKey in ext) {
1165
+ this.log[logKey][extKey] = ext[extKey];
1166
+ }
1167
+ }
1168
+ };
1169
+ _proto2.reportStartPlay = function reportStartPlay() {
1170
+ if (!this.started) {
1171
+ this.started = true;
1172
+ this.log.start_play.start_play_time = this.log.start_play.timestamp = getCurrentTime();
1173
+ this.logmanager.push(this.log.start_play, true);
1174
+ }
1175
+ };
1176
+ _proto2.initWindowListener = function initWindowListener() {
1177
+ if (sniffer.device === "pc") {
1178
+ window.addEventListener("beforeunload", this.handleUserLeave);
1179
+ } else if (sniffer.device === "mobile") {
1180
+ window.addEventListener("beforeunload", this.handleUserLeave);
1181
+ window.addEventListener("pagehide", this.handleUserLeave);
1182
+ }
1183
+ };
1184
+ _proto2.removeWindowListener = function removeWindowListener() {
1185
+ if (sniffer.device === "pc") {
1186
+ window.removeEventListener("beforeunload", this.handleUserLeave);
1187
+ } else if (sniffer.device === "mobile") {
1188
+ window.removeEventListener("beforeunload", this.handleUserLeave);
1189
+ window.removeEventListener("pagehide", this.handleUserLeave);
1190
+ }
1191
+ };
1192
+ _proto2.initEvt = function initEvt() {
1193
+ var _this2 = this;
1194
+ var player = this.player;
1195
+ videoEvts.forEach(function(name) {
1196
+ _this2["handleVideo" + name + "Evt"] = function() {
1197
+ _this2["handleVideo" + name] && _this2["handleVideo" + name]();
1198
+ };
1199
+ _this2.initWindowListener();
1200
+ _this2.bindVideoEvt(name, _this2["handleVideo" + name + "Evt"]);
1201
+ });
1202
+ player.once("error", this.handlePlayerError);
1203
+ player.once("complete", this.handlePlayerComlete);
1204
+ player.once("playing", this.handlePlayerPlaying);
1205
+ player.once("timeupdate", this.handlePlayerPlaying);
1206
+ player.once("destroy", this.destroyFunc);
1207
+ player.on("ready", this.handlePlayerReady);
1208
+ player.on("waiting", this.handlePlayerWaiting);
1209
+ player.on("pause", this.handlePlayerPause);
1210
+ player.on("urlchange", this.handleUrlChange);
1211
+ player.once("sourceopen", this.handleSourceOpen);
1212
+ player.once("bufferappend", this.handleBufferAppend);
1213
+ player.on("core_event", this.handleCoreEvent);
1214
+ player.on("degrade", this.handleDegrade);
1215
+ this.hiJackPlayerStart();
1216
+ };
1217
+ _proto2.handleCoreEvent = function handleCoreEvent(info) {
1218
+ var eventName = info.eventName, headers = info.headers, pts = info.pts, type = info.type, meta = info.meta, sei = info.sei, decodeFps = info.decodeFps, url = info.url, state = info.state;
1219
+ switch (eventName) {
1220
+ case "core.ttfb":
1221
+ this.handleTTFB(info);
1222
+ break;
1223
+ case "core.loadresponseheaders":
1224
+ var serverIp = headers.get("X-Server-Ip");
1225
+ if (this.player.hlsOps !== void 0) {
1226
+ this.log.play_stop.review_ts_count += 1;
1227
+ }
1228
+ if (serverIp) {
1229
+ this.commonParams.cdn_ip = serverIp;
1230
+ }
1231
+ break;
1232
+ case "core.loadretry":
1233
+ this.log.play_stop.retry_count++;
1234
+ break;
1235
+ case "core.keyframe":
1236
+ this.handleKeyframe(pts);
1237
+ break;
1238
+ case "core.metadataparsed":
1239
+ this.handleMetaDataLoaded(type, meta);
1240
+ break;
1241
+ case "core.sei":
1242
+ this.handleSEIParsed(sei);
1243
+ break;
1244
+ case "core.lowdecode":
1245
+ if (this.commonParams.is_wasm) {
1246
+ Object.assign(this.log.play_low_decode, info || {});
1247
+ this.log.play_low_decode.decode_fps = decodeFps;
1248
+ this.log.play_low_decode.timestamp = getCurrentTime();
1249
+ this.logmanager.push(this.log.play_low_decode, true);
1250
+ this.commonParams.is_wasm = 0;
1251
+ }
1252
+ break;
1253
+ case "core.largeavgap":
1254
+ this.handleAVUnsync(info);
1255
+ break;
1256
+ case "core.loadstart":
1257
+ this.handlePlayerLoadStream(info);
1258
+ this.reportStartPlay();
1259
+ break;
1260
+ case "core.loadcomplete":
1261
+ this.handlePlayerLoadedStream(info);
1262
+ break;
1263
+ case "core.streamexception":
1264
+ this.handleStreamException(info);
1265
+ break;
1266
+ case "core.rtcstatechange":
1267
+ this.logmanager.push(Object.assign({
1268
+ url,
1269
+ state
1270
+ }, this.log.rtcstatechange));
1271
+ break;
1272
+ }
1273
+ };
1274
+ _proto2.handleDegrade = function handleDegrade(payload) {
1275
+ this.log.degrade.payload = payload;
1276
+ this.logmanager.push(this.log.degrade, true);
1277
+ };
1278
+ _proto2.hiJackPlayerStart = function hiJackPlayerStart() {
1279
+ var _arguments = arguments, _this3 = this;
1280
+ this.player._start = this.player.start;
1281
+ var player = this.player;
1282
+ player.start = function() {
1283
+ try {
1284
+ if (player._start) {
1285
+ return player._start.apply(player, Array.prototype.slice.call(_arguments, 0));
1286
+ }
1287
+ } catch (e2) {
1288
+ }
1289
+ if (!_this3.destroyed) {
1290
+ _this3.handlePlayerComlete();
1291
+ }
1292
+ };
1293
+ };
1294
+ _proto2.handleTTFB = function handleTTFB(params) {
1295
+ var _ref = params || {}, end = _ref.end, elapsed = _ref.elapsed;
1296
+ this.log.first_frame.ttfb = elapsed || -1;
1297
+ this.log.first_frame.ttfb_end = end || 0;
1298
+ };
1299
+ _proto2.handleUrlChange = function handleUrlChange(url) {
1300
+ this.logmanager.push(Object.assign(this.log.play_url_change, {
1301
+ url,
1302
+ timestamp: getCurrentTime()
1303
+ }));
1304
+ };
1305
+ _proto2.handleKeyframe = function handleKeyframe(pts) {
1306
+ this.log.play_stop.is_firstframe_received = 1;
1307
+ this.log.play_stop.firstframe_pts = pts;
1308
+ };
1309
+ _proto2.handleSourceOpen = function handleSourceOpen() {
1310
+ this.log.source_opened.timestamp = getCurrentTime();
1311
+ this.logmanager.push(this.log.source_opened);
1312
+ };
1313
+ _proto2.handleBufferAppend = function handleBufferAppend() {
1314
+ this.log.source_updateend.timestamp = getCurrentTime();
1315
+ this.logmanager.push(this.log.source_updateend);
1316
+ };
1317
+ _proto2.handlePlayerPause = function handlePlayerPause() {
1318
+ this.log.pause.timestamp = getCurrentTime();
1319
+ this.logmanager.push(this.log.pause, true);
1320
+ this.stallEnd();
1321
+ };
1322
+ _proto2.handlePlayerError = function handlePlayerError(err) {
1323
+ this.errorNumber = 1;
1324
+ var errorType = err.errorType;
1325
+ var code = err.errorCode;
1326
+ Object.assign(this.log.play_error, _objectSpread2({
1327
+ timestamp: getCurrentTime(),
1328
+ code: err.httpCode || code || (errorType === "parse" ? 31 : 21),
1329
+ info: err.message,
1330
+ detail: JSON.stringify(err)
1331
+ }, this.videoSize));
1332
+ this.logmanager.push(this.log.play_error, true);
1333
+ if (this.destroyed) {
1334
+ return;
1335
+ }
1336
+ if (this.log.first_frame.first_frame_view === 0) {
1337
+ Object.assign(this.log.first_frame_failed, {
1338
+ code: code || (errorType === "parse" ? 31 : 21),
1339
+ msg: err.message
1340
+ });
1341
+ if (this.log.first_frame_failed.timestamp !== void 0) {
1342
+ this.log.first_frame_failed.timestamp = getCurrentTime();
1343
+ }
1344
+ this.logmanager.push(this.log.first_frame_failed, true);
1345
+ if (!this.log.play_result.is_threshold) {
1346
+ this.clearPlayResultTimer();
1347
+ this.log.play_result.reason = err.message || "first frame failed";
1348
+ this.log.play_result.code = this.log.play_error.code;
1349
+ this.logmanager.push(this.log.play_result, true);
1350
+ }
1351
+ }
1352
+ if (this.options.error_report_stop) {
1353
+ this.handleUserLeave();
1354
+ } else {
1355
+ this.updatePlayStopParams();
1356
+ }
1357
+ };
1358
+ _proto2.handlePlayerLoadStream = function handlePlayerLoadStream(info) {
1359
+ var url = info.url, offersdp = info.offersdp, sessionId = info.sessionId;
1360
+ if (typeof url !== "string") {
1361
+ return;
1362
+ }
1363
+ var play_loadstream = this.log.play_loadstream;
1364
+ play_loadstream.timestamp = getCurrentTime();
1365
+ play_loadstream.loadstream_url = url;
1366
+ play_loadstream.offersdp = offersdp;
1367
+ play_loadstream.sessionId = sessionId;
1368
+ this.logmanager.push(play_loadstream);
1369
+ };
1370
+ _proto2.handlePlayerLoadedStream = function handlePlayerLoadedStream(info) {
1371
+ var play_stream_loaded = this.log.play_stream_loaded;
1372
+ play_stream_loaded.timestamp = getCurrentTime();
1373
+ Object.assign(play_stream_loaded, info);
1374
+ this.logmanager.push(play_stream_loaded);
1375
+ };
1376
+ _proto2.handleSEIParsed = function handleSEIParsed(sei) {
1377
+ var _this$log = this.log, playing = _this$log.playing, first_frame = _this$log.first_frame;
1378
+ if (sei.code === 100) {
1379
+ var seiString = Utf8ArrayToStr(sei.content);
1380
+ seiString = seiString.slice(seiString.indexOf("{"), seiString.lastIndexOf("}") + 1);
1381
+ try {
1382
+ var seiContent = JSON.parse(seiString);
1383
+ var seiDelay = this.getPlayerBuffer() + this.ntpTime - seiContent.ts;
1384
+ playing.sei_delay = seiDelay;
1385
+ playing.sei_source = seiContent.source;
1386
+ playing.ntp_sync = this.options.ntp ? 1 : 0;
1387
+ playing.ntp_delta = this.ntp_delta;
1388
+ first_frame.first_sei_delay = seiDelay;
1389
+ first_frame.ntp_sync = this.options.ntp ? 1 : 0;
1390
+ first_frame.ntp_delta = this.ntp_delta;
1391
+ } catch (e2) {
1392
+ }
1393
+ }
1394
+ };
1395
+ _proto2.handleMetaDataLoaded = function handleMetaDataLoaded(type, meta) {
1396
+ this.log.play_stop.meta = this.log.play_stop.meta || {};
1397
+ if (type) {
1398
+ this.log.play_stop.meta[type] = meta;
1399
+ }
1400
+ this.log.play_metadata_loaded.timestamp = getCurrentTime();
1401
+ this.log.play_metadata_loaded.metadata_type = type;
1402
+ if (meta) {
1403
+ this.log.play_metadata_loaded.meta = meta;
1404
+ this.log.play_metadata_loaded.codec = meta.codec;
1405
+ if (type === "video") {
1406
+ this.commonParams.codec_type = meta.codec;
1407
+ this.commonParams.codec_support = isCodecSupport(meta.codec);
1408
+ }
1409
+ }
1410
+ if (!meta) {
1411
+ this.log.play_metadata_loaded.meta = void 0;
1412
+ this.log.play_metadata_loaded.codec = void 0;
1413
+ if (type === "video") {
1414
+ this.commonParams.codec_type = "unknown";
1415
+ }
1416
+ }
1417
+ this.logmanager.push(this.log.play_metadata_loaded);
1418
+ };
1419
+ _proto2.handleAVUnsync = function handleAVUnsync(unsyncInfo) {
1420
+ Object.assign(this.log.play_av_unsync, unsyncInfo || {});
1421
+ this.log.play_av_unsync.timestamp = getCurrentTime();
1422
+ this.logmanager.push(this.log.play_av_unsync, false);
1423
+ };
1424
+ _proto2.handleStreamException = function handleStreamException(info) {
1425
+ this.logmanager.push(Object.assign({}, this.log.stream_exception, info));
1426
+ };
1427
+ _proto2.handlePlayerComlete = function handlePlayerComlete() {
1428
+ if (this.completed) {
1429
+ return;
1430
+ }
1431
+ this.completed = true;
1432
+ this.core = getPlayerCore(this.player);
1433
+ if (this.core) {
1434
+ this.commonParams.live_sdk_version = "2";
1435
+ }
1436
+ if (this.player.config.autoplay || this.player.config.videoInit) {
1437
+ this.reportStartPlay();
1438
+ }
1439
+ };
1440
+ _proto2.getPlayerBuffer = function getPlayerBuffer() {
1441
+ var buffered = this.player.video.buffered;
1442
+ if (buffered) {
1443
+ var bufferIdx = Math.max(0, buffered.length - 1);
1444
+ try {
1445
+ var bufferedTime = Number.parseInt((buffered.end(bufferIdx) - this.player.video.currentTime) * 1e3);
1446
+ this.log.playing.audio_buffer_time = this.log.playing.video_buffer_time = bufferedTime;
1447
+ return bufferedTime;
1448
+ } catch (e2) {
1449
+ return 0;
1450
+ }
1451
+ }
1452
+ };
1453
+ _proto2.getPlayerDownloadSpeed = function getPlayerDownloadSpeed() {
1454
+ if (this.core && this.core.core) {
1455
+ if (typeof this.core.core.speedInfo === "function") {
1456
+ return this.core.core.speedInfo().speed;
1457
+ }
1458
+ }
1459
+ };
1460
+ _proto2.getPlayerQuality = function getPlayerQuality() {
1461
+ var video = this.player.video;
1462
+ if (video.getVideoPlaybackQuality) {
1463
+ var quality = video.getVideoPlaybackQuality();
1464
+ this.log.playing.drop_count = quality.droppedVideoFrames - this.tempDroppedFrameCount;
1465
+ this.log.playing.drop_percent = Number.parseFloat(this.tempTotalFrameCount / quality.totalVideoFrames).toFixed(1);
1466
+ this.log.play_stop.drop_percent = Number.parseFloat(quality.droppedVideoFrames / quality.totalVideoFrames).toFixed(1);
1467
+ this.tempDroppedFrameCount = quality.droppedVideoFrames;
1468
+ this.tempTotalFrameCount = quality.totalVideoFrames;
1469
+ }
1470
+ };
1471
+ _proto2.getRtcStats = function getRtcStats(duration, first) {
1472
+ try {
1473
+ var _this5 = this;
1474
+ var rtm = _this5.player.plugins.rts || _this5.player.plugins.rtm;
1475
+ var pc = rtm && rtm.pc;
1476
+ var rtc_stats = {};
1477
+ if (!pc)
1478
+ return Promise.resolve(rtc_stats);
1479
+ return Promise.resolve(pc.getStats()).then(function(tmp) {
1480
+ tmp.forEach(function(stat) {
1481
+ var type = stat.type, mediaType = stat.mediaType, bytesReceived = stat.bytesReceived, packetsReceived = stat.packetsReceived, audioLevel = stat.audioLevel, concealmentEvents = stat.concealmentEvents, remoteTimestamp = stat.remoteTimestamp, timestamp = stat.timestamp, framesDropped = stat.framesDropped, keyFramesDecoded = stat.keyFramesDecoded, totalDecodeTime = stat.totalDecodeTime, framesDecoded = stat.framesDecoded, frameHeight = stat.frameHeight, frameWidth = stat.frameWidth, framesReceived = stat.framesReceived, jitterBufferDelay = stat.jitterBufferDelay, jitterBufferEmittedCount = stat.jitterBufferEmittedCount, jitter = stat.jitter, nackCount = stat.nackCount, packetsLost = stat.packetsLost, pliCount = stat.pliCount, totalSamplesReceived = stat.totalSamplesReceived, concealedSamples = stat.concealedSamples, currentRoundTripTime = stat.currentRoundTripTime, decoderImplementation = stat.decoderImplementation, mimeType = stat.mimeType, freezeCount = stat.freezeCount, totalFreezesDuration = stat.totalFreezesDuration, totalPausesDuration = stat.totalPausesDuration;
1482
+ switch (type) {
1483
+ case "inbound-rtp":
1484
+ if (mediaType === "audio") {
1485
+ rtc_stats.audio_bytes_received = bytesReceived - (_this5.cacheRtcStats.audioBytesReceived || 0);
1486
+ _this5.cacheRtcStats.audioBytesReceived = bytesReceived;
1487
+ rtc_stats.audio_packets_lost = packetsLost - (_this5.cacheRtcStats.audioPacketsLost || 0);
1488
+ rtc_stats.audio_packets_received = packetsReceived - (_this5.cacheRtcStats.audioPacketsReceived || 0);
1489
+ _this5.cacheRtcStats.audioPacketsLost = packetsLost;
1490
+ _this5.cacheRtcStats.audioPacketsReceived = packetsReceived;
1491
+ rtc_stats.audio_level = audioLevel;
1492
+ rtc_stats.concealment_event = concealmentEvents;
1493
+ rtc_stats.audio_fraction_lost = rtc_stats.audio_packets_lost / rtc_stats.audio_packets_received;
1494
+ if (_this5.cacheRtcStats.totalSamplesReceived !== void 0) {
1495
+ rtc_stats.audio_rec_sample_rate = (totalSamplesReceived - _this5.cacheRtcStats.totalSamplesReceived) / duration;
1496
+ }
1497
+ _this5.cacheRtcStats.totalSamplesReceived = totalSamplesReceived;
1498
+ rtc_stats.concealed_samples = concealedSamples;
1499
+ rtc_stats.total_samples_received = totalSamplesReceived;
1500
+ } else {
1501
+ rtc_stats.frames_dropped = framesDropped;
1502
+ rtc_stats.iframes_decoded = keyFramesDecoded;
1503
+ rtc_stats.video_bytes_received = bytesReceived - (_this5.cacheRtcStats.videoBytesReceived || 0);
1504
+ _this5.cacheRtcStats.videoBytesReceived = bytesReceived;
1505
+ rtc_stats.video_dec_time = totalDecodeTime;
1506
+ rtc_stats.video_decoded_delay_ms = rtc_stats.video_dec_elapse / framesDecoded;
1507
+ rtc_stats.video_frame_height = frameHeight;
1508
+ rtc_stats.video_frame_width = frameWidth;
1509
+ if (_this5.cacheRtcStats.framesDecoded !== void 0) {
1510
+ rtc_stats.video_decode_framerate = (framesDecoded - _this5.cacheRtcStats.framesDecoded) / duration;
1511
+ }
1512
+ _this5.cacheRtcStats.framesDecoded = framesDecoded;
1513
+ if (_this5.cacheRtcStats.framesReceived !== void 0) {
1514
+ rtc_stats.video_recv_framerate = (framesReceived - _this5.cacheRtcStats.framesReceived) / duration;
1515
+ }
1516
+ if (_this5.cacheRtcStats.freezeCount !== void 0) {
1517
+ rtc_stats.freeze_count = freezeCount - _this5.cacheRtcStats.freezeCount;
1518
+ rtc_stats.freeze_duration = totalFreezesDuration - _this5.cacheRtcStats.totalFreezesDuration;
1519
+ }
1520
+ _this5.cacheRtcStats.freezeCount = freezeCount;
1521
+ _this5.cacheRtcStats.totalFreezesDuration = totalFreezesDuration;
1522
+ _this5.cacheRtcStats.framesReceived = framesReceived;
1523
+ rtc_stats.total_pauses_duration = totalPausesDuration;
1524
+ rtc_stats.video_jb_delay = jitterBufferDelay / jitterBufferEmittedCount * 1e3;
1525
+ rtc_stats.video_jitter = jitter * 1e3;
1526
+ rtc_stats.video_nack_count = nackCount;
1527
+ rtc_stats.video_packets_lost = packetsLost - (_this5.cacheRtcStats.videoPacketsLost || 0);
1528
+ rtc_stats.video_packets_received = packetsReceived - (_this5.cacheRtcStats.videoPacketsReceived || 0);
1529
+ rtc_stats.video_fraction_lost = rtc_stats.video_packets_lost / rtc_stats.video_packets_received;
1530
+ _this5.cacheRtcStats.videoPacketsLost = packetsLost;
1531
+ _this5.cacheRtcStats.videoPacketsReceived = packetsReceived;
1532
+ rtc_stats.video_pli_count = pliCount;
1533
+ rtc_stats.decoder_name = decoderImplementation;
1534
+ }
1535
+ break;
1536
+ case "remote-outbound-rtp":
1537
+ rtc_stats.e2e_delay_ms = timestamp - remoteTimestamp;
1538
+ break;
1539
+ case "track":
1540
+ if (frameWidth !== void 0) {
1541
+ rtc_stats.video_frame_width = frameWidth;
1542
+ rtc_stats.video_frame_height = frameHeight;
1543
+ }
1544
+ break;
1545
+ case "candidate-pair":
1546
+ rtc_stats.rtt = currentRoundTripTime * 1e3;
1547
+ break;
1548
+ case "codec":
1549
+ if (mimeType.includes("video")) {
1550
+ rtc_stats.video_codec = mimeType;
1551
+ } else {
1552
+ rtc_stats.audio_codec = mediaType;
1553
+ }
1554
+ }
1555
+ rtc_stats.total_delay = rtc_stats.e2e_delay_ms + (rtc_stats.video_decoded_delay_ms || 0) + (rtc_stats.video_jb_delay || 0);
1556
+ });
1557
+ Object.assign(_this5.log.playing, {
1558
+ video_download_size: rtc_stats.video_bytes_received,
1559
+ decode_fps: rtc_stats.video_decode_framerate,
1560
+ sei_delay: rtc_stats.total_delay,
1561
+ sei_network_delay: rtc_stats.e2e_delay_ms,
1562
+ width: rtc_stats.video_frame_width,
1563
+ height: rtc_stats.video_frame_height,
1564
+ current_speed: (rtc_stats.audio_bytes_received + rtc_stats.video_bytes_received) / duration
1565
+ });
1566
+ return rtc_stats;
1567
+ });
1568
+ } catch (e2) {
1569
+ return Promise.reject(e2);
1570
+ }
1571
+ };
1572
+ _proto2.reportPlaying = function reportPlaying(first) {
1573
+ try {
1574
+ var _this7 = this;
1575
+ if (_this7.commonParams.is_wasm) {
1576
+ _this7.commonParams.fps = _this7.player.video.fps;
1577
+ _this7.log.playing.render_fps = _this7.player.video.fps;
1578
+ _this7.log.playing.decode_fps = _this7.player.video.decodeFps;
1579
+ }
1580
+ _this7.log.playing.index++;
1581
+ var lastPlayingTime = _this7.log.playing.timestamp;
1582
+ var stallTime;
1583
+ if (_this7.inWaitingStart && _this7.inWaitingStart < getCurrentTime()) {
1584
+ stallTime = Math.min(_this7.options.playingInterval || _this7.log.playing.play_time, getCurrentTime() - Math.max(_this7.inWaitingStart, lastPlayingTime));
1585
+ }
1586
+ _this7.getPlayerQuality();
1587
+ _this7.getPlayerBuffer();
1588
+ if (!_this7.options.downloadSpeedInterval) {
1589
+ _this7.log.playing.current_speed = _this7.getPlayerDownloadSpeed();
1590
+ }
1591
+ var now2 = getCurrentTime();
1592
+ var playedTime = now2 - lastPlayingTime;
1593
+ var stall_time = (stallTime > 200 ? stallTime : 0) + _this7.log.playing.stall_time;
1594
+ var stall_count = (stallTime > 200 ? 1 : 0) + _this7.log.playing.stall_count;
1595
+ if (_this7.options.aggregationDowngradeStallTime) {
1596
+ _this7.log.playing.aggregation_downgrade_stall = (stallTime > _this7.options.aggregationDowngradeStallTime ? stallTime : 0) + (_this7.log.playing.aggregation_downgrade_stall || 0);
1597
+ }
1598
+ Object.assign(_this7.log.playing, _objectSpread2({
1599
+ timestamp: now2,
1600
+ // 60s内存在多次触发playing
1601
+ stop_time: now2,
1602
+ duration: first ? 0 : playedTime / 1e3,
1603
+ stall_time_per_100sec: stall_time / playedTime * 100,
1604
+ // 计算百秒卡顿时长
1605
+ stall_count_per_100sec: stall_count * 1e3 / playedTime * 100,
1606
+ // 计算百秒卡顿次数
1607
+ stall_count,
1608
+ // playing前会有一次卡顿现处于waiting状态
1609
+ stall_time,
1610
+ play_current_time: _this7.player.currentTime
1611
+ }, _this7.videoSize));
1612
+ return Promise.resolve(_this7.getRtcStats(playedTime, first)).then(function(stats) {
1613
+ _this7.logmanager.push(Object.assign({}, _this7.log.playing, _objectSpread2({
1614
+ play_time: first ? 0 : playedTime
1615
+ }, stats)), true);
1616
+ _this7.log.playing.download_speed_array = [];
1617
+ _this7.log.playing.stall_time = 0;
1618
+ _this7.log.playing.stall_count = 0;
1619
+ if (_this7.options.aggregationDowngradeStallTime) {
1620
+ _this7.log.playing.aggregation_downgrade_stall = 0;
1621
+ }
1622
+ });
1623
+ } catch (e2) {
1624
+ return Promise.reject(e2);
1625
+ }
1626
+ };
1627
+ _proto2.handlePlayerPlaying = function handlePlayerPlaying() {
1628
+ try {
1629
+ var _this9 = this;
1630
+ if (_this9.player && _this9.player.video.readyState < 3) {
1631
+ return Promise.resolve();
1632
+ }
1633
+ _this9.player.off("playing", _this9.handlePlayerPlaying);
1634
+ _this9.player.off("timeupdate", _this9.handlePlayerPlaying);
1635
+ if (_this9.core) {
1636
+ var _ref2 = _this9.core.getStats() || {}, fps = _ref2.fps;
1637
+ _this9.commonParams.fps = fps;
1638
+ }
1639
+ return Promise.resolve(_this9.reportPlaying(true)).then(function() {
1640
+ _this9.clearPlayingInterval();
1641
+ var timer = _this9.options.playingInterval || _this9.log.playing.play_time;
1642
+ _this9.intervalId = setInterval(function() {
1643
+ try {
1644
+ var _temp4 = function() {
1645
+ if (Math.abs(Date.now() - _this9.log.playing.timestamp - timer) < 100 || Date.now() - _this9.log.playing.timestamp >= timer) {
1646
+ var _temp5 = function() {
1647
+ if (!_this9.player.video) {
1648
+ _this9.destroyFunc();
1649
+ } else {
1650
+ var _temp6 = function() {
1651
+ if (_this9.player.paused) {
1652
+ _this9.handleVideopause();
1653
+ } else {
1654
+ return Promise.resolve(_this9.reportPlaying()).then(function() {
1655
+ });
1656
+ }
1657
+ }();
1658
+ if (_temp6 && _temp6.then)
1659
+ return _temp6.then(function() {
1660
+ });
1661
+ }
1662
+ }();
1663
+ if (_temp5 && _temp5.then)
1664
+ return _temp5.then(function() {
1665
+ });
1666
+ }
1667
+ }();
1668
+ return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(function() {
1669
+ }) : void 0);
1670
+ } catch (e2) {
1671
+ return Promise.reject(e2);
1672
+ }
1673
+ }, 1e3);
1674
+ _this9.clearStallTimer();
1675
+ _this9.handleVideoplaying();
1676
+ if (!_this9.started) {
1677
+ _this9.reportStartPlay();
1678
+ }
1679
+ _this9.saveBuffered();
1680
+ });
1681
+ } catch (e2) {
1682
+ return Promise.reject(e2);
1683
+ }
1684
+ };
1685
+ _proto2.handlePlayerReady = function handlePlayerReady() {
1686
+ var _this10 = this;
1687
+ this.log.start_play.start_play_time = getCurrentTime();
1688
+ if (this.player.config.autoplay) {
1689
+ this.reportStartPlay();
1690
+ }
1691
+ if (this.options.playResultThreshold) {
1692
+ this.log.play_result.threshold = this.options.playResultThreshold;
1693
+ }
1694
+ this.clearPlayResultTimer();
1695
+ this.log.play_result.start = getCurrentTime();
1696
+ this.playResultTimer = setTimeout(function() {
1697
+ if (_this10.log.play_result.timestamp >= _this10.log.play_result.start)
1698
+ return;
1699
+ _this10.log.play_result.is_threshold = 1;
1700
+ _this10.logmanager.push(_this10.log.play_result, true);
1701
+ }, this.log.play_result.threshold);
1702
+ };
1703
+ _proto2.handlePlayerWaiting = function handlePlayerWaiting() {
1704
+ var _this11 = this;
1705
+ if (!!this.inWaitingStart || !this.log.first_frame.timestamp)
1706
+ return;
1707
+ this.log.stall.timestamp = this.inWaitingStart = this.log.stall.stall_start = getCurrentTime();
1708
+ this.log.stall_start.ready_state = this.log.stall.ready_state = this.player.video.readyState;
1709
+ this.log.stall_start.timestamp = getCurrentTime();
1710
+ this.log.stall_start.stall_start_time = getCurrentTime();
1711
+ this.log.stall_start.video_buffer_time = this.player.video.readyState;
1712
+ this.log.stall_start.play_current_time = this.player.currentTime;
1713
+ this.log.stall.play_current_time = this.player.currentTime;
1714
+ this.log.stall_start.buffered = this.getBuffered();
1715
+ this.log.stall.buffered = this.log.stall_start.buffered;
1716
+ this.log.stall.current_speed = this.getPlayerDownloadSpeed();
1717
+ Object.assign(this.log.stall_start, this.videoSize);
1718
+ this.clearStallTimer();
1719
+ this.stallStartTimer = setTimeout(function() {
1720
+ _this11.logmanager.push(_this11.log.stall_start, true);
1721
+ }, 205);
1722
+ };
1723
+ _proto2.handleVideoseeking = function handleVideoseeking() {
1724
+ if (!this.player || !this.player.video)
1725
+ return;
1726
+ if (this.inWaitingStart && this.player.video.duration < Infinity) {
1727
+ this.inWaitingStart = 0;
1728
+ this.clearStallTimer();
1729
+ }
1730
+ };
1731
+ _proto2.handleVideoseeked = function handleVideoseeked() {
1732
+ if (!this.player || !this.player.video)
1733
+ return;
1734
+ if (this.inWaitingStart && this.player.video.duration < Infinity) {
1735
+ this.inWaitingStart = 0;
1736
+ this.log.play_stop.stall_count > 0 && this.log.play_stop.stall_count--;
1737
+ }
1738
+ };
1739
+ _proto2.handleVideoplay = function handleVideoplay() {
1740
+ this.reportStartPlay();
1741
+ this.removeVideoEvt("play", this.handleVideoplay);
1742
+ };
1743
+ _proto2.handleVideotimeupdate = function handleVideotimeupdate() {
1744
+ if (Math.abs(this.player.currentTime - this.log.stall_start.play_current_time) > 0.2) {
1745
+ this.stallEnd();
1746
+ }
1747
+ this.saveBuffered();
1748
+ };
1749
+ _proto2.handleVideocanplay = function handleVideocanplay() {
1750
+ this.stallEnd();
1751
+ this.reportFirstframe();
1752
+ };
1753
+ _proto2.handleVideoplaying = function handleVideoplaying() {
1754
+ this.stallEnd();
1755
+ this.log.play_stop.is_stream_received = 1;
1756
+ var currentTime = getCurrentTime();
1757
+ this.reportStartPlay();
1758
+ this.log.first_frame.start = currentTime;
1759
+ };
1760
+ _proto2.stallEnd = function stallEnd() {
1761
+ this.clearStallTimer();
1762
+ var currentTime = getCurrentTime();
1763
+ if (this.inWaitingStart) {
1764
+ var diff = currentTime - this.inWaitingStart;
1765
+ if (diff > 200) {
1766
+ this.log.play_stop.stall_count++;
1767
+ this.log.play_stop.stall_time += currentTime - this.inWaitingStart;
1768
+ this.log.playing.stall_time += currentTime - Math.max(this.inWaitingStart, this.log.playing.timestamp);
1769
+ this.log.stall.stall_end = currentTime;
1770
+ this.log.stall.timestamp = getCurrentTime();
1771
+ this.log.playing.stall_count++;
1772
+ Object.assign(this.log.stall, _objectSpread2({}, this.videoSize));
1773
+ this.logmanager.push(this.log.stall, true);
1774
+ }
1775
+ if (this.options.aggregationDowngradeStallTime && diff > this.options.aggregationDowngradeStallTime) {
1776
+ this.log.playing.aggregation_downgrade_stall = (this.log.playing.aggregation_downgrade_stall || 0) + (currentTime - Math.max(this.inWaitingStart, this.log.playing.timestamp));
1777
+ }
1778
+ }
1779
+ this.inWaitingStart = 0;
1780
+ };
1781
+ _proto2.handleVideoloadeddata = function handleVideoloadeddata() {
1782
+ this.reportFirstframe();
1783
+ };
1784
+ _proto2.handleVideoratechange = function handleVideoratechange() {
1785
+ this.log.playing.speed_switch_count++;
1786
+ this.log.playing.speed_switch_info = this.player.video.playbackRate;
1787
+ };
1788
+ _proto2.handleVideoended = function handleVideoended() {
1789
+ this.clearPlayingInterval();
1790
+ this.clearStallTimer();
1791
+ Object.assign(this.log.playing, _objectSpread2({
1792
+ timestamp: getCurrentTime(),
1793
+ is_last: 1
1794
+ }, this.videoSize));
1795
+ this.logmanager.push(this.log.playing);
1796
+ };
1797
+ _proto2.handleVideoerror = function handleVideoerror() {
1798
+ var _this12 = this;
1799
+ this.errorNumber = 1;
1800
+ var error2 = this.player.video.error;
1801
+ var firstframeFailed = function firstframeFailed2() {
1802
+ if (_this12.log.first_frame.first_frame_view === 0 && !_this12.log.first_frame_failed.code) {
1803
+ if (error2) {
1804
+ _this12.log.first_frame_failed.code = error2.code;
1805
+ _this12.log.first_frame_failed.msg = video_error[error2.code];
1806
+ if (_this12.log.first_frame_failed.timestamp !== void 0) {
1807
+ _this12.log.first_frame_failed.timestamp = getCurrentTime();
1808
+ }
1809
+ _this12.logmanager.push(_this12.log.first_frame_failed, true);
1810
+ if (!_this12.log.play_result.is_threshold) {
1811
+ _this12.log.play_result.reason = video_error[error2.code] || "first frame failed";
1812
+ _this12.log.play_result.code = error2.code;
1813
+ _this12.clearPlayResultTimer();
1814
+ _this12.logmanager.push(_this12.log.play_result, true);
1815
+ }
1816
+ }
1817
+ }
1818
+ if (_this12.options.error_report_stop) {
1819
+ _this12.handleUserLeave();
1820
+ } else {
1821
+ _this12.updatePlayStopParams();
1822
+ }
1823
+ };
1824
+ Object.assign(this.log.play_error, _objectSpread2(_objectSpread2({
1825
+ timestamp: getCurrentTime()
1826
+ }, this.videoSize), error2 && {
1827
+ code: error2.code,
1828
+ info: error2.message
1829
+ }));
1830
+ this.logmanager.push(this.log.play_error, true);
1831
+ firstframeFailed();
1832
+ };
1833
+ _proto2.handleVideopause = function handleVideopause() {
1834
+ this.stallEnd();
1835
+ this.clearPlayingInterval();
1836
+ this.clearStallTimer();
1837
+ clearTimeout(this.collectDownloadSpeedTimer);
1838
+ this.player.once("playing", this.handlePlayerPlaying);
1839
+ this.player.once("timeupdate", this.handlePlayerPlaying);
1840
+ };
1841
+ _proto2.destroyFunc = function destroyFunc(no_report_stop) {
1842
+ var _this13 = this;
1843
+ if (this.destroyed) {
1844
+ return;
1845
+ }
1846
+ if (!no_report_stop) {
1847
+ this.handleUserLeave();
1848
+ }
1849
+ this.destroyed = true;
1850
+ if (sniffer.device === "pc") {
1851
+ window.removeEventListener("beforeunload", this.handleUserLeave);
1852
+ } else if (sniffer.device === "mobile") {
1853
+ window.removeEventListener("pagehide", this.handleUserLeave);
1854
+ }
1855
+ videoEvts.forEach(function(name) {
1856
+ _this13.removeVideoEvt(name, _this13["handleVideo" + name + "Evt"]);
1857
+ });
1858
+ if (this.player) {
1859
+ if (this.player._start) {
1860
+ this.player.start = this.player._start;
1861
+ delete this.player._start;
1862
+ }
1863
+ this.player.off("destroy", this.destroyFunc);
1864
+ this.player.off("complete", this.handlePlayerComlete);
1865
+ this.player.off("playing", this.handlePlayerPlaying);
1866
+ this.player.off("timeupdate", this.handlePlayerPlaying);
1867
+ this.player.off("ready", this.handlePlayerReady);
1868
+ this.player.off("waiting", this.handlePlayerWaiting);
1869
+ this.player.off("largeavgap", this.handleAVUnsync);
1870
+ this.player.off("error", this.handlePlayerError);
1871
+ this.player.off("SEI_PARSED", this.handleSEIParsed);
1872
+ this.player.off("pause", this.handlePlayerPause);
1873
+ this.player.off("ttfb", this.handleTTFB);
1874
+ this.player.off("urlchange", this.handleUrlChange);
1875
+ this.player.off("isKeyframe", this.handleKeyframe);
1876
+ this.player.off("sourceopen", this.handleSourceOpen);
1877
+ this.player.off("bufferappend", this.handleBufferAppend);
1878
+ this.player.off("core_event", this.handleCoreEvent);
1879
+ this.player.off("degrade", this.handleDegrade);
1880
+ this.clearPlayingInterval();
1881
+ this.clearStallTimer();
1882
+ this.clearPlayResultTimer();
1883
+ clearTimeout(this.collectDownloadSpeedTimer);
1884
+ this._player = null;
1885
+ }
1886
+ };
1887
+ _proto2.handleUserLeave = function handleUserLeave() {
1888
+ if (this.destroyed || !this.started) {
1889
+ return;
1890
+ }
1891
+ this.destroyed = true;
1892
+ this.updatePlayStopParams();
1893
+ this.reportPlayStop();
1894
+ this.clearPlayingInterval();
1895
+ this.clearStallTimer();
1896
+ clearTimeout(this.collectDownloadSpeedTimer);
1897
+ this.removeWindowListener();
1898
+ };
1899
+ _proto2.saveBuffered = function saveBuffered() {
1900
+ try {
1901
+ var buffered = this.getBuffered();
1902
+ if (buffered && buffered.length) {
1903
+ this.log.play_stop.buffered = buffered;
1904
+ }
1905
+ } catch (error2) {
1906
+ }
1907
+ };
1908
+ _proto2.getBuffered = function getBuffered() {
1909
+ try {
1910
+ var buffered = [];
1911
+ var video = this.player.video;
1912
+ for (var i2 = 0; i2 < video.buffered.length; i2++) {
1913
+ buffered.push([video.buffered.start(i2), video.buffered.end(i2)]);
1914
+ }
1915
+ return buffered;
1916
+ } catch (error2) {
1917
+ }
1918
+ };
1919
+ _proto2.reportPlayStop = function reportPlayStop() {
1920
+ this.log.play_stop.play_current_time = this.player.currentTime || this.log.playing.play_current_time;
1921
+ this.saveBuffered();
1922
+ this.logmanager.push(this.log.play_stop, true);
1923
+ };
1924
+ _proto2.reportFirstframe = function reportFirstframe() {
1925
+ if (this.firstFrameViewed) {
1926
+ return;
1927
+ }
1928
+ if (this.core) {
1929
+ var _ref3 = this.core.getStats() || {}, fps = _ref3.fps;
1930
+ this.commonParams.fps = fps;
1931
+ }
1932
+ this.firstFrameViewed = true;
1933
+ var currentTime = getCurrentTime();
1934
+ Object.assign(this.log.first_frame, _objectSpread2({
1935
+ first_frame_view: currentTime - this.log.start_play.start_play_time || currentTime,
1936
+ timestamp: currentTime
1937
+ }, this.videoSize));
1938
+ if (this.log.first_frame.ttfb_end) {
1939
+ this.log.first_frame.ttdb = currentTime - this.log.first_frame.ttfb_end;
1940
+ }
1941
+ this.logmanager.push(this.log.first_frame, true);
1942
+ this.clearPlayResultTimer();
1943
+ this.log.play_result.result = 1;
1944
+ this.logmanager.push(this.log.play_result, true);
1945
+ this.log.play_stop.is_stream_received = 1;
1946
+ };
1947
+ _proto2.updatePlayStopParams = function updatePlayStopParams() {
1948
+ var timing = getResourceTiming(this._url);
1949
+ var endTime = getCurrentTime();
1950
+ this.playedTime = endTime - this.log.start_play.start_play_time;
1951
+ var play_stop = this.log.play_stop;
1952
+ Object.assign(play_stop, _objectSpread2({}, play_stop.stall_count === 0 && {
1953
+ stall_time: 0
1954
+ }));
1955
+ if (this.inWaitingStart && endTime - this.inWaitingStart > 200) {
1956
+ play_stop.stall_time += endTime - this.inWaitingStart;
1957
+ }
1958
+ this.inWaitingStart = 0;
1959
+ Object.assign(play_stop, _objectSpread2({
1960
+ stall_time_per_100sec: play_stop.stall_time / this.playedTime * 100,
1961
+ // 计算百秒卡顿时长
1962
+ stall_count_per_100sec: play_stop.stall_count * 1e3 / this.playedTime * 100
1963
+ }, timing));
1964
+ if (this.log.play_stop.stall_count_per_100sec === 0) {
1965
+ this.log.play_stop.stall_time_per_100sec = 0;
1966
+ }
1967
+ if (this.log.play_stop.stall_time_per_100sec > 100 || this.log.play_stop.stall_time_per_100sec < 0) {
1968
+ return;
1969
+ }
1970
+ if (this.log.playing.index) {
1971
+ Object.assign(this.log.playing, _objectSpread2({
1972
+ timestamp: getCurrentTime(),
1973
+ is_last: 1
1974
+ }, this.videoSize));
1975
+ this.logmanager.push(this.log.playing, true);
1976
+ } else {
1977
+ this.log.play_stop.error_code = this.log.play_error.code;
1978
+ this.log.play_stop.error_info = this.log.play_error.info;
1979
+ }
1980
+ endTime = getCurrentTime();
1981
+ Object.assign(play_stop, _objectSpread2({
1982
+ timestamp: endTime,
1983
+ stop_time: endTime,
1984
+ duration: this.playedTime / 1e3,
1985
+ play_time: this.playedTime / 1e3
1986
+ }, this.videoSize));
1987
+ if (this.errorNumber === 0) {
1988
+ play_stop.play_time_on_no_frame = play_stop.stop_time - this.log.start_play.start_play_time;
1989
+ }
1990
+ };
1991
+ _proto2.clearPlayingInterval = function clearPlayingInterval() {
1992
+ if (this.intervalId) {
1993
+ clearInterval(this.intervalId);
1994
+ this.intervalId = null;
1995
+ }
1996
+ };
1997
+ _proto2.clearStallTimer = function clearStallTimer() {
1998
+ clearTimeout(this.stallStartTimer);
1999
+ };
2000
+ _proto2.clearPlayResultTimer = function clearPlayResultTimer() {
2001
+ clearTimeout(this.playResultTimer);
2002
+ };
2003
+ _proto2.destroy = function destroy(report_stop) {
2004
+ this.destroyFunc(!report_stop);
2005
+ };
2006
+ _proto2.bindVideoEvt = function bindVideoEvt(name, handleFunc) {
2007
+ if (!this.player)
2008
+ return;
2009
+ this.player.video.addEventListener(name, handleFunc, false);
2010
+ };
2011
+ _proto2.removeVideoEvt = function removeVideoEvt(name, handleFunc) {
2012
+ if (!this.player || !this.player.video)
2013
+ return;
2014
+ this.player.video.removeEventListener(name, handleFunc, false);
2015
+ };
2016
+ _proto2.send = function send(log, retryTime) {
2017
+ this.logmanager.send(log, retryTime);
2018
+ };
2019
+ return XgLiveLogger2;
2020
+ }();
2021
+ var e = function() {
2022
+ return e = Object.assign || function(e2) {
2023
+ for (var t2, i2 = 1, n2 = arguments.length; i2 < n2; i2++)
2024
+ for (var o2 in t2 = arguments[i2])
2025
+ Object.prototype.hasOwnProperty.call(t2, o2) && (e2[o2] = t2[o2]);
2026
+ return e2;
2027
+ }, e.apply(this, arguments);
2028
+ };
2029
+ function t(e2, t2) {
2030
+ var i2 = "function" == typeof Symbol && e2[Symbol.iterator];
2031
+ if (!i2)
2032
+ return e2;
2033
+ var n2, o2, r2 = i2.call(e2), s2 = [];
2034
+ try {
2035
+ for (; (void 0 === t2 || t2-- > 0) && !(n2 = r2.next()).done; )
2036
+ s2.push(n2.value);
2037
+ } catch (e3) {
2038
+ o2 = { error: e3 };
2039
+ } finally {
2040
+ try {
2041
+ n2 && !n2.done && (i2 = r2.return) && i2.call(r2);
2042
+ } finally {
2043
+ if (o2)
2044
+ throw o2.error;
2045
+ }
2046
+ }
2047
+ return s2;
2048
+ }
2049
+ function i() {
2050
+ for (var e2 = [], i2 = 0; i2 < arguments.length; i2++)
2051
+ e2 = e2.concat(t(arguments[i2]));
2052
+ return e2;
2053
+ }
2054
+ var n, o = function() {
2055
+ function e2() {
2056
+ this._hooks = {}, this._cache = [], this._hooksCache = {};
2057
+ }
2058
+ return e2.prototype.on = function(e3, t2) {
2059
+ e3 && t2 && "function" == typeof t2 && (this._hooks[e3] || (this._hooks[e3] = []), this._hooks[e3].push(t2));
2060
+ }, e2.prototype.once = function(e3, t2) {
2061
+ var i2 = this;
2062
+ if (e3 && t2 && "function" == typeof t2) {
2063
+ this.on(e3, function n2(o2) {
2064
+ t2(o2), i2.off(e3, n2);
2065
+ });
2066
+ }
2067
+ }, e2.prototype.off = function(e3, t2) {
2068
+ if (e3 && this._hooks[e3] && this._hooks[e3].length)
2069
+ if (t2) {
2070
+ var i2 = this._hooks[e3].indexOf(t2);
2071
+ -1 !== i2 && this._hooks[e3].splice(i2, 1);
2072
+ } else
2073
+ this._hooks[e3] = [];
2074
+ }, e2.prototype.emit = function(e3, t2, i2) {
2075
+ if (i2) {
2076
+ if (!e3)
2077
+ return;
2078
+ -1 !== this._cache.indexOf(i2) ? this._emit(e3, t2) : (this._hooksCache.hasOwnProperty(i2) || (this._hooksCache[i2] = {}), this._hooksCache[i2].hasOwnProperty(e3) || (this._hooksCache[i2][e3] = []), this._hooksCache[i2][e3].push(t2));
2079
+ } else
2080
+ this._emit(e3, t2);
2081
+ }, e2.prototype._emit = function(e3, t2) {
2082
+ e3 && this._hooks[e3] && this._hooks[e3].length && i(this._hooks[e3]).forEach(function(e4) {
2083
+ try {
2084
+ e4(t2);
2085
+ } catch (e5) {
2086
+ }
2087
+ });
2088
+ }, e2.prototype.set = function(e3) {
2089
+ e3 && -1 === this._cache.indexOf(e3) && this._cache.push(e3);
2090
+ }, e2;
2091
+ }(), r = function(e2) {
2092
+ return null != e2 && "[object Object]" == Object.prototype.toString.call(e2);
2093
+ }, s = (n = +Date.now() + Number(("" + Math.random()).slice(2, 8)), function() {
2094
+ return n += 1;
2095
+ }), a = function(e2) {
2096
+ return function(e3, t2, i2) {
2097
+ if ("string" == typeof e3 && "number" == typeof t2 && "number" == typeof i2) {
2098
+ var n2, o2 = [];
2099
+ i2 = i2 <= 25 ? i2 : i2 % 25;
2100
+ var r2 = String.fromCharCode(i2 + 97);
2101
+ n2 = e3.split(r2);
2102
+ for (var s2 = 0; s2 < n2.length; s2++) {
2103
+ var a2 = parseInt(n2[s2], i2);
2104
+ a2 = 1 * a2 ^ t2;
2105
+ var c2 = String.fromCharCode(a2);
2106
+ o2.push(c2);
2107
+ }
2108
+ return o2.join("");
2109
+ }
2110
+ }(e2, 64, 25);
2111
+ }, c = function(e2) {
2112
+ var t2 = document.createElement("a");
2113
+ return t2.href = e2, t2;
2114
+ }, h = function() {
2115
+ function e2(e3) {
2116
+ this.appid = e3, this.userAgent = window.navigator.userAgent, this.appVersion = window.navigator.appVersion;
2117
+ }
2118
+ return e2.prototype.init = function() {
2119
+ var e3 = window.navigator.userAgent, t2 = window.navigator.language, i2 = document.referrer, n2 = i2 ? c(i2).hostname : "";
2120
+ !function(e4) {
2121
+ var t3 = {};
2122
+ try {
2123
+ var i3 = c(e4).search;
2124
+ (i3 = i3.slice(1)).split("&").forEach(function(e5) {
2125
+ var i4, n3, o3 = e5.split("=");
2126
+ o3.length && (i4 = o3[0], n3 = o3[1]);
2127
+ try {
2128
+ t3[i4] = decodeURIComponent(void 0 === n3 ? "" : n3);
2129
+ } catch (e6) {
2130
+ t3[i4] = n3;
2131
+ }
2132
+ });
2133
+ } catch (e5) {
2134
+ }
2135
+ }(window.location.href);
2136
+ var o2 = /Mobile|htc|mini|Android|iP(ad|od|hone)/.test(this.appVersion) ? "wap" : "web", r2 = this.browser(), s2 = this.os();
2137
+ return { browser: r2.browser, browser_version: r2.browser_version, platform: o2, os_name: s2.os_name, os_version: s2.os_version, userAgent: e3, screen_width: window.screen && window.screen.width, screen_height: window.screen && window.screen.height, device_model: this.getDeviceModel(s2.os_name), language: t2, referrer: i2, referrer_host: n2 };
2138
+ }, e2.prototype.browser = function() {
2139
+ var e3, t2, i2 = "", n2 = "" + parseFloat(this.appVersion), o2 = this.userAgent;
2140
+ return -1 !== o2.indexOf("Edge") || -1 !== o2.indexOf("Edg") ? (i2 = "Microsoft Edge", -1 !== o2.indexOf("Edge") ? (e3 = o2.indexOf("Edge"), n2 = o2.substring(e3 + 5)) : (e3 = o2.indexOf("Edg"), n2 = o2.substring(e3 + 4))) : -1 !== (e3 = o2.indexOf("MSIE")) ? (i2 = "Microsoft Internet Explorer", n2 = o2.substring(e3 + 5)) : -1 !== (e3 = o2.indexOf("Lark")) ? (i2 = "Lark", n2 = o2.substring(e3 + 5, e3 + 11)) : -1 !== (e3 = o2.indexOf("MetaSr")) ? (i2 = "sougoubrowser", n2 = o2.substring(e3 + 7, e3 + 10)) : -1 !== o2.indexOf("MQQBrowser") || -1 !== o2.indexOf("QQBrowser") ? (i2 = "qqbrowser", -1 !== o2.indexOf("MQQBrowser") ? (e3 = o2.indexOf("MQQBrowser"), n2 = o2.substring(e3 + 11, e3 + 15)) : -1 !== o2.indexOf("QQBrowser") && (e3 = o2.indexOf("QQBrowser"), n2 = o2.substring(e3 + 10, e3 + 17))) : -1 !== o2.indexOf("Chrome") ? -1 !== (e3 = o2.indexOf("MicroMessenger")) ? (i2 = "weixin", n2 = o2.substring(e3 + 15, e3 + 20)) : -1 !== (e3 = o2.indexOf("360")) ? (i2 = "360browser", n2 = o2.substring(o2.indexOf("Chrome") + 7)) : -1 !== o2.indexOf("baidubrowser") || -1 !== o2.indexOf("BIDUBrowser") ? (-1 !== o2.indexOf("baidubrowser") ? (e3 = o2.indexOf("baidubrowser"), n2 = o2.substring(e3 + 13, e3 + 16)) : -1 !== o2.indexOf("BIDUBrowser") && (e3 = o2.indexOf("BIDUBrowser"), n2 = o2.substring(e3 + 12, e3 + 15)), i2 = "baidubrowser") : -1 !== (e3 = o2.indexOf("xiaomi")) ? -1 !== o2.indexOf("openlanguagexiaomi") ? (i2 = "openlanguage xiaomi", n2 = o2.substring(e3 + 7, e3 + 13)) : (i2 = "xiaomi", n2 = o2.substring(e3 - 7, e3 - 1)) : -1 !== (e3 = o2.indexOf("TTWebView")) ? (i2 = "TTWebView", n2 = o2.substring(e3 + 10, e3 + 23)) : (-1 !== (e3 = o2.indexOf("Chrome")) || -1 !== (e3 = o2.indexOf("Chrome"))) && (i2 = "Chrome", n2 = o2.substring(e3 + 7)) : -1 !== o2.indexOf("Safari") ? -1 !== (e3 = o2.indexOf("QQ")) ? (i2 = "qqbrowser", n2 = o2.substring(e3 + 10, e3 + 16)) : -1 !== (e3 = o2.indexOf("Safari")) && (i2 = "Safari", n2 = o2.substring(e3 + 7), -1 !== (e3 = o2.indexOf("Version")) && (n2 = o2.substring(e3 + 8))) : -1 !== (e3 = o2.indexOf("Firefox")) ? (i2 = "Firefox", n2 = o2.substring(e3 + 8)) : -1 !== (e3 = o2.indexOf("MicroMessenger")) ? (i2 = "weixin", n2 = o2.substring(e3 + 15, e3 + 20)) : -1 !== (e3 = o2.indexOf("QQ")) ? (i2 = "qqbrowser", n2 = o2.substring(e3 + 3, e3 + 8)) : -1 !== (e3 = o2.indexOf("Opera")) && (i2 = "Opera", n2 = o2.substring(e3 + 6), -1 !== (e3 = o2.indexOf("Version")) && (n2 = o2.substring(e3 + 8))), -1 !== (t2 = n2.indexOf(";")) && (n2 = n2.substring(0, t2)), -1 !== (t2 = n2.indexOf(" ")) && (n2 = n2.substring(0, t2)), -1 !== (t2 = n2.indexOf(")")) && (n2 = n2.substring(0, t2)), { browser: i2, browser_version: n2 };
2141
+ }, e2.prototype.os = function() {
2142
+ for (var e3 = "", t2 = "", i2 = [{ s: "Windows 10", r: /(Windows 10.0|Windows NT 10.0|Windows NT 10.1)/ }, { s: "Windows 8.1", r: /(Windows 8.1|Windows NT 6.3)/ }, { s: "Windows 8", r: /(Windows 8|Windows NT 6.2)/ }, { s: "Windows 7", r: /(Windows 7|Windows NT 6.1)/ }, { s: "Android", r: /Android/ }, { s: "Sun OS", r: /SunOS/ }, { s: "Linux", r: /(Linux|X11)/ }, { s: "iOS", r: /(iPhone|iPad|iPod)/ }, { s: "Mac OS X", r: /Mac OS X/ }, { s: "Mac OS", r: /(MacPPC|MacIntel|Mac_PowerPC|Macintosh)/ }], n2 = 0; n2 < i2.length; n2++) {
2143
+ var o2 = i2[n2];
2144
+ if (o2.r.test(this.userAgent)) {
2145
+ "Mac OS X" === (e3 = o2.s) && this.isNewIpad() && (e3 = "iOS");
2146
+ break;
2147
+ }
2148
+ }
2149
+ var r2 = function(e4, t3) {
2150
+ var i3 = e4.exec(t3);
2151
+ return i3 && i3[1] ? i3[1] : "";
2152
+ }, s2 = function(e4, t3) {
2153
+ var i3 = RegExp("(?:^|[^A-Z0-9-_]|[^A-Z0-9-]_|sprd-)(?:" + e4 + ")", "i").exec(t3);
2154
+ return i3 ? i3.slice(1)[0] : "";
2155
+ };
2156
+ /Windows/.test(e3) && (t2 = r2(/Windows (.*)/, e3), e3 = "windows");
2157
+ var a2, c2;
2158
+ switch (e3) {
2159
+ case "Mac OS X":
2160
+ t2 = s2("Mac[ +]OS[ +]X(?:[ /](?:Version )?(\\d+(?:[_\\.]\\d+)+))?", this.userAgent), e3 = "mac";
2161
+ break;
2162
+ case "Android":
2163
+ a2 = this.userAgent, (c2 = r2(/Android ([\.\_\d]+)/, a2)) || (c2 = r2(/Android\/([\.\_\d]+)/, a2)), t2 = c2, e3 = "android";
2164
+ break;
2165
+ case "iOS":
2166
+ t2 = this.isNewIpad() ? s2("Mac[ +]OS[ +]X(?:[ /](?:Version )?(\\d+(?:[_\\.]\\d+)+))?", this.userAgent) : (t2 = /OS (\d+)_(\d+)_?(\d+)?/.exec(this.appVersion)) ? t2[1] + "." + t2[2] + "." + (0 | t2[3]) : "", e3 = "ios";
2167
+ }
2168
+ return { os_name: e3, os_version: t2 };
2169
+ }, e2.prototype.getDeviceModel = function(e3) {
2170
+ var t2 = "";
2171
+ try {
2172
+ if ("android" === e3)
2173
+ navigator.userAgent.split(";").forEach(function(e4) {
2174
+ e4.indexOf("Build/") > -1 && (t2 = e4.slice(0, e4.indexOf("Build/")));
2175
+ });
2176
+ else if ("ios" === e3 || "mac" === e3 || "windows" === e3)
2177
+ if (this.isNewIpad())
2178
+ t2 = "iPad";
2179
+ else {
2180
+ var i2 = navigator.userAgent.replace("Mozilla/5.0 (", ""), n2 = i2.indexOf(";");
2181
+ t2 = i2.slice(0, n2);
2182
+ }
2183
+ } catch (e4) {
2184
+ return t2.trim();
2185
+ }
2186
+ return t2.trim();
2187
+ }, e2.prototype.isNewIpad = function() {
2188
+ return void 0 !== this.userAgent && "MacIntel" === navigator.platform && "number" == typeof navigator.maxTouchPoints && navigator.maxTouchPoints > 1;
2189
+ }, e2;
2190
+ }();
2191
+ var u, p, f = (u = function(e2, t2) {
2192
+ e2.exports = function() {
2193
+ function e3(e4) {
2194
+ for (var t4 = 1; t4 < arguments.length; t4++) {
2195
+ var i2 = arguments[t4];
2196
+ for (var n2 in i2)
2197
+ e4[n2] = i2[n2];
2198
+ }
2199
+ return e4;
2200
+ }
2201
+ function t3(i2, n2) {
2202
+ function o2(t4, o3, r3) {
2203
+ if ("undefined" != typeof document) {
2204
+ "number" == typeof (r3 = e3({}, n2, r3)).expires && (r3.expires = new Date(Date.now() + 864e5 * r3.expires)), r3.expires && (r3.expires = r3.expires.toUTCString()), t4 = encodeURIComponent(t4).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
2205
+ var s2 = "";
2206
+ for (var a2 in r3)
2207
+ r3[a2] && (s2 += "; " + a2, true !== r3[a2] && (s2 += "=" + r3[a2].split(";")[0]));
2208
+ return document.cookie = t4 + "=" + i2.write(o3, t4) + s2;
2209
+ }
2210
+ }
2211
+ function r2(e4) {
2212
+ if ("undefined" != typeof document && (!arguments.length || e4)) {
2213
+ for (var t4 = document.cookie ? document.cookie.split("; ") : [], n3 = {}, o3 = 0; o3 < t4.length; o3++) {
2214
+ var r3 = t4[o3].split("="), s2 = r3.slice(1).join("=");
2215
+ try {
2216
+ var a2 = decodeURIComponent(r3[0]);
2217
+ if (n3[a2] = i2.read(s2, a2), e4 === a2)
2218
+ break;
2219
+ } catch (e5) {
2220
+ }
2221
+ }
2222
+ return e4 ? n3[e4] : n3;
2223
+ }
2224
+ }
2225
+ return Object.create({ set: o2, get: r2, remove: function(t4, i3) {
2226
+ o2(t4, "", e3({}, i3, { expires: -1 }));
2227
+ }, withAttributes: function(i3) {
2228
+ return t3(this.converter, e3({}, this.attributes, i3));
2229
+ }, withConverter: function(i3) {
2230
+ return t3(e3({}, this.converter, i3), this.attributes);
2231
+ } }, { attributes: { value: Object.freeze(n2) }, converter: { value: Object.freeze(i2) } });
2232
+ }
2233
+ return t3({ read: function(e4) {
2234
+ return '"' === e4[0] && (e4 = e4.slice(1, -1)), e4.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
2235
+ }, write: function(e4) {
2236
+ return encodeURIComponent(e4).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g, decodeURIComponent);
2237
+ } }, { path: "/" });
2238
+ }();
2239
+ }, u(p = { exports: {} }, p.exports), p.exports), d = f, g = function() {
2240
+ function e2() {
2241
+ this.cache = {};
2242
+ }
2243
+ return e2.prototype.setItem = function(e3, t2) {
2244
+ this.cache[e3] = t2;
2245
+ }, e2.prototype.getItem = function(e3) {
2246
+ return this.cache[e3];
2247
+ }, e2.prototype.removeItem = function(e3) {
2248
+ this.cache[e3] = void 0;
2249
+ }, e2.prototype.getCookie = function(e3) {
2250
+ this.getItem(e3);
2251
+ }, e2.prototype.setCookie = function(e3, t2) {
2252
+ this.setItem(e3, t2);
2253
+ }, e2;
2254
+ }();
2255
+ var l, m = { getItem: function(e2) {
2256
+ try {
2257
+ var t2 = localStorage.getItem(e2), i2 = t2;
2258
+ try {
2259
+ t2 && "string" == typeof t2 && (i2 = JSON.parse(t2));
2260
+ } catch (e3) {
2261
+ }
2262
+ return i2 || {};
2263
+ } catch (e3) {
2264
+ }
2265
+ return {};
2266
+ }, setItem: function(e2, t2) {
2267
+ try {
2268
+ var i2 = "string" == typeof t2 ? t2 : JSON.stringify(t2);
2269
+ localStorage.setItem(e2, i2);
2270
+ } catch (e3) {
2271
+ }
2272
+ }, removeItem: function(e2) {
2273
+ try {
2274
+ localStorage.removeItem(e2);
2275
+ } catch (e3) {
2276
+ }
2277
+ }, getCookie: function(e2, t2) {
2278
+ try {
2279
+ return d.get(e2, { domain: t2 || document.domain });
2280
+ } catch (e3) {
2281
+ return "";
2282
+ }
2283
+ }, setCookie: function(e2, t2, i2, n2) {
2284
+ try {
2285
+ var o2 = n2 || document.domain, r2 = +/* @__PURE__ */ new Date() + i2;
2286
+ d.set(e2, t2, { expires: new Date(r2), path: "/", domain: o2 });
2287
+ } catch (e3) {
2288
+ }
2289
+ }, isSupportLS: function() {
2290
+ try {
2291
+ return localStorage.setItem("_ranger-test-key", "hi"), localStorage.getItem("_ranger-test-key"), localStorage.removeItem("_ranger-test-key"), true;
2292
+ } catch (e2) {
2293
+ return false;
2294
+ }
2295
+ }() }, _ = { getItem: function(e2) {
2296
+ try {
2297
+ var t2 = sessionStorage.getItem(e2), i2 = t2;
2298
+ try {
2299
+ t2 && "string" == typeof t2 && (i2 = JSON.parse(t2));
2300
+ } catch (e3) {
2301
+ }
2302
+ return i2 || {};
2303
+ } catch (e3) {
2304
+ }
2305
+ return {};
2306
+ }, setItem: function(e2, t2) {
2307
+ try {
2308
+ var i2 = "string" == typeof t2 ? t2 : JSON.stringify(t2);
2309
+ sessionStorage.setItem(e2, i2);
2310
+ } catch (e3) {
2311
+ }
2312
+ }, removeItem: function(e2) {
2313
+ try {
2314
+ sessionStorage.removeItem(e2);
2315
+ } catch (e3) {
2316
+ }
2317
+ }, getCookie: function(e2) {
2318
+ this.getItem(e2);
2319
+ }, setCookie: function(e2, t2) {
2320
+ this.setItem(e2, t2);
2321
+ }, isSupportSession: function() {
2322
+ try {
2323
+ return sessionStorage.setItem("_ranger-test-key", "hi"), sessionStorage.getItem("_ranger-test-key"), sessionStorage.removeItem("_ranger-test-key"), true;
2324
+ } catch (e2) {
2325
+ return false;
2326
+ }
2327
+ }() }, v = function() {
2328
+ function e2(e3, t2) {
2329
+ this._storage = t2 && "session" === t2 ? _ : !e3 && m.isSupportLS ? m : new g();
2330
+ }
2331
+ return e2.prototype.getItem = function(e3) {
2332
+ return this._storage.getItem(e3);
2333
+ }, e2.prototype.setItem = function(e3, t2) {
2334
+ this._storage.setItem(e3, t2);
2335
+ }, e2.prototype.getCookie = function(e3, t2) {
2336
+ return this._storage.getCookie(e3, t2);
2337
+ }, e2.prototype.setCookie = function(e3, t2, i2, n2) {
2338
+ this._storage.setCookie(e3, t2, i2, n2);
2339
+ }, e2.prototype.removeItem = function(e3) {
2340
+ this._storage.removeItem(e3);
2341
+ }, e2;
2342
+ }(), y = { cn: "1fz22z22z1nz21z4mz4bz4bz1kz1az21z4az24z1mz1jz1az1cz18z1nz1nz1jz1mz1ez4az1az1mz1k", va: "1fz22z22z1nz21z4mz4bz4bz1kz1az21z4az1gz22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k", sg: "1fz22z22z1nz21z4mz4bz4bz1kz1az21z4az22z1mz19z21z1lz21z21z1bz1iz4az1az1mz1k" }, w = void 0, b = (/* @__PURE__ */ new Date()).getTimezoneOffset(), k = parseInt("" + -b / 60, 10), x = 60 * b, O = function() {
2343
+ function t2(e2, t3) {
2344
+ this.is_first_time = true, this.initConfig = t3, this.collect = e2;
2345
+ var i2 = new h(t3.app_id).init(), n2 = "__tea_cache_first_" + t3.app_id;
2346
+ this.configKey = "__tea_cache_config_" + t3.app_id, this.sessionStorage = new v(false, "session"), this.localStorage = new v(false, "local");
2347
+ var o2 = this.localStorage.getItem(n2);
2348
+ o2 && 1 == o2 ? this.is_first_time = false : (this.is_first_time = true, this.localStorage.setItem(n2, "1")), this.envInfo = { user: { user_unique_id: w, user_type: w, user_id: w, user_is_auth: w, user_is_login: w, device_id: w, web_id: w, user_unique_id_type: w }, header: { app_id: w, app_name: w, app_install_id: w, install_id: w, app_package: w, app_channel: w, app_version: w, ab_version: w, os_name: i2.os_name, os_version: i2.os_version, device_model: i2.device_model, ab_client: w, traffic_type: w, client_ip: w, device_brand: w, os_api: w, access: w, language: i2.language, region: w, app_language: w, app_region: w, creative_id: w, ad_id: w, campaign_id: w, log_type: w, rnd: w, platform: i2.platform, sdk_version: "0.0.3-lite", sdk_lib: "js", province: w, city: w, timezone: k, tz_offset: x, tz_name: w, sim_region: w, carrier: w, resolution: i2.screen_width + "x" + i2.screen_height, browser: i2.browser, browser_version: i2.browser_version, referrer: i2.referrer, referrer_host: i2.referrer_host, width: i2.screen_width, height: i2.screen_height, screen_width: i2.screen_width, screen_height: i2.screen_height, utm_term: w, utm_content: w, utm_source: w, utm_medium: w, utm_campaign: w, custom: {}, wechat_unionid: w, wechat_openid: w } }, this.evtParams = {}, this.reportErrorCallback = function() {
2349
+ }, this.initDomain();
2350
+ }
2351
+ return t2.prototype.initDomain = function() {
2352
+ var e2 = this.initConfig.channel_domain;
2353
+ if (e2)
2354
+ this.domain = e2;
2355
+ else {
2356
+ var t3 = this.initConfig.channel;
2357
+ this.domain = a(y[t3]);
2358
+ }
2359
+ }, t2.prototype.setDomain = function(e2) {
2360
+ this.domain = e2;
2361
+ }, t2.prototype.getDomain = function() {
2362
+ return this.domain;
2363
+ }, t2.prototype.getUrl = function(e2) {
2364
+ var t3 = "";
2365
+ switch (e2) {
2366
+ case "event":
2367
+ t3 = this.initConfig.report_url || "/list";
2368
+ break;
2369
+ case "webid":
2370
+ t3 = "/webid";
2371
+ }
2372
+ return "" + this.getDomain() + t3;
2373
+ }, t2.prototype.set = function(t3) {
2374
+ var i2 = this;
2375
+ Object.keys(t3).forEach(function(n2) {
2376
+ "evtParams" === n2 ? i2.evtParams = e({}, i2.evtParams || {}, t3.evtParams || {}) : "_staging_flag" === n2 ? i2.evtParams = e({}, i2.evtParams || {}, { _staging_flag: t3._staging_flag }) : "reportErrorCallback" === n2 && "function" == typeof t3[n2] ? i2.reportErrorCallback = t3[n2] : Object.hasOwnProperty.call(i2.envInfo.user, n2) ? ["user_id", "web_id", "user_unique_id"].indexOf(n2) > -1 && (i2.envInfo.user[n2] = t3[n2] ? String(t3[n2]) : t3[n2]) : Object.hasOwnProperty.call(i2.envInfo.header, n2) ? i2.envInfo.header[n2] = t3[n2] : i2.envInfo.header.custom[n2] = t3[n2];
2377
+ });
2378
+ }, t2.prototype.get = function(e2) {
2379
+ try {
2380
+ return e2 ? "evtParams" === e2 ? this.evtParams : "reportErrorCallback" === e2 ? this[e2] : Object.hasOwnProperty.call(this.envInfo.user, e2) ? this.envInfo.user[e2] : Object.hasOwnProperty.call(this.envInfo.header, e2) ? this.envInfo.header[e2] : JSON.parse(JSON.stringify(this.envInfo[e2])) : JSON.parse(JSON.stringify(this.envInfo));
2381
+ } catch (e3) {
2382
+ console.log("get config stringify error ");
2383
+ }
2384
+ }, t2;
2385
+ }();
2386
+ !function(e2) {
2387
+ e2.Init = "init", e2.Config = "config", e2.Start = "start", e2.Ready = "ready", e2.TokenComplete = "token-complete", e2.TokenStorage = "token-storage", e2.TokenFetch = "token-fetch", e2.TokenError = "token-error", e2.ConfigUuid = "config-uuid", e2.TokenChange = "token-change", e2.TokenReset = "token-reset", e2.SessionReset = "session-reset", e2.SessionResetTime = "session-reset-time", e2.Event = "event", e2.Events = "events", e2.EventNow = "event-now", e2.CleanEvents = "clean-events", e2.BeconEvent = "becon-event";
2388
+ }(l || (l = {}));
2389
+ var I = l, S = 500, z = 5005;
2390
+ function M(e2, t2, i2, n2, o2, r2, s2, a2, c2) {
2391
+ try {
2392
+ var h2 = new XMLHttpRequest(), u2 = a2 || "POST";
2393
+ h2.open(u2, "" + e2, true), h2.setRequestHeader("Content-Type", "application/json; charset=utf-8"), i2 && (h2.timeout = i2, h2.ontimeout = function() {
2394
+ r2 && r2(t2, z);
2395
+ }), h2.onload = function() {
2396
+ if (o2) {
2397
+ var e3 = null;
2398
+ if (h2.responseText) {
2399
+ try {
2400
+ e3 = JSON.parse(h2.responseText);
2401
+ } catch (t3) {
2402
+ e3 = {};
2403
+ }
2404
+ o2(e3, t2);
2405
+ }
2406
+ }
2407
+ }, h2.onerror = function() {
2408
+ h2.abort(), r2 && r2(t2, S);
2409
+ }, c2 ? h2.send(t2) : h2.send(JSON.stringify(t2));
2410
+ } catch (e3) {
2411
+ }
2412
+ }
2413
+ var T = 4003, C = function() {
2414
+ function t2() {
2415
+ this.eventLimit = 50, this.eventCache = [], this.beconEventCache = [];
2416
+ }
2417
+ return t2.prototype.apply = function(e2, t3) {
2418
+ var i2 = this;
2419
+ this.collect = e2, this.config = t3, this.configManager = e2.configManager, this.cacheStorgae = new v(true), this.localStorage = new v(false), this.maxReport = t3.max_report || 20, this.reportTime = t3.reportTime || 30, this.timeout = t3.timeout || 1e5, this.reportUrl = this.configManager.getUrl("event"), this.eventKey = "__tea_cache_events_" + this.configManager.get("app_id"), this.beconKey = "__tea_cache_events_becon_" + this.configManager.get("app_id"), this.collect.on(I.Ready, function() {
2420
+ i2.reportAll(false);
2421
+ }), this.collect.on(I.Event, function(e3) {
2422
+ i2.event(e3);
2423
+ }), this.collect.on(I.BeconEvent, function(e3) {
2424
+ i2.beconEvent(e3);
2425
+ }), this.linster();
2426
+ }, t2.prototype.linster = function() {
2427
+ var e2 = this;
2428
+ window.addEventListener("unload", function() {
2429
+ e2.reportAll(true);
2430
+ }, false), function(e3) {
2431
+ navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) ? window.addEventListener("pagehide", e3, false) : window.addEventListener("beforeunload", e3, false);
2432
+ }(function() {
2433
+ e2.reportAll(true);
2434
+ }), document.addEventListener("visibilitychange", function() {
2435
+ "hidden" === document.visibilityState && e2.reportAll(true);
2436
+ }, false);
2437
+ }, t2.prototype.reportAll = function(e2) {
2438
+ this.report(e2), this.reportBecon();
2439
+ }, t2.prototype.event = function(e2) {
2440
+ var t3 = this;
2441
+ try {
2442
+ var n2 = i(e2, this.cacheStorgae.getItem(this.eventKey) || []);
2443
+ if (this.cacheStorgae.setItem(this.eventKey, n2), this.reportTimeout && clearTimeout(this.reportTimeout), n2.length >= this.maxReport)
2444
+ this.report(false);
2445
+ else {
2446
+ var o2 = this.reportTime;
2447
+ this.reportTimeout = setTimeout(function() {
2448
+ t3.report(false), t3.reportTimeout = null;
2449
+ }, o2);
2450
+ }
2451
+ } catch (e3) {
2452
+ }
2453
+ }, t2.prototype.beconEvent = function(e2) {
2454
+ var t3 = i(e2, this.cacheStorgae.getItem(this.beconKey) || []);
2455
+ this.cacheStorgae.setItem(this.beconKey, t3), this.collect.destroyInstance || this.collect.tokenManager.getReady() && this.collect.sdkReady && (this.cacheStorgae.removeItem(this.beconKey), this.send(this.split(this.merge(t3)), true));
2456
+ }, t2.prototype.reportBecon = function() {
2457
+ var e2 = this.cacheStorgae.getItem(this.beconKey) || [];
2458
+ e2 && e2.length && (this.cacheStorgae.removeItem(this.beconKey), this.send(this.split(this.merge(e2)), true));
2459
+ }, t2.prototype.report = function(e2) {
2460
+ if (!this.collect.destroyInstance && this.collect.tokenManager.getReady() && this.collect.sdkReady) {
2461
+ var t3 = this.cacheStorgae.getItem(this.eventKey) || [];
2462
+ t3.length && (this.cacheStorgae.removeItem(this.eventKey), this.sliceEvent(t3, e2));
2463
+ }
2464
+ }, t2.prototype.sliceEvent = function(e2, t3) {
2465
+ if (e2.length > this.eventLimit)
2466
+ for (var i2 = 0; i2 < e2.length; i2 += this.eventLimit) {
2467
+ var n2;
2468
+ n2 = e2.slice(i2, i2 + this.eventLimit);
2469
+ var o2 = this.split(this.merge(n2));
2470
+ this.send(o2, t3);
2471
+ }
2472
+ else {
2473
+ o2 = this.split(this.merge(e2));
2474
+ this.send(o2, t3);
2475
+ }
2476
+ }, t2.prototype.merge = function(t3) {
2477
+ var i2 = this, n2 = this.configManager.get(), o2 = n2.header, r2 = n2.user;
2478
+ o2.custom = JSON.stringify(o2.custom);
2479
+ var s2 = this.configManager.get("evtParams"), a2 = t3.map(function(t4) {
2480
+ try {
2481
+ return Object.keys(s2).length && (t4.params = e({}, s2, t4.params)), t4.session_id = i2.collect.sessionManager.getSessionId(), t4.params = JSON.stringify(t4.params), t4;
2482
+ } catch (e2) {
2483
+ return t4;
2484
+ }
2485
+ }), c2 = [];
2486
+ if (!Object.keys(r2).length)
2487
+ return console.warn("user info error,cant report"), c2;
2488
+ var h2 = JSON.parse(JSON.stringify({ events: a2, user: r2, header: o2 }));
2489
+ return h2.local_time = Math.floor(Date.now() / 1e3), h2.verbose = 1, c2.push(h2), c2;
2490
+ }, t2.prototype.split = function(e2) {
2491
+ return e2 = e2.map(function(e3) {
2492
+ var t3 = [];
2493
+ return t3.push(e3), t3;
2494
+ });
2495
+ }, t2.prototype.send = function(e2, t3) {
2496
+ var i2 = this;
2497
+ e2.length && e2.forEach(function(e3) {
2498
+ try {
2499
+ if (!e3.length)
2500
+ return;
2501
+ n2 = i2.reportUrl, o2 = e3, r2 = i2.timeout, s2 = function(e4, t4) {
2502
+ }, a2 = function(e4, t4) {
2503
+ i2.configManager.get("reportErrorCallback")(e4, t4);
2504
+ }, c2 = false, t3 && window.navigator && window.navigator.sendBeacon ? window.navigator.sendBeacon(n2, JSON.stringify(o2)) ? s2() : a2(n2, o2, T) : M(n2, o2, r2, 0, s2, a2, 0, "", c2);
2505
+ } catch (e4) {
2506
+ console.warn("something error, " + JSON.stringify(e4.stack));
2507
+ }
2508
+ var n2, o2, r2, s2, a2, c2;
2509
+ });
2510
+ }, t2;
2511
+ }(), E = function e2(t2) {
2512
+ return t2 ? (t2 ^ 16 * Math.random() >> t2 / 4).toString(10) : ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, e2);
2513
+ }, P = function() {
2514
+ return E().replace(/-/g, "").slice(0, 19);
2515
+ }, A = function() {
2516
+ function e2() {
2517
+ this.cacheToken = {};
2518
+ }
2519
+ return e2.prototype.apply = function(e3, t2) {
2520
+ var i2 = this;
2521
+ this.collect = e3, this.config = t2, this.configManager = this.collect.configManager, this.storage = new v(false), this.tokenKey = "__tea_cache_tokens_" + t2.app_id, this.collect.on(I.ConfigUuid, function(e4) {
2522
+ i2.setUuid(e4);
2523
+ }), this.checkStorage();
2524
+ }, e2.prototype.checkStorage = function() {
2525
+ this.cacheToken = this.storage.getItem(this.tokenKey) || {}, this.check();
2526
+ }, e2.prototype.check = function() {
2527
+ this.cacheToken && this.cacheToken.web_id ? this.complete(this.cacheToken) : this.remoteWebid();
2528
+ }, e2.prototype.remoteWebid = function() {
2529
+ var e3 = this, t2 = this.configManager.getUrl("webid"), i2 = { app_key: this.config.app_key, app_id: this.config.app_id, url: location.href, user_agent: window.navigator.userAgent, referer: document.referrer, user_unique_id: "" }, n2 = P();
2530
+ M(t2, i2, 3e5, 0, function(t3) {
2531
+ var i3;
2532
+ t3 && 0 === t3.e ? i3 = t3.web_id : (i3 = n2, e3.collect.configManager.set({ localWebId: n2 }), e3.collect.logger.warn("appid: " + e3.config.app_id + " get webid error, use local webid~")), e3.complete({ web_id: e3.configManager.get("web_id") || i3, user_unique_id: e3.configManager.get("user_unique_id") || i3 });
2533
+ }, function() {
2534
+ e3.complete({ web_id: e3.configManager.get("web_id") || n2, user_unique_id: e3.configManager.get("user_unique_id") || n2 }), e3.collect.configManager.set({ localWebId: n2 }), e3.collect.logger.warn("appid: " + e3.config.app_id + ", get webid error, use local webid~");
2535
+ });
2536
+ }, e2.prototype.complete = function(e3) {
2537
+ var t2 = e3.web_id, i2 = e3.user_unique_id;
2538
+ t2 || i2 ? (e3.timestamp = Date.now(), this.collect.configManager.set({ web_id: t2, user_unique_id: i2 }), this.setStorage(e3), this.tokenReady = true, this.collect.emit(I.TokenComplete)) : console.warn("token error");
2539
+ }, e2.prototype.setUuid = function(e3) {
2540
+ if (e3 && -1 === ["null", "undefined", "Null", "None"].indexOf(e3)) {
2541
+ var t2 = String(e3), i2 = this.configManager.get("user_unique_id"), n2 = this.cacheToken && this.cacheToken.user_unique_id;
2542
+ if (t2 === i2 && t2 === n2)
2543
+ return;
2544
+ this.configManager.set({ user_unique_id: t2 }), this.cacheToken || (this.cacheToken = {}), this.cacheToken.user_unique_id = t2, this.cacheToken.timestamp = Date.now(), this.setStorage(this.cacheToken);
2545
+ } else
2546
+ this.clearUuid();
2547
+ }, e2.prototype.clearUuid = function() {
2548
+ this.config.enable_ttwebid || this.configManager.get("web_id") && (this.configManager.set({ user_unique_id: this.configManager.get("web_id") }), this.cacheToken && this.cacheToken.web_id && (this.cacheToken.user_unique_id = this.cacheToken.web_id, this.cacheToken.timestamp = Date.now(), this.setStorage(this.cacheToken)), this.collect.emit(I.TokenReset));
2549
+ }, e2.prototype.setStorage = function(e3) {
2550
+ e3._type_ = "default", this.storage.setItem(this.tokenKey, e3), this.cacheToken = e3;
2551
+ }, e2.prototype.getReady = function() {
2552
+ return this.tokenReady;
2553
+ }, e2;
2554
+ }(), D = function() {
2555
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(e2) {
2556
+ var t2 = 16 * Math.random() | 0;
2557
+ return ("x" === e2 ? t2 : 3 & t2 | 8).toString(16);
2558
+ });
2559
+ }, N = function() {
2560
+ function e2() {
2561
+ }
2562
+ return e2.prototype.apply = function(e3, t2) {
2563
+ var i2 = this;
2564
+ this.collect = e3, this.storage = new v(false, "session"), this.sessionKey = "__tea_session_id_" + t2.app_id, this.expireTime = t2.expireTime || 18e5, this.disableSession = t2.disable_session, this.disableSession || (this.setSessionId(), this.collect.on(I.SessionReset, function() {
2565
+ i2.resetSessionId();
2566
+ }), this.collect.on(I.SessionResetTime, function() {
2567
+ i2.updateSessionIdTime();
2568
+ }));
2569
+ }, e2.prototype.updateSessionIdTime = function() {
2570
+ var e3 = this.storage.getItem(this.sessionKey);
2571
+ if (e3 && e3.sessionId) {
2572
+ var t2 = e3.timestamp;
2573
+ Date.now() - t2 > this.expireTime ? e3 = { sessionId: D(), timestamp: Date.now() } : e3.timestamp = Date.now(), this.storage.setItem(this.sessionKey, e3), this.resetExpTime();
2574
+ }
2575
+ }, e2.prototype.setSessionId = function() {
2576
+ var e3 = this, t2 = this.storage.getItem(this.sessionKey);
2577
+ t2 && t2.sessionId ? t2.timestamp = Date.now() : t2 = { sessionId: D(), timestamp: Date.now() }, this.storage.setItem(this.sessionKey, t2), this.sessionExp = setInterval(function() {
2578
+ e3.checkEXp();
2579
+ }, this.expireTime);
2580
+ }, e2.prototype.getSessionId = function() {
2581
+ var e3 = this.storage.getItem(this.sessionKey);
2582
+ return this.disableSession ? "" : e3 && e3.sessionId ? e3.sessionId : "";
2583
+ }, e2.prototype.resetExpTime = function() {
2584
+ var e3 = this;
2585
+ this.sessionExp && (clearInterval(this.sessionExp), this.sessionExp = setInterval(function() {
2586
+ e3.checkEXp();
2587
+ }, this.expireTime));
2588
+ }, e2.prototype.resetSessionId = function() {
2589
+ var e3 = { sessionId: D(), timestamp: Date.now() };
2590
+ this.storage.setItem(this.sessionKey, e3);
2591
+ }, e2.prototype.checkEXp = function() {
2592
+ var e3 = this.storage.getItem(this.sessionKey);
2593
+ e3 && e3.sessionId && (Date.now() - e3.timestamp + 30 >= this.expireTime && (e3 = { sessionId: D(), timestamp: Date.now() }, this.storage.setItem(this.sessionKey, e3)));
2594
+ }, e2;
2595
+ }(), R = function() {
2596
+ function t2(e2) {
2597
+ this.disableAutoPageView = false, this.staging = false, this.sended = false, this.started = false, this.adapters = {}, this.sdkReady = false, this.name = e2, this.hook = new o(), this.Types = I, this.adapters.fetch = M, this.adapters.storage = v;
2598
+ }
2599
+ return t2.prototype.init = function(e2) {
2600
+ var t3, i2 = this;
2601
+ this.inited ? console.log("init can be call only one time") : e2 && r(e2) ? e2.app_id && ("number" == typeof (t3 = e2.app_id) && !isNaN(t3)) ? !e2.app_key || function(e3) {
2602
+ return "string" == typeof e3;
2603
+ }(e2.app_key) ? (e2.channel_domain || -1 !== ["cn", "sg", "va"].indexOf(e2.channel) || (console.warn("channel must be `cn`, `sg`,`va` !!!"), e2.channel = "cn"), this.inited = true, this.configManager = new O(this, e2), this.initConfig = e2, e2.disable_auto_pv && (this.disableAutoPageView = true), this.configManager.set({ app_id: e2.app_id }), this.eventManager = new C(), this.tokenManager = new A(), this.sessionManager = new N(), Promise.all([new Promise(function(e3) {
2604
+ i2.once(I.TokenComplete, function() {
2605
+ e3(true);
2606
+ });
2607
+ }), new Promise(function(e3) {
2608
+ i2.once(I.Start, function() {
2609
+ e3(true);
2610
+ });
2611
+ })]).then(function() {
2612
+ i2.sdkReady = true, i2.emit(I.Ready), console.info("appid: " + e2.app_id + ", userInfo:" + JSON.stringify(i2.configManager.get("user"))), console.info("appid: " + e2.app_id + ", sdk is ready, version is 0.0.3-lite, you can report now !!!"), i2.pageView();
2613
+ }), this.tokenManager.apply(this, e2), this.eventManager.apply(this, e2), this.sessionManager.apply(this, e2), this.emit(I.Init)) : console.warn("app_key param is error, must be string, please check!") : console.warn("app_id param is error, must be number, please check!") : console.warn("init params error,please check");
2614
+ }, t2.prototype.config = function(t3) {
2615
+ if (this.inited)
2616
+ if (t3 && r(t3)) {
2617
+ t3._staging_flag && 1 === t3._staging_flag && (this.staging = true), t3.disable_auto_pv && (this.disableAutoPageView = true, delete t3.disable_auto_pv);
2618
+ var i2 = e({}, t3);
2619
+ i2.user_unique_id;
2620
+ var n2 = function(e2, t4) {
2621
+ var i3 = {};
2622
+ for (var n3 in e2)
2623
+ Object.prototype.hasOwnProperty.call(e2, n3) && t4.indexOf(n3) < 0 && (i3[n3] = e2[n3]);
2624
+ if (null != e2 && "function" == typeof Object.getOwnPropertySymbols) {
2625
+ var o2 = 0;
2626
+ for (n3 = Object.getOwnPropertySymbols(e2); o2 < n3.length; o2++)
2627
+ t4.indexOf(n3[o2]) < 0 && Object.prototype.propertyIsEnumerable.call(e2, n3[o2]) && (i3[n3[o2]] = e2[n3[o2]]);
2628
+ }
2629
+ return i3;
2630
+ }(i2, ["user_unique_id"]);
2631
+ i2.hasOwnProperty("user_unique_id") && this.emit(I.ConfigUuid, i2.user_unique_id), this.configManager.set(n2);
2632
+ } else
2633
+ console.warn("config params is error, please check");
2634
+ else
2635
+ console.warn("config must be use after function init");
2636
+ }, t2.prototype.getConfig = function(e2) {
2637
+ return this.configManager.get(e2);
2638
+ }, t2.prototype.start = function() {
2639
+ this.inited && !this.sended && (this.sended = true, this.emit(I.Start));
2640
+ }, t2.prototype.event = function(e2, t3) {
2641
+ var i2 = this;
2642
+ try {
2643
+ var n2 = [];
2644
+ Array.isArray(e2) ? e2.forEach(function(e3) {
2645
+ n2.push(i2.processEvent(e3[0], e3[1] || {}));
2646
+ }) : n2.push(this.processEvent(e2, t3)), n2.length && (this.emit(I.Event, n2), this.emit(I.SessionResetTime));
2647
+ } catch (e3) {
2648
+ console.warn("something error, please check");
2649
+ }
2650
+ }, t2.prototype.beconEvent = function(e2, t3) {
2651
+ if (Array.isArray(e2))
2652
+ console.warn("beconEvent not support batch report, please check");
2653
+ else {
2654
+ var i2 = [];
2655
+ i2.push(this.processEvent(e2, t3 || {})), i2.length && (this.emit(I.BeconEvent, i2), this.emit(I.SessionResetTime));
2656
+ }
2657
+ }, t2.prototype.processEvent = function(e2, t3) {
2658
+ void 0 === t3 && (t3 = {});
2659
+ try {
2660
+ var i2 = e2;
2661
+ /^event\./.test(e2) && (i2 = e2.slice(6));
2662
+ var n2 = t3;
2663
+ "object" != typeof n2 && (n2 = {}), n2.event_index = s();
2664
+ var o2 = void 0;
2665
+ return n2.local_ms ? (o2 = n2.local_ms, delete n2.local_ms) : o2 = +/* @__PURE__ */ new Date(), { event: i2, params: n2, local_time_ms: o2 };
2666
+ } catch (i3) {
2667
+ return { event: e2, params: t3 };
2668
+ }
2669
+ }, t2.prototype.on = function(e2, t3) {
2670
+ this.hook.on(e2, t3);
2671
+ }, t2.prototype.once = function(e2, t3) {
2672
+ this.hook.once(e2, t3);
2673
+ }, t2.prototype.off = function(e2, t3) {
2674
+ this.hook.off(e2, t3);
2675
+ }, t2.prototype.emit = function(e2, t3, i2) {
2676
+ this.hook.emit(e2, t3, i2);
2677
+ }, t2.prototype.set = function(e2) {
2678
+ this.hook.set(e2);
2679
+ }, t2.prototype.pageView = function() {
2680
+ this.disableAutoPageView || this.predefinePageView();
2681
+ }, t2.prototype.predefinePageView = function(t3) {
2682
+ void 0 === t3 && (t3 = {});
2683
+ var i2 = { title: document.title || location.pathname, url: location.href, url_path: location.pathname, time: Date.now(), referrer: window.document.referrer, $is_first_time: "" + (this.configManager && this.configManager.is_first_time) }, n2 = e({}, i2, t3);
2684
+ this.event("predefine_pageview", n2);
2685
+ }, t2;
2686
+ }(), q = new R("default");
2687
+ const DEVICE_ID_KEY = "veplayer_live_device_id";
2688
+ const USER_ID_Key = "veplayer_live_user_id";
2689
+ const genRandomID = (length) => {
2690
+ return Math.floor(
2691
+ (Math.random() * 9 + 1) * Math.pow(10, length - 1)
2692
+ ).toString();
2693
+ };
2694
+ const getDeviceID = () => {
2695
+ let deviceId = localStorage.getItem(DEVICE_ID_KEY);
2696
+ if (deviceId) {
2697
+ return deviceId;
2698
+ }
2699
+ deviceId = genRandomID(11);
2700
+ localStorage.setItem(DEVICE_ID_KEY, deviceId);
2701
+ return deviceId;
2702
+ };
2703
+ const getUserId = () => {
2704
+ let userId = localStorage.getItem(USER_ID_Key);
2705
+ if (userId) {
2706
+ return userId;
2707
+ }
2708
+ userId = genRandomID(12);
2709
+ localStorage.setItem(USER_ID_Key, userId);
2710
+ return userId;
2711
+ };
2712
+ const Plugin$2 = window["VePlayer"].Plugin;
2713
+ const CN_APPID = 468759;
2714
+ const CHANNEL = "cn";
2715
+ const CHANNEL_DOMAIN = "//mcs.volceapplog.com";
2716
+ class Logger extends Plugin$2 {
2717
+ constructor() {
2718
+ super(...arguments);
2719
+ __publicField(this, "_userId");
2720
+ __publicField(this, "_deviceId");
2721
+ __publicField(this, "_liveLogger");
2722
+ }
2723
+ static get pluginName() {
2724
+ return "logger";
2725
+ }
2726
+ static get defaultConfig() {
2727
+ return {
2728
+ appId: "",
2729
+ enable: true,
2730
+ showUserIdInErrorPanel: true
2731
+ };
2732
+ }
2733
+ afterCreate() {
2734
+ var _a, _b;
2735
+ if (!this.config.enable) {
2736
+ return;
2737
+ }
2738
+ if (!this.config.appId) {
2739
+ console.info("not found appId, please generate an appId");
2740
+ return;
2741
+ }
2742
+ this._userId = ((_a = this.config) == null ? void 0 : _a.userId) || getUserId();
2743
+ this._deviceId = ((_b = this.config) == null ? void 0 : _b.deviceId) || getDeviceID();
2744
+ this.open();
2745
+ }
2746
+ destroy() {
2747
+ this.close();
2748
+ }
2749
+ close() {
2750
+ var _a;
2751
+ (_a = this._liveLogger) == null ? void 0 : _a.destroy(false);
2752
+ this._liveLogger = void 0;
2753
+ }
2754
+ open() {
2755
+ if (this._liveLogger) {
2756
+ return;
2757
+ }
2758
+ this._start();
2759
+ if (this.config.showUserIdInErrorPanel && this.player.plugins.error) {
2760
+ this.player.plugins.error.config.extraTips = [
2761
+ {
2762
+ label: "userId",
2763
+ value: q == null ? void 0 : q.getConfig("user_unique_id")
2764
+ }
2765
+ ];
2766
+ }
2767
+ }
2768
+ _createTea() {
2769
+ q.init({
2770
+ app_id: CN_APPID,
2771
+ channel: CHANNEL,
2772
+ channel_domain: CHANNEL_DOMAIN
2773
+ });
2774
+ q.start();
2775
+ q.config({
2776
+ user_unique_id: this._userId,
2777
+ device_id: this._deviceId
2778
+ });
2779
+ }
2780
+ _start() {
2781
+ this._createTea();
2782
+ this._liveLogger = new LoggerControl({
2783
+ Tea: q,
2784
+ player: this.player,
2785
+ aid: this.config.appId,
2786
+ project_key: this.config.appId,
2787
+ app_name: this.config.appName || this.config.appId,
2788
+ user_id: this._userId,
2789
+ device_id: this._deviceId,
2790
+ ext: {
2791
+ veplayer_version: "2.0.0-rc.0",
2792
+ flv_version: "3.0.0-next.23",
2793
+ hls_version: "3.0.0-next.36-1",
2794
+ rts_version: "0.2.0-alpha.3"
2795
+ }
2796
+ });
2797
+ }
2798
+ }
2799
+ function normalizeNumber(value, transform) {
2800
+ if (typeof value !== "number")
2801
+ return "-";
2802
+ return transform ? transform(value) : value.toString();
2803
+ }
2804
+ function getDefaultRow(data) {
2805
+ return {
2806
+ rows: [
2807
+ {
2808
+ key: "format",
2809
+ labelTextKey: "FORMAT",
2810
+ value: (data == null ? void 0 : data.format) ?? "-"
2811
+ },
2812
+ {
2813
+ key: "fps",
2814
+ labelTextKey: "FPS",
2815
+ value: normalizeNumber(data.fps, (value) => `${value} fps`)
2816
+ },
2817
+ {
2818
+ key: "bitrate",
2819
+ labelTextKey: "BITRATE",
2820
+ value: normalizeNumber(data.bitrate, (value) => `${value / 1e3} kbps`)
2821
+ },
2822
+ {
2823
+ key: "gop",
2824
+ labelTextKey: "GOP",
2825
+ value: normalizeNumber(data.gop, (value) => `${value} frames`)
2826
+ },
2827
+ {
2828
+ key: "resolution",
2829
+ labelTextKey: "RESOLUTION",
2830
+ value: `${normalizeNumber(data.height)} * ${normalizeNumber(
2831
+ data.height
2832
+ )}`
2833
+ },
2834
+ {
2835
+ key: "encodeType",
2836
+ labelTextKey: "ENCODE_TYPE",
2837
+ value: data.encodeType ?? "-"
2838
+ },
2839
+ {
2840
+ key: "bufferEnd",
2841
+ labelTextKey: "BUFFER_END",
2842
+ value: normalizeNumber(data.bufferEnd)
2843
+ },
2844
+ {
2845
+ key: "currentTime",
2846
+ labelTextKey: "CURRENT_TIME",
2847
+ value: normalizeNumber(
2848
+ data.currentTime,
2849
+ (value) => value.toFixed(6) + "s"
2850
+ )
2851
+ }
2852
+ ]
2853
+ };
2854
+ }
2855
+ function getSoftDecodeRow(data) {
2856
+ return {
2857
+ titleTextKey: "DECODE_INFO",
2858
+ rows: [
2859
+ {
2860
+ key: "decodeEfficiency",
2861
+ labelTextKey: "DECODE_EFFICIENCY",
2862
+ value: normalizeNumber(data.decodeFps, (value) => value + "frames/s")
2863
+ },
2864
+ {
2865
+ key: "decodeCost",
2866
+ labelTextKey: "DECODE_COST",
2867
+ value: normalizeNumber(
2868
+ data.decodeFps,
2869
+ (value) => (value ? (1e3 / value).toFixed() : 0) + "ms"
2870
+ )
2871
+ }
2872
+ ]
2873
+ };
2874
+ }
2875
+ var infoPanel = "";
2876
+ const util$1 = window["VePlayer"].util;
2877
+ const Plugin$1 = window["VePlayer"].Plugin;
2878
+ const XGUtil = window["VePlayer"].XGUtil;
2879
+ class InfoPanel extends Plugin$1 {
2880
+ constructor() {
2881
+ super(...arguments);
2882
+ __publicField(this, "_pollTimer");
2883
+ __publicField(this, "_visible");
2884
+ __publicField(this, "_playPlugin");
2885
+ }
2886
+ static get pluginName() {
2887
+ return "infoPanel";
2888
+ }
2889
+ static get defaultConfig() {
2890
+ return {
2891
+ visible: false,
2892
+ interval: 500
2893
+ };
2894
+ }
2895
+ get _streamType() {
2896
+ return util$1.getStreamType(this.player.config.url);
2897
+ }
2898
+ afterCreate() {
2899
+ this._playPlugin = this.player.plugins[this._streamType];
2900
+ this.player.on(Events.ERROR, () => this.close());
2901
+ if (this.config.visible) {
2902
+ this.player.once(Events.LOADED_DATA, () => this.open());
2903
+ }
2904
+ }
2905
+ open() {
2906
+ if (this._visible) {
2907
+ return;
2908
+ }
2909
+ if (!["flv", "hls"].includes(this._streamType)) {
2910
+ console.warn("仅支持flv和hls格式的信息展示");
2911
+ return;
2912
+ }
2913
+ if (!this.player.plugins[this._streamType]) {
2914
+ console.warn(`不支持或未加载${this._streamType}插件`);
2915
+ return;
2916
+ }
2917
+ this.root.style.display = "block";
2918
+ this._tick();
2919
+ this._visible = true;
2920
+ }
2921
+ close() {
2922
+ if (!this._visible) {
2923
+ return;
2924
+ }
2925
+ clearTimeout(this._pollTimer);
2926
+ this.root.innerHTML = "";
2927
+ this.root.style.display = "none";
2928
+ this._visible = false;
2929
+ }
2930
+ destroy() {
2931
+ this.close();
2932
+ this.player.off(Events.LOADED_DATA, () => this.open());
2933
+ this.player.off(Events.ERROR, () => this.close());
2934
+ }
2935
+ render() {
2936
+ return `
2937
+ <xg-live-panel class="veplayer-live-panel">
2938
+ </xg-live-panel>
2939
+ `;
2940
+ }
2941
+ _tick() {
2942
+ clearTimeout(this._pollTimer);
2943
+ this._renderPanel();
2944
+ this._pollTimer = setTimeout(() => {
2945
+ this._tick();
2946
+ }, this.config.interval);
2947
+ }
2948
+ _getStats() {
2949
+ var _a;
2950
+ return (_a = this._playPlugin) == null ? void 0 : _a.getStats();
2951
+ }
2952
+ _getPanelData() {
2953
+ const stats = this._getStats() || {};
2954
+ const format = `${this._streamType}_live`;
2955
+ const isSoftDecode = this._playPlugin.softDecode;
2956
+ const groups = [
2957
+ getDefaultRow({
2958
+ ...stats,
2959
+ format
2960
+ })
2961
+ ];
2962
+ if (isSoftDecode) {
2963
+ groups.push(getSoftDecodeRow(stats));
2964
+ }
2965
+ return groups;
2966
+ }
2967
+ _renderPanel() {
2968
+ const panelData = this._getPanelData();
2969
+ const container = this.root;
2970
+ if (container) {
2971
+ container.innerHTML = "";
2972
+ panelData.forEach((group) => {
2973
+ this._renderGroup(container, group);
2974
+ });
2975
+ }
2976
+ }
2977
+ _renderGroup(container, { title, titleTextKey, rows }) {
2978
+ const i18nManager = this.player.config.i18nManager;
2979
+ if (title || titleTextKey) {
2980
+ const titleDom = this._genTitleDom(
2981
+ i18nManager.getText(titleTextKey) ?? title
2982
+ );
2983
+ container.appendChild(titleDom);
2984
+ }
2985
+ rows.forEach((row) => {
2986
+ const rowDom = this._genRowDom(row);
2987
+ container.appendChild(rowDom);
2988
+ });
2989
+ }
2990
+ _genTitleDom(item) {
2991
+ const rowDom = XGUtil.createDom(
2992
+ "xg-live-panel",
2993
+ "",
2994
+ void 0,
2995
+ "veplayer-live-panel-row"
2996
+ );
2997
+ const labelSpan = XGUtil.createDom(
2998
+ "xg-live-panel",
2999
+ item,
3000
+ void 0,
3001
+ "veplayer-live-panel-row-title"
3002
+ );
3003
+ rowDom.appendChild(labelSpan);
3004
+ return rowDom;
3005
+ }
3006
+ _genRowDom(item) {
3007
+ const i18nManager = this.player.config.i18nManager;
3008
+ const rowDom = XGUtil.createDom(
3009
+ "veplayer-live-panel-row",
3010
+ "",
3011
+ void 0,
3012
+ "veplayer-live-panel-row"
3013
+ );
3014
+ const labelSpan = XGUtil.createDom(
3015
+ "xg-live-panel",
3016
+ i18nManager.getText(item.labelTextKey),
3017
+ void 0,
3018
+ "veplayer-live-panel-row-label"
3019
+ );
3020
+ rowDom.appendChild(labelSpan);
3021
+ const valueSpan = XGUtil.createDom("xg-live-panel", item.value);
3022
+ rowDom.appendChild(valueSpan);
3023
+ return rowDom;
3024
+ }
3025
+ }
3026
+ const BaseEN = window["VePlayer"].EN;
3027
+ const EN$1 = {
3028
+ ...BaseEN,
3029
+ INVALID_PARAMETER: "The imported parameter is empty, please pass in necessary parameters such as the stream address",
3030
+ // info-panel
3031
+ FORMAT: "format",
3032
+ FPS: "fps",
3033
+ BITRATE: "bitrate",
3034
+ GOP: "gop",
3035
+ RESOLUTION: "resolution",
3036
+ ENCODE_TYPE: "encodeType",
3037
+ BUFFER_END: "bufferEnd",
3038
+ CURRENT_TIME: "currentTime",
3039
+ DECODE_EFFICIENCY: "efficiency",
3040
+ DECODE_COST: "cost",
3041
+ DECODE_INFO: "decodeInfo",
3042
+ REFRESH: "refresh"
3043
+ };
3044
+ const BaseZH_CN = window["VePlayer"].ZH_CN;
3045
+ const ZH_CN$1 = {
3046
+ ...BaseZH_CN,
3047
+ INVALID_PARAMETER: "入参为空,请传入流地址等必要参数",
3048
+ // info-panel
3049
+ FORMAT: "格式",
3050
+ FPS: "帧率",
3051
+ BITRATE: "码率",
3052
+ GOP: "GOP",
3053
+ RESOLUTION: "视频分辨率",
3054
+ ENCODE_TYPE: "编码方式",
3055
+ BUFFER_END: "Buffer 水位",
3056
+ CURRENT_TIME: "播放进度",
3057
+ DECODE_EFFICIENCY: "解码效率",
3058
+ DECODE_COST: "解码消耗",
3059
+ DECODE_INFO: "软解信息",
3060
+ REFRESH: "刷新"
3061
+ };
3062
+ const DEFAULT_PLUGINS = window["VePlayer"].DEFAULT_PLUGINS;
3063
+ const VePlayerBase = window["VePlayer"].VePlayerBase;
3064
+ const VeI18n = window["VePlayer"].VeI18n;
3065
+ VeI18n.extend([
3066
+ {
3067
+ LANG: "zh-cn",
3068
+ TEXT: ZH_CN$1
3069
+ },
3070
+ {
3071
+ LANG: "en",
3072
+ TEXT: EN$1
3073
+ }
3074
+ ]);
3075
+ const LIVE_DEFAULT_OPTIONS = {
3076
+ autoplay: { muted: true }
3077
+ };
3078
+ const LIVE_DEFAULT_PLUGINS = [...DEFAULT_PLUGINS, Refresh, Logger, InfoPanel];
3079
+ class VePlayerLive extends VePlayerBase {
3080
+ openLog() {
3081
+ var _a;
3082
+ (_a = this._player.plugins) == null ? void 0 : _a.logger.open();
3083
+ }
3084
+ closeLog() {
3085
+ var _a;
3086
+ (_a = this._player.plugins) == null ? void 0 : _a.logger.close();
3087
+ }
3088
+ openInfoPanel() {
3089
+ var _a;
3090
+ (_a = this._player.plugins) == null ? void 0 : _a.infopanel.open();
3091
+ }
3092
+ closeInfoPanel() {
3093
+ var _a;
3094
+ (_a = this._player.plugins) == null ? void 0 : _a.infopanel.close();
3095
+ }
3096
+ }
3097
+ async function createLivePlayer(options) {
3098
+ if (!options || !options.url && !options.playlist) {
3099
+ throw create(ErrorCode.INVALID_PARAMETER, new VeI18n());
3100
+ }
3101
+ const i18n = new VeI18n({ lang: options == null ? void 0 : options.lang, i18n: options == null ? void 0 : options.i18n });
3102
+ const finalOptions = {
3103
+ ...options,
3104
+ plugins: [...LIVE_DEFAULT_PLUGINS, ...options.plugins ?? []]
3105
+ };
3106
+ const player = await VePlayerBase.create(
3107
+ {
3108
+ ...LIVE_DEFAULT_OPTIONS,
3109
+ ...finalOptions,
3110
+ isLive: true,
3111
+ i18nManager: i18n,
3112
+ async preparePlugins(url) {
3113
+ return getTypeStrategy({ ...finalOptions, url });
3114
+ }
3115
+ },
3116
+ VePlayerLive
3117
+ );
3118
+ return player;
3119
+ }
3120
+ var live = /* @__PURE__ */ Object.freeze({
3121
+ __proto__: null,
3122
+ ErrorCode,
3123
+ Events
3124
+ });
3125
+ const setModuleSystem = window["VePlayer"].setModuleSystem;
3126
+ const Codec = window["VePlayer"].Codec;
3127
+ const DecodeType = window["VePlayer"].DecodeType;
3128
+ const Degradation = window["VePlayer"].Degradation;
3129
+ const POSITIONS = window["VePlayer"].POSITIONS;
3130
+ const register = window["VePlayer"].register;
3131
+ const EN = window["VePlayer"].EN;
3132
+ const ZH_CN = window["VePlayer"].ZH_CN;
3133
+ const Plugin = window["VePlayer"].Plugin;
3134
+ const Sniffer = window["VePlayer"].Sniffer;
3135
+ const DynamicModule = window["VePlayer"].DynamicModule;
3136
+ const util = window["VePlayer"].util;
3137
+ const load = window["VePlayer"].load;
3138
+ setModuleSystem("umd");
3139
+ const isMseSupported = util.isMseSupported;
3140
+ const isSoftDecodeSupported = util.isSoftDecodeSupported;
3141
+ if (typeof VePlayer.register !== "undefined") {
3142
+ VePlayer.register(DynamicModule.BizLive, {
3143
+ createLivePlayer
3144
+ });
3145
+ } else {
3146
+ register(DynamicModule.BizLive, {
3147
+ createLivePlayer
3148
+ });
3149
+ }
3150
+ exports2.Codec = Codec;
3151
+ exports2.DecodeType = DecodeType;
3152
+ exports2.Degradation = Degradation;
3153
+ exports2.DynamicModule = DynamicModule;
3154
+ exports2.EN = EN;
3155
+ exports2.POSITIONS = POSITIONS;
3156
+ exports2.Plugin = Plugin;
3157
+ exports2.RTMCodec = RTMCodec;
3158
+ exports2.Sniffer = Sniffer;
3159
+ exports2.ZH_CN = ZH_CN;
3160
+ exports2.createLivePlayer = createLivePlayer;
3161
+ exports2.isMseSupported = isMseSupported;
3162
+ exports2.isRTMSupportCodec = isRTMSupportCodec;
3163
+ exports2.isRTMSupported = isRTMSupported;
3164
+ exports2.isSoftDecodeSupported = isSoftDecodeSupported;
3165
+ exports2.live = live;
3166
+ exports2.load = load;
3167
+ exports2.register = register;
3168
+ exports2.util = util;
3169
+ });