@volcengine/veplayer-plugin 2.0.0-rc.0 → 2.2.0-rc.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.
Files changed (30) hide show
  1. package/README.md +21 -0
  2. package/esm/index.development.js +45768 -41842
  3. package/esm/index.production.js +5 -4
  4. package/esm/veplayer.plugin.flv.development.js +1988 -8535
  5. package/esm/veplayer.plugin.flv.production.js +1 -1
  6. package/esm/veplayer.plugin.hls.development.js +3548 -10507
  7. package/esm/veplayer.plugin.hls.production.js +1 -1
  8. package/esm/veplayer.plugin.mp4.development.js +87 -4
  9. package/esm/veplayer.plugin.mp4.production.js +1 -1
  10. package/esm/veplayer.plugin.rtm.development.js +159 -43
  11. package/esm/veplayer.plugin.rtm.production.js +1 -1
  12. package/esm/veplayer.plugin.shaka.development.js +86 -3
  13. package/esm/veplayer.plugin.shaka.production.js +1 -1
  14. package/esm/veplayer.plugin.xgvideo.development.js +226 -225
  15. package/esm/veplayer.plugin.xgvideo.production.js +1 -1
  16. package/package.json +2 -1
  17. package/umd/index.development.js +35422 -31496
  18. package/umd/index.production.js +1 -1
  19. package/umd/veplayer.plugin.flv.development.js +2034 -8580
  20. package/umd/veplayer.plugin.flv.production.js +1 -1
  21. package/umd/veplayer.plugin.hls.development.js +3654 -10614
  22. package/umd/veplayer.plugin.hls.production.js +1 -1
  23. package/umd/veplayer.plugin.mp4.development.js +87 -4
  24. package/umd/veplayer.plugin.mp4.production.js +1 -1
  25. package/umd/veplayer.plugin.rtm.development.js +180 -65
  26. package/umd/veplayer.plugin.rtm.production.js +1 -1
  27. package/umd/veplayer.plugin.shaka.development.js +86 -3
  28. package/umd/veplayer.plugin.shaka.production.js +1 -1
  29. package/umd/veplayer.plugin.xgvideo.development.js +26 -26
  30. package/umd/veplayer.plugin.xgvideo.production.js +1 -1
@@ -835,13 +835,13 @@ var XgplayerTimeRange = /* @__PURE__ */ function() {
835
835
  }
836
836
  _createClass$1(XgplayerTimeRange2, [{
837
837
  key: "start",
838
- value: function start(index) {
839
- return this.bufferedList[index].start;
838
+ value: function start(index2) {
839
+ return this.bufferedList[index2].start;
840
840
  }
841
841
  }, {
842
842
  key: "end",
843
- value: function end(index) {
844
- return this.bufferedList[index].end;
843
+ value: function end(index2) {
844
+ return this.bufferedList[index2].end;
845
845
  }
846
846
  }, {
847
847
  key: "length",
@@ -1384,6 +1384,9 @@ util.isMSE = function(video) {
1384
1384
  }
1385
1385
  return /^blob/.test(video.currentSrc) || /^blob/.test(video.src);
1386
1386
  };
1387
+ util.isBlob = function(url) {
1388
+ return typeof url === "string" && /^blob/.test(url);
1389
+ };
1387
1390
  util.generateSessionId = function() {
1388
1391
  var did = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0;
1389
1392
  var d = (/* @__PURE__ */ new Date()).getTime();
@@ -1436,7 +1439,24 @@ util.getTransformStyle = function() {
1436
1439
  scale: 1,
1437
1440
  rotate: 0
1438
1441
  };
1439
- return "scale(".concat(pos.scale || 1, ") translate(").concat(pos.x || 0, "%, ").concat(pos.y || 0, "%) rotate(").concat(pos.rotate || 0, "deg)");
1442
+ var transformValue = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
1443
+ var styles = {
1444
+ scale: "".concat(pos.scale || 1),
1445
+ translate: "".concat(pos.x || 0, "%, ").concat(pos.y || 0, "%"),
1446
+ rotate: "".concat(pos.rotate || 0, "deg")
1447
+ };
1448
+ var stylesKeys = Object.keys(styles);
1449
+ stylesKeys.forEach(function(key) {
1450
+ var reg = new RegExp("".concat(key, "\\([^\\(]+\\)"), "g");
1451
+ var fn = "".concat(key, "(").concat(styles[key], ")");
1452
+ if (reg.test(transformValue)) {
1453
+ reg.lastIndex = -1;
1454
+ transformValue = transformValue.replace(reg, fn);
1455
+ } else {
1456
+ transformValue += "".concat(fn, " ");
1457
+ }
1458
+ });
1459
+ return transformValue;
1440
1460
  };
1441
1461
  util.convertDeg = function(val) {
1442
1462
  if (Math.abs(val) <= 1) {
@@ -1444,7 +1464,70 @@ util.convertDeg = function(val) {
1444
1464
  }
1445
1465
  return val % 360;
1446
1466
  };
1447
- var version = "3.0.7";
1467
+ util.getIndexByTime = function(time, segments) {
1468
+ var _len = segments.length;
1469
+ var _index = -1;
1470
+ if (_len < 1) {
1471
+ return _index;
1472
+ }
1473
+ if (time <= segments[0].end || _len < 2) {
1474
+ _index = 0;
1475
+ } else if (time > segments[_len - 1].end) {
1476
+ _index = _len - 1;
1477
+ } else {
1478
+ for (var i = 1; i < _len; i++) {
1479
+ if (time > segments[i - 1].end && time <= segments[i].end) {
1480
+ _index = i;
1481
+ break;
1482
+ }
1483
+ }
1484
+ }
1485
+ return _index;
1486
+ };
1487
+ util.getOffsetCurrentTime = function(currentTime, segments) {
1488
+ var index2 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : -1;
1489
+ var _index = -1;
1490
+ if (index2 >= 0 && index2 < segments.length) {
1491
+ _index = index2;
1492
+ } else {
1493
+ _index = util.getIndexByTime(currentTime, segments);
1494
+ }
1495
+ if (_index < 0) {
1496
+ return -1;
1497
+ }
1498
+ var _len = segments.length;
1499
+ var _segments$_index = segments[_index], start = _segments$_index.start, end = _segments$_index.end, cTime = _segments$_index.cTime, offset = _segments$_index.offset;
1500
+ if (currentTime < start) {
1501
+ return cTime;
1502
+ } else if (currentTime >= start && currentTime <= end) {
1503
+ return currentTime - offset;
1504
+ } else if (currentTime > end && _index >= _len - 1) {
1505
+ return end;
1506
+ }
1507
+ return -1;
1508
+ };
1509
+ util.getCurrentTimeByOffset = function(offsetTime, segments) {
1510
+ var _index = -1;
1511
+ if (!segments || segments.length < 0) {
1512
+ return offsetTime;
1513
+ }
1514
+ for (var i = 0; i < segments.length; i++) {
1515
+ if (offsetTime <= segments[i].duration) {
1516
+ _index = i;
1517
+ break;
1518
+ }
1519
+ }
1520
+ if (_index !== -1) {
1521
+ var start = segments[_index].start;
1522
+ if (_index - 1 < 0) {
1523
+ return start + offsetTime;
1524
+ } else {
1525
+ return start + (offsetTime - segments[_index - 1].duration);
1526
+ }
1527
+ }
1528
+ return offsetTime;
1529
+ };
1530
+ var version = "3.0.11-alpha.2";
1448
1531
  var ERROR_MAP = {
1449
1532
  1: 5101,
1450
1533
  2: 5102,
@@ -2953,7 +3036,7 @@ function setUrlParams(url, params) {
2953
3036
  }
2954
3037
  return url;
2955
3038
  }
2956
- function createResponse(data, done, response, contentLength, age, startTime, firstByteTime, index, range, vid, priOptions) {
3039
+ function createResponse(data, done, response, contentLength, age, startTime, firstByteTime, index2, range, vid, priOptions) {
2957
3040
  age = age !== null && age !== void 0 ? parseFloat(age) : null;
2958
3041
  contentLength = parseInt(contentLength || "0", 10);
2959
3042
  if (Number.isNaN(contentLength))
@@ -2961,7 +3044,7 @@ function createResponse(data, done, response, contentLength, age, startTime, fir
2961
3044
  var options = {
2962
3045
  range,
2963
3046
  vid,
2964
- index,
3047
+ index: index2,
2965
3048
  contentLength,
2966
3049
  age,
2967
3050
  startTime,
@@ -3039,14 +3122,14 @@ var FetchLoader = /* @__PURE__ */ function(_EventEmitter) {
3039
3122
  key: "load",
3040
3123
  value: function load(_ref) {
3041
3124
  var _this$_abortControlle, _this2 = this;
3042
- var url = _ref.url, vid = _ref.vid, timeout = _ref.timeout, responseType = _ref.responseType, onProgress = _ref.onProgress, index = _ref.index, onTimeout = _ref.onTimeout, onCancel = _ref.onCancel, range = _ref.range, transformResponse = _ref.transformResponse, request = _ref.request, params = _ref.params, logger2 = _ref.logger, method = _ref.method, headers = _ref.headers, body = _ref.body, mode = _ref.mode, credentials = _ref.credentials, cache = _ref.cache, redirect = _ref.redirect, referrer = _ref.referrer, referrerPolicy = _ref.referrerPolicy, onProcessMinLen = _ref.onProcessMinLen, priOptions = _ref.priOptions;
3125
+ var url = _ref.url, vid = _ref.vid, timeout = _ref.timeout, responseType = _ref.responseType, onProgress = _ref.onProgress, index2 = _ref.index, onTimeout = _ref.onTimeout, onCancel = _ref.onCancel, range = _ref.range, transformResponse = _ref.transformResponse, request = _ref.request, params = _ref.params, logger2 = _ref.logger, method = _ref.method, headers = _ref.headers, body = _ref.body, mode = _ref.mode, credentials = _ref.credentials, cache = _ref.cache, redirect = _ref.redirect, referrer = _ref.referrer, referrerPolicy = _ref.referrerPolicy, onProcessMinLen = _ref.onProcessMinLen, priOptions = _ref.priOptions;
3043
3126
  this._logger = logger2;
3044
3127
  this._aborted = false;
3045
3128
  this._onProcessMinLen = onProcessMinLen;
3046
3129
  this._onCancel = onCancel;
3047
3130
  this._abortController = typeof AbortController !== "undefined" && new AbortController();
3048
3131
  this._running = true;
3049
- this._index = index;
3132
+ this._index = index2;
3050
3133
  this._range = range || [0, 0];
3051
3134
  this._vid = vid || url;
3052
3135
  this._priOptions = priOptions || {};
@@ -3095,7 +3178,7 @@ var FetchLoader = /* @__PURE__ */ function(_EventEmitter) {
3095
3178
  }, timeout);
3096
3179
  }
3097
3180
  var startTime = Date.now();
3098
- this._logger.debug("[fetch load start], index,", index, ",range,", range);
3181
+ this._logger.debug("[fetch load start], index,", index2, ",range,", range);
3099
3182
  return new Promise(function(resolve, reject) {
3100
3183
  fetch(request || url, request ? void 0 : init).then(/* @__PURE__ */ function() {
3101
3184
  var _ref2 = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee(response) {
@@ -3173,8 +3256,8 @@ var FetchLoader = /* @__PURE__ */ function(_EventEmitter) {
3173
3256
  priOptions: _this2._priOptions
3174
3257
  });
3175
3258
  case 37:
3176
- _this2._logger.debug("[fetch load end], index,", index, ",range,", range);
3177
- resolve(createResponse(data, true, response, response.headers.get("Content-Length"), response.headers.get("age"), startTime, firstByteTime, index, range, _this2._vid, _this2._priOptions));
3259
+ _this2._logger.debug("[fetch load end], index,", index2, ",range,", range);
3260
+ resolve(createResponse(data, true, response, response.headers.get("Content-Length"), response.headers.get("age"), startTime, firstByteTime, index2, range, _this2._vid, _this2._priOptions));
3178
3261
  case 39:
3179
3262
  case "end":
3180
3263
  return _context.stop();
@@ -4891,6 +4974,11 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
4891
4974
  get: function get() {
4892
4975
  return this._video;
4893
4976
  }
4977
+ }, {
4978
+ key: "loader",
4979
+ get: function get() {
4980
+ return this._loader;
4981
+ }
4894
4982
  }, {
4895
4983
  key: "getStats",
4896
4984
  value: function getStats$1() {
@@ -4992,7 +5080,7 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
4992
5080
  key: "_connect",
4993
5081
  value: function() {
4994
5082
  var _connect2 = _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee2() {
4995
- var pc, offer, delayHint, parsed, _answer$remoteSdp, _answer$remoteSdp2, parseSession, sessionId, reqStart, res, answer, _parsed;
5083
+ var pc, offer, delayHint, parsed, finnalUrl, _answer$remoteSdp, _answer$remoteSdp2, parseSession, sessionId, reqStart, res, answer, err, _parsed;
4996
5084
  return _regeneratorRuntime$1().wrap(function _callee2$(_context2) {
4997
5085
  while (1)
4998
5086
  switch (_context2.prev = _context2.next) {
@@ -5054,39 +5142,53 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5054
5142
  _context2.next = 22;
5055
5143
  return pc.setLocalDescription(offer);
5056
5144
  case 22:
5057
- _context2.prev = 22;
5058
- parseSession = /_?session_id=([^&$]+)/.exec(this._url);
5059
- sessionId = parseSession ? parseSession[1] : Date.now() + "";
5145
+ finnalUrl = this._url;
5146
+ _context2.prev = 23;
5147
+ if (this._opts.preProcessUrl) {
5148
+ finnalUrl = this._opts.preProcessUrl(finnalUrl).url;
5149
+ }
5150
+ this._loader.finnalUrl = finnalUrl;
5151
+ parseSession = /_?session_id=([^&$]+)/.exec(finnalUrl);
5152
+ sessionId = parseSession ? parseSession[1] : Date.now() + "666";
5060
5153
  this.emit(EVENT.LOAD_START, {
5061
- url: this._url,
5154
+ url: finnalUrl,
5062
5155
  offersdp: offer.sdp,
5063
5156
  sessionId
5064
5157
  });
5065
5158
  reqStart = Date.now();
5066
- _context2.next = 29;
5067
- return this._loader.load(this._url, {
5159
+ _context2.next = 32;
5160
+ return this._loader.load(finnalUrl, {
5068
5161
  body: JSON.stringify({
5069
5162
  sessionId,
5070
5163
  version: "1.0-html",
5071
5164
  localSdp: offer
5072
5165
  })
5073
5166
  });
5074
- case 29:
5167
+ case 32:
5075
5168
  res = _context2.sent;
5076
5169
  this.emit(EVENT.LOAD_RESPONSE_HEADERS, {
5077
5170
  headers: res.response.headers
5078
5171
  });
5079
5172
  answer = res === null || res === void 0 ? void 0 : res.data;
5173
+ if (!((answer === null || answer === void 0 ? void 0 : answer.code) === 404 || (answer === null || answer === void 0 ? void 0 : answer.code) === 403)) {
5174
+ _context2.next = 40;
5175
+ break;
5176
+ }
5177
+ err = StreamingError.create(answer.code === 404 ? ERR.NETWORK_NOTFOUND : ERR.NETWORK_FORBIDDEN, null, answer);
5178
+ err.errorType = ERR.NETWORK;
5179
+ this._emitError(err);
5180
+ return _context2.abrupt("return");
5181
+ case 40:
5080
5182
  if (!((answer === null || answer === void 0 ? void 0 : answer.code) !== 200)) {
5081
- _context2.next = 34;
5183
+ _context2.next = 42;
5082
5184
  break;
5083
5185
  }
5084
5186
  throw new Error("code: ".concat(answer === null || answer === void 0 ? void 0 : answer.code, ", message:").concat(answer === null || answer === void 0 ? void 0 : answer.message));
5085
- case 34:
5187
+ case 42:
5086
5188
  logger.log("answer:");
5087
5189
  logger.log((_answer$remoteSdp = answer.remoteSdp) === null || _answer$remoteSdp === void 0 ? void 0 : _answer$remoteSdp.sdp);
5088
5190
  this.emit(EVENT.LOAD_COMPLETE, {
5089
- url: this._url,
5191
+ url: finnalUrl,
5090
5192
  elapsed: Date.now() - reqStart,
5091
5193
  answersdp: (_answer$remoteSdp2 = answer.remoteSdp) === null || _answer$remoteSdp2 === void 0 ? void 0 : _answer$remoteSdp2.sdp
5092
5194
  });
@@ -5097,20 +5199,20 @@ var Rts = /* @__PURE__ */ function(_EventEmitter) {
5097
5199
  answer.remoteSdp.sdp = lib.write(_parsed);
5098
5200
  logger.log("answer modified:\n", answer.remoteSdp.sdp);
5099
5201
  this._rctConnectStartTs = Date.now();
5100
- _context2.next = 44;
5202
+ _context2.next = 52;
5101
5203
  return this._pc.setRemoteDescription(answer.remoteSdp);
5102
- case 44:
5103
- _context2.next = 49;
5204
+ case 52:
5205
+ _context2.next = 57;
5104
5206
  break;
5105
- case 46:
5106
- _context2.prev = 46;
5107
- _context2.t0 = _context2["catch"](22);
5207
+ case 54:
5208
+ _context2.prev = 54;
5209
+ _context2.t0 = _context2["catch"](23);
5108
5210
  this._emitError(StreamingError.network(_context2.t0));
5109
- case 49:
5211
+ case 57:
5110
5212
  case "end":
5111
5213
  return _context2.stop();
5112
5214
  }
5113
- }, _callee2, this, [[22, 46]]);
5215
+ }, _callee2, this, [[23, 54]]);
5114
5216
  }));
5115
5217
  function _connect() {
5116
5218
  return _connect2.apply(this, arguments);
@@ -5245,7 +5347,14 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5245
5347
  var rtsOpts = config.rts || {};
5246
5348
  _this._rtsOpts = rtsOpts;
5247
5349
  _this._rts = new Rts(_objectSpread2$2({
5248
- media: _this.player.video
5350
+ media: _this.player.video,
5351
+ preProcessUrl: function preProcessUrl(url, ext) {
5352
+ var _this$player$preProce, _this$player;
5353
+ 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)) || {
5354
+ url,
5355
+ ext
5356
+ };
5357
+ }
5249
5358
  }, rtsOpts));
5250
5359
  _this._rts.load(config.url);
5251
5360
  });
@@ -5280,18 +5389,24 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5280
5389
  get: function get() {
5281
5390
  return this._rts;
5282
5391
  }
5392
+ }, {
5393
+ key: "loader",
5394
+ get: function get() {
5395
+ var _this$_rts5;
5396
+ return (_this$_rts5 = this._rts) === null || _this$_rts5 === void 0 ? void 0 : _this$_rts5.loader;
5397
+ }
5283
5398
  }, {
5284
5399
  key: "version",
5285
5400
  get: function get() {
5286
- return "0.2.0-alpha.3";
5401
+ return "0.2.0-alpha.5";
5287
5402
  }
5288
5403
  }, {
5289
5404
  key: "beforePlayerInit",
5290
5405
  value: function beforePlayerInit() {
5291
- var _this$player, _this2 = this;
5406
+ var _this$player2, _this2 = this;
5292
5407
  this._init();
5293
5408
  this.player.switchURL = this._onSwitchURL;
5294
- (_this$player = this.player) === null || _this$player === void 0 ? void 0 : _this$player.useHooks("replay", function() {
5409
+ (_this$player2 = this.player) === null || _this$player2 === void 0 ? void 0 : _this$player2.useHooks("replay", function() {
5295
5410
  var _this2$_rts;
5296
5411
  return (_this2$_rts = _this2._rts) === null || _this2$_rts === void 0 ? void 0 : _this2$_rts.switchURL();
5297
5412
  });
@@ -5326,14 +5441,14 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5326
5441
  }, {
5327
5442
  key: "getStats",
5328
5443
  value: function getStats2() {
5329
- var _this$_rts5;
5330
- return (_this$_rts5 = this._rts) === null || _this$_rts5 === void 0 ? void 0 : _this$_rts5.getStats();
5444
+ var _this$_rts6;
5445
+ return (_this$_rts6 = this._rts) === null || _this$_rts6 === void 0 ? void 0 : _this$_rts6.getStats();
5331
5446
  }
5332
5447
  }, {
5333
5448
  key: "getStatsSnapshoot",
5334
5449
  value: function getStatsSnapshoot2() {
5335
- var _this$_rts6;
5336
- return (_this$_rts6 = this._rts) === null || _this$_rts6 === void 0 ? void 0 : _this$_rts6.getStatsSnapshoot();
5450
+ var _this$_rts7;
5451
+ return (_this$_rts7 = this._rts) === null || _this$_rts7 === void 0 ? void 0 : _this$_rts7.getStatsSnapshoot();
5337
5452
  }
5338
5453
  }, {
5339
5454
  key: "_transErrorEvent",
@@ -5398,8 +5513,8 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5398
5513
  }, {
5399
5514
  key: "destroy",
5400
5515
  value: function destroy() {
5401
- var _this$_rts7;
5402
- (_this$_rts7 = this._rts) === null || _this$_rts7 === void 0 ? void 0 : _this$_rts7.destroy();
5516
+ var _this$_rts8;
5517
+ (_this$_rts8 = this._rts) === null || _this$_rts8 === void 0 ? void 0 : _this$_rts8.destroy();
5403
5518
  }
5404
5519
  }], [{
5405
5520
  key: "pluginName",
@@ -5464,6 +5579,7 @@ var RtsPlugin = /* @__PURE__ */ function(_BasePlugin) {
5464
5579
  }]);
5465
5580
  return RtsPlugin2;
5466
5581
  }(BasePlugin);
5582
+ var index = { RtmPlugin: RtsPlugin };
5467
5583
  export {
5468
- RtsPlugin as default
5584
+ index as default
5469
5585
  };