@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.
@@ -335,6 +335,14 @@ function _regeneratorRuntime$1() {
335
335
  }
336
336
  }, exports;
337
337
  }
338
+ function _typeof$2(obj) {
339
+ "@babel/helpers - typeof";
340
+ return _typeof$2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) {
341
+ return typeof obj2;
342
+ } : function(obj2) {
343
+ return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
344
+ }, _typeof$2(obj);
345
+ }
338
346
  function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
339
347
  try {
340
348
  var info = gen[key](arg);
@@ -5074,6 +5082,7 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5074
5082
  _defineProperty$2(_assertThisInitialized$1(_this), "_audioTransceicer", null);
5075
5083
  _defineProperty$2(_assertThisInitialized$1(_this), "_videoTransceicer", null);
5076
5084
  _defineProperty$2(_assertThisInitialized$1(_this), "_mediaStream", null);
5085
+ _defineProperty$2(_assertThisInitialized$1(_this), "_lastMediaStream", null);
5077
5086
  _defineProperty$2(_assertThisInitialized$1(_this), "_media", null);
5078
5087
  _defineProperty$2(_assertThisInitialized$1(_this), "_opts", null);
5079
5088
  _defineProperty$2(_assertThisInitialized$1(_this), "_loader", null);
@@ -5081,6 +5090,7 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5081
5090
  _defineProperty$2(_assertThisInitialized$1(_this), "_retry", 0);
5082
5091
  _defineProperty$2(_assertThisInitialized$1(_this), "_waitingTimer", 0);
5083
5092
  _defineProperty$2(_assertThisInitialized$1(_this), "_rctConnectStartTs", 0);
5093
+ _defineProperty$2(_assertThisInitialized$1(_this), "_isReplacing", false);
5084
5094
  _defineProperty$2(_assertThisInitialized$1(_this), "_onTrack", function(e) {
5085
5095
  logger.log("addTrack: ", e.track, e.streams);
5086
5096
  _this["_".concat(e.track.kind)] = e.track;
@@ -5131,6 +5141,9 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5131
5141
  }));
5132
5142
  _this._retry = _this._opts.retryCount;
5133
5143
  _this._bindMediaEvent();
5144
+ if (_this._opts.mediaStream && _this._opts.seamlesslyReload) {
5145
+ _this._lastMediaStream = _this._opts.mediaStream;
5146
+ }
5134
5147
  return _this;
5135
5148
  }
5136
5149
  _createClass$2(Rts2, [{
@@ -5174,9 +5187,9 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5174
5187
  }, {
5175
5188
  key: "load",
5176
5189
  value: function() {
5177
- var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee(url) {
5190
+ var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee(url, seamless) {
5178
5191
  var _this2 = this;
5179
- var lastPc;
5192
+ var _this$_pc3;
5180
5193
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
5181
5194
  while (1)
5182
5195
  switch (_context.prev = _context.next) {
@@ -5184,39 +5197,43 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5184
5197
  this._disconnect();
5185
5198
  this._url = url;
5186
5199
  this._retry = this._opts.retryCount;
5187
- lastPc = this._pc;
5188
- if (lastPc) {
5189
- lastPc.close();
5200
+ if (seamless) {
5201
+ this._lastPc = this._pc;
5202
+ } else {
5203
+ (_this$_pc3 = this._pc) === null || _this$_pc3 === void 0 ? void 0 : _this$_pc3.close();
5190
5204
  }
5191
- _context.prev = 5;
5205
+ _context.prev = 4;
5192
5206
  this._pc = new RTCPeerConnection();
5193
5207
  this._bindRTCEvents();
5194
- _context.next = 10;
5208
+ _context.next = 9;
5195
5209
  return this._connect(url);
5196
- case 10:
5197
- _context.next = 15;
5210
+ case 9:
5211
+ _context.next = 14;
5198
5212
  break;
5199
- case 12:
5200
- _context.prev = 12;
5201
- _context.t0 = _context["catch"](5);
5213
+ case 11:
5214
+ _context.prev = 11;
5215
+ _context.t0 = _context["catch"](4);
5202
5216
  setTimeout(function() {
5203
5217
  return _this2._emitError(StreamingError.create(ERR.OTHER, null, _context.t0));
5204
5218
  });
5205
- case 15:
5219
+ case 14:
5206
5220
  case "end":
5207
5221
  return _context.stop();
5208
5222
  }
5209
- }, _callee, this, [[5, 12]]);
5223
+ }, _callee, this, [[4, 11]]);
5210
5224
  }));
5211
- function load(_x) {
5225
+ function load(_x, _x2) {
5212
5226
  return _load.apply(this, arguments);
5213
5227
  }
5214
5228
  return load;
5215
5229
  }()
5216
5230
  }, {
5217
5231
  key: "switchURL",
5218
- value: function switchURL(url) {
5219
- this.load(url || this._url);
5232
+ value: function switchURL(url, seamless) {
5233
+ if (seamless) {
5234
+ this._lastMediaStream = this._mediaStream;
5235
+ }
5236
+ this.load(url || this._url, seamless);
5220
5237
  }
5221
5238
  }, {
5222
5239
  key: "_bindRTCEvents",
@@ -5242,6 +5259,7 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5242
5259
  _this3.load(_this3._url);
5243
5260
  }
5244
5261
  if (pc.connectionState === "connected") {
5262
+ _this3._closeLastPc();
5245
5263
  _this3._handleMediaStream();
5246
5264
  _this3.emit(EVENT.TTFB, {
5247
5265
  url: _this3._url,
@@ -5254,18 +5272,29 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5254
5272
  }, {
5255
5273
  key: "_handleMediaStream",
5256
5274
  value: function _handleMediaStream() {
5257
- if (this._opts.mediaStream && this._opts.seamlesslyReload) {
5258
- var videoTrack = this._opts.mediaStream.getVideoTracks()[0];
5259
- var audioTrack = this._opts.mediaStream.getAudioTracks()[0];
5275
+ var _this4 = this;
5276
+ if (this._lastMediaStream) {
5277
+ var _this$_media$play;
5278
+ var videoTrack = this._lastMediaStream.getVideoTracks()[0];
5279
+ var audioTrack = this._lastMediaStream.getAudioTracks()[0];
5260
5280
  if (videoTrack) {
5261
- this._opts.mediaStream.removeTrack(videoTrack);
5281
+ this._lastMediaStream.removeTrack(videoTrack);
5262
5282
  }
5263
5283
  if (audioTrack) {
5264
- this._opts.mediaStream.removeTrack(audioTrack);
5284
+ this._lastMediaStream.removeTrack(audioTrack);
5265
5285
  }
5266
- this._mediaStream = this._opts.mediaStream;
5286
+ this._mediaStream = this._lastMediaStream;
5287
+ this._mediaStream.addTrack(this._audio);
5288
+ this._mediaStream.addTrack(this._video);
5289
+ this._isReplacing = true;
5290
+ this._media.pause();
5291
+ (_this$_media$play = this._media.play()) === null || _this$_media$play === void 0 ? void 0 : _this$_media$play.finally(function() {
5292
+ _this4._isReplacing = false;
5293
+ });
5267
5294
  } else {
5268
5295
  this._mediaStream = new MediaStream();
5296
+ this._mediaStream.addTrack(this._audio);
5297
+ this._mediaStream.addTrack(this._video);
5269
5298
  this._media.srcObject = this._mediaStream;
5270
5299
  var req = this._media.play();
5271
5300
  if (req && req.catch) {
@@ -5273,8 +5302,6 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5273
5302
  });
5274
5303
  }
5275
5304
  }
5276
- this._mediaStream.addTrack(this._audio);
5277
- this._mediaStream.addTrack(this._video);
5278
5305
  }
5279
5306
  }, {
5280
5307
  key: "_bindMediaEvent",
@@ -5430,14 +5457,20 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5430
5457
  }
5431
5458
  return _connect;
5432
5459
  }()
5460
+ }, {
5461
+ key: "_closeLastPc",
5462
+ value: function _closeLastPc() {
5463
+ if (this._lastPc) {
5464
+ this._lastPc.close();
5465
+ this._lastPc = null;
5466
+ }
5467
+ }
5433
5468
  }, {
5434
5469
  key: "_disconnect",
5435
5470
  value: function _disconnect() {
5436
- var _this$_loader, _this$_networkEvaluat2, _this$_videoTransceic, _this$_audioTransceic;
5471
+ var _this$_loader, _this$_networkEvaluat2;
5437
5472
  (_this$_loader = this._loader) === null || _this$_loader === void 0 ? void 0 : _this$_loader.cancel();
5438
5473
  (_this$_networkEvaluat2 = this._networkEvaluate) === null || _this$_networkEvaluat2 === void 0 ? void 0 : _this$_networkEvaluat2.destroy();
5439
- (_this$_videoTransceic = this._videoTransceicer) === null || _this$_videoTransceic === void 0 ? void 0 : _this$_videoTransceic.stop();
5440
- (_this$_audioTransceic = this._audioTransceicer) === null || _this$_audioTransceic === void 0 ? void 0 : _this$_audioTransceic.stop();
5441
5474
  this._audioTransceicer = null;
5442
5475
  this._videoTransceicer = null;
5443
5476
  this._mediaStream = null;
@@ -5446,6 +5479,7 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5446
5479
  }, {
5447
5480
  key: "_emitError",
5448
5481
  value: function _emitError(error) {
5482
+ this._closeLastPc();
5449
5483
  this.emit(EVENT.ERROR, error);
5450
5484
  }
5451
5485
  }, {
@@ -5457,6 +5491,7 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5457
5491
  if (this._media && !((_this$_opts = this._opts) !== null && _this$_opts !== void 0 && _this$_opts.seamlesslyReload)) {
5458
5492
  this._media.srcObject = null;
5459
5493
  }
5494
+ this._closeLastPc();
5460
5495
  if (this._pc) {
5461
5496
  this._pc.close();
5462
5497
  }
@@ -5557,26 +5592,26 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5557
5592
  _defineProperty$2(_assertThisInitialized$1(_this), "_mediaStream", null);
5558
5593
  _defineProperty$2(_assertThisInitialized$1(_this), "_rtsOpts", null);
5559
5594
  _defineProperty$2(_assertThisInitialized$1(_this), "_onPause", function() {
5560
- var _this$_rts, _this$config, _this$_rts3;
5561
- if (!((_this$_rts = _this._rts) !== null && _this$_rts !== void 0 && _this$_rts._pc)) {
5595
+ var _this$_rts, _this$_rts2, _this$config, _this$_rts4;
5596
+ 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) {
5562
5597
  return;
5563
5598
  }
5564
5599
  if ((_this$config = _this.config) !== null && _this$config !== void 0 && _this$config.seamlesslyReload) {
5565
- var _this$_rts2;
5566
- _this._mediaStream = (_this$_rts2 = _this._rts) === null || _this$_rts2 === void 0 ? void 0 : _this$_rts2._mediaStream;
5600
+ var _this$_rts3;
5601
+ _this._mediaStream = (_this$_rts3 = _this._rts) === null || _this$_rts3 === void 0 ? void 0 : _this$_rts3._mediaStream;
5567
5602
  }
5568
- (_this$_rts3 = _this._rts) === null || _this$_rts3 === void 0 ? void 0 : _this$_rts3.destroy();
5603
+ (_this$_rts4 = _this._rts) === null || _this$_rts4 === void 0 ? void 0 : _this$_rts4.destroy();
5569
5604
  });
5570
5605
  _defineProperty$2(_assertThisInitialized$1(_this), "_onPlay", function() {
5571
- var _this$_rts4;
5572
- if ((_this$_rts4 = _this._rts) !== null && _this$_rts4 !== void 0 && _this$_rts4._pc) {
5606
+ var _this$_rts5, _this$_rts6;
5607
+ 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) {
5573
5608
  return;
5574
5609
  }
5575
5610
  _this._init();
5576
5611
  });
5577
5612
  _defineProperty$2(_assertThisInitialized$1(_this), "_init", function() {
5578
- var _this$_rts5;
5579
- (_this$_rts5 = _this._rts) === null || _this$_rts5 === void 0 ? void 0 : _this$_rts5.destroy();
5613
+ var _this$_rts7;
5614
+ (_this$_rts7 = _this._rts) === null || _this$_rts7 === void 0 ? void 0 : _this$_rts7.destroy();
5580
5615
  var config = _this.player.config;
5581
5616
  var rtsOpts = config.rts || {};
5582
5617
  _this._rtsOpts = rtsOpts;
@@ -5593,36 +5628,39 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5593
5628
  }, rtsOpts));
5594
5629
  _this._rts.load(config.url);
5595
5630
  });
5596
- _defineProperty$2(_assertThisInitialized$1(_this), "_onSwitchURL", function(url) {
5631
+ _defineProperty$2(_assertThisInitialized$1(_this), "_onSwitchURL", function(url, seamless) {
5597
5632
  if (_this._rts) {
5633
+ if (_typeof$2(seamless) === "object") {
5634
+ seamless = seamless.seamless;
5635
+ }
5598
5636
  _this.player.config.url = url;
5599
- _this._rts.switchURL(url);
5637
+ _this._rts.switchURL(url, seamless);
5600
5638
  }
5601
5639
  });
5602
5640
  _defineProperty$2(_assertThisInitialized$1(_this), "destroy", function() {
5603
- var _this$_rts6;
5641
+ var _this$_rts8;
5604
5642
  _this.player.switchURL = _this._originSwitchFn;
5605
- (_this$_rts6 = _this._rts) === null || _this$_rts6 === void 0 ? void 0 : _this$_rts6.destroy();
5643
+ (_this$_rts8 = _this._rts) === null || _this$_rts8 === void 0 ? void 0 : _this$_rts8.destroy();
5606
5644
  });
5607
5645
  return _this;
5608
5646
  }
5609
5647
  _createClass$2(RtsPlugin2, [{
5610
5648
  key: "pc",
5611
5649
  get: function get() {
5612
- var _this$_rts7;
5613
- return (_this$_rts7 = this._rts) === null || _this$_rts7 === void 0 ? void 0 : _this$_rts7.pc;
5650
+ var _this$_rts9;
5651
+ return (_this$_rts9 = this._rts) === null || _this$_rts9 === void 0 ? void 0 : _this$_rts9.pc;
5614
5652
  }
5615
5653
  }, {
5616
5654
  key: "videoTrack",
5617
5655
  get: function get() {
5618
- var _this$_rts8;
5619
- return (_this$_rts8 = this._rts) === null || _this$_rts8 === void 0 ? void 0 : _this$_rts8.videoTack;
5656
+ var _this$_rts10;
5657
+ return (_this$_rts10 = this._rts) === null || _this$_rts10 === void 0 ? void 0 : _this$_rts10.videoTack;
5620
5658
  }
5621
5659
  }, {
5622
5660
  key: "audioTrack",
5623
5661
  get: function get() {
5624
- var _this$_rts9;
5625
- return (_this$_rts9 = this._rts) === null || _this$_rts9 === void 0 ? void 0 : _this$_rts9.audioTrack;
5662
+ var _this$_rts11;
5663
+ return (_this$_rts11 = this._rts) === null || _this$_rts11 === void 0 ? void 0 : _this$_rts11.audioTrack;
5626
5664
  }
5627
5665
  }, {
5628
5666
  key: "core",
@@ -5632,13 +5670,13 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5632
5670
  }, {
5633
5671
  key: "loader",
5634
5672
  get: function get() {
5635
- var _this$_rts10;
5636
- return (_this$_rts10 = this._rts) === null || _this$_rts10 === void 0 ? void 0 : _this$_rts10.loader;
5673
+ var _this$_rts12;
5674
+ return (_this$_rts12 = this._rts) === null || _this$_rts12 === void 0 ? void 0 : _this$_rts12.loader;
5637
5675
  }
5638
5676
  }, {
5639
5677
  key: "version",
5640
5678
  get: function get() {
5641
- return "0.2.1-alpha.2";
5679
+ return "0.2.1-alpha.4";
5642
5680
  }
5643
5681
  }, {
5644
5682
  key: "beforePlayerInit",
@@ -5688,20 +5726,20 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5688
5726
  }, {
5689
5727
  key: "getStats",
5690
5728
  value: function getStats2() {
5691
- var _this$_rts11;
5692
- return (_this$_rts11 = this._rts) === null || _this$_rts11 === void 0 ? void 0 : _this$_rts11.getStats();
5729
+ var _this$_rts13;
5730
+ return (_this$_rts13 = this._rts) === null || _this$_rts13 === void 0 ? void 0 : _this$_rts13.getStats();
5693
5731
  }
5694
5732
  }, {
5695
5733
  key: "getStatsSnapshoot",
5696
5734
  value: function getStatsSnapshoot2() {
5697
- var _this$_rts12;
5698
- return (_this$_rts12 = this._rts) === null || _this$_rts12 === void 0 ? void 0 : _this$_rts12.getStatsSnapshoot();
5735
+ var _this$_rts14;
5736
+ return (_this$_rts14 = this._rts) === null || _this$_rts14 === void 0 ? void 0 : _this$_rts14.getStatsSnapshoot();
5699
5737
  }
5700
5738
  }, {
5701
5739
  key: "getNetWorkInfo",
5702
5740
  value: function getNetWorkInfo() {
5703
- var _this$_rts13;
5704
- return (_this$_rts13 = this._rts) === null || _this$_rts13 === void 0 ? void 0 : _this$_rts13.networkStats;
5741
+ var _this$_rts15;
5742
+ return (_this$_rts15 = this._rts) === null || _this$_rts15 === void 0 ? void 0 : _this$_rts15.networkStats;
5705
5743
  }
5706
5744
  }, {
5707
5745
  key: "_transErrorEvent",