@byteplus/veplayer-plugin 2.8.0 → 2.8.1

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.
@@ -23137,7 +23137,7 @@ function _wrapNativeSuper$4(Class) {
23137
23137
  };
23138
23138
  return _wrapNativeSuper$4(Class);
23139
23139
  }
23140
- function _objectWithoutPropertiesLoose$5(source, excluded) {
23140
+ function _objectWithoutPropertiesLoose$6(source, excluded) {
23141
23141
  if (source == null)
23142
23142
  return {};
23143
23143
  var target = {};
@@ -23151,10 +23151,10 @@ function _objectWithoutPropertiesLoose$5(source, excluded) {
23151
23151
  }
23152
23152
  return target;
23153
23153
  }
23154
- function _objectWithoutProperties$5(source, excluded) {
23154
+ function _objectWithoutProperties$6(source, excluded) {
23155
23155
  if (source == null)
23156
23156
  return {};
23157
- var target = _objectWithoutPropertiesLoose$5(source, excluded);
23157
+ var target = _objectWithoutPropertiesLoose$6(source, excluded);
23158
23158
  var key2, i2;
23159
23159
  if (Object.getOwnPropertySymbols) {
23160
23160
  var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
@@ -25373,7 +25373,7 @@ var XhrLoader$3 = /* @__PURE__ */ function(_EventEmitter) {
25373
25373
  }]);
25374
25374
  return XhrLoader2;
25375
25375
  }(EventEmitter$1);
25376
- var _excluded$6 = ["retry", "retryDelay", "onRetryError", "transformError"];
25376
+ var _excluded$7 = ["retry", "retryDelay", "onRetryError", "transformError"];
25377
25377
  var Task$3 = /* @__PURE__ */ function() {
25378
25378
  function Task2(type, config2) {
25379
25379
  _classCallCheck$n(this, Task2);
@@ -25393,7 +25393,7 @@ var Task$3 = /* @__PURE__ */ function() {
25393
25393
  key: "exec",
25394
25394
  value: function exec2() {
25395
25395
  var _this = this;
25396
- var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties$5(_this$_config, _excluded$6);
25396
+ var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties$6(_this$_config, _excluded$7);
25397
25397
  var request2 = /* @__PURE__ */ function() {
25398
25398
  var _ref6 = _asyncToGenerator$b(/* @__PURE__ */ _regeneratorRuntime$b().mark(function _callee() {
25399
25399
  var response, error, isRetry;
@@ -48312,6 +48312,38 @@ function _isNativeReflectConstruct$f() {
48312
48312
  return false;
48313
48313
  }
48314
48314
  }
48315
+ function _objectWithoutPropertiesLoose$5(source, excluded) {
48316
+ if (source == null)
48317
+ return {};
48318
+ var target = {};
48319
+ var sourceKeys = Object.keys(source);
48320
+ var key2, i2;
48321
+ for (i2 = 0; i2 < sourceKeys.length; i2++) {
48322
+ key2 = sourceKeys[i2];
48323
+ if (excluded.indexOf(key2) >= 0)
48324
+ continue;
48325
+ target[key2] = source[key2];
48326
+ }
48327
+ return target;
48328
+ }
48329
+ function _objectWithoutProperties$5(source, excluded) {
48330
+ if (source == null)
48331
+ return {};
48332
+ var target = _objectWithoutPropertiesLoose$5(source, excluded);
48333
+ var key2, i2;
48334
+ if (Object.getOwnPropertySymbols) {
48335
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
48336
+ for (i2 = 0; i2 < sourceSymbolKeys.length; i2++) {
48337
+ key2 = sourceSymbolKeys[i2];
48338
+ if (excluded.indexOf(key2) >= 0)
48339
+ continue;
48340
+ if (!Object.prototype.propertyIsEnumerable.call(source, key2))
48341
+ continue;
48342
+ target[key2] = source[key2];
48343
+ }
48344
+ }
48345
+ return target;
48346
+ }
48315
48347
  function _assertThisInitialized$f(self2) {
48316
48348
  if (self2 === void 0) {
48317
48349
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
@@ -50311,7 +50343,7 @@ var XhrLoader$2 = /* @__PURE__ */ function(_EventEmitter) {
50311
50343
  }]);
50312
50344
  return XhrLoader2;
50313
50345
  }(EventEmitter$1);
50314
- var _excluded$5 = ["retry", "retryDelay", "onRetryError", "transformError"];
50346
+ var _excluded$6 = ["retry", "retryDelay", "onRetryError", "transformError"];
50315
50347
  var Task$2 = /* @__PURE__ */ function() {
50316
50348
  function Task2(type, config2) {
50317
50349
  _classCallCheck$j(this, Task2);
@@ -50331,7 +50363,7 @@ var Task$2 = /* @__PURE__ */ function() {
50331
50363
  key: "exec",
50332
50364
  value: function exec2() {
50333
50365
  var _this = this;
50334
- var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties$4(_this$_config, _excluded$5);
50366
+ var _this$_config = this._config, retry = _this$_config.retry, retryDelay = _this$_config.retryDelay, onRetryError = _this$_config.onRetryError, transformError = _this$_config.transformError, rest = _objectWithoutProperties$4(_this$_config, _excluded$6);
50335
50367
  var request2 = /* @__PURE__ */ function() {
50336
50368
  var _ref6 = _asyncToGenerator$9(/* @__PURE__ */ _regeneratorRuntime$9().mark(function _callee() {
50337
50369
  var response, error, isRetry;
@@ -51247,7 +51279,9 @@ lib$1.parsePayloads = parser.parsePayloads;
51247
51279
  lib$1.parseRemoteCandidates = parser.parseRemoteCandidates;
51248
51280
  lib$1.parseImageAttributes = parser.parseImageAttributes;
51249
51281
  lib$1.parseSimulcastStreamList = parser.parseSimulcastStreamList;
51250
- function getOption(opts) {
51282
+ var _excluded$5 = ["adaptiveJitterBuffer"];
51283
+ function getOption(options) {
51284
+ var _ref6 = options || {}, _ref$adaptiveJitterBu = _ref6.adaptiveJitterBuffer, adaptiveJitterBuffer = _ref$adaptiveJitterBu === void 0 ? {} : _ref$adaptiveJitterBu, opts = _objectWithoutProperties$5(_ref6, _excluded$5);
51251
51285
  return _objectSpread2$a({
51252
51286
  retryCount: 0,
51253
51287
  retryDelay: 1e3,
@@ -51263,6 +51297,7 @@ function getOption(opts) {
51263
51297
  connectionStateChangeTimeout: 5e3,
51264
51298
  enableNetworkQuality: false,
51265
51299
  hackCreateOfferIssue: false,
51300
+ progressiveSetDelay: false,
51266
51301
  networkQuality: {
51267
51302
  networkQos: {
51268
51303
  1: {
@@ -51293,9 +51328,14 @@ function getOption(opts) {
51293
51328
  }
51294
51329
  },
51295
51330
  enableAdaptiveJitterBuffer: false,
51296
- adaptiveJitterBuffer: {
51297
- networkWindow: 3
51298
- },
51331
+ adaptiveJitterBuffer: _objectSpread2$a({
51332
+ networkWindow: 3,
51333
+ windowMethod: "max",
51334
+ loopInterval: 500,
51335
+ maxAvSyncDelay: 400,
51336
+ maxJitterBufferDiff: 500,
51337
+ maxStep: 500
51338
+ }, adaptiveJitterBuffer),
51299
51339
  networkStrategy: {
51300
51340
  1: {
51301
51341
  "jitterBuffer": null
@@ -52744,6 +52784,12 @@ function _getRecvAudioStats() {
52744
52784
  if (stat.fecPacketsReceived !== void 0) {
52745
52785
  currentStats.fecPacketsReceived = stat.fecPacketsReceived;
52746
52786
  }
52787
+ if (stat.estimatedPlayoutTimestamp !== void 0) {
52788
+ currentStats.estimatedPlayoutTimestamp = stat.estimatedPlayoutTimestamp;
52789
+ }
52790
+ if (stat.totalSamplesDuration !== void 0) {
52791
+ currentStats.totalSamplesDuration = stat.totalSamplesDuration;
52792
+ }
52747
52793
  } else if (stat.type === "codec") {
52748
52794
  currentStats.recordSampleRate = stat.clockRate;
52749
52795
  if (stat.channels) {
@@ -52771,13 +52817,17 @@ function diffRecvAudioStats(oldStats, newStats) {
52771
52817
  var statsInterval = diffNumber(oldStats, newStats, "timestamp");
52772
52818
  var packetsLostDiff = diffNumber(oldStats, newStats, "packetsLost");
52773
52819
  var jitterBufferDelay = Math.round(diffNumber(oldStats, newStats, "jitterBufferDelay") / diffNumber(oldStats, newStats, "jitterBufferEmittedCount") * 1e3);
52820
+ var packetsReceived = diffNumber(oldStats, newStats, "packetsReceived");
52774
52821
  return {
52775
- audioLossRate: +(packetsLostDiff / (diffNumber(oldStats, newStats, "packetsReceived") + packetsLostDiff)).toFixed(2),
52822
+ audioLossRate: +(packetsLostDiff / (packetsReceived + packetsLostDiff)).toFixed(2),
52776
52823
  receivedKBitrate: +(diffNumber(oldStats, newStats, "bytesReceived") * 8 / statsInterval).toFixed(2),
52777
52824
  statsInterval,
52778
52825
  rtt: newStats.rtt || 0,
52779
52826
  jitterBufferDelay,
52827
+ packetsReceived,
52780
52828
  numChannels: newStats.numChannels || 1,
52829
+ estimatedPlayoutTimestamp: newStats.estimatedPlayoutTimestamp,
52830
+ samplesDuration: Math.round(diffNumber(oldStats, newStats, "totalSamplesDuration") * 1e3),
52781
52831
  receivedSampleRate: diffNumber(oldStats, newStats, "totalSamplesReceived") / statsInterval,
52782
52832
  concealedSamples: Math.round(diffNumber(oldStats, newStats, "concealedSamples")),
52783
52833
  concealmentEvent: Math.round(diffNumber(oldStats, newStats, "concealmentEvents")),
@@ -52821,6 +52871,9 @@ function _getRecvVideoStats() {
52821
52871
  currentStats.width = stat.frameWidth;
52822
52872
  currentStats.height = stat.frameHeight;
52823
52873
  }
52874
+ if (stat.estimatedPlayoutTimestamp !== void 0) {
52875
+ currentStats.estimatedPlayoutTimestamp = stat.estimatedPlayoutTimestamp;
52876
+ }
52824
52877
  } else if (stat.type === "track" && stat.frameWidth !== void 0) {
52825
52878
  currentStats.width = stat.frameWidth;
52826
52879
  currentStats.height = stat.frameHeight;
@@ -52853,6 +52906,7 @@ function diffRecvVideoStats(oldStats, newStats) {
52853
52906
  statsInterval,
52854
52907
  width: newStats.width || 0,
52855
52908
  height: newStats.height || 0,
52909
+ estimatedPlayoutTimestamp: newStats.estimatedPlayoutTimestamp,
52856
52910
  videoLossRate: +(packetsLostDiff / (diffNumber(oldStats, newStats, "packetsReceived") + packetsLostDiff)),
52857
52911
  receivedKBitrate: +(diffNumber(oldStats, newStats, "bytesReceived") * 8 / statsInterval).toFixed(2),
52858
52912
  decoderOutputFrameRate: Math.round(diffNumber(oldStats, newStats, "framesDecoded") * 1e3 / statsInterval),
@@ -53110,33 +53164,165 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
53110
53164
  });
53111
53165
  });
53112
53166
  _defineProperty$h(_assertThisInitialized$f(_this), "_setDelay", function(delayHint) {
53113
- var videoDelaySync = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
53114
- var currentDelay = _this._getDelay();
53115
- delayHint = typeof delayHint === "number" && delayHint > 0 ? delayHint : null;
53116
- if (currentDelay === delayHint)
53117
- return;
53118
- try {
53119
- var videoReceiver = _this._videoTransceicer.receiver;
53120
- var audioReceiver = _this._audioTransceicer.receiver;
53167
+ if (_this._opts.progressiveSetDelay) {
53168
+ _this._startSetDelayLoop(delayHint);
53169
+ } else {
53170
+ var _this$_audioTransceic2;
53121
53171
  var key2 = [
53122
53172
  "playoutDelayHint",
53123
53173
  "jitterBufferDelayHint",
53124
53174
  "jitterBufferTarget"
53125
53175
  ].find(function(key22) {
53126
- return key22 in videoReceiver && key22 in audioReceiver;
53176
+ var _this$_audioTransceic, _this$_videoTransceic;
53177
+ return key22 in ((_this$_audioTransceic = _this._audioTransceicer) === null || _this$_audioTransceic === void 0 ? void 0 : _this$_audioTransceic.receiver) && key22 in ((_this$_videoTransceic = _this._videoTransceicer) === null || _this$_videoTransceic === void 0 ? void 0 : _this$_videoTransceic.receiver);
53127
53178
  });
53128
- if (key2) {
53129
- audioReceiver[key2] = delayHint;
53130
- if (!videoDelaySync) {
53131
- videoReceiver[key2] = delayHint;
53132
- logger$a.log("set videoReceiver.".concat(key2, " = ").concat(delayHint));
53133
- }
53134
- logger$a.log("set audioReceiver.".concat(key2, " = ").concat(delayHint));
53135
- }
53136
- } catch (error) {
53137
- logger$a.error("set delay error", error);
53179
+ if (!key2)
53180
+ return;
53181
+ delayHint = typeof delayHint === "number" && delayHint > 0 ? delayHint : null;
53182
+ if (((_this$_audioTransceic2 = _this._audioTransceicer) === null || _this$_audioTransceic2 === void 0 ? void 0 : _this$_audioTransceic2.receiver[key2]) === delayHint)
53183
+ return;
53184
+ _this._audioTransceicer.receiver[key2] = delayHint;
53185
+ _this._videoTransceicer.receiver[key2] = delayHint;
53138
53186
  }
53139
53187
  });
53188
+ _defineProperty$h(_assertThisInitialized$f(_this), "_targetDelayHint", null);
53189
+ _defineProperty$h(_assertThisInitialized$f(_this), "_setDelayTimer", null);
53190
+ _defineProperty$h(_assertThisInitialized$f(_this), "_setDelayError", null);
53191
+ _defineProperty$h(_assertThisInitialized$f(_this), "_startSetDelayLoop", /* @__PURE__ */ function() {
53192
+ var _ref32 = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee4(delayHint) {
53193
+ var key2, preAudioStats, preVideoStats, _this$_opts$adaptiveJ, loopInterval, maxAvSyncDelay, maxJitterBufferDiff, maxStep, avDiffTooMuchCount;
53194
+ return _regeneratorRuntime$a().wrap(function _callee4$(_context4) {
53195
+ while (1)
53196
+ switch (_context4.prev = _context4.next) {
53197
+ case 0:
53198
+ key2 = [
53199
+ "playoutDelayHint",
53200
+ "jitterBufferDelayHint",
53201
+ "jitterBufferTarget"
53202
+ ].find(function(key22) {
53203
+ var _this$_audioTransceic3, _this$_videoTransceic2;
53204
+ return key22 in ((_this$_audioTransceic3 = _this._audioTransceicer) === null || _this$_audioTransceic3 === void 0 ? void 0 : _this$_audioTransceic3.receiver) && key22 in ((_this$_videoTransceic2 = _this._videoTransceicer) === null || _this$_videoTransceic2 === void 0 ? void 0 : _this$_videoTransceic2.receiver);
53205
+ });
53206
+ if (key2) {
53207
+ _context4.next = 3;
53208
+ break;
53209
+ }
53210
+ return _context4.abrupt("return");
53211
+ case 3:
53212
+ delayHint = typeof delayHint === "number" && delayHint > 0 ? delayHint : null;
53213
+ if (!(_this._targetDelayHint === delayHint)) {
53214
+ _context4.next = 6;
53215
+ break;
53216
+ }
53217
+ return _context4.abrupt("return");
53218
+ case 6:
53219
+ _this._targetDelayHint = delayHint;
53220
+ if (!_this._setDelayTimer) {
53221
+ _context4.next = 9;
53222
+ break;
53223
+ }
53224
+ return _context4.abrupt("return");
53225
+ case 9:
53226
+ preAudioStats = null;
53227
+ preVideoStats = null;
53228
+ _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;
53229
+ avDiffTooMuchCount = 0;
53230
+ _this._setDelayTimer = setInterval(/* @__PURE__ */ _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee3() {
53231
+ 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;
53232
+ return _regeneratorRuntime$a().wrap(function _callee3$(_context3) {
53233
+ while (1)
53234
+ switch (_context3.prev = _context3.next) {
53235
+ case 0:
53236
+ _context3.prev = 0;
53237
+ 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))) {
53238
+ _context3.next = 5;
53239
+ break;
53240
+ }
53241
+ preAudioStats = null;
53242
+ preVideoStats = null;
53243
+ return _context3.abrupt("return");
53244
+ case 5:
53245
+ currentTargetDelay = _this._audioTransceicer.receiver[key2];
53246
+ if (!(currentTargetDelay === _this._targetDelayHint)) {
53247
+ _context3.next = 8;
53248
+ break;
53249
+ }
53250
+ return _context3.abrupt("return");
53251
+ case 8:
53252
+ targetDelayMs = _this._targetDelayHint * 1e3;
53253
+ currentTargetDelayMs = currentTargetDelay * 1e3;
53254
+ _context3.next = 12;
53255
+ return Promise.all([getRecvAudioStats(_this._audioTransceicer.receiver.getStats()), getRecvVideoStats(_this._videoTransceicer.receiver.getStats())]);
53256
+ case 12:
53257
+ _yield$Promise$all = _context3.sent;
53258
+ _yield$Promise$all2 = _slicedToArray$7(_yield$Promise$all, 2);
53259
+ curAudioStats = _yield$Promise$all2[0];
53260
+ curVideoStats = _yield$Promise$all2[1];
53261
+ if (!(preAudioStats && preVideoStats)) {
53262
+ _context3.next = 36;
53263
+ break;
53264
+ }
53265
+ audioStats = diffRecvAudioStats(preAudioStats, curAudioStats);
53266
+ videoStats = diffRecvVideoStats(preVideoStats, curVideoStats);
53267
+ if (videoStats.estimatedPlayoutTimestamp && audioStats.estimatedPlayoutTimestamp) {
53268
+ av_sync_diff = videoStats.estimatedPlayoutTimestamp - audioStats.estimatedPlayoutTimestamp;
53269
+ }
53270
+ currentAudioDelay = audioStats.jitterBufferDelay;
53271
+ currentVideoDelay = videoStats.jitterBufferDelay;
53272
+ if (!(currentAudioDelay && currentVideoDelay)) {
53273
+ _context3.next = 36;
53274
+ break;
53275
+ }
53276
+ if (!(Math.abs(currentAudioDelay - currentVideoDelay) > maxAvSyncDelay || av_sync_diff && Math.abs(av_sync_diff) > maxAvSyncDelay)) {
53277
+ _context3.next = 27;
53278
+ break;
53279
+ }
53280
+ if (avDiffTooMuchCount++ > 8 && currentVideoDelay > currentAudioDelay) {
53281
+ _this._audioTransceicer.receiver[key2] = Math.min(currentVideoDelay / 1e3, _this._targetDelayHint);
53282
+ avDiffTooMuchCount = 0;
53283
+ }
53284
+ logger$a.log("av_jb_diff(".concat(currentAudioDelay - currentVideoDelay, "=").concat(currentAudioDelay, "-").concat(currentVideoDelay, ") or av_sync_diff(").concat(av_sync_diff, ") too much, skip setting"));
53285
+ return _context3.abrupt("return");
53286
+ case 27:
53287
+ avDiffTooMuchCount = 0;
53288
+ if (!(currentTargetDelay !== null && (Math.abs(currentAudioDelay - currentTargetDelayMs) > maxJitterBufferDiff || Math.abs(currentVideoDelay - currentTargetDelayMs) > maxJitterBufferDiff))) {
53289
+ _context3.next = 31;
53290
+ break;
53291
+ }
53292
+ logger$a.log("audio(".concat(currentAudioDelay - currentTargetDelayMs, "),video(").concat(currentVideoDelay - currentTargetDelayMs, "). current_target_diff too much, skip setting"));
53293
+ return _context3.abrupt("return");
53294
+ case 31:
53295
+ addOrReduce = targetDelayMs > (currentTargetDelayMs || currentAudioDelay) ? 1 : -1;
53296
+ nextJitterBufferDelay = (Math.abs(targetDelayMs - (currentTargetDelayMs || currentAudioDelay)) > maxStep ? (currentTargetDelayMs || currentAudioDelay) + addOrReduce * maxStep : targetDelayMs) / 1e3;
53297
+ nextJitterBufferDelay = nextJitterBufferDelay > 0.2 ? nextJitterBufferDelay : null;
53298
+ logger$a.log("set receiver.".concat(key2, " = ").concat(nextJitterBufferDelay));
53299
+ _this._audioTransceicer.receiver[key2] = nextJitterBufferDelay;
53300
+ case 36:
53301
+ preAudioStats = curAudioStats;
53302
+ preVideoStats = curVideoStats;
53303
+ _context3.next = 44;
53304
+ break;
53305
+ case 40:
53306
+ _context3.prev = 40;
53307
+ _context3.t0 = _context3["catch"](0);
53308
+ logger$a.error("set delay loop error:", _context3.t0);
53309
+ _this._setDelayError = _context3.t0.message || _context3.t0.toString() || "unknown error";
53310
+ case 44:
53311
+ case "end":
53312
+ return _context3.stop();
53313
+ }
53314
+ }, _callee3, null, [[0, 40]]);
53315
+ })), loopInterval);
53316
+ case 14:
53317
+ case "end":
53318
+ return _context4.stop();
53319
+ }
53320
+ }, _callee4);
53321
+ }));
53322
+ return function(_x) {
53323
+ return _ref32.apply(this, arguments);
53324
+ };
53325
+ }());
53140
53326
  _defineProperty$h(_assertThisInitialized$f(_this), "_getDelay", function() {
53141
53327
  try {
53142
53328
  var key2 = ["playoutDelayHint", "jitterBufferDelayHint", "jitterBufferTarget"].find(function(key22) {
@@ -53212,51 +53398,51 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
53212
53398
  }, {
53213
53399
  key: "load",
53214
53400
  value: function() {
53215
- var _load = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee3(url2) {
53401
+ var _load = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee5(url2) {
53216
53402
  var _this2 = this;
53217
- var lastPc, encodedTransformSupported;
53218
- return _regeneratorRuntime$a().wrap(function _callee3$(_context3) {
53403
+ var encodedTransformSupported, lastPc;
53404
+ return _regeneratorRuntime$a().wrap(function _callee5$(_context5) {
53219
53405
  while (1)
53220
- switch (_context3.prev = _context3.next) {
53406
+ switch (_context5.prev = _context5.next) {
53221
53407
  case 0:
53222
53408
  this._disconnect();
53223
53409
  this._url = url2;
53224
53410
  this._retry = this._opts.retryCount;
53225
- lastPc = this._pc;
53226
- if (lastPc) {
53227
- lastPc.close();
53228
- }
53229
- encodedTransformSupported = isLegacyEncodedTransformSupported();
53230
- _context3.prev = 6;
53231
53411
  if (!this._opts.hackCreateOfferIssue) {
53232
- _context3.next = 10;
53412
+ _context5.next = 6;
53233
53413
  break;
53234
53414
  }
53235
- _context3.next = 10;
53415
+ _context5.next = 6;
53236
53416
  return this._createEmptyPeer();
53237
- case 10:
53417
+ case 6:
53418
+ encodedTransformSupported = isLegacyEncodedTransformSupported();
53419
+ _context5.prev = 7;
53420
+ lastPc = this._pc;
53421
+ if (lastPc) {
53422
+ lastPc.close();
53423
+ }
53238
53424
  this._pc = new RTCPeerConnection({
53239
53425
  encodedInsertableStreams: encodedTransformSupported && this._opts.enableSei ? true : void 0
53240
53426
  });
53241
53427
  this._bindRTCEvents();
53242
- _context3.next = 14;
53428
+ _context5.next = 14;
53243
53429
  return this._connect(url2);
53244
53430
  case 14:
53245
- _context3.next = 19;
53431
+ _context5.next = 19;
53246
53432
  break;
53247
53433
  case 16:
53248
- _context3.prev = 16;
53249
- _context3.t0 = _context3["catch"](6);
53434
+ _context5.prev = 16;
53435
+ _context5.t0 = _context5["catch"](7);
53250
53436
  setTimeout(function() {
53251
- return _this2._emitError(StreamingError$2.create(ERR$2.OTHER, null, _context3.t0));
53437
+ return _this2._emitError(StreamingError$2.create(ERR$2.OTHER, null, _context5.t0));
53252
53438
  });
53253
53439
  case 19:
53254
53440
  case "end":
53255
- return _context3.stop();
53441
+ return _context5.stop();
53256
53442
  }
53257
- }, _callee3, this, [[6, 16]]);
53443
+ }, _callee5, this, [[7, 16]]);
53258
53444
  }));
53259
- function load(_x) {
53445
+ function load(_x2) {
53260
53446
  return _load.apply(this, arguments);
53261
53447
  }
53262
53448
  return load;
@@ -53394,15 +53580,15 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
53394
53580
  }, {
53395
53581
  key: "_connect",
53396
53582
  value: function() {
53397
- var _connect2 = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee4() {
53583
+ var _connect2 = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee6() {
53398
53584
  var pc, offer, parsed, finnalUrl, _this$_opts, _answer$remoteSdp, _this$_opts2, _answer$remoteSdp2, _parsed$media, parseSession, sessionId, reqStart, res, answer, err, _parsed;
53399
- return _regeneratorRuntime$a().wrap(function _callee4$(_context4) {
53585
+ return _regeneratorRuntime$a().wrap(function _callee6$(_context6) {
53400
53586
  while (1)
53401
- switch (_context4.prev = _context4.next) {
53587
+ switch (_context6.prev = _context6.next) {
53402
53588
  case 0:
53403
53589
  pc = this._pc;
53404
53590
  if (!pc.addTransceiver) {
53405
- _context4.next = 11;
53591
+ _context6.next = 11;
53406
53592
  break;
53407
53593
  }
53408
53594
  this._audioTransceicer = pc.addTransceiver("audio", {
@@ -53411,26 +53597,26 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
53411
53597
  this._videoTransceicer = pc.addTransceiver("video", {
53412
53598
  direction: "recvonly"
53413
53599
  });
53414
- this._opts.delayHint !== void 0 && this._setDelay(this._opts.delayHint, this._opts.videoDelaySync);
53600
+ this._setDelay(this._opts.delayHint);
53415
53601
  if (this._opts.enableSei) {
53416
53602
  this.initVideoEncodedTransform();
53417
53603
  this.initAudioEncodedTransform();
53418
53604
  }
53419
- _context4.next = 8;
53605
+ _context6.next = 8;
53420
53606
  return pc.createOffer();
53421
53607
  case 8:
53422
- offer = _context4.sent;
53423
- _context4.next = 14;
53608
+ offer = _context6.sent;
53609
+ _context6.next = 14;
53424
53610
  break;
53425
53611
  case 11:
53426
- _context4.next = 13;
53612
+ _context6.next = 13;
53427
53613
  return pc.createOffer({
53428
53614
  iceRestart: true,
53429
53615
  offerToReceiveAudio: true,
53430
53616
  offerToReceiveVideo: true
53431
53617
  });
53432
53618
  case 13:
53433
- offer = _context4.sent;
53619
+ offer = _context6.sent;
53434
53620
  case 14:
53435
53621
  if (this._opts.hackCreateOfferIssue) {
53436
53622
  this._createEmptyPeer();
@@ -53459,11 +53645,11 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
53459
53645
  });
53460
53646
  offer.sdp = lib$1.write(parsed);
53461
53647
  logger$a.log("local offer modified:\n", offer.sdp);
53462
- _context4.next = 23;
53648
+ _context6.next = 23;
53463
53649
  return pc.setLocalDescription(offer);
53464
53650
  case 23:
53465
53651
  finnalUrl = this._url;
53466
- _context4.prev = 24;
53652
+ _context6.prev = 24;
53467
53653
  if (this._opts.preProcessUrl) {
53468
53654
  finnalUrl = this._opts.preProcessUrl(finnalUrl).url;
53469
53655
  }
@@ -53476,7 +53662,7 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
53476
53662
  sessionId
53477
53663
  });
53478
53664
  reqStart = Date.now();
53479
- _context4.next = 33;
53665
+ _context6.next = 33;
53480
53666
  return this._loader.load(finnalUrl, {
53481
53667
  body: JSON.stringify({
53482
53668
  sessionId,
@@ -53485,22 +53671,22 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
53485
53671
  })
53486
53672
  });
53487
53673
  case 33:
53488
- res = _context4.sent;
53674
+ res = _context6.sent;
53489
53675
  this.emit(EVENT$2.LOAD_RESPONSE_HEADERS, {
53490
53676
  headers: res.response.headers
53491
53677
  });
53492
53678
  answer = res === null || res === void 0 ? void 0 : res.data;
53493
53679
  if (!((answer === null || answer === void 0 ? void 0 : answer.code) === 404 || (answer === null || answer === void 0 ? void 0 : answer.code) === 403)) {
53494
- _context4.next = 41;
53680
+ _context6.next = 41;
53495
53681
  break;
53496
53682
  }
53497
53683
  err = StreamingError$2.create(answer.code === 404 ? ERR$2.NETWORK_NOTFOUND : ERR$2.NETWORK_FORBIDDEN, null, answer);
53498
53684
  err.errorType = ERR$2.NETWORK;
53499
53685
  this._emitError(err);
53500
- return _context4.abrupt("return");
53686
+ return _context6.abrupt("return");
53501
53687
  case 41:
53502
53688
  if (!((answer === null || answer === void 0 ? void 0 : answer.code) !== 200)) {
53503
- _context4.next = 43;
53689
+ _context6.next = 43;
53504
53690
  break;
53505
53691
  }
53506
53692
  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));
@@ -53533,22 +53719,28 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
53533
53719
  answer.remoteSdp.sdp = lib$1.write(_parsed);
53534
53720
  logger$a.log("answer modified:\n", answer.remoteSdp.sdp);
53535
53721
  this._rctConnectStartTs = Date.now();
53536
- _context4.next = 53;
53537
- return this._pc.setRemoteDescription(answer.remoteSdp);
53722
+ if (!(pc.signalingState === "closed")) {
53723
+ _context6.next = 53;
53724
+ break;
53725
+ }
53726
+ return _context6.abrupt("return");
53538
53727
  case 53:
53728
+ _context6.next = 55;
53729
+ return pc.setRemoteDescription(answer.remoteSdp);
53730
+ case 55:
53539
53731
  this._networkEvaluate = new NetworkEvaluate(pc, this._opts.networkEvaluateInterval);
53540
53732
  this._listenPeerStateTimeout();
53541
- _context4.next = 60;
53733
+ _context6.next = 62;
53542
53734
  break;
53543
- case 57:
53544
- _context4.prev = 57;
53545
- _context4.t0 = _context4["catch"](24);
53546
- this._emitError(StreamingError$2.network(_context4.t0));
53547
- case 60:
53735
+ case 59:
53736
+ _context6.prev = 59;
53737
+ _context6.t0 = _context6["catch"](24);
53738
+ this._emitError(StreamingError$2.network(_context6.t0));
53739
+ case 62:
53548
53740
  case "end":
53549
- return _context4.stop();
53741
+ return _context6.stop();
53550
53742
  }
53551
- }, _callee4, this, [[24, 57]]);
53743
+ }, _callee6, this, [[24, 59]]);
53552
53744
  }));
53553
53745
  function _connect() {
53554
53746
  return _connect2.apply(this, arguments);
@@ -53579,12 +53771,21 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
53579
53771
  value: function _startRtcReport() {
53580
53772
  var _this7 = this;
53581
53773
  this._stopRtcReport();
53582
- this._rtcReportTimer = setInterval(/* @__PURE__ */ _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee5() {
53583
- var _yield$Promise$all, _yield$Promise$all2, curAudioStats, curVideoStats, _this7$_audioStallObs, _this7$_videoStallObs, _this7$_networkQualit, _this7$_networkQualit2, audioStats, videoStats, audioStallInfo, videoStallInfo, _ref42, _ref52, quality, qualityInfo, targetDelay;
53584
- return _regeneratorRuntime$a().wrap(function _callee5$(_context5) {
53774
+ this._rtcReportTimer = setInterval(/* @__PURE__ */ _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee7() {
53775
+ var _this7$_audioTranscei, _this7$_videoTranscei;
53776
+ 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;
53777
+ return _regeneratorRuntime$a().wrap(function _callee7$(_context7) {
53585
53778
  while (1)
53586
- switch (_context5.prev = _context5.next) {
53779
+ switch (_context7.prev = _context7.next) {
53587
53780
  case 0:
53781
+ 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))) {
53782
+ _context7.next = 4;
53783
+ break;
53784
+ }
53785
+ _this7._preAudioStats = null;
53786
+ _this7._preVideoStats = null;
53787
+ return _context7.abrupt("return");
53788
+ case 4:
53588
53789
  if (!_this7._audioStallObserver && _this7._audioTransceicer) {
53589
53790
  _this7._audioStallObserver = new AudioStallObserver();
53590
53791
  _this7._audioStallObserver.start(_this7._audioTransceicer);
@@ -53596,43 +53797,45 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
53596
53797
  if (!_this7._networkQuality && _this7._opts.enableNetworkQuality) {
53597
53798
  _this7._networkQuality = new NetworkQuality(_this7._pc, _this7._opts.networkQuality);
53598
53799
  }
53599
- _context5.next = 5;
53800
+ _context7.next = 9;
53600
53801
  return Promise.all([getRecvAudioStats(_this7._audioTransceicer.receiver.getStats()), getRecvVideoStats(_this7._videoTransceicer.receiver.getStats())]);
53601
- case 5:
53602
- _yield$Promise$all = _context5.sent;
53603
- _yield$Promise$all2 = _slicedToArray$7(_yield$Promise$all, 2);
53604
- curAudioStats = _yield$Promise$all2[0];
53605
- curVideoStats = _yield$Promise$all2[1];
53802
+ case 9:
53803
+ _yield$Promise$all3 = _context7.sent;
53804
+ _yield$Promise$all4 = _slicedToArray$7(_yield$Promise$all3, 2);
53805
+ curAudioStats = _yield$Promise$all4[0];
53806
+ curVideoStats = _yield$Promise$all4[1];
53606
53807
  if (!(_this7._preAudioStats && _this7._preVideoStats)) {
53607
- _context5.next = 21;
53808
+ _context7.next = 26;
53608
53809
  break;
53609
53810
  }
53610
53811
  audioStats = diffRecvAudioStats(_this7._preAudioStats, curAudioStats);
53611
53812
  videoStats = diffRecvVideoStats(_this7._preVideoStats, curVideoStats);
53612
- _context5.next = 14;
53813
+ _context7.next = 18;
53613
53814
  return (_this7$_audioStallObs = _this7._audioStallObserver) === null || _this7$_audioStallObs === void 0 ? void 0 : _this7$_audioStallObs.getAudioStallInfo();
53614
- case 14:
53615
- audioStallInfo = _context5.sent;
53616
- _context5.next = 17;
53815
+ case 18:
53816
+ audioStallInfo = _context7.sent;
53817
+ _context7.next = 21;
53617
53818
  return (_this7$_videoStallObs = _this7._videoStallObserver) === null || _this7$_videoStallObs === void 0 ? void 0 : _this7$_videoStallObs.getStallInfo({
53618
53819
  interval: videoStats.statsInterval,
53619
53820
  frameRateReceived: videoStats.frameRateReceived,
53620
53821
  frameRateDecoded: videoStats.frameRateDecoded,
53621
53822
  bitrate: videoStats.receivedKBitrate
53622
53823
  });
53623
- case 17:
53624
- videoStallInfo = _context5.sent;
53625
- _ref42 = (_this7$_networkQualit = (_this7$_networkQualit2 = _this7._networkQuality) === null || _this7$_networkQualit2 === void 0 ? void 0 : _this7$_networkQualit2.getDownlinkQuality(_objectSpread2$a(_objectSpread2$a({}, audioStats), {}, {
53824
+ case 21:
53825
+ videoStallInfo = _context7.sent;
53826
+ _ref6 = (_this7$_networkQualit = (_this7$_networkQualit2 = _this7._networkQuality) === null || _this7$_networkQualit2 === void 0 ? void 0 : _this7$_networkQualit2.getDownlinkQuality(_objectSpread2$a(_objectSpread2$a({}, audioStats), {}, {
53626
53827
  stallDuration: audioStallInfo.stallDuration
53627
53828
  }), _objectSpread2$a(_objectSpread2$a({}, videoStats), {}, {
53628
- stallDuration: videoStallInfo.stall.stallDuration100ms
53629
- }))) !== null && _this7$_networkQualit !== void 0 ? _this7$_networkQualit : [], _ref52 = _slicedToArray$7(_ref42, 2), quality = _ref52[0], qualityInfo = _ref52[1];
53829
+ stallDuration: videoStallInfo.stall.stallDuration100ms || videoStallInfo.stall.stallDuration500ms
53830
+ }))) !== null && _this7$_networkQualit !== void 0 ? _this7$_networkQualit : [], _ref7 = _slicedToArray$7(_ref6, 2), quality = _ref7[0], qualityInfo = _ref7[1];
53630
53831
  if (_this7._opts.enableAdaptiveJitterBuffer) {
53631
- targetDelay = _this7._handleJitterBuffer(qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.qualityQos, _this7._opts.adaptiveJitterBuffer, _this7._opts.networkStrategy);
53832
+ _this7._handleJitterBuffer(qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.qualityQos, _this7._opts.adaptiveJitterBuffer, _this7._opts.networkStrategy);
53833
+ }
53834
+ if (videoStats.estimatedPlayoutTimestamp && audioStats.estimatedPlayoutTimestamp) {
53835
+ av_sync_diff = videoStats.estimatedPlayoutTimestamp - audioStats.estimatedPlayoutTimestamp;
53632
53836
  }
53633
53837
  _this7.emit(EXTEND_EVENTS.RTC_NETWORK, {
53634
53838
  interval: videoStats.statsInterval,
53635
- visibility_state: document.visibilityState,
53636
53839
  network_quality: quality,
53637
53840
  audio_stall_duration: audioStallInfo.stallDuration,
53638
53841
  audio_stall_count: audioStallInfo.stallCount,
@@ -53658,16 +53861,20 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
53658
53861
  quality_audio_qoe: qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.audioQoe,
53659
53862
  quality_video_qoe: qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.videoQoe,
53660
53863
  current_delay: _this7._getDelay(),
53661
- target_delay: targetDelay
53864
+ visibility_state: document.visibilityState,
53865
+ target_delay: _this7._targetDelayHint,
53866
+ av_sync_diff,
53867
+ set_delay_error: _this7._setDelayError || null
53662
53868
  });
53663
- case 21:
53869
+ case 26:
53664
53870
  _this7._preAudioStats = curAudioStats;
53665
53871
  _this7._preVideoStats = curVideoStats;
53666
- case 23:
53872
+ _this7.set_delay_error = null;
53873
+ case 29:
53667
53874
  case "end":
53668
- return _context5.stop();
53875
+ return _context7.stop();
53669
53876
  }
53670
- }, _callee5);
53877
+ }, _callee7);
53671
53878
  })), 2e3);
53672
53879
  }
53673
53880
  }, {
@@ -53680,15 +53887,21 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
53680
53887
  var validNetworkQualityResult = this._networkQualityResult.filter(Boolean);
53681
53888
  if (validNetworkQualityResult.length === adaptiveJitterBuffer.networkWindow) {
53682
53889
  var _networkStrategy$aver;
53683
- var sorted = _toConsumableArray$9(validNetworkQualityResult).sort(function(a2, b2) {
53684
- return a2 - b2;
53685
- });
53686
- var mid = Math.floor(sorted.length / 2);
53687
- var averageQuality = sorted.length % 2 !== 0 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2;
53890
+ var averageQuality;
53891
+ if (adaptiveJitterBuffer.windowMethod === "min") {
53892
+ averageQuality = Math.min.apply(Math, _toConsumableArray$9(validNetworkQualityResult));
53893
+ } else if (adaptiveJitterBuffer.windowMethod === "max") {
53894
+ averageQuality = Math.max.apply(Math, _toConsumableArray$9(validNetworkQualityResult));
53895
+ } else {
53896
+ var sorted = _toConsumableArray$9(validNetworkQualityResult).sort(function(a2, b2) {
53897
+ return a2 - b2;
53898
+ });
53899
+ var mid = Math.floor(sorted.length / 2);
53900
+ averageQuality = sorted.length % 2 !== 0 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2;
53901
+ }
53688
53902
  if (averageQuality && ((_networkStrategy$aver = networkStrategy[averageQuality]) === null || _networkStrategy$aver === void 0 ? void 0 : _networkStrategy$aver.jitterBuffer) !== void 0) {
53689
- var _networkStrategy$aver2, _networkStrategy$aver3;
53690
- this._setDelay((_networkStrategy$aver2 = networkStrategy[averageQuality]) === null || _networkStrategy$aver2 === void 0 ? void 0 : _networkStrategy$aver2.jitterBuffer);
53691
- return (_networkStrategy$aver3 = networkStrategy[averageQuality]) === null || _networkStrategy$aver3 === void 0 ? void 0 : _networkStrategy$aver3.jitterBuffer;
53903
+ var _networkStrategy$aver2;
53904
+ this._startSetDelayLoop((_networkStrategy$aver2 = networkStrategy[averageQuality]) === null || _networkStrategy$aver2 === void 0 ? void 0 : _networkStrategy$aver2.jitterBuffer);
53692
53905
  }
53693
53906
  }
53694
53907
  }
@@ -53702,6 +53915,8 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
53702
53915
  this._audioStallObserver = null;
53703
53916
  this._videoStallObserver = null;
53704
53917
  this._networkQuality = null;
53918
+ this._preAudioStats = null;
53919
+ this._preVideoStats = null;
53705
53920
  if (this._rtcReportTimer) {
53706
53921
  clearInterval(this._rtcReportTimer);
53707
53922
  this._rtcReportTimer = 0;
@@ -53729,28 +53944,31 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
53729
53944
  this._clearPeerStateTimeout();
53730
53945
  if (this._pc) {
53731
53946
  this._pc.close();
53947
+ if (this._media) {
53948
+ this._media.srcObject = null;
53949
+ }
53732
53950
  }
53733
53951
  }
53734
53952
  }, {
53735
53953
  key: "_createEmptyPeer",
53736
53954
  value: function() {
53737
- var _createEmptyPeer2 = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee6() {
53955
+ var _createEmptyPeer2 = _asyncToGenerator$a(/* @__PURE__ */ _regeneratorRuntime$a().mark(function _callee8() {
53738
53956
  var pc;
53739
- return _regeneratorRuntime$a().wrap(function _callee6$(_context6) {
53957
+ return _regeneratorRuntime$a().wrap(function _callee8$(_context8) {
53740
53958
  while (1)
53741
- switch (_context6.prev = _context6.next) {
53959
+ switch (_context8.prev = _context8.next) {
53742
53960
  case 0:
53743
53961
  pc = new RTCPeerConnection();
53744
- _context6.next = 3;
53962
+ _context8.next = 3;
53745
53963
  return pc.createOffer();
53746
53964
  case 3:
53747
53965
  pc.close();
53748
53966
  pc = null;
53749
53967
  case 5:
53750
53968
  case "end":
53751
- return _context6.stop();
53969
+ return _context8.stop();
53752
53970
  }
53753
- }, _callee6);
53971
+ }, _callee8);
53754
53972
  }));
53755
53973
  function _createEmptyPeer() {
53756
53974
  return _createEmptyPeer2.apply(this, arguments);
@@ -53897,7 +54115,7 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
53897
54115
  }, {
53898
54116
  key: "version",
53899
54117
  get: function get4() {
53900
- return "0.2.1-alpha.35";
54118
+ return "0.2.1-alpha.42";
53901
54119
  }
53902
54120
  }, {
53903
54121
  key: "beforePlayerInit",