@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.
@@ -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);
@@ -1530,7 +1538,7 @@ util.getCurrentTimeByOffset = function(offsetTime, segments) {
1530
1538
  }
1531
1539
  return offsetTime;
1532
1540
  };
1533
- var version = "3.0.20-rc.3";
1541
+ var version = "3.0.19-rc.0";
1534
1542
  var ERROR_MAP = {
1535
1543
  1: 5101,
1536
1544
  2: 5102,
@@ -1594,6 +1602,8 @@ var Errors = /* @__PURE__ */ _createClass$1(
1594
1602
  }
1595
1603
  }
1596
1604
  );
1605
+ var PLAY = "play";
1606
+ var PAUSE = "pause";
1597
1607
  var ERROR = "error";
1598
1608
  var DESTROY = "destroy";
1599
1609
  var URL_CHANGE = "urlchange";
@@ -4808,7 +4818,8 @@ function getOption(opts) {
4808
4818
  loadTimeout: 5e3,
4809
4819
  stallInterval: 400,
4810
4820
  networkEvaluateInterval: 1e3,
4811
- delayHint: 0
4821
+ delayHint: 0,
4822
+ seamlesslyReload: false
4812
4823
  }, opts);
4813
4824
  }
4814
4825
  function _getStats(stats) {
@@ -5071,6 +5082,7 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5071
5082
  _defineProperty$2(_assertThisInitialized$1(_this), "_audioTransceicer", null);
5072
5083
  _defineProperty$2(_assertThisInitialized$1(_this), "_videoTransceicer", null);
5073
5084
  _defineProperty$2(_assertThisInitialized$1(_this), "_mediaStream", null);
5085
+ _defineProperty$2(_assertThisInitialized$1(_this), "_lastMediaStream", null);
5074
5086
  _defineProperty$2(_assertThisInitialized$1(_this), "_media", null);
5075
5087
  _defineProperty$2(_assertThisInitialized$1(_this), "_opts", null);
5076
5088
  _defineProperty$2(_assertThisInitialized$1(_this), "_loader", null);
@@ -5078,19 +5090,10 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5078
5090
  _defineProperty$2(_assertThisInitialized$1(_this), "_retry", 0);
5079
5091
  _defineProperty$2(_assertThisInitialized$1(_this), "_waitingTimer", 0);
5080
5092
  _defineProperty$2(_assertThisInitialized$1(_this), "_rctConnectStartTs", 0);
5093
+ _defineProperty$2(_assertThisInitialized$1(_this), "_isReplacing", false);
5081
5094
  _defineProperty$2(_assertThisInitialized$1(_this), "_onTrack", function(e) {
5082
5095
  logger.log("addTrack: ", e.track, e.streams);
5083
5096
  _this["_".concat(e.track.kind)] = e.track;
5084
- if (!_this._mediaStream) {
5085
- _this._mediaStream = new MediaStream();
5086
- _this._media.srcObject = _this._mediaStream;
5087
- var req = _this._media.play();
5088
- if (req && req.catch) {
5089
- req.catch(function(e2) {
5090
- });
5091
- }
5092
- }
5093
- _this._mediaStream.addTrack(e.track);
5094
5097
  });
5095
5098
  _defineProperty$2(_assertThisInitialized$1(_this), "_mockWaitingByTimeupdate", function() {
5096
5099
  var _this$_pc, _this$_pc2;
@@ -5138,6 +5141,9 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5138
5141
  }));
5139
5142
  _this._retry = _this._opts.retryCount;
5140
5143
  _this._bindMediaEvent();
5144
+ if (_this._opts.mediaStream && _this._opts.seamlesslyReload) {
5145
+ _this._lastMediaStream = _this._opts.mediaStream;
5146
+ }
5141
5147
  return _this;
5142
5148
  }
5143
5149
  _createClass$2(Rts2, [{
@@ -5181,9 +5187,9 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5181
5187
  }, {
5182
5188
  key: "load",
5183
5189
  value: function() {
5184
- var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee(url) {
5190
+ var _load = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee(url, seamless) {
5185
5191
  var _this2 = this;
5186
- var lastPc;
5192
+ var _this$_pc3;
5187
5193
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
5188
5194
  while (1)
5189
5195
  switch (_context.prev = _context.next) {
@@ -5191,39 +5197,43 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5191
5197
  this._disconnect();
5192
5198
  this._url = url;
5193
5199
  this._retry = this._opts.retryCount;
5194
- lastPc = this._pc;
5195
- if (lastPc) {
5196
- 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();
5197
5204
  }
5198
- _context.prev = 5;
5205
+ _context.prev = 4;
5199
5206
  this._pc = new RTCPeerConnection();
5200
5207
  this._bindRTCEvents();
5201
- _context.next = 10;
5208
+ _context.next = 9;
5202
5209
  return this._connect(url);
5203
- case 10:
5204
- _context.next = 15;
5210
+ case 9:
5211
+ _context.next = 14;
5205
5212
  break;
5206
- case 12:
5207
- _context.prev = 12;
5208
- _context.t0 = _context["catch"](5);
5213
+ case 11:
5214
+ _context.prev = 11;
5215
+ _context.t0 = _context["catch"](4);
5209
5216
  setTimeout(function() {
5210
5217
  return _this2._emitError(StreamingError.create(ERR.OTHER, null, _context.t0));
5211
5218
  });
5212
- case 15:
5219
+ case 14:
5213
5220
  case "end":
5214
5221
  return _context.stop();
5215
5222
  }
5216
- }, _callee, this, [[5, 12]]);
5223
+ }, _callee, this, [[4, 11]]);
5217
5224
  }));
5218
- function load(_x) {
5225
+ function load(_x, _x2) {
5219
5226
  return _load.apply(this, arguments);
5220
5227
  }
5221
5228
  return load;
5222
5229
  }()
5223
5230
  }, {
5224
5231
  key: "switchURL",
5225
- value: function switchURL(url) {
5226
- 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);
5227
5237
  }
5228
5238
  }, {
5229
5239
  key: "_bindRTCEvents",
@@ -5249,6 +5259,8 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5249
5259
  _this3.load(_this3._url);
5250
5260
  }
5251
5261
  if (pc.connectionState === "connected") {
5262
+ _this3._closeLastPc();
5263
+ _this3._handleMediaStream();
5252
5264
  _this3.emit(EVENT.TTFB, {
5253
5265
  url: _this3._url,
5254
5266
  responseUrl: _this3._url,
@@ -5257,6 +5269,40 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5257
5269
  }
5258
5270
  });
5259
5271
  }
5272
+ }, {
5273
+ key: "_handleMediaStream",
5274
+ value: function _handleMediaStream() {
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];
5280
+ if (videoTrack) {
5281
+ this._lastMediaStream.removeTrack(videoTrack);
5282
+ }
5283
+ if (audioTrack) {
5284
+ this._lastMediaStream.removeTrack(audioTrack);
5285
+ }
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
+ });
5294
+ } else {
5295
+ this._mediaStream = new MediaStream();
5296
+ this._mediaStream.addTrack(this._audio);
5297
+ this._mediaStream.addTrack(this._video);
5298
+ this._media.srcObject = this._mediaStream;
5299
+ var req = this._media.play();
5300
+ if (req && req.catch) {
5301
+ req.catch(function(e) {
5302
+ });
5303
+ }
5304
+ }
5305
+ }
5260
5306
  }, {
5261
5307
  key: "_bindMediaEvent",
5262
5308
  value: function _bindMediaEvent() {
@@ -5411,6 +5457,14 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5411
5457
  }
5412
5458
  return _connect;
5413
5459
  }()
5460
+ }, {
5461
+ key: "_closeLastPc",
5462
+ value: function _closeLastPc() {
5463
+ if (this._lastPc) {
5464
+ this._lastPc.close();
5465
+ this._lastPc = null;
5466
+ }
5467
+ }
5414
5468
  }, {
5415
5469
  key: "_disconnect",
5416
5470
  value: function _disconnect() {
@@ -5425,17 +5479,19 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5425
5479
  }, {
5426
5480
  key: "_emitError",
5427
5481
  value: function _emitError(error) {
5482
+ this._closeLastPc();
5428
5483
  this.emit(EVENT.ERROR, error);
5429
5484
  }
5430
5485
  }, {
5431
5486
  key: "destroy",
5432
5487
  value: function destroy() {
5433
- var _this$_media2;
5488
+ var _this$_media2, _this$_opts;
5434
5489
  this._disconnect();
5435
5490
  (_this$_media2 = this._media) === null || _this$_media2 === void 0 ? void 0 : _this$_media2.removeEventListener("timeupdate", this._mockWaitingByTimeupdate);
5436
- if (this._media) {
5491
+ if (this._media && !((_this$_opts = this._opts) !== null && _this$_opts !== void 0 && _this$_opts.seamlesslyReload)) {
5437
5492
  this._media.srcObject = null;
5438
5493
  }
5494
+ this._closeLastPc();
5439
5495
  if (this._pc) {
5440
5496
  this._pc.close();
5441
5497
  }
@@ -5533,15 +5589,35 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5533
5589
  }
5534
5590
  _this = _super.call.apply(_super, [this].concat(args));
5535
5591
  _defineProperty$2(_assertThisInitialized$1(_this), "_rts", null);
5592
+ _defineProperty$2(_assertThisInitialized$1(_this), "_mediaStream", null);
5536
5593
  _defineProperty$2(_assertThisInitialized$1(_this), "_rtsOpts", null);
5594
+ _defineProperty$2(_assertThisInitialized$1(_this), "_onPause", function() {
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) {
5597
+ return;
5598
+ }
5599
+ if ((_this$config = _this.config) !== null && _this$config !== void 0 && _this$config.seamlesslyReload) {
5600
+ var _this$_rts3;
5601
+ _this._mediaStream = (_this$_rts3 = _this._rts) === null || _this$_rts3 === void 0 ? void 0 : _this$_rts3._mediaStream;
5602
+ }
5603
+ (_this$_rts4 = _this._rts) === null || _this$_rts4 === void 0 ? void 0 : _this$_rts4.destroy();
5604
+ });
5605
+ _defineProperty$2(_assertThisInitialized$1(_this), "_onPlay", function() {
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) {
5608
+ return;
5609
+ }
5610
+ _this._init();
5611
+ });
5537
5612
  _defineProperty$2(_assertThisInitialized$1(_this), "_init", function() {
5538
- var _this$_rts;
5539
- (_this$_rts = _this._rts) === null || _this$_rts === void 0 ? void 0 : _this$_rts.destroy();
5613
+ var _this$_rts7;
5614
+ (_this$_rts7 = _this._rts) === null || _this$_rts7 === void 0 ? void 0 : _this$_rts7.destroy();
5540
5615
  var config = _this.player.config;
5541
5616
  var rtsOpts = config.rts || {};
5542
5617
  _this._rtsOpts = rtsOpts;
5543
5618
  _this._rts = new Rts(_objectSpread2$2({
5544
5619
  media: _this.player.video,
5620
+ mediaStream: _this._mediaStream,
5545
5621
  preProcessUrl: function preProcessUrl(url, ext) {
5546
5622
  var _this$player$preProce, _this$player;
5547
5623
  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)) || {
@@ -5552,36 +5628,39 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5552
5628
  }, rtsOpts));
5553
5629
  _this._rts.load(config.url);
5554
5630
  });
5555
- _defineProperty$2(_assertThisInitialized$1(_this), "_onSwitchURL", function(url) {
5631
+ _defineProperty$2(_assertThisInitialized$1(_this), "_onSwitchURL", function(url, seamless) {
5556
5632
  if (_this._rts) {
5633
+ if (_typeof$2(seamless) === "object") {
5634
+ seamless = seamless.seamless;
5635
+ }
5557
5636
  _this.player.config.url = url;
5558
- _this._rts.switchURL(url);
5637
+ _this._rts.switchURL(url, seamless);
5559
5638
  }
5560
5639
  });
5561
5640
  _defineProperty$2(_assertThisInitialized$1(_this), "destroy", function() {
5562
- var _this$_rts2;
5641
+ var _this$_rts8;
5563
5642
  _this.player.switchURL = _this._originSwitchFn;
5564
- (_this$_rts2 = _this._rts) === null || _this$_rts2 === void 0 ? void 0 : _this$_rts2.destroy();
5643
+ (_this$_rts8 = _this._rts) === null || _this$_rts8 === void 0 ? void 0 : _this$_rts8.destroy();
5565
5644
  });
5566
5645
  return _this;
5567
5646
  }
5568
5647
  _createClass$2(RtsPlugin2, [{
5569
5648
  key: "pc",
5570
5649
  get: function get() {
5571
- var _this$_rts3;
5572
- return (_this$_rts3 = this._rts) === null || _this$_rts3 === void 0 ? void 0 : _this$_rts3.pc;
5650
+ var _this$_rts9;
5651
+ return (_this$_rts9 = this._rts) === null || _this$_rts9 === void 0 ? void 0 : _this$_rts9.pc;
5573
5652
  }
5574
5653
  }, {
5575
5654
  key: "videoTrack",
5576
5655
  get: function get() {
5577
- var _this$_rts4;
5578
- return (_this$_rts4 = this._rts) === null || _this$_rts4 === void 0 ? void 0 : _this$_rts4.videoTack;
5656
+ var _this$_rts10;
5657
+ return (_this$_rts10 = this._rts) === null || _this$_rts10 === void 0 ? void 0 : _this$_rts10.videoTack;
5579
5658
  }
5580
5659
  }, {
5581
5660
  key: "audioTrack",
5582
5661
  get: function get() {
5583
- var _this$_rts5;
5584
- return (_this$_rts5 = this._rts) === null || _this$_rts5 === void 0 ? void 0 : _this$_rts5.audioTrack;
5662
+ var _this$_rts11;
5663
+ return (_this$_rts11 = this._rts) === null || _this$_rts11 === void 0 ? void 0 : _this$_rts11.audioTrack;
5585
5664
  }
5586
5665
  }, {
5587
5666
  key: "core",
@@ -5591,18 +5670,18 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5591
5670
  }, {
5592
5671
  key: "loader",
5593
5672
  get: function get() {
5594
- var _this$_rts6;
5595
- return (_this$_rts6 = this._rts) === null || _this$_rts6 === void 0 ? void 0 : _this$_rts6.loader;
5673
+ var _this$_rts12;
5674
+ return (_this$_rts12 = this._rts) === null || _this$_rts12 === void 0 ? void 0 : _this$_rts12.loader;
5596
5675
  }
5597
5676
  }, {
5598
5677
  key: "version",
5599
5678
  get: function get() {
5600
- return "0.2.1-alpha.1";
5679
+ return "0.2.1-alpha.4";
5601
5680
  }
5602
5681
  }, {
5603
5682
  key: "beforePlayerInit",
5604
5683
  value: function beforePlayerInit() {
5605
- var _this$player2, _this2 = this;
5684
+ var _this$player2, _this2 = this, _this$player$config, _this$player$config$r;
5606
5685
  this._init();
5607
5686
  if (!this._originSwitchFn) {
5608
5687
  this._originSwitchFn = this.player.switchURL.bind(this.player);
@@ -5614,6 +5693,10 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5614
5693
  });
5615
5694
  this.on(URL_CHANGE, this._onSwitchURL);
5616
5695
  this.on(DESTROY, this.destroy);
5696
+ 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) {
5697
+ this.on(PAUSE, this._onPause);
5698
+ this.on(PLAY, this._onPlay);
5699
+ }
5617
5700
  this._transErrorEvent();
5618
5701
  this._transCoreEvent(EVENT.LOAD_START);
5619
5702
  this._transCoreEvent(EVENT.LOAD_COMPLETE);
@@ -5643,20 +5726,20 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5643
5726
  }, {
5644
5727
  key: "getStats",
5645
5728
  value: function getStats2() {
5646
- var _this$_rts7;
5647
- return (_this$_rts7 = this._rts) === null || _this$_rts7 === void 0 ? void 0 : _this$_rts7.getStats();
5729
+ var _this$_rts13;
5730
+ return (_this$_rts13 = this._rts) === null || _this$_rts13 === void 0 ? void 0 : _this$_rts13.getStats();
5648
5731
  }
5649
5732
  }, {
5650
5733
  key: "getStatsSnapshoot",
5651
5734
  value: function getStatsSnapshoot2() {
5652
- var _this$_rts8;
5653
- return (_this$_rts8 = this._rts) === null || _this$_rts8 === void 0 ? void 0 : _this$_rts8.getStatsSnapshoot();
5735
+ var _this$_rts14;
5736
+ return (_this$_rts14 = this._rts) === null || _this$_rts14 === void 0 ? void 0 : _this$_rts14.getStatsSnapshoot();
5654
5737
  }
5655
5738
  }, {
5656
5739
  key: "getNetWorkInfo",
5657
5740
  value: function getNetWorkInfo() {
5658
- var _this$_rts9;
5659
- return (_this$_rts9 = this._rts) === null || _this$_rts9 === void 0 ? void 0 : _this$_rts9.networkStats;
5741
+ var _this$_rts15;
5742
+ return (_this$_rts15 = this._rts) === null || _this$_rts15 === void 0 ? void 0 : _this$_rts15.networkStats;
5660
5743
  }
5661
5744
  }, {
5662
5745
  key: "_transErrorEvent",
@@ -5693,14 +5776,8 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5693
5776
  }
5694
5777
  player.config.url = backupURL;
5695
5778
  if (backupConstruct) {
5696
- if (!Array.isArray(backupConstruct)) {
5697
- backupConstruct = [backupConstruct];
5698
- }
5699
- backupConstruct.forEach(function(construct) {
5700
- var _newPlugin$beforePlay;
5701
- var newPlugin = player.registerPlugin(construct);
5702
- (_newPlugin$beforePlay = newPlugin.beforePlayerInit) === null || _newPlugin$beforePlay === void 0 ? void 0 : _newPlugin$beforePlay.call(newPlugin);
5703
- });
5779
+ var newPlugin = player.registerPlugin(backupConstruct);
5780
+ newPlugin.beforePlayerInit();
5704
5781
  } else {
5705
5782
  player.video.src = backupURL;
5706
5783
  }