@byteplus/veplayer-plugin 2.7.1-rc.0 → 2.8.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.
@@ -1,3 +1,29 @@
1
+ function _iterableToArrayLimit(arr, i) {
2
+ var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
3
+ if (null != _i) {
4
+ var _s, _e, _x, _r, _arr = [], _n = true, _d = false;
5
+ try {
6
+ if (_x = (_i = _i.call(arr)).next, 0 === i) {
7
+ if (Object(_i) !== _i)
8
+ return;
9
+ _n = false;
10
+ } else
11
+ for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = true)
12
+ ;
13
+ } catch (err) {
14
+ _d = true, _e = err;
15
+ } finally {
16
+ try {
17
+ if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r))
18
+ return;
19
+ } finally {
20
+ if (_d)
21
+ throw _e;
22
+ }
23
+ }
24
+ return _arr;
25
+ }
26
+ }
1
27
  function ownKeys$2(object, enumerableOnly) {
2
28
  var keys = Object.keys(object);
3
29
  if (Object.getOwnPropertySymbols) {
@@ -41,10 +67,10 @@ function _regeneratorRuntime$1() {
41
67
  return obj[key] = value;
42
68
  };
43
69
  }
44
- function wrap(innerFn, outerFn, self, tryLocsList) {
70
+ function wrap(innerFn, outerFn, self2, tryLocsList) {
45
71
  var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []);
46
72
  return defineProperty(generator, "_invoke", {
47
- value: makeInvokeMethod(innerFn, self, context)
73
+ value: makeInvokeMethod(innerFn, self2, context)
48
74
  }), generator;
49
75
  }
50
76
  function tryCatch(fn, obj, arg) {
@@ -111,7 +137,7 @@ function _regeneratorRuntime$1() {
111
137
  }
112
138
  });
113
139
  }
114
- function makeInvokeMethod(innerFn, self, context) {
140
+ function makeInvokeMethod(innerFn, self2, context) {
115
141
  var state = "suspendedStart";
116
142
  return function(method, arg) {
117
143
  if ("executing" === state)
@@ -140,7 +166,7 @@ function _regeneratorRuntime$1() {
140
166
  } else
141
167
  "return" === context.method && context.abrupt("return", context.arg);
142
168
  state = "executing";
143
- var record = tryCatch(innerFn, self, context);
169
+ var record = tryCatch(innerFn, self2, context);
144
170
  if ("normal" === record.type) {
145
171
  if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel)
146
172
  continue;
@@ -222,9 +248,9 @@ function _regeneratorRuntime$1() {
222
248
  };
223
249
  }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function() {
224
250
  return this;
225
- }), exports.AsyncIterator = AsyncIterator, exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
251
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function(innerFn, outerFn, self2, tryLocsList, PromiseImpl) {
226
252
  void 0 === PromiseImpl && (PromiseImpl = Promise);
227
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
253
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self2, tryLocsList), PromiseImpl);
228
254
  return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function(result) {
229
255
  return result.done ? result.value : iter.next();
230
256
  });
@@ -351,9 +377,9 @@ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
351
377
  }
352
378
  function _asyncToGenerator$1(fn) {
353
379
  return function() {
354
- var self = this, args = arguments;
380
+ var self2 = this, args = arguments;
355
381
  return new Promise(function(resolve, reject) {
356
- var gen = fn.apply(self, args);
382
+ var gen = fn.apply(self2, args);
357
383
  function _next(value) {
358
384
  asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
359
385
  }
@@ -364,33 +390,33 @@ function _asyncToGenerator$1(fn) {
364
390
  });
365
391
  };
366
392
  }
367
- function _classCallCheck$2(instance, Constructor) {
393
+ function _classCallCheck$3(instance, Constructor) {
368
394
  if (!(instance instanceof Constructor)) {
369
395
  throw new TypeError("Cannot call a class as a function");
370
396
  }
371
397
  }
372
- function _defineProperties$2(target, props) {
398
+ function _defineProperties$3(target, props) {
373
399
  for (var i = 0; i < props.length; i++) {
374
400
  var descriptor = props[i];
375
401
  descriptor.enumerable = descriptor.enumerable || false;
376
402
  descriptor.configurable = true;
377
403
  if ("value" in descriptor)
378
404
  descriptor.writable = true;
379
- Object.defineProperty(target, _toPropertyKey$2(descriptor.key), descriptor);
405
+ Object.defineProperty(target, _toPropertyKey$3(descriptor.key), descriptor);
380
406
  }
381
407
  }
382
- function _createClass$2(Constructor, protoProps, staticProps) {
408
+ function _createClass$3(Constructor, protoProps, staticProps) {
383
409
  if (protoProps)
384
- _defineProperties$2(Constructor.prototype, protoProps);
410
+ _defineProperties$3(Constructor.prototype, protoProps);
385
411
  if (staticProps)
386
- _defineProperties$2(Constructor, staticProps);
412
+ _defineProperties$3(Constructor, staticProps);
387
413
  Object.defineProperty(Constructor, "prototype", {
388
414
  writable: false
389
415
  });
390
416
  return Constructor;
391
417
  }
392
418
  function _defineProperty$2(obj, key, value) {
393
- key = _toPropertyKey$2(key);
419
+ key = _toPropertyKey$3(key);
394
420
  if (key in obj) {
395
421
  Object.defineProperty(obj, key, {
396
422
  value,
@@ -448,19 +474,19 @@ function _isNativeReflectConstruct$1() {
448
474
  return false;
449
475
  }
450
476
  }
451
- function _assertThisInitialized$1(self) {
452
- if (self === void 0) {
477
+ function _assertThisInitialized$1(self2) {
478
+ if (self2 === void 0) {
453
479
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
454
480
  }
455
- return self;
481
+ return self2;
456
482
  }
457
- function _possibleConstructorReturn$1(self, call) {
483
+ function _possibleConstructorReturn$1(self2, call) {
458
484
  if (call && (typeof call === "object" || typeof call === "function")) {
459
485
  return call;
460
486
  } else if (call !== void 0) {
461
487
  throw new TypeError("Derived constructors may only return object or undefined");
462
488
  }
463
- return _assertThisInitialized$1(self);
489
+ return _assertThisInitialized$1(self2);
464
490
  }
465
491
  function _createSuper$1(Derived) {
466
492
  var hasNativeReflectConstruct = _isNativeReflectConstruct$1();
@@ -475,7 +501,51 @@ function _createSuper$1(Derived) {
475
501
  return _possibleConstructorReturn$1(this, result);
476
502
  };
477
503
  }
478
- function _toPrimitive$2(input, hint) {
504
+ function _slicedToArray(arr, i) {
505
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray$2(arr, i) || _nonIterableRest();
506
+ }
507
+ function _toConsumableArray$1(arr) {
508
+ return _arrayWithoutHoles$1(arr) || _iterableToArray$1(arr) || _unsupportedIterableToArray$2(arr) || _nonIterableSpread$1();
509
+ }
510
+ function _arrayWithoutHoles$1(arr) {
511
+ if (Array.isArray(arr))
512
+ return _arrayLikeToArray$2(arr);
513
+ }
514
+ function _arrayWithHoles(arr) {
515
+ if (Array.isArray(arr))
516
+ return arr;
517
+ }
518
+ function _iterableToArray$1(iter) {
519
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null)
520
+ return Array.from(iter);
521
+ }
522
+ function _unsupportedIterableToArray$2(o, minLen) {
523
+ if (!o)
524
+ return;
525
+ if (typeof o === "string")
526
+ return _arrayLikeToArray$2(o, minLen);
527
+ var n = Object.prototype.toString.call(o).slice(8, -1);
528
+ if (n === "Object" && o.constructor)
529
+ n = o.constructor.name;
530
+ if (n === "Map" || n === "Set")
531
+ return Array.from(o);
532
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
533
+ return _arrayLikeToArray$2(o, minLen);
534
+ }
535
+ function _arrayLikeToArray$2(arr, len) {
536
+ if (len == null || len > arr.length)
537
+ len = arr.length;
538
+ for (var i = 0, arr2 = new Array(len); i < len; i++)
539
+ arr2[i] = arr[i];
540
+ return arr2;
541
+ }
542
+ function _nonIterableSpread$1() {
543
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
544
+ }
545
+ function _nonIterableRest() {
546
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
547
+ }
548
+ function _toPrimitive$3(input, hint) {
479
549
  if (typeof input !== "object" || input === null)
480
550
  return input;
481
551
  var prim = input[Symbol.toPrimitive];
@@ -487,8 +557,8 @@ function _toPrimitive$2(input, hint) {
487
557
  }
488
558
  return (hint === "string" ? String : Number)(input);
489
559
  }
490
- function _toPropertyKey$2(arg) {
491
- var key = _toPrimitive$2(arg, "string");
560
+ function _toPropertyKey$3(arg) {
561
+ var key = _toPrimitive$3(arg, "string");
492
562
  return typeof key === "symbol" ? key : String(key);
493
563
  }
494
564
  function ownKeys$1(object, enumerableOnly) {
@@ -520,33 +590,33 @@ function _typeof$1(obj) {
520
590
  return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
521
591
  }, _typeof$1(obj);
522
592
  }
523
- function _classCallCheck$1(instance, Constructor) {
593
+ function _classCallCheck$2(instance, Constructor) {
524
594
  if (!(instance instanceof Constructor)) {
525
595
  throw new TypeError("Cannot call a class as a function");
526
596
  }
527
597
  }
528
- function _defineProperties$1(target, props) {
598
+ function _defineProperties$2(target, props) {
529
599
  for (var i = 0; i < props.length; i++) {
530
600
  var descriptor = props[i];
531
601
  descriptor.enumerable = descriptor.enumerable || false;
532
602
  descriptor.configurable = true;
533
603
  if ("value" in descriptor)
534
604
  descriptor.writable = true;
535
- Object.defineProperty(target, _toPropertyKey$1(descriptor.key), descriptor);
605
+ Object.defineProperty(target, _toPropertyKey$2(descriptor.key), descriptor);
536
606
  }
537
607
  }
538
- function _createClass$1(Constructor, protoProps, staticProps) {
608
+ function _createClass$2(Constructor, protoProps, staticProps) {
539
609
  if (protoProps)
540
- _defineProperties$1(Constructor.prototype, protoProps);
610
+ _defineProperties$2(Constructor.prototype, protoProps);
541
611
  if (staticProps)
542
- _defineProperties$1(Constructor, staticProps);
612
+ _defineProperties$2(Constructor, staticProps);
543
613
  Object.defineProperty(Constructor, "prototype", {
544
614
  writable: false
545
615
  });
546
616
  return Constructor;
547
617
  }
548
618
  function _defineProperty$1(obj, key, value) {
549
- key = _toPropertyKey$1(key);
619
+ key = _toPropertyKey$2(key);
550
620
  if (key in obj) {
551
621
  Object.defineProperty(obj, key, {
552
622
  value,
@@ -593,7 +663,7 @@ function _arrayLikeToArray$1(arr, len) {
593
663
  function _nonIterableSpread() {
594
664
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
595
665
  }
596
- function _toPrimitive$1(input, hint) {
666
+ function _toPrimitive$2(input, hint) {
597
667
  if (typeof input !== "object" || input === null)
598
668
  return input;
599
669
  var prim = input[Symbol.toPrimitive];
@@ -605,8 +675,8 @@ function _toPrimitive$1(input, hint) {
605
675
  }
606
676
  return (hint === "string" ? String : Number)(input);
607
677
  }
608
- function _toPropertyKey$1(arg) {
609
- var key = _toPrimitive$1(arg, "string");
678
+ function _toPropertyKey$2(arg) {
679
+ var key = _toPrimitive$2(arg, "string");
610
680
  return typeof key === "symbol" ? key : String(key);
611
681
  }
612
682
  function getDefaultExportFromCjs(x) {
@@ -830,10 +900,10 @@ var XG_DEBUG = {
830
900
  };
831
901
  var XgplayerTimeRange = /* @__PURE__ */ function() {
832
902
  function XgplayerTimeRange2(bufferedList) {
833
- _classCallCheck$1(this, XgplayerTimeRange2);
903
+ _classCallCheck$2(this, XgplayerTimeRange2);
834
904
  this.bufferedList = bufferedList;
835
905
  }
836
- _createClass$1(XgplayerTimeRange2, [{
906
+ _createClass$2(XgplayerTimeRange2, [{
837
907
  key: "start",
838
908
  value: function start(index) {
839
909
  return this.bufferedList[index].start;
@@ -1539,7 +1609,7 @@ var ERROR_MAP = {
1539
1609
  5: 5105,
1540
1610
  6: 5106
1541
1611
  };
1542
- var Errors = /* @__PURE__ */ _createClass$1(
1612
+ var Errors = /* @__PURE__ */ _createClass$2(
1543
1613
  function Errors2(player) {
1544
1614
  var errorInfo = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
1545
1615
  errorType: "",
@@ -1549,7 +1619,7 @@ var Errors = /* @__PURE__ */ _createClass$1(
1549
1619
  ext: {},
1550
1620
  mediaError: null
1551
1621
  };
1552
- _classCallCheck$1(this, Errors2);
1622
+ _classCallCheck$2(this, Errors2);
1553
1623
  var ERROR_TYPES = player && player.i18n ? player.i18n.ERROR_TYPES : null;
1554
1624
  if (player.media) {
1555
1625
  var mediaError = errorInfo.mediaError ? errorInfo.mediaError : player.media.error || {};
@@ -1766,7 +1836,7 @@ function showErrorMsg(pluginName, msg) {
1766
1836
  }
1767
1837
  var BasePlugin = /* @__PURE__ */ function() {
1768
1838
  function BasePlugin2(args) {
1769
- _classCallCheck$1(this, BasePlugin2);
1839
+ _classCallCheck$2(this, BasePlugin2);
1770
1840
  if (util.checkIsFunction(this.beforeCreate)) {
1771
1841
  this.beforeCreate(args);
1772
1842
  }
@@ -1780,7 +1850,7 @@ var BasePlugin = /* @__PURE__ */ function() {
1780
1850
  this.pluginName = "";
1781
1851
  this.__init(args);
1782
1852
  }
1783
- _createClass$1(BasePlugin2, [{
1853
+ _createClass$2(BasePlugin2, [{
1784
1854
  key: "beforeCreate",
1785
1855
  value: function beforeCreate(args) {
1786
1856
  }
@@ -2068,10 +2138,10 @@ function _regeneratorRuntime() {
2068
2138
  return obj[key] = value;
2069
2139
  };
2070
2140
  }
2071
- function wrap(innerFn, outerFn, self, tryLocsList) {
2141
+ function wrap(innerFn, outerFn, self2, tryLocsList) {
2072
2142
  var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []);
2073
2143
  return defineProperty(generator, "_invoke", {
2074
- value: makeInvokeMethod(innerFn, self, context)
2144
+ value: makeInvokeMethod(innerFn, self2, context)
2075
2145
  }), generator;
2076
2146
  }
2077
2147
  function tryCatch(fn, obj, arg) {
@@ -2138,7 +2208,7 @@ function _regeneratorRuntime() {
2138
2208
  }
2139
2209
  });
2140
2210
  }
2141
- function makeInvokeMethod(innerFn, self, context) {
2211
+ function makeInvokeMethod(innerFn, self2, context) {
2142
2212
  var state = "suspendedStart";
2143
2213
  return function(method, arg) {
2144
2214
  if ("executing" === state)
@@ -2167,7 +2237,7 @@ function _regeneratorRuntime() {
2167
2237
  } else
2168
2238
  "return" === context.method && context.abrupt("return", context.arg);
2169
2239
  state = "executing";
2170
- var record = tryCatch(innerFn, self, context);
2240
+ var record = tryCatch(innerFn, self2, context);
2171
2241
  if ("normal" === record.type) {
2172
2242
  if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel)
2173
2243
  continue;
@@ -2249,9 +2319,9 @@ function _regeneratorRuntime() {
2249
2319
  };
2250
2320
  }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function() {
2251
2321
  return this;
2252
- }), exports.AsyncIterator = AsyncIterator, exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
2322
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function(innerFn, outerFn, self2, tryLocsList, PromiseImpl) {
2253
2323
  void 0 === PromiseImpl && (PromiseImpl = Promise);
2254
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
2324
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self2, tryLocsList), PromiseImpl);
2255
2325
  return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function(result) {
2256
2326
  return result.done ? result.value : iter.next();
2257
2327
  });
@@ -2386,9 +2456,9 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2386
2456
  }
2387
2457
  function _asyncToGenerator(fn) {
2388
2458
  return function() {
2389
- var self = this, args = arguments;
2459
+ var self2 = this, args = arguments;
2390
2460
  return new Promise(function(resolve, reject) {
2391
- var gen = fn.apply(self, args);
2461
+ var gen = fn.apply(self2, args);
2392
2462
  function _next(value) {
2393
2463
  asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
2394
2464
  }
@@ -2399,33 +2469,33 @@ function _asyncToGenerator(fn) {
2399
2469
  });
2400
2470
  };
2401
2471
  }
2402
- function _classCallCheck(instance, Constructor) {
2472
+ function _classCallCheck$1(instance, Constructor) {
2403
2473
  if (!(instance instanceof Constructor)) {
2404
2474
  throw new TypeError("Cannot call a class as a function");
2405
2475
  }
2406
2476
  }
2407
- function _defineProperties(target, props) {
2477
+ function _defineProperties$1(target, props) {
2408
2478
  for (var i = 0; i < props.length; i++) {
2409
2479
  var descriptor = props[i];
2410
2480
  descriptor.enumerable = descriptor.enumerable || false;
2411
2481
  descriptor.configurable = true;
2412
2482
  if ("value" in descriptor)
2413
2483
  descriptor.writable = true;
2414
- Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
2484
+ Object.defineProperty(target, _toPropertyKey$1(descriptor.key), descriptor);
2415
2485
  }
2416
2486
  }
2417
- function _createClass(Constructor, protoProps, staticProps) {
2487
+ function _createClass$1(Constructor, protoProps, staticProps) {
2418
2488
  if (protoProps)
2419
- _defineProperties(Constructor.prototype, protoProps);
2489
+ _defineProperties$1(Constructor.prototype, protoProps);
2420
2490
  if (staticProps)
2421
- _defineProperties(Constructor, staticProps);
2491
+ _defineProperties$1(Constructor, staticProps);
2422
2492
  Object.defineProperty(Constructor, "prototype", {
2423
2493
  writable: false
2424
2494
  });
2425
2495
  return Constructor;
2426
2496
  }
2427
2497
  function _defineProperty(obj, key, value) {
2428
- key = _toPropertyKey(key);
2498
+ key = _toPropertyKey$1(key);
2429
2499
  if (key in obj) {
2430
2500
  Object.defineProperty(obj, key, {
2431
2501
  value,
@@ -2562,19 +2632,19 @@ function _objectWithoutProperties(source, excluded) {
2562
2632
  }
2563
2633
  return target;
2564
2634
  }
2565
- function _assertThisInitialized(self) {
2566
- if (self === void 0) {
2635
+ function _assertThisInitialized(self2) {
2636
+ if (self2 === void 0) {
2567
2637
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
2568
2638
  }
2569
- return self;
2639
+ return self2;
2570
2640
  }
2571
- function _possibleConstructorReturn(self, call) {
2641
+ function _possibleConstructorReturn(self2, call) {
2572
2642
  if (call && (typeof call === "object" || typeof call === "function")) {
2573
2643
  return call;
2574
2644
  } else if (call !== void 0) {
2575
2645
  throw new TypeError("Derived constructors may only return object or undefined");
2576
2646
  }
2577
- return _assertThisInitialized(self);
2647
+ return _assertThisInitialized(self2);
2578
2648
  }
2579
2649
  function _createSuper(Derived) {
2580
2650
  var hasNativeReflectConstruct = _isNativeReflectConstruct();
@@ -2688,7 +2758,7 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
2688
2758
  }
2689
2759
  };
2690
2760
  }
2691
- function _toPrimitive(input, hint) {
2761
+ function _toPrimitive$1(input, hint) {
2692
2762
  if (typeof input !== "object" || input === null)
2693
2763
  return input;
2694
2764
  var prim = input[Symbol.toPrimitive];
@@ -2700,8 +2770,8 @@ function _toPrimitive(input, hint) {
2700
2770
  }
2701
2771
  return (hint === "string" ? String : Number)(input);
2702
2772
  }
2703
- function _toPropertyKey(arg) {
2704
- var key = _toPrimitive(arg, "string");
2773
+ function _toPropertyKey$1(arg) {
2774
+ var key = _toPrimitive$1(arg, "string");
2705
2775
  return typeof key === "symbol" ? key : String(key);
2706
2776
  }
2707
2777
  function createPublicPromise() {
@@ -2800,7 +2870,7 @@ var StreamingError = /* @__PURE__ */ function(_Error) {
2800
2870
  var _super = _createSuper(StreamingError2);
2801
2871
  function StreamingError2(type, subType, origin, payload, msg) {
2802
2872
  var _this;
2803
- _classCallCheck(this, StreamingError2);
2873
+ _classCallCheck$1(this, StreamingError2);
2804
2874
  _this = _super.call(this, msg || (origin === null || origin === void 0 ? void 0 : origin.message));
2805
2875
  _this.errorType = type === ERR.NETWORK_TIMEOUT ? ERR.NETWORK : type;
2806
2876
  _this.originError = origin;
@@ -2813,7 +2883,7 @@ var StreamingError = /* @__PURE__ */ function(_Error) {
2813
2883
  }
2814
2884
  return _this;
2815
2885
  }
2816
- _createClass(StreamingError2, null, [{
2886
+ _createClass$1(StreamingError2, null, [{
2817
2887
  key: "create",
2818
2888
  value: function create(type, subType, origin, payload, msg) {
2819
2889
  if (type instanceof StreamingError2) {
@@ -2849,7 +2919,7 @@ var LOG_MAX_SIZE = 200 * 1024;
2849
2919
  var SIMPLE_TYPE = ["Boolean", "Number", "String", "Undefined", "Null", "Date", "Object"];
2850
2920
  var Logger = /* @__PURE__ */ function() {
2851
2921
  function Logger2(name, config) {
2852
- _classCallCheck(this, Logger2);
2922
+ _classCallCheck$1(this, Logger2);
2853
2923
  this.name = name || "";
2854
2924
  this._prefix = "[".concat(this.name, "]");
2855
2925
  this.logCacheLevel = (config === null || config === void 0 ? void 0 : config.logCacheLevel) || 3;
@@ -2857,7 +2927,7 @@ var Logger = /* @__PURE__ */ function() {
2857
2927
  this.logSize = 0;
2858
2928
  this.logTextArray = [];
2859
2929
  }
2860
- _createClass(Logger2, [{
2930
+ _createClass$1(Logger2, [{
2861
2931
  key: "debug",
2862
2932
  value: function debug() {
2863
2933
  var _console;
@@ -3035,7 +3105,7 @@ var NetError = /* @__PURE__ */ function(_Error) {
3035
3105
  var _super = _createSuper(NetError2);
3036
3106
  function NetError2(url, request, response, msg) {
3037
3107
  var _this;
3038
- _classCallCheck(this, NetError2);
3108
+ _classCallCheck$1(this, NetError2);
3039
3109
  _this = _super.call(this, msg);
3040
3110
  _defineProperty(_assertThisInitialized(_this), "retryCount", 0);
3041
3111
  _defineProperty(_assertThisInitialized(_this), "isTimeout", false);
@@ -3048,7 +3118,7 @@ var NetError = /* @__PURE__ */ function(_Error) {
3048
3118
  _this.response = response;
3049
3119
  return _this;
3050
3120
  }
3051
- return _createClass(NetError2);
3121
+ return _createClass$1(NetError2);
3052
3122
  }(/* @__PURE__ */ _wrapNativeSuper(Error));
3053
3123
  var toString = Object.prototype.toString;
3054
3124
  function isObject(a) {
@@ -3173,7 +3243,7 @@ var FetchLoader = /* @__PURE__ */ function(_EventEmitter) {
3173
3243
  var _super = _createSuper(FetchLoader2);
3174
3244
  function FetchLoader2() {
3175
3245
  var _this;
3176
- _classCallCheck(this, FetchLoader2);
3246
+ _classCallCheck$1(this, FetchLoader2);
3177
3247
  _this = _super.call(this);
3178
3248
  _defineProperty(_assertThisInitialized(_this), "_abortController", null);
3179
3249
  _defineProperty(_assertThisInitialized(_this), "_timeoutTimer", null);
@@ -3191,7 +3261,7 @@ var FetchLoader = /* @__PURE__ */ function(_EventEmitter) {
3191
3261
  _defineProperty(_assertThisInitialized(_this), "_priOptions", null);
3192
3262
  return _this;
3193
3263
  }
3194
- _createClass(FetchLoader2, [{
3264
+ _createClass$1(FetchLoader2, [{
3195
3265
  key: "load",
3196
3266
  value: function load(_ref) {
3197
3267
  var _this$_abortControlle, _this2 = this;
@@ -3625,7 +3695,7 @@ var XhrLoader = /* @__PURE__ */ function(_EventEmitter) {
3625
3695
  var _super = _createSuper(XhrLoader2);
3626
3696
  function XhrLoader2() {
3627
3697
  var _this;
3628
- _classCallCheck(this, XhrLoader2);
3698
+ _classCallCheck$1(this, XhrLoader2);
3629
3699
  _this = _super.call(this);
3630
3700
  _defineProperty(_assertThisInitialized(_this), "_xhr", null);
3631
3701
  _defineProperty(_assertThisInitialized(_this), "_aborted", false);
@@ -3655,7 +3725,7 @@ var XhrLoader = /* @__PURE__ */ function(_EventEmitter) {
3655
3725
  _defineProperty(_assertThisInitialized(_this), "_priOptions", null);
3656
3726
  return _this;
3657
3727
  }
3658
- _createClass(XhrLoader2, [{
3728
+ _createClass$1(XhrLoader2, [{
3659
3729
  key: "load",
3660
3730
  value: function load(req) {
3661
3731
  var _this2 = this;
@@ -3940,7 +4010,7 @@ var XhrLoader = /* @__PURE__ */ function(_EventEmitter) {
3940
4010
  var _excluded = ["retry", "retryDelay", "onRetryError", "transformError"];
3941
4011
  var Task = /* @__PURE__ */ function() {
3942
4012
  function Task2(type, config) {
3943
- _classCallCheck(this, Task2);
4013
+ _classCallCheck$1(this, Task2);
3944
4014
  this.promise = createPublicPromise();
3945
4015
  this.alive = !!config.onProgress;
3946
4016
  !config.logger && (config.logger = new Logger("Loader"));
@@ -3953,7 +4023,7 @@ var Task = /* @__PURE__ */ function() {
3953
4023
  this._retryCheckFunc = config.retryCheckFunc;
3954
4024
  this._logger = config.logger;
3955
4025
  }
3956
- _createClass(Task2, [{
4026
+ _createClass$1(Task2, [{
3957
4027
  key: "exec",
3958
4028
  value: function exec() {
3959
4029
  var _this = this;
@@ -4072,7 +4142,7 @@ var NetLoader = /* @__PURE__ */ function(_EventEmitter) {
4072
4142
  var _super = _createSuper(NetLoader2);
4073
4143
  function NetLoader2(cfg) {
4074
4144
  var _this;
4075
- _classCallCheck(this, NetLoader2);
4145
+ _classCallCheck$1(this, NetLoader2);
4076
4146
  _this = _super.call(this, cfg);
4077
4147
  _defineProperty(_assertThisInitialized(_this), "type", LoaderType.FETCH);
4078
4148
  _defineProperty(_assertThisInitialized(_this), "_queue", []);
@@ -4087,7 +4157,7 @@ var NetLoader = /* @__PURE__ */ function(_EventEmitter) {
4087
4157
  _this.log = cfg.logger;
4088
4158
  return _this;
4089
4159
  }
4090
- _createClass(NetLoader2, [{
4160
+ _createClass$1(NetLoader2, [{
4091
4161
  key: "isFetch",
4092
4162
  value: function isFetch() {
4093
4163
  return this.type === LoaderType.FETCH;
@@ -4191,7 +4261,8 @@ var NetLoader = /* @__PURE__ */ function(_EventEmitter) {
4191
4261
  return NetLoader2;
4192
4262
  }(EventEmitter);
4193
4263
  var EXTEND_EVENTS = {
4194
- RTC_STATE_CHANGE: "core.rtcstatechange"
4264
+ RTC_STATE_CHANGE: "core.rtcstatechange",
4265
+ RTC_NETWORK: "core.rtcnetwork"
4195
4266
  };
4196
4267
  var lib = {};
4197
4268
  var parser$1 = {};
@@ -4881,7 +4952,60 @@ function getOption(opts) {
4881
4952
  networkEvaluateInterval: 1e3,
4882
4953
  delayHint: 0,
4883
4954
  seamlesslyReload: false,
4884
- enableOriginSdpLogger: false
4955
+ enableSei: false,
4956
+ enableOriginSdpLogger: false,
4957
+ checkStatsErrorDelay: 5e3,
4958
+ enableNetworkQuality: false,
4959
+ networkQuality: {
4960
+ networkQos: {
4961
+ 1: {
4962
+ "maxRtt": 250,
4963
+ "maxLoss": 0.15
4964
+ },
4965
+ 2: {
4966
+ "maxRtt": 500,
4967
+ "maxLoss": 0.3,
4968
+ "minRetransmittedRate": 0.2
4969
+ },
4970
+ 3: {
4971
+ "maxRtt": 750,
4972
+ "maxLoss": 0.45,
4973
+ "minRetransmittedRate": 0.35
4974
+ },
4975
+ 4: {
4976
+ "maxRtt": 1e3,
4977
+ "maxLoss": 0.6,
4978
+ "minRetransmittedRate": 0.5
4979
+ }
4980
+ },
4981
+ networkQoe: {
4982
+ audioDelay: 2e3,
4983
+ audioStallRadio: 0.3,
4984
+ videoDelay: 2e3,
4985
+ videoStallRadio: 0.6
4986
+ }
4987
+ },
4988
+ enableAdaptiveJitterBuffer: false,
4989
+ adaptiveJitterBuffer: {
4990
+ networkWindow: 3
4991
+ },
4992
+ networkStrategy: {
4993
+ 1: {
4994
+ "jitterBuffer": null
4995
+ },
4996
+ 2: {
4997
+ "jitterBuffer": 1.5
4998
+ },
4999
+ 3: {
5000
+ "jitterBuffer": 2
5001
+ },
5002
+ 4: {
5003
+ "jitterBuffer": 3
5004
+ },
5005
+ 5: {
5006
+ "jitterBuffer": 3
5007
+ }
5008
+ }
4885
5009
  }, opts);
4886
5010
  }
4887
5011
  function _getStats(stats) {
@@ -4896,10 +5020,11 @@ function _getStats(stats) {
4896
5020
  }
4897
5021
  });
4898
5022
  return inboundRtps.map(function(inbound) {
5023
+ var _inbound$mediaType;
4899
5024
  var codec = stats.get(inbound.codecId);
4900
5025
  var track = stats.get(inbound.trackId);
4901
5026
  return {
4902
- type: inbound.mediaType,
5027
+ type: (_inbound$mediaType = inbound.mediaType) !== null && _inbound$mediaType !== void 0 ? _inbound$mediaType : inbound.kind,
4903
5028
  inboundRtp: inbound,
4904
5029
  remoteOutBoundRtp: remoteOutboundRtps.find(function(x) {
4905
5030
  return x.mediaType === inbound.mediaType;
@@ -4919,7 +5044,7 @@ function getStats(pc) {
4919
5044
  });
4920
5045
  }
4921
5046
  function getStatsSnapshoot(stats) {
4922
- var _v$codec, _v$codec2, _v$codec3, _v$inboundRtp, _v$inboundRtp2, _v$inboundRtp3, _v$inboundRtp4, _v$inboundRtp5, _v$inboundRtp6, _v$inboundRtp7, _v$inboundRtp8, _v$inboundRtp9, _v$inboundRtp10, _v$inboundRtp11, _v$inboundRtp12, _v$inboundRtp13, _v$inboundRtp14, _v$inboundRtp15, _a$codec, _a$codec2, _a$codec3, _a$inboundRtp, _a$inboundRtp2, _a$inboundRtp3, _a$inboundRtp4, _a$inboundRtp5, _a$inboundRtp6, _a$inboundRtp7, _a$inboundRtp8;
5047
+ var _v$inboundRtp, _v$codec, _v$codec2, _v$codec3, _v$inboundRtp4, _v$inboundRtp5, _v$inboundRtp6, _v$inboundRtp7, _v$inboundRtp8, _v$inboundRtp9, _v$inboundRtp10, _v$inboundRtp11, _v$inboundRtp$framesR, _v$inboundRtp12, _v$track, _v$inboundRtp13, _v$inboundRtp14, _v$inboundRtp15, _v$inboundRtp16, _v$inboundRtp17, _v$inboundRtp18, _a$codec, _a$codec2, _a$codec3, _a$inboundRtp, _a$inboundRtp2, _a$inboundRtp3, _a$inboundRtp4, _a$inboundRtp5, _a$inboundRtp6, _a$inboundRtp7, _a$inboundRtp8;
4923
5048
  var v = stats === null || stats === void 0 ? void 0 : stats.filter(function(x) {
4924
5049
  return x.type === "video";
4925
5050
  })[0];
@@ -4928,6 +5053,7 @@ function getStatsSnapshoot(stats) {
4928
5053
  })[0];
4929
5054
  var videoRemote;
4930
5055
  var audioRemote;
5056
+ var averageJitterBufferDelay;
4931
5057
  if (v && v.remoteOutBoundRtp) {
4932
5058
  videoRemote = {
4933
5059
  bytesSent: v.remoteOutBoundRtp.bytesSent,
@@ -4940,26 +5066,31 @@ function getStatsSnapshoot(stats) {
4940
5066
  packetsSent: a.remoteOutBoundRtp.packetsSent
4941
5067
  };
4942
5068
  }
5069
+ if ((v === null || v === void 0 ? void 0 : (_v$inboundRtp = v.inboundRtp) === null || _v$inboundRtp === void 0 ? void 0 : _v$inboundRtp.jitterBufferDelay) !== void 0) {
5070
+ var _v$inboundRtp2, _v$inboundRtp3;
5071
+ averageJitterBufferDelay = ((_v$inboundRtp2 = v.inboundRtp) === null || _v$inboundRtp2 === void 0 ? void 0 : _v$inboundRtp2.jitterBufferDelay) / ((_v$inboundRtp3 = v.inboundRtp) === null || _v$inboundRtp3 === void 0 ? void 0 : _v$inboundRtp3.jitterBufferEmittedCount) * 1e3;
5072
+ }
4943
5073
  return {
4944
5074
  video: !v ? void 0 : {
4945
5075
  codec: (_v$codec = v.codec) === null || _v$codec === void 0 ? void 0 : _v$codec.mimeType,
4946
5076
  payloadType: (_v$codec2 = v.codec) === null || _v$codec2 === void 0 ? void 0 : _v$codec2.payloadType,
4947
5077
  sdpFmtpLine: (_v$codec3 = v.codec) === null || _v$codec3 === void 0 ? void 0 : _v$codec3.sdpFmtpLine,
4948
- bytesReceived: ((_v$inboundRtp = v.inboundRtp) === null || _v$inboundRtp === void 0 ? void 0 : _v$inboundRtp.bytesReceived) || 0,
4949
- firCount: (_v$inboundRtp2 = v.inboundRtp) === null || _v$inboundRtp2 === void 0 ? void 0 : _v$inboundRtp2.firCount,
4950
- pliCount: (_v$inboundRtp3 = v.inboundRtp) === null || _v$inboundRtp3 === void 0 ? void 0 : _v$inboundRtp3.pliCount,
4951
- frameHeight: (_v$inboundRtp4 = v.inboundRtp) === null || _v$inboundRtp4 === void 0 ? void 0 : _v$inboundRtp4.frameHeight,
4952
- frameWidth: (_v$inboundRtp5 = v.inboundRtp) === null || _v$inboundRtp5 === void 0 ? void 0 : _v$inboundRtp5.frameWidth,
4953
- framesDecoded: (_v$inboundRtp6 = v.inboundRtp) === null || _v$inboundRtp6 === void 0 ? void 0 : _v$inboundRtp6.framesDecoded,
4954
- framesDropped: (_v$inboundRtp7 = v.inboundRtp) === null || _v$inboundRtp7 === void 0 ? void 0 : _v$inboundRtp7.framesDropped,
4955
- framesPerSecond: (_v$inboundRtp8 = v.inboundRtp) === null || _v$inboundRtp8 === void 0 ? void 0 : _v$inboundRtp8.framesPerSecond,
4956
- framesReceived: (_v$inboundRtp9 = v.inboundRtp) === null || _v$inboundRtp9 === void 0 ? void 0 : _v$inboundRtp9.framesReceived,
4957
- jitter: (_v$inboundRtp10 = v.inboundRtp) === null || _v$inboundRtp10 === void 0 ? void 0 : _v$inboundRtp10.jitter,
4958
- jitterBufferDelay: (_v$inboundRtp11 = v.inboundRtp) === null || _v$inboundRtp11 === void 0 ? void 0 : _v$inboundRtp11.jitterBufferDelay,
4959
- keyFramesDecoded: (_v$inboundRtp12 = v.inboundRtp) === null || _v$inboundRtp12 === void 0 ? void 0 : _v$inboundRtp12.keyFramesDecoded,
4960
- nackCount: (_v$inboundRtp13 = v.inboundRtp) === null || _v$inboundRtp13 === void 0 ? void 0 : _v$inboundRtp13.nackCount,
4961
- packetsLost: ((_v$inboundRtp14 = v.inboundRtp) === null || _v$inboundRtp14 === void 0 ? void 0 : _v$inboundRtp14.packetsLost) || 0,
4962
- packetsReceived: ((_v$inboundRtp15 = v.inboundRtp) === null || _v$inboundRtp15 === void 0 ? void 0 : _v$inboundRtp15.packetsReceived) || 0
5078
+ bytesReceived: ((_v$inboundRtp4 = v.inboundRtp) === null || _v$inboundRtp4 === void 0 ? void 0 : _v$inboundRtp4.bytesReceived) || 0,
5079
+ firCount: (_v$inboundRtp5 = v.inboundRtp) === null || _v$inboundRtp5 === void 0 ? void 0 : _v$inboundRtp5.firCount,
5080
+ pliCount: (_v$inboundRtp6 = v.inboundRtp) === null || _v$inboundRtp6 === void 0 ? void 0 : _v$inboundRtp6.pliCount,
5081
+ frameHeight: (_v$inboundRtp7 = v.inboundRtp) === null || _v$inboundRtp7 === void 0 ? void 0 : _v$inboundRtp7.frameHeight,
5082
+ frameWidth: (_v$inboundRtp8 = v.inboundRtp) === null || _v$inboundRtp8 === void 0 ? void 0 : _v$inboundRtp8.frameWidth,
5083
+ framesDecoded: (_v$inboundRtp9 = v.inboundRtp) === null || _v$inboundRtp9 === void 0 ? void 0 : _v$inboundRtp9.framesDecoded,
5084
+ framesDropped: (_v$inboundRtp10 = v.inboundRtp) === null || _v$inboundRtp10 === void 0 ? void 0 : _v$inboundRtp10.framesDropped,
5085
+ framesPerSecond: (_v$inboundRtp11 = v.inboundRtp) === null || _v$inboundRtp11 === void 0 ? void 0 : _v$inboundRtp11.framesPerSecond,
5086
+ framesReceived: (_v$inboundRtp$framesR = (_v$inboundRtp12 = v.inboundRtp) === null || _v$inboundRtp12 === void 0 ? void 0 : _v$inboundRtp12.framesReceived) !== null && _v$inboundRtp$framesR !== void 0 ? _v$inboundRtp$framesR : (_v$track = v.track) === null || _v$track === void 0 ? void 0 : _v$track.framesReceived,
5087
+ jitter: (_v$inboundRtp13 = v.inboundRtp) === null || _v$inboundRtp13 === void 0 ? void 0 : _v$inboundRtp13.jitter,
5088
+ jitterBufferDelay: (_v$inboundRtp14 = v.inboundRtp) === null || _v$inboundRtp14 === void 0 ? void 0 : _v$inboundRtp14.jitterBufferDelay,
5089
+ keyFramesDecoded: (_v$inboundRtp15 = v.inboundRtp) === null || _v$inboundRtp15 === void 0 ? void 0 : _v$inboundRtp15.keyFramesDecoded,
5090
+ nackCount: (_v$inboundRtp16 = v.inboundRtp) === null || _v$inboundRtp16 === void 0 ? void 0 : _v$inboundRtp16.nackCount,
5091
+ packetsLost: ((_v$inboundRtp17 = v.inboundRtp) === null || _v$inboundRtp17 === void 0 ? void 0 : _v$inboundRtp17.packetsLost) || 0,
5092
+ packetsReceived: ((_v$inboundRtp18 = v.inboundRtp) === null || _v$inboundRtp18 === void 0 ? void 0 : _v$inboundRtp18.packetsReceived) || 0,
5093
+ averageJitterBufferDelay
4963
5094
  },
4964
5095
  audio: !a ? void 0 : {
4965
5096
  codec: (_a$codec = a.codec) === null || _a$codec === void 0 ? void 0 : _a$codec.mimeType,
@@ -4982,7 +5113,7 @@ var QUEUE_SIZE = 5;
4982
5113
  var NetworkEvaluate = /* @__PURE__ */ function() {
4983
5114
  function NetworkEvaluate2(pc, interval) {
4984
5115
  var _this = this;
4985
- _classCallCheck$2(this, NetworkEvaluate2);
5116
+ _classCallCheck$3(this, NetworkEvaluate2);
4986
5117
  _defineProperty$2(this, "_pc", null);
4987
5118
  _defineProperty$2(this, "_lastVideoStats", null);
4988
5119
  _defineProperty$2(this, "_lastRemoteVideoStats", null);
@@ -5045,7 +5176,7 @@ var NetworkEvaluate = /* @__PURE__ */ function() {
5045
5176
  this._timerInterval = interval;
5046
5177
  this.start(interval);
5047
5178
  }
5048
- _createClass$2(NetworkEvaluate2, [{
5179
+ _createClass$3(NetworkEvaluate2, [{
5049
5180
  key: "start",
5050
5181
  value: function start(interval) {
5051
5182
  clearInterval(this._timer);
@@ -5131,105 +5262,1600 @@ var NetworkEvaluate = /* @__PURE__ */ function() {
5131
5262
  }]);
5132
5263
  return NetworkEvaluate2;
5133
5264
  }();
5134
- var logger = new Logger("rts");
5135
- var Rts = /* @__PURE__ */ function(_EventEmitter) {
5136
- _inherits$1(Rts2, _EventEmitter);
5137
- var _super = _createSuper$1(Rts2);
5138
- function Rts2(opts) {
5139
- var _this;
5140
- _classCallCheck$2(this, Rts2);
5141
- _this = _super.call(this);
5142
- _defineProperty$2(_assertThisInitialized$1(_this), "_url", "");
5143
- _defineProperty$2(_assertThisInitialized$1(_this), "_pc", null);
5144
- _defineProperty$2(_assertThisInitialized$1(_this), "_audioTransceicer", null);
5145
- _defineProperty$2(_assertThisInitialized$1(_this), "_videoTransceicer", null);
5146
- _defineProperty$2(_assertThisInitialized$1(_this), "_mediaStream", null);
5147
- _defineProperty$2(_assertThisInitialized$1(_this), "_lastMediaStream", null);
5148
- _defineProperty$2(_assertThisInitialized$1(_this), "_media", null);
5149
- _defineProperty$2(_assertThisInitialized$1(_this), "_opts", null);
5150
- _defineProperty$2(_assertThisInitialized$1(_this), "_loader", null);
5151
- _defineProperty$2(_assertThisInitialized$1(_this), "_networkEvaluate", null);
5152
- _defineProperty$2(_assertThisInitialized$1(_this), "_retry", 0);
5153
- _defineProperty$2(_assertThisInitialized$1(_this), "_waitingTimer", 0);
5154
- _defineProperty$2(_assertThisInitialized$1(_this), "_rctConnectStartTs", 0);
5155
- _defineProperty$2(_assertThisInitialized$1(_this), "_isReplacing", false);
5156
- _defineProperty$2(_assertThisInitialized$1(_this), "_onTrack", function(e) {
5157
- logger.log("addTrack: ", e.track, e.streams);
5158
- _this["_".concat(e.track.kind)] = e.track;
5265
+ function isSupported() {
5266
+ if (!window.RTCPeerConnection || !window.RTCPeerConnection.prototype.addTransceiver) {
5267
+ return false;
5268
+ }
5269
+ return true;
5270
+ }
5271
+ function getCapacity() {
5272
+ if (!isSupported())
5273
+ return Promise.reject("RTCPeerConnection no support");
5274
+ var pc;
5275
+ try {
5276
+ pc = new RTCPeerConnection();
5277
+ pc.addTransceiver("video", {
5278
+ direction: "recvonly"
5159
5279
  });
5160
- _defineProperty$2(_assertThisInitialized$1(_this), "_mockWaitingByTimeupdate", function() {
5161
- var _this$_pc, _this$_pc2;
5162
- if (!(((_this$_pc = _this._pc) === null || _this$_pc === void 0 ? void 0 : _this$_pc.connectionState) === "connected" || ((_this$_pc2 = _this._pc) === null || _this$_pc2 === void 0 ? void 0 : _this$_pc2.iceConnectionState) === "connected"))
5163
- return;
5164
- clearTimeout(_this._waitingTimer);
5165
- _this._waitingTimer = setTimeout(function() {
5166
- var _this$_media;
5167
- if ((_this$_media = _this._media) !== null && _this$_media !== void 0 && _this$_media.paused)
5168
- return;
5169
- _this.emit("waiting");
5170
- }, _this._opts.stallInterval);
5280
+ pc.addTransceiver("audio", {
5281
+ direction: "recvonly"
5171
5282
  });
5172
- _defineProperty$2(_assertThisInitialized$1(_this), "_onLoadedData", function() {
5173
- logger.log("loadeddata emit");
5174
- _this.getStatsSnapshoot().then(function(snap) {
5175
- _this.emit(EVENT.METADATA_PARSED, {
5176
- type: "video",
5177
- elapsed: Date.now() - _this._rctConnectStartTs,
5178
- meta: snap.video
5179
- });
5180
- _this.emit(EVENT.METADATA_PARSED, {
5181
- type: "audio",
5182
- elapsed: Date.now() - _this._rctConnectStartTs,
5183
- meta: snap.audio
5184
- });
5185
- });
5283
+ } catch (e) {
5284
+ return Promise.reject(e === null || e === void 0 ? void 0 : e.message);
5285
+ }
5286
+ return pc.createOffer().then(function(offer) {
5287
+ var _sdpJson$media, _sdpJson$media2, _vMedia$rtp, _aMedia$rtp;
5288
+ logger.log(offer.sdp);
5289
+ var sdpJson = lib.parse(offer.sdp);
5290
+ var vMedia = (_sdpJson$media = sdpJson.media) === null || _sdpJson$media === void 0 ? void 0 : _sdpJson$media.filter(function(x) {
5291
+ return x.type === "video";
5292
+ })[0];
5293
+ var aMedia = (_sdpJson$media2 = sdpJson.media) === null || _sdpJson$media2 === void 0 ? void 0 : _sdpJson$media2.filter(function(x) {
5294
+ return x.type === "audio";
5295
+ })[0];
5296
+ var vCodecs = vMedia === null || vMedia === void 0 ? void 0 : (_vMedia$rtp = vMedia.rtp) === null || _vMedia$rtp === void 0 ? void 0 : _vMedia$rtp.filter(function(x) {
5297
+ return x.codec === "VP8" || x.codec === "VP9" || x.codec === "H264";
5186
5298
  });
5187
- _defineProperty$2(_assertThisInitialized$1(_this), "_onLoaderRetry", function(error, retryTime) {
5188
- _this.emit(EVENT.LOAD_RETRY, {
5189
- error: StreamingError.network(error),
5190
- retryTime
5191
- });
5299
+ var aCodecs = aMedia === null || aMedia === void 0 ? void 0 : (_aMedia$rtp = aMedia.rtp) === null || _aMedia$rtp === void 0 ? void 0 : _aMedia$rtp.filter(function(x) {
5300
+ return x.codec === "opus";
5192
5301
  });
5193
- _this._opts = getOption(opts);
5194
- _this._media = _this._opts.media;
5195
- _this._loader = new NetLoader(_objectSpread2$2(_objectSpread2$2({}, opts.fetchOptions), {}, {
5196
- responseType: "json",
5197
- method: "POST",
5198
- retry: _this._opts.retryCount,
5199
- retryDelay: _this._opts.retryDelay,
5200
- timeout: _this._opts.loadTimeout,
5201
- onRetryError: _this._onLoaderRetry,
5202
- logger
5203
- }));
5204
- _this._retry = _this._opts.retryCount;
5205
- _this._bindMediaEvent();
5206
- if (_this._opts.mediaStream && _this._opts.seamlesslyReload) {
5207
- _this._lastMediaStream = _this._opts.mediaStream;
5208
- }
5209
- return _this;
5210
- }
5211
- _createClass$2(Rts2, [{
5212
- key: "pc",
5213
- get: function get() {
5214
- return this._pc;
5302
+ var vFmtp = vMedia === null || vMedia === void 0 ? void 0 : vMedia.fmtp;
5303
+ var aFmtp = aMedia === null || aMedia === void 0 ? void 0 : aMedia.fmtp;
5304
+ vFmtp && vCodecs.map(function(codec) {
5305
+ var _vFmtp$filter$;
5306
+ codec.config = (_vFmtp$filter$ = vFmtp.filter(function(x) {
5307
+ return x.payload === codec.payload;
5308
+ })[0]) === null || _vFmtp$filter$ === void 0 ? void 0 : _vFmtp$filter$.config;
5309
+ });
5310
+ aFmtp && aCodecs.map(function(codec) {
5311
+ var _aFmtp$filter$;
5312
+ codec.config = (_aFmtp$filter$ = aFmtp.filter(function(x) {
5313
+ return x.payload === codec.payload;
5314
+ })[0]) === null || _aFmtp$filter$ === void 0 ? void 0 : _aFmtp$filter$.config;
5315
+ });
5316
+ pc.close();
5317
+ return {
5318
+ video: vCodecs,
5319
+ audio: aCodecs
5320
+ };
5321
+ });
5322
+ }
5323
+ var isEncodedTransformSupported = function isEncodedTransformSupported2() {
5324
+ return typeof TransformStream !== "undefined" && typeof RTCRtpSender !== "undefined" && typeof RTCRtpReceiver !== "undefined" && typeof RTCRtpScriptTransform !== "undefined" && "transform" in RTCRtpSender.prototype && "transform" in RTCRtpReceiver.prototype && isWorkerSupported() && isMessageChannelSupported();
5325
+ };
5326
+ var isWorkerSupported = function isWorkerSupported2() {
5327
+ return typeof window !== "undefined" && window.Worker;
5328
+ };
5329
+ var isMessageChannelSupported = function isMessageChannelSupported2() {
5330
+ return typeof MessageChannel !== "undefined";
5331
+ };
5332
+ var isLegacyEncodedTransformSupported = function isLegacyEncodedTransformSupported2() {
5333
+ return typeof TransformStream !== "undefined" && typeof RTCRtpSender !== "undefined" && typeof RTCRtpReceiver !== "undefined" && typeof RTCRtpSender.prototype.createEncodedStreams !== "undefined" && typeof RTCRtpReceiver.prototype.createEncodedStreams !== "undefined";
5334
+ };
5335
+ var Nalunit = {
5336
+ getNALUnits: function getNALUnits(buffer) {
5337
+ var isH265 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
5338
+ if (buffer.length - buffer.position < 4) {
5339
+ return [];
5215
5340
  }
5216
- }, {
5217
- key: "audioTrack",
5218
- get: function get() {
5219
- return this._audio;
5341
+ var position = buffer.position;
5342
+ if (buffer.getInt32(position) === 1 || buffer.getInt16(position) === 0 && buffer.getInt8(position + 2) === 1) {
5343
+ return Nalunit.getAnnexbNals(buffer, isH265);
5344
+ } else {
5345
+ return Nalunit.getAvccNals(buffer, isH265);
5220
5346
  }
5221
- }, {
5222
- key: "videoTack",
5223
- get: function get() {
5224
- return this._video;
5347
+ },
5348
+ getAnnexbNals: function getAnnexbNals(buffer, isH265) {
5349
+ var nals = [];
5350
+ var position = Nalunit.getHeaderPositionAnnexB(buffer);
5351
+ var start = position.pos;
5352
+ var end = start;
5353
+ while (start < buffer.length - 4) {
5354
+ var header = new Uint8Array(buffer.buffer.slice(start, start + position.headerLength));
5355
+ if (position.pos === buffer.position) {
5356
+ buffer.skip(position.headerLength);
5357
+ }
5358
+ position = Nalunit.getHeaderPositionAnnexB(buffer);
5359
+ end = position.pos;
5360
+ var body = new Uint8Array(buffer.buffer.slice(start + header.byteLength, end));
5361
+ var unit = {
5362
+ header,
5363
+ body,
5364
+ type: -1
5365
+ };
5366
+ isH265 ? Nalunit.analyseH265Nal(unit) : Nalunit.analyseNal(unit);
5367
+ if ((unit.type <= 9 || isH265 && unit.type <= 40) && unit.type !== 0) {
5368
+ nals.push(unit);
5369
+ }
5370
+ buffer.skip(end - buffer.position);
5371
+ start = end;
5225
5372
  }
5226
- }, {
5227
- key: "loader",
5228
- get: function get() {
5229
- return this._loader;
5373
+ return nals;
5374
+ },
5375
+ getAvccNals: function getAvccNals(buffer, isH265) {
5376
+ var nals = [];
5377
+ while (buffer.position < buffer.length - 4) {
5378
+ var length = buffer.getInt32(buffer.position);
5379
+ if (buffer.length - buffer.position >= length) {
5380
+ var header = new Uint8Array(buffer.buffer.slice(buffer.position, buffer.position + 4));
5381
+ buffer.skip(4);
5382
+ var body = new Uint8Array(buffer.buffer.slice(buffer.position, buffer.position + length));
5383
+ buffer.skip(length);
5384
+ var unit = {
5385
+ header,
5386
+ body,
5387
+ type: -1
5388
+ };
5389
+ isH265 ? Nalunit.analyseH265Nal(unit) : Nalunit.analyseNal(unit);
5390
+ if (unit.type <= 9 && unit.type !== 0) {
5391
+ nals.push(unit);
5392
+ }
5393
+ } else {
5394
+ break;
5395
+ }
5230
5396
  }
5231
- }, {
5232
- key: "networkStats",
5397
+ return nals;
5398
+ },
5399
+ analyseNal: function analyseNal(unit) {
5400
+ var type = unit.body[0] & 31;
5401
+ unit.type = type;
5402
+ switch (type) {
5403
+ case 1:
5404
+ unit.ndr = true;
5405
+ break;
5406
+ case 5:
5407
+ unit.idr = true;
5408
+ break;
5409
+ case 6:
5410
+ unit.sei = true;
5411
+ break;
5412
+ case 7:
5413
+ unit.sps = true;
5414
+ break;
5415
+ case 8:
5416
+ unit.pps = true;
5417
+ break;
5418
+ }
5419
+ },
5420
+ analyseH265Nal: function analyseH265Nal(unit) {
5421
+ var type = (unit.body[0] & 126) >> 1;
5422
+ unit.type = type;
5423
+ switch (type) {
5424
+ case 39:
5425
+ case 40:
5426
+ unit.sei = true;
5427
+ break;
5428
+ }
5429
+ },
5430
+ getHeaderPositionAnnexB: function getHeaderPositionAnnexB(buffer) {
5431
+ var pos = buffer.position;
5432
+ var headerLength = 0;
5433
+ var bufferLen = buffer.length;
5434
+ while (headerLength !== 3 && headerLength !== 4 && pos < bufferLen - 4) {
5435
+ if (buffer.getInt16(pos) === 0) {
5436
+ if (buffer.getInt16(pos + 2) === 1) {
5437
+ headerLength = 4;
5438
+ } else if (buffer.getInt8(pos + 2) === 1) {
5439
+ headerLength = 3;
5440
+ } else {
5441
+ pos++;
5442
+ }
5443
+ } else {
5444
+ pos++;
5445
+ }
5446
+ }
5447
+ if (pos === bufferLen - 4) {
5448
+ if (buffer.getInt16(pos) === 0) {
5449
+ if (buffer.getInt16(pos + 2) === 1) {
5450
+ headerLength = 4;
5451
+ } else {
5452
+ pos = bufferLen;
5453
+ }
5454
+ } else {
5455
+ pos++;
5456
+ if (buffer.getInt16(pos) === 0 && buffer.getInt8(pos) === 1) {
5457
+ headerLength = 3;
5458
+ } else {
5459
+ pos = bufferLen;
5460
+ }
5461
+ }
5462
+ }
5463
+ return {
5464
+ pos,
5465
+ headerLength
5466
+ };
5467
+ },
5468
+ isH265VideoFrame: function isH265VideoFrame(chunk) {
5469
+ var _chunk$getMetadata, _chunk$getMetadata$ca;
5470
+ return (((_chunk$getMetadata = chunk.getMetadata) === null || _chunk$getMetadata === void 0 ? void 0 : (_chunk$getMetadata$ca = _chunk$getMetadata.call(chunk)) === null || _chunk$getMetadata$ca === void 0 ? void 0 : _chunk$getMetadata$ca.mimeType) || "").toLowerCase().includes("h265");
5471
+ }
5472
+ };
5473
+ var RTCDataView = /* @__PURE__ */ function() {
5474
+ function RTCDataView2(buffer) {
5475
+ _classCallCheck$3(this, RTCDataView2);
5476
+ _defineProperty$2(this, "_position", 0);
5477
+ this._dataview = new DataView(buffer);
5478
+ }
5479
+ _createClass$3(RTCDataView2, [{
5480
+ key: "length",
5481
+ get: function get() {
5482
+ return this.buffer.byteLength;
5483
+ }
5484
+ }, {
5485
+ key: "buffer",
5486
+ get: function get() {
5487
+ return this._dataview.buffer;
5488
+ }
5489
+ }, {
5490
+ key: "position",
5491
+ get: function get() {
5492
+ return this._position;
5493
+ },
5494
+ set: function set(value) {
5495
+ this._position = value;
5496
+ }
5497
+ }, {
5498
+ key: "back",
5499
+ value: function back(count) {
5500
+ this.position -= count;
5501
+ }
5502
+ }, {
5503
+ key: "getUint8",
5504
+ value: function getUint8(offset) {
5505
+ return this._dataview.getUint8(offset);
5506
+ }
5507
+ }, {
5508
+ key: "getInt8",
5509
+ value: function getInt8(offset) {
5510
+ return this._dataview.getInt8(offset);
5511
+ }
5512
+ }, {
5513
+ key: "getInt16",
5514
+ value: function getInt16(offset) {
5515
+ return this._dataview.getInt16(offset);
5516
+ }
5517
+ }, {
5518
+ key: "getUint16",
5519
+ value: function getUint16(offset) {
5520
+ return this._dataview.getUint16(offset);
5521
+ }
5522
+ }, {
5523
+ key: "getUint32",
5524
+ value: function getUint32(offset) {
5525
+ return this._dataview.getUint32(offset);
5526
+ }
5527
+ }, {
5528
+ key: "getInt32",
5529
+ value: function getInt32(offset) {
5530
+ return this._dataview.getInt32(offset);
5531
+ }
5532
+ }, {
5533
+ key: "skip",
5534
+ value: function skip(count) {
5535
+ var loop = Math.floor(count / 4);
5536
+ var last = count % 4;
5537
+ for (var i = 0; i < loop; i++) {
5538
+ RTCDataView2.readByte(this, 4);
5539
+ }
5540
+ if (last > 0) {
5541
+ RTCDataView2.readByte(this, last);
5542
+ }
5543
+ }
5544
+ }, {
5545
+ key: "readUint8",
5546
+ value: function readUint8() {
5547
+ return RTCDataView2.readByte(this, 1);
5548
+ }
5549
+ }, {
5550
+ key: "readUint16",
5551
+ value: function readUint16() {
5552
+ return RTCDataView2.readByte(this, 2);
5553
+ }
5554
+ }, {
5555
+ key: "readUint24",
5556
+ value: function readUint24() {
5557
+ return RTCDataView2.readByte(this, 3);
5558
+ }
5559
+ }, {
5560
+ key: "readUint32",
5561
+ value: function readUint32() {
5562
+ return RTCDataView2.readByte(this, 4);
5563
+ }
5564
+ }, {
5565
+ key: "readUint64",
5566
+ value: function readUint64() {
5567
+ return RTCDataView2.readByte(this, 8);
5568
+ }
5569
+ }, {
5570
+ key: "readInt8",
5571
+ value: function readInt8() {
5572
+ return RTCDataView2.readByte(this, 1, true);
5573
+ }
5574
+ }, {
5575
+ key: "readInt16",
5576
+ value: function readInt16() {
5577
+ return RTCDataView2.readByte(this, 2, true);
5578
+ }
5579
+ }, {
5580
+ key: "readInt32",
5581
+ value: function readInt32() {
5582
+ return RTCDataView2.readByte(this, 4, true);
5583
+ }
5584
+ }, {
5585
+ key: "writeUint32",
5586
+ value: function writeUint32(value) {
5587
+ return new Uint8Array([value >>> 24 & 255, value >>> 16 & 255, value >>> 8 & 255, value & 255]);
5588
+ }
5589
+ }], [{
5590
+ key: "readByte",
5591
+ value: function readByte(buffer, size, sign) {
5592
+ var res;
5593
+ switch (size) {
5594
+ case 1:
5595
+ if (sign) {
5596
+ res = buffer.getInt8(buffer.position);
5597
+ } else {
5598
+ res = buffer.getUint8(buffer.position);
5599
+ }
5600
+ break;
5601
+ case 2:
5602
+ if (sign) {
5603
+ res = buffer.getInt16(buffer.position);
5604
+ } else {
5605
+ res = buffer.getUint16(buffer.position);
5606
+ }
5607
+ break;
5608
+ case 3:
5609
+ if (sign) {
5610
+ throw new Error("not supported for readByte 3");
5611
+ } else {
5612
+ res = buffer.getUint8(buffer.position) << 16;
5613
+ res |= buffer.getUint8(buffer.position + 1) << 8;
5614
+ res |= buffer.getUint8(buffer.position + 2);
5615
+ }
5616
+ break;
5617
+ case 4:
5618
+ if (sign) {
5619
+ res = buffer.getInt32(buffer.position);
5620
+ } else {
5621
+ res = buffer.getUint32(buffer.position);
5622
+ }
5623
+ break;
5624
+ case 8:
5625
+ if (sign) {
5626
+ throw new Error("not supported for readBody 8");
5627
+ } else {
5628
+ res = buffer.getUint32(buffer.position) << 32;
5629
+ res |= buffer.getUint32(buffer.position + 4);
5630
+ }
5631
+ break;
5632
+ default:
5633
+ res = "";
5634
+ }
5635
+ buffer.position += size;
5636
+ return res;
5637
+ }
5638
+ }]);
5639
+ return RTCDataView2;
5640
+ }();
5641
+ function _classCallCheck(instance, Constructor) {
5642
+ if (!(instance instanceof Constructor)) {
5643
+ throw new TypeError("Cannot call a class as a function");
5644
+ }
5645
+ }
5646
+ function _defineProperties(target, props) {
5647
+ for (var i = 0; i < props.length; i++) {
5648
+ var descriptor = props[i];
5649
+ descriptor.enumerable = descriptor.enumerable || false;
5650
+ descriptor.configurable = true;
5651
+ if ("value" in descriptor)
5652
+ descriptor.writable = true;
5653
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
5654
+ }
5655
+ }
5656
+ function _createClass(Constructor, protoProps, staticProps) {
5657
+ if (protoProps)
5658
+ _defineProperties(Constructor.prototype, protoProps);
5659
+ if (staticProps)
5660
+ _defineProperties(Constructor, staticProps);
5661
+ Object.defineProperty(Constructor, "prototype", {
5662
+ writable: false
5663
+ });
5664
+ return Constructor;
5665
+ }
5666
+ function _toPrimitive(input, hint) {
5667
+ if (typeof input !== "object" || input === null)
5668
+ return input;
5669
+ var prim = input[Symbol.toPrimitive];
5670
+ if (prim !== void 0) {
5671
+ var res = prim.call(input, hint || "default");
5672
+ if (typeof res !== "object")
5673
+ return res;
5674
+ throw new TypeError("@@toPrimitive must return a primitive value.");
5675
+ }
5676
+ return (hint === "string" ? String : Number)(input);
5677
+ }
5678
+ function _toPropertyKey(arg) {
5679
+ var key = _toPrimitive(arg, "string");
5680
+ return typeof key === "symbol" ? key : String(key);
5681
+ }
5682
+ function readBig32(data) {
5683
+ var i = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0;
5684
+ return (data[i] << 24 >>> 0) + (data[i + 1] << 16) + (data[i + 2] << 8) + (data[i + 3] || 0);
5685
+ }
5686
+ var NALu = /* @__PURE__ */ function() {
5687
+ function NALu2() {
5688
+ _classCallCheck(this, NALu2);
5689
+ }
5690
+ _createClass(NALu2, null, [{
5691
+ key: "parseAnnexB",
5692
+ value: function parseAnnexB(data) {
5693
+ var j = data.byteLength - 1;
5694
+ var dropZerosLength = 0;
5695
+ do {
5696
+ if (data[j] === 0) {
5697
+ dropZerosLength++;
5698
+ } else {
5699
+ break;
5700
+ }
5701
+ j--;
5702
+ } while (j > 0);
5703
+ if (dropZerosLength >= 3) {
5704
+ data = data.subarray(0, j + 1);
5705
+ }
5706
+ var len = data.length;
5707
+ var start = 2;
5708
+ var end = 0;
5709
+ while (data[start] !== null && data[start] !== void 0 && data[start] !== 1) {
5710
+ start++;
5711
+ }
5712
+ start++;
5713
+ end = start + 2;
5714
+ if (end >= len)
5715
+ return [];
5716
+ var units = [];
5717
+ while (end < len) {
5718
+ switch (data[end]) {
5719
+ case 0:
5720
+ if (data[end - 1] !== 0) {
5721
+ end += 2;
5722
+ break;
5723
+ } else if (data[end - 2] !== 0) {
5724
+ end++;
5725
+ break;
5726
+ } else if (end < len - 1 && data[end + 1] !== 1) {
5727
+ end++;
5728
+ break;
5729
+ }
5730
+ if (start !== end - 2)
5731
+ units.push(data.subarray(start, end - 2));
5732
+ do {
5733
+ end++;
5734
+ } while (data[end] !== 1 && end < len);
5735
+ start = end + 1;
5736
+ end = start + 2;
5737
+ break;
5738
+ case 1:
5739
+ if (data[end - 1] !== 0 || data[end - 2] !== 0) {
5740
+ end += 3;
5741
+ break;
5742
+ }
5743
+ if (start !== end - 2)
5744
+ units.push(data.subarray(start, end - 2));
5745
+ start = end + 1;
5746
+ end = start + 2;
5747
+ break;
5748
+ default:
5749
+ end += 3;
5750
+ break;
5751
+ }
5752
+ }
5753
+ if (start < len)
5754
+ units.push(data.subarray(start));
5755
+ return units;
5756
+ }
5757
+ }, {
5758
+ key: "parseAvcC",
5759
+ value: function parseAvcC(data) {
5760
+ var size = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 4;
5761
+ if (data.length < 4)
5762
+ return;
5763
+ var dataLen = data.length;
5764
+ var units = [];
5765
+ var offset = 0;
5766
+ var length;
5767
+ while (offset + size < dataLen) {
5768
+ length = readBig32(data, offset);
5769
+ if (size === 3)
5770
+ length >>>= 8;
5771
+ offset += size;
5772
+ if (!length)
5773
+ continue;
5774
+ if (offset + length > dataLen) {
5775
+ break;
5776
+ }
5777
+ units.push(data.subarray(offset, offset + length));
5778
+ offset += length;
5779
+ }
5780
+ return units;
5781
+ }
5782
+ }, {
5783
+ key: "parseSEI",
5784
+ value: function parseSEI(unit, isHevc) {
5785
+ var len = unit.length;
5786
+ var i = isHevc ? 2 : 1;
5787
+ var type = 0;
5788
+ var size = 0;
5789
+ var uuid = "";
5790
+ while (unit[i] === 255) {
5791
+ type += 255;
5792
+ i++;
5793
+ }
5794
+ type += unit[i++];
5795
+ while (unit[i] === 255) {
5796
+ size += 255;
5797
+ i++;
5798
+ }
5799
+ size += unit[i++];
5800
+ if (type === 5 && len > i + 16) {
5801
+ for (var j = 0; j < 16; j++) {
5802
+ uuid += unit[i].toString(16);
5803
+ i++;
5804
+ }
5805
+ }
5806
+ return {
5807
+ payload: unit.subarray(i, i + size),
5808
+ type,
5809
+ size,
5810
+ uuid
5811
+ };
5812
+ }
5813
+ }, {
5814
+ key: "removeEPB",
5815
+ value: function removeEPB(uint) {
5816
+ var length = uint.byteLength;
5817
+ var emulationPreventionBytesPositions = [];
5818
+ var i = 1;
5819
+ while (i < length - 2) {
5820
+ if (uint[i] === 0 && uint[i + 1] === 0 && uint[i + 2] === 3) {
5821
+ emulationPreventionBytesPositions.push(i + 2);
5822
+ i += 2;
5823
+ } else {
5824
+ i++;
5825
+ }
5826
+ }
5827
+ if (!emulationPreventionBytesPositions.length)
5828
+ return uint;
5829
+ var newLength = length - emulationPreventionBytesPositions.length;
5830
+ var newData = new Uint8Array(newLength);
5831
+ var sourceIndex = 0;
5832
+ for (i = 0; i < newLength; sourceIndex++, i++) {
5833
+ if (sourceIndex === emulationPreventionBytesPositions[0]) {
5834
+ sourceIndex++;
5835
+ emulationPreventionBytesPositions.shift();
5836
+ }
5837
+ newData[i] = uint[sourceIndex];
5838
+ }
5839
+ return newData;
5840
+ }
5841
+ }]);
5842
+ return NALu2;
5843
+ }();
5844
+ function receiveSEITransform(postMessage) {
5845
+ var transform = new TransformStream({
5846
+ transform: function transform2(encodedFrame, controller) {
5847
+ var isH265 = Nalunit.isH265VideoFrame(encodedFrame);
5848
+ var NALs = Nalunit.getNALUnits(new RTCDataView(encodedFrame.data), isH265);
5849
+ NALs.forEach(function(nalUnit) {
5850
+ if (nalUnit.sei) {
5851
+ var decodedSei = NALu.parseSEI(NALu.removeEPB(nalUnit.body), false);
5852
+ if (decodedSei) {
5853
+ postMessage({
5854
+ data: decodedSei,
5855
+ sei: {
5856
+ code: decodedSei.type,
5857
+ content: decodedSei.payload
5858
+ }
5859
+ });
5860
+ }
5861
+ }
5862
+ });
5863
+ controller.enqueue(encodedFrame);
5864
+ }
5865
+ });
5866
+ return transform;
5867
+ }
5868
+ if (typeof self !== "undefined" && self.constructor.name === "DedicatedWorkerGlobalScope") {
5869
+ self.addEventListener("rtctransform", function(event) {
5870
+ var transformer = event.transformer;
5871
+ var port = transformer.options.port;
5872
+ var transform = receiveSEITransform(function(msg) {
5873
+ port.postMessage(msg);
5874
+ });
5875
+ transformer.readable.pipeThrough(transform).pipeTo(event.transformer.writable);
5876
+ });
5877
+ }
5878
+ var encodedJs = "IWZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO3ZhciBlPXtnZXROQUxVbml0czpmdW5jdGlvbih0KXt2YXIgbj1hcmd1bWVudHMubGVuZ3RoPjEmJnZvaWQgMCE9PWFyZ3VtZW50c1sxXSYmYXJndW1lbnRzWzFdO2lmKHQubGVuZ3RoLXQucG9zaXRpb248NClyZXR1cm5bXTt2YXIgcj10LnBvc2l0aW9uO3JldHVybiAxPT09dC5nZXRJbnQzMihyKXx8MD09PXQuZ2V0SW50MTYocikmJjE9PT10LmdldEludDgocisyKT9lLmdldEFubmV4Yk5hbHModCxuKTplLmdldEF2Y2NOYWxzKHQsbil9LGdldEFubmV4Yk5hbHM6ZnVuY3Rpb24odC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3ZlRVBCKGUuYm9keSksITEpO3QmJm4oe2RhdGE6dCxzZWk6e2NvZGU6dC50eXBlLGNvbnRlbnQ6dC5wYXlsb2FkfX0pfX0pKSxyLmVucXVldWUodCl9fSkpO3IucmVhZGFibGUucGlwZVRocm91Z2gobykucGlwZVRvKHQudHJhbnNmb3JtZXIud3JpdGFibGUpfSkpfSgpOwo=";
5879
+ var blob = typeof window !== "undefined" && window.Blob && new Blob([atob(encodedJs)], {
5880
+ type: "text/javascript;charset=utf-8"
5881
+ });
5882
+ function WorkerWrapper() {
5883
+ var objURL = blob && (window.URL || window.webkitURL).createObjectURL(blob);
5884
+ try {
5885
+ return objURL ? new Worker(objURL, {}) : new Worker("data:application/javascript;base64," + encodedJs, {
5886
+ type: "module"
5887
+ });
5888
+ } finally {
5889
+ objURL && (window.URL || window.webkitURL).revokeObjectURL(objURL);
5890
+ }
5891
+ }
5892
+ var AudioStallObserver = /* @__PURE__ */ function() {
5893
+ function AudioStallObserver2() {
5894
+ _classCallCheck$3(this, AudioStallObserver2);
5895
+ _defineProperty$2(this, "_audioStallTimer", null);
5896
+ _defineProperty$2(this, "_preSample", null);
5897
+ _defineProperty$2(this, "_isStallInPreReportEnd", false);
5898
+ _defineProperty$2(this, "_stallList", []);
5899
+ _defineProperty$2(this, "_audioTransceiver", null);
5900
+ }
5901
+ _createClass$3(AudioStallObserver2, [{
5902
+ key: "start",
5903
+ value: function start(transceiver) {
5904
+ this.stop();
5905
+ this._audioTransceiver = transceiver;
5906
+ if (AudioStallObserver2.interval >= 100) {
5907
+ this._startStallCountInterval();
5908
+ }
5909
+ }
5910
+ }, {
5911
+ key: "stop",
5912
+ value: function stop() {
5913
+ this._stallList = [];
5914
+ if (this._audioStallTimer) {
5915
+ clearTimeout(this._audioStallTimer);
5916
+ this._audioStallTimer = null;
5917
+ }
5918
+ }
5919
+ }, {
5920
+ key: "destroy",
5921
+ value: function destroy() {
5922
+ this.stop();
5923
+ this._audioTransceiver = null;
5924
+ }
5925
+ }, {
5926
+ key: "getAudioStallInfo",
5927
+ value: function() {
5928
+ var _getAudioStallInfo = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee() {
5929
+ var extra, reportInfo;
5930
+ return _regeneratorRuntime$1().wrap(function _callee$(_context) {
5931
+ while (1)
5932
+ switch (_context.prev = _context.next) {
5933
+ case 0:
5934
+ extra = {
5935
+ stats_count: this._stallList.filter(function(v) {
5936
+ return v.get_stats_cost;
5937
+ }).length,
5938
+ stall_list: _toConsumableArray$1(this._stallList)
5939
+ };
5940
+ _context.prev = 1;
5941
+ _context.next = 4;
5942
+ return this._audioStallCount();
5943
+ case 4:
5944
+ _context.next = 8;
5945
+ break;
5946
+ case 6:
5947
+ _context.prev = 6;
5948
+ _context.t0 = _context["catch"](1);
5949
+ case 8:
5950
+ reportInfo = computeStallInfo(this._stallList, 2, this._isStallInPreReportEnd);
5951
+ this._isStallInPreReportEnd = reportInfo.isStallInEnd;
5952
+ this.stop();
5953
+ this._startStallCountInterval();
5954
+ return _context.abrupt("return", {
5955
+ stallCount: reportInfo.stall_count,
5956
+ stallDuration: reportInfo.stall_duration,
5957
+ list: reportInfo.list,
5958
+ extra
5959
+ });
5960
+ case 13:
5961
+ case "end":
5962
+ return _context.stop();
5963
+ }
5964
+ }, _callee, this, [[1, 6]]);
5965
+ }));
5966
+ function getAudioStallInfo() {
5967
+ return _getAudioStallInfo.apply(this, arguments);
5968
+ }
5969
+ return getAudioStallInfo;
5970
+ }()
5971
+ }, {
5972
+ key: "_startStallCountInterval",
5973
+ value: function _startStallCountInterval() {
5974
+ var _this = this;
5975
+ var loop = /* @__PURE__ */ function() {
5976
+ var _ref = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee2() {
5977
+ return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
5978
+ while (1)
5979
+ switch (_context2.prev = _context2.next) {
5980
+ case 0:
5981
+ clearTimeout(_this._audioStallTimer);
5982
+ _this._audioStallTimer = null;
5983
+ _context2.next = 4;
5984
+ return _this._audioStallCount();
5985
+ case 4:
5986
+ if (!_this._audioStallTimer) {
5987
+ _this._audioStallTimer = setTimeout(loop, AudioStallObserver2.interval);
5988
+ }
5989
+ case 5:
5990
+ case "end":
5991
+ return _context2.stop();
5992
+ }
5993
+ }, _callee2);
5994
+ }));
5995
+ return function loop2() {
5996
+ return _ref.apply(this, arguments);
5997
+ };
5998
+ }();
5999
+ this._audioStallTimer = setTimeout(loop, AudioStallObserver2.interval);
6000
+ }
6001
+ }, {
6002
+ key: "_audioStallCount",
6003
+ value: function() {
6004
+ var _audioStallCount2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee3() {
6005
+ var get_stats_start, inboundRTP, reason, len, _this$_audioTransceiv, reports, _inboundRTP, _inboundRTP2, get_stats_end, end, diff, _inboundRTP3, concealedSamples, totalSamplesReceived, interval_concealed_samples, interval_samples_received, is_stall;
6006
+ return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
6007
+ while (1)
6008
+ switch (_context3.prev = _context3.next) {
6009
+ case 0:
6010
+ if (!(this._preSample && Date.now() - this._preSample.ts < AudioStallObserver2.interval * 0.5)) {
6011
+ _context3.next = 2;
6012
+ break;
6013
+ }
6014
+ return _context3.abrupt("return");
6015
+ case 2:
6016
+ get_stats_start = Date.now();
6017
+ len = 0;
6018
+ _context3.prev = 4;
6019
+ _context3.next = 7;
6020
+ return (_this$_audioTransceiv = this._audioTransceiver) === null || _this$_audioTransceiv === void 0 ? void 0 : _this$_audioTransceiv.receiver.getStats();
6021
+ case 7:
6022
+ reports = _context3.sent;
6023
+ reports === null || reports === void 0 ? void 0 : reports.forEach(function(stats) {
6024
+ if (stats.type === "inbound-rtp") {
6025
+ inboundRTP = stats;
6026
+ }
6027
+ len++;
6028
+ });
6029
+ _context3.next = 14;
6030
+ break;
6031
+ case 11:
6032
+ _context3.prev = 11;
6033
+ _context3.t0 = _context3["catch"](4);
6034
+ reason = _context3.t0.message || JSON.stringify(_context3.t0);
6035
+ case 14:
6036
+ if (this._preSample) {
6037
+ _context3.next = 17;
6038
+ break;
6039
+ }
6040
+ this._preSample = {
6041
+ ts: Date.now(),
6042
+ concealedSamples: ((_inboundRTP = inboundRTP) === null || _inboundRTP === void 0 ? void 0 : _inboundRTP.concealedSamples) || 0,
6043
+ totalSamplesReceived: ((_inboundRTP2 = inboundRTP) === null || _inboundRTP2 === void 0 ? void 0 : _inboundRTP2.totalSamplesReceived) || 0
6044
+ };
6045
+ return _context3.abrupt("return");
6046
+ case 17:
6047
+ get_stats_end = Date.now();
6048
+ end = Date.now();
6049
+ diff = end - this._preSample.ts;
6050
+ if (!inboundRTP) {
6051
+ this._stallList.push({
6052
+ diff,
6053
+ start: this._preSample.ts,
6054
+ end,
6055
+ get_stats_cost: get_stats_end - get_stats_start,
6056
+ get_stats_start,
6057
+ get_stats_end,
6058
+ reason: !len ? "no report" : reason || "no inbound-rtp"
6059
+ });
6060
+ } else {
6061
+ _inboundRTP3 = inboundRTP, concealedSamples = _inboundRTP3.concealedSamples, totalSamplesReceived = _inboundRTP3.totalSamplesReceived;
6062
+ interval_concealed_samples = concealedSamples - this._preSample.concealedSamples;
6063
+ interval_samples_received = totalSamplesReceived - this._preSample.totalSamplesReceived;
6064
+ is_stall = interval_concealed_samples >= 0 && interval_samples_received >= 0 && interval_concealed_samples >= AudioStallObserver2.ratio * interval_samples_received;
6065
+ this._stallList.push({
6066
+ concealed: interval_concealed_samples,
6067
+ received: interval_samples_received,
6068
+ diff,
6069
+ start: this._preSample.ts,
6070
+ end,
6071
+ get_stats_cost: get_stats_end - get_stats_start,
6072
+ get_stats_start,
6073
+ get_stats_end,
6074
+ is_stall
6075
+ });
6076
+ this._preSample.concealedSamples = concealedSamples;
6077
+ this._preSample.totalSamplesReceived = totalSamplesReceived;
6078
+ this._preSample.ts = end;
6079
+ }
6080
+ case 21:
6081
+ case "end":
6082
+ return _context3.stop();
6083
+ }
6084
+ }, _callee3, this, [[4, 11]]);
6085
+ }));
6086
+ function _audioStallCount() {
6087
+ return _audioStallCount2.apply(this, arguments);
6088
+ }
6089
+ return _audioStallCount;
6090
+ }()
6091
+ }]);
6092
+ return AudioStallObserver2;
6093
+ }();
6094
+ _defineProperty$2(AudioStallObserver, "interval", 100);
6095
+ _defineProperty$2(AudioStallObserver, "ratio", 0.6);
6096
+ var computeStallInfo = function computeStallInfo2(list, times, isStallInPreEnd) {
6097
+ var _list$;
6098
+ var res = {
6099
+ stall_count: 0,
6100
+ stall_duration: 0,
6101
+ isStallInEnd: false,
6102
+ list: []
6103
+ };
6104
+ var count = 0;
6105
+ var duration = 0;
6106
+ var _loop = function _loop2(_idx) {
6107
+ var info = list[_idx];
6108
+ if (info.is_stall) {
6109
+ count++;
6110
+ duration += info.diff || 0;
6111
+ }
6112
+ var lastItem = _idx === list.length - 1;
6113
+ if (!info.is_stall || lastItem) {
6114
+ var needCount = count >= times;
6115
+ var rightIdx = _idx + times - count - 1;
6116
+ if (!needCount && count > 2) {
6117
+ var tempDuration = 0;
6118
+ list.slice(_idx + 1, rightIdx + 1).forEach(function(v) {
6119
+ if (v.is_stall) {
6120
+ tempDuration += v.diff || 0;
6121
+ }
6122
+ });
6123
+ needCount = duration + tempDuration > AudioStallObserver.interval * times * AudioStallObserver.ratio;
6124
+ if (needCount) {
6125
+ _idx = rightIdx;
6126
+ duration += tempDuration;
6127
+ }
6128
+ }
6129
+ if (needCount) {
6130
+ res.stall_count++;
6131
+ res.stall_duration += duration;
6132
+ res.list.push(duration);
6133
+ }
6134
+ if (lastItem) {
6135
+ res.isStallInEnd = needCount;
6136
+ }
6137
+ count = duration = 0;
6138
+ }
6139
+ idx = _idx;
6140
+ };
6141
+ for (var idx = 0; idx < list.length; idx++) {
6142
+ _loop(idx);
6143
+ }
6144
+ if (((_list$ = list[0]) === null || _list$ === void 0 ? void 0 : _list$.is_stall) === true && isStallInPreEnd && res.stall_count > 0) {
6145
+ res.stall_count--;
6146
+ }
6147
+ return res;
6148
+ };
6149
+ function isSafari() {
6150
+ var ua = navigator.userAgent;
6151
+ return ua.match("Safari") !== null && ua.match("Chrome") === null;
6152
+ }
6153
+ function isFirefox() {
6154
+ var ua = navigator.userAgent;
6155
+ return ua.match("Firefox") !== null;
6156
+ }
6157
+ var checkVideoFrameCallback = function checkVideoFrameCallback2() {
6158
+ return typeof window !== "undefined" && typeof HTMLVideoElement.prototype.requestVideoFrameCallback === "function";
6159
+ };
6160
+ var VideoStallObserver = /* @__PURE__ */ function() {
6161
+ function VideoStallObserver2() {
6162
+ _classCallCheck$3(this, VideoStallObserver2);
6163
+ this._removeHandler = void 0;
6164
+ this._remotePlayPauseHandler = void 0;
6165
+ this._prePts = void 0;
6166
+ this._stallList = void 0;
6167
+ this._videoInWaiting100ms = false;
6168
+ this._videoInWaiting500ms = false;
6169
+ this._isPaused = void 0;
6170
+ this._pauseStart = 0;
6171
+ this._pauseDuration = 0;
6172
+ this._requestVideoFrameCallbackTimer = void 0;
6173
+ this._player = void 0;
6174
+ this._stallTimeThreshold = {
6175
+ stall500ms: isSafari() || isFirefox() ? 550 : 500,
6176
+ stall100ms: 100
6177
+ };
6178
+ this._support100msStall = checkVideoFrameCallback();
6179
+ }
6180
+ _createClass$3(VideoStallObserver2, [{
6181
+ key: "start",
6182
+ value: function start(player) {
6183
+ var _this = this;
6184
+ this._player = player;
6185
+ if (this._support100msStall) {
6186
+ if (player) {
6187
+ this._requestVideoFrameCallbackTimer = player.requestVideoFrameCallback(this._onVideoRefresh.bind(this));
6188
+ this._removeHandler = function() {
6189
+ if (_this._requestVideoFrameCallbackTimer) {
6190
+ player.cancelVideoFrameCallback(_this._requestVideoFrameCallbackTimer);
6191
+ }
6192
+ };
6193
+ }
6194
+ } else {
6195
+ var handle = function handle2() {
6196
+ return _this._onVideoTimeupdate(player);
6197
+ };
6198
+ player.addEventListener("timeupdate", handle);
6199
+ this._removeHandler = function() {
6200
+ return player.removeEventListener("timeupdate", handle);
6201
+ };
6202
+ }
6203
+ var handlePause = function handlePause2() {
6204
+ return _this._onVideoPause();
6205
+ };
6206
+ player.addEventListener("pause", handlePause);
6207
+ var handlePlay = function handlePlay2() {
6208
+ return _this._onVideoPlay();
6209
+ };
6210
+ player.addEventListener("play", handlePlay);
6211
+ this._remotePlayPauseHandler = function() {
6212
+ player.removeEventListener("pause", handlePause);
6213
+ player.removeEventListener("play", handlePlay);
6214
+ };
6215
+ }
6216
+ }, {
6217
+ key: "stop",
6218
+ value: function stop() {
6219
+ delete this._player;
6220
+ if (this._removeHandler) {
6221
+ this._removeHandler();
6222
+ }
6223
+ delete this._removeHandler;
6224
+ if (this._remotePlayPauseHandler) {
6225
+ this._remotePlayPauseHandler();
6226
+ }
6227
+ delete this._remotePlayPauseHandler;
6228
+ delete this._stallList;
6229
+ delete this._prePts;
6230
+ this._videoInWaiting100ms = false;
6231
+ this._videoInWaiting500ms = false;
6232
+ }
6233
+ }, {
6234
+ key: "destroy",
6235
+ value: function destroy() {
6236
+ this.stop();
6237
+ }
6238
+ }, {
6239
+ key: "getStallInfo",
6240
+ value: function getStallInfo(_ref) {
6241
+ var _this2 = this;
6242
+ var interval = _ref.interval, frameRateReceived = _ref.frameRateReceived, frameRateDecoded = _ref.frameRateDecoded, bitrate = _ref.bitrate;
6243
+ var stallInfo = {
6244
+ pts: 0,
6245
+ stall: {
6246
+ stallCount500ms: 0,
6247
+ stallDuration500ms: 0,
6248
+ stallRate500ms: 0,
6249
+ stallCount100ms: 0,
6250
+ stallDuration100ms: 0,
6251
+ stallRate100ms: 0
6252
+ },
6253
+ pauseDuration: this._getPauseDuration()
6254
+ };
6255
+ if (this._stallList) {
6256
+ var poorNetworkInSafari = (isSafari() || isFirefox()) && (bitrate === 0 || (frameRateDecoded || Infinity) <= 1 || (frameRateReceived || Infinity) <= 1);
6257
+ if (poorNetworkInSafari || this._stallList.length === 0) {
6258
+ stallInfo.stall.stallDuration500ms = interval;
6259
+ stallInfo.stall.stallCount500ms = this._videoInWaiting500ms ? 0 : 1;
6260
+ stallInfo.stall.stallRate500ms = 1;
6261
+ this._videoInWaiting500ms = true;
6262
+ if (this._support100msStall) {
6263
+ stallInfo.stall.stallDuration100ms = interval;
6264
+ stallInfo.stall.stallCount100ms = this._videoInWaiting100ms ? 0 : 1;
6265
+ stallInfo.stall.stallRate100ms = 1;
6266
+ this._videoInWaiting100ms = true;
6267
+ }
6268
+ } else {
6269
+ this._stallList.forEach(function(frameRecord, idx) {
6270
+ var timeUpdateInterval = frameRecord.timeUpdateInterval, playTime = frameRecord.playTime;
6271
+ var stallDuration = timeUpdateInterval;
6272
+ if (idx === 0 && (_this2._videoInWaiting100ms || _this2._videoInWaiting500ms)) {
6273
+ stallDuration = Math.round(timeUpdateInterval % interval);
6274
+ }
6275
+ if (timeUpdateInterval > _this2._stallTimeThreshold.stall500ms) {
6276
+ stallInfo.stall.stallDuration500ms += stallDuration;
6277
+ if (!_this2._videoInWaiting500ms) {
6278
+ stallInfo.stall.stallCount500ms++;
6279
+ }
6280
+ _this2._videoInWaiting500ms = true;
6281
+ } else {
6282
+ _this2._videoInWaiting500ms = false;
6283
+ }
6284
+ if (_this2._support100msStall) {
6285
+ if (timeUpdateInterval > _this2._stallTimeThreshold.stall100ms) {
6286
+ stallInfo.stall.stallDuration100ms += stallDuration;
6287
+ if (!_this2._videoInWaiting100ms) {
6288
+ stallInfo.stall.stallCount100ms++;
6289
+ }
6290
+ _this2._videoInWaiting100ms = true;
6291
+ } else {
6292
+ _this2._videoInWaiting100ms = false;
6293
+ }
6294
+ }
6295
+ stallInfo.pts = playTime;
6296
+ });
6297
+ }
6298
+ var _stallInfo$stall = stallInfo.stall, stallDuration500ms = _stallInfo$stall.stallDuration500ms, stallDuration100ms = _stallInfo$stall.stallDuration100ms;
6299
+ stallInfo.stall.stallRate500ms = Math.min(Number((stallDuration500ms / interval).toFixed(4)), 1);
6300
+ if (this._support100msStall) {
6301
+ stallInfo.stall.stallRate100ms = Math.min(Number((stallDuration100ms / interval).toFixed(4)), 1);
6302
+ } else {
6303
+ delete stallInfo.stall.stallRate100ms;
6304
+ delete stallInfo.stall.stallCount100ms;
6305
+ delete stallInfo.stall.stallDuration100ms;
6306
+ }
6307
+ this._stallList = [];
6308
+ }
6309
+ return stallInfo;
6310
+ }
6311
+ }, {
6312
+ key: "_getPauseDuration",
6313
+ value: function _getPauseDuration() {
6314
+ var pause_duration = this._pauseDuration;
6315
+ this._pauseDuration = 0;
6316
+ if (this._isPaused) {
6317
+ var now = Date.now();
6318
+ var diff = now - (this._pauseStart || 0);
6319
+ if (diff > 500) {
6320
+ this._pauseStart = now;
6321
+ pause_duration += diff;
6322
+ }
6323
+ }
6324
+ return pause_duration;
6325
+ }
6326
+ }, {
6327
+ key: "_onVideoPause",
6328
+ value: function _onVideoPause() {
6329
+ this._isPaused = true;
6330
+ this._pauseStart = Date.now();
6331
+ }
6332
+ }, {
6333
+ key: "_onVideoPlay",
6334
+ value: function _onVideoPlay() {
6335
+ this._isPaused = false;
6336
+ var diff = Date.now() - this._pauseStart;
6337
+ if (diff > 500) {
6338
+ this._pauseDuration += diff;
6339
+ }
6340
+ }
6341
+ }, {
6342
+ key: "_onVideoTimeupdate",
6343
+ value: function _onVideoTimeupdate(video) {
6344
+ if (!video || video.currentTime === 0) {
6345
+ return;
6346
+ }
6347
+ if (this._prePts === void 0) {
6348
+ this._prePts = video.currentTime;
6349
+ return;
6350
+ }
6351
+ if (!this._stallList) {
6352
+ this._stallList = [];
6353
+ }
6354
+ if (video.currentTime > this._prePts) {
6355
+ var delta = video.currentTime - this._prePts;
6356
+ this._stallList.push({
6357
+ playTime: video.currentTime,
6358
+ timeUpdateInterval: Math.round(delta * 1e3)
6359
+ });
6360
+ }
6361
+ this._prePts = video.currentTime;
6362
+ }
6363
+ }, {
6364
+ key: "_onVideoRefresh",
6365
+ value: function _onVideoRefresh(_, data) {
6366
+ if (!this._stallList) {
6367
+ this._stallList = [];
6368
+ }
6369
+ if (this._prePts) {
6370
+ var delta = data.presentationTime - this._prePts;
6371
+ this._stallList.push({
6372
+ playTime: data.presentationTime,
6373
+ timeUpdateInterval: Math.round(delta)
6374
+ });
6375
+ }
6376
+ this._prePts = data.presentationTime;
6377
+ if (this._player) {
6378
+ this._player.requestVideoFrameCallback(this._onVideoRefresh.bind(this));
6379
+ }
6380
+ }
6381
+ }]);
6382
+ return VideoStallObserver2;
6383
+ }();
6384
+ function getRecvAudioStats(_x) {
6385
+ return _getRecvAudioStats.apply(this, arguments);
6386
+ }
6387
+ function _getRecvAudioStats() {
6388
+ _getRecvAudioStats = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee(getStats2) {
6389
+ var currentStats, result;
6390
+ return _regeneratorRuntime$1().wrap(function _callee$(_context) {
6391
+ while (1)
6392
+ switch (_context.prev = _context.next) {
6393
+ case 0:
6394
+ currentStats = {};
6395
+ _context.next = 3;
6396
+ return getStats2;
6397
+ case 3:
6398
+ result = _context.sent;
6399
+ currentStats.timestamp = Date.now();
6400
+ result === null || result === void 0 ? void 0 : result.forEach(function(stat) {
6401
+ if (stat.type === "inbound-rtp") {
6402
+ currentStats.packetsLost = stat.packetsLost;
6403
+ currentStats.packetsReceived = stat.packetsReceived;
6404
+ currentStats.bytesReceived = stat.bytesReceived;
6405
+ if (stat.jitterBufferDelay !== void 0) {
6406
+ currentStats.jitterBufferDelay = stat.jitterBufferDelay;
6407
+ currentStats.jitterBufferEmittedCount = stat.jitterBufferEmittedCount;
6408
+ }
6409
+ if (stat.totalSamplesReceived !== void 0) {
6410
+ currentStats.totalSamplesReceived = stat.totalSamplesReceived;
6411
+ currentStats.concealedSamples = stat.concealedSamples;
6412
+ currentStats.silentConcealedSamples = stat.silentConcealedSamples;
6413
+ currentStats.concealmentEvents = stat.concealmentEvents;
6414
+ }
6415
+ if (stat.fecPacketsReceived !== void 0) {
6416
+ currentStats.fecPacketsReceived = stat.fecPacketsReceived;
6417
+ }
6418
+ } else if (stat.type === "codec") {
6419
+ currentStats.recordSampleRate = stat.clockRate;
6420
+ if (stat.channels) {
6421
+ currentStats.numChannels = stat.channels;
6422
+ }
6423
+ currentStats.codecType = stat.mimeType;
6424
+ } else if (stat.type === "candidate-pair") {
6425
+ currentStats.rtt = stat.currentRoundTripTime * 1e3;
6426
+ currentStats.total_rtt = stat.totalRoundTripTime * 1e3;
6427
+ } else if (stat.type === "track" && stat.audioLevel !== void 0)
6428
+ ;
6429
+ else if (stat.type === "ssrc")
6430
+ ;
6431
+ });
6432
+ return _context.abrupt("return", currentStats);
6433
+ case 7:
6434
+ case "end":
6435
+ return _context.stop();
6436
+ }
6437
+ }, _callee);
6438
+ }));
6439
+ return _getRecvAudioStats.apply(this, arguments);
6440
+ }
6441
+ function diffRecvAudioStats(oldStats, newStats) {
6442
+ var statsInterval = diffNumber(oldStats, newStats, "timestamp");
6443
+ var packetsLostDiff = diffNumber(oldStats, newStats, "packetsLost");
6444
+ var jitterBufferDelay = Math.round(diffNumber(oldStats, newStats, "jitterBufferDelay") / diffNumber(oldStats, newStats, "jitterBufferEmittedCount") * 1e3);
6445
+ return {
6446
+ audioLossRate: +(packetsLostDiff / (diffNumber(oldStats, newStats, "packetsReceived") + packetsLostDiff)).toFixed(2),
6447
+ receivedKBitrate: +(diffNumber(oldStats, newStats, "bytesReceived") * 8 / statsInterval).toFixed(2),
6448
+ statsInterval,
6449
+ rtt: newStats.rtt || 0,
6450
+ jitterBufferDelay,
6451
+ numChannels: newStats.numChannels || 1,
6452
+ receivedSampleRate: diffNumber(oldStats, newStats, "totalSamplesReceived") / statsInterval,
6453
+ concealedSamples: Math.round(diffNumber(oldStats, newStats, "concealedSamples")),
6454
+ concealmentEvent: Math.round(diffNumber(oldStats, newStats, "concealmentEvents")),
6455
+ e2eDelay: Math.round(newStats.rtt + jitterBufferDelay)
6456
+ };
6457
+ }
6458
+ function getRecvVideoStats(_x2) {
6459
+ return _getRecvVideoStats.apply(this, arguments);
6460
+ }
6461
+ function _getRecvVideoStats() {
6462
+ _getRecvVideoStats = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee2(getStats2) {
6463
+ var currentStats, result;
6464
+ return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
6465
+ while (1)
6466
+ switch (_context2.prev = _context2.next) {
6467
+ case 0:
6468
+ currentStats = {};
6469
+ _context2.next = 3;
6470
+ return getStats2;
6471
+ case 3:
6472
+ result = _context2.sent;
6473
+ currentStats.timestamp = Date.now();
6474
+ result === null || result === void 0 ? void 0 : result.forEach(function(stat) {
6475
+ if (stat.type === "inbound-rtp") {
6476
+ currentStats.packetsLost = stat.packetsLost;
6477
+ currentStats.packetsReceived = stat.packetsReceived;
6478
+ currentStats.bytesReceived = stat.bytesReceived;
6479
+ currentStats.framesDecoded = stat.framesDecoded;
6480
+ currentStats.totalDecodeTime = stat.totalDecodeTime;
6481
+ currentStats.framesReceived = stat.framesReceived;
6482
+ currentStats.keyFramesDecoded = stat.keyFramesDecoded;
6483
+ currentStats.framesDropped = stat.framesDropped;
6484
+ currentStats.firCount = stat.firCount;
6485
+ currentStats.nackCount = stat.nackCount;
6486
+ currentStats.pliCount = stat.pliCount;
6487
+ if (stat.jitterBufferDelay !== void 0) {
6488
+ currentStats.jitterBufferEmittedCount = stat.jitterBufferEmittedCount;
6489
+ currentStats.jitterBufferDelay = stat.jitterBufferDelay;
6490
+ }
6491
+ if (stat.frameWidth !== void 0) {
6492
+ currentStats.width = stat.frameWidth;
6493
+ currentStats.height = stat.frameHeight;
6494
+ }
6495
+ } else if (stat.type === "track" && stat.frameWidth !== void 0) {
6496
+ currentStats.width = stat.frameWidth;
6497
+ currentStats.height = stat.frameHeight;
6498
+ if (stat.framesReceived !== void 0) {
6499
+ currentStats.framesReceived = stat.framesReceived;
6500
+ }
6501
+ } else if (stat.type === "codec") {
6502
+ currentStats.codecType = stat.mimeType;
6503
+ } else if (stat.type === "candidate-pair") {
6504
+ currentStats.rtt = stat.currentRoundTripTime * 1e3;
6505
+ currentStats.totalRtt = stat.totalRoundTripTime * 1e3;
6506
+ }
6507
+ });
6508
+ return _context2.abrupt("return", currentStats);
6509
+ case 7:
6510
+ case "end":
6511
+ return _context2.stop();
6512
+ }
6513
+ }, _callee2);
6514
+ }));
6515
+ return _getRecvVideoStats.apply(this, arguments);
6516
+ }
6517
+ function diffRecvVideoStats(oldStats, newStats) {
6518
+ var statsInterval = diffNumber(oldStats, newStats, "timestamp");
6519
+ var packetsLostDiff = diffNumber(oldStats, newStats, "packetsLost");
6520
+ var nackCount = diffNumber(oldStats, newStats, "nackCount");
6521
+ var packetsReceived = diffNumber(oldStats, newStats, "packetsReceived");
6522
+ var jitterBufferDelay = Math.round(diffNumber(oldStats, newStats, "jitterBufferDelay") / diffNumber(oldStats, newStats, "jitterBufferEmittedCount") * 1e3);
6523
+ return {
6524
+ statsInterval,
6525
+ width: newStats.width || 0,
6526
+ height: newStats.height || 0,
6527
+ videoLossRate: +(packetsLostDiff / (diffNumber(oldStats, newStats, "packetsReceived") + packetsLostDiff)),
6528
+ receivedKBitrate: +(diffNumber(oldStats, newStats, "bytesReceived") * 8 / statsInterval).toFixed(2),
6529
+ decoderOutputFrameRate: Math.round(diffNumber(oldStats, newStats, "framesDecoded") * 1e3 / statsInterval),
6530
+ receivedFrameRate: Math.round(diffNumber(oldStats, newStats, "framesReceived") * 1e3 / statsInterval),
6531
+ rtt: newStats.rtt || 0,
6532
+ totalRtt: Math.round(newStats.totalRtt || 0),
6533
+ jitterBufferDelay,
6534
+ codecType: newStats.codecType,
6535
+ packetsReceived,
6536
+ avgDecodeDelay: Math.round(diffNumber(oldStats, newStats, "totalDecodeTime") * 1e3 / diffNumber(oldStats, newStats, "framesDecoded")),
6537
+ keyFramesDecoded: diffNumber(oldStats, newStats, "keyFramesDecoded"),
6538
+ framesDropped: diffNumber(oldStats, newStats, "framesDropped"),
6539
+ firCount: diffNumber(oldStats, newStats, "firCount"),
6540
+ nackCount,
6541
+ pliCount: diffNumber(oldStats, newStats, "pliCount"),
6542
+ e2eDelay: Math.round(newStats.rtt + jitterBufferDelay),
6543
+ retransmittedRate: +(nackCount / (packetsReceived + packetsLostDiff)).toFixed(2)
6544
+ };
6545
+ }
6546
+ function diffNumber(oldValue, newValue, key) {
6547
+ var oldV = Number.isNaN(oldValue[key]) ? 0 : +oldValue[key];
6548
+ var newV = Number.isNaN(newValue[key]) ? 0 : +newValue[key];
6549
+ return Math.max(0, newV - oldV);
6550
+ }
6551
+ var QoELevel = {
6552
+ INVALID: 0,
6553
+ GOOD: 1,
6554
+ MEDIUM: 2,
6555
+ POOR: 3
6556
+ };
6557
+ var QosLevel = {
6558
+ UNKOWN: 0,
6559
+ EXCELLENT: 1,
6560
+ GOOD: 2,
6561
+ POOR: 3,
6562
+ BAD: 4,
6563
+ VBAD: 5
6564
+ };
6565
+ var Quality = {
6566
+ UNKNOWN: 0,
6567
+ EXCELLENT: 1,
6568
+ GOOD: 2,
6569
+ POOR: 3,
6570
+ BAD: 4,
6571
+ VBAD: 5,
6572
+ DOWN: 6
6573
+ };
6574
+ var NetworkQuality = /* @__PURE__ */ function() {
6575
+ function NetworkQuality2(peer, networkQualityParams) {
6576
+ _classCallCheck$3(this, NetworkQuality2);
6577
+ _defineProperty$2(this, "_preDownlinkStats", []);
6578
+ this._peer = peer;
6579
+ this._networkQualityParams = networkQualityParams;
6580
+ }
6581
+ _createClass$3(NetworkQuality2, [{
6582
+ key: "getDownlinkQuality",
6583
+ value: function getDownlinkQuality(audioStats, videoStats) {
6584
+ if (audioStats.receivedKBitrate === 0 && videoStats.receivedKBitrate === 0) {
6585
+ return;
6586
+ }
6587
+ if (this._peer.connectionState !== "connected" && this._peer.connectionState !== "connecting" || !navigator.onLine) {
6588
+ return [Quality.DOWN, {}];
6589
+ }
6590
+ var audioQos = this._getQosLevel(audioStats.rtt, audioStats.audioLossRate, videoStats.retransmittedRate);
6591
+ var audioQoe = this._getDownlinkQoE("audio", audioStats.stallDuration / audioStats.statsInterval, audioStats.e2eDelay);
6592
+ var audioLevel = this._getNetworkQuality(audioQos, audioQoe);
6593
+ var videoQos = this._getQosLevel(videoStats.rtt, videoStats.videoLossRate, videoStats.retransmittedRate);
6594
+ var videoQoe = this._getDownlinkQoE("video", videoStats.stallDuration / videoStats.statsInterval, videoStats.e2eDelay);
6595
+ var videoLevel = this._getNetworkQuality(videoQos, videoQoe);
6596
+ var quality = audioLevel && videoLevel ? Math.ceil((audioLevel + videoLevel) / 2) : audioLevel || videoLevel;
6597
+ var qualityQos = audioQos && videoQos ? Math.ceil((audioQos + videoQos) / 2) : audioQos || videoQos;
6598
+ if (quality) {
6599
+ this._preDownlinkStats = [].concat(_toConsumableArray$1(this._preDownlinkStats), [quality]).slice(-2);
6600
+ return [Math.floor(this._preDownlinkStats.reduce(function(res, cur) {
6601
+ return cur + res;
6602
+ }, 0) / this._preDownlinkStats.length), {
6603
+ qualityQos,
6604
+ audioLevel,
6605
+ videoLevel,
6606
+ audioQos,
6607
+ audioQoe,
6608
+ videoQos,
6609
+ videoQoe
6610
+ }];
6611
+ }
6612
+ }
6613
+ }, {
6614
+ key: "destroy",
6615
+ value: function destroy() {
6616
+ this._preDownlinkStats = [];
6617
+ }
6618
+ }, {
6619
+ key: "_getQosLevel",
6620
+ value: function _getQosLevel(rtt, loss, retransmittedRate) {
6621
+ var quality;
6622
+ var qosQualityParams = this._networkQualityParams.networkQos;
6623
+ if ((!rtt || rtt <= qosQualityParams[QosLevel.EXCELLENT].maxRtt) && loss <= qosQualityParams[QosLevel.EXCELLENT].maxLoss) {
6624
+ quality = QosLevel.EXCELLENT;
6625
+ } else if ((!rtt || rtt <= qosQualityParams[QosLevel.GOOD].maxRtt) && loss <= qosQualityParams[QosLevel.GOOD].maxLoss) {
6626
+ quality = QosLevel.GOOD;
6627
+ } else if ((!rtt || rtt <= qosQualityParams[QosLevel.POOR].maxRtt) && loss <= qosQualityParams[QosLevel.POOR].maxLoss) {
6628
+ quality = QosLevel.POOR;
6629
+ } else if ((!rtt || rtt <= qosQualityParams[QosLevel.BAD].maxRtt) && loss <= qosQualityParams[QosLevel.BAD].maxLoss) {
6630
+ quality = QosLevel.BAD;
6631
+ } else {
6632
+ quality = QosLevel.VBAD;
6633
+ }
6634
+ if (retransmittedRate > qosQualityParams[QosLevel.BAD].minRetransmittedRate) {
6635
+ quality = Math.max(quality, QosLevel.BAD);
6636
+ } else if (retransmittedRate > qosQualityParams[QosLevel.POOR].minRetransmittedRate) {
6637
+ quality = Math.max(quality, QosLevel.POOR);
6638
+ } else if (retransmittedRate > qosQualityParams[QosLevel.GOOD].minRetransmittedRate) {
6639
+ quality = Math.max(quality, QosLevel.GOOD);
6640
+ }
6641
+ return quality;
6642
+ }
6643
+ }, {
6644
+ key: "_getDownlinkQoE",
6645
+ value: function _getDownlinkQoE(streamType, stallRadio, delay) {
6646
+ var qoeQualityParams = this._networkQualityParams.networkQoe;
6647
+ var conf = {
6648
+ audio: {
6649
+ delay: qoeQualityParams.audioDelay,
6650
+ stallRadio: qoeQualityParams.audioStallRadio
6651
+ },
6652
+ video: {
6653
+ delay: qoeQualityParams.videoDelay,
6654
+ stallRadio: qoeQualityParams.videoStallRadio
6655
+ }
6656
+ }[streamType];
6657
+ if (stallRadio > conf.stallRadio || delay > conf.delay || stallRadio > conf.stallRadio / 2 && delay > conf.delay / 2) {
6658
+ return QoELevel.POOR;
6659
+ } else if (stallRadio > conf.stallRadio / 2 || delay > conf.delay / 2) {
6660
+ return QoELevel.MEDIUM;
6661
+ } else {
6662
+ return QoELevel.MEDIUM;
6663
+ }
6664
+ }
6665
+ }, {
6666
+ key: "_getNetworkQuality",
6667
+ value: function _getNetworkQuality(QoS, QoE) {
6668
+ if (QoE === QoELevel.GOOD) {
6669
+ return Math.max(QoS - 2, 1);
6670
+ } else if (QoE === QoELevel.MEDIUM) {
6671
+ return QoS;
6672
+ } else {
6673
+ return Math.min(QoS + 1, 5);
6674
+ }
6675
+ }
6676
+ }]);
6677
+ return NetworkQuality2;
6678
+ }();
6679
+ var logger = new Logger("rts");
6680
+ var Rts = /* @__PURE__ */ function(_EventEmitter) {
6681
+ _inherits$1(Rts2, _EventEmitter);
6682
+ var _super = _createSuper$1(Rts2);
6683
+ function Rts2(opts) {
6684
+ var _this;
6685
+ _classCallCheck$3(this, Rts2);
6686
+ _this = _super.call(this);
6687
+ _defineProperty$2(_assertThisInitialized$1(_this), "_url", "");
6688
+ _defineProperty$2(_assertThisInitialized$1(_this), "_pc", null);
6689
+ _defineProperty$2(_assertThisInitialized$1(_this), "_audioTransceicer", null);
6690
+ _defineProperty$2(_assertThisInitialized$1(_this), "_videoTransceicer", null);
6691
+ _defineProperty$2(_assertThisInitialized$1(_this), "_mediaStream", null);
6692
+ _defineProperty$2(_assertThisInitialized$1(_this), "_lastMediaStream", null);
6693
+ _defineProperty$2(_assertThisInitialized$1(_this), "_media", null);
6694
+ _defineProperty$2(_assertThisInitialized$1(_this), "_opts", null);
6695
+ _defineProperty$2(_assertThisInitialized$1(_this), "_loader", null);
6696
+ _defineProperty$2(_assertThisInitialized$1(_this), "_networkEvaluate", null);
6697
+ _defineProperty$2(_assertThisInitialized$1(_this), "_retry", 0);
6698
+ _defineProperty$2(_assertThisInitialized$1(_this), "_waitingTimer", 0);
6699
+ _defineProperty$2(_assertThisInitialized$1(_this), "_rctConnectStartTs", 0);
6700
+ _defineProperty$2(_assertThisInitialized$1(_this), "_isReplacing", false);
6701
+ _defineProperty$2(_assertThisInitialized$1(_this), "_checkStatsErrorTimer", null);
6702
+ _defineProperty$2(_assertThisInitialized$1(_this), "_audioStallObserver", null);
6703
+ _defineProperty$2(_assertThisInitialized$1(_this), "_videoStallObserver", null);
6704
+ _defineProperty$2(_assertThisInitialized$1(_this), "_networkQuality", null);
6705
+ _defineProperty$2(_assertThisInitialized$1(_this), "_preAudioStats", null);
6706
+ _defineProperty$2(_assertThisInitialized$1(_this), "_preVideoStats", null);
6707
+ _defineProperty$2(_assertThisInitialized$1(_this), "_rtcReportTimer", 0);
6708
+ _defineProperty$2(_assertThisInitialized$1(_this), "_networkQualityResult", []);
6709
+ _defineProperty$2(_assertThisInitialized$1(_this), "_checkStatsError", /* @__PURE__ */ _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee2() {
6710
+ return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
6711
+ while (1)
6712
+ switch (_context2.prev = _context2.next) {
6713
+ case 0:
6714
+ _this._checkStatsErrorTimer = setTimeout(/* @__PURE__ */ _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee() {
6715
+ var stats, _stats$video, framesDecoded, bytesReceived;
6716
+ return _regeneratorRuntime$1().wrap(function _callee$(_context) {
6717
+ while (1)
6718
+ switch (_context.prev = _context.next) {
6719
+ case 0:
6720
+ _context.next = 2;
6721
+ return _this.getStatsSnapshoot();
6722
+ case 2:
6723
+ stats = _context.sent;
6724
+ if (stats.video) {
6725
+ _stats$video = stats.video, framesDecoded = _stats$video.framesDecoded, bytesReceived = _stats$video.bytesReceived;
6726
+ if (!bytesReceived) {
6727
+ _this._emitError(StreamingError.create(ERR.MEDIA, ERR.SUB_TYPES.MEDIA_ERR_DECODE, {
6728
+ message: "rts receive empty"
6729
+ }));
6730
+ } else if (!framesDecoded) {
6731
+ _this._emitError(StreamingError.create(ERR.MEDIA, ERR.SUB_TYPES.MEDIA_ERR_DECODE, {
6732
+ message: "rts decode error"
6733
+ }));
6734
+ }
6735
+ }
6736
+ case 4:
6737
+ case "end":
6738
+ return _context.stop();
6739
+ }
6740
+ }, _callee);
6741
+ })), _this._opts.checkStatsErrorDelay);
6742
+ case 1:
6743
+ case "end":
6744
+ return _context2.stop();
6745
+ }
6746
+ }, _callee2);
6747
+ })));
6748
+ _defineProperty$2(_assertThisInitialized$1(_this), "_onTrack", function(e) {
6749
+ logger.log("addTrack: ", e.track, e.streams);
6750
+ _this["_".concat(e.track.kind)] = e.track;
6751
+ });
6752
+ _defineProperty$2(_assertThisInitialized$1(_this), "_mockWaitingByTimeupdate", function() {
6753
+ var _this$_pc, _this$_pc2;
6754
+ if (!(((_this$_pc = _this._pc) === null || _this$_pc === void 0 ? void 0 : _this$_pc.connectionState) === "connected" || ((_this$_pc2 = _this._pc) === null || _this$_pc2 === void 0 ? void 0 : _this$_pc2.iceConnectionState) === "connected"))
6755
+ return;
6756
+ clearTimeout(_this._waitingTimer);
6757
+ _this._waitingTimer = setTimeout(function() {
6758
+ var _this$_media;
6759
+ if ((_this$_media = _this._media) !== null && _this$_media !== void 0 && _this$_media.paused)
6760
+ return;
6761
+ _this.emit("waiting");
6762
+ }, _this._opts.stallInterval);
6763
+ });
6764
+ _defineProperty$2(_assertThisInitialized$1(_this), "_onLoadedData", function() {
6765
+ logger.log("loadeddata emit");
6766
+ _this._startRtcReport();
6767
+ _this.getStatsSnapshoot().then(function(snap) {
6768
+ _this.emit(EVENT.METADATA_PARSED, {
6769
+ type: "video",
6770
+ elapsed: Date.now() - _this._rctConnectStartTs,
6771
+ meta: snap.video
6772
+ });
6773
+ _this.emit(EVENT.METADATA_PARSED, {
6774
+ type: "audio",
6775
+ elapsed: Date.now() - _this._rctConnectStartTs,
6776
+ meta: snap.audio
6777
+ });
6778
+ });
6779
+ });
6780
+ _defineProperty$2(_assertThisInitialized$1(_this), "_setDelay", function(delayHint) {
6781
+ var currentDelay = _this._getDelay();
6782
+ delayHint = typeof delayHint === "number" && delayHint > 0 ? delayHint : null;
6783
+ if (currentDelay === delayHint)
6784
+ return;
6785
+ try {
6786
+ var videoReceiver = _this._videoTransceicer.receiver;
6787
+ var audioReceiver = _this._audioTransceicer.receiver;
6788
+ var key = [
6789
+ "playoutDelayHint",
6790
+ "jitterBufferDelayHint",
6791
+ "jitterBufferTarget"
6792
+ ].find(function(key2) {
6793
+ return key2 in videoReceiver && key2 in audioReceiver;
6794
+ });
6795
+ if (key) {
6796
+ audioReceiver[key] = delayHint;
6797
+ logger.log("set audioReceiver.".concat(key, " = ").concat(delayHint));
6798
+ }
6799
+ } catch (error) {
6800
+ logger.error("set delay error", error);
6801
+ }
6802
+ });
6803
+ _defineProperty$2(_assertThisInitialized$1(_this), "_getDelay", function() {
6804
+ try {
6805
+ var key = ["playoutDelayHint", "jitterBufferDelayHint", "jitterBufferTarget"].find(function(key2) {
6806
+ return key2 in _this._videoTransceicer.receiver && key2 in _this._audioTransceicer.receiver;
6807
+ });
6808
+ return _this._audioTransceicer.receiver[key];
6809
+ } catch (error) {
6810
+ logger.error("get delay error");
6811
+ }
6812
+ });
6813
+ _defineProperty$2(_assertThisInitialized$1(_this), "_onLoaderRetry", function(error, retryTime) {
6814
+ _this.emit(EVENT.LOAD_RETRY, {
6815
+ error: StreamingError.network(error),
6816
+ retryTime
6817
+ });
6818
+ });
6819
+ _this._opts = getOption(opts);
6820
+ _this._media = _this._opts.media;
6821
+ _this._loader = new NetLoader(_objectSpread2$2(_objectSpread2$2({}, opts.fetchOptions), {}, {
6822
+ responseType: "json",
6823
+ method: "POST",
6824
+ retry: _this._opts.retryCount,
6825
+ retryDelay: _this._opts.retryDelay,
6826
+ timeout: _this._opts.loadTimeout,
6827
+ onRetryError: _this._onLoaderRetry,
6828
+ logger
6829
+ }));
6830
+ _this._retry = _this._opts.retryCount;
6831
+ _this._bindMediaEvent();
6832
+ if (_this._opts.mediaStream && _this._opts.seamlesslyReload) {
6833
+ _this._lastMediaStream = _this._opts.mediaStream;
6834
+ }
6835
+ return _this;
6836
+ }
6837
+ _createClass$3(Rts2, [{
6838
+ key: "pc",
6839
+ get: function get() {
6840
+ return this._pc;
6841
+ }
6842
+ }, {
6843
+ key: "audioTrack",
6844
+ get: function get() {
6845
+ return this._audio;
6846
+ }
6847
+ }, {
6848
+ key: "videoTack",
6849
+ get: function get() {
6850
+ return this._video;
6851
+ }
6852
+ }, {
6853
+ key: "loader",
6854
+ get: function get() {
6855
+ return this._loader;
6856
+ }
6857
+ }, {
6858
+ key: "networkStats",
5233
6859
  get: function get() {
5234
6860
  var _this$_networkEvaluat;
5235
6861
  return (_this$_networkEvaluat = this._networkEvaluate) === null || _this$_networkEvaluat === void 0 ? void 0 : _this$_networkEvaluat.getStats();
@@ -5249,12 +6875,12 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5249
6875
  }, {
5250
6876
  key: "load",
5251
6877
  value: function() {
5252
- var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee(url) {
6878
+ var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee3(url) {
5253
6879
  var _this2 = this;
5254
- var lastPc;
5255
- return _regeneratorRuntime$1().wrap(function _callee$(_context) {
6880
+ var lastPc, encodedTransformSupported;
6881
+ return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
5256
6882
  while (1)
5257
- switch (_context.prev = _context.next) {
6883
+ switch (_context3.prev = _context3.next) {
5258
6884
  case 0:
5259
6885
  this._disconnect();
5260
6886
  this._url = url;
@@ -5263,25 +6889,28 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5263
6889
  if (lastPc) {
5264
6890
  lastPc.close();
5265
6891
  }
5266
- _context.prev = 5;
5267
- this._pc = new RTCPeerConnection();
6892
+ encodedTransformSupported = isLegacyEncodedTransformSupported();
6893
+ _context3.prev = 6;
6894
+ this._pc = new RTCPeerConnection({
6895
+ encodedInsertableStreams: encodedTransformSupported && this._opts.enableSei ? true : void 0
6896
+ });
5268
6897
  this._bindRTCEvents();
5269
- _context.next = 10;
6898
+ _context3.next = 11;
5270
6899
  return this._connect(url);
5271
- case 10:
5272
- _context.next = 15;
6900
+ case 11:
6901
+ _context3.next = 16;
5273
6902
  break;
5274
- case 12:
5275
- _context.prev = 12;
5276
- _context.t0 = _context["catch"](5);
6903
+ case 13:
6904
+ _context3.prev = 13;
6905
+ _context3.t0 = _context3["catch"](6);
5277
6906
  setTimeout(function() {
5278
- return _this2._emitError(StreamingError.create(ERR.OTHER, null, _context.t0));
6907
+ return _this2._emitError(StreamingError.create(ERR.OTHER, null, _context3.t0));
5279
6908
  });
5280
- case 15:
6909
+ case 16:
5281
6910
  case "end":
5282
- return _context.stop();
6911
+ return _context3.stop();
5283
6912
  }
5284
- }, _callee, this, [[5, 12]]);
6913
+ }, _callee3, this, [[6, 13]]);
5285
6914
  }));
5286
6915
  function load(_x) {
5287
6916
  return _load.apply(this, arguments);
@@ -5307,6 +6936,7 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5307
6936
  });
5308
6937
  if (pc.connectionState === "disconnected" || pc.connectionState === "failed") {
5309
6938
  _this3.emit("waiting");
6939
+ _this3._stopRtcReport();
5310
6940
  }
5311
6941
  if (pc.connectionState === "failed") {
5312
6942
  if (_this3._retry === 0) {
@@ -5323,6 +6953,7 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5323
6953
  responseUrl: _this3._url,
5324
6954
  elapsed: Date.now() - _this3._rctConnectStartTs
5325
6955
  });
6956
+ _this3._checkStatsError();
5326
6957
  }
5327
6958
  });
5328
6959
  }
@@ -5360,6 +6991,54 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5360
6991
  }
5361
6992
  }
5362
6993
  }
6994
+ }, {
6995
+ key: "initVideoEncodedTransform",
6996
+ value: function initVideoEncodedTransform() {
6997
+ var _this5 = this;
6998
+ if (!this._videoTransceicer || !this._videoTransceicer.receiver) {
6999
+ console.log("no receiver found when trying to bind encodedTransform");
7000
+ return;
7001
+ }
7002
+ var receiver = this._videoTransceicer.receiver;
7003
+ if (isLegacyEncodedTransformSupported()) {
7004
+ var _receiver$createEncod = receiver.createEncodedStreams(), readable = _receiver$createEncod.readable, writable = _receiver$createEncod.writable;
7005
+ readable.pipeThrough(receiveSEITransform(function(sei) {
7006
+ _this5.emit(EVENT.SEI, sei);
7007
+ })).pipeTo(writable);
7008
+ } else if (isEncodedTransformSupported()) {
7009
+ var worker = new WorkerWrapper();
7010
+ var channel = new MessageChannel();
7011
+ this._videoTransceicer.receiver.transform = new RTCRtpScriptTransform(worker, {
7012
+ port: channel.port2
7013
+ }, [channel.port2]);
7014
+ channel.port1.onmessage = function(e) {
7015
+ _this5.emit(EVENT.SEI, e.data);
7016
+ };
7017
+ }
7018
+ }
7019
+ }, {
7020
+ key: "initAudioEncodedTransform",
7021
+ value: function initAudioEncodedTransform() {
7022
+ if (!this._audioTransceicer || !this._audioTransceicer.receiver) {
7023
+ logger.warn("no receiver found when trying to bind encodedTransform");
7024
+ return;
7025
+ }
7026
+ if (!isLegacyEncodedTransformSupported()) {
7027
+ logger.warn("legacy EncodedTransform is not supported");
7028
+ return;
7029
+ }
7030
+ var receiver = this._audioTransceicer.receiver;
7031
+ var _receiver$createEncod2 = receiver.createEncodedStreams(), readable = _receiver$createEncod2.readable, writable = _receiver$createEncod2.writable;
7032
+ readable.pipeThrough(new TransformStream({
7033
+ transform: function transform(chunk, controller) {
7034
+ if (chunk.data.byteLength <= 1e3) {
7035
+ controller.enqueue(chunk);
7036
+ } else {
7037
+ logger.log("too large audio frame", chunk.data.byteLength);
7038
+ }
7039
+ }
7040
+ })).pipeTo(writable);
7041
+ }
5363
7042
  }, {
5364
7043
  key: "_bindMediaEvent",
5365
7044
  value: function _bindMediaEvent() {
@@ -5369,15 +7048,15 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5369
7048
  }, {
5370
7049
  key: "_connect",
5371
7050
  value: function() {
5372
- var _connect2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee2() {
5373
- var pc, offer, delayHint, parsed, finnalUrl, _this$_opts, _answer$remoteSdp, _this$_opts2, _answer$remoteSdp2, _parsed$media, parseSession, sessionId, reqStart, res, answer, err, _parsed;
5374
- return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
7051
+ var _connect2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee4() {
7052
+ var pc, offer, parsed, finnalUrl, _this$_opts, _answer$remoteSdp, _this$_opts2, _answer$remoteSdp2, _parsed$media, parseSession, sessionId, reqStart, res, answer, err, _parsed;
7053
+ return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
5375
7054
  while (1)
5376
- switch (_context2.prev = _context2.next) {
7055
+ switch (_context4.prev = _context4.next) {
5377
7056
  case 0:
5378
7057
  pc = this._pc;
5379
7058
  if (!pc.addTransceiver) {
5380
- _context2.next = 11;
7059
+ _context4.next = 11;
5381
7060
  break;
5382
7061
  }
5383
7062
  this._audioTransceicer = pc.addTransceiver("audio", {
@@ -5386,28 +7065,26 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5386
7065
  this._videoTransceicer = pc.addTransceiver("video", {
5387
7066
  direction: "recvonly"
5388
7067
  });
5389
- delayHint = this._opts.delayHint;
5390
- if (delayHint) {
5391
- this._audioTransceicer.receiver.playoutDelayHint = delayHint;
5392
- this._audioTransceicer.receiver.jitterBufferDelayHint = delayHint;
5393
- this._videoTransceicer.receiver.playoutDelayHint = delayHint;
5394
- this._videoTransceicer.receiver.jitterBufferDelayHint = delayHint;
7068
+ !this._opts.enableAdaptiveJitterBuffer && this._setDelay(this._opts.delayHint);
7069
+ if (this._opts.enableSei) {
7070
+ this.initVideoEncodedTransform();
7071
+ this.initAudioEncodedTransform();
5395
7072
  }
5396
- _context2.next = 8;
7073
+ _context4.next = 8;
5397
7074
  return pc.createOffer();
5398
7075
  case 8:
5399
- offer = _context2.sent;
5400
- _context2.next = 14;
7076
+ offer = _context4.sent;
7077
+ _context4.next = 14;
5401
7078
  break;
5402
7079
  case 11:
5403
- _context2.next = 13;
7080
+ _context4.next = 13;
5404
7081
  return pc.createOffer({
5405
7082
  iceRestart: true,
5406
7083
  offerToReceiveAudio: true,
5407
7084
  offerToReceiveVideo: true
5408
7085
  });
5409
7086
  case 13:
5410
- offer = _context2.sent;
7087
+ offer = _context4.sent;
5411
7088
  case 14:
5412
7089
  logger.log("local offer");
5413
7090
  logger.log(offer.sdp);
@@ -5433,11 +7110,11 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5433
7110
  });
5434
7111
  offer.sdp = lib.write(parsed);
5435
7112
  logger.log("local offer modified:\n", offer.sdp);
5436
- _context2.next = 22;
7113
+ _context4.next = 22;
5437
7114
  return pc.setLocalDescription(offer);
5438
7115
  case 22:
5439
7116
  finnalUrl = this._url;
5440
- _context2.prev = 23;
7117
+ _context4.prev = 23;
5441
7118
  if (this._opts.preProcessUrl) {
5442
7119
  finnalUrl = this._opts.preProcessUrl(finnalUrl).url;
5443
7120
  }
@@ -5450,7 +7127,7 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5450
7127
  sessionId
5451
7128
  });
5452
7129
  reqStart = Date.now();
5453
- _context2.next = 32;
7130
+ _context4.next = 32;
5454
7131
  return this._loader.load(finnalUrl, {
5455
7132
  body: JSON.stringify({
5456
7133
  sessionId,
@@ -5459,22 +7136,22 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5459
7136
  })
5460
7137
  });
5461
7138
  case 32:
5462
- res = _context2.sent;
7139
+ res = _context4.sent;
5463
7140
  this.emit(EVENT.LOAD_RESPONSE_HEADERS, {
5464
7141
  headers: res.response.headers
5465
7142
  });
5466
7143
  answer = res === null || res === void 0 ? void 0 : res.data;
5467
7144
  if (!((answer === null || answer === void 0 ? void 0 : answer.code) === 404 || (answer === null || answer === void 0 ? void 0 : answer.code) === 403)) {
5468
- _context2.next = 40;
7145
+ _context4.next = 40;
5469
7146
  break;
5470
7147
  }
5471
7148
  err = StreamingError.create(answer.code === 404 ? ERR.NETWORK_NOTFOUND : ERR.NETWORK_FORBIDDEN, null, answer);
5472
7149
  err.errorType = ERR.NETWORK;
5473
7150
  this._emitError(err);
5474
- return _context2.abrupt("return");
7151
+ return _context4.abrupt("return");
5475
7152
  case 40:
5476
7153
  if (!((answer === null || answer === void 0 ? void 0 : answer.code) !== 200)) {
5477
- _context2.next = 42;
7154
+ _context4.next = 42;
5478
7155
  break;
5479
7156
  }
5480
7157
  throw new Error("code: ".concat(answer === null || answer === void 0 ? void 0 : answer.code, ", message:").concat(answer === null || answer === void 0 ? void 0 : answer.message));
@@ -5495,38 +7172,178 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5495
7172
  })
5496
7173
  });
5497
7174
  _parsed.media.forEach(function(x) {
7175
+ var _x$ssrcs, _x$ssrcs$find;
5498
7176
  x.fingerprint.hash = x.fingerprint.hash.toUpperCase();
7177
+ var msid = (_x$ssrcs = x.ssrcs) === null || _x$ssrcs === void 0 ? void 0 : (_x$ssrcs$find = _x$ssrcs.find(function(s) {
7178
+ return s.attribute === "msid";
7179
+ })) === null || _x$ssrcs$find === void 0 ? void 0 : _x$ssrcs$find.value;
7180
+ if (msid && !x.msid) {
7181
+ x.msid = msid;
7182
+ }
5499
7183
  });
5500
7184
  answer.remoteSdp.sdp = lib.write(_parsed);
5501
7185
  logger.log("answer modified:\n", answer.remoteSdp.sdp);
5502
7186
  this._rctConnectStartTs = Date.now();
5503
- _context2.next = 52;
7187
+ _context4.next = 52;
5504
7188
  return this._pc.setRemoteDescription(answer.remoteSdp);
5505
7189
  case 52:
5506
7190
  this._networkEvaluate = new NetworkEvaluate(pc, this._opts.networkEvaluateInterval);
5507
- _context2.next = 58;
7191
+ _context4.next = 58;
5508
7192
  break;
5509
7193
  case 55:
5510
- _context2.prev = 55;
5511
- _context2.t0 = _context2["catch"](23);
5512
- this._emitError(StreamingError.network(_context2.t0));
7194
+ _context4.prev = 55;
7195
+ _context4.t0 = _context4["catch"](23);
7196
+ this._emitError(StreamingError.network(_context4.t0));
5513
7197
  case 58:
5514
7198
  case "end":
5515
- return _context2.stop();
7199
+ return _context4.stop();
5516
7200
  }
5517
- }, _callee2, this, [[23, 55]]);
7201
+ }, _callee4, this, [[23, 55]]);
5518
7202
  }));
5519
7203
  function _connect() {
5520
7204
  return _connect2.apply(this, arguments);
5521
7205
  }
5522
7206
  return _connect;
5523
7207
  }()
7208
+ }, {
7209
+ key: "_startRtcReport",
7210
+ value: function _startRtcReport() {
7211
+ var _this6 = this;
7212
+ this._rtcReportTimer = setInterval(/* @__PURE__ */ _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee5() {
7213
+ var _yield$Promise$all, _yield$Promise$all2, curAudioStats, curVideoStats, _this6$_audioStallObs, _this6$_videoStallObs, _this6$_networkQualit, _this6$_networkQualit2, audioStats, videoStats, audioStallInfo, videoStallInfo, _ref4, _ref5, quality, qualityInfo, targetDelay;
7214
+ return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
7215
+ while (1)
7216
+ switch (_context5.prev = _context5.next) {
7217
+ case 0:
7218
+ if (!_this6._audioStallObserver && _this6._audioTransceicer) {
7219
+ _this6._audioStallObserver = new AudioStallObserver();
7220
+ _this6._audioStallObserver.start(_this6._audioTransceicer);
7221
+ }
7222
+ if (!_this6._videoStallObserver && _this6._video) {
7223
+ _this6._videoStallObserver = new VideoStallObserver();
7224
+ _this6._videoStallObserver.start(_this6._media);
7225
+ }
7226
+ if (!_this6._networkQuality && _this6._opts.enableNetworkQuality) {
7227
+ _this6._networkQuality = new NetworkQuality(_this6._pc, _this6._opts.networkQuality);
7228
+ }
7229
+ _context5.next = 5;
7230
+ return Promise.all([getRecvAudioStats(_this6._audioTransceicer.receiver.getStats()), getRecvVideoStats(_this6._videoTransceicer.receiver.getStats())]);
7231
+ case 5:
7232
+ _yield$Promise$all = _context5.sent;
7233
+ _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
7234
+ curAudioStats = _yield$Promise$all2[0];
7235
+ curVideoStats = _yield$Promise$all2[1];
7236
+ if (!(_this6._preAudioStats && _this6._preVideoStats)) {
7237
+ _context5.next = 21;
7238
+ break;
7239
+ }
7240
+ audioStats = diffRecvAudioStats(_this6._preAudioStats, curAudioStats);
7241
+ videoStats = diffRecvVideoStats(_this6._preVideoStats, curVideoStats);
7242
+ _context5.next = 14;
7243
+ return (_this6$_audioStallObs = _this6._audioStallObserver) === null || _this6$_audioStallObs === void 0 ? void 0 : _this6$_audioStallObs.getAudioStallInfo();
7244
+ case 14:
7245
+ audioStallInfo = _context5.sent;
7246
+ _context5.next = 17;
7247
+ return (_this6$_videoStallObs = _this6._videoStallObserver) === null || _this6$_videoStallObs === void 0 ? void 0 : _this6$_videoStallObs.getStallInfo({
7248
+ interval: videoStats.statsInterval,
7249
+ frameRateReceived: videoStats.frameRateReceived,
7250
+ frameRateDecoded: videoStats.frameRateDecoded,
7251
+ bitrate: videoStats.receivedKBitrate
7252
+ });
7253
+ case 17:
7254
+ videoStallInfo = _context5.sent;
7255
+ _ref4 = (_this6$_networkQualit = (_this6$_networkQualit2 = _this6._networkQuality) === null || _this6$_networkQualit2 === void 0 ? void 0 : _this6$_networkQualit2.getDownlinkQuality(_objectSpread2$2(_objectSpread2$2({}, audioStats), {}, {
7256
+ stallDuration: audioStallInfo.stallDuration
7257
+ }), _objectSpread2$2(_objectSpread2$2({}, videoStats), {}, {
7258
+ stallDuration: videoStallInfo.stall.stallDuration100ms
7259
+ }))) !== null && _this6$_networkQualit !== void 0 ? _this6$_networkQualit : [], _ref5 = _slicedToArray(_ref4, 2), quality = _ref5[0], qualityInfo = _ref5[1];
7260
+ if (_this6._opts.enableAdaptiveJitterBuffer) {
7261
+ targetDelay = _this6._handleJitterBuffer(qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.qualityQos, _this6._opts.adaptiveJitterBuffer, _this6._opts.networkStrategy);
7262
+ }
7263
+ _this6.emit(EXTEND_EVENTS.RTC_NETWORK, {
7264
+ interval: videoStats.statsInterval,
7265
+ visibility_state: document.visibilityState,
7266
+ network_quality: quality,
7267
+ audio_stall_duration: audioStallInfo.stallDuration,
7268
+ audio_stall_count: audioStallInfo.stallCount,
7269
+ audio_stall_time_per_100sec: audioStallInfo.stallDuration / audioStats.statsInterval * 100,
7270
+ audio_stall_count_per_100sec: audioStallInfo.stallCount / audioStats.statsInterval * 100 * 1e3,
7271
+ video_stall_duration: videoStallInfo.stall.stallDuration500ms,
7272
+ video_stall_count: videoStallInfo.stall.stallCount500ms,
7273
+ video_stall_duration_100ms: videoStallInfo.stall.stallDuration100ms,
7274
+ video_stall_count_100ms: videoStallInfo.stall.stallCount100ms,
7275
+ video_stall_time_per_100sec: videoStallInfo.stall.stallDuration500ms / videoStats.statsInterval * 100,
7276
+ video_stall_count_per_100sec: videoStallInfo.stall.stallCount500ms / videoStats.statsInterval * 100 * 1e3,
7277
+ rtt: videoStats.rtt,
7278
+ video_jb_delay: videoStats.jitterBufferDelay,
7279
+ audio_jb_delay: audioStats.jitterBufferDelay,
7280
+ audio_lost_rate: audioStats.audioLossRate,
7281
+ video_lost_rate: videoStats.videoLossRate,
7282
+ video_retransmitted_rate: videoStats.retransmittedRate,
7283
+ quality_audio_level: qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.audioLevel,
7284
+ quality_video_level: qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.videoLevel,
7285
+ quality_audio_qos: qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.audioQos,
7286
+ quality_video_qos: qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.videoQos,
7287
+ quality_qos: qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.qualityQos,
7288
+ quality_audio_qoe: qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.audioQoe,
7289
+ quality_video_qoe: qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.videoQoe,
7290
+ current_delay: _this6._getDelay(),
7291
+ target_delay: targetDelay
7292
+ });
7293
+ case 21:
7294
+ _this6._preAudioStats = curAudioStats;
7295
+ _this6._preVideoStats = curVideoStats;
7296
+ case 23:
7297
+ case "end":
7298
+ return _context5.stop();
7299
+ }
7300
+ }, _callee5);
7301
+ })), 2e3);
7302
+ }
7303
+ }, {
7304
+ key: "_handleJitterBuffer",
7305
+ value: function _handleJitterBuffer(quality, adaptiveJitterBuffer, networkStrategy) {
7306
+ this._networkQualityResult.push(quality);
7307
+ if (this._networkQualityResult.length > adaptiveJitterBuffer.networkWindow) {
7308
+ this._networkQualityResult.shift();
7309
+ }
7310
+ var validNetworkQualityResult = this._networkQualityResult.filter(Boolean);
7311
+ if (validNetworkQualityResult.length === adaptiveJitterBuffer.networkWindow) {
7312
+ var _networkStrategy$aver;
7313
+ var sorted = _toConsumableArray$1(validNetworkQualityResult).sort(function(a, b) {
7314
+ return a - b;
7315
+ });
7316
+ var mid = Math.floor(sorted.length / 2);
7317
+ var averageQuality = sorted.length % 2 !== 0 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2;
7318
+ if (averageQuality && ((_networkStrategy$aver = networkStrategy[averageQuality]) === null || _networkStrategy$aver === void 0 ? void 0 : _networkStrategy$aver.jitterBuffer) !== void 0) {
7319
+ var _networkStrategy$aver2, _networkStrategy$aver3;
7320
+ this._setDelay((_networkStrategy$aver2 = networkStrategy[averageQuality]) === null || _networkStrategy$aver2 === void 0 ? void 0 : _networkStrategy$aver2.jitterBuffer);
7321
+ return (_networkStrategy$aver3 = networkStrategy[averageQuality]) === null || _networkStrategy$aver3 === void 0 ? void 0 : _networkStrategy$aver3.jitterBuffer;
7322
+ }
7323
+ }
7324
+ }
7325
+ }, {
7326
+ key: "_stopRtcReport",
7327
+ value: function _stopRtcReport() {
7328
+ var _this$_audioStallObse, _this$_videoStallObse, _this$_networkQuality;
7329
+ (_this$_audioStallObse = this._audioStallObserver) === null || _this$_audioStallObse === void 0 ? void 0 : _this$_audioStallObse.destroy();
7330
+ (_this$_videoStallObse = this._videoStallObserver) === null || _this$_videoStallObse === void 0 ? void 0 : _this$_videoStallObse.destroy();
7331
+ (_this$_networkQuality = this._networkQuality) === null || _this$_networkQuality === void 0 ? void 0 : _this$_networkQuality.destroy();
7332
+ this._audioStallObserver = null;
7333
+ this._videoStallObserver = null;
7334
+ this._networkQuality = null;
7335
+ if (this._rtcReportTimer) {
7336
+ clearInterval(this._rtcReportTimer);
7337
+ this._rtcReportTimer = 0;
7338
+ }
7339
+ }
5524
7340
  }, {
5525
7341
  key: "_disconnect",
5526
7342
  value: function _disconnect() {
5527
7343
  var _this$_loader, _this$_networkEvaluat2;
5528
7344
  (_this$_loader = this._loader) === null || _this$_loader === void 0 ? void 0 : _this$_loader.cancel();
5529
7345
  (_this$_networkEvaluat2 = this._networkEvaluate) === null || _this$_networkEvaluat2 === void 0 ? void 0 : _this$_networkEvaluat2.destroy();
7346
+ this._stopRtcReport();
5530
7347
  this._audioTransceicer = null;
5531
7348
  this._videoTransceicer = null;
5532
7349
  this._mediaStream = null;
@@ -5536,6 +7353,10 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5536
7353
  key: "_emitError",
5537
7354
  value: function _emitError(error) {
5538
7355
  this.emit(EVENT.ERROR, error);
7356
+ clearTimeout(this._checkStatsErrorTimer);
7357
+ if (this._pc) {
7358
+ this._pc.close();
7359
+ }
5539
7360
  }
5540
7361
  }, {
5541
7362
  key: "destroy",
@@ -5552,6 +7373,7 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5552
7373
  this._loader = null;
5553
7374
  this._media = null;
5554
7375
  this._pc = null;
7376
+ this._opts = null;
5555
7377
  }
5556
7378
  }], [{
5557
7379
  key: "enableLogger",
@@ -5574,70 +7396,12 @@ try {
5574
7396
  }
5575
7397
  } catch (error) {
5576
7398
  }
5577
- function isSupported() {
5578
- if (!window.RTCPeerConnection || !window.RTCPeerConnection.prototype.addTransceiver) {
5579
- return false;
5580
- }
5581
- return true;
5582
- }
5583
- function getCapacity() {
5584
- if (!isSupported())
5585
- return Promise.reject("RTCPeerConnection no support");
5586
- var pc;
5587
- try {
5588
- pc = new RTCPeerConnection();
5589
- pc.addTransceiver("video", {
5590
- direction: "recvonly"
5591
- });
5592
- pc.addTransceiver("audio", {
5593
- direction: "recvonly"
5594
- });
5595
- } catch (e) {
5596
- return Promise.reject(e === null || e === void 0 ? void 0 : e.message);
5597
- }
5598
- return pc.createOffer().then(function(offer) {
5599
- var _sdpJson$media, _sdpJson$media2, _vMedia$rtp, _aMedia$rtp;
5600
- logger.log(offer.sdp);
5601
- var sdpJson = lib.parse(offer.sdp);
5602
- var vMedia = (_sdpJson$media = sdpJson.media) === null || _sdpJson$media === void 0 ? void 0 : _sdpJson$media.filter(function(x) {
5603
- return x.type === "video";
5604
- })[0];
5605
- var aMedia = (_sdpJson$media2 = sdpJson.media) === null || _sdpJson$media2 === void 0 ? void 0 : _sdpJson$media2.filter(function(x) {
5606
- return x.type === "audio";
5607
- })[0];
5608
- var vCodecs = vMedia === null || vMedia === void 0 ? void 0 : (_vMedia$rtp = vMedia.rtp) === null || _vMedia$rtp === void 0 ? void 0 : _vMedia$rtp.filter(function(x) {
5609
- return x.codec === "VP8" || x.codec === "VP9" || x.codec === "H264";
5610
- });
5611
- var aCodecs = aMedia === null || aMedia === void 0 ? void 0 : (_aMedia$rtp = aMedia.rtp) === null || _aMedia$rtp === void 0 ? void 0 : _aMedia$rtp.filter(function(x) {
5612
- return x.codec === "opus";
5613
- });
5614
- var vFmtp = vMedia === null || vMedia === void 0 ? void 0 : vMedia.fmtp;
5615
- var aFmtp = aMedia === null || aMedia === void 0 ? void 0 : aMedia.fmtp;
5616
- vFmtp && vCodecs.map(function(codec) {
5617
- var _vFmtp$filter$;
5618
- codec.config = (_vFmtp$filter$ = vFmtp.filter(function(x) {
5619
- return x.payload === codec.payload;
5620
- })[0]) === null || _vFmtp$filter$ === void 0 ? void 0 : _vFmtp$filter$.config;
5621
- });
5622
- aFmtp && aCodecs.map(function(codec) {
5623
- var _aFmtp$filter$;
5624
- codec.config = (_aFmtp$filter$ = aFmtp.filter(function(x) {
5625
- return x.payload === codec.payload;
5626
- })[0]) === null || _aFmtp$filter$ === void 0 ? void 0 : _aFmtp$filter$.config;
5627
- });
5628
- pc.close();
5629
- return {
5630
- video: vCodecs,
5631
- audio: aCodecs
5632
- };
5633
- });
5634
- }
5635
7399
  var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5636
7400
  _inherits$1(RtsPlugin2, _BasePlugin);
5637
7401
  var _super = _createSuper$1(RtsPlugin2);
5638
7402
  function RtsPlugin2() {
5639
7403
  var _this;
5640
- _classCallCheck$2(this, RtsPlugin2);
7404
+ _classCallCheck$3(this, RtsPlugin2);
5641
7405
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
5642
7406
  args[_key] = arguments[_key];
5643
7407
  }
@@ -5702,7 +7466,7 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5702
7466
  });
5703
7467
  return _this;
5704
7468
  }
5705
- _createClass$2(RtsPlugin2, [{
7469
+ _createClass$3(RtsPlugin2, [{
5706
7470
  key: "pc",
5707
7471
  get: function get() {
5708
7472
  var _this$_rts4;
@@ -5734,7 +7498,7 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5734
7498
  }, {
5735
7499
  key: "version",
5736
7500
  get: function get() {
5737
- return "0.2.1-alpha.14";
7501
+ return "0.2.1-alpha.29";
5738
7502
  }
5739
7503
  }, {
5740
7504
  key: "beforePlayerInit",
@@ -5799,6 +7563,12 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5799
7563
  var _this$_rts10;
5800
7564
  return (_this$_rts10 = this._rts) === null || _this$_rts10 === void 0 ? void 0 : _this$_rts10.networkStats;
5801
7565
  }
7566
+ }, {
7567
+ key: "setDelay",
7568
+ value: function setDelay(delayHint) {
7569
+ var _this$_rts11;
7570
+ (_this$_rts11 = this._rts) === null || _this$_rts11 === void 0 ? void 0 : _this$_rts11._setDelay(delayHint);
7571
+ }
5802
7572
  }, {
5803
7573
  key: "_clearDisconnectTimer",
5804
7574
  value: function _clearDisconnectTimer() {
@@ -5808,15 +7578,15 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5808
7578
  }, {
5809
7579
  key: "_closeAfterPause",
5810
7580
  value: function _closeAfterPause() {
5811
- var _this$_rts11, _this$config, _this$_rts13;
5812
- if (!((_this$_rts11 = this._rts) !== null && _this$_rts11 !== void 0 && _this$_rts11._pc)) {
7581
+ var _this$_rts12, _this$config, _this$_rts14;
7582
+ if (!((_this$_rts12 = this._rts) !== null && _this$_rts12 !== void 0 && _this$_rts12._pc)) {
5813
7583
  return;
5814
7584
  }
5815
7585
  if ((_this$config = this.config) !== null && _this$config !== void 0 && _this$config.seamlesslyReload) {
5816
- var _this$_rts12;
5817
- this._mediaStream = (_this$_rts12 = this._rts) === null || _this$_rts12 === void 0 ? void 0 : _this$_rts12._mediaStream;
7586
+ var _this$_rts13;
7587
+ this._mediaStream = (_this$_rts13 = this._rts) === null || _this$_rts13 === void 0 ? void 0 : _this$_rts13._mediaStream;
5818
7588
  }
5819
- (_this$_rts13 = this._rts) === null || _this$_rts13 === void 0 ? void 0 : _this$_rts13.destroy(true);
7589
+ (_this$_rts14 = this._rts) === null || _this$_rts14 === void 0 ? void 0 : _this$_rts14.destroy(true);
5820
7590
  this._rts = null;
5821
7591
  }
5822
7592
  }, {
@@ -5829,7 +7599,9 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5829
7599
  this._transCoreEvent(EVENT.LOAD_RESPONSE_HEADERS);
5830
7600
  this._transCoreEvent(EVENT.LOAD_RETRY);
5831
7601
  this._transCoreEvent(EVENT.METADATA_PARSED);
7602
+ this._transCoreEvent(EVENT.SEI);
5832
7603
  this._transCoreEvent(EXTEND_EVENTS.RTC_STATE_CHANGE);
7604
+ this._transCoreEvent(EXTEND_EVENTS.RTC_NETWORK);
5833
7605
  }
5834
7606
  }, {
5835
7607
  key: "_transErrorEvent",