@volcengine/veplayer-plugin 2.8.0-rc.2 → 2.8.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.
@@ -4955,11 +4955,14 @@
4955
4955
  stallInterval: 400,
4956
4956
  networkEvaluateInterval: 1e3,
4957
4957
  delayHint: 0,
4958
+ videoDelaySync: false,
4958
4959
  seamlesslyReload: false,
4959
4960
  enableSei: false,
4960
4961
  enableOriginSdpLogger: false,
4961
4962
  checkStatsErrorDelay: 5e3,
4963
+ connectionStateChangeTimeout: 5e3,
4962
4964
  enableNetworkQuality: false,
4965
+ hackCreateOfferIssue: false,
4963
4966
  networkQuality: {
4964
4967
  networkQos: {
4965
4968
  1: {
@@ -6732,11 +6735,15 @@
6732
6735
  _defineProperty$2(_assertThisInitialized$1(_this), "_preVideoStats", null);
6733
6736
  _defineProperty$2(_assertThisInitialized$1(_this), "_rtcReportTimer", 0);
6734
6737
  _defineProperty$2(_assertThisInitialized$1(_this), "_networkQualityResult", []);
6738
+ _defineProperty$2(_assertThisInitialized$1(_this), "_peerStateTimer", null);
6735
6739
  _defineProperty$2(_assertThisInitialized$1(_this), "_checkStatsError", /* @__PURE__ */ _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee2() {
6736
6740
  return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
6737
6741
  while (1)
6738
6742
  switch (_context2.prev = _context2.next) {
6739
6743
  case 0:
6744
+ if (_this._checkStatsErrorTimer) {
6745
+ clearTimeout(_this._checkStatsErrorTimer);
6746
+ }
6740
6747
  _this._checkStatsErrorTimer = setTimeout(/* @__PURE__ */ _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee() {
6741
6748
  var stats, _stats$video, framesDecoded, bytesReceived;
6742
6749
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
@@ -6765,7 +6772,7 @@
6765
6772
  }
6766
6773
  }, _callee);
6767
6774
  })), _this._opts.checkStatsErrorDelay);
6768
- case 1:
6775
+ case 2:
6769
6776
  case "end":
6770
6777
  return _context2.stop();
6771
6778
  }
@@ -6803,6 +6810,7 @@
6803
6810
  });
6804
6811
  });
6805
6812
  _defineProperty$2(_assertThisInitialized$1(_this), "_setDelay", function(delayHint) {
6813
+ var videoDelaySync = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
6806
6814
  var currentDelay = _this._getDelay();
6807
6815
  delayHint = typeof delayHint === "number" && delayHint > 0 ? delayHint : null;
6808
6816
  if (currentDelay === delayHint)
@@ -6819,6 +6827,10 @@
6819
6827
  });
6820
6828
  if (key) {
6821
6829
  audioReceiver[key] = delayHint;
6830
+ if (!videoDelaySync) {
6831
+ videoReceiver[key] = delayHint;
6832
+ logger.log("set videoReceiver.".concat(key, " = ").concat(delayHint));
6833
+ }
6822
6834
  logger.log("set audioReceiver.".concat(key, " = ").concat(delayHint));
6823
6835
  }
6824
6836
  } catch (error) {
@@ -6916,26 +6928,33 @@
6916
6928
  }
6917
6929
  encodedTransformSupported = isLegacyEncodedTransformSupported();
6918
6930
  _context3.prev = 6;
6931
+ if (!this._opts.hackCreateOfferIssue) {
6932
+ _context3.next = 10;
6933
+ break;
6934
+ }
6935
+ _context3.next = 10;
6936
+ return this._createEmptyPeer();
6937
+ case 10:
6919
6938
  this._pc = new RTCPeerConnection({
6920
6939
  encodedInsertableStreams: encodedTransformSupported && this._opts.enableSei ? true : void 0
6921
6940
  });
6922
6941
  this._bindRTCEvents();
6923
- _context3.next = 11;
6942
+ _context3.next = 14;
6924
6943
  return this._connect(url);
6925
- case 11:
6926
- _context3.next = 16;
6944
+ case 14:
6945
+ _context3.next = 19;
6927
6946
  break;
6928
- case 13:
6929
- _context3.prev = 13;
6947
+ case 16:
6948
+ _context3.prev = 16;
6930
6949
  _context3.t0 = _context3["catch"](6);
6931
6950
  setTimeout(function() {
6932
6951
  return _this2._emitError(StreamingError.create(ERR.OTHER, null, _context3.t0));
6933
6952
  });
6934
- case 16:
6953
+ case 19:
6935
6954
  case "end":
6936
6955
  return _context3.stop();
6937
6956
  }
6938
- }, _callee3, this, [[6, 13]]);
6957
+ }, _callee3, this, [[6, 16]]);
6939
6958
  }));
6940
6959
  function load(_x) {
6941
6960
  return _load.apply(this, arguments);
@@ -6955,6 +6974,7 @@
6955
6974
  pc.addEventListener("track", this._onTrack);
6956
6975
  pc.addEventListener("connectionstatechange", function() {
6957
6976
  logger.warn("onconnectionstatechange:", pc.connectionState);
6977
+ _this3._clearPeerStateTimeout();
6958
6978
  _this3.emit(EXTEND_EVENTS.RTC_STATE_CHANGE, {
6959
6979
  state: pc.connectionState,
6960
6980
  url: _this3._url
@@ -7091,7 +7111,7 @@
7091
7111
  this._videoTransceicer = pc.addTransceiver("video", {
7092
7112
  direction: "recvonly"
7093
7113
  });
7094
- !this._opts.enableAdaptiveJitterBuffer && this._setDelay(this._opts.delayHint);
7114
+ this._opts.delayHint !== void 0 && this._setDelay(this._opts.delayHint, this._opts.videoDelaySync);
7095
7115
  if (this._opts.enableSei) {
7096
7116
  this.initVideoEncodedTransform();
7097
7117
  this.initAudioEncodedTransform();
@@ -7112,6 +7132,9 @@
7112
7132
  case 13:
7113
7133
  offer = _context4.sent;
7114
7134
  case 14:
7135
+ if (this._opts.hackCreateOfferIssue) {
7136
+ this._createEmptyPeer();
7137
+ }
7115
7138
  logger.log("local offer");
7116
7139
  logger.log(offer.sdp);
7117
7140
  parsed = lib.parse(offer.sdp);
@@ -7136,11 +7159,11 @@
7136
7159
  });
7137
7160
  offer.sdp = lib.write(parsed);
7138
7161
  logger.log("local offer modified:\n", offer.sdp);
7139
- _context4.next = 22;
7162
+ _context4.next = 23;
7140
7163
  return pc.setLocalDescription(offer);
7141
- case 22:
7164
+ case 23:
7142
7165
  finnalUrl = this._url;
7143
- _context4.prev = 23;
7166
+ _context4.prev = 24;
7144
7167
  if (this._opts.preProcessUrl) {
7145
7168
  finnalUrl = this._opts.preProcessUrl(finnalUrl).url;
7146
7169
  }
@@ -7153,7 +7176,7 @@
7153
7176
  sessionId
7154
7177
  });
7155
7178
  reqStart = Date.now();
7156
- _context4.next = 32;
7179
+ _context4.next = 33;
7157
7180
  return this._loader.load(finnalUrl, {
7158
7181
  body: JSON.stringify({
7159
7182
  sessionId,
@@ -7161,27 +7184,27 @@
7161
7184
  localSdp: offer
7162
7185
  })
7163
7186
  });
7164
- case 32:
7187
+ case 33:
7165
7188
  res = _context4.sent;
7166
7189
  this.emit(EVENT.LOAD_RESPONSE_HEADERS, {
7167
7190
  headers: res.response.headers
7168
7191
  });
7169
7192
  answer = res === null || res === void 0 ? void 0 : res.data;
7170
7193
  if (!((answer === null || answer === void 0 ? void 0 : answer.code) === 404 || (answer === null || answer === void 0 ? void 0 : answer.code) === 403)) {
7171
- _context4.next = 40;
7194
+ _context4.next = 41;
7172
7195
  break;
7173
7196
  }
7174
7197
  err = StreamingError.create(answer.code === 404 ? ERR.NETWORK_NOTFOUND : ERR.NETWORK_FORBIDDEN, null, answer);
7175
7198
  err.errorType = ERR.NETWORK;
7176
7199
  this._emitError(err);
7177
7200
  return _context4.abrupt("return");
7178
- case 40:
7201
+ case 41:
7179
7202
  if (!((answer === null || answer === void 0 ? void 0 : answer.code) !== 200)) {
7180
- _context4.next = 42;
7203
+ _context4.next = 43;
7181
7204
  break;
7182
7205
  }
7183
7206
  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));
7184
- case 42:
7207
+ case 43:
7185
7208
  logger.log("answer:");
7186
7209
  logger.log((_answer$remoteSdp = answer.remoteSdp) === null || _answer$remoteSdp === void 0 ? void 0 : _answer$remoteSdp.sdp);
7187
7210
  _parsed = lib.parse(answer.remoteSdp.sdp);
@@ -7210,68 +7233,88 @@
7210
7233
  answer.remoteSdp.sdp = lib.write(_parsed);
7211
7234
  logger.log("answer modified:\n", answer.remoteSdp.sdp);
7212
7235
  this._rctConnectStartTs = Date.now();
7213
- _context4.next = 52;
7236
+ _context4.next = 53;
7214
7237
  return this._pc.setRemoteDescription(answer.remoteSdp);
7215
- case 52:
7238
+ case 53:
7216
7239
  this._networkEvaluate = new NetworkEvaluate(pc, this._opts.networkEvaluateInterval);
7217
- _context4.next = 58;
7240
+ this._listenPeerStateTimeout();
7241
+ _context4.next = 60;
7218
7242
  break;
7219
- case 55:
7220
- _context4.prev = 55;
7221
- _context4.t0 = _context4["catch"](23);
7243
+ case 57:
7244
+ _context4.prev = 57;
7245
+ _context4.t0 = _context4["catch"](24);
7222
7246
  this._emitError(StreamingError.network(_context4.t0));
7223
- case 58:
7247
+ case 60:
7224
7248
  case "end":
7225
7249
  return _context4.stop();
7226
7250
  }
7227
- }, _callee4, this, [[23, 55]]);
7251
+ }, _callee4, this, [[24, 57]]);
7228
7252
  }));
7229
7253
  function _connect() {
7230
7254
  return _connect2.apply(this, arguments);
7231
7255
  }
7232
7256
  return _connect;
7233
7257
  }()
7258
+ }, {
7259
+ key: "_listenPeerStateTimeout",
7260
+ value: function _listenPeerStateTimeout() {
7261
+ var _this6 = this;
7262
+ this._peerStateTimer && this._clearPeerStateTimeout();
7263
+ if (this._opts.connectionStateChangeTimeout) {
7264
+ this._peerStateTimer = setTimeout(function() {
7265
+ _this6._emitError(StreamingError.create(ERR.MEDIA, ERR.SUB_TYPES.MEDIA_ERR_SRC_NOT_SUPPORTED, {
7266
+ message: "listen connectionstatechange timeout"
7267
+ }));
7268
+ }, this._opts.connectionStateChangeTimeout);
7269
+ }
7270
+ }
7271
+ }, {
7272
+ key: "_clearPeerStateTimeout",
7273
+ value: function _clearPeerStateTimeout() {
7274
+ clearTimeout(this._peerStateTimer);
7275
+ this._peerStateTimer = null;
7276
+ }
7234
7277
  }, {
7235
7278
  key: "_startRtcReport",
7236
7279
  value: function _startRtcReport() {
7237
- var _this6 = this;
7280
+ var _this7 = this;
7238
7281
  this._stopRtcReport();
7239
7282
  this._rtcReportTimer = setInterval(/* @__PURE__ */ _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee5() {
7240
- 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;
7283
+ 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;
7241
7284
  return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
7242
7285
  while (1)
7243
7286
  switch (_context5.prev = _context5.next) {
7244
7287
  case 0:
7245
- if (!_this6._audioStallObserver && _this6._audioTransceicer) {
7246
- _this6._audioStallObserver = new AudioStallObserver();
7247
- _this6._audioStallObserver.start(_this6._audioTransceicer);
7288
+ if (!_this7._audioStallObserver && _this7._audioTransceicer) {
7289
+ _this7._audioStallObserver = new AudioStallObserver();
7290
+ _this7._audioStallObserver.start(_this7._audioTransceicer);
7248
7291
  }
7249
- if (!_this6._videoStallObserver && _this6._video) {
7250
- _this6._videoStallObserver = new VideoStallObserver();
7251
- _this6._videoStallObserver.start(_this6._media);
7292
+ if (!_this7._videoStallObserver && _this7._video) {
7293
+ _this7._videoStallObserver = new VideoStallObserver();
7294
+ _this7._videoStallObserver.start(_this7._media);
7252
7295
  }
7253
- if (!_this6._networkQuality && _this6._opts.enableNetworkQuality) {
7254
- _this6._networkQuality = new NetworkQuality(_this6._pc, _this6._opts.networkQuality);
7296
+ if (!_this7._networkQuality && _this7._opts.enableNetworkQuality) {
7297
+ _this7._networkQuality = new NetworkQuality(_this7._pc, _this7._opts.networkQuality);
7255
7298
  }
7256
7299
  _context5.next = 5;
7257
- return Promise.all([getRecvAudioStats(_this6._audioTransceicer.receiver.getStats()), getRecvVideoStats(_this6._videoTransceicer.receiver.getStats())]);
7300
+ return Promise.all([getRecvAudioStats(_this7._audioTransceicer.receiver.getStats()), getRecvVideoStats(_this7._videoTransceicer.receiver.getStats())]);
7258
7301
  case 5:
7259
7302
  _yield$Promise$all = _context5.sent;
7260
7303
  _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
7261
7304
  curAudioStats = _yield$Promise$all2[0];
7262
7305
  curVideoStats = _yield$Promise$all2[1];
7263
- if (!(_this6._preAudioStats && _this6._preVideoStats)) {
7306
+ if (!(_this7._preAudioStats && _this7._preVideoStats)) {
7264
7307
  _context5.next = 21;
7265
7308
  break;
7266
7309
  }
7267
- audioStats = diffRecvAudioStats(_this6._preAudioStats, curAudioStats);
7268
- videoStats = diffRecvVideoStats(_this6._preVideoStats, curVideoStats);
7310
+ audioStats = diffRecvAudioStats(_this7._preAudioStats, curAudioStats);
7311
+ videoStats = diffRecvVideoStats(_this7._preVideoStats, curVideoStats);
7269
7312
  _context5.next = 14;
7270
- return (_this6$_audioStallObs = _this6._audioStallObserver) === null || _this6$_audioStallObs === void 0 ? void 0 : _this6$_audioStallObs.getAudioStallInfo();
7313
+ return (_this7$_audioStallObs = _this7._audioStallObserver) === null || _this7$_audioStallObs === void 0 ? void 0 : _this7$_audioStallObs.getAudioStallInfo();
7271
7314
  case 14:
7272
7315
  audioStallInfo = _context5.sent;
7273
7316
  _context5.next = 17;
7274
- return (_this6$_videoStallObs = _this6._videoStallObserver) === null || _this6$_videoStallObs === void 0 ? void 0 : _this6$_videoStallObs.getStallInfo({
7317
+ return (_this7$_videoStallObs = _this7._videoStallObserver) === null || _this7$_videoStallObs === void 0 ? void 0 : _this7$_videoStallObs.getStallInfo({
7275
7318
  interval: videoStats.statsInterval,
7276
7319
  frameRateReceived: videoStats.frameRateReceived,
7277
7320
  frameRateDecoded: videoStats.frameRateDecoded,
@@ -7279,15 +7322,15 @@
7279
7322
  });
7280
7323
  case 17:
7281
7324
  videoStallInfo = _context5.sent;
7282
- _ref4 = (_this6$_networkQualit = (_this6$_networkQualit2 = _this6._networkQuality) === null || _this6$_networkQualit2 === void 0 ? void 0 : _this6$_networkQualit2.getDownlinkQuality(_objectSpread2$2(_objectSpread2$2({}, audioStats), {}, {
7325
+ _ref4 = (_this7$_networkQualit = (_this7$_networkQualit2 = _this7._networkQuality) === null || _this7$_networkQualit2 === void 0 ? void 0 : _this7$_networkQualit2.getDownlinkQuality(_objectSpread2$2(_objectSpread2$2({}, audioStats), {}, {
7283
7326
  stallDuration: audioStallInfo.stallDuration
7284
7327
  }), _objectSpread2$2(_objectSpread2$2({}, videoStats), {}, {
7285
7328
  stallDuration: videoStallInfo.stall.stallDuration100ms
7286
- }))) !== null && _this6$_networkQualit !== void 0 ? _this6$_networkQualit : [], _ref5 = _slicedToArray(_ref4, 2), quality = _ref5[0], qualityInfo = _ref5[1];
7287
- if (_this6._opts.enableAdaptiveJitterBuffer) {
7288
- targetDelay = _this6._handleJitterBuffer(qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.qualityQos, _this6._opts.adaptiveJitterBuffer, _this6._opts.networkStrategy);
7329
+ }))) !== null && _this7$_networkQualit !== void 0 ? _this7$_networkQualit : [], _ref5 = _slicedToArray(_ref4, 2), quality = _ref5[0], qualityInfo = _ref5[1];
7330
+ if (_this7._opts.enableAdaptiveJitterBuffer) {
7331
+ targetDelay = _this7._handleJitterBuffer(qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.qualityQos, _this7._opts.adaptiveJitterBuffer, _this7._opts.networkStrategy);
7289
7332
  }
7290
- _this6.emit(EXTEND_EVENTS.RTC_NETWORK, {
7333
+ _this7.emit(EXTEND_EVENTS.RTC_NETWORK, {
7291
7334
  interval: videoStats.statsInterval,
7292
7335
  visibility_state: document.visibilityState,
7293
7336
  network_quality: quality,
@@ -7314,12 +7357,12 @@
7314
7357
  quality_qos: qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.qualityQos,
7315
7358
  quality_audio_qoe: qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.audioQoe,
7316
7359
  quality_video_qoe: qualityInfo === null || qualityInfo === void 0 ? void 0 : qualityInfo.videoQoe,
7317
- current_delay: _this6._getDelay(),
7360
+ current_delay: _this7._getDelay(),
7318
7361
  target_delay: targetDelay
7319
7362
  });
7320
7363
  case 21:
7321
- _this6._preAudioStats = curAudioStats;
7322
- _this6._preVideoStats = curVideoStats;
7364
+ _this7._preAudioStats = curAudioStats;
7365
+ _this7._preVideoStats = curVideoStats;
7323
7366
  case 23:
7324
7367
  case "end":
7325
7368
  return _context5.stop();
@@ -7371,6 +7414,8 @@
7371
7414
  (_this$_loader = this._loader) === null || _this$_loader === void 0 ? void 0 : _this$_loader.cancel();
7372
7415
  (_this$_networkEvaluat2 = this._networkEvaluate) === null || _this$_networkEvaluat2 === void 0 ? void 0 : _this$_networkEvaluat2.destroy();
7373
7416
  this._stopRtcReport();
7417
+ clearTimeout(this._checkStatsErrorTimer);
7418
+ this._clearPeerStateTimeout();
7374
7419
  this._audioTransceicer = null;
7375
7420
  this._videoTransceicer = null;
7376
7421
  this._mediaStream = null;
@@ -7381,10 +7426,37 @@
7381
7426
  value: function _emitError(error) {
7382
7427
  this.emit(EVENT.ERROR, error);
7383
7428
  clearTimeout(this._checkStatsErrorTimer);
7429
+ this._clearPeerStateTimeout();
7384
7430
  if (this._pc) {
7385
7431
  this._pc.close();
7386
7432
  }
7387
7433
  }
7434
+ }, {
7435
+ key: "_createEmptyPeer",
7436
+ value: function() {
7437
+ var _createEmptyPeer2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee6() {
7438
+ var pc;
7439
+ return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
7440
+ while (1)
7441
+ switch (_context6.prev = _context6.next) {
7442
+ case 0:
7443
+ pc = new RTCPeerConnection();
7444
+ _context6.next = 3;
7445
+ return pc.createOffer();
7446
+ case 3:
7447
+ pc.close();
7448
+ pc = null;
7449
+ case 5:
7450
+ case "end":
7451
+ return _context6.stop();
7452
+ }
7453
+ }, _callee6);
7454
+ }));
7455
+ function _createEmptyPeer() {
7456
+ return _createEmptyPeer2.apply(this, arguments);
7457
+ }
7458
+ return _createEmptyPeer;
7459
+ }()
7388
7460
  }, {
7389
7461
  key: "destroy",
7390
7462
  value: function destroy(keepClearMediaStream) {
@@ -7525,7 +7597,7 @@
7525
7597
  }, {
7526
7598
  key: "version",
7527
7599
  get: function get() {
7528
- return "0.2.1-alpha.30";
7600
+ return "0.2.1-alpha.35";
7529
7601
  }
7530
7602
  }, {
7531
7603
  key: "beforePlayerInit",