@volcengine/veplayer-plugin 2.8.0-rc.2 → 2.8.1-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.
@@ -474,6 +474,38 @@ function _isNativeReflectConstruct$1() {
474
474
  return false;
475
475
  }
476
476
  }
477
+ function _objectWithoutPropertiesLoose$1(source, excluded) {
478
+ if (source == null)
479
+ return {};
480
+ var target = {};
481
+ var sourceKeys = Object.keys(source);
482
+ var key, i;
483
+ for (i = 0; i < sourceKeys.length; i++) {
484
+ key = sourceKeys[i];
485
+ if (excluded.indexOf(key) >= 0)
486
+ continue;
487
+ target[key] = source[key];
488
+ }
489
+ return target;
490
+ }
491
+ function _objectWithoutProperties$1(source, excluded) {
492
+ if (source == null)
493
+ return {};
494
+ var target = _objectWithoutPropertiesLoose$1(source, excluded);
495
+ var key, i;
496
+ if (Object.getOwnPropertySymbols) {
497
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
498
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
499
+ key = sourceSymbolKeys[i];
500
+ if (excluded.indexOf(key) >= 0)
501
+ continue;
502
+ if (!Object.prototype.propertyIsEnumerable.call(source, key))
503
+ continue;
504
+ target[key] = source[key];
505
+ }
506
+ }
507
+ return target;
508
+ }
477
509
  function _assertThisInitialized$1(self2) {
478
510
  if (self2 === void 0) {
479
511
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
@@ -4007,7 +4039,7 @@ var XhrLoader = /* @__PURE__ */ function(_EventEmitter) {
4007
4039
  }]);
4008
4040
  return XhrLoader2;
4009
4041
  }(EventEmitter);
4010
- var _excluded = ["retry", "retryDelay", "onRetryError", "transformError"];
4042
+ var _excluded$1 = ["retry", "retryDelay", "onRetryError", "transformError"];
4011
4043
  var Task = /* @__PURE__ */ function() {
4012
4044
  function Task2(type, config) {
4013
4045
  _classCallCheck$1(this, Task2);
@@ -4027,7 +4059,7 @@ var Task = /* @__PURE__ */ function() {
4027
4059
  key: "exec",
4028
4060
  value: function exec() {
4029
4061
  var _this = this;
4030
- var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties(_this$_config, _excluded);
4062
+ var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties(_this$_config, _excluded$1);
4031
4063
  var request = /* @__PURE__ */ function() {
4032
4064
  var _ref = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee() {
4033
4065
  var response, error, isRetry;
@@ -4943,7 +4975,9 @@ lib.parsePayloads = parser.parsePayloads;
4943
4975
  lib.parseRemoteCandidates = parser.parseRemoteCandidates;
4944
4976
  lib.parseImageAttributes = parser.parseImageAttributes;
4945
4977
  lib.parseSimulcastStreamList = parser.parseSimulcastStreamList;
4946
- function getOption(opts) {
4978
+ var _excluded = ["adaptiveJitterBuffer"];
4979
+ function getOption(options) {
4980
+ var _ref = options || {}, _ref$adaptiveJitterBu = _ref.adaptiveJitterBuffer, adaptiveJitterBuffer = _ref$adaptiveJitterBu === void 0 ? {} : _ref$adaptiveJitterBu, opts = _objectWithoutProperties$1(_ref, _excluded);
4947
4981
  return _objectSpread2$2({
4948
4982
  retryCount: 0,
4949
4983
  retryDelay: 1e3,
@@ -4951,11 +4985,15 @@ function getOption(opts) {
4951
4985
  stallInterval: 400,
4952
4986
  networkEvaluateInterval: 1e3,
4953
4987
  delayHint: 0,
4988
+ videoDelaySync: false,
4954
4989
  seamlesslyReload: false,
4955
4990
  enableSei: false,
4956
4991
  enableOriginSdpLogger: false,
4957
4992
  checkStatsErrorDelay: 5e3,
4993
+ connectionStateChangeTimeout: 5e3,
4958
4994
  enableNetworkQuality: false,
4995
+ hackCreateOfferIssue: false,
4996
+ progressiveSetDelay: false,
4959
4997
  networkQuality: {
4960
4998
  networkQos: {
4961
4999
  1: {
@@ -4986,9 +5024,14 @@ function getOption(opts) {
4986
5024
  }
4987
5025
  },
4988
5026
  enableAdaptiveJitterBuffer: false,
4989
- adaptiveJitterBuffer: {
4990
- networkWindow: 3
4991
- },
5027
+ adaptiveJitterBuffer: _objectSpread2$2({
5028
+ networkWindow: 3,
5029
+ windowMethod: "max",
5030
+ loopInterval: 500,
5031
+ maxAvSyncDelay: 400,
5032
+ maxJitterBufferDiff: 500,
5033
+ maxStep: 500
5034
+ }, adaptiveJitterBuffer),
4992
5035
  networkStrategy: {
4993
5036
  1: {
4994
5037
  "jitterBuffer": null
@@ -6437,6 +6480,12 @@ function _getRecvAudioStats() {
6437
6480
  if (stat.fecPacketsReceived !== void 0) {
6438
6481
  currentStats.fecPacketsReceived = stat.fecPacketsReceived;
6439
6482
  }
6483
+ if (stat.estimatedPlayoutTimestamp !== void 0) {
6484
+ currentStats.estimatedPlayoutTimestamp = stat.estimatedPlayoutTimestamp;
6485
+ }
6486
+ if (stat.totalSamplesDuration !== void 0) {
6487
+ currentStats.totalSamplesDuration = stat.totalSamplesDuration;
6488
+ }
6440
6489
  } else if (stat.type === "codec") {
6441
6490
  currentStats.recordSampleRate = stat.clockRate;
6442
6491
  if (stat.channels) {
@@ -6464,13 +6513,17 @@ function diffRecvAudioStats(oldStats, newStats) {
6464
6513
  var statsInterval = diffNumber(oldStats, newStats, "timestamp");
6465
6514
  var packetsLostDiff = diffNumber(oldStats, newStats, "packetsLost");
6466
6515
  var jitterBufferDelay = Math.round(diffNumber(oldStats, newStats, "jitterBufferDelay") / diffNumber(oldStats, newStats, "jitterBufferEmittedCount") * 1e3);
6516
+ var packetsReceived = diffNumber(oldStats, newStats, "packetsReceived");
6467
6517
  return {
6468
- audioLossRate: +(packetsLostDiff / (diffNumber(oldStats, newStats, "packetsReceived") + packetsLostDiff)).toFixed(2),
6518
+ audioLossRate: +(packetsLostDiff / (packetsReceived + packetsLostDiff)).toFixed(2),
6469
6519
  receivedKBitrate: +(diffNumber(oldStats, newStats, "bytesReceived") * 8 / statsInterval).toFixed(2),
6470
6520
  statsInterval,
6471
6521
  rtt: newStats.rtt || 0,
6472
6522
  jitterBufferDelay,
6523
+ packetsReceived,
6473
6524
  numChannels: newStats.numChannels || 1,
6525
+ estimatedPlayoutTimestamp: newStats.estimatedPlayoutTimestamp,
6526
+ samplesDuration: Math.round(diffNumber(oldStats, newStats, "totalSamplesDuration") * 1e3),
6474
6527
  receivedSampleRate: diffNumber(oldStats, newStats, "totalSamplesReceived") / statsInterval,
6475
6528
  concealedSamples: Math.round(diffNumber(oldStats, newStats, "concealedSamples")),
6476
6529
  concealmentEvent: Math.round(diffNumber(oldStats, newStats, "concealmentEvents")),
@@ -6514,6 +6567,9 @@ function _getRecvVideoStats() {
6514
6567
  currentStats.width = stat.frameWidth;
6515
6568
  currentStats.height = stat.frameHeight;
6516
6569
  }
6570
+ if (stat.estimatedPlayoutTimestamp !== void 0) {
6571
+ currentStats.estimatedPlayoutTimestamp = stat.estimatedPlayoutTimestamp;
6572
+ }
6517
6573
  } else if (stat.type === "track" && stat.frameWidth !== void 0) {
6518
6574
  currentStats.width = stat.frameWidth;
6519
6575
  currentStats.height = stat.frameHeight;
@@ -6546,6 +6602,7 @@ function diffRecvVideoStats(oldStats, newStats) {
6546
6602
  statsInterval,
6547
6603
  width: newStats.width || 0,
6548
6604
  height: newStats.height || 0,
6605
+ estimatedPlayoutTimestamp: newStats.estimatedPlayoutTimestamp,
6549
6606
  videoLossRate: +(packetsLostDiff / (diffNumber(oldStats, newStats, "packetsReceived") + packetsLostDiff)),
6550
6607
  receivedKBitrate: +(diffNumber(oldStats, newStats, "bytesReceived") * 8 / statsInterval).toFixed(2),
6551
6608
  decoderOutputFrameRate: Math.round(diffNumber(oldStats, newStats, "framesDecoded") * 1e3 / statsInterval),
@@ -6728,11 +6785,15 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
6728
6785
  _defineProperty$2(_assertThisInitialized$1(_this), "_preVideoStats", null);
6729
6786
  _defineProperty$2(_assertThisInitialized$1(_this), "_rtcReportTimer", 0);
6730
6787
  _defineProperty$2(_assertThisInitialized$1(_this), "_networkQualityResult", []);
6788
+ _defineProperty$2(_assertThisInitialized$1(_this), "_peerStateTimer", null);
6731
6789
  _defineProperty$2(_assertThisInitialized$1(_this), "_checkStatsError", /* @__PURE__ */ _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee2() {
6732
6790
  return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
6733
6791
  while (1)
6734
6792
  switch (_context2.prev = _context2.next) {
6735
6793
  case 0:
6794
+ if (_this._checkStatsErrorTimer) {
6795
+ clearTimeout(_this._checkStatsErrorTimer);
6796
+ }
6736
6797
  _this._checkStatsErrorTimer = setTimeout(/* @__PURE__ */ _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee() {
6737
6798
  var stats, _stats$video, framesDecoded, bytesReceived;
6738
6799
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
@@ -6761,7 +6822,7 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
6761
6822
  }
6762
6823
  }, _callee);
6763
6824
  })), _this._opts.checkStatsErrorDelay);
6764
- case 1:
6825
+ case 2:
6765
6826
  case "end":
6766
6827
  return _context2.stop();
6767
6828
  }
@@ -6799,28 +6860,165 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
6799
6860
  });
6800
6861
  });
6801
6862
  _defineProperty$2(_assertThisInitialized$1(_this), "_setDelay", function(delayHint) {
6802
- var currentDelay = _this._getDelay();
6803
- delayHint = typeof delayHint === "number" && delayHint > 0 ? delayHint : null;
6804
- if (currentDelay === delayHint)
6805
- return;
6806
- try {
6807
- var videoReceiver = _this._videoTransceicer.receiver;
6808
- var audioReceiver = _this._audioTransceicer.receiver;
6863
+ if (_this._opts.progressiveSetDelay) {
6864
+ _this._startSetDelayLoop(delayHint);
6865
+ } else {
6866
+ var _this$_audioTransceic2;
6809
6867
  var key = [
6810
6868
  "playoutDelayHint",
6811
6869
  "jitterBufferDelayHint",
6812
6870
  "jitterBufferTarget"
6813
6871
  ].find(function(key2) {
6814
- return key2 in videoReceiver && key2 in audioReceiver;
6872
+ var _this$_audioTransceic, _this$_videoTransceic;
6873
+ return key2 in ((_this$_audioTransceic = _this._audioTransceicer) === null || _this$_audioTransceic === void 0 ? void 0 : _this$_audioTransceic.receiver) && key2 in ((_this$_videoTransceic = _this._videoTransceicer) === null || _this$_videoTransceic === void 0 ? void 0 : _this$_videoTransceic.receiver);
6815
6874
  });
6816
- if (key) {
6817
- audioReceiver[key] = delayHint;
6818
- logger.log("set audioReceiver.".concat(key, " = ").concat(delayHint));
6819
- }
6820
- } catch (error) {
6821
- logger.error("set delay error", error);
6875
+ if (!key)
6876
+ return;
6877
+ delayHint = typeof delayHint === "number" && delayHint > 0 ? delayHint : null;
6878
+ if (((_this$_audioTransceic2 = _this._audioTransceicer) === null || _this$_audioTransceic2 === void 0 ? void 0 : _this$_audioTransceic2.receiver[key]) === delayHint)
6879
+ return;
6880
+ _this._audioTransceicer.receiver[key] = delayHint;
6881
+ _this._videoTransceicer.receiver[key] = delayHint;
6822
6882
  }
6823
6883
  });
6884
+ _defineProperty$2(_assertThisInitialized$1(_this), "_targetDelayHint", null);
6885
+ _defineProperty$2(_assertThisInitialized$1(_this), "_setDelayTimer", null);
6886
+ _defineProperty$2(_assertThisInitialized$1(_this), "_setDelayError", null);
6887
+ _defineProperty$2(_assertThisInitialized$1(_this), "_startSetDelayLoop", /* @__PURE__ */ function() {
6888
+ var _ref3 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee4(delayHint) {
6889
+ var key, preAudioStats, preVideoStats, _this$_opts$adaptiveJ, loopInterval, maxAvSyncDelay, maxJitterBufferDiff, maxStep, avDiffTooMuchCount;
6890
+ return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
6891
+ while (1)
6892
+ switch (_context4.prev = _context4.next) {
6893
+ case 0:
6894
+ key = [
6895
+ "playoutDelayHint",
6896
+ "jitterBufferDelayHint",
6897
+ "jitterBufferTarget"
6898
+ ].find(function(key2) {
6899
+ var _this$_audioTransceic3, _this$_videoTransceic2;
6900
+ return key2 in ((_this$_audioTransceic3 = _this._audioTransceicer) === null || _this$_audioTransceic3 === void 0 ? void 0 : _this$_audioTransceic3.receiver) && key2 in ((_this$_videoTransceic2 = _this._videoTransceicer) === null || _this$_videoTransceic2 === void 0 ? void 0 : _this$_videoTransceic2.receiver);
6901
+ });
6902
+ if (key) {
6903
+ _context4.next = 3;
6904
+ break;
6905
+ }
6906
+ return _context4.abrupt("return");
6907
+ case 3:
6908
+ delayHint = typeof delayHint === "number" && delayHint > 0 ? delayHint : null;
6909
+ if (!(_this._targetDelayHint === delayHint)) {
6910
+ _context4.next = 6;
6911
+ break;
6912
+ }
6913
+ return _context4.abrupt("return");
6914
+ case 6:
6915
+ _this._targetDelayHint = delayHint;
6916
+ if (!_this._setDelayTimer) {
6917
+ _context4.next = 9;
6918
+ break;
6919
+ }
6920
+ return _context4.abrupt("return");
6921
+ case 9:
6922
+ preAudioStats = null;
6923
+ preVideoStats = null;
6924
+ _this$_opts$adaptiveJ = _this._opts.adaptiveJitterBuffer, loopInterval = _this$_opts$adaptiveJ.loopInterval, maxAvSyncDelay = _this$_opts$adaptiveJ.maxAvSyncDelay, maxJitterBufferDiff = _this$_opts$adaptiveJ.maxJitterBufferDiff, maxStep = _this$_opts$adaptiveJ.maxStep;
6925
+ avDiffTooMuchCount = 0;
6926
+ _this._setDelayTimer = setInterval(/* @__PURE__ */ _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee3() {
6927
+ var _this$_audioTransceic4, _this$_videoTransceic3, currentTargetDelay, targetDelayMs, currentTargetDelayMs, _yield$Promise$all, _yield$Promise$all2, curAudioStats, curVideoStats, audioStats, videoStats, av_sync_diff, currentAudioDelay, currentVideoDelay, addOrReduce, nextJitterBufferDelay;
6928
+ return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
6929
+ while (1)
6930
+ switch (_context3.prev = _context3.next) {
6931
+ case 0:
6932
+ _context3.prev = 0;
6933
+ if (!(!((_this$_audioTransceic4 = _this._audioTransceicer) !== null && _this$_audioTransceic4 !== void 0 && _this$_audioTransceic4.receiver) || !((_this$_videoTransceic3 = _this._videoTransceicer) !== null && _this$_videoTransceic3 !== void 0 && _this$_videoTransceic3.receiver))) {
6934
+ _context3.next = 5;
6935
+ break;
6936
+ }
6937
+ preAudioStats = null;
6938
+ preVideoStats = null;
6939
+ return _context3.abrupt("return");
6940
+ case 5:
6941
+ currentTargetDelay = _this._audioTransceicer.receiver[key];
6942
+ if (!(currentTargetDelay === _this._targetDelayHint)) {
6943
+ _context3.next = 8;
6944
+ break;
6945
+ }
6946
+ return _context3.abrupt("return");
6947
+ case 8:
6948
+ targetDelayMs = _this._targetDelayHint * 1e3;
6949
+ currentTargetDelayMs = currentTargetDelay * 1e3;
6950
+ _context3.next = 12;
6951
+ return Promise.all([getRecvAudioStats(_this._audioTransceicer.receiver.getStats()), getRecvVideoStats(_this._videoTransceicer.receiver.getStats())]);
6952
+ case 12:
6953
+ _yield$Promise$all = _context3.sent;
6954
+ _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
6955
+ curAudioStats = _yield$Promise$all2[0];
6956
+ curVideoStats = _yield$Promise$all2[1];
6957
+ if (!(preAudioStats && preVideoStats)) {
6958
+ _context3.next = 36;
6959
+ break;
6960
+ }
6961
+ audioStats = diffRecvAudioStats(preAudioStats, curAudioStats);
6962
+ videoStats = diffRecvVideoStats(preVideoStats, curVideoStats);
6963
+ if (videoStats.estimatedPlayoutTimestamp && audioStats.estimatedPlayoutTimestamp) {
6964
+ av_sync_diff = videoStats.estimatedPlayoutTimestamp - audioStats.estimatedPlayoutTimestamp;
6965
+ }
6966
+ currentAudioDelay = audioStats.jitterBufferDelay;
6967
+ currentVideoDelay = videoStats.jitterBufferDelay;
6968
+ if (!(currentAudioDelay && currentVideoDelay)) {
6969
+ _context3.next = 36;
6970
+ break;
6971
+ }
6972
+ if (!(Math.abs(currentAudioDelay - currentVideoDelay) > maxAvSyncDelay || av_sync_diff && Math.abs(av_sync_diff) > maxAvSyncDelay)) {
6973
+ _context3.next = 27;
6974
+ break;
6975
+ }
6976
+ if (avDiffTooMuchCount++ > 8 && currentVideoDelay > currentAudioDelay) {
6977
+ _this._audioTransceicer.receiver[key] = Math.min(currentVideoDelay / 1e3, _this._targetDelayHint);
6978
+ avDiffTooMuchCount = 0;
6979
+ }
6980
+ logger.log("av_jb_diff(".concat(currentAudioDelay - currentVideoDelay, "=").concat(currentAudioDelay, "-").concat(currentVideoDelay, ") or av_sync_diff(").concat(av_sync_diff, ") too much, skip setting"));
6981
+ return _context3.abrupt("return");
6982
+ case 27:
6983
+ avDiffTooMuchCount = 0;
6984
+ if (!(currentTargetDelay !== null && (Math.abs(currentAudioDelay - currentTargetDelayMs) > maxJitterBufferDiff || Math.abs(currentVideoDelay - currentTargetDelayMs) > maxJitterBufferDiff))) {
6985
+ _context3.next = 31;
6986
+ break;
6987
+ }
6988
+ logger.log("audio(".concat(currentAudioDelay - currentTargetDelayMs, "),video(").concat(currentVideoDelay - currentTargetDelayMs, "). current_target_diff too much, skip setting"));
6989
+ return _context3.abrupt("return");
6990
+ case 31:
6991
+ addOrReduce = targetDelayMs > (currentTargetDelayMs || currentAudioDelay) ? 1 : -1;
6992
+ nextJitterBufferDelay = (Math.abs(targetDelayMs - (currentTargetDelayMs || currentAudioDelay)) > maxStep ? (currentTargetDelayMs || currentAudioDelay) + addOrReduce * maxStep : targetDelayMs) / 1e3;
6993
+ nextJitterBufferDelay = nextJitterBufferDelay > 0.2 ? nextJitterBufferDelay : null;
6994
+ logger.log("set receiver.".concat(key, " = ").concat(nextJitterBufferDelay));
6995
+ _this._audioTransceicer.receiver[key] = nextJitterBufferDelay;
6996
+ case 36:
6997
+ preAudioStats = curAudioStats;
6998
+ preVideoStats = curVideoStats;
6999
+ _context3.next = 44;
7000
+ break;
7001
+ case 40:
7002
+ _context3.prev = 40;
7003
+ _context3.t0 = _context3["catch"](0);
7004
+ logger.error("set delay loop error:", _context3.t0);
7005
+ _this._setDelayError = _context3.t0.message || _context3.t0.toString() || "unknown error";
7006
+ case 44:
7007
+ case "end":
7008
+ return _context3.stop();
7009
+ }
7010
+ }, _callee3, null, [[0, 40]]);
7011
+ })), loopInterval);
7012
+ case 14:
7013
+ case "end":
7014
+ return _context4.stop();
7015
+ }
7016
+ }, _callee4);
7017
+ }));
7018
+ return function(_x) {
7019
+ return _ref3.apply(this, arguments);
7020
+ };
7021
+ }());
6824
7022
  _defineProperty$2(_assertThisInitialized$1(_this), "_getDelay", function() {
6825
7023
  try {
6826
7024
  var key = ["playoutDelayHint", "jitterBufferDelayHint", "jitterBufferTarget"].find(function(key2) {
@@ -6896,44 +7094,51 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
6896
7094
  }, {
6897
7095
  key: "load",
6898
7096
  value: function() {
6899
- var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee3(url) {
7097
+ var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee5(url) {
6900
7098
  var _this2 = this;
6901
- var lastPc, encodedTransformSupported;
6902
- return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
7099
+ var encodedTransformSupported, lastPc;
7100
+ return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
6903
7101
  while (1)
6904
- switch (_context3.prev = _context3.next) {
7102
+ switch (_context5.prev = _context5.next) {
6905
7103
  case 0:
6906
7104
  this._disconnect();
6907
7105
  this._url = url;
6908
7106
  this._retry = this._opts.retryCount;
7107
+ if (!this._opts.hackCreateOfferIssue) {
7108
+ _context5.next = 6;
7109
+ break;
7110
+ }
7111
+ _context5.next = 6;
7112
+ return this._createEmptyPeer();
7113
+ case 6:
7114
+ encodedTransformSupported = isLegacyEncodedTransformSupported();
7115
+ _context5.prev = 7;
6909
7116
  lastPc = this._pc;
6910
7117
  if (lastPc) {
6911
7118
  lastPc.close();
6912
7119
  }
6913
- encodedTransformSupported = isLegacyEncodedTransformSupported();
6914
- _context3.prev = 6;
6915
7120
  this._pc = new RTCPeerConnection({
6916
7121
  encodedInsertableStreams: encodedTransformSupported && this._opts.enableSei ? true : void 0
6917
7122
  });
6918
7123
  this._bindRTCEvents();
6919
- _context3.next = 11;
7124
+ _context5.next = 14;
6920
7125
  return this._connect(url);
6921
- case 11:
6922
- _context3.next = 16;
7126
+ case 14:
7127
+ _context5.next = 19;
6923
7128
  break;
6924
- case 13:
6925
- _context3.prev = 13;
6926
- _context3.t0 = _context3["catch"](6);
7129
+ case 16:
7130
+ _context5.prev = 16;
7131
+ _context5.t0 = _context5["catch"](7);
6927
7132
  setTimeout(function() {
6928
- return _this2._emitError(StreamingError.create(ERR.OTHER, null, _context3.t0));
7133
+ return _this2._emitError(StreamingError.create(ERR.OTHER, null, _context5.t0));
6929
7134
  });
6930
- case 16:
7135
+ case 19:
6931
7136
  case "end":
6932
- return _context3.stop();
7137
+ return _context5.stop();
6933
7138
  }
6934
- }, _callee3, this, [[6, 13]]);
7139
+ }, _callee5, this, [[7, 16]]);
6935
7140
  }));
6936
- function load(_x) {
7141
+ function load(_x2) {
6937
7142
  return _load.apply(this, arguments);
6938
7143
  }
6939
7144
  return load;
@@ -6951,6 +7156,7 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
6951
7156
  pc.addEventListener("track", this._onTrack);
6952
7157
  pc.addEventListener("connectionstatechange", function() {
6953
7158
  logger.warn("onconnectionstatechange:", pc.connectionState);
7159
+ _this3._clearPeerStateTimeout();
6954
7160
  _this3.emit(EXTEND_EVENTS.RTC_STATE_CHANGE, {
6955
7161
  state: pc.connectionState,
6956
7162
  url: _this3._url
@@ -7070,15 +7276,15 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7070
7276
  }, {
7071
7277
  key: "_connect",
7072
7278
  value: function() {
7073
- var _connect2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee4() {
7279
+ var _connect2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee6() {
7074
7280
  var pc, offer, parsed, finnalUrl, _this$_opts, _answer$remoteSdp, _this$_opts2, _answer$remoteSdp2, _parsed$media, parseSession, sessionId, reqStart, res, answer, err, _parsed;
7075
- return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
7281
+ return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
7076
7282
  while (1)
7077
- switch (_context4.prev = _context4.next) {
7283
+ switch (_context6.prev = _context6.next) {
7078
7284
  case 0:
7079
7285
  pc = this._pc;
7080
7286
  if (!pc.addTransceiver) {
7081
- _context4.next = 11;
7287
+ _context6.next = 11;
7082
7288
  break;
7083
7289
  }
7084
7290
  this._audioTransceicer = pc.addTransceiver("audio", {
@@ -7087,27 +7293,30 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7087
7293
  this._videoTransceicer = pc.addTransceiver("video", {
7088
7294
  direction: "recvonly"
7089
7295
  });
7090
- !this._opts.enableAdaptiveJitterBuffer && this._setDelay(this._opts.delayHint);
7296
+ this._setDelay(this._opts.delayHint);
7091
7297
  if (this._opts.enableSei) {
7092
7298
  this.initVideoEncodedTransform();
7093
7299
  this.initAudioEncodedTransform();
7094
7300
  }
7095
- _context4.next = 8;
7301
+ _context6.next = 8;
7096
7302
  return pc.createOffer();
7097
7303
  case 8:
7098
- offer = _context4.sent;
7099
- _context4.next = 14;
7304
+ offer = _context6.sent;
7305
+ _context6.next = 14;
7100
7306
  break;
7101
7307
  case 11:
7102
- _context4.next = 13;
7308
+ _context6.next = 13;
7103
7309
  return pc.createOffer({
7104
7310
  iceRestart: true,
7105
7311
  offerToReceiveAudio: true,
7106
7312
  offerToReceiveVideo: true
7107
7313
  });
7108
7314
  case 13:
7109
- offer = _context4.sent;
7315
+ offer = _context6.sent;
7110
7316
  case 14:
7317
+ if (this._opts.hackCreateOfferIssue) {
7318
+ this._createEmptyPeer();
7319
+ }
7111
7320
  logger.log("local offer");
7112
7321
  logger.log(offer.sdp);
7113
7322
  parsed = lib.parse(offer.sdp);
@@ -7132,11 +7341,11 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7132
7341
  });
7133
7342
  offer.sdp = lib.write(parsed);
7134
7343
  logger.log("local offer modified:\n", offer.sdp);
7135
- _context4.next = 22;
7344
+ _context6.next = 23;
7136
7345
  return pc.setLocalDescription(offer);
7137
- case 22:
7346
+ case 23:
7138
7347
  finnalUrl = this._url;
7139
- _context4.prev = 23;
7348
+ _context6.prev = 24;
7140
7349
  if (this._opts.preProcessUrl) {
7141
7350
  finnalUrl = this._opts.preProcessUrl(finnalUrl).url;
7142
7351
  }
@@ -7149,7 +7358,7 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7149
7358
  sessionId
7150
7359
  });
7151
7360
  reqStart = Date.now();
7152
- _context4.next = 32;
7361
+ _context6.next = 33;
7153
7362
  return this._loader.load(finnalUrl, {
7154
7363
  body: JSON.stringify({
7155
7364
  sessionId,
@@ -7157,27 +7366,27 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7157
7366
  localSdp: offer
7158
7367
  })
7159
7368
  });
7160
- case 32:
7161
- res = _context4.sent;
7369
+ case 33:
7370
+ res = _context6.sent;
7162
7371
  this.emit(EVENT.LOAD_RESPONSE_HEADERS, {
7163
7372
  headers: res.response.headers
7164
7373
  });
7165
7374
  answer = res === null || res === void 0 ? void 0 : res.data;
7166
7375
  if (!((answer === null || answer === void 0 ? void 0 : answer.code) === 404 || (answer === null || answer === void 0 ? void 0 : answer.code) === 403)) {
7167
- _context4.next = 40;
7376
+ _context6.next = 41;
7168
7377
  break;
7169
7378
  }
7170
7379
  err = StreamingError.create(answer.code === 404 ? ERR.NETWORK_NOTFOUND : ERR.NETWORK_FORBIDDEN, null, answer);
7171
7380
  err.errorType = ERR.NETWORK;
7172
7381
  this._emitError(err);
7173
- return _context4.abrupt("return");
7174
- case 40:
7382
+ return _context6.abrupt("return");
7383
+ case 41:
7175
7384
  if (!((answer === null || answer === void 0 ? void 0 : answer.code) !== 200)) {
7176
- _context4.next = 42;
7385
+ _context6.next = 43;
7177
7386
  break;
7178
7387
  }
7179
7388
  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));
7180
- case 42:
7389
+ case 43:
7181
7390
  logger.log("answer:");
7182
7391
  logger.log((_answer$remoteSdp = answer.remoteSdp) === null || _answer$remoteSdp === void 0 ? void 0 : _answer$remoteSdp.sdp);
7183
7392
  _parsed = lib.parse(answer.remoteSdp.sdp);
@@ -7206,86 +7415,123 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7206
7415
  answer.remoteSdp.sdp = lib.write(_parsed);
7207
7416
  logger.log("answer modified:\n", answer.remoteSdp.sdp);
7208
7417
  this._rctConnectStartTs = Date.now();
7209
- _context4.next = 52;
7210
- return this._pc.setRemoteDescription(answer.remoteSdp);
7211
- case 52:
7418
+ if (!(pc.signalingState === "closed")) {
7419
+ _context6.next = 53;
7420
+ break;
7421
+ }
7422
+ return _context6.abrupt("return");
7423
+ case 53:
7424
+ _context6.next = 55;
7425
+ return pc.setRemoteDescription(answer.remoteSdp);
7426
+ case 55:
7212
7427
  this._networkEvaluate = new NetworkEvaluate(pc, this._opts.networkEvaluateInterval);
7213
- _context4.next = 58;
7428
+ this._listenPeerStateTimeout();
7429
+ _context6.next = 62;
7214
7430
  break;
7215
- case 55:
7216
- _context4.prev = 55;
7217
- _context4.t0 = _context4["catch"](23);
7218
- this._emitError(StreamingError.network(_context4.t0));
7219
- case 58:
7431
+ case 59:
7432
+ _context6.prev = 59;
7433
+ _context6.t0 = _context6["catch"](24);
7434
+ this._emitError(StreamingError.network(_context6.t0));
7435
+ case 62:
7220
7436
  case "end":
7221
- return _context4.stop();
7437
+ return _context6.stop();
7222
7438
  }
7223
- }, _callee4, this, [[23, 55]]);
7439
+ }, _callee6, this, [[24, 59]]);
7224
7440
  }));
7225
7441
  function _connect() {
7226
7442
  return _connect2.apply(this, arguments);
7227
7443
  }
7228
7444
  return _connect;
7229
7445
  }()
7446
+ }, {
7447
+ key: "_listenPeerStateTimeout",
7448
+ value: function _listenPeerStateTimeout() {
7449
+ var _this6 = this;
7450
+ this._peerStateTimer && this._clearPeerStateTimeout();
7451
+ if (this._opts.connectionStateChangeTimeout) {
7452
+ this._peerStateTimer = setTimeout(function() {
7453
+ _this6._emitError(StreamingError.create(ERR.MEDIA, ERR.SUB_TYPES.MEDIA_ERR_SRC_NOT_SUPPORTED, {
7454
+ message: "listen connectionstatechange timeout"
7455
+ }));
7456
+ }, this._opts.connectionStateChangeTimeout);
7457
+ }
7458
+ }
7459
+ }, {
7460
+ key: "_clearPeerStateTimeout",
7461
+ value: function _clearPeerStateTimeout() {
7462
+ clearTimeout(this._peerStateTimer);
7463
+ this._peerStateTimer = null;
7464
+ }
7230
7465
  }, {
7231
7466
  key: "_startRtcReport",
7232
7467
  value: function _startRtcReport() {
7233
- var _this6 = this;
7468
+ var _this7 = this;
7234
7469
  this._stopRtcReport();
7235
- this._rtcReportTimer = setInterval(/* @__PURE__ */ _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee5() {
7236
- 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;
7237
- return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
7470
+ this._rtcReportTimer = setInterval(/* @__PURE__ */ _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee7() {
7471
+ var _this7$_audioTranscei, _this7$_videoTranscei;
7472
+ var _yield$Promise$all3, _yield$Promise$all4, curAudioStats, curVideoStats, _this7$_audioStallObs, _this7$_videoStallObs, _this7$_networkQualit, _this7$_networkQualit2, audioStats, videoStats, audioStallInfo, videoStallInfo, _ref6, _ref7, quality, qualityInfo, av_sync_diff;
7473
+ return _regeneratorRuntime$1().wrap(function _callee7$(_context7) {
7238
7474
  while (1)
7239
- switch (_context5.prev = _context5.next) {
7475
+ switch (_context7.prev = _context7.next) {
7240
7476
  case 0:
7241
- if (!_this6._audioStallObserver && _this6._audioTransceicer) {
7242
- _this6._audioStallObserver = new AudioStallObserver();
7243
- _this6._audioStallObserver.start(_this6._audioTransceicer);
7477
+ if (!(!((_this7$_audioTranscei = _this7._audioTransceicer) !== null && _this7$_audioTranscei !== void 0 && _this7$_audioTranscei.receiver) || !((_this7$_videoTranscei = _this7._videoTransceicer) !== null && _this7$_videoTranscei !== void 0 && _this7$_videoTranscei.receiver))) {
7478
+ _context7.next = 4;
7479
+ break;
7244
7480
  }
7245
- if (!_this6._videoStallObserver && _this6._video) {
7246
- _this6._videoStallObserver = new VideoStallObserver();
7247
- _this6._videoStallObserver.start(_this6._media);
7481
+ _this7._preAudioStats = null;
7482
+ _this7._preVideoStats = null;
7483
+ return _context7.abrupt("return");
7484
+ case 4:
7485
+ if (!_this7._audioStallObserver && _this7._audioTransceicer) {
7486
+ _this7._audioStallObserver = new AudioStallObserver();
7487
+ _this7._audioStallObserver.start(_this7._audioTransceicer);
7248
7488
  }
7249
- if (!_this6._networkQuality && _this6._opts.enableNetworkQuality) {
7250
- _this6._networkQuality = new NetworkQuality(_this6._pc, _this6._opts.networkQuality);
7489
+ if (!_this7._videoStallObserver && _this7._video) {
7490
+ _this7._videoStallObserver = new VideoStallObserver();
7491
+ _this7._videoStallObserver.start(_this7._media);
7251
7492
  }
7252
- _context5.next = 5;
7253
- return Promise.all([getRecvAudioStats(_this6._audioTransceicer.receiver.getStats()), getRecvVideoStats(_this6._videoTransceicer.receiver.getStats())]);
7254
- case 5:
7255
- _yield$Promise$all = _context5.sent;
7256
- _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
7257
- curAudioStats = _yield$Promise$all2[0];
7258
- curVideoStats = _yield$Promise$all2[1];
7259
- if (!(_this6._preAudioStats && _this6._preVideoStats)) {
7260
- _context5.next = 21;
7493
+ if (!_this7._networkQuality && _this7._opts.enableNetworkQuality) {
7494
+ _this7._networkQuality = new NetworkQuality(_this7._pc, _this7._opts.networkQuality);
7495
+ }
7496
+ _context7.next = 9;
7497
+ return Promise.all([getRecvAudioStats(_this7._audioTransceicer.receiver.getStats()), getRecvVideoStats(_this7._videoTransceicer.receiver.getStats())]);
7498
+ case 9:
7499
+ _yield$Promise$all3 = _context7.sent;
7500
+ _yield$Promise$all4 = _slicedToArray(_yield$Promise$all3, 2);
7501
+ curAudioStats = _yield$Promise$all4[0];
7502
+ curVideoStats = _yield$Promise$all4[1];
7503
+ if (!(_this7._preAudioStats && _this7._preVideoStats)) {
7504
+ _context7.next = 26;
7261
7505
  break;
7262
7506
  }
7263
- audioStats = diffRecvAudioStats(_this6._preAudioStats, curAudioStats);
7264
- videoStats = diffRecvVideoStats(_this6._preVideoStats, curVideoStats);
7265
- _context5.next = 14;
7266
- return (_this6$_audioStallObs = _this6._audioStallObserver) === null || _this6$_audioStallObs === void 0 ? void 0 : _this6$_audioStallObs.getAudioStallInfo();
7267
- case 14:
7268
- audioStallInfo = _context5.sent;
7269
- _context5.next = 17;
7270
- return (_this6$_videoStallObs = _this6._videoStallObserver) === null || _this6$_videoStallObs === void 0 ? void 0 : _this6$_videoStallObs.getStallInfo({
7507
+ audioStats = diffRecvAudioStats(_this7._preAudioStats, curAudioStats);
7508
+ videoStats = diffRecvVideoStats(_this7._preVideoStats, curVideoStats);
7509
+ _context7.next = 18;
7510
+ return (_this7$_audioStallObs = _this7._audioStallObserver) === null || _this7$_audioStallObs === void 0 ? void 0 : _this7$_audioStallObs.getAudioStallInfo();
7511
+ case 18:
7512
+ audioStallInfo = _context7.sent;
7513
+ _context7.next = 21;
7514
+ return (_this7$_videoStallObs = _this7._videoStallObserver) === null || _this7$_videoStallObs === void 0 ? void 0 : _this7$_videoStallObs.getStallInfo({
7271
7515
  interval: videoStats.statsInterval,
7272
7516
  frameRateReceived: videoStats.frameRateReceived,
7273
7517
  frameRateDecoded: videoStats.frameRateDecoded,
7274
7518
  bitrate: videoStats.receivedKBitrate
7275
7519
  });
7276
- case 17:
7277
- videoStallInfo = _context5.sent;
7278
- _ref4 = (_this6$_networkQualit = (_this6$_networkQualit2 = _this6._networkQuality) === null || _this6$_networkQualit2 === void 0 ? void 0 : _this6$_networkQualit2.getDownlinkQuality(_objectSpread2$2(_objectSpread2$2({}, audioStats), {}, {
7520
+ case 21:
7521
+ videoStallInfo = _context7.sent;
7522
+ _ref6 = (_this7$_networkQualit = (_this7$_networkQualit2 = _this7._networkQuality) === null || _this7$_networkQualit2 === void 0 ? void 0 : _this7$_networkQualit2.getDownlinkQuality(_objectSpread2$2(_objectSpread2$2({}, audioStats), {}, {
7279
7523
  stallDuration: audioStallInfo.stallDuration
7280
7524
  }), _objectSpread2$2(_objectSpread2$2({}, videoStats), {}, {
7281
- stallDuration: videoStallInfo.stall.stallDuration100ms
7282
- }))) !== null && _this6$_networkQualit !== void 0 ? _this6$_networkQualit : [], _ref5 = _slicedToArray(_ref4, 2), quality = _ref5[0], qualityInfo = _ref5[1];
7283
- if (_this6._opts.enableAdaptiveJitterBuffer) {
7284
- targetDelay = _this6._handleJitterBuffer(qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.qualityQos, _this6._opts.adaptiveJitterBuffer, _this6._opts.networkStrategy);
7525
+ stallDuration: videoStallInfo.stall.stallDuration100ms || videoStallInfo.stall.stallDuration500ms
7526
+ }))) !== null && _this7$_networkQualit !== void 0 ? _this7$_networkQualit : [], _ref7 = _slicedToArray(_ref6, 2), quality = _ref7[0], qualityInfo = _ref7[1];
7527
+ if (_this7._opts.enableAdaptiveJitterBuffer) {
7528
+ _this7._handleJitterBuffer(qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.qualityQos, _this7._opts.adaptiveJitterBuffer, _this7._opts.networkStrategy);
7285
7529
  }
7286
- _this6.emit(EXTEND_EVENTS.RTC_NETWORK, {
7530
+ if (videoStats.estimatedPlayoutTimestamp && audioStats.estimatedPlayoutTimestamp) {
7531
+ av_sync_diff = videoStats.estimatedPlayoutTimestamp - audioStats.estimatedPlayoutTimestamp;
7532
+ }
7533
+ _this7.emit(EXTEND_EVENTS.RTC_NETWORK, {
7287
7534
  interval: videoStats.statsInterval,
7288
- visibility_state: document.visibilityState,
7289
7535
  network_quality: quality,
7290
7536
  audio_stall_duration: audioStallInfo.stallDuration,
7291
7537
  audio_stall_count: audioStallInfo.stallCount,
@@ -7310,17 +7556,21 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7310
7556
  quality_qos: qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.qualityQos,
7311
7557
  quality_audio_qoe: qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.audioQoe,
7312
7558
  quality_video_qoe: qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.videoQoe,
7313
- current_delay: _this6._getDelay(),
7314
- target_delay: targetDelay
7559
+ current_delay: _this7._getDelay(),
7560
+ visibility_state: document.visibilityState,
7561
+ target_delay: _this7._targetDelayHint,
7562
+ av_sync_diff,
7563
+ set_delay_error: _this7._setDelayError || null
7315
7564
  });
7316
- case 21:
7317
- _this6._preAudioStats = curAudioStats;
7318
- _this6._preVideoStats = curVideoStats;
7319
- case 23:
7565
+ case 26:
7566
+ _this7._preAudioStats = curAudioStats;
7567
+ _this7._preVideoStats = curVideoStats;
7568
+ _this7.set_delay_error = null;
7569
+ case 29:
7320
7570
  case "end":
7321
- return _context5.stop();
7571
+ return _context7.stop();
7322
7572
  }
7323
- }, _callee5);
7573
+ }, _callee7);
7324
7574
  })), 2e3);
7325
7575
  }
7326
7576
  }, {
@@ -7333,15 +7583,21 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7333
7583
  var validNetworkQualityResult = this._networkQualityResult.filter(Boolean);
7334
7584
  if (validNetworkQualityResult.length === adaptiveJitterBuffer.networkWindow) {
7335
7585
  var _networkStrategy$aver;
7336
- var sorted = _toConsumableArray$1(validNetworkQualityResult).sort(function(a, b) {
7337
- return a - b;
7338
- });
7339
- var mid = Math.floor(sorted.length / 2);
7340
- var averageQuality = sorted.length % 2 !== 0 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2;
7586
+ var averageQuality;
7587
+ if (adaptiveJitterBuffer.windowMethod === "min") {
7588
+ averageQuality = Math.min.apply(Math, _toConsumableArray$1(validNetworkQualityResult));
7589
+ } else if (adaptiveJitterBuffer.windowMethod === "max") {
7590
+ averageQuality = Math.max.apply(Math, _toConsumableArray$1(validNetworkQualityResult));
7591
+ } else {
7592
+ var sorted = _toConsumableArray$1(validNetworkQualityResult).sort(function(a, b) {
7593
+ return a - b;
7594
+ });
7595
+ var mid = Math.floor(sorted.length / 2);
7596
+ averageQuality = sorted.length % 2 !== 0 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2;
7597
+ }
7341
7598
  if (averageQuality && ((_networkStrategy$aver = networkStrategy[averageQuality]) === null || _networkStrategy$aver === void 0 ? void 0 : _networkStrategy$aver.jitterBuffer) !== void 0) {
7342
- var _networkStrategy$aver2, _networkStrategy$aver3;
7343
- this._setDelay((_networkStrategy$aver2 = networkStrategy[averageQuality]) === null || _networkStrategy$aver2 === void 0 ? void 0 : _networkStrategy$aver2.jitterBuffer);
7344
- return (_networkStrategy$aver3 = networkStrategy[averageQuality]) === null || _networkStrategy$aver3 === void 0 ? void 0 : _networkStrategy$aver3.jitterBuffer;
7599
+ var _networkStrategy$aver2;
7600
+ this._startSetDelayLoop((_networkStrategy$aver2 = networkStrategy[averageQuality]) === null || _networkStrategy$aver2 === void 0 ? void 0 : _networkStrategy$aver2.jitterBuffer);
7345
7601
  }
7346
7602
  }
7347
7603
  }
@@ -7355,6 +7611,8 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7355
7611
  this._audioStallObserver = null;
7356
7612
  this._videoStallObserver = null;
7357
7613
  this._networkQuality = null;
7614
+ this._preAudioStats = null;
7615
+ this._preVideoStats = null;
7358
7616
  if (this._rtcReportTimer) {
7359
7617
  clearInterval(this._rtcReportTimer);
7360
7618
  this._rtcReportTimer = 0;
@@ -7367,6 +7625,8 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7367
7625
  (_this$_loader = this._loader) === null || _this$_loader === void 0 ? void 0 : _this$_loader.cancel();
7368
7626
  (_this$_networkEvaluat2 = this._networkEvaluate) === null || _this$_networkEvaluat2 === void 0 ? void 0 : _this$_networkEvaluat2.destroy();
7369
7627
  this._stopRtcReport();
7628
+ clearTimeout(this._checkStatsErrorTimer);
7629
+ this._clearPeerStateTimeout();
7370
7630
  this._audioTransceicer = null;
7371
7631
  this._videoTransceicer = null;
7372
7632
  this._mediaStream = null;
@@ -7377,10 +7637,40 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7377
7637
  value: function _emitError(error) {
7378
7638
  this.emit(EVENT.ERROR, error);
7379
7639
  clearTimeout(this._checkStatsErrorTimer);
7640
+ this._clearPeerStateTimeout();
7380
7641
  if (this._pc) {
7381
7642
  this._pc.close();
7643
+ if (this._media) {
7644
+ this._media.srcObject = null;
7645
+ }
7382
7646
  }
7383
7647
  }
7648
+ }, {
7649
+ key: "_createEmptyPeer",
7650
+ value: function() {
7651
+ var _createEmptyPeer2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee8() {
7652
+ var pc;
7653
+ return _regeneratorRuntime$1().wrap(function _callee8$(_context8) {
7654
+ while (1)
7655
+ switch (_context8.prev = _context8.next) {
7656
+ case 0:
7657
+ pc = new RTCPeerConnection();
7658
+ _context8.next = 3;
7659
+ return pc.createOffer();
7660
+ case 3:
7661
+ pc.close();
7662
+ pc = null;
7663
+ case 5:
7664
+ case "end":
7665
+ return _context8.stop();
7666
+ }
7667
+ }, _callee8);
7668
+ }));
7669
+ function _createEmptyPeer() {
7670
+ return _createEmptyPeer2.apply(this, arguments);
7671
+ }
7672
+ return _createEmptyPeer;
7673
+ }()
7384
7674
  }, {
7385
7675
  key: "destroy",
7386
7676
  value: function destroy(keepClearMediaStream) {
@@ -7521,7 +7811,7 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
7521
7811
  }, {
7522
7812
  key: "version",
7523
7813
  get: function get() {
7524
- return "0.2.1-alpha.30";
7814
+ return "0.2.1-alpha.42";
7525
7815
  }
7526
7816
  }, {
7527
7817
  key: "beforePlayerInit",