@volcengine/veplayer-plugin 2.8.0 → 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,
@@ -4959,6 +4993,7 @@ function getOption(opts) {
4959
4993
  connectionStateChangeTimeout: 5e3,
4960
4994
  enableNetworkQuality: false,
4961
4995
  hackCreateOfferIssue: false,
4996
+ progressiveSetDelay: false,
4962
4997
  networkQuality: {
4963
4998
  networkQos: {
4964
4999
  1: {
@@ -4989,9 +5024,14 @@ function getOption(opts) {
4989
5024
  }
4990
5025
  },
4991
5026
  enableAdaptiveJitterBuffer: false,
4992
- adaptiveJitterBuffer: {
4993
- networkWindow: 3
4994
- },
5027
+ adaptiveJitterBuffer: _objectSpread2$2({
5028
+ networkWindow: 3,
5029
+ windowMethod: "max",
5030
+ loopInterval: 500,
5031
+ maxAvSyncDelay: 400,
5032
+ maxJitterBufferDiff: 500,
5033
+ maxStep: 500
5034
+ }, adaptiveJitterBuffer),
4995
5035
  networkStrategy: {
4996
5036
  1: {
4997
5037
  "jitterBuffer": null
@@ -6440,6 +6480,12 @@ function _getRecvAudioStats() {
6440
6480
  if (stat.fecPacketsReceived !== void 0) {
6441
6481
  currentStats.fecPacketsReceived = stat.fecPacketsReceived;
6442
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
+ }
6443
6489
  } else if (stat.type === "codec") {
6444
6490
  currentStats.recordSampleRate = stat.clockRate;
6445
6491
  if (stat.channels) {
@@ -6467,13 +6513,17 @@ function diffRecvAudioStats(oldStats, newStats) {
6467
6513
  var statsInterval = diffNumber(oldStats, newStats, "timestamp");
6468
6514
  var packetsLostDiff = diffNumber(oldStats, newStats, "packetsLost");
6469
6515
  var jitterBufferDelay = Math.round(diffNumber(oldStats, newStats, "jitterBufferDelay") / diffNumber(oldStats, newStats, "jitterBufferEmittedCount") * 1e3);
6516
+ var packetsReceived = diffNumber(oldStats, newStats, "packetsReceived");
6470
6517
  return {
6471
- audioLossRate: +(packetsLostDiff / (diffNumber(oldStats, newStats, "packetsReceived") + packetsLostDiff)).toFixed(2),
6518
+ audioLossRate: +(packetsLostDiff / (packetsReceived + packetsLostDiff)).toFixed(2),
6472
6519
  receivedKBitrate: +(diffNumber(oldStats, newStats, "bytesReceived") * 8 / statsInterval).toFixed(2),
6473
6520
  statsInterval,
6474
6521
  rtt: newStats.rtt || 0,
6475
6522
  jitterBufferDelay,
6523
+ packetsReceived,
6476
6524
  numChannels: newStats.numChannels || 1,
6525
+ estimatedPlayoutTimestamp: newStats.estimatedPlayoutTimestamp,
6526
+ samplesDuration: Math.round(diffNumber(oldStats, newStats, "totalSamplesDuration") * 1e3),
6477
6527
  receivedSampleRate: diffNumber(oldStats, newStats, "totalSamplesReceived") / statsInterval,
6478
6528
  concealedSamples: Math.round(diffNumber(oldStats, newStats, "concealedSamples")),
6479
6529
  concealmentEvent: Math.round(diffNumber(oldStats, newStats, "concealmentEvents")),
@@ -6517,6 +6567,9 @@ function _getRecvVideoStats() {
6517
6567
  currentStats.width = stat.frameWidth;
6518
6568
  currentStats.height = stat.frameHeight;
6519
6569
  }
6570
+ if (stat.estimatedPlayoutTimestamp !== void 0) {
6571
+ currentStats.estimatedPlayoutTimestamp = stat.estimatedPlayoutTimestamp;
6572
+ }
6520
6573
  } else if (stat.type === "track" && stat.frameWidth !== void 0) {
6521
6574
  currentStats.width = stat.frameWidth;
6522
6575
  currentStats.height = stat.frameHeight;
@@ -6549,6 +6602,7 @@ function diffRecvVideoStats(oldStats, newStats) {
6549
6602
  statsInterval,
6550
6603
  width: newStats.width || 0,
6551
6604
  height: newStats.height || 0,
6605
+ estimatedPlayoutTimestamp: newStats.estimatedPlayoutTimestamp,
6552
6606
  videoLossRate: +(packetsLostDiff / (diffNumber(oldStats, newStats, "packetsReceived") + packetsLostDiff)),
6553
6607
  receivedKBitrate: +(diffNumber(oldStats, newStats, "bytesReceived") * 8 / statsInterval).toFixed(2),
6554
6608
  decoderOutputFrameRate: Math.round(diffNumber(oldStats, newStats, "framesDecoded") * 1e3 / statsInterval),
@@ -6806,33 +6860,165 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
6806
6860
  });
6807
6861
  });
6808
6862
  _defineProperty$2(_assertThisInitialized$1(_this), "_setDelay", function(delayHint) {
6809
- var videoDelaySync = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
6810
- var currentDelay = _this._getDelay();
6811
- delayHint = typeof delayHint === "number" && delayHint > 0 ? delayHint : null;
6812
- if (currentDelay === delayHint)
6813
- return;
6814
- try {
6815
- var videoReceiver = _this._videoTransceicer.receiver;
6816
- var audioReceiver = _this._audioTransceicer.receiver;
6863
+ if (_this._opts.progressiveSetDelay) {
6864
+ _this._startSetDelayLoop(delayHint);
6865
+ } else {
6866
+ var _this$_audioTransceic2;
6817
6867
  var key = [
6818
6868
  "playoutDelayHint",
6819
6869
  "jitterBufferDelayHint",
6820
6870
  "jitterBufferTarget"
6821
6871
  ].find(function(key2) {
6822
- 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);
6823
6874
  });
6824
- if (key) {
6825
- audioReceiver[key] = delayHint;
6826
- if (!videoDelaySync) {
6827
- videoReceiver[key] = delayHint;
6828
- logger.log("set videoReceiver.".concat(key, " = ").concat(delayHint));
6829
- }
6830
- logger.log("set audioReceiver.".concat(key, " = ").concat(delayHint));
6831
- }
6832
- } catch (error) {
6833
- 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;
6834
6882
  }
6835
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
+ }());
6836
7022
  _defineProperty$2(_assertThisInitialized$1(_this), "_getDelay", function() {
6837
7023
  try {
6838
7024
  var key = ["playoutDelayHint", "jitterBufferDelayHint", "jitterBufferTarget"].find(function(key2) {
@@ -6908,51 +7094,51 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
6908
7094
  }, {
6909
7095
  key: "load",
6910
7096
  value: function() {
6911
- var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee3(url) {
7097
+ var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee5(url) {
6912
7098
  var _this2 = this;
6913
- var lastPc, encodedTransformSupported;
6914
- return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
7099
+ var encodedTransformSupported, lastPc;
7100
+ return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
6915
7101
  while (1)
6916
- switch (_context3.prev = _context3.next) {
7102
+ switch (_context5.prev = _context5.next) {
6917
7103
  case 0:
6918
7104
  this._disconnect();
6919
7105
  this._url = url;
6920
7106
  this._retry = this._opts.retryCount;
6921
- lastPc = this._pc;
6922
- if (lastPc) {
6923
- lastPc.close();
6924
- }
6925
- encodedTransformSupported = isLegacyEncodedTransformSupported();
6926
- _context3.prev = 6;
6927
7107
  if (!this._opts.hackCreateOfferIssue) {
6928
- _context3.next = 10;
7108
+ _context5.next = 6;
6929
7109
  break;
6930
7110
  }
6931
- _context3.next = 10;
7111
+ _context5.next = 6;
6932
7112
  return this._createEmptyPeer();
6933
- case 10:
7113
+ case 6:
7114
+ encodedTransformSupported = isLegacyEncodedTransformSupported();
7115
+ _context5.prev = 7;
7116
+ lastPc = this._pc;
7117
+ if (lastPc) {
7118
+ lastPc.close();
7119
+ }
6934
7120
  this._pc = new RTCPeerConnection({
6935
7121
  encodedInsertableStreams: encodedTransformSupported && this._opts.enableSei ? true : void 0
6936
7122
  });
6937
7123
  this._bindRTCEvents();
6938
- _context3.next = 14;
7124
+ _context5.next = 14;
6939
7125
  return this._connect(url);
6940
7126
  case 14:
6941
- _context3.next = 19;
7127
+ _context5.next = 19;
6942
7128
  break;
6943
7129
  case 16:
6944
- _context3.prev = 16;
6945
- _context3.t0 = _context3["catch"](6);
7130
+ _context5.prev = 16;
7131
+ _context5.t0 = _context5["catch"](7);
6946
7132
  setTimeout(function() {
6947
- return _this2._emitError(StreamingError.create(ERR.OTHER, null, _context3.t0));
7133
+ return _this2._emitError(StreamingError.create(ERR.OTHER, null, _context5.t0));
6948
7134
  });
6949
7135
  case 19:
6950
7136
  case "end":
6951
- return _context3.stop();
7137
+ return _context5.stop();
6952
7138
  }
6953
- }, _callee3, this, [[6, 16]]);
7139
+ }, _callee5, this, [[7, 16]]);
6954
7140
  }));
6955
- function load(_x) {
7141
+ function load(_x2) {
6956
7142
  return _load.apply(this, arguments);
6957
7143
  }
6958
7144
  return load;
@@ -7090,15 +7276,15 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7090
7276
  }, {
7091
7277
  key: "_connect",
7092
7278
  value: function() {
7093
- var _connect2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee4() {
7279
+ var _connect2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee6() {
7094
7280
  var pc, offer, parsed, finnalUrl, _this$_opts, _answer$remoteSdp, _this$_opts2, _answer$remoteSdp2, _parsed$media, parseSession, sessionId, reqStart, res, answer, err, _parsed;
7095
- return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
7281
+ return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
7096
7282
  while (1)
7097
- switch (_context4.prev = _context4.next) {
7283
+ switch (_context6.prev = _context6.next) {
7098
7284
  case 0:
7099
7285
  pc = this._pc;
7100
7286
  if (!pc.addTransceiver) {
7101
- _context4.next = 11;
7287
+ _context6.next = 11;
7102
7288
  break;
7103
7289
  }
7104
7290
  this._audioTransceicer = pc.addTransceiver("audio", {
@@ -7107,26 +7293,26 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7107
7293
  this._videoTransceicer = pc.addTransceiver("video", {
7108
7294
  direction: "recvonly"
7109
7295
  });
7110
- this._opts.delayHint !== void 0 && this._setDelay(this._opts.delayHint, this._opts.videoDelaySync);
7296
+ this._setDelay(this._opts.delayHint);
7111
7297
  if (this._opts.enableSei) {
7112
7298
  this.initVideoEncodedTransform();
7113
7299
  this.initAudioEncodedTransform();
7114
7300
  }
7115
- _context4.next = 8;
7301
+ _context6.next = 8;
7116
7302
  return pc.createOffer();
7117
7303
  case 8:
7118
- offer = _context4.sent;
7119
- _context4.next = 14;
7304
+ offer = _context6.sent;
7305
+ _context6.next = 14;
7120
7306
  break;
7121
7307
  case 11:
7122
- _context4.next = 13;
7308
+ _context6.next = 13;
7123
7309
  return pc.createOffer({
7124
7310
  iceRestart: true,
7125
7311
  offerToReceiveAudio: true,
7126
7312
  offerToReceiveVideo: true
7127
7313
  });
7128
7314
  case 13:
7129
- offer = _context4.sent;
7315
+ offer = _context6.sent;
7130
7316
  case 14:
7131
7317
  if (this._opts.hackCreateOfferIssue) {
7132
7318
  this._createEmptyPeer();
@@ -7155,11 +7341,11 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7155
7341
  });
7156
7342
  offer.sdp = lib.write(parsed);
7157
7343
  logger.log("local offer modified:\n", offer.sdp);
7158
- _context4.next = 23;
7344
+ _context6.next = 23;
7159
7345
  return pc.setLocalDescription(offer);
7160
7346
  case 23:
7161
7347
  finnalUrl = this._url;
7162
- _context4.prev = 24;
7348
+ _context6.prev = 24;
7163
7349
  if (this._opts.preProcessUrl) {
7164
7350
  finnalUrl = this._opts.preProcessUrl(finnalUrl).url;
7165
7351
  }
@@ -7172,7 +7358,7 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7172
7358
  sessionId
7173
7359
  });
7174
7360
  reqStart = Date.now();
7175
- _context4.next = 33;
7361
+ _context6.next = 33;
7176
7362
  return this._loader.load(finnalUrl, {
7177
7363
  body: JSON.stringify({
7178
7364
  sessionId,
@@ -7181,22 +7367,22 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7181
7367
  })
7182
7368
  });
7183
7369
  case 33:
7184
- res = _context4.sent;
7370
+ res = _context6.sent;
7185
7371
  this.emit(EVENT.LOAD_RESPONSE_HEADERS, {
7186
7372
  headers: res.response.headers
7187
7373
  });
7188
7374
  answer = res === null || res === void 0 ? void 0 : res.data;
7189
7375
  if (!((answer === null || answer === void 0 ? void 0 : answer.code) === 404 || (answer === null || answer === void 0 ? void 0 : answer.code) === 403)) {
7190
- _context4.next = 41;
7376
+ _context6.next = 41;
7191
7377
  break;
7192
7378
  }
7193
7379
  err = StreamingError.create(answer.code === 404 ? ERR.NETWORK_NOTFOUND : ERR.NETWORK_FORBIDDEN, null, answer);
7194
7380
  err.errorType = ERR.NETWORK;
7195
7381
  this._emitError(err);
7196
- return _context4.abrupt("return");
7382
+ return _context6.abrupt("return");
7197
7383
  case 41:
7198
7384
  if (!((answer === null || answer === void 0 ? void 0 : answer.code) !== 200)) {
7199
- _context4.next = 43;
7385
+ _context6.next = 43;
7200
7386
  break;
7201
7387
  }
7202
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));
@@ -7229,22 +7415,28 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7229
7415
  answer.remoteSdp.sdp = lib.write(_parsed);
7230
7416
  logger.log("answer modified:\n", answer.remoteSdp.sdp);
7231
7417
  this._rctConnectStartTs = Date.now();
7232
- _context4.next = 53;
7233
- return this._pc.setRemoteDescription(answer.remoteSdp);
7418
+ if (!(pc.signalingState === "closed")) {
7419
+ _context6.next = 53;
7420
+ break;
7421
+ }
7422
+ return _context6.abrupt("return");
7234
7423
  case 53:
7424
+ _context6.next = 55;
7425
+ return pc.setRemoteDescription(answer.remoteSdp);
7426
+ case 55:
7235
7427
  this._networkEvaluate = new NetworkEvaluate(pc, this._opts.networkEvaluateInterval);
7236
7428
  this._listenPeerStateTimeout();
7237
- _context4.next = 60;
7429
+ _context6.next = 62;
7238
7430
  break;
7239
- case 57:
7240
- _context4.prev = 57;
7241
- _context4.t0 = _context4["catch"](24);
7242
- this._emitError(StreamingError.network(_context4.t0));
7243
- case 60:
7431
+ case 59:
7432
+ _context6.prev = 59;
7433
+ _context6.t0 = _context6["catch"](24);
7434
+ this._emitError(StreamingError.network(_context6.t0));
7435
+ case 62:
7244
7436
  case "end":
7245
- return _context4.stop();
7437
+ return _context6.stop();
7246
7438
  }
7247
- }, _callee4, this, [[24, 57]]);
7439
+ }, _callee6, this, [[24, 59]]);
7248
7440
  }));
7249
7441
  function _connect() {
7250
7442
  return _connect2.apply(this, arguments);
@@ -7275,12 +7467,21 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7275
7467
  value: function _startRtcReport() {
7276
7468
  var _this7 = this;
7277
7469
  this._stopRtcReport();
7278
- this._rtcReportTimer = setInterval(/* @__PURE__ */ _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee5() {
7279
- var _yield$Promise$all, _yield$Promise$all2, curAudioStats, curVideoStats, _this7$_audioStallObs, _this7$_videoStallObs, _this7$_networkQualit, _this7$_networkQualit2, audioStats, videoStats, audioStallInfo, videoStallInfo, _ref4, _ref5, quality, qualityInfo, targetDelay;
7280
- 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) {
7281
7474
  while (1)
7282
- switch (_context5.prev = _context5.next) {
7475
+ switch (_context7.prev = _context7.next) {
7283
7476
  case 0:
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;
7480
+ }
7481
+ _this7._preAudioStats = null;
7482
+ _this7._preVideoStats = null;
7483
+ return _context7.abrupt("return");
7484
+ case 4:
7284
7485
  if (!_this7._audioStallObserver && _this7._audioTransceicer) {
7285
7486
  _this7._audioStallObserver = new AudioStallObserver();
7286
7487
  _this7._audioStallObserver.start(_this7._audioTransceicer);
@@ -7292,43 +7493,45 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7292
7493
  if (!_this7._networkQuality && _this7._opts.enableNetworkQuality) {
7293
7494
  _this7._networkQuality = new NetworkQuality(_this7._pc, _this7._opts.networkQuality);
7294
7495
  }
7295
- _context5.next = 5;
7496
+ _context7.next = 9;
7296
7497
  return Promise.all([getRecvAudioStats(_this7._audioTransceicer.receiver.getStats()), getRecvVideoStats(_this7._videoTransceicer.receiver.getStats())]);
7297
- case 5:
7298
- _yield$Promise$all = _context5.sent;
7299
- _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
7300
- curAudioStats = _yield$Promise$all2[0];
7301
- curVideoStats = _yield$Promise$all2[1];
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];
7302
7503
  if (!(_this7._preAudioStats && _this7._preVideoStats)) {
7303
- _context5.next = 21;
7504
+ _context7.next = 26;
7304
7505
  break;
7305
7506
  }
7306
7507
  audioStats = diffRecvAudioStats(_this7._preAudioStats, curAudioStats);
7307
7508
  videoStats = diffRecvVideoStats(_this7._preVideoStats, curVideoStats);
7308
- _context5.next = 14;
7509
+ _context7.next = 18;
7309
7510
  return (_this7$_audioStallObs = _this7._audioStallObserver) === null || _this7$_audioStallObs === void 0 ? void 0 : _this7$_audioStallObs.getAudioStallInfo();
7310
- case 14:
7311
- audioStallInfo = _context5.sent;
7312
- _context5.next = 17;
7511
+ case 18:
7512
+ audioStallInfo = _context7.sent;
7513
+ _context7.next = 21;
7313
7514
  return (_this7$_videoStallObs = _this7._videoStallObserver) === null || _this7$_videoStallObs === void 0 ? void 0 : _this7$_videoStallObs.getStallInfo({
7314
7515
  interval: videoStats.statsInterval,
7315
7516
  frameRateReceived: videoStats.frameRateReceived,
7316
7517
  frameRateDecoded: videoStats.frameRateDecoded,
7317
7518
  bitrate: videoStats.receivedKBitrate
7318
7519
  });
7319
- case 17:
7320
- videoStallInfo = _context5.sent;
7321
- _ref4 = (_this7$_networkQualit = (_this7$_networkQualit2 = _this7._networkQuality) === null || _this7$_networkQualit2 === void 0 ? void 0 : _this7$_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), {}, {
7322
7523
  stallDuration: audioStallInfo.stallDuration
7323
7524
  }), _objectSpread2$2(_objectSpread2$2({}, videoStats), {}, {
7324
- stallDuration: videoStallInfo.stall.stallDuration100ms
7325
- }))) !== null && _this7$_networkQualit !== void 0 ? _this7$_networkQualit : [], _ref5 = _slicedToArray(_ref4, 2), quality = _ref5[0], qualityInfo = _ref5[1];
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];
7326
7527
  if (_this7._opts.enableAdaptiveJitterBuffer) {
7327
- targetDelay = _this7._handleJitterBuffer(qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.qualityQos, _this7._opts.adaptiveJitterBuffer, _this7._opts.networkStrategy);
7528
+ _this7._handleJitterBuffer(qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.qualityQos, _this7._opts.adaptiveJitterBuffer, _this7._opts.networkStrategy);
7529
+ }
7530
+ if (videoStats.estimatedPlayoutTimestamp && audioStats.estimatedPlayoutTimestamp) {
7531
+ av_sync_diff = videoStats.estimatedPlayoutTimestamp - audioStats.estimatedPlayoutTimestamp;
7328
7532
  }
7329
7533
  _this7.emit(EXTEND_EVENTS.RTC_NETWORK, {
7330
7534
  interval: videoStats.statsInterval,
7331
- visibility_state: document.visibilityState,
7332
7535
  network_quality: quality,
7333
7536
  audio_stall_duration: audioStallInfo.stallDuration,
7334
7537
  audio_stall_count: audioStallInfo.stallCount,
@@ -7354,16 +7557,20 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7354
7557
  quality_audio_qoe: qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.audioQoe,
7355
7558
  quality_video_qoe: qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.videoQoe,
7356
7559
  current_delay: _this7._getDelay(),
7357
- target_delay: targetDelay
7560
+ visibility_state: document.visibilityState,
7561
+ target_delay: _this7._targetDelayHint,
7562
+ av_sync_diff,
7563
+ set_delay_error: _this7._setDelayError || null
7358
7564
  });
7359
- case 21:
7565
+ case 26:
7360
7566
  _this7._preAudioStats = curAudioStats;
7361
7567
  _this7._preVideoStats = curVideoStats;
7362
- case 23:
7568
+ _this7.set_delay_error = null;
7569
+ case 29:
7363
7570
  case "end":
7364
- return _context5.stop();
7571
+ return _context7.stop();
7365
7572
  }
7366
- }, _callee5);
7573
+ }, _callee7);
7367
7574
  })), 2e3);
7368
7575
  }
7369
7576
  }, {
@@ -7376,15 +7583,21 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7376
7583
  var validNetworkQualityResult = this._networkQualityResult.filter(Boolean);
7377
7584
  if (validNetworkQualityResult.length === adaptiveJitterBuffer.networkWindow) {
7378
7585
  var _networkStrategy$aver;
7379
- var sorted = _toConsumableArray$1(validNetworkQualityResult).sort(function(a, b) {
7380
- return a - b;
7381
- });
7382
- var mid = Math.floor(sorted.length / 2);
7383
- 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
+ }
7384
7598
  if (averageQuality && ((_networkStrategy$aver = networkStrategy[averageQuality]) === null || _networkStrategy$aver === void 0 ? void 0 : _networkStrategy$aver.jitterBuffer) !== void 0) {
7385
- var _networkStrategy$aver2, _networkStrategy$aver3;
7386
- this._setDelay((_networkStrategy$aver2 = networkStrategy[averageQuality]) === null || _networkStrategy$aver2 === void 0 ? void 0 : _networkStrategy$aver2.jitterBuffer);
7387
- 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);
7388
7601
  }
7389
7602
  }
7390
7603
  }
@@ -7398,6 +7611,8 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7398
7611
  this._audioStallObserver = null;
7399
7612
  this._videoStallObserver = null;
7400
7613
  this._networkQuality = null;
7614
+ this._preAudioStats = null;
7615
+ this._preVideoStats = null;
7401
7616
  if (this._rtcReportTimer) {
7402
7617
  clearInterval(this._rtcReportTimer);
7403
7618
  this._rtcReportTimer = 0;
@@ -7425,28 +7640,31 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
7425
7640
  this._clearPeerStateTimeout();
7426
7641
  if (this._pc) {
7427
7642
  this._pc.close();
7643
+ if (this._media) {
7644
+ this._media.srcObject = null;
7645
+ }
7428
7646
  }
7429
7647
  }
7430
7648
  }, {
7431
7649
  key: "_createEmptyPeer",
7432
7650
  value: function() {
7433
- var _createEmptyPeer2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee6() {
7651
+ var _createEmptyPeer2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee8() {
7434
7652
  var pc;
7435
- return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
7653
+ return _regeneratorRuntime$1().wrap(function _callee8$(_context8) {
7436
7654
  while (1)
7437
- switch (_context6.prev = _context6.next) {
7655
+ switch (_context8.prev = _context8.next) {
7438
7656
  case 0:
7439
7657
  pc = new RTCPeerConnection();
7440
- _context6.next = 3;
7658
+ _context8.next = 3;
7441
7659
  return pc.createOffer();
7442
7660
  case 3:
7443
7661
  pc.close();
7444
7662
  pc = null;
7445
7663
  case 5:
7446
7664
  case "end":
7447
- return _context6.stop();
7665
+ return _context8.stop();
7448
7666
  }
7449
- }, _callee6);
7667
+ }, _callee8);
7450
7668
  }));
7451
7669
  function _createEmptyPeer() {
7452
7670
  return _createEmptyPeer2.apply(this, arguments);
@@ -7593,7 +7811,7 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
7593
7811
  }, {
7594
7812
  key: "version",
7595
7813
  get: function get() {
7596
- return "0.2.1-alpha.35";
7814
+ return "0.2.1-alpha.42";
7597
7815
  }
7598
7816
  }, {
7599
7817
  key: "beforePlayerInit",