@byteplus/veplayer-plugin 2.4.1-rc.1 → 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.
@@ -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);
@@ -1534,7 +1542,7 @@
1534
1542
  }
1535
1543
  return offsetTime;
1536
1544
  };
1537
- var version = "3.0.20-rc.3";
1545
+ var version = "3.0.19-rc.0";
1538
1546
  var ERROR_MAP = {
1539
1547
  1: 5101,
1540
1548
  2: 5102,
@@ -1598,6 +1606,8 @@
1598
1606
  }
1599
1607
  }
1600
1608
  );
1609
+ var PLAY = "play";
1610
+ var PAUSE = "pause";
1601
1611
  var ERROR = "error";
1602
1612
  var DESTROY = "destroy";
1603
1613
  var URL_CHANGE = "urlchange";
@@ -4812,7 +4822,8 @@
4812
4822
  loadTimeout: 5e3,
4813
4823
  stallInterval: 400,
4814
4824
  networkEvaluateInterval: 1e3,
4815
- delayHint: 0
4825
+ delayHint: 0,
4826
+ seamlesslyReload: false
4816
4827
  }, opts);
4817
4828
  }
4818
4829
  function _getStats(stats) {
@@ -5075,6 +5086,7 @@
5075
5086
  _defineProperty$2(_assertThisInitialized$1(_this), "_audioTransceicer", null);
5076
5087
  _defineProperty$2(_assertThisInitialized$1(_this), "_videoTransceicer", null);
5077
5088
  _defineProperty$2(_assertThisInitialized$1(_this), "_mediaStream", null);
5089
+ _defineProperty$2(_assertThisInitialized$1(_this), "_lastMediaStream", null);
5078
5090
  _defineProperty$2(_assertThisInitialized$1(_this), "_media", null);
5079
5091
  _defineProperty$2(_assertThisInitialized$1(_this), "_opts", null);
5080
5092
  _defineProperty$2(_assertThisInitialized$1(_this), "_loader", null);
@@ -5082,19 +5094,10 @@
5082
5094
  _defineProperty$2(_assertThisInitialized$1(_this), "_retry", 0);
5083
5095
  _defineProperty$2(_assertThisInitialized$1(_this), "_waitingTimer", 0);
5084
5096
  _defineProperty$2(_assertThisInitialized$1(_this), "_rctConnectStartTs", 0);
5097
+ _defineProperty$2(_assertThisInitialized$1(_this), "_isReplacing", false);
5085
5098
  _defineProperty$2(_assertThisInitialized$1(_this), "_onTrack", function(e) {
5086
5099
  logger.log("addTrack: ", e.track, e.streams);
5087
5100
  _this["_".concat(e.track.kind)] = e.track;
5088
- if (!_this._mediaStream) {
5089
- _this._mediaStream = new MediaStream();
5090
- _this._media.srcObject = _this._mediaStream;
5091
- var req = _this._media.play();
5092
- if (req && req.catch) {
5093
- req.catch(function(e2) {
5094
- });
5095
- }
5096
- }
5097
- _this._mediaStream.addTrack(e.track);
5098
5101
  });
5099
5102
  _defineProperty$2(_assertThisInitialized$1(_this), "_mockWaitingByTimeupdate", function() {
5100
5103
  var _this$_pc, _this$_pc2;
@@ -5142,6 +5145,9 @@
5142
5145
  }));
5143
5146
  _this._retry = _this._opts.retryCount;
5144
5147
  _this._bindMediaEvent();
5148
+ if (_this._opts.mediaStream && _this._opts.seamlesslyReload) {
5149
+ _this._lastMediaStream = _this._opts.mediaStream;
5150
+ }
5145
5151
  return _this;
5146
5152
  }
5147
5153
  _createClass$2(Rts2, [{
@@ -5185,9 +5191,9 @@
5185
5191
  }, {
5186
5192
  key: "load",
5187
5193
  value: function() {
5188
- var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee(url) {
5194
+ var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee(url, seamless) {
5189
5195
  var _this2 = this;
5190
- var lastPc;
5196
+ var _this$_pc3;
5191
5197
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
5192
5198
  while (1)
5193
5199
  switch (_context.prev = _context.next) {
@@ -5195,39 +5201,43 @@
5195
5201
  this._disconnect();
5196
5202
  this._url = url;
5197
5203
  this._retry = this._opts.retryCount;
5198
- lastPc = this._pc;
5199
- if (lastPc) {
5200
- 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();
5201
5208
  }
5202
- _context.prev = 5;
5209
+ _context.prev = 4;
5203
5210
  this._pc = new RTCPeerConnection();
5204
5211
  this._bindRTCEvents();
5205
- _context.next = 10;
5212
+ _context.next = 9;
5206
5213
  return this._connect(url);
5207
- case 10:
5208
- _context.next = 15;
5214
+ case 9:
5215
+ _context.next = 14;
5209
5216
  break;
5210
- case 12:
5211
- _context.prev = 12;
5212
- _context.t0 = _context["catch"](5);
5217
+ case 11:
5218
+ _context.prev = 11;
5219
+ _context.t0 = _context["catch"](4);
5213
5220
  setTimeout(function() {
5214
5221
  return _this2._emitError(StreamingError.create(ERR.OTHER, null, _context.t0));
5215
5222
  });
5216
- case 15:
5223
+ case 14:
5217
5224
  case "end":
5218
5225
  return _context.stop();
5219
5226
  }
5220
- }, _callee, this, [[5, 12]]);
5227
+ }, _callee, this, [[4, 11]]);
5221
5228
  }));
5222
- function load(_x) {
5229
+ function load(_x, _x2) {
5223
5230
  return _load.apply(this, arguments);
5224
5231
  }
5225
5232
  return load;
5226
5233
  }()
5227
5234
  }, {
5228
5235
  key: "switchURL",
5229
- value: function switchURL(url) {
5230
- 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);
5231
5241
  }
5232
5242
  }, {
5233
5243
  key: "_bindRTCEvents",
@@ -5253,6 +5263,8 @@
5253
5263
  _this3.load(_this3._url);
5254
5264
  }
5255
5265
  if (pc.connectionState === "connected") {
5266
+ _this3._closeLastPc();
5267
+ _this3._handleMediaStream();
5256
5268
  _this3.emit(EVENT.TTFB, {
5257
5269
  url: _this3._url,
5258
5270
  responseUrl: _this3._url,
@@ -5261,6 +5273,40 @@
5261
5273
  }
5262
5274
  });
5263
5275
  }
5276
+ }, {
5277
+ key: "_handleMediaStream",
5278
+ value: function _handleMediaStream() {
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];
5284
+ if (videoTrack) {
5285
+ this._lastMediaStream.removeTrack(videoTrack);
5286
+ }
5287
+ if (audioTrack) {
5288
+ this._lastMediaStream.removeTrack(audioTrack);
5289
+ }
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
+ });
5298
+ } else {
5299
+ this._mediaStream = new MediaStream();
5300
+ this._mediaStream.addTrack(this._audio);
5301
+ this._mediaStream.addTrack(this._video);
5302
+ this._media.srcObject = this._mediaStream;
5303
+ var req = this._media.play();
5304
+ if (req && req.catch) {
5305
+ req.catch(function(e) {
5306
+ });
5307
+ }
5308
+ }
5309
+ }
5264
5310
  }, {
5265
5311
  key: "_bindMediaEvent",
5266
5312
  value: function _bindMediaEvent() {
@@ -5415,6 +5461,14 @@
5415
5461
  }
5416
5462
  return _connect;
5417
5463
  }()
5464
+ }, {
5465
+ key: "_closeLastPc",
5466
+ value: function _closeLastPc() {
5467
+ if (this._lastPc) {
5468
+ this._lastPc.close();
5469
+ this._lastPc = null;
5470
+ }
5471
+ }
5418
5472
  }, {
5419
5473
  key: "_disconnect",
5420
5474
  value: function _disconnect() {
@@ -5429,17 +5483,19 @@
5429
5483
  }, {
5430
5484
  key: "_emitError",
5431
5485
  value: function _emitError(error) {
5486
+ this._closeLastPc();
5432
5487
  this.emit(EVENT.ERROR, error);
5433
5488
  }
5434
5489
  }, {
5435
5490
  key: "destroy",
5436
5491
  value: function destroy() {
5437
- var _this$_media2;
5492
+ var _this$_media2, _this$_opts;
5438
5493
  this._disconnect();
5439
5494
  (_this$_media2 = this._media) === null || _this$_media2 === void 0 ? void 0 : _this$_media2.removeEventListener("timeupdate", this._mockWaitingByTimeupdate);
5440
- if (this._media) {
5495
+ if (this._media && !((_this$_opts = this._opts) !== null && _this$_opts !== void 0 && _this$_opts.seamlesslyReload)) {
5441
5496
  this._media.srcObject = null;
5442
5497
  }
5498
+ this._closeLastPc();
5443
5499
  if (this._pc) {
5444
5500
  this._pc.close();
5445
5501
  }
@@ -5537,15 +5593,35 @@
5537
5593
  }
5538
5594
  _this = _super.call.apply(_super, [this].concat(args));
5539
5595
  _defineProperty$2(_assertThisInitialized$1(_this), "_rts", null);
5596
+ _defineProperty$2(_assertThisInitialized$1(_this), "_mediaStream", null);
5540
5597
  _defineProperty$2(_assertThisInitialized$1(_this), "_rtsOpts", null);
5598
+ _defineProperty$2(_assertThisInitialized$1(_this), "_onPause", function() {
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) {
5601
+ return;
5602
+ }
5603
+ if ((_this$config = _this.config) !== null && _this$config !== void 0 && _this$config.seamlesslyReload) {
5604
+ var _this$_rts3;
5605
+ _this._mediaStream = (_this$_rts3 = _this._rts) === null || _this$_rts3 === void 0 ? void 0 : _this$_rts3._mediaStream;
5606
+ }
5607
+ (_this$_rts4 = _this._rts) === null || _this$_rts4 === void 0 ? void 0 : _this$_rts4.destroy();
5608
+ });
5609
+ _defineProperty$2(_assertThisInitialized$1(_this), "_onPlay", function() {
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) {
5612
+ return;
5613
+ }
5614
+ _this._init();
5615
+ });
5541
5616
  _defineProperty$2(_assertThisInitialized$1(_this), "_init", function() {
5542
- var _this$_rts;
5543
- (_this$_rts = _this._rts) === null || _this$_rts === void 0 ? void 0 : _this$_rts.destroy();
5617
+ var _this$_rts7;
5618
+ (_this$_rts7 = _this._rts) === null || _this$_rts7 === void 0 ? void 0 : _this$_rts7.destroy();
5544
5619
  var config = _this.player.config;
5545
5620
  var rtsOpts = config.rts || {};
5546
5621
  _this._rtsOpts = rtsOpts;
5547
5622
  _this._rts = new Rts(_objectSpread2$2({
5548
5623
  media: _this.player.video,
5624
+ mediaStream: _this._mediaStream,
5549
5625
  preProcessUrl: function preProcessUrl(url, ext) {
5550
5626
  var _this$player$preProce, _this$player;
5551
5627
  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)) || {
@@ -5556,36 +5632,39 @@
5556
5632
  }, rtsOpts));
5557
5633
  _this._rts.load(config.url);
5558
5634
  });
5559
- _defineProperty$2(_assertThisInitialized$1(_this), "_onSwitchURL", function(url) {
5635
+ _defineProperty$2(_assertThisInitialized$1(_this), "_onSwitchURL", function(url, seamless) {
5560
5636
  if (_this._rts) {
5637
+ if (_typeof$2(seamless) === "object") {
5638
+ seamless = seamless.seamless;
5639
+ }
5561
5640
  _this.player.config.url = url;
5562
- _this._rts.switchURL(url);
5641
+ _this._rts.switchURL(url, seamless);
5563
5642
  }
5564
5643
  });
5565
5644
  _defineProperty$2(_assertThisInitialized$1(_this), "destroy", function() {
5566
- var _this$_rts2;
5645
+ var _this$_rts8;
5567
5646
  _this.player.switchURL = _this._originSwitchFn;
5568
- (_this$_rts2 = _this._rts) === null || _this$_rts2 === void 0 ? void 0 : _this$_rts2.destroy();
5647
+ (_this$_rts8 = _this._rts) === null || _this$_rts8 === void 0 ? void 0 : _this$_rts8.destroy();
5569
5648
  });
5570
5649
  return _this;
5571
5650
  }
5572
5651
  _createClass$2(RtsPlugin2, [{
5573
5652
  key: "pc",
5574
5653
  get: function get() {
5575
- var _this$_rts3;
5576
- return (_this$_rts3 = this._rts) === null || _this$_rts3 === void 0 ? void 0 : _this$_rts3.pc;
5654
+ var _this$_rts9;
5655
+ return (_this$_rts9 = this._rts) === null || _this$_rts9 === void 0 ? void 0 : _this$_rts9.pc;
5577
5656
  }
5578
5657
  }, {
5579
5658
  key: "videoTrack",
5580
5659
  get: function get() {
5581
- var _this$_rts4;
5582
- return (_this$_rts4 = this._rts) === null || _this$_rts4 === void 0 ? void 0 : _this$_rts4.videoTack;
5660
+ var _this$_rts10;
5661
+ return (_this$_rts10 = this._rts) === null || _this$_rts10 === void 0 ? void 0 : _this$_rts10.videoTack;
5583
5662
  }
5584
5663
  }, {
5585
5664
  key: "audioTrack",
5586
5665
  get: function get() {
5587
- var _this$_rts5;
5588
- return (_this$_rts5 = this._rts) === null || _this$_rts5 === void 0 ? void 0 : _this$_rts5.audioTrack;
5666
+ var _this$_rts11;
5667
+ return (_this$_rts11 = this._rts) === null || _this$_rts11 === void 0 ? void 0 : _this$_rts11.audioTrack;
5589
5668
  }
5590
5669
  }, {
5591
5670
  key: "core",
@@ -5595,18 +5674,18 @@
5595
5674
  }, {
5596
5675
  key: "loader",
5597
5676
  get: function get() {
5598
- var _this$_rts6;
5599
- return (_this$_rts6 = this._rts) === null || _this$_rts6 === void 0 ? void 0 : _this$_rts6.loader;
5677
+ var _this$_rts12;
5678
+ return (_this$_rts12 = this._rts) === null || _this$_rts12 === void 0 ? void 0 : _this$_rts12.loader;
5600
5679
  }
5601
5680
  }, {
5602
5681
  key: "version",
5603
5682
  get: function get() {
5604
- return "0.2.1-alpha.1";
5683
+ return "0.2.1-alpha.4";
5605
5684
  }
5606
5685
  }, {
5607
5686
  key: "beforePlayerInit",
5608
5687
  value: function beforePlayerInit() {
5609
- var _this$player2, _this2 = this;
5688
+ var _this$player2, _this2 = this, _this$player$config, _this$player$config$r;
5610
5689
  this._init();
5611
5690
  if (!this._originSwitchFn) {
5612
5691
  this._originSwitchFn = this.player.switchURL.bind(this.player);
@@ -5618,6 +5697,10 @@
5618
5697
  });
5619
5698
  this.on(URL_CHANGE, this._onSwitchURL);
5620
5699
  this.on(DESTROY, this.destroy);
5700
+ if ((_this$player$config = this.player.config) !== null && _this$player$config !== void 0 && (_this$player$config$r = _this$player$config.rts) !== null && _this$player$config$r !== void 0 && _this$player$config$r.seamlesslyReload) {
5701
+ this.on(PAUSE, this._onPause);
5702
+ this.on(PLAY, this._onPlay);
5703
+ }
5621
5704
  this._transErrorEvent();
5622
5705
  this._transCoreEvent(EVENT.LOAD_START);
5623
5706
  this._transCoreEvent(EVENT.LOAD_COMPLETE);
@@ -5647,20 +5730,20 @@
5647
5730
  }, {
5648
5731
  key: "getStats",
5649
5732
  value: function getStats2() {
5650
- var _this$_rts7;
5651
- return (_this$_rts7 = this._rts) === null || _this$_rts7 === void 0 ? void 0 : _this$_rts7.getStats();
5733
+ var _this$_rts13;
5734
+ return (_this$_rts13 = this._rts) === null || _this$_rts13 === void 0 ? void 0 : _this$_rts13.getStats();
5652
5735
  }
5653
5736
  }, {
5654
5737
  key: "getStatsSnapshoot",
5655
5738
  value: function getStatsSnapshoot2() {
5656
- var _this$_rts8;
5657
- return (_this$_rts8 = this._rts) === null || _this$_rts8 === void 0 ? void 0 : _this$_rts8.getStatsSnapshoot();
5739
+ var _this$_rts14;
5740
+ return (_this$_rts14 = this._rts) === null || _this$_rts14 === void 0 ? void 0 : _this$_rts14.getStatsSnapshoot();
5658
5741
  }
5659
5742
  }, {
5660
5743
  key: "getNetWorkInfo",
5661
5744
  value: function getNetWorkInfo() {
5662
- var _this$_rts9;
5663
- return (_this$_rts9 = this._rts) === null || _this$_rts9 === void 0 ? void 0 : _this$_rts9.networkStats;
5745
+ var _this$_rts15;
5746
+ return (_this$_rts15 = this._rts) === null || _this$_rts15 === void 0 ? void 0 : _this$_rts15.networkStats;
5664
5747
  }
5665
5748
  }, {
5666
5749
  key: "_transErrorEvent",
@@ -5697,14 +5780,8 @@
5697
5780
  }
5698
5781
  player.config.url = backupURL;
5699
5782
  if (backupConstruct) {
5700
- if (!Array.isArray(backupConstruct)) {
5701
- backupConstruct = [backupConstruct];
5702
- }
5703
- backupConstruct.forEach(function(construct) {
5704
- var _newPlugin$beforePlay;
5705
- var newPlugin = player.registerPlugin(construct);
5706
- (_newPlugin$beforePlay = newPlugin.beforePlayerInit) === null || _newPlugin$beforePlay === void 0 ? void 0 : _newPlugin$beforePlay.call(newPlugin);
5707
- });
5783
+ var newPlugin = player.registerPlugin(backupConstruct);
5784
+ newPlugin.beforePlayerInit();
5708
5785
  } else {
5709
5786
  player.video.src = backupURL;
5710
5787
  }