@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
@@ -11,7 +11,7 @@ var __publicField = (obj, key, value) => {
11
11
  const error = window["VePlayer"].error;
12
12
  const { VeError } = error;
13
13
  var LiveErrorCode = /* @__PURE__ */ ((LiveErrorCode2) => {
14
- LiveErrorCode2[LiveErrorCode2["INVALID_PARAMETER"] = 200] = "INVALID_PARAMETER";
14
+ LiveErrorCode2[LiveErrorCode2["INVALID_PARAMETER"] = 210] = "INVALID_PARAMETER";
15
15
  return LiveErrorCode2;
16
16
  })(LiveErrorCode || {});
17
17
  error.Level;
@@ -22,7 +22,7 @@ var __publicField = (obj, key, value) => {
22
22
  const ERRORS = {
23
23
  ...error.ERROR_INFO,
24
24
  [
25
- 200
25
+ 210
26
26
  /* INVALID_PARAMETER */
27
27
  ]: {
28
28
  messageTextKey: "INVALID_PARAMETER",
@@ -32,6 +32,18 @@ var __publicField = (obj, key, value) => {
32
32
  function create(errorCode, i18n) {
33
33
  return new VeError(ERRORS[errorCode], i18n);
34
34
  }
35
+ const DynamicModule$2 = window["VePlayer"].DynamicModule;
36
+ const load$2 = window["VePlayer"].load;
37
+ async function isRTMSupported() {
38
+ const Rtm = await load$2(DynamicModule$2.PluginRtm);
39
+ return Rtm.isSupported();
40
+ }
41
+ async function isRTMSupportCodec(codec = RTMCodec.H264) {
42
+ const Rtm = await load$2(DynamicModule$2.PluginRtm);
43
+ if (codec === RTMCodec.H264)
44
+ return Rtm.isSupportedH264();
45
+ return false;
46
+ }
35
47
  const strategy$1 = window["VePlayer"].strategy;
36
48
  const util$3 = window["VePlayer"].util;
37
49
  const DynamicModule$1 = window["VePlayer"].DynamicModule;
@@ -42,11 +54,20 @@ var __publicField = (obj, key, value) => {
42
54
  options: {},
43
55
  module: DynamicModule$1.PluginRtm
44
56
  };
45
- const getRtmStrategy = async (options) => {
57
+ const generateFallbackUrl = (url) => {
58
+ if (Sniffer$2.device === "pc") {
59
+ return url.replace(".sdp", ".flv");
60
+ } else {
61
+ return url.replace(".sdp", ".m3u8");
62
+ }
63
+ };
64
+ const getRtmStrategy = async (options, player) => {
46
65
  var _a;
47
66
  let backupStrategy;
48
- const { fallbackUrl, ...ret } = options.rtm || {};
49
- const backupType = fallbackUrl && util$3.getStreamType(fallbackUrl);
67
+ const { url } = options;
68
+ const { fallbackUrl, enableFallback = true, ...ret } = options.rtm || {};
69
+ const actualFallbackUrl = !enableFallback ? "" : !fallbackUrl && url ? generateFallbackUrl(url) : fallbackUrl;
70
+ const backupType = actualFallbackUrl && util$3.getStreamType(actualFallbackUrl);
50
71
  if (backupType === "flv" && util$3.isMseSupported(Codec$1.H264)) {
51
72
  backupStrategy = strategy$1.createFlvMseStrategy(options);
52
73
  } 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)) {
@@ -56,41 +77,57 @@ var __publicField = (obj, key, value) => {
56
77
  load$1(rtmStrategy.module).catch(() => void 0),
57
78
  backupStrategy && load$1(backupStrategy.module).catch(() => void 0)
58
79
  ]);
80
+ const [RTMSupported, RTMSupportCodec] = await Promise.all([
81
+ isRTMSupported(),
82
+ isRTMSupportCodec()
83
+ ]);
84
+ if (!RTMSupported || !RTMSupportCodec) {
85
+ if (player) {
86
+ player.emit("degrade", {
87
+ url: actualFallbackUrl,
88
+ originRtmUrl: url,
89
+ code: "NOT_SUPPORT",
90
+ message: "not support rtm or h264",
91
+ isRTMSupported: RTMSupported,
92
+ isRTMSupportCodec: RTMSupportCodec
93
+ });
94
+ }
95
+ return {
96
+ options: {
97
+ ...(backupStrategy == null ? void 0 : backupStrategy.options) || {},
98
+ url: actualFallbackUrl,
99
+ _RTMdegrade: {
100
+ _originRtmUrl: url,
101
+ _isRTMSupported: RTMSupported,
102
+ _isRTMSupportCodec: RTMSupportCodec
103
+ }
104
+ },
105
+ plugins: backupCdn ? [backupCdn] : []
106
+ };
107
+ }
59
108
  return {
60
109
  options: {
61
110
  ...(backupStrategy == null ? void 0 : backupStrategy.options) || {},
111
+ _RTMdegrade: void 0,
62
112
  rts: {
63
113
  retryCount: 0,
64
114
  ...ret,
65
- backupURL: fallbackUrl,
115
+ backupURL: actualFallbackUrl,
66
116
  backupConstruct: backupCdn
67
117
  }
68
118
  },
69
119
  plugins: rtmCdn ? [rtmCdn] : []
70
120
  };
71
121
  };
72
- var RTMCodec = /* @__PURE__ */ ((RTMCodec2) => {
73
- RTMCodec2["H264"] = "h264";
74
- return RTMCodec2;
75
- })(RTMCodec || {});
76
- const isRTMSupported = async () => {
77
- const Rtm = await load$1(DynamicModule$1.PluginRtm);
78
- return Rtm.isSupported();
79
- };
80
- const isRTMSupportCodec = async (codec = "h264", options) => {
81
- const Rtm = await load$1(DynamicModule$1.PluginRtm);
82
- if (codec === "h264")
83
- return Rtm.isSupportedH264(options == null ? void 0 : options.targetProfileLevel);
84
- };
85
122
  const util$2 = window["VePlayer"].util;
86
123
  const strategy = window["VePlayer"].strategy;
87
- const getTypeStrategy = async (options) => {
124
+ const getTypeStrategy = async (options, player) => {
88
125
  const type = options.url ? util$2.getStreamType(options.url) : "";
89
126
  if (!type || type === "unknown") {
90
127
  return { options: {}, plugins: [] };
91
128
  }
92
129
  if (type === "rtm") {
93
- return await getRtmStrategy(options);
130
+ return await getRtmStrategy(options, player);
94
131
  }
95
132
  if (type === "flv") {
96
133
  return await strategy.getFlvStrategy(options);
@@ -546,9 +583,9 @@ var __publicField = (obj, key, value) => {
546
583
  function isCodecSupport(codec) {
547
584
  return typeof MediaSource !== "undefined" ? +MediaSource.isTypeSupported("video/mp4; codecs=" + codec) : 0;
548
585
  }
549
- function getUrlQuery(url, key) {
586
+ function getUrlQuery(url, key, key2) {
550
587
  var x2 = new URLSearchParams(url.split("?")[1]);
551
- return x2.get(key);
588
+ return x2.get(key) || x2.get(key2);
552
589
  }
553
590
  function getDeviceInfo() {
554
591
  var res = {
@@ -575,19 +612,11 @@ var __publicField = (obj, key, value) => {
575
612
  return player.plugins.hls;
576
613
  } else if (player.plugins.rts) {
577
614
  return player.plugins.rts;
578
- } else if (player.plugins.flvlive) {
579
- return player.plugins.flvlive;
580
- } else if (player.plugins.hlslive) {
581
- return player.plugins.hlslive;
582
- } else if (player.plugins.hlsvod) {
583
- return player.plugins.hlsvod;
584
- } else if (player.plugins.hlslivemobile) {
585
- return player.plugins.hlslivemobile;
586
- } else if (player.plugins.flvlivemobile) {
587
- return player.plugins.flvlivemobile;
588
- }
589
- }
590
- return player.newHls || player.newFlv || player.__core__ || player.flv;
615
+ } else if (player.plugins.rtm) {
616
+ return player.plugins.rtm;
617
+ }
618
+ }
619
+ return null;
591
620
  }
592
621
  function getDefaultOptions(options) {
593
622
  return {
@@ -816,7 +845,7 @@ var __publicField = (obj, key, value) => {
816
845
  live_sdk_version: getPlayerCore(player) || player.hlsOps ? "2" : "-1",
817
846
  player_sdk_version: player.version,
818
847
  // eslint-disable-next-line no-undef
819
- logger_version: "1.1.0-alpha.5",
848
+ logger_version: "1.1.0-alpha.7",
820
849
  // 由rollup 在编译时注入
821
850
  report_version: "5",
822
851
  product_line: options.product_line,
@@ -940,9 +969,13 @@ var __publicField = (obj, key, value) => {
940
969
  if (this._player.video) {
941
970
  log.play_current_time = this._player.currentTime;
942
971
  }
943
- log.cdn_play_url = url && url.startsWith("//") ? window.location.protocol + url : url;
944
- log.live_stream_session_id = getUrlQuery(url, "session_id");
945
- log.play_format = getPlayFormat(url);
972
+ if (this.core && this.core.loader && this.core.loader.finnalUrl) {
973
+ log.cdn_play_url = this.core.loader.finnalUrl;
974
+ } else {
975
+ log.cdn_play_url = url && url.startsWith("//") ? window.location.protocol + url : url;
976
+ }
977
+ log.live_stream_session_id = getUrlQuery(log.cdn_play_url, "_session_id", "session_id");
978
+ log.play_format = getPlayFormat(log.cdn_play_url);
946
979
  log.timestamp = getCurrentTime();
947
980
  var _getDeviceInfo = getDeviceInfo(), cpu_core_number = _getDeviceInfo.cpu_core_number, memory_usage = _getDeviceInfo.memory_usage, network_downlink = _getDeviceInfo.network_downlink;
948
981
  log.cpu_core_number = cpu_core_number;
@@ -1168,6 +1201,11 @@ var __publicField = (obj, key, value) => {
1168
1201
  };
1169
1202
  _proto2.reportStartPlay = function reportStartPlay() {
1170
1203
  if (!this.started) {
1204
+ this.core = getPlayerCore(this.player);
1205
+ if (this.core) {
1206
+ this.commonParams.live_sdk_version = "2";
1207
+ this.logmanager.core = this.core;
1208
+ }
1171
1209
  this.started = true;
1172
1210
  this.log.start_play.start_play_time = this.log.start_play.timestamp = getCurrentTime();
1173
1211
  this.logmanager.push(this.log.start_play, true);
@@ -1432,6 +1470,7 @@ var __publicField = (obj, key, value) => {
1432
1470
  this.core = getPlayerCore(this.player);
1433
1471
  if (this.core) {
1434
1472
  this.commonParams.live_sdk_version = "2";
1473
+ this.logmanager.core = this.core;
1435
1474
  }
1436
1475
  if (this.player.config.autoplay || this.player.config.videoInit) {
1437
1476
  this.reportStartPlay();
@@ -2684,6 +2723,45 @@ var __publicField = (obj, key, value) => {
2684
2723
  this.event("predefine_pageview", n2);
2685
2724
  }, t2;
2686
2725
  }(), q = new R("default");
2726
+ let getRandomValues;
2727
+ const rnds8 = new Uint8Array(16);
2728
+ function rng() {
2729
+ if (!getRandomValues) {
2730
+ getRandomValues = typeof crypto !== "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
2731
+ if (!getRandomValues) {
2732
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
2733
+ }
2734
+ }
2735
+ return getRandomValues(rnds8);
2736
+ }
2737
+ const byteToHex = [];
2738
+ for (let i2 = 0; i2 < 256; ++i2) {
2739
+ byteToHex.push((i2 + 256).toString(16).slice(1));
2740
+ }
2741
+ function unsafeStringify(arr, offset = 0) {
2742
+ 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]];
2743
+ }
2744
+ const randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
2745
+ var native = {
2746
+ randomUUID
2747
+ };
2748
+ function v4(options, buf, offset) {
2749
+ if (native.randomUUID && !buf && !options) {
2750
+ return native.randomUUID();
2751
+ }
2752
+ options = options || {};
2753
+ const rnds = options.random || (options.rng || rng)();
2754
+ rnds[6] = rnds[6] & 15 | 64;
2755
+ rnds[8] = rnds[8] & 63 | 128;
2756
+ if (buf) {
2757
+ offset = offset || 0;
2758
+ for (let i2 = 0; i2 < 16; ++i2) {
2759
+ buf[offset + i2] = rnds[i2];
2760
+ }
2761
+ return buf;
2762
+ }
2763
+ return unsafeStringify(rnds);
2764
+ }
2687
2765
  const DEVICE_ID_KEY = "veplayer_live_device_id";
2688
2766
  const USER_ID_Key = "veplayer_live_user_id";
2689
2767
  const genRandomID = (length) => {
@@ -2709,6 +2787,45 @@ var __publicField = (obj, key, value) => {
2709
2787
  localStorage.setItem(USER_ID_Key, userId);
2710
2788
  return userId;
2711
2789
  };
2790
+ const generateUrlWithSessionId = (url) => {
2791
+ var _a, _b;
2792
+ if (!url) {
2793
+ return "";
2794
+ }
2795
+ const withoutProtocol = url.startsWith("//");
2796
+ if (withoutProtocol) {
2797
+ url = location.protocol + url;
2798
+ }
2799
+ try {
2800
+ const urlObject = new URL(url);
2801
+ if ((_a = urlObject == null ? void 0 : urlObject.searchParams) == null ? void 0 : _a.get("_session_id")) {
2802
+ return url;
2803
+ }
2804
+ (_b = urlObject == null ? void 0 : urlObject.searchParams) == null ? void 0 : _b.append("_session_id", generateSessionId());
2805
+ return urlObject.toString();
2806
+ } catch (error2) {
2807
+ return url;
2808
+ }
2809
+ };
2810
+ const hashCode = (str) => {
2811
+ str += "";
2812
+ let h2 = 0;
2813
+ let off = 0;
2814
+ const len = str.length;
2815
+ for (let i2 = 0; i2 < len; i2++) {
2816
+ h2 = 31 * h2 + str.charCodeAt(off++);
2817
+ if (h2 > 140737488355327 || h2 < -140737488355328) {
2818
+ h2 &= 281474976710655;
2819
+ }
2820
+ }
2821
+ if (h2 < 0) {
2822
+ h2 += 2251799813685247;
2823
+ }
2824
+ return h2;
2825
+ };
2826
+ const generateSessionId = () => {
2827
+ return v4().replace(/-/g, "") + "." + Date.now() + "." + hashCode(v4().replace(/-/g, ""));
2828
+ };
2712
2829
  const Plugin$2 = window["VePlayer"].Plugin;
2713
2830
  const CN_APPID = 468759;
2714
2831
  const CHANNEL = "cn";
@@ -2788,10 +2905,10 @@ var __publicField = (obj, key, value) => {
2788
2905
  user_id: this._userId,
2789
2906
  device_id: this._deviceId,
2790
2907
  ext: {
2791
- veplayer_version: "2.0.0-rc.0",
2792
- flv_version: "3.0.0-next.23",
2793
- hls_version: "3.0.0-next.36-1",
2794
- rts_version: "0.2.0-alpha.3"
2908
+ veplayer_version: "2.1.0-rc.0",
2909
+ flv_version: "3.0.10-alpha.4",
2910
+ hls_version: "3.0.10-alpha.4",
2911
+ rts_version: "0.2.0-alpha.5"
2795
2912
  }
2796
2913
  });
2797
2914
  }
@@ -3076,25 +3193,51 @@ var __publicField = (obj, key, value) => {
3076
3193
  autoplay: { muted: true }
3077
3194
  };
3078
3195
  const LIVE_DEFAULT_PLUGINS = [...DEFAULT_PLUGINS, Refresh, Logger, InfoPanel];
3196
+ var RTMCodec = /* @__PURE__ */ ((RTMCodec2) => {
3197
+ RTMCodec2["H264"] = "h264";
3198
+ return RTMCodec2;
3199
+ })(RTMCodec || {});
3079
3200
  class VePlayerLive extends VePlayerBase {
3201
+ /**
3202
+ * @hidden
3203
+ * @param options
3204
+ */
3205
+ constructor(options) {
3206
+ super(options);
3207
+ }
3208
+ /** {zh}
3209
+ * @brief 调用此方法开启直播日志上报。
3210
+ */
3080
3211
  openLog() {
3081
3212
  var _a;
3082
3213
  (_a = this._player.plugins) == null ? void 0 : _a.logger.open();
3083
3214
  }
3215
+ /** {zh}
3216
+ * @brief 调用此方法关闭直播日志上报。
3217
+ */
3084
3218
  closeLog() {
3085
3219
  var _a;
3086
3220
  (_a = this._player.plugins) == null ? void 0 : _a.logger.close();
3087
3221
  }
3222
+ /** {zh}
3223
+ * @brief 调用此方法将打开直播信息面板,面板将展示拉流格式、帧率、码率、GOP、视频分辨率、编码方式、Buffer 水位、播放进度等基础信息。如果当前是软解,还会显示软解解码效率和解码消耗。
3224
+ */
3088
3225
  openInfoPanel() {
3089
3226
  var _a;
3090
3227
  (_a = this._player.plugins) == null ? void 0 : _a.infopanel.open();
3091
3228
  }
3229
+ /** {zh}
3230
+ * @brief 调用此方法关闭直播信息面板。
3231
+ *
3232
+ */
3092
3233
  closeInfoPanel() {
3093
3234
  var _a;
3094
3235
  (_a = this._player.plugins) == null ? void 0 : _a.infopanel.close();
3095
3236
  }
3096
3237
  }
3097
3238
  async function createLivePlayer(options) {
3239
+ var _a, _b;
3240
+ let player = void 0;
3098
3241
  if (!options || !options.url && !options.playlist) {
3099
3242
  throw create(ErrorCode.INVALID_PARAMETER, new VeI18n());
3100
3243
  }
@@ -3103,18 +3246,35 @@ var __publicField = (obj, key, value) => {
3103
3246
  ...options,
3104
3247
  plugins: [...LIVE_DEFAULT_PLUGINS, ...options.plugins ?? []]
3105
3248
  };
3106
- const player = await VePlayerBase.create(
3249
+ player = await VePlayerBase.create(
3107
3250
  {
3108
3251
  ...LIVE_DEFAULT_OPTIONS,
3109
3252
  ...finalOptions,
3110
3253
  isLive: true,
3111
3254
  i18nManager: i18n,
3255
+ preProcessUrl: (url) => {
3256
+ return {
3257
+ url: generateUrlWithSessionId(url)
3258
+ };
3259
+ },
3112
3260
  async preparePlugins(url) {
3113
- return getTypeStrategy({ ...finalOptions, url });
3261
+ return getTypeStrategy({ ...finalOptions, url }, player);
3114
3262
  }
3115
3263
  },
3116
3264
  VePlayerLive
3117
3265
  );
3266
+ if (player) {
3267
+ const RTMDegrade = (_b = (_a = player == null ? void 0 : player._player) == null ? void 0 : _a.config) == null ? void 0 : _b._RTMdegrade;
3268
+ if (RTMDegrade) {
3269
+ player.emit("degrade", {
3270
+ originRtmUrl: RTMDegrade._originRtmUrl,
3271
+ code: "NOT_SUPPORT",
3272
+ message: "not support rtm or h264",
3273
+ isRTMSupported: RTMDegrade._isRTMSupported,
3274
+ isRTMSupportCodec: RTMDegrade._isRTMSupportCodec
3275
+ });
3276
+ }
3277
+ }
3118
3278
  return player;
3119
3279
  }
3120
3280
  var live = /* @__PURE__ */ Object.freeze({