@volcengine/veplayer 2.0.0-rc.1 → 2.1.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 (38) hide show
  1. package/README.md +14 -1
  2. package/esm/index.d.ts +2055 -285
  3. package/esm/veplayer.biz.live.development.js +206 -46
  4. package/esm/veplayer.biz.live.production.js +1 -1
  5. package/esm/veplayer.d.ts +4468 -791
  6. package/esm/veplayer.development.css +1 -1
  7. package/esm/veplayer.development.js +884 -288
  8. package/esm/veplayer.live.d.ts +4534 -858
  9. package/esm/veplayer.live.development.css +1 -1
  10. package/esm/veplayer.live.development.js +884 -288
  11. package/esm/veplayer.live.production.css +1 -1
  12. package/esm/veplayer.live.production.js +4 -4
  13. package/esm/veplayer.production.css +1 -1
  14. package/esm/veplayer.production.js +4 -4
  15. package/esm/veplayer.vod.d.ts +2055 -285
  16. package/esm/veplayer.vod.development.css +1 -1
  17. package/esm/veplayer.vod.development.js +653 -213
  18. package/esm/veplayer.vod.production.css +1 -1
  19. package/esm/veplayer.vod.production.js +4 -4
  20. package/package.json +2 -1
  21. package/umd/index.d.ts +2055 -285
  22. package/umd/veplayer.biz.live.development.js +206 -46
  23. package/umd/veplayer.biz.live.production.js +1 -1
  24. package/umd/veplayer.d.ts +4468 -791
  25. package/umd/veplayer.development.css +1 -1
  26. package/umd/veplayer.development.js +884 -288
  27. package/umd/veplayer.live.d.ts +4534 -858
  28. package/umd/veplayer.live.development.css +1 -1
  29. package/umd/veplayer.live.development.js +882 -286
  30. package/umd/veplayer.live.production.css +1 -1
  31. package/umd/veplayer.live.production.js +1 -1
  32. package/umd/veplayer.production.css +1 -1
  33. package/umd/veplayer.production.js +1 -1
  34. package/umd/veplayer.vod.d.ts +2055 -285
  35. package/umd/veplayer.vod.development.css +1 -1
  36. package/umd/veplayer.vod.development.js +653 -213
  37. package/umd/veplayer.vod.production.css +1 -1
  38. package/umd/veplayer.vod.production.js +1 -1
@@ -7,7 +7,7 @@ var __publicField = (obj, key, value) => {
7
7
  const error = window["VePlayer"].error;
8
8
  const { VeError } = error;
9
9
  var LiveErrorCode = /* @__PURE__ */ ((LiveErrorCode2) => {
10
- LiveErrorCode2[LiveErrorCode2["INVALID_PARAMETER"] = 200] = "INVALID_PARAMETER";
10
+ LiveErrorCode2[LiveErrorCode2["INVALID_PARAMETER"] = 210] = "INVALID_PARAMETER";
11
11
  return LiveErrorCode2;
12
12
  })(LiveErrorCode || {});
13
13
  error.Level;
@@ -18,7 +18,7 @@ const ErrorCode = {
18
18
  const ERRORS = {
19
19
  ...error.ERROR_INFO,
20
20
  [
21
- 200
21
+ 210
22
22
  /* INVALID_PARAMETER */
23
23
  ]: {
24
24
  messageTextKey: "INVALID_PARAMETER",
@@ -28,6 +28,18 @@ const ERRORS = {
28
28
  function create(errorCode, i18n) {
29
29
  return new VeError(ERRORS[errorCode], i18n);
30
30
  }
31
+ const DynamicModule$2 = window["VePlayer"].DynamicModule;
32
+ const load$2 = window["VePlayer"].load;
33
+ async function isRTMSupported() {
34
+ const Rtm = await load$2(DynamicModule$2.PluginRtm);
35
+ return Rtm.isSupported();
36
+ }
37
+ async function isRTMSupportCodec(codec = RTMCodec.H264) {
38
+ const Rtm = await load$2(DynamicModule$2.PluginRtm);
39
+ if (codec === RTMCodec.H264)
40
+ return Rtm.isSupportedH264();
41
+ return false;
42
+ }
31
43
  const strategy$1 = window["VePlayer"].strategy;
32
44
  const util$3 = window["VePlayer"].util;
33
45
  const DynamicModule$1 = window["VePlayer"].DynamicModule;
@@ -38,11 +50,20 @@ const rtmStrategy = {
38
50
  options: {},
39
51
  module: DynamicModule$1.PluginRtm
40
52
  };
41
- const getRtmStrategy = async (options) => {
53
+ const generateFallbackUrl = (url) => {
54
+ if (Sniffer$2.device === "pc") {
55
+ return url.replace(".sdp", ".flv");
56
+ } else {
57
+ return url.replace(".sdp", ".m3u8");
58
+ }
59
+ };
60
+ const getRtmStrategy = async (options, player) => {
42
61
  var _a;
43
62
  let backupStrategy;
44
- const { fallbackUrl, ...ret } = options.rtm || {};
45
- const backupType = fallbackUrl && util$3.getStreamType(fallbackUrl);
63
+ const { url } = options;
64
+ const { fallbackUrl, enableFallback = true, ...ret } = options.rtm || {};
65
+ const actualFallbackUrl = !enableFallback ? "" : !fallbackUrl && url ? generateFallbackUrl(url) : fallbackUrl;
66
+ const backupType = actualFallbackUrl && util$3.getStreamType(actualFallbackUrl);
46
67
  if (backupType === "flv" && util$3.isMseSupported(Codec$1.H264)) {
47
68
  backupStrategy = strategy$1.createFlvMseStrategy(options);
48
69
  } else if (backupType === "hls" && (Sniffer$2.device !== "mobile" || ((_a = options == null ? void 0 : options.hls) == null ? void 0 : _a.enableMSE)) && util$3.isMseSupported(Codec$1.H264)) {
@@ -52,41 +73,57 @@ const getRtmStrategy = async (options) => {
52
73
  load$1(rtmStrategy.module).catch(() => void 0),
53
74
  backupStrategy && load$1(backupStrategy.module).catch(() => void 0)
54
75
  ]);
76
+ const [RTMSupported, RTMSupportCodec] = await Promise.all([
77
+ isRTMSupported(),
78
+ isRTMSupportCodec()
79
+ ]);
80
+ if (!RTMSupported || !RTMSupportCodec) {
81
+ if (player) {
82
+ player.emit("degrade", {
83
+ url: actualFallbackUrl,
84
+ originRtmUrl: url,
85
+ code: "NOT_SUPPORT",
86
+ message: "not support rtm or h264",
87
+ isRTMSupported: RTMSupported,
88
+ isRTMSupportCodec: RTMSupportCodec
89
+ });
90
+ }
91
+ return {
92
+ options: {
93
+ ...(backupStrategy == null ? void 0 : backupStrategy.options) || {},
94
+ url: actualFallbackUrl,
95
+ _RTMdegrade: {
96
+ _originRtmUrl: url,
97
+ _isRTMSupported: RTMSupported,
98
+ _isRTMSupportCodec: RTMSupportCodec
99
+ }
100
+ },
101
+ plugins: backupCdn ? [backupCdn] : []
102
+ };
103
+ }
55
104
  return {
56
105
  options: {
57
106
  ...(backupStrategy == null ? void 0 : backupStrategy.options) || {},
107
+ _RTMdegrade: void 0,
58
108
  rts: {
59
109
  retryCount: 0,
60
110
  ...ret,
61
- backupURL: fallbackUrl,
111
+ backupURL: actualFallbackUrl,
62
112
  backupConstruct: backupCdn
63
113
  }
64
114
  },
65
115
  plugins: rtmCdn ? [rtmCdn] : []
66
116
  };
67
117
  };
68
- var RTMCodec = /* @__PURE__ */ ((RTMCodec2) => {
69
- RTMCodec2["H264"] = "h264";
70
- return RTMCodec2;
71
- })(RTMCodec || {});
72
- const isRTMSupported = async () => {
73
- const Rtm = await load$1(DynamicModule$1.PluginRtm);
74
- return Rtm.isSupported();
75
- };
76
- const isRTMSupportCodec = async (codec = "h264", options) => {
77
- const Rtm = await load$1(DynamicModule$1.PluginRtm);
78
- if (codec === "h264")
79
- return Rtm.isSupportedH264(options == null ? void 0 : options.targetProfileLevel);
80
- };
81
118
  const util$2 = window["VePlayer"].util;
82
119
  const strategy = window["VePlayer"].strategy;
83
- const getTypeStrategy = async (options) => {
120
+ const getTypeStrategy = async (options, player) => {
84
121
  const type = options.url ? util$2.getStreamType(options.url) : "";
85
122
  if (!type || type === "unknown") {
86
123
  return { options: {}, plugins: [] };
87
124
  }
88
125
  if (type === "rtm") {
89
- return await getRtmStrategy(options);
126
+ return await getRtmStrategy(options, player);
90
127
  }
91
128
  if (type === "flv") {
92
129
  return await strategy.getFlvStrategy(options);
@@ -542,9 +579,9 @@ function getPlayFormat(url) {
542
579
  function isCodecSupport(codec) {
543
580
  return typeof MediaSource !== "undefined" ? +MediaSource.isTypeSupported("video/mp4; codecs=" + codec) : 0;
544
581
  }
545
- function getUrlQuery(url, key) {
582
+ function getUrlQuery(url, key, key2) {
546
583
  var x2 = new URLSearchParams(url.split("?")[1]);
547
- return x2.get(key);
584
+ return x2.get(key) || x2.get(key2);
548
585
  }
549
586
  function getDeviceInfo() {
550
587
  var res = {
@@ -571,19 +608,11 @@ function getPlayerCore(player) {
571
608
  return player.plugins.hls;
572
609
  } else if (player.plugins.rts) {
573
610
  return player.plugins.rts;
574
- } else if (player.plugins.flvlive) {
575
- return player.plugins.flvlive;
576
- } else if (player.plugins.hlslive) {
577
- return player.plugins.hlslive;
578
- } else if (player.plugins.hlsvod) {
579
- return player.plugins.hlsvod;
580
- } else if (player.plugins.hlslivemobile) {
581
- return player.plugins.hlslivemobile;
582
- } else if (player.plugins.flvlivemobile) {
583
- return player.plugins.flvlivemobile;
584
- }
585
- }
586
- return player.newHls || player.newFlv || player.__core__ || player.flv;
611
+ } else if (player.plugins.rtm) {
612
+ return player.plugins.rtm;
613
+ }
614
+ }
615
+ return null;
587
616
  }
588
617
  function getDefaultOptions(options) {
589
618
  return {
@@ -812,7 +841,7 @@ function getCommonLog(options) {
812
841
  live_sdk_version: getPlayerCore(player) || player.hlsOps ? "2" : "-1",
813
842
  player_sdk_version: player.version,
814
843
  // eslint-disable-next-line no-undef
815
- logger_version: "1.1.0-alpha.5",
844
+ logger_version: "1.1.0-alpha.7",
816
845
  // 由rollup 在编译时注入
817
846
  report_version: "5",
818
847
  product_line: options.product_line,
@@ -936,9 +965,13 @@ var Manage = /* @__PURE__ */ function() {
936
965
  if (this._player.video) {
937
966
  log.play_current_time = this._player.currentTime;
938
967
  }
939
- log.cdn_play_url = url && url.startsWith("//") ? window.location.protocol + url : url;
940
- log.live_stream_session_id = getUrlQuery(url, "session_id");
941
- log.play_format = getPlayFormat(url);
968
+ if (this.core && this.core.loader && this.core.loader.finnalUrl) {
969
+ log.cdn_play_url = this.core.loader.finnalUrl;
970
+ } else {
971
+ log.cdn_play_url = url && url.startsWith("//") ? window.location.protocol + url : url;
972
+ }
973
+ log.live_stream_session_id = getUrlQuery(log.cdn_play_url, "_session_id", "session_id");
974
+ log.play_format = getPlayFormat(log.cdn_play_url);
942
975
  log.timestamp = getCurrentTime();
943
976
  var _getDeviceInfo = getDeviceInfo(), cpu_core_number = _getDeviceInfo.cpu_core_number, memory_usage = _getDeviceInfo.memory_usage, network_downlink = _getDeviceInfo.network_downlink;
944
977
  log.cpu_core_number = cpu_core_number;
@@ -1164,6 +1197,11 @@ var XgLiveLogger = /* @__PURE__ */ function() {
1164
1197
  };
1165
1198
  _proto2.reportStartPlay = function reportStartPlay() {
1166
1199
  if (!this.started) {
1200
+ this.core = getPlayerCore(this.player);
1201
+ if (this.core) {
1202
+ this.commonParams.live_sdk_version = "2";
1203
+ this.logmanager.core = this.core;
1204
+ }
1167
1205
  this.started = true;
1168
1206
  this.log.start_play.start_play_time = this.log.start_play.timestamp = getCurrentTime();
1169
1207
  this.logmanager.push(this.log.start_play, true);
@@ -1428,6 +1466,7 @@ var XgLiveLogger = /* @__PURE__ */ function() {
1428
1466
  this.core = getPlayerCore(this.player);
1429
1467
  if (this.core) {
1430
1468
  this.commonParams.live_sdk_version = "2";
1469
+ this.logmanager.core = this.core;
1431
1470
  }
1432
1471
  if (this.player.config.autoplay || this.player.config.videoInit) {
1433
1472
  this.reportStartPlay();
@@ -2680,6 +2719,45 @@ var T = 4003, C = function() {
2680
2719
  this.event("predefine_pageview", n2);
2681
2720
  }, t2;
2682
2721
  }(), q = new R("default");
2722
+ let getRandomValues;
2723
+ const rnds8 = new Uint8Array(16);
2724
+ function rng() {
2725
+ if (!getRandomValues) {
2726
+ getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
2727
+ if (!getRandomValues) {
2728
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
2729
+ }
2730
+ }
2731
+ return getRandomValues(rnds8);
2732
+ }
2733
+ const byteToHex = [];
2734
+ for (let i2 = 0; i2 < 256; ++i2) {
2735
+ byteToHex.push((i2 + 256).toString(16).slice(1));
2736
+ }
2737
+ function unsafeStringify(arr, offset = 0) {
2738
+ return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
2739
+ }
2740
+ const randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
2741
+ var native = {
2742
+ randomUUID
2743
+ };
2744
+ function v4(options, buf, offset) {
2745
+ if (native.randomUUID && !buf && !options) {
2746
+ return native.randomUUID();
2747
+ }
2748
+ options = options || {};
2749
+ const rnds = options.random || (options.rng || rng)();
2750
+ rnds[6] = rnds[6] & 15 | 64;
2751
+ rnds[8] = rnds[8] & 63 | 128;
2752
+ if (buf) {
2753
+ offset = offset || 0;
2754
+ for (let i2 = 0; i2 < 16; ++i2) {
2755
+ buf[offset + i2] = rnds[i2];
2756
+ }
2757
+ return buf;
2758
+ }
2759
+ return unsafeStringify(rnds);
2760
+ }
2683
2761
  const DEVICE_ID_KEY = "veplayer_live_device_id";
2684
2762
  const USER_ID_Key = "veplayer_live_user_id";
2685
2763
  const genRandomID2 = (length) => {
@@ -2705,6 +2783,45 @@ const getUserId2 = () => {
2705
2783
  localStorage.setItem(USER_ID_Key, userId);
2706
2784
  return userId;
2707
2785
  };
2786
+ const generateUrlWithSessionId = (url) => {
2787
+ var _a, _b;
2788
+ if (!url) {
2789
+ return "";
2790
+ }
2791
+ const withoutProtocol = url.startsWith("//");
2792
+ if (withoutProtocol) {
2793
+ url = location.protocol + url;
2794
+ }
2795
+ try {
2796
+ const urlObject = new URL(url);
2797
+ if ((_a = urlObject == null ? void 0 : urlObject.searchParams) == null ? void 0 : _a.get("_session_id")) {
2798
+ return url;
2799
+ }
2800
+ (_b = urlObject == null ? void 0 : urlObject.searchParams) == null ? void 0 : _b.append("_session_id", generateSessionId());
2801
+ return urlObject.toString();
2802
+ } catch (error2) {
2803
+ return url;
2804
+ }
2805
+ };
2806
+ const hashCode = (str) => {
2807
+ str += "";
2808
+ let h2 = 0;
2809
+ let off = 0;
2810
+ const len = str.length;
2811
+ for (let i2 = 0; i2 < len; i2++) {
2812
+ h2 = 31 * h2 + str.charCodeAt(off++);
2813
+ if (h2 > 140737488355327 || h2 < -140737488355328) {
2814
+ h2 &= 281474976710655;
2815
+ }
2816
+ }
2817
+ if (h2 < 0) {
2818
+ h2 += 2251799813685247;
2819
+ }
2820
+ return h2;
2821
+ };
2822
+ const generateSessionId = () => {
2823
+ return v4().replace(/-/g, "") + "." + Date.now() + "." + hashCode(v4().replace(/-/g, ""));
2824
+ };
2708
2825
  const Plugin$2 = window["VePlayer"].Plugin;
2709
2826
  const CN_APPID = 468759;
2710
2827
  const CHANNEL = "cn";
@@ -2784,10 +2901,10 @@ class Logger extends Plugin$2 {
2784
2901
  user_id: this._userId,
2785
2902
  device_id: this._deviceId,
2786
2903
  ext: {
2787
- veplayer_version: "2.0.0-rc.0",
2788
- flv_version: "3.0.0-next.23",
2789
- hls_version: "3.0.0-next.36-1",
2790
- rts_version: "0.2.0-alpha.3"
2904
+ veplayer_version: "2.1.0-rc.0",
2905
+ flv_version: "3.0.10-alpha.4",
2906
+ hls_version: "3.0.10-alpha.4",
2907
+ rts_version: "0.2.0-alpha.5"
2791
2908
  }
2792
2909
  });
2793
2910
  }
@@ -3072,25 +3189,51 @@ const LIVE_DEFAULT_OPTIONS = {
3072
3189
  autoplay: { muted: true }
3073
3190
  };
3074
3191
  const LIVE_DEFAULT_PLUGINS = [...DEFAULT_PLUGINS, Refresh, Logger, InfoPanel];
3192
+ var RTMCodec = /* @__PURE__ */ ((RTMCodec2) => {
3193
+ RTMCodec2["H264"] = "h264";
3194
+ return RTMCodec2;
3195
+ })(RTMCodec || {});
3075
3196
  class VePlayerLive extends VePlayerBase {
3197
+ /**
3198
+ * @hidden
3199
+ * @param options
3200
+ */
3201
+ constructor(options) {
3202
+ super(options);
3203
+ }
3204
+ /** {zh}
3205
+ * @brief 调用此方法开启直播日志上报。
3206
+ */
3076
3207
  openLog() {
3077
3208
  var _a;
3078
3209
  (_a = this._player.plugins) == null ? void 0 : _a.logger.open();
3079
3210
  }
3211
+ /** {zh}
3212
+ * @brief 调用此方法关闭直播日志上报。
3213
+ */
3080
3214
  closeLog() {
3081
3215
  var _a;
3082
3216
  (_a = this._player.plugins) == null ? void 0 : _a.logger.close();
3083
3217
  }
3218
+ /** {zh}
3219
+ * @brief 调用此方法将打开直播信息面板,面板将展示拉流格式、帧率、码率、GOP、视频分辨率、编码方式、Buffer 水位、播放进度等基础信息。如果当前是软解,还会显示软解解码效率和解码消耗。
3220
+ */
3084
3221
  openInfoPanel() {
3085
3222
  var _a;
3086
3223
  (_a = this._player.plugins) == null ? void 0 : _a.infopanel.open();
3087
3224
  }
3225
+ /** {zh}
3226
+ * @brief 调用此方法关闭直播信息面板。
3227
+ *
3228
+ */
3088
3229
  closeInfoPanel() {
3089
3230
  var _a;
3090
3231
  (_a = this._player.plugins) == null ? void 0 : _a.infopanel.close();
3091
3232
  }
3092
3233
  }
3093
3234
  async function createLivePlayer(options) {
3235
+ var _a, _b;
3236
+ let player = void 0;
3094
3237
  if (!options || !options.url && !options.playlist) {
3095
3238
  throw create(ErrorCode.INVALID_PARAMETER, new VeI18n());
3096
3239
  }
@@ -3099,18 +3242,35 @@ async function createLivePlayer(options) {
3099
3242
  ...options,
3100
3243
  plugins: [...LIVE_DEFAULT_PLUGINS, ...options.plugins ?? []]
3101
3244
  };
3102
- const player = await VePlayerBase.create(
3245
+ player = await VePlayerBase.create(
3103
3246
  {
3104
3247
  ...LIVE_DEFAULT_OPTIONS,
3105
3248
  ...finalOptions,
3106
3249
  isLive: true,
3107
3250
  i18nManager: i18n,
3251
+ preProcessUrl: (url) => {
3252
+ return {
3253
+ url: generateUrlWithSessionId(url)
3254
+ };
3255
+ },
3108
3256
  async preparePlugins(url) {
3109
- return getTypeStrategy({ ...finalOptions, url });
3257
+ return getTypeStrategy({ ...finalOptions, url }, player);
3110
3258
  }
3111
3259
  },
3112
3260
  VePlayerLive
3113
3261
  );
3262
+ if (player) {
3263
+ const RTMDegrade = (_b = (_a = player == null ? void 0 : player._player) == null ? void 0 : _a.config) == null ? void 0 : _b._RTMdegrade;
3264
+ if (RTMDegrade) {
3265
+ player.emit("degrade", {
3266
+ originRtmUrl: RTMDegrade._originRtmUrl,
3267
+ code: "NOT_SUPPORT",
3268
+ message: "not support rtm or h264",
3269
+ isRTMSupported: RTMDegrade._isRTMSupported,
3270
+ isRTMSupportCodec: RTMDegrade._isRTMSupportCodec
3271
+ });
3272
+ }
3273
+ }
3114
3274
  return player;
3115
3275
  }
3116
3276
  var live = /* @__PURE__ */ Object.freeze({