@volcengine/veplayer 2.5.1 → 2.5.2-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.
package/esm/index.d.ts CHANGED
@@ -419,7 +419,14 @@ declare enum Level {
419
419
  /** {en}
420
420
  * @brief Error.
421
421
  */
422
- Error = "Error"
422
+ Error = "Error",
423
+ /** {zh}
424
+ * @brief 提示。
425
+ */
426
+ /** {en}
427
+ * @brief Warn.
428
+ */
429
+ Warn = "Warn"
423
430
  }
424
431
  declare enum ErrorCode {
425
432
  /** {zh}
@@ -1501,15 +1508,16 @@ type PrepareResult = {
1501
1508
  options?: Partial<VePlayerBaseOptions>;
1502
1509
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1503
1510
  plugins?: any[];
1511
+ useSrc?: boolean;
1504
1512
  };
1505
1513
  type PreparePlugins = (url: string) => Promise<PrepareResult> | undefined;
1506
1514
  /** {zh}
1507
1515
  * @detail option
1508
- * @brief 视频的实际编码格式。如果您在degradation 设置了 SoftFirst 属性(即硬解不支持降级软解),建议您传入该参数,省去探测实际编码格式的操作。
1516
+ * @brief 视频的实际编码格式。如果您在 degradation 设置了 SoftFirst 属性(即硬解不支持降级软解),建议您传入该参数,省去探测实际编码格式的操作。
1509
1517
  */
1510
1518
  /** {en}
1511
1519
  * @detail option
1512
- * @brief The actual codec of the video.
1520
+ * @brief The actual codec of the video. If you set the SoftFirst property in degradation (that is, hard solutions do not support downgrading soft solutions), it is recommended that you pass this parameter to save the operation of probing the actual encoding format.
1513
1521
  */
1514
1522
  declare enum Codec {
1515
1523
  /** {zh}
@@ -2147,16 +2155,17 @@ declare class VePlayerBase {
2147
2155
  * @hidden
2148
2156
  */
2149
2157
  prepare(url: string): Promise<{
2150
- plugins: any[];
2158
+ plugins: any[] | undefined;
2151
2159
  options: Partial<VePlayerBaseOptions> | undefined;
2160
+ isSameProtocol: boolean | "";
2161
+ useSrc: boolean | undefined;
2152
2162
  }>;
2153
2163
  private _handleFallback;
2154
2164
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2155
2165
  private _transformEvent;
2156
2166
  private _switch;
2167
+ private _switchDifferentProtocolUrl;
2157
2168
  private _switchUrl;
2158
- // 获取需要卸载和需要注册的播放插件
2159
- private _diffPlugins;
2160
2169
  private _callBeforePlayerInitForUrl;
2161
2170
  }
2162
2171
  declare const enum State {
@@ -2679,7 +2688,14 @@ declare namespace strategy {
2679
2688
  /** {en}
2680
2689
  * @brief Error.
2681
2690
  */
2682
- Error = "Error"
2691
+ Error = "Error",
2692
+ /** {zh}
2693
+ * @brief 提示。
2694
+ */
2695
+ /** {en}
2696
+ * @brief Warn.
2697
+ */
2698
+ Warn = "Warn"
2683
2699
  }
2684
2700
  enum ErrorCode {
2685
2701
  /** {zh}
@@ -3824,15 +3840,16 @@ declare namespace strategy {
3824
3840
  options?: Partial<VePlayerBaseOptions>;
3825
3841
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3826
3842
  plugins?: any[];
3843
+ useSrc?: boolean;
3827
3844
  };
3828
3845
  type PreparePlugins = (url: string) => Promise<PrepareResult> | undefined;
3829
3846
  /** {zh}
3830
3847
  * @detail option
3831
- * @brief 视频的实际编码格式。如果您在degradation 设置了 SoftFirst 属性(即硬解不支持降级软解),建议您传入该参数,省去探测实际编码格式的操作。
3848
+ * @brief 视频的实际编码格式。如果您在 degradation 设置了 SoftFirst 属性(即硬解不支持降级软解),建议您传入该参数,省去探测实际编码格式的操作。
3832
3849
  */
3833
3850
  /** {en}
3834
3851
  * @detail option
3835
- * @brief The actual codec of the video.
3852
+ * @brief The actual codec of the video. If you set the SoftFirst property in degradation (that is, hard solutions do not support downgrading soft solutions), it is recommended that you pass this parameter to save the operation of probing the actual encoding format.
3836
3853
  */
3837
3854
  enum Codec {
3838
3855
  /** {zh}
@@ -4172,7 +4189,14 @@ declare namespace error {
4172
4189
  /** {en}
4173
4190
  * @brief Error.
4174
4191
  */
4175
- Error = "Error"
4192
+ Error = "Error",
4193
+ /** {zh}
4194
+ * @brief 提示。
4195
+ */
4196
+ /** {en}
4197
+ * @brief Warn.
4198
+ */
4199
+ Warn = "Warn"
4176
4200
  }
4177
4201
  enum ErrorCode {
4178
4202
  /** {zh}
@@ -8,6 +8,7 @@ const error = window["VePlayer"].error;
8
8
  const { VeError } = error;
9
9
  var LiveErrorCode = /* @__PURE__ */ ((LiveErrorCode2) => {
10
10
  LiveErrorCode2[LiveErrorCode2["INVALID_PARAMETER"] = 210] = "INVALID_PARAMETER";
11
+ LiveErrorCode2[LiveErrorCode2["EMPTY_RTM_FALLBACK_PARAMETER"] = 211] = "EMPTY_RTM_FALLBACK_PARAMETER";
11
12
  LiveErrorCode2[LiveErrorCode2["INVALID_LOGGER"] = 220] = "INVALID_LOGGER";
12
13
  return LiveErrorCode2;
13
14
  })(LiveErrorCode || {});
@@ -25,12 +26,19 @@ const ERRORS = {
25
26
  messageTextKey: "INVALID_PARAMETER",
26
27
  level: error.Level.Fatal
27
28
  },
29
+ [
30
+ 211
31
+ /* EMPTY_RTM_FALLBACK_PARAMETER */
32
+ ]: {
33
+ messageTextKey: "EMPTY_RTM_FALLBACK_PARAMETER",
34
+ level: error.Level.Warn
35
+ },
28
36
  [
29
37
  220
30
38
  /* INVALID_LOGGER */
31
39
  ]: {
32
40
  messageTextKey: "INVALID_LOGGER",
33
- level: error.Level.Error
41
+ level: error.Level.Warn
34
42
  }
35
43
  };
36
44
  function create(errorCode, i18n) {
@@ -54,38 +62,63 @@ async function isRTMSupportCodec(codec = RTMCodec.H264) {
54
62
  return RtmPlugin.isSupportedH264();
55
63
  return false;
56
64
  }
65
+ const getUrlObject = (url) => {
66
+ if (!url) {
67
+ return;
68
+ }
69
+ const withoutProtocol = url.startsWith("//");
70
+ if (withoutProtocol) {
71
+ url = location.protocol + url;
72
+ }
73
+ try {
74
+ return new URL(url);
75
+ } catch (error2) {
76
+ return;
77
+ }
78
+ };
57
79
  const strategy$2 = window["VePlayer"].strategy;
58
80
  const util$6 = window["VePlayer"].util;
59
81
  const DynamicModule$3 = window["VePlayer"].DynamicModule;
60
82
  const load$4 = window["VePlayer"].load;
61
83
  const Codec$3 = window["VePlayer"].Codec;
62
- const Sniffer$5 = window["VePlayer"].Sniffer;
84
+ const Sniffer$4 = window["VePlayer"].Sniffer;
63
85
  const rtmStrategy = {
64
86
  options: {},
65
87
  module: DynamicModule$3.PluginRtm
66
88
  };
67
89
  const generateFallbackUrl = (url) => {
68
- if (Sniffer$5.device === "pc") {
90
+ if (Sniffer$4.device === "pc") {
69
91
  return url.replace(".sdp", ".flv");
70
92
  } else {
71
93
  return url.replace(".sdp", ".m3u8");
72
94
  }
73
95
  };
74
- const getRtmStrategy = async (options, player) => {
75
- var _a;
96
+ const getRtmStrategy = async (options, player, i18n) => {
97
+ var _a, _b;
76
98
  let backupStrategy;
77
- const { url } = options;
78
- const {
79
- fallbackUrl,
80
- enableFallback = true,
81
- enableRTMAutoTranscode,
82
- ...ret
83
- } = options.rtm || {};
84
- const actualFallbackUrl = !enableFallback ? "" : !fallbackUrl && url ? generateFallbackUrl(url) : fallbackUrl;
99
+ let actualFallbackUrl = "";
100
+ const { url, playlist } = options;
101
+ const { fallbackUrl, enableRTMAutoTranscode, ...ret } = options.rtm || {};
102
+ let { enableFallback = true } = options.rtm || {};
103
+ if (playlist == null ? void 0 : playlist.length) {
104
+ enableFallback = false;
105
+ }
106
+ const isRTMAutoTranscode = enableRTMAutoTranscode || ((_a = getUrlObject(url)) == null ? void 0 : _a.searchParams.get("enableRTMAutoTranscode")) === "true";
107
+ if (enableFallback) {
108
+ if (fallbackUrl) {
109
+ actualFallbackUrl = fallbackUrl;
110
+ } else if (isRTMAutoTranscode && url) {
111
+ actualFallbackUrl = generateFallbackUrl(url);
112
+ } else {
113
+ console.warn(
114
+ create(ErrorCode.EMPTY_RTM_FALLBACK_PARAMETER, i18n).message
115
+ );
116
+ }
117
+ }
85
118
  const backupType = actualFallbackUrl && util$6.getStreamType(actualFallbackUrl);
86
119
  if (backupType === "flv" && util$6.isMseSupported(Codec$3.H264)) {
87
120
  backupStrategy = strategy$2.createFlvMseStrategy(options);
88
- } else if (backupType === "hls" && (Sniffer$5.device !== "mobile" || ((_a = options == null ? void 0 : options.hls) == null ? void 0 : _a.enableMSE)) && util$6.isMseSupported(Codec$3.H264)) {
121
+ } else if (backupType === "hls" && (Sniffer$4.device !== "mobile" || ((_b = options == null ? void 0 : options.hls) == null ? void 0 : _b.enableMSE)) && util$6.isMseSupported(Codec$3.H264)) {
89
122
  backupStrategy = strategy$2.createHlsMseStrategy(options);
90
123
  }
91
124
  const [rtmCdn, backupCdn] = await Promise.all([
@@ -100,33 +133,35 @@ const getRtmStrategy = async (options, player) => {
100
133
  }
101
134
  }).catch(() => void 0)
102
135
  ]);
103
- const [RTMSupported, RTMSupportCodec] = await Promise.all([
104
- isRTMSupported(),
105
- isRTMSupportCodec()
106
- ]);
107
- if (!RTMSupported || !RTMSupportCodec) {
108
- if (player) {
109
- player.emit("degrade", {
110
- url: actualFallbackUrl,
111
- originRtmUrl: url,
112
- code: "NOT_SUPPORT",
113
- message: "not support rtm or h264",
114
- isRTMSupported: RTMSupported,
115
- isRTMSupportCodec: RTMSupportCodec
116
- });
136
+ if (actualFallbackUrl) {
137
+ const [RTMSupported, RTMSupportCodec] = await Promise.all([
138
+ isRTMSupported(),
139
+ isRTMSupportCodec()
140
+ ]);
141
+ if (!RTMSupported || !RTMSupportCodec) {
142
+ if (player) {
143
+ player.emit("degrade", {
144
+ url: actualFallbackUrl,
145
+ originRtmUrl: url,
146
+ code: "NOT_SUPPORT",
147
+ message: "not support rtm or h264",
148
+ isRTMSupported: RTMSupported,
149
+ isRTMSupportCodec: RTMSupportCodec
150
+ });
151
+ }
152
+ return {
153
+ options: {
154
+ ...(backupStrategy == null ? void 0 : backupStrategy.options) || {},
155
+ url: actualFallbackUrl,
156
+ _RTMdegrade: {
157
+ _originRtmUrl: url,
158
+ _isRTMSupported: RTMSupported,
159
+ _isRTMSupportCodec: RTMSupportCodec
160
+ }
161
+ },
162
+ plugins: backupCdn ? [backupCdn] : []
163
+ };
117
164
  }
118
- return {
119
- options: {
120
- ...(backupStrategy == null ? void 0 : backupStrategy.options) || {},
121
- url: actualFallbackUrl,
122
- _RTMdegrade: {
123
- _originRtmUrl: url,
124
- _isRTMSupported: RTMSupported,
125
- _isRTMSupportCodec: RTMSupportCodec
126
- }
127
- },
128
- plugins: backupCdn ? [backupCdn] : []
129
- };
130
165
  }
131
166
  return {
132
167
  options: {
@@ -143,13 +178,13 @@ const getRtmStrategy = async (options, player) => {
143
178
  plugins: rtmCdn ? [rtmCdn] : []
144
179
  };
145
180
  };
146
- const Sniffer$4 = window["VePlayer"].Sniffer;
181
+ const Sniffer$3 = window["VePlayer"].Sniffer;
147
182
  var DrmType = /* @__PURE__ */ ((DrmType2) => {
148
183
  DrmType2["Fairplay"] = "fairplay";
149
184
  return DrmType2;
150
185
  })(DrmType || {});
151
186
  function getDrmType(drm) {
152
- if ((drm == null ? void 0 : drm.fairplay) && (Sniffer$4.browser === "safari" || Sniffer$4.os.isIos)) {
187
+ if ((drm == null ? void 0 : drm.fairplay) && (Sniffer$3.browser === "safari" || Sniffer$3.os.isIos)) {
153
188
  return "fairplay";
154
189
  }
155
190
  return;
@@ -167,12 +202,12 @@ function isMseSupportedWithDrm({
167
202
  }
168
203
  return true;
169
204
  }
170
- const Sniffer$3 = window["VePlayer"].Sniffer;
205
+ const Sniffer$2 = window["VePlayer"].Sniffer;
171
206
  const Codec$2 = window["VePlayer"].Codec;
172
207
  const util$5 = window["VePlayer"].util;
173
208
  const { isMMSSupported: isMMSSupported$1, isMseSupported: isMseSupported$1 } = util$5;
174
209
  function enableMMS() {
175
- return Sniffer$3.os.isIos;
210
+ return Sniffer$2.os.isIos;
176
211
  }
177
212
  function isFLVSupported(codec = Codec$2.H264) {
178
213
  const isMediaSourceSupported = enableMMS() ? isMMSSupported$1 : isMseSupported$1;
@@ -180,7 +215,6 @@ function isFLVSupported(codec = Codec$2.H264) {
180
215
  }
181
216
  const strategy$1 = window["VePlayer"].strategy;
182
217
  const load$3 = window["VePlayer"].load;
183
- const Sniffer$2 = window["VePlayer"].Sniffer;
184
218
  const Codec$1 = window["VePlayer"].Codec;
185
219
  const util$4 = window["VePlayer"].util;
186
220
  const { appendSearchParams } = util$4;
@@ -188,7 +222,7 @@ const getFlvStrategy = async (options) => {
188
222
  var _a, _b, _c, _d, _e, _f;
189
223
  let mseStrategy;
190
224
  let softStrategy;
191
- const enableLowLatency = ((_a = options == null ? void 0 : options.flv) == null ? void 0 : _a.enableLowLatency) && Sniffer$2.device === "pc";
225
+ const enableLowLatency = (_a = options == null ? void 0 : options.flv) == null ? void 0 : _a.enableLowLatency;
192
226
  const enableFrameChasing = ((_c = (_b = options == null ? void 0 : options.flv) == null ? void 0 : _b.lowLatency) == null ? void 0 : _c.enableFrameChasing) ?? true;
193
227
  const abrPts = ((_e = (_d = options == null ? void 0 : options.flv) == null ? void 0 : _d.lowLatency) == null ? void 0 : _e.abrPts) ?? "-800";
194
228
  const codec = await strategy$1.getCodec(options);
@@ -226,13 +260,13 @@ const getFlvStrategy = async (options) => {
226
260
  };
227
261
  const util$3 = window["VePlayer"].util;
228
262
  const strategy = window["VePlayer"].strategy;
229
- const getTypeStrategy = async (options, player) => {
263
+ const getTypeStrategy = async (options, player, i18n) => {
230
264
  const type = options.url ? util$3.getStreamType(options.url) : "";
231
265
  if (!type || type === "unknown") {
232
266
  return { options: {}, plugins: [] };
233
267
  }
234
268
  if (type === "rtm") {
235
- return await getRtmStrategy(options, player);
269
+ return await getRtmStrategy(options, player, i18n);
236
270
  }
237
271
  if (type === "flv") {
238
272
  return await getFlvStrategy(options);
@@ -3058,7 +3092,7 @@ class Logger extends Plugin$2 {
3058
3092
  device_id: this._deviceId,
3059
3093
  error_report_stop: true,
3060
3094
  ext: {
3061
- veplayer_version: "2.3.0",
3095
+ veplayer_version: "2.3.1-rc.1",
3062
3096
  flv_version: "3.0.21-rc.5",
3063
3097
  hls_version: "3.0.21-rc.5",
3064
3098
  rts_version: "0.2.1-alpha.14"
@@ -3303,6 +3337,7 @@ const EN$1 = {
3303
3337
  ...BaseEN,
3304
3338
  INVALID_PARAMETER: "The imported parameter is empty, please pass in necessary parameters such as the stream address",
3305
3339
  INVALID_LOGGER: `Log options not configured correctly. Please refer to this document ${logDoc} to configure the logs.`,
3340
+ EMPTY_RTM_FALLBACK_PARAMETER: "Fallback URL for RTM is not configured. Please set enableFallback: false to disable fallback, or configure fallbackUrl for FLV and HLS formats based on the browser environment.",
3306
3341
  // info-panel
3307
3342
  FORMAT: "format",
3308
3343
  FPS: "fps",
@@ -3322,6 +3357,7 @@ const ZH_CN$1 = {
3322
3357
  ...BaseZH_CN,
3323
3358
  INVALID_PARAMETER: "入参为空,请传入流地址等必要参数",
3324
3359
  INVALID_LOGGER: `未正确配置质量日志参数, 请参考 ${logDoc} 配置`,
3360
+ EMPTY_RTM_FALLBACK_PARAMETER: "未配置 RTM 降级地址 fallbackUrl,请设置 enableFallback: false 取消降级或根据浏览器环境配置 FLV、HLS 格式降级地址",
3325
3361
  // info-panel
3326
3362
  FORMAT: "格式",
3327
3363
  FPS: "帧率",
@@ -3655,13 +3691,15 @@ async function createLivePlayer(options) {
3655
3691
  };
3656
3692
  },
3657
3693
  async preparePlugins(url) {
3694
+ var _a2;
3658
3695
  const [typeStrategy, drmStrategy, abrStrategy] = await Promise.all([
3659
3696
  getTypeStrategy(
3660
3697
  {
3661
3698
  ...finalOptions,
3662
3699
  url
3663
3700
  },
3664
- player
3701
+ player,
3702
+ i18n
3665
3703
  ),
3666
3704
  getDrmStrategy(
3667
3705
  {
@@ -3684,7 +3722,8 @@ async function createLivePlayer(options) {
3684
3722
  ...plugins ?? [],
3685
3723
  ...drmPlugins ?? [],
3686
3724
  ...abrPlugins ?? []
3687
- ]
3725
+ ],
3726
+ useSrc: !((_a2 = typeStrategy.plugins) == null ? void 0 : _a2.length)
3688
3727
  };
3689
3728
  }
3690
3729
  },