@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.
@@ -6502,6 +6502,7 @@ var index_min = "";
6502
6502
  var Level = /* @__PURE__ */ ((Level2) => {
6503
6503
  Level2["Fatal"] = "Fatal";
6504
6504
  Level2["Error"] = "Error";
6505
+ Level2["Warn"] = "Warn";
6505
6506
  return Level2;
6506
6507
  })(Level || {});
6507
6508
  var ErrorCode$1 = /* @__PURE__ */ ((ErrorCode2) => {
@@ -13868,7 +13869,7 @@ class VePlayerBase {
13868
13869
  * @brief Retrieve the player SDK version number.
13869
13870
  */
13870
13871
  get playerVersion() {
13871
- return "2.5.1";
13872
+ return "2.5.2-rc.0";
13872
13873
  }
13873
13874
  /** {zh}
13874
13875
  * @brief 获取当前播放视频的清晰度唯一标识(definition)。
@@ -14352,25 +14353,27 @@ class VePlayerBase {
14352
14353
  * @hidden
14353
14354
  */
14354
14355
  async prepare(url) {
14355
- var _a, _b;
14356
+ var _a, _b, _c, _d, _e, _f, _g;
14356
14357
  const result = await ((_a = this._preparePlugins) == null ? void 0 : _a.call(this, url));
14357
- const { removedPlugins, addedPlugins } = this._diffPlugins(
14358
- ((_b = this._previousPrepareResult) == null ? void 0 : _b.plugins) ?? [],
14359
- (result == null ? void 0 : result.plugins) ?? []
14360
- );
14361
- removedPlugins == null ? void 0 : removedPlugins.forEach((pluginName) => {
14362
- /* istanbul ignore next -- @preserve */
14363
- this._player.unRegisterPlugin(pluginName);
14364
- });
14358
+ const newUrl = ((_b = result == null ? void 0 : result.options) == null ? void 0 : _b.url) ?? url;
14359
+ const oldUrl = (_d = (_c = this._player) == null ? void 0 : _c.config) == null ? void 0 : _d.url;
14360
+ const isSameProtocol = oldUrl && getStreamType(newUrl) === getStreamType(oldUrl);
14361
+ if (!isSameProtocol) {
14362
+ (_f = (_e = this._previousPrepareResult) == null ? void 0 : _e.plugins) == null ? void 0 : _f.forEach((plugin) => {
14363
+ this._player.unRegisterPlugin(plugin.pluginName);
14364
+ });
14365
+ }
14365
14366
  this._previousPrepareResult = result;
14366
14367
  if (result == null ? void 0 : result.options) {
14367
14368
  this._player.setConfig(result.options);
14368
14369
  }
14369
14370
  return {
14370
- plugins: addedPlugins.map((plugin) => {
14371
+ plugins: isSameProtocol ? [] : (_g = result == null ? void 0 : result.plugins) == null ? void 0 : _g.map((plugin) => {
14371
14372
  return this._player.registerPlugin(plugin);
14372
14373
  }),
14373
- options: result == null ? void 0 : result.options
14374
+ options: result == null ? void 0 : result.options,
14375
+ isSameProtocol,
14376
+ useSrc: result == null ? void 0 : result.useSrc
14374
14377
  };
14375
14378
  }
14376
14379
  async _handleFallback(err) {
@@ -14413,81 +14416,105 @@ class VePlayerBase {
14413
14416
  async _switch(targetDefinition) {
14414
14417
  var _a, _b, _c, _d, _e, _f;
14415
14418
  const preDefinition = clonedeep(this._sourceManager.definition);
14416
- const { plugins: newPlugins, options } = await this.prepare(targetDefinition.url) || {};
14419
+ const isPaused = this._player.paused && !this._player.isError;
14420
+ const {
14421
+ plugins: newPlugins,
14422
+ options,
14423
+ isSameProtocol,
14424
+ useSrc
14425
+ } = await this.prepare(targetDefinition.url) || {};
14417
14426
  if (options == null ? void 0 : options.url) {
14418
14427
  targetDefinition.url = options == null ? void 0 : options.url;
14419
14428
  }
14420
14429
  this._sourceManager.switch(targetDefinition);
14421
14430
  (_b = (_a = this._player) == null ? void 0 : _a.plugins) == null ? void 0 : _b.sources.renderItemList();
14422
14431
  (_d = (_c = this._player) == null ? void 0 : _c.plugins) == null ? void 0 : _d.definition.renderItemList();
14423
- if (((_e = targetDefinition == null ? void 0 : targetDefinition.source) == null ? void 0 : _e.name) !== ((_f = preDefinition == null ? void 0 : preDefinition.source) == null ? void 0 : _f.name)) {
14424
- this.emit(Events$1.SOURCE_CHANGE);
14425
- }
14426
- if (newPlugins == null ? void 0 : newPlugins.length) {
14427
- this.emit(Events$1.DEFINITION_CHANGE);
14428
- await this._callBeforePlayerInitForUrl(newPlugins, targetDefinition.url);
14429
- this.emit(Events$1.AFTER_DEFINITION_CHANGE);
14432
+ const isSourceSwitching = ((_e = targetDefinition == null ? void 0 : targetDefinition.source) == null ? void 0 : _e.name) !== ((_f = preDefinition == null ? void 0 : preDefinition.source) == null ? void 0 : _f.name);
14433
+ this._player.config.url = targetDefinition.url;
14434
+ if (isSameProtocol) {
14435
+ if (isSourceSwitching) {
14436
+ this.emit(Events$1.SOURCE_CHANGE);
14437
+ this._player.switchURL(targetDefinition.url);
14438
+ } else {
14439
+ this._player.changeDefinition(targetDefinition, preDefinition);
14440
+ }
14430
14441
  } else {
14431
- this._player.changeDefinition(targetDefinition, preDefinition);
14442
+ this.emit(
14443
+ isSourceSwitching ? Events$1.SOURCE_CHANGE : Events$1.DEFINITION_CHANGE
14444
+ );
14445
+ await this._switchDifferentProtocolUrl(
14446
+ newPlugins,
14447
+ targetDefinition.url,
14448
+ isPaused,
14449
+ useSrc
14450
+ );
14451
+ !isSourceSwitching && this.emit(Events$1.AFTER_DEFINITION_CHANGE);
14432
14452
  }
14433
14453
  }
14454
+ async _switchDifferentProtocolUrl(plugins, url, isPaused, useSrc) {
14455
+ var _a, _b;
14456
+ if (useSrc && this._player.media) {
14457
+ if ((_a = this._player.config) == null ? void 0 : _a.preProcessUrl) {
14458
+ url = (_b = this._player.config) == null ? void 0 : _b.preProcessUrl(url).url;
14459
+ }
14460
+ this._player.media.src = url;
14461
+ }
14462
+ if (plugins == null ? void 0 : plugins.length) {
14463
+ await this._callBeforePlayerInitForUrl(plugins);
14464
+ }
14465
+ return new Promise((resolve) => {
14466
+ const curTime = this._player.currentTime;
14467
+ const _canplay = () => {
14468
+ console.log("canplay canplay");
14469
+ this._player.currentTime = curTime;
14470
+ if (isPaused) {
14471
+ this._player.once(CANPLAY, () => {
14472
+ this._player.pause();
14473
+ });
14474
+ }
14475
+ resolve();
14476
+ };
14477
+ if (sniffer$1.os.isAndroid) {
14478
+ this.once(TIME_UPDATE, () => {
14479
+ _canplay();
14480
+ });
14481
+ } else {
14482
+ this.once(CANPLAY, () => {
14483
+ _canplay();
14484
+ });
14485
+ }
14486
+ this._player.play();
14487
+ });
14488
+ }
14434
14489
  async _switchUrl(url, config) {
14435
- const { plugins: newPlugins, options } = await this.prepare(url) || {};
14490
+ const isPaused = this._player.paused && !this._player.isError;
14491
+ const {
14492
+ plugins: newPlugins,
14493
+ options,
14494
+ isSameProtocol,
14495
+ useSrc
14496
+ } = await this.prepare(url) || {};
14436
14497
  const newUrl = (options == null ? void 0 : options.url) ?? url;
14437
14498
  this._sourceManager.url = newUrl;
14438
- if (newPlugins == null ? void 0 : newPlugins.length) {
14439
- this._callBeforePlayerInitForUrl(newPlugins, newUrl);
14440
- } else {
14499
+ this._player.config.url = newUrl;
14500
+ if (isSameProtocol) {
14441
14501
  const res = this._player.switchURL(newUrl, {
14442
14502
  seamless: config == null ? void 0 : config.seamless
14443
14503
  });
14444
- const curTime = this._player.currentTime;
14445
14504
  if (res && res.then) {
14446
14505
  return res;
14447
- } else {
14448
- return new Promise((resolve) => {
14449
- const isPaused = this._player.paused && !this._player.isError;
14450
- const _canplay = () => {
14451
- this._player.currentTime = curTime;
14452
- if (isPaused) {
14453
- this._player.once(CANPLAY, () => {
14454
- this._player.pause();
14455
- });
14456
- }
14457
- resolve();
14458
- };
14459
- if (sniffer$1.os.isAndroid) {
14460
- this.once(TIME_UPDATE, () => {
14461
- _canplay();
14462
- });
14463
- } else {
14464
- this.once(CANPLAY, () => {
14465
- _canplay();
14466
- });
14467
- }
14468
- this._player.play();
14469
- });
14470
14506
  }
14507
+ } else {
14508
+ return this._switchDifferentProtocolUrl(
14509
+ newPlugins,
14510
+ newUrl,
14511
+ isPaused,
14512
+ useSrc
14513
+ );
14471
14514
  }
14472
14515
  }
14473
- // 获取需要卸载和需要注册的播放插件
14474
- _diffPlugins(previousPlugins, newPlugins) {
14475
- const previousPluginNames = previousPlugins.map((item) => item.pluginName);
14476
- const newPluginNames = newPlugins.map((item) => item.pluginName);
14477
- const removedPlugins = previousPluginNames.filter(
14478
- (name) => !newPluginNames.includes(name)
14479
- );
14480
- const addedPlugins = newPlugins.filter(
14481
- (name) => !previousPluginNames.includes(name.pluginName)
14482
- );
14483
- return {
14484
- removedPlugins,
14485
- addedPlugins
14486
- };
14487
- }
14488
- _callBeforePlayerInitForUrl(newPlugins, url) {
14516
+ _callBeforePlayerInitForUrl(newPlugins) {
14489
14517
  return new Promise((resolve) => {
14490
- this._player.config.url = url;
14491
14518
  newPlugins == null ? void 0 : newPlugins.forEach((plugin) => {
14492
14519
  plugin.beforePlayerInit();
14493
14520
  });
@@ -19146,6 +19173,7 @@ function combineOptions(strategyList) {
19146
19173
  const { VeError: VeError2 } = error$1;
19147
19174
  var LiveErrorCode = /* @__PURE__ */ ((LiveErrorCode2) => {
19148
19175
  LiveErrorCode2[LiveErrorCode2["INVALID_PARAMETER"] = 210] = "INVALID_PARAMETER";
19176
+ LiveErrorCode2[LiveErrorCode2["EMPTY_RTM_FALLBACK_PARAMETER"] = 211] = "EMPTY_RTM_FALLBACK_PARAMETER";
19149
19177
  LiveErrorCode2[LiveErrorCode2["INVALID_LOGGER"] = 220] = "INVALID_LOGGER";
19150
19178
  return LiveErrorCode2;
19151
19179
  })(LiveErrorCode || {});
@@ -19162,12 +19190,19 @@ const ERRORS = {
19162
19190
  messageTextKey: "INVALID_PARAMETER",
19163
19191
  level: Level.Fatal
19164
19192
  },
19193
+ [
19194
+ 211
19195
+ /* EMPTY_RTM_FALLBACK_PARAMETER */
19196
+ ]: {
19197
+ messageTextKey: "EMPTY_RTM_FALLBACK_PARAMETER",
19198
+ level: Level.Warn
19199
+ },
19165
19200
  [
19166
19201
  220
19167
19202
  /* INVALID_LOGGER */
19168
19203
  ]: {
19169
19204
  messageTextKey: "INVALID_LOGGER",
19170
- level: Level.Error
19205
+ level: Level.Warn
19171
19206
  }
19172
19207
  };
19173
19208
  function create(errorCode, i18n) {
@@ -19200,21 +19235,32 @@ const generateFallbackUrl = (url) => {
19200
19235
  return url.replace(".sdp", ".m3u8");
19201
19236
  }
19202
19237
  };
19203
- const getRtmStrategy = async (options, player) => {
19204
- var _a;
19238
+ const getRtmStrategy = async (options, player, i18n) => {
19239
+ var _a, _b;
19205
19240
  let backupStrategy;
19206
- const { url } = options;
19207
- const {
19208
- fallbackUrl,
19209
- enableFallback = true,
19210
- enableRTMAutoTranscode,
19211
- ...ret
19212
- } = options.rtm || {};
19213
- const actualFallbackUrl = !enableFallback ? "" : !fallbackUrl && url ? generateFallbackUrl(url) : fallbackUrl;
19241
+ let actualFallbackUrl = "";
19242
+ const { url, playlist } = options;
19243
+ const { fallbackUrl, enableRTMAutoTranscode, ...ret } = options.rtm || {};
19244
+ let { enableFallback = true } = options.rtm || {};
19245
+ if (playlist == null ? void 0 : playlist.length) {
19246
+ enableFallback = false;
19247
+ }
19248
+ const isRTMAutoTranscode = enableRTMAutoTranscode || ((_a = getUrlObject(url)) == null ? void 0 : _a.searchParams.get("enableRTMAutoTranscode")) === "true";
19249
+ if (enableFallback) {
19250
+ if (fallbackUrl) {
19251
+ actualFallbackUrl = fallbackUrl;
19252
+ } else if (isRTMAutoTranscode && url) {
19253
+ actualFallbackUrl = generateFallbackUrl(url);
19254
+ } else {
19255
+ console.warn(
19256
+ create(ErrorCode.EMPTY_RTM_FALLBACK_PARAMETER, i18n).message
19257
+ );
19258
+ }
19259
+ }
19214
19260
  const backupType = actualFallbackUrl && util.getStreamType(actualFallbackUrl);
19215
19261
  if (backupType === "flv" && util.isMseSupported(Codec.H264)) {
19216
19262
  backupStrategy = createFlvMseStrategy(options);
19217
- } else if (backupType === "hls" && (sniffer$1.device !== "mobile" || ((_a = options == null ? void 0 : options.hls) == null ? void 0 : _a.enableMSE)) && util.isMseSupported(Codec.H264)) {
19263
+ } else if (backupType === "hls" && (sniffer$1.device !== "mobile" || ((_b = options == null ? void 0 : options.hls) == null ? void 0 : _b.enableMSE)) && util.isMseSupported(Codec.H264)) {
19218
19264
  backupStrategy = createHlsMseStrategy(options);
19219
19265
  }
19220
19266
  const [rtmCdn, backupCdn] = await Promise.all([
@@ -19229,33 +19275,35 @@ const getRtmStrategy = async (options, player) => {
19229
19275
  }
19230
19276
  }).catch(() => void 0)
19231
19277
  ]);
19232
- const [RTMSupported, RTMSupportCodec] = await Promise.all([
19233
- isRTMSupported(),
19234
- isRTMSupportCodec()
19235
- ]);
19236
- if (!RTMSupported || !RTMSupportCodec) {
19237
- if (player) {
19238
- player.emit("degrade", {
19239
- url: actualFallbackUrl,
19240
- originRtmUrl: url,
19241
- code: "NOT_SUPPORT",
19242
- message: "not support rtm or h264",
19243
- isRTMSupported: RTMSupported,
19244
- isRTMSupportCodec: RTMSupportCodec
19245
- });
19278
+ if (actualFallbackUrl) {
19279
+ const [RTMSupported, RTMSupportCodec] = await Promise.all([
19280
+ isRTMSupported(),
19281
+ isRTMSupportCodec()
19282
+ ]);
19283
+ if (!RTMSupported || !RTMSupportCodec) {
19284
+ if (player) {
19285
+ player.emit("degrade", {
19286
+ url: actualFallbackUrl,
19287
+ originRtmUrl: url,
19288
+ code: "NOT_SUPPORT",
19289
+ message: "not support rtm or h264",
19290
+ isRTMSupported: RTMSupported,
19291
+ isRTMSupportCodec: RTMSupportCodec
19292
+ });
19293
+ }
19294
+ return {
19295
+ options: {
19296
+ ...(backupStrategy == null ? void 0 : backupStrategy.options) || {},
19297
+ url: actualFallbackUrl,
19298
+ _RTMdegrade: {
19299
+ _originRtmUrl: url,
19300
+ _isRTMSupported: RTMSupported,
19301
+ _isRTMSupportCodec: RTMSupportCodec
19302
+ }
19303
+ },
19304
+ plugins: backupCdn ? [backupCdn] : []
19305
+ };
19246
19306
  }
19247
- return {
19248
- options: {
19249
- ...(backupStrategy == null ? void 0 : backupStrategy.options) || {},
19250
- url: actualFallbackUrl,
19251
- _RTMdegrade: {
19252
- _originRtmUrl: url,
19253
- _isRTMSupported: RTMSupported,
19254
- _isRTMSupportCodec: RTMSupportCodec
19255
- }
19256
- },
19257
- plugins: backupCdn ? [backupCdn] : []
19258
- };
19259
19307
  }
19260
19308
  return {
19261
19309
  options: {
@@ -19308,7 +19356,7 @@ const getFlvStrategy = async (options) => {
19308
19356
  var _a, _b, _c, _d, _e, _f;
19309
19357
  let mseStrategy;
19310
19358
  let softStrategy;
19311
- const enableLowLatency = ((_a = options == null ? void 0 : options.flv) == null ? void 0 : _a.enableLowLatency) && sniffer$1.device === "pc";
19359
+ const enableLowLatency = (_a = options == null ? void 0 : options.flv) == null ? void 0 : _a.enableLowLatency;
19312
19360
  const enableFrameChasing = ((_c = (_b = options == null ? void 0 : options.flv) == null ? void 0 : _b.lowLatency) == null ? void 0 : _c.enableFrameChasing) ?? true;
19313
19361
  const abrPts = ((_e = (_d = options == null ? void 0 : options.flv) == null ? void 0 : _d.lowLatency) == null ? void 0 : _e.abrPts) ?? "-800";
19314
19362
  const codec = await getCodec(options);
@@ -19344,13 +19392,13 @@ const getFlvStrategy = async (options) => {
19344
19392
  plugins
19345
19393
  };
19346
19394
  };
19347
- const getTypeStrategy = async (options, player) => {
19395
+ const getTypeStrategy = async (options, player, i18n) => {
19348
19396
  const type = options.url ? util.getStreamType(options.url) : "";
19349
19397
  if (!type || type === "unknown") {
19350
19398
  return { options: {}, plugins: [] };
19351
19399
  }
19352
19400
  if (type === "rtm") {
19353
- return await getRtmStrategy(options, player);
19401
+ return await getRtmStrategy(options, player, i18n);
19354
19402
  }
19355
19403
  if (type === "flv") {
19356
19404
  return await getFlvStrategy(options);
@@ -22166,7 +22214,7 @@ class Logger extends Plugin {
22166
22214
  device_id: this._deviceId,
22167
22215
  error_report_stop: true,
22168
22216
  ext: {
22169
- veplayer_version: "2.5.1",
22217
+ veplayer_version: "2.5.2-rc.0",
22170
22218
  flv_version: "3.0.21-rc.5",
22171
22219
  hls_version: "3.0.21-rc.5",
22172
22220
  rts_version: "0.2.1-alpha.14"
@@ -22407,6 +22455,7 @@ const EN = {
22407
22455
  ...EN$1,
22408
22456
  INVALID_PARAMETER: "The imported parameter is empty, please pass in necessary parameters such as the stream address",
22409
22457
  INVALID_LOGGER: `Log options not configured correctly. Please refer to this document ${logDoc} to configure the logs.`,
22458
+ 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.",
22410
22459
  // info-panel
22411
22460
  FORMAT: "format",
22412
22461
  FPS: "fps",
@@ -22425,6 +22474,7 @@ const ZH_CN = {
22425
22474
  ...ZH_CN$1,
22426
22475
  INVALID_PARAMETER: "入参为空,请传入流地址等必要参数",
22427
22476
  INVALID_LOGGER: `未正确配置质量日志参数, 请参考 ${logDoc} 配置`,
22477
+ EMPTY_RTM_FALLBACK_PARAMETER: "未配置 RTM 降级地址 fallbackUrl,请设置 enableFallback: false 取消降级或根据浏览器环境配置 FLV、HLS 格式降级地址",
22428
22478
  // info-panel
22429
22479
  FORMAT: "格式",
22430
22480
  FPS: "帧率",
@@ -22723,13 +22773,15 @@ async function createLivePlayer(options) {
22723
22773
  };
22724
22774
  },
22725
22775
  async preparePlugins(url) {
22776
+ var _a2;
22726
22777
  const [typeStrategy, drmStrategy, abrStrategy] = await Promise.all([
22727
22778
  getTypeStrategy(
22728
22779
  {
22729
22780
  ...finalOptions,
22730
22781
  url
22731
22782
  },
22732
- player
22783
+ player,
22784
+ i18n
22733
22785
  ),
22734
22786
  getDrmStrategy(
22735
22787
  {
@@ -22752,7 +22804,8 @@ async function createLivePlayer(options) {
22752
22804
  ...plugins ?? [],
22753
22805
  ...drmPlugins ?? [],
22754
22806
  ...abrPlugins ?? []
22755
- ]
22807
+ ],
22808
+ useSrc: !((_a2 = typeStrategy.plugins) == null ? void 0 : _a2.length)
22756
22809
  };
22757
22810
  }
22758
22811
  },