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