@volcengine/veplayer-plugin 2.4.2-rc.0 → 2.4.2-rc.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volcengine/veplayer-plugin",
3
- "version": "2.4.2-rc.0",
3
+ "version": "2.4.2-rc.1",
4
4
  "main": "./umd/index.production.js",
5
5
  "module": "./esm/index.production.js",
6
6
  "browser": "./umd/index.production.js",
@@ -339,6 +339,14 @@
339
339
  }
340
340
  }, exports3;
341
341
  }
342
+ function _typeof$2(obj) {
343
+ "@babel/helpers - typeof";
344
+ return _typeof$2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
345
+ return typeof obj2;
346
+ } : function(obj2) {
347
+ return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
348
+ }, _typeof$2(obj);
349
+ }
342
350
  function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
343
351
  try {
344
352
  var info = gen[key](arg);
@@ -5078,6 +5086,7 @@
5078
5086
  _defineProperty$2(_assertThisInitialized$1(_this), "_audioTransceicer", null);
5079
5087
  _defineProperty$2(_assertThisInitialized$1(_this), "_videoTransceicer", null);
5080
5088
  _defineProperty$2(_assertThisInitialized$1(_this), "_mediaStream", null);
5089
+ _defineProperty$2(_assertThisInitialized$1(_this), "_lastMediaStream", null);
5081
5090
  _defineProperty$2(_assertThisInitialized$1(_this), "_media", null);
5082
5091
  _defineProperty$2(_assertThisInitialized$1(_this), "_opts", null);
5083
5092
  _defineProperty$2(_assertThisInitialized$1(_this), "_loader", null);
@@ -5085,6 +5094,7 @@
5085
5094
  _defineProperty$2(_assertThisInitialized$1(_this), "_retry", 0);
5086
5095
  _defineProperty$2(_assertThisInitialized$1(_this), "_waitingTimer", 0);
5087
5096
  _defineProperty$2(_assertThisInitialized$1(_this), "_rctConnectStartTs", 0);
5097
+ _defineProperty$2(_assertThisInitialized$1(_this), "_isReplacing", false);
5088
5098
  _defineProperty$2(_assertThisInitialized$1(_this), "_onTrack", function(e) {
5089
5099
  logger.log("addTrack: ", e.track, e.streams);
5090
5100
  _this["_".concat(e.track.kind)] = e.track;
@@ -5135,6 +5145,9 @@
5135
5145
  }));
5136
5146
  _this._retry = _this._opts.retryCount;
5137
5147
  _this._bindMediaEvent();
5148
+ if (_this._opts.mediaStream && _this._opts.seamlesslyReload) {
5149
+ _this._lastMediaStream = _this._opts.mediaStream;
5150
+ }
5138
5151
  return _this;
5139
5152
  }
5140
5153
  _createClass$2(Rts2, [{
@@ -5178,9 +5191,9 @@
5178
5191
  }, {
5179
5192
  key: "load",
5180
5193
  value: function() {
5181
- var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee(url) {
5194
+ var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee(url, seamless) {
5182
5195
  var _this2 = this;
5183
- var lastPc;
5196
+ var _this$_pc3;
5184
5197
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
5185
5198
  while (1)
5186
5199
  switch (_context.prev = _context.next) {
@@ -5188,39 +5201,43 @@
5188
5201
  this._disconnect();
5189
5202
  this._url = url;
5190
5203
  this._retry = this._opts.retryCount;
5191
- lastPc = this._pc;
5192
- if (lastPc) {
5193
- lastPc.close();
5204
+ if (seamless) {
5205
+ this._lastPc = this._pc;
5206
+ } else {
5207
+ (_this$_pc3 = this._pc) === null || _this$_pc3 === void 0 ? void 0 : _this$_pc3.close();
5194
5208
  }
5195
- _context.prev = 5;
5209
+ _context.prev = 4;
5196
5210
  this._pc = new RTCPeerConnection();
5197
5211
  this._bindRTCEvents();
5198
- _context.next = 10;
5212
+ _context.next = 9;
5199
5213
  return this._connect(url);
5200
- case 10:
5201
- _context.next = 15;
5214
+ case 9:
5215
+ _context.next = 14;
5202
5216
  break;
5203
- case 12:
5204
- _context.prev = 12;
5205
- _context.t0 = _context["catch"](5);
5217
+ case 11:
5218
+ _context.prev = 11;
5219
+ _context.t0 = _context["catch"](4);
5206
5220
  setTimeout(function() {
5207
5221
  return _this2._emitError(StreamingError.create(ERR.OTHER, null, _context.t0));
5208
5222
  });
5209
- case 15:
5223
+ case 14:
5210
5224
  case "end":
5211
5225
  return _context.stop();
5212
5226
  }
5213
- }, _callee, this, [[5, 12]]);
5227
+ }, _callee, this, [[4, 11]]);
5214
5228
  }));
5215
- function load(_x) {
5229
+ function load(_x, _x2) {
5216
5230
  return _load.apply(this, arguments);
5217
5231
  }
5218
5232
  return load;
5219
5233
  }()
5220
5234
  }, {
5221
5235
  key: "switchURL",
5222
- value: function switchURL(url) {
5223
- this.load(url || this._url);
5236
+ value: function switchURL(url, seamless) {
5237
+ if (seamless) {
5238
+ this._lastMediaStream = this._mediaStream;
5239
+ }
5240
+ this.load(url || this._url, seamless);
5224
5241
  }
5225
5242
  }, {
5226
5243
  key: "_bindRTCEvents",
@@ -5246,6 +5263,7 @@
5246
5263
  _this3.load(_this3._url);
5247
5264
  }
5248
5265
  if (pc.connectionState === "connected") {
5266
+ _this3._closeLastPc();
5249
5267
  _this3._handleMediaStream();
5250
5268
  _this3.emit(EVENT.TTFB, {
5251
5269
  url: _this3._url,
@@ -5258,18 +5276,29 @@
5258
5276
  }, {
5259
5277
  key: "_handleMediaStream",
5260
5278
  value: function _handleMediaStream() {
5261
- if (this._opts.mediaStream && this._opts.seamlesslyReload) {
5262
- var videoTrack = this._opts.mediaStream.getVideoTracks()[0];
5263
- var audioTrack = this._opts.mediaStream.getAudioTracks()[0];
5279
+ var _this4 = this;
5280
+ if (this._lastMediaStream) {
5281
+ var _this$_media$play;
5282
+ var videoTrack = this._lastMediaStream.getVideoTracks()[0];
5283
+ var audioTrack = this._lastMediaStream.getAudioTracks()[0];
5264
5284
  if (videoTrack) {
5265
- this._opts.mediaStream.removeTrack(videoTrack);
5285
+ this._lastMediaStream.removeTrack(videoTrack);
5266
5286
  }
5267
5287
  if (audioTrack) {
5268
- this._opts.mediaStream.removeTrack(audioTrack);
5288
+ this._lastMediaStream.removeTrack(audioTrack);
5269
5289
  }
5270
- this._mediaStream = this._opts.mediaStream;
5290
+ this._mediaStream = this._lastMediaStream;
5291
+ this._mediaStream.addTrack(this._audio);
5292
+ this._mediaStream.addTrack(this._video);
5293
+ this._isReplacing = true;
5294
+ this._media.pause();
5295
+ (_this$_media$play = this._media.play()) === null || _this$_media$play === void 0 ? void 0 : _this$_media$play.finally(function() {
5296
+ _this4._isReplacing = false;
5297
+ });
5271
5298
  } else {
5272
5299
  this._mediaStream = new MediaStream();
5300
+ this._mediaStream.addTrack(this._audio);
5301
+ this._mediaStream.addTrack(this._video);
5273
5302
  this._media.srcObject = this._mediaStream;
5274
5303
  var req = this._media.play();
5275
5304
  if (req && req.catch) {
@@ -5277,8 +5306,6 @@
5277
5306
  });
5278
5307
  }
5279
5308
  }
5280
- this._mediaStream.addTrack(this._audio);
5281
- this._mediaStream.addTrack(this._video);
5282
5309
  }
5283
5310
  }, {
5284
5311
  key: "_bindMediaEvent",
@@ -5434,14 +5461,20 @@
5434
5461
  }
5435
5462
  return _connect;
5436
5463
  }()
5464
+ }, {
5465
+ key: "_closeLastPc",
5466
+ value: function _closeLastPc() {
5467
+ if (this._lastPc) {
5468
+ this._lastPc.close();
5469
+ this._lastPc = null;
5470
+ }
5471
+ }
5437
5472
  }, {
5438
5473
  key: "_disconnect",
5439
5474
  value: function _disconnect() {
5440
- var _this$_loader, _this$_networkEvaluat2, _this$_videoTransceic, _this$_audioTransceic;
5475
+ var _this$_loader, _this$_networkEvaluat2;
5441
5476
  (_this$_loader = this._loader) === null || _this$_loader === void 0 ? void 0 : _this$_loader.cancel();
5442
5477
  (_this$_networkEvaluat2 = this._networkEvaluate) === null || _this$_networkEvaluat2 === void 0 ? void 0 : _this$_networkEvaluat2.destroy();
5443
- (_this$_videoTransceic = this._videoTransceicer) === null || _this$_videoTransceic === void 0 ? void 0 : _this$_videoTransceic.stop();
5444
- (_this$_audioTransceic = this._audioTransceicer) === null || _this$_audioTransceic === void 0 ? void 0 : _this$_audioTransceic.stop();
5445
5478
  this._audioTransceicer = null;
5446
5479
  this._videoTransceicer = null;
5447
5480
  this._mediaStream = null;
@@ -5450,6 +5483,7 @@
5450
5483
  }, {
5451
5484
  key: "_emitError",
5452
5485
  value: function _emitError(error) {
5486
+ this._closeLastPc();
5453
5487
  this.emit(EVENT.ERROR, error);
5454
5488
  }
5455
5489
  }, {
@@ -5461,6 +5495,7 @@
5461
5495
  if (this._media && !((_this$_opts = this._opts) !== null && _this$_opts !== void 0 && _this$_opts.seamlesslyReload)) {
5462
5496
  this._media.srcObject = null;
5463
5497
  }
5498
+ this._closeLastPc();
5464
5499
  if (this._pc) {
5465
5500
  this._pc.close();
5466
5501
  }
@@ -5561,26 +5596,26 @@
5561
5596
  _defineProperty$2(_assertThisInitialized$1(_this), "_mediaStream", null);
5562
5597
  _defineProperty$2(_assertThisInitialized$1(_this), "_rtsOpts", null);
5563
5598
  _defineProperty$2(_assertThisInitialized$1(_this), "_onPause", function() {
5564
- var _this$_rts, _this$config, _this$_rts3;
5565
- if (!((_this$_rts = _this._rts) !== null && _this$_rts !== void 0 && _this$_rts._pc)) {
5599
+ var _this$_rts, _this$_rts2, _this$config, _this$_rts4;
5600
+ if (!((_this$_rts = _this._rts) !== null && _this$_rts !== void 0 && _this$_rts._pc) || (_this$_rts2 = _this._rts) !== null && _this$_rts2 !== void 0 && _this$_rts2._isReplacing) {
5566
5601
  return;
5567
5602
  }
5568
5603
  if ((_this$config = _this.config) !== null && _this$config !== void 0 && _this$config.seamlesslyReload) {
5569
- var _this$_rts2;
5570
- _this._mediaStream = (_this$_rts2 = _this._rts) === null || _this$_rts2 === void 0 ? void 0 : _this$_rts2._mediaStream;
5604
+ var _this$_rts3;
5605
+ _this._mediaStream = (_this$_rts3 = _this._rts) === null || _this$_rts3 === void 0 ? void 0 : _this$_rts3._mediaStream;
5571
5606
  }
5572
- (_this$_rts3 = _this._rts) === null || _this$_rts3 === void 0 ? void 0 : _this$_rts3.destroy();
5607
+ (_this$_rts4 = _this._rts) === null || _this$_rts4 === void 0 ? void 0 : _this$_rts4.destroy();
5573
5608
  });
5574
5609
  _defineProperty$2(_assertThisInitialized$1(_this), "_onPlay", function() {
5575
- var _this$_rts4;
5576
- if ((_this$_rts4 = _this._rts) !== null && _this$_rts4 !== void 0 && _this$_rts4._pc) {
5610
+ var _this$_rts5, _this$_rts6;
5611
+ if ((_this$_rts5 = _this._rts) !== null && _this$_rts5 !== void 0 && _this$_rts5._pc || (_this$_rts6 = _this._rts) !== null && _this$_rts6 !== void 0 && _this$_rts6._isReplacing) {
5577
5612
  return;
5578
5613
  }
5579
5614
  _this._init();
5580
5615
  });
5581
5616
  _defineProperty$2(_assertThisInitialized$1(_this), "_init", function() {
5582
- var _this$_rts5;
5583
- (_this$_rts5 = _this._rts) === null || _this$_rts5 === void 0 ? void 0 : _this$_rts5.destroy();
5617
+ var _this$_rts7;
5618
+ (_this$_rts7 = _this._rts) === null || _this$_rts7 === void 0 ? void 0 : _this$_rts7.destroy();
5584
5619
  var config = _this.player.config;
5585
5620
  var rtsOpts = config.rts || {};
5586
5621
  _this._rtsOpts = rtsOpts;
@@ -5597,36 +5632,39 @@
5597
5632
  }, rtsOpts));
5598
5633
  _this._rts.load(config.url);
5599
5634
  });
5600
- _defineProperty$2(_assertThisInitialized$1(_this), "_onSwitchURL", function(url) {
5635
+ _defineProperty$2(_assertThisInitialized$1(_this), "_onSwitchURL", function(url, seamless) {
5601
5636
  if (_this._rts) {
5637
+ if (_typeof$2(seamless) === "object") {
5638
+ seamless = seamless.seamless;
5639
+ }
5602
5640
  _this.player.config.url = url;
5603
- _this._rts.switchURL(url);
5641
+ _this._rts.switchURL(url, seamless);
5604
5642
  }
5605
5643
  });
5606
5644
  _defineProperty$2(_assertThisInitialized$1(_this), "destroy", function() {
5607
- var _this$_rts6;
5645
+ var _this$_rts8;
5608
5646
  _this.player.switchURL = _this._originSwitchFn;
5609
- (_this$_rts6 = _this._rts) === null || _this$_rts6 === void 0 ? void 0 : _this$_rts6.destroy();
5647
+ (_this$_rts8 = _this._rts) === null || _this$_rts8 === void 0 ? void 0 : _this$_rts8.destroy();
5610
5648
  });
5611
5649
  return _this;
5612
5650
  }
5613
5651
  _createClass$2(RtsPlugin2, [{
5614
5652
  key: "pc",
5615
5653
  get: function get() {
5616
- var _this$_rts7;
5617
- return (_this$_rts7 = this._rts) === null || _this$_rts7 === void 0 ? void 0 : _this$_rts7.pc;
5654
+ var _this$_rts9;
5655
+ return (_this$_rts9 = this._rts) === null || _this$_rts9 === void 0 ? void 0 : _this$_rts9.pc;
5618
5656
  }
5619
5657
  }, {
5620
5658
  key: "videoTrack",
5621
5659
  get: function get() {
5622
- var _this$_rts8;
5623
- return (_this$_rts8 = this._rts) === null || _this$_rts8 === void 0 ? void 0 : _this$_rts8.videoTack;
5660
+ var _this$_rts10;
5661
+ return (_this$_rts10 = this._rts) === null || _this$_rts10 === void 0 ? void 0 : _this$_rts10.videoTack;
5624
5662
  }
5625
5663
  }, {
5626
5664
  key: "audioTrack",
5627
5665
  get: function get() {
5628
- var _this$_rts9;
5629
- return (_this$_rts9 = this._rts) === null || _this$_rts9 === void 0 ? void 0 : _this$_rts9.audioTrack;
5666
+ var _this$_rts11;
5667
+ return (_this$_rts11 = this._rts) === null || _this$_rts11 === void 0 ? void 0 : _this$_rts11.audioTrack;
5630
5668
  }
5631
5669
  }, {
5632
5670
  key: "core",
@@ -5636,13 +5674,13 @@
5636
5674
  }, {
5637
5675
  key: "loader",
5638
5676
  get: function get() {
5639
- var _this$_rts10;
5640
- return (_this$_rts10 = this._rts) === null || _this$_rts10 === void 0 ? void 0 : _this$_rts10.loader;
5677
+ var _this$_rts12;
5678
+ return (_this$_rts12 = this._rts) === null || _this$_rts12 === void 0 ? void 0 : _this$_rts12.loader;
5641
5679
  }
5642
5680
  }, {
5643
5681
  key: "version",
5644
5682
  get: function get() {
5645
- return "0.2.1-alpha.2";
5683
+ return "0.2.1-alpha.4";
5646
5684
  }
5647
5685
  }, {
5648
5686
  key: "beforePlayerInit",
@@ -5692,20 +5730,20 @@
5692
5730
  }, {
5693
5731
  key: "getStats",
5694
5732
  value: function getStats2() {
5695
- var _this$_rts11;
5696
- return (_this$_rts11 = this._rts) === null || _this$_rts11 === void 0 ? void 0 : _this$_rts11.getStats();
5733
+ var _this$_rts13;
5734
+ return (_this$_rts13 = this._rts) === null || _this$_rts13 === void 0 ? void 0 : _this$_rts13.getStats();
5697
5735
  }
5698
5736
  }, {
5699
5737
  key: "getStatsSnapshoot",
5700
5738
  value: function getStatsSnapshoot2() {
5701
- var _this$_rts12;
5702
- return (_this$_rts12 = this._rts) === null || _this$_rts12 === void 0 ? void 0 : _this$_rts12.getStatsSnapshoot();
5739
+ var _this$_rts14;
5740
+ return (_this$_rts14 = this._rts) === null || _this$_rts14 === void 0 ? void 0 : _this$_rts14.getStatsSnapshoot();
5703
5741
  }
5704
5742
  }, {
5705
5743
  key: "getNetWorkInfo",
5706
5744
  value: function getNetWorkInfo() {
5707
- var _this$_rts13;
5708
- return (_this$_rts13 = this._rts) === null || _this$_rts13 === void 0 ? void 0 : _this$_rts13.networkStats;
5745
+ var _this$_rts15;
5746
+ return (_this$_rts15 = this._rts) === null || _this$_rts15 === void 0 ? void 0 : _this$_rts15.networkStats;
5709
5747
  }
5710
5748
  }, {
5711
5749
  key: "_transErrorEvent",