@byteplus/veplayer-plugin 2.6.0-rc.5 → 2.6.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.
@@ -1534,7 +1534,7 @@
1534
1534
  }
1535
1535
  return offsetTime;
1536
1536
  };
1537
- var version = "3.0.21-rc.3";
1537
+ var version = "3.0.21-rc.5";
1538
1538
  var ERROR_MAP = {
1539
1539
  1: 5101,
1540
1540
  2: 5102,
@@ -1598,6 +1598,8 @@
1598
1598
  }
1599
1599
  }
1600
1600
  );
1601
+ var PLAY = "play";
1602
+ var PAUSE = "pause";
1601
1603
  var ERROR = "error";
1602
1604
  var DESTROY = "destroy";
1603
1605
  var URL_CHANGE = "urlchange";
@@ -4880,7 +4882,9 @@
4880
4882
  loadTimeout: 5e3,
4881
4883
  stallInterval: 400,
4882
4884
  networkEvaluateInterval: 1e3,
4883
- delayHint: 0
4885
+ delayHint: 0,
4886
+ seamlesslyReload: false,
4887
+ enableOriginSdpLogger: false
4884
4888
  }, opts);
4885
4889
  }
4886
4890
  function _getStats(stats) {
@@ -5143,6 +5147,7 @@
5143
5147
  _defineProperty$2(_assertThisInitialized$1(_this), "_audioTransceicer", null);
5144
5148
  _defineProperty$2(_assertThisInitialized$1(_this), "_videoTransceicer", null);
5145
5149
  _defineProperty$2(_assertThisInitialized$1(_this), "_mediaStream", null);
5150
+ _defineProperty$2(_assertThisInitialized$1(_this), "_lastMediaStream", null);
5146
5151
  _defineProperty$2(_assertThisInitialized$1(_this), "_media", null);
5147
5152
  _defineProperty$2(_assertThisInitialized$1(_this), "_opts", null);
5148
5153
  _defineProperty$2(_assertThisInitialized$1(_this), "_loader", null);
@@ -5150,19 +5155,10 @@
5150
5155
  _defineProperty$2(_assertThisInitialized$1(_this), "_retry", 0);
5151
5156
  _defineProperty$2(_assertThisInitialized$1(_this), "_waitingTimer", 0);
5152
5157
  _defineProperty$2(_assertThisInitialized$1(_this), "_rctConnectStartTs", 0);
5158
+ _defineProperty$2(_assertThisInitialized$1(_this), "_isReplacing", false);
5153
5159
  _defineProperty$2(_assertThisInitialized$1(_this), "_onTrack", function(e) {
5154
5160
  logger.log("addTrack: ", e.track, e.streams);
5155
5161
  _this["_".concat(e.track.kind)] = e.track;
5156
- if (!_this._mediaStream) {
5157
- _this._mediaStream = new MediaStream();
5158
- _this._media.srcObject = _this._mediaStream;
5159
- var req = _this._media.play();
5160
- if (req && req.catch) {
5161
- req.catch(function(e2) {
5162
- });
5163
- }
5164
- }
5165
- _this._mediaStream.addTrack(e.track);
5166
5162
  });
5167
5163
  _defineProperty$2(_assertThisInitialized$1(_this), "_mockWaitingByTimeupdate", function() {
5168
5164
  var _this$_pc, _this$_pc2;
@@ -5210,6 +5206,9 @@
5210
5206
  }));
5211
5207
  _this._retry = _this._opts.retryCount;
5212
5208
  _this._bindMediaEvent();
5209
+ if (_this._opts.mediaStream && _this._opts.seamlesslyReload) {
5210
+ _this._lastMediaStream = _this._opts.mediaStream;
5211
+ }
5213
5212
  return _this;
5214
5213
  }
5215
5214
  _createClass$2(Rts2, [{
@@ -5321,6 +5320,7 @@
5321
5320
  _this3.load(_this3._url);
5322
5321
  }
5323
5322
  if (pc.connectionState === "connected") {
5323
+ _this3._handleMediaStream();
5324
5324
  _this3.emit(EVENT.TTFB, {
5325
5325
  url: _this3._url,
5326
5326
  responseUrl: _this3._url,
@@ -5329,6 +5329,40 @@
5329
5329
  }
5330
5330
  });
5331
5331
  }
5332
+ }, {
5333
+ key: "_handleMediaStream",
5334
+ value: function _handleMediaStream() {
5335
+ var _this4 = this;
5336
+ if (this._lastMediaStream) {
5337
+ var _this$_media$play;
5338
+ var videoTrack = this._lastMediaStream.getVideoTracks()[0];
5339
+ var audioTrack = this._lastMediaStream.getAudioTracks()[0];
5340
+ if (videoTrack) {
5341
+ this._lastMediaStream.removeTrack(videoTrack);
5342
+ }
5343
+ if (audioTrack) {
5344
+ this._lastMediaStream.removeTrack(audioTrack);
5345
+ }
5346
+ this._mediaStream = this._lastMediaStream;
5347
+ this._audio && this._mediaStream.addTrack(this._audio);
5348
+ this._video && this._mediaStream.addTrack(this._video);
5349
+ this._isReplacing = true;
5350
+ this._media.pause();
5351
+ (_this$_media$play = this._media.play()) === null || _this$_media$play === void 0 ? void 0 : _this$_media$play.finally(function() {
5352
+ _this4._isReplacing = false;
5353
+ });
5354
+ } else {
5355
+ this._mediaStream = new MediaStream();
5356
+ this._audio && this._mediaStream.addTrack(this._audio);
5357
+ this._video && this._mediaStream.addTrack(this._video);
5358
+ this._media.srcObject = this._mediaStream;
5359
+ var req = this._media.play();
5360
+ if (req && req.catch) {
5361
+ req.catch(function(e) {
5362
+ });
5363
+ }
5364
+ }
5365
+ }
5332
5366
  }, {
5333
5367
  key: "_bindMediaEvent",
5334
5368
  value: function _bindMediaEvent() {
@@ -5339,7 +5373,7 @@
5339
5373
  key: "_connect",
5340
5374
  value: function() {
5341
5375
  var _connect2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee2() {
5342
- var pc, offer, delayHint, parsed, finnalUrl, _answer$remoteSdp, _answer$remoteSdp2, parseSession, sessionId, reqStart, res, answer, err, _parsed;
5376
+ var pc, offer, delayHint, parsed, finnalUrl, _this$_opts, _answer$remoteSdp, _this$_opts2, _answer$remoteSdp2, _parsed$media, parseSession, sessionId, reqStart, res, answer, err, _parsed;
5343
5377
  return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
5344
5378
  while (1)
5345
5379
  switch (_context2.prev = _context2.next) {
@@ -5415,7 +5449,7 @@
5415
5449
  sessionId = parseSession ? parseSession[1] : Date.now() + "666";
5416
5450
  this.emit(EVENT.LOAD_START, {
5417
5451
  url: finnalUrl,
5418
- offersdp: offer.sdp,
5452
+ offersdp: (_this$_opts = this._opts) !== null && _this$_opts !== void 0 && _this$_opts.enableOriginSdpLogger ? offer.sdp : void 0,
5419
5453
  sessionId
5420
5454
  });
5421
5455
  reqStart = Date.now();
@@ -5450,12 +5484,19 @@
5450
5484
  case 42:
5451
5485
  logger.log("answer:");
5452
5486
  logger.log((_answer$remoteSdp = answer.remoteSdp) === null || _answer$remoteSdp === void 0 ? void 0 : _answer$remoteSdp.sdp);
5487
+ _parsed = lib.parse(answer.remoteSdp.sdp);
5453
5488
  this.emit(EVENT.LOAD_COMPLETE, {
5454
5489
  url: finnalUrl,
5455
5490
  elapsed: Date.now() - reqStart,
5456
- answersdp: (_answer$remoteSdp2 = answer.remoteSdp) === null || _answer$remoteSdp2 === void 0 ? void 0 : _answer$remoteSdp2.sdp
5491
+ answersdp: (_this$_opts2 = this._opts) !== null && _this$_opts2 !== void 0 && _this$_opts2.enableOriginSdpLogger ? answer === null || answer === void 0 ? void 0 : (_answer$remoteSdp2 = answer.remoteSdp) === null || _answer$remoteSdp2 === void 0 ? void 0 : _answer$remoteSdp2.sdp : void 0,
5492
+ parsedSdp: _parsed === null || _parsed === void 0 ? void 0 : (_parsed$media = _parsed.media) === null || _parsed$media === void 0 ? void 0 : _parsed$media.map(function(media) {
5493
+ return {
5494
+ candidates: media.candidates,
5495
+ rtp: media.rtp,
5496
+ type: media.type
5497
+ };
5498
+ })
5457
5499
  });
5458
- _parsed = lib.parse(answer.remoteSdp.sdp);
5459
5500
  _parsed.media.forEach(function(x) {
5460
5501
  x.fingerprint.hash = x.fingerprint.hash.toUpperCase();
5461
5502
  });
@@ -5501,11 +5542,11 @@
5501
5542
  }
5502
5543
  }, {
5503
5544
  key: "destroy",
5504
- value: function destroy() {
5545
+ value: function destroy(keepClearMediaStream) {
5505
5546
  var _this$_media2;
5506
5547
  this._disconnect();
5507
5548
  (_this$_media2 = this._media) === null || _this$_media2 === void 0 ? void 0 : _this$_media2.removeEventListener("timeupdate", this._mockWaitingByTimeupdate);
5508
- if (this._media) {
5549
+ if (this._media && !keepClearMediaStream) {
5509
5550
  this._media.srcObject = null;
5510
5551
  }
5511
5552
  if (this._pc) {
@@ -5605,15 +5646,36 @@
5605
5646
  }
5606
5647
  _this = _super.call.apply(_super, [this].concat(args));
5607
5648
  _defineProperty$2(_assertThisInitialized$1(_this), "_rts", null);
5649
+ _defineProperty$2(_assertThisInitialized$1(_this), "_mediaStream", null);
5650
+ _defineProperty$2(_assertThisInitialized$1(_this), "_disconnectTimer", void 0);
5608
5651
  _defineProperty$2(_assertThisInitialized$1(_this), "_rtsOpts", null);
5609
- _defineProperty$2(_assertThisInitialized$1(_this), "_init", function() {
5652
+ _defineProperty$2(_assertThisInitialized$1(_this), "_onPause", function() {
5653
+ if (_this._disconnectTimer) {
5654
+ return;
5655
+ }
5656
+ _this._disconnectTimer = setTimeout(function() {
5657
+ _this._closeAfterPause();
5658
+ _this._clearDisconnectTimer();
5659
+ }, _this.config.disconnectTime * 1e3);
5660
+ });
5661
+ _defineProperty$2(_assertThisInitialized$1(_this), "_reInit", function() {
5610
5662
  var _this$_rts;
5611
- (_this$_rts = _this._rts) === null || _this$_rts === void 0 ? void 0 : _this$_rts.destroy();
5663
+ _this._clearDisconnectTimer();
5664
+ if ((_this$_rts = _this._rts) !== null && _this$_rts !== void 0 && _this$_rts._pc) {
5665
+ return;
5666
+ }
5667
+ _this._init();
5668
+ _this._bindRtsEvents();
5669
+ });
5670
+ _defineProperty$2(_assertThisInitialized$1(_this), "_init", function() {
5671
+ var _this$_rts2;
5672
+ (_this$_rts2 = _this._rts) === null || _this$_rts2 === void 0 ? void 0 : _this$_rts2.destroy();
5612
5673
  var config = _this.player.config;
5613
5674
  var rtsOpts = config.rts || {};
5614
5675
  _this._rtsOpts = rtsOpts;
5615
5676
  _this._rts = new Rts(_objectSpread2$2({
5616
5677
  media: _this.player.video,
5678
+ mediaStream: _this._mediaStream,
5617
5679
  preProcessUrl: function preProcessUrl(url, ext) {
5618
5680
  var _this$player$preProce, _this$player;
5619
5681
  return ((_this$player$preProce = (_this$player = _this.player).preProcessUrl) === null || _this$player$preProce === void 0 ? void 0 : _this$player$preProce.call(_this$player, url, ext)) || {
@@ -5625,35 +5687,41 @@
5625
5687
  _this._rts.load(config.url);
5626
5688
  });
5627
5689
  _defineProperty$2(_assertThisInitialized$1(_this), "_onSwitchURL", function(url) {
5628
- if (_this._rts) {
5690
+ if (url) {
5629
5691
  _this.player.config.url = url;
5692
+ }
5693
+ if (_this._rts) {
5630
5694
  _this._rts.switchURL(url);
5695
+ } else {
5696
+ _this._reInit();
5631
5697
  }
5632
5698
  });
5633
5699
  _defineProperty$2(_assertThisInitialized$1(_this), "destroy", function() {
5634
- var _this$_rts2;
5700
+ var _this$_rts3;
5635
5701
  _this.player.switchURL = _this._originSwitchFn;
5636
- (_this$_rts2 = _this._rts) === null || _this$_rts2 === void 0 ? void 0 : _this$_rts2.destroy();
5702
+ _this._clearDisconnectTimer();
5703
+ (_this$_rts3 = _this._rts) === null || _this$_rts3 === void 0 ? void 0 : _this$_rts3.destroy();
5704
+ _this._rts = null;
5637
5705
  });
5638
5706
  return _this;
5639
5707
  }
5640
5708
  _createClass$2(RtsPlugin2, [{
5641
5709
  key: "pc",
5642
5710
  get: function get() {
5643
- var _this$_rts3;
5644
- return (_this$_rts3 = this._rts) === null || _this$_rts3 === void 0 ? void 0 : _this$_rts3.pc;
5711
+ var _this$_rts4;
5712
+ return (_this$_rts4 = this._rts) === null || _this$_rts4 === void 0 ? void 0 : _this$_rts4.pc;
5645
5713
  }
5646
5714
  }, {
5647
5715
  key: "videoTrack",
5648
5716
  get: function get() {
5649
- var _this$_rts4;
5650
- return (_this$_rts4 = this._rts) === null || _this$_rts4 === void 0 ? void 0 : _this$_rts4.videoTack;
5717
+ var _this$_rts5;
5718
+ return (_this$_rts5 = this._rts) === null || _this$_rts5 === void 0 ? void 0 : _this$_rts5.videoTack;
5651
5719
  }
5652
5720
  }, {
5653
5721
  key: "audioTrack",
5654
5722
  get: function get() {
5655
- var _this$_rts5;
5656
- return (_this$_rts5 = this._rts) === null || _this$_rts5 === void 0 ? void 0 : _this$_rts5.audioTrack;
5723
+ var _this$_rts6;
5724
+ return (_this$_rts6 = this._rts) === null || _this$_rts6 === void 0 ? void 0 : _this$_rts6.audioTrack;
5657
5725
  }
5658
5726
  }, {
5659
5727
  key: "core",
@@ -5663,37 +5731,41 @@
5663
5731
  }, {
5664
5732
  key: "loader",
5665
5733
  get: function get() {
5666
- var _this$_rts6;
5667
- return (_this$_rts6 = this._rts) === null || _this$_rts6 === void 0 ? void 0 : _this$_rts6.loader;
5734
+ var _this$_rts7;
5735
+ return (_this$_rts7 = this._rts) === null || _this$_rts7 === void 0 ? void 0 : _this$_rts7.loader;
5668
5736
  }
5669
5737
  }, {
5670
5738
  key: "version",
5671
5739
  get: function get() {
5672
- return "0.2.1-alpha.0";
5740
+ return "0.2.1-alpha.14";
5673
5741
  }
5674
5742
  }, {
5675
5743
  key: "beforePlayerInit",
5676
5744
  value: function beforePlayerInit() {
5677
- var _this$player2, _this2 = this;
5745
+ var _this$player2, _this$player$config, _this$player$config$r, _this2 = this;
5678
5746
  this._init();
5679
5747
  if (!this._originSwitchFn) {
5680
5748
  this._originSwitchFn = this.player.switchURL.bind(this.player);
5681
5749
  }
5682
5750
  this.player.switchURL = this._onSwitchURL;
5683
- (_this$player2 = this.player) === null || _this$player2 === void 0 ? void 0 : _this$player2.useHooks("replay", function() {
5684
- var _this2$_rts;
5685
- return (_this2$_rts = _this2._rts) === null || _this2$_rts === void 0 ? void 0 : _this2$_rts.switchURL();
5686
- });
5751
+ (_this$player2 = this.player) === null || _this$player2 === void 0 ? void 0 : _this$player2.useHooks("replay", this._onSwitchURL);
5687
5752
  this.on(URL_CHANGE, this._onSwitchURL);
5688
5753
  this.on(DESTROY, this.destroy);
5689
- this._transErrorEvent();
5690
- this._transCoreEvent(EVENT.LOAD_START);
5691
- this._transCoreEvent(EVENT.LOAD_COMPLETE);
5692
- this._transCoreEvent(EVENT.TTFB);
5693
- this._transCoreEvent(EVENT.LOAD_RESPONSE_HEADERS);
5694
- this._transCoreEvent(EVENT.LOAD_RETRY);
5695
- this._transCoreEvent(EVENT.METADATA_PARSED);
5696
- this._transCoreEvent(EXTEND_EVENTS.RTC_STATE_CHANGE);
5754
+ if (typeof ((_this$player$config = this.player.config) === null || _this$player$config === void 0 ? void 0 : (_this$player$config$r = _this$player$config.rts) === null || _this$player$config$r === void 0 ? void 0 : _this$player$config$r.disconnectTime) !== "undefined") {
5755
+ this.on(PAUSE, function() {
5756
+ var _this2$_rts;
5757
+ if (!((_this2$_rts = _this2._rts) !== null && _this2$_rts !== void 0 && _this2$_rts._isReplacing)) {
5758
+ _this2._onPause();
5759
+ }
5760
+ });
5761
+ this.on(PLAY, function() {
5762
+ var _this2$_rts2;
5763
+ if (!((_this2$_rts2 = _this2._rts) !== null && _this2$_rts2 !== void 0 && _this2$_rts2._isReplacing)) {
5764
+ _this2._reInit();
5765
+ }
5766
+ });
5767
+ }
5768
+ this._bindRtsEvents();
5697
5769
  try {
5698
5770
  BasePlugin.defineGetterOrSetter(this.player, {
5699
5771
  __url: {
@@ -5715,20 +5787,52 @@
5715
5787
  }, {
5716
5788
  key: "getStats",
5717
5789
  value: function getStats2() {
5718
- var _this$_rts7;
5719
- return (_this$_rts7 = this._rts) === null || _this$_rts7 === void 0 ? void 0 : _this$_rts7.getStats();
5790
+ var _this$_rts8;
5791
+ return (_this$_rts8 = this._rts) === null || _this$_rts8 === void 0 ? void 0 : _this$_rts8.getStats();
5720
5792
  }
5721
5793
  }, {
5722
5794
  key: "getStatsSnapshoot",
5723
5795
  value: function getStatsSnapshoot2() {
5724
- var _this$_rts8;
5725
- return (_this$_rts8 = this._rts) === null || _this$_rts8 === void 0 ? void 0 : _this$_rts8.getStatsSnapshoot();
5796
+ var _this$_rts9;
5797
+ return (_this$_rts9 = this._rts) === null || _this$_rts9 === void 0 ? void 0 : _this$_rts9.getStatsSnapshoot();
5726
5798
  }
5727
5799
  }, {
5728
5800
  key: "getNetWorkInfo",
5729
5801
  value: function getNetWorkInfo() {
5730
- var _this$_rts9;
5731
- return (_this$_rts9 = this._rts) === null || _this$_rts9 === void 0 ? void 0 : _this$_rts9.networkStats;
5802
+ var _this$_rts10;
5803
+ return (_this$_rts10 = this._rts) === null || _this$_rts10 === void 0 ? void 0 : _this$_rts10.networkStats;
5804
+ }
5805
+ }, {
5806
+ key: "_clearDisconnectTimer",
5807
+ value: function _clearDisconnectTimer() {
5808
+ clearTimeout(this._disconnectTimer);
5809
+ this._disconnectTimer = void 0;
5810
+ }
5811
+ }, {
5812
+ key: "_closeAfterPause",
5813
+ value: function _closeAfterPause() {
5814
+ var _this$_rts11, _this$config, _this$_rts13;
5815
+ if (!((_this$_rts11 = this._rts) !== null && _this$_rts11 !== void 0 && _this$_rts11._pc)) {
5816
+ return;
5817
+ }
5818
+ if ((_this$config = this.config) !== null && _this$config !== void 0 && _this$config.seamlesslyReload) {
5819
+ var _this$_rts12;
5820
+ this._mediaStream = (_this$_rts12 = this._rts) === null || _this$_rts12 === void 0 ? void 0 : _this$_rts12._mediaStream;
5821
+ }
5822
+ (_this$_rts13 = this._rts) === null || _this$_rts13 === void 0 ? void 0 : _this$_rts13.destroy(true);
5823
+ this._rts = null;
5824
+ }
5825
+ }, {
5826
+ key: "_bindRtsEvents",
5827
+ value: function _bindRtsEvents() {
5828
+ this._transErrorEvent();
5829
+ this._transCoreEvent(EVENT.LOAD_START);
5830
+ this._transCoreEvent(EVENT.LOAD_COMPLETE);
5831
+ this._transCoreEvent(EVENT.TTFB);
5832
+ this._transCoreEvent(EVENT.LOAD_RESPONSE_HEADERS);
5833
+ this._transCoreEvent(EVENT.LOAD_RETRY);
5834
+ this._transCoreEvent(EVENT.METADATA_PARSED);
5835
+ this._transCoreEvent(EXTEND_EVENTS.RTC_STATE_CHANGE);
5732
5836
  }
5733
5837
  }, {
5734
5838
  key: "_transErrorEvent",