@volcengine/veplayer 2.5.1-rc.2 → 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.
@@ -6506,6 +6506,7 @@ var __publicField = (obj, key, value) => {
6506
6506
  var Level = /* @__PURE__ */ ((Level2) => {
6507
6507
  Level2["Fatal"] = "Fatal";
6508
6508
  Level2["Error"] = "Error";
6509
+ Level2["Warn"] = "Warn";
6509
6510
  return Level2;
6510
6511
  })(Level || {});
6511
6512
  var ErrorCode$1 = /* @__PURE__ */ ((ErrorCode2) => {
@@ -13872,7 +13873,7 @@ var __publicField = (obj, key, value) => {
13872
13873
  * @brief Retrieve the player SDK version number.
13873
13874
  */
13874
13875
  get playerVersion() {
13875
- return "2.5.1-rc.2";
13876
+ return "2.5.2-rc.0";
13876
13877
  }
13877
13878
  /** {zh}
13878
13879
  * @brief 获取当前播放视频的清晰度唯一标识(definition)。
@@ -14356,25 +14357,27 @@ var __publicField = (obj, key, value) => {
14356
14357
  * @hidden
14357
14358
  */
14358
14359
  async prepare(url) {
14359
- var _a, _b;
14360
+ var _a, _b, _c, _d, _e, _f, _g;
14360
14361
  const result = await ((_a = this._preparePlugins) == null ? void 0 : _a.call(this, url));
14361
- const { removedPlugins, addedPlugins } = this._diffPlugins(
14362
- ((_b = this._previousPrepareResult) == null ? void 0 : _b.plugins) ?? [],
14363
- (result == null ? void 0 : result.plugins) ?? []
14364
- );
14365
- removedPlugins == null ? void 0 : removedPlugins.forEach((pluginName) => {
14366
- /* istanbul ignore next -- @preserve */
14367
- this._player.unRegisterPlugin(pluginName);
14368
- });
14362
+ const newUrl = ((_b = result == null ? void 0 : result.options) == null ? void 0 : _b.url) ?? url;
14363
+ const oldUrl = (_d = (_c = this._player) == null ? void 0 : _c.config) == null ? void 0 : _d.url;
14364
+ const isSameProtocol = oldUrl && getStreamType(newUrl) === getStreamType(oldUrl);
14365
+ if (!isSameProtocol) {
14366
+ (_f = (_e = this._previousPrepareResult) == null ? void 0 : _e.plugins) == null ? void 0 : _f.forEach((plugin) => {
14367
+ this._player.unRegisterPlugin(plugin.pluginName);
14368
+ });
14369
+ }
14369
14370
  this._previousPrepareResult = result;
14370
14371
  if (result == null ? void 0 : result.options) {
14371
14372
  this._player.setConfig(result.options);
14372
14373
  }
14373
14374
  return {
14374
- plugins: addedPlugins.map((plugin) => {
14375
+ plugins: isSameProtocol ? [] : (_g = result == null ? void 0 : result.plugins) == null ? void 0 : _g.map((plugin) => {
14375
14376
  return this._player.registerPlugin(plugin);
14376
14377
  }),
14377
- options: result == null ? void 0 : result.options
14378
+ options: result == null ? void 0 : result.options,
14379
+ isSameProtocol,
14380
+ useSrc: result == null ? void 0 : result.useSrc
14378
14381
  };
14379
14382
  }
14380
14383
  async _handleFallback(err) {
@@ -14417,81 +14420,105 @@ var __publicField = (obj, key, value) => {
14417
14420
  async _switch(targetDefinition) {
14418
14421
  var _a, _b, _c, _d, _e, _f;
14419
14422
  const preDefinition = clonedeep(this._sourceManager.definition);
14420
- const { plugins: newPlugins, options } = await this.prepare(targetDefinition.url) || {};
14423
+ const isPaused = this._player.paused && !this._player.isError;
14424
+ const {
14425
+ plugins: newPlugins,
14426
+ options,
14427
+ isSameProtocol,
14428
+ useSrc
14429
+ } = await this.prepare(targetDefinition.url) || {};
14421
14430
  if (options == null ? void 0 : options.url) {
14422
14431
  targetDefinition.url = options == null ? void 0 : options.url;
14423
14432
  }
14424
14433
  this._sourceManager.switch(targetDefinition);
14425
14434
  (_b = (_a = this._player) == null ? void 0 : _a.plugins) == null ? void 0 : _b.sources.renderItemList();
14426
14435
  (_d = (_c = this._player) == null ? void 0 : _c.plugins) == null ? void 0 : _d.definition.renderItemList();
14427
- 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)) {
14428
- this.emit(Events$1.SOURCE_CHANGE);
14429
- }
14430
- if (newPlugins == null ? void 0 : newPlugins.length) {
14431
- this.emit(Events$1.DEFINITION_CHANGE);
14432
- await this._callBeforePlayerInitForUrl(newPlugins, targetDefinition.url);
14433
- this.emit(Events$1.AFTER_DEFINITION_CHANGE);
14436
+ 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);
14437
+ this._player.config.url = targetDefinition.url;
14438
+ if (isSameProtocol) {
14439
+ if (isSourceSwitching) {
14440
+ this.emit(Events$1.SOURCE_CHANGE);
14441
+ this._player.switchURL(targetDefinition.url);
14442
+ } else {
14443
+ this._player.changeDefinition(targetDefinition, preDefinition);
14444
+ }
14434
14445
  } else {
14435
- this._player.changeDefinition(targetDefinition, preDefinition);
14446
+ this.emit(
14447
+ isSourceSwitching ? Events$1.SOURCE_CHANGE : Events$1.DEFINITION_CHANGE
14448
+ );
14449
+ await this._switchDifferentProtocolUrl(
14450
+ newPlugins,
14451
+ targetDefinition.url,
14452
+ isPaused,
14453
+ useSrc
14454
+ );
14455
+ !isSourceSwitching && this.emit(Events$1.AFTER_DEFINITION_CHANGE);
14436
14456
  }
14437
14457
  }
14458
+ async _switchDifferentProtocolUrl(plugins, url, isPaused, useSrc) {
14459
+ var _a, _b;
14460
+ if (useSrc && this._player.media) {
14461
+ if ((_a = this._player.config) == null ? void 0 : _a.preProcessUrl) {
14462
+ url = (_b = this._player.config) == null ? void 0 : _b.preProcessUrl(url).url;
14463
+ }
14464
+ this._player.media.src = url;
14465
+ }
14466
+ if (plugins == null ? void 0 : plugins.length) {
14467
+ await this._callBeforePlayerInitForUrl(plugins);
14468
+ }
14469
+ return new Promise((resolve) => {
14470
+ const curTime = this._player.currentTime;
14471
+ const _canplay = () => {
14472
+ console.log("canplay canplay");
14473
+ this._player.currentTime = curTime;
14474
+ if (isPaused) {
14475
+ this._player.once(CANPLAY, () => {
14476
+ this._player.pause();
14477
+ });
14478
+ }
14479
+ resolve();
14480
+ };
14481
+ if (sniffer$1.os.isAndroid) {
14482
+ this.once(TIME_UPDATE, () => {
14483
+ _canplay();
14484
+ });
14485
+ } else {
14486
+ this.once(CANPLAY, () => {
14487
+ _canplay();
14488
+ });
14489
+ }
14490
+ this._player.play();
14491
+ });
14492
+ }
14438
14493
  async _switchUrl(url, config) {
14439
- const { plugins: newPlugins, options } = await this.prepare(url) || {};
14494
+ const isPaused = this._player.paused && !this._player.isError;
14495
+ const {
14496
+ plugins: newPlugins,
14497
+ options,
14498
+ isSameProtocol,
14499
+ useSrc
14500
+ } = await this.prepare(url) || {};
14440
14501
  const newUrl = (options == null ? void 0 : options.url) ?? url;
14441
14502
  this._sourceManager.url = newUrl;
14442
- if (newPlugins == null ? void 0 : newPlugins.length) {
14443
- this._callBeforePlayerInitForUrl(newPlugins, newUrl);
14444
- } else {
14503
+ this._player.config.url = newUrl;
14504
+ if (isSameProtocol) {
14445
14505
  const res = this._player.switchURL(newUrl, {
14446
14506
  seamless: config == null ? void 0 : config.seamless
14447
14507
  });
14448
- const curTime = this._player.currentTime;
14449
14508
  if (res && res.then) {
14450
14509
  return res;
14451
- } else {
14452
- return new Promise((resolve) => {
14453
- const isPaused = this._player.paused && !this._player.isError;
14454
- const _canplay = () => {
14455
- this._player.currentTime = curTime;
14456
- if (isPaused) {
14457
- this._player.once(CANPLAY, () => {
14458
- this._player.pause();
14459
- });
14460
- }
14461
- resolve();
14462
- };
14463
- if (sniffer$1.os.isAndroid) {
14464
- this.once(TIME_UPDATE, () => {
14465
- _canplay();
14466
- });
14467
- } else {
14468
- this.once(CANPLAY, () => {
14469
- _canplay();
14470
- });
14471
- }
14472
- this._player.play();
14473
- });
14474
14510
  }
14511
+ } else {
14512
+ return this._switchDifferentProtocolUrl(
14513
+ newPlugins,
14514
+ newUrl,
14515
+ isPaused,
14516
+ useSrc
14517
+ );
14475
14518
  }
14476
14519
  }
14477
- // 获取需要卸载和需要注册的播放插件
14478
- _diffPlugins(previousPlugins, newPlugins) {
14479
- const previousPluginNames = previousPlugins.map((item) => item.pluginName);
14480
- const newPluginNames = newPlugins.map((item) => item.pluginName);
14481
- const removedPlugins = previousPluginNames.filter(
14482
- (name) => !newPluginNames.includes(name)
14483
- );
14484
- const addedPlugins = newPlugins.filter(
14485
- (name) => !previousPluginNames.includes(name.pluginName)
14486
- );
14487
- return {
14488
- removedPlugins,
14489
- addedPlugins
14490
- };
14491
- }
14492
- _callBeforePlayerInitForUrl(newPlugins, url) {
14520
+ _callBeforePlayerInitForUrl(newPlugins) {
14493
14521
  return new Promise((resolve) => {
14494
- this._player.config.url = url;
14495
14522
  newPlugins == null ? void 0 : newPlugins.forEach((plugin) => {
14496
14523
  plugin.beforePlayerInit();
14497
14524
  });
@@ -19150,6 +19177,7 @@ var __publicField = (obj, key, value) => {
19150
19177
  const { VeError } = error$1;
19151
19178
  var LiveErrorCode = /* @__PURE__ */ ((LiveErrorCode2) => {
19152
19179
  LiveErrorCode2[LiveErrorCode2["INVALID_PARAMETER"] = 210] = "INVALID_PARAMETER";
19180
+ LiveErrorCode2[LiveErrorCode2["EMPTY_RTM_FALLBACK_PARAMETER"] = 211] = "EMPTY_RTM_FALLBACK_PARAMETER";
19153
19181
  LiveErrorCode2[LiveErrorCode2["INVALID_LOGGER"] = 220] = "INVALID_LOGGER";
19154
19182
  return LiveErrorCode2;
19155
19183
  })(LiveErrorCode || {});
@@ -19166,12 +19194,19 @@ var __publicField = (obj, key, value) => {
19166
19194
  messageTextKey: "INVALID_PARAMETER",
19167
19195
  level: Level.Fatal
19168
19196
  },
19197
+ [
19198
+ 211
19199
+ /* EMPTY_RTM_FALLBACK_PARAMETER */
19200
+ ]: {
19201
+ messageTextKey: "EMPTY_RTM_FALLBACK_PARAMETER",
19202
+ level: Level.Warn
19203
+ },
19169
19204
  [
19170
19205
  220
19171
19206
  /* INVALID_LOGGER */
19172
19207
  ]: {
19173
19208
  messageTextKey: "INVALID_LOGGER",
19174
- level: Level.Error
19209
+ level: Level.Warn
19175
19210
  }
19176
19211
  };
19177
19212
  function create(errorCode, i18n) {
@@ -19204,21 +19239,32 @@ var __publicField = (obj, key, value) => {
19204
19239
  return url.replace(".sdp", ".m3u8");
19205
19240
  }
19206
19241
  };
19207
- const getRtmStrategy = async (options, player) => {
19208
- var _a;
19242
+ const getRtmStrategy = async (options, player, i18n) => {
19243
+ var _a, _b;
19209
19244
  let backupStrategy;
19210
- const { url } = options;
19211
- const {
19212
- fallbackUrl,
19213
- enableFallback = true,
19214
- enableRTMAutoTranscode,
19215
- ...ret
19216
- } = options.rtm || {};
19217
- const actualFallbackUrl = !enableFallback ? "" : !fallbackUrl && url ? generateFallbackUrl(url) : fallbackUrl;
19245
+ let actualFallbackUrl = "";
19246
+ const { url, playlist } = options;
19247
+ const { fallbackUrl, enableRTMAutoTranscode, ...ret } = options.rtm || {};
19248
+ let { enableFallback = true } = options.rtm || {};
19249
+ if (playlist == null ? void 0 : playlist.length) {
19250
+ enableFallback = false;
19251
+ }
19252
+ const isRTMAutoTranscode = enableRTMAutoTranscode || ((_a = getUrlObject(url)) == null ? void 0 : _a.searchParams.get("enableRTMAutoTranscode")) === "true";
19253
+ if (enableFallback) {
19254
+ if (fallbackUrl) {
19255
+ actualFallbackUrl = fallbackUrl;
19256
+ } else if (isRTMAutoTranscode && url) {
19257
+ actualFallbackUrl = generateFallbackUrl(url);
19258
+ } else {
19259
+ console.warn(
19260
+ create(ErrorCode.EMPTY_RTM_FALLBACK_PARAMETER, i18n).message
19261
+ );
19262
+ }
19263
+ }
19218
19264
  const backupType = actualFallbackUrl && util.getStreamType(actualFallbackUrl);
19219
19265
  if (backupType === "flv" && util.isMseSupported(Codec.H264)) {
19220
19266
  backupStrategy = createFlvMseStrategy(options);
19221
- } else if (backupType === "hls" && (sniffer$1.device !== "mobile" || ((_a = options == null ? void 0 : options.hls) == null ? void 0 : _a.enableMSE)) && util.isMseSupported(Codec.H264)) {
19267
+ } else if (backupType === "hls" && (sniffer$1.device !== "mobile" || ((_b = options == null ? void 0 : options.hls) == null ? void 0 : _b.enableMSE)) && util.isMseSupported(Codec.H264)) {
19222
19268
  backupStrategy = createHlsMseStrategy(options);
19223
19269
  }
19224
19270
  const [rtmCdn, backupCdn] = await Promise.all([
@@ -19233,33 +19279,35 @@ var __publicField = (obj, key, value) => {
19233
19279
  }
19234
19280
  }).catch(() => void 0)
19235
19281
  ]);
19236
- const [RTMSupported, RTMSupportCodec] = await Promise.all([
19237
- isRTMSupported(),
19238
- isRTMSupportCodec()
19239
- ]);
19240
- if (!RTMSupported || !RTMSupportCodec) {
19241
- if (player) {
19242
- player.emit("degrade", {
19243
- url: actualFallbackUrl,
19244
- originRtmUrl: url,
19245
- code: "NOT_SUPPORT",
19246
- message: "not support rtm or h264",
19247
- isRTMSupported: RTMSupported,
19248
- isRTMSupportCodec: RTMSupportCodec
19249
- });
19282
+ if (actualFallbackUrl) {
19283
+ const [RTMSupported, RTMSupportCodec] = await Promise.all([
19284
+ isRTMSupported(),
19285
+ isRTMSupportCodec()
19286
+ ]);
19287
+ if (!RTMSupported || !RTMSupportCodec) {
19288
+ if (player) {
19289
+ player.emit("degrade", {
19290
+ url: actualFallbackUrl,
19291
+ originRtmUrl: url,
19292
+ code: "NOT_SUPPORT",
19293
+ message: "not support rtm or h264",
19294
+ isRTMSupported: RTMSupported,
19295
+ isRTMSupportCodec: RTMSupportCodec
19296
+ });
19297
+ }
19298
+ return {
19299
+ options: {
19300
+ ...(backupStrategy == null ? void 0 : backupStrategy.options) || {},
19301
+ url: actualFallbackUrl,
19302
+ _RTMdegrade: {
19303
+ _originRtmUrl: url,
19304
+ _isRTMSupported: RTMSupported,
19305
+ _isRTMSupportCodec: RTMSupportCodec
19306
+ }
19307
+ },
19308
+ plugins: backupCdn ? [backupCdn] : []
19309
+ };
19250
19310
  }
19251
- return {
19252
- options: {
19253
- ...(backupStrategy == null ? void 0 : backupStrategy.options) || {},
19254
- url: actualFallbackUrl,
19255
- _RTMdegrade: {
19256
- _originRtmUrl: url,
19257
- _isRTMSupported: RTMSupported,
19258
- _isRTMSupportCodec: RTMSupportCodec
19259
- }
19260
- },
19261
- plugins: backupCdn ? [backupCdn] : []
19262
- };
19263
19311
  }
19264
19312
  return {
19265
19313
  options: {
@@ -19312,7 +19360,7 @@ var __publicField = (obj, key, value) => {
19312
19360
  var _a, _b, _c, _d, _e, _f;
19313
19361
  let mseStrategy;
19314
19362
  let softStrategy;
19315
- const enableLowLatency = ((_a = options == null ? void 0 : options.flv) == null ? void 0 : _a.enableLowLatency) && sniffer$1.device === "pc";
19363
+ const enableLowLatency = (_a = options == null ? void 0 : options.flv) == null ? void 0 : _a.enableLowLatency;
19316
19364
  const enableFrameChasing = ((_c = (_b = options == null ? void 0 : options.flv) == null ? void 0 : _b.lowLatency) == null ? void 0 : _c.enableFrameChasing) ?? true;
19317
19365
  const abrPts = ((_e = (_d = options == null ? void 0 : options.flv) == null ? void 0 : _d.lowLatency) == null ? void 0 : _e.abrPts) ?? "-800";
19318
19366
  const codec = await getCodec(options);
@@ -19348,13 +19396,13 @@ var __publicField = (obj, key, value) => {
19348
19396
  plugins
19349
19397
  };
19350
19398
  };
19351
- const getTypeStrategy = async (options, player) => {
19399
+ const getTypeStrategy = async (options, player, i18n) => {
19352
19400
  const type = options.url ? util.getStreamType(options.url) : "";
19353
19401
  if (!type || type === "unknown") {
19354
19402
  return { options: {}, plugins: [] };
19355
19403
  }
19356
19404
  if (type === "rtm") {
19357
- return await getRtmStrategy(options, player);
19405
+ return await getRtmStrategy(options, player, i18n);
19358
19406
  }
19359
19407
  if (type === "flv") {
19360
19408
  return await getFlvStrategy(options);
@@ -22170,7 +22218,7 @@ var __publicField = (obj, key, value) => {
22170
22218
  device_id: this._deviceId,
22171
22219
  error_report_stop: true,
22172
22220
  ext: {
22173
- veplayer_version: "2.5.1-rc.2",
22221
+ veplayer_version: "2.5.2-rc.0",
22174
22222
  flv_version: "3.0.21-rc.5",
22175
22223
  hls_version: "3.0.21-rc.5",
22176
22224
  rts_version: "0.2.1-alpha.14"
@@ -22411,6 +22459,7 @@ var __publicField = (obj, key, value) => {
22411
22459
  ...EN$1,
22412
22460
  INVALID_PARAMETER: "The imported parameter is empty, please pass in necessary parameters such as the stream address",
22413
22461
  INVALID_LOGGER: `Log options not configured correctly. Please refer to this document ${logDoc} to configure the logs.`,
22462
+ 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.",
22414
22463
  // info-panel
22415
22464
  FORMAT: "format",
22416
22465
  FPS: "fps",
@@ -22429,6 +22478,7 @@ var __publicField = (obj, key, value) => {
22429
22478
  ...ZH_CN$1,
22430
22479
  INVALID_PARAMETER: "入参为空,请传入流地址等必要参数",
22431
22480
  INVALID_LOGGER: `未正确配置质量日志参数, 请参考 ${logDoc} 配置`,
22481
+ EMPTY_RTM_FALLBACK_PARAMETER: "未配置 RTM 降级地址 fallbackUrl,请设置 enableFallback: false 取消降级或根据浏览器环境配置 FLV、HLS 格式降级地址",
22432
22482
  // info-panel
22433
22483
  FORMAT: "格式",
22434
22484
  FPS: "帧率",
@@ -22727,13 +22777,15 @@ var __publicField = (obj, key, value) => {
22727
22777
  };
22728
22778
  },
22729
22779
  async preparePlugins(url) {
22780
+ var _a2;
22730
22781
  const [typeStrategy, drmStrategy, abrStrategy] = await Promise.all([
22731
22782
  getTypeStrategy(
22732
22783
  {
22733
22784
  ...finalOptions,
22734
22785
  url
22735
22786
  },
22736
- player
22787
+ player,
22788
+ i18n
22737
22789
  ),
22738
22790
  getDrmStrategy(
22739
22791
  {
@@ -22756,7 +22808,8 @@ var __publicField = (obj, key, value) => {
22756
22808
  ...plugins ?? [],
22757
22809
  ...drmPlugins ?? [],
22758
22810
  ...abrPlugins ?? []
22759
- ]
22811
+ ],
22812
+ useSrc: !((_a2 = typeStrategy.plugins) == null ? void 0 : _a2.length)
22760
22813
  };
22761
22814
  }
22762
22815
  },