@volcengine/veplayer 2.6.2 → 2.7.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.
@@ -11846,14 +11846,6 @@ var __publicField = (obj, key, value) => {
11846
11846
  const sourceManager = args.player.config.sources.sourceManager;
11847
11847
  args.config.list = sourceManager.sources;
11848
11848
  }
11849
- afterCreate() {
11850
- super.afterCreate();
11851
- if (this.config.sourceManager.sources.length < 2) {
11852
- this.hide();
11853
- } else {
11854
- this.renderItemList();
11855
- }
11856
- }
11857
11849
  registerIcons() {
11858
11850
  return {
11859
11851
  source: { icon: SourceIcon }
@@ -11862,6 +11854,10 @@ var __publicField = (obj, key, value) => {
11862
11854
  renderItemList() {
11863
11855
  const { sources, source } = this.config.sourceManager;
11864
11856
  const i18nManager = this.player.config.i18nManager;
11857
+ if (sources.length < 2) {
11858
+ this.hide();
11859
+ return;
11860
+ }
11865
11861
  const renderItems = sources.map((source2) => {
11866
11862
  return {
11867
11863
  ...source2,
@@ -12543,6 +12539,10 @@ var __publicField = (obj, key, value) => {
12543
12539
  var _a, _b;
12544
12540
  const sourceManager = this.player.config.sourceManager;
12545
12541
  const definitions = ((_a = sourceManager.source) == null ? void 0 : _a.definitions) ?? [];
12542
+ if (definitions.length < 2) {
12543
+ this.hide();
12544
+ return;
12545
+ }
12546
12546
  const renderItems = definitions.map((definition) => {
12547
12547
  const showItem = {
12548
12548
  url: definition.url,
@@ -13463,7 +13463,7 @@ var __publicField = (obj, key, value) => {
13463
13463
  }
13464
13464
  return "unknown";
13465
13465
  }
13466
- function isMseSupported$1(codec = Codec.H264) {
13466
+ function isMseSupported$2(codec = Codec.H264) {
13467
13467
  if (codec === Codec.H265) {
13468
13468
  return sniffer$1.isHevcSupported();
13469
13469
  }
@@ -13494,7 +13494,7 @@ var __publicField = (obj, key, value) => {
13494
13494
  ...util$1,
13495
13495
  ...DomUtils,
13496
13496
  getStreamType,
13497
- isMseSupported: isMseSupported$1,
13497
+ isMseSupported: isMseSupported$2,
13498
13498
  isSoftDecodeSupported,
13499
13499
  isMMSSupported: isMMSSupported$1,
13500
13500
  appendSearchParams: appendSearchParams$1,
@@ -14231,10 +14231,12 @@ var __publicField = (obj, key, value) => {
14231
14231
  __publicField(this, "_events", {});
14232
14232
  __publicField(this, "_customMedia");
14233
14233
  __publicField(this, "_errorCallback");
14234
+ __publicField(this, "_beforeFallbackError");
14234
14235
  var _a, _b, _c, _d, _e, _f;
14235
14236
  this._sourceManager = options.sourceManager;
14236
14237
  this._preparePlugins = options.preparePlugins;
14237
14238
  this._previousPrepareResult = options.prepareResult;
14239
+ this._beforeFallbackError = options.beforeFallbackError;
14238
14240
  this._i18nManager = options.i18nManager ?? new VeI18n({
14239
14241
  i18n: options.i18n
14240
14242
  });
@@ -14259,6 +14261,9 @@ var __publicField = (obj, key, value) => {
14259
14261
  ...DEFAULT_OPTIONS,
14260
14262
  ...xgOptions,
14261
14263
  definition: {
14264
+ // TODO: ts
14265
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
14266
+ // @ts-ignore
14262
14267
  list: ((_d = this._sourceManager.source) == null ? void 0 : _d.definitions) ?? [],
14263
14268
  defaultDefinition: (_e = this._sourceManager.definition) == null ? void 0 : _e.definition,
14264
14269
  ...options.definition ?? {}
@@ -14443,7 +14448,7 @@ var __publicField = (obj, key, value) => {
14443
14448
  * @brief Retrieve the player SDK version number.
14444
14449
  */
14445
14450
  get playerVersion() {
14446
- return "2.6.2";
14451
+ return "2.7.0";
14447
14452
  }
14448
14453
  /** {zh}
14449
14454
  * @brief 获取当前播放视频的清晰度唯一标识(definition)。
@@ -14929,13 +14934,18 @@ var __publicField = (obj, key, value) => {
14929
14934
  * @hidden
14930
14935
  */
14931
14936
  async prepare(url) {
14932
- var _a, _b, _c, _d, _e, _f, _g;
14937
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
14933
14938
  const result = await ((_a = this._preparePlugins) == null ? void 0 : _a.call(this, url));
14934
- const newUrl = ((_b = result == null ? void 0 : result.options) == null ? void 0 : _b.url) ?? url;
14935
- const oldUrl = (_d = (_c = this._player) == null ? void 0 : _c.config) == null ? void 0 : _d.url;
14936
- const isSameProtocol = oldUrl && getStreamType(newUrl) === getStreamType(oldUrl);
14939
+ let isSameProtocol;
14940
+ if ((result == null ? void 0 : result.protocol) && ((_b = this._previousPrepareResult) == null ? void 0 : _b.protocol)) {
14941
+ isSameProtocol = result.protocol === ((_c = this._previousPrepareResult) == null ? void 0 : _c.protocol);
14942
+ } else {
14943
+ const newUrl = ((_d = result == null ? void 0 : result.options) == null ? void 0 : _d.url) ?? url;
14944
+ const oldUrl = (_f = (_e = this._player) == null ? void 0 : _e.config) == null ? void 0 : _f.url;
14945
+ isSameProtocol = oldUrl && getStreamType(newUrl) === getStreamType(oldUrl);
14946
+ }
14937
14947
  if (!isSameProtocol) {
14938
- (_f = (_e = this._previousPrepareResult) == null ? void 0 : _e.plugins) == null ? void 0 : _f.forEach((plugin) => {
14948
+ (_h = (_g = this._previousPrepareResult) == null ? void 0 : _g.plugins) == null ? void 0 : _h.forEach((plugin) => {
14939
14949
  this._player.unRegisterPlugin(plugin.pluginName);
14940
14950
  });
14941
14951
  }
@@ -14944,7 +14954,7 @@ var __publicField = (obj, key, value) => {
14944
14954
  this._player.setConfig(result.options);
14945
14955
  }
14946
14956
  return {
14947
- plugins: isSameProtocol ? [] : (_g = result == null ? void 0 : result.plugins) == null ? void 0 : _g.map((plugin) => {
14957
+ plugins: isSameProtocol ? [] : (_i = result == null ? void 0 : result.plugins) == null ? void 0 : _i.map((plugin) => {
14948
14958
  return this._player.registerPlugin(plugin);
14949
14959
  }),
14950
14960
  options: result == null ? void 0 : result.options,
@@ -14957,11 +14967,18 @@ var __publicField = (obj, key, value) => {
14957
14967
  const preUrl = this._sourceManager.url;
14958
14968
  const url = this._sourceManager.fallback();
14959
14969
  if (!url) {
14970
+ const transformedError = transform$1(err, this._i18nManager);
14971
+ try {
14972
+ const { canEmitError } = await this._beforeFallbackError(
14973
+ transformedError
14974
+ );
14975
+ if (!canEmitError) {
14976
+ return;
14977
+ }
14978
+ } catch (error2) {
14979
+ }
14960
14980
  this._player.removeClass(STATE_CLASS.ENTER);
14961
- this.emit(
14962
- Events$1.FALLBACK_ERROR,
14963
- transform$1(err, this._i18nManager)
14964
- );
14981
+ this.emit(Events$1.FALLBACK_ERROR, transformedError);
14965
14982
  return;
14966
14983
  }
14967
14984
  this._player.once("canplay", () => {
@@ -15041,7 +15058,6 @@ var __publicField = (obj, key, value) => {
15041
15058
  return new Promise((resolve) => {
15042
15059
  const curTime = this._player.currentTime;
15043
15060
  const _canplay = () => {
15044
- console.log("canplay canplay");
15045
15061
  this._player.currentTime = curTime;
15046
15062
  if (isPaused) {
15047
15063
  this._player.once(CANPLAY, () => {
@@ -19592,44 +19608,6 @@ var __publicField = (obj, key, value) => {
19592
19608
  return result;
19593
19609
  }
19594
19610
  }
19595
- function enableHlsJs(options) {
19596
- var _a, _b;
19597
- if ((_a = options == null ? void 0 : options.hls) == null ? void 0 : _a.enableHlsJs) {
19598
- return true;
19599
- }
19600
- if (((_b = options == null ? void 0 : options.ad) == null ? void 0 : _b.adType) === "ssai") {
19601
- return true;
19602
- }
19603
- return false;
19604
- }
19605
- const getHlsStrategy = async (options) => {
19606
- var _a, _b;
19607
- let mseStrategy;
19608
- let softStrategy;
19609
- const codec = await getCodec(options);
19610
- const isSoftDecode$1 = await isSoftDecode(options, codec);
19611
- const useHlsJs = enableHlsJs(options);
19612
- if (isSoftDecode$1) {
19613
- softStrategy = codec === Codec.H265 ? createSoftDecodeH265Strategy() : createSoftDecodeH264Strategy();
19614
- mseStrategy = createHlsMseStrategy(options, useHlsJs);
19615
- }
19616
- if ((sniffer$1.device !== "mobile" || ((_a = options == null ? void 0 : options.hls) == null ? void 0 : _a.enableMSE)) && (codec === "unknown" ? isMseSupported$1(Codec.H264) : isMseSupported$1(codec))) {
19617
- mseStrategy = createHlsMseStrategy(options, useHlsJs);
19618
- }
19619
- if (!mseStrategy && !softStrategy) {
19620
- return {};
19621
- }
19622
- const [mseModule, softModule] = await Promise.all([
19623
- (mseStrategy == null ? void 0 : mseStrategy.module) && load(mseStrategy.module).catch(() => void 0),
19624
- (softStrategy == null ? void 0 : softStrategy.module) && load(softStrategy.module).catch(() => void 0)
19625
- ]);
19626
- (softModule == null ? void 0 : softModule.XGVideoPlugin) && ((_b = softStrategy == null ? void 0 : softStrategy.afterLoad) == null ? void 0 : _b.call(softStrategy, softModule == null ? void 0 : softModule.XGVideoPlugin));
19627
- const combineOptions$1 = combineOptions([mseStrategy, softStrategy]);
19628
- return {
19629
- options: combineOptions$1,
19630
- plugins: (mseModule == null ? void 0 : mseModule.HlsPlugin) ? [mseModule.HlsPlugin] : []
19631
- };
19632
- };
19633
19611
  const getDefaultFlvOptions = (options) => {
19634
19612
  var _a;
19635
19613
  return {
@@ -19801,203 +19779,6 @@ var __publicField = (obj, key, value) => {
19801
19779
  i18n
19802
19780
  );
19803
19781
  }
19804
- async function isRTMSupported() {
19805
- const { RtmPlugin } = await load(DynamicModule.PluginRtm);
19806
- return RtmPlugin.isSupported();
19807
- }
19808
- async function isRTMSupportCodec(codec = RTMCodec.H264) {
19809
- const { RtmPlugin } = await load(DynamicModule.PluginRtm);
19810
- if (codec === RTMCodec.H264)
19811
- return RtmPlugin.isSupportedH264();
19812
- return false;
19813
- }
19814
- const rtmStrategy = {
19815
- options: {},
19816
- module: DynamicModule.PluginRtm
19817
- };
19818
- const generateFallbackUrl = (url) => {
19819
- if (sniffer$1.device === "pc") {
19820
- return url.replace(".sdp", ".flv");
19821
- } else {
19822
- return url.replace(".sdp", ".m3u8");
19823
- }
19824
- };
19825
- const getRtmStrategy = async (options, player, i18n) => {
19826
- var _a, _b;
19827
- let backupStrategy;
19828
- let actualFallbackUrl = "";
19829
- const { url, playlist } = options;
19830
- const { fallbackUrl, enableRTMAutoTranscode, ...ret } = options.rtm || {};
19831
- let { enableFallback = true } = options.rtm || {};
19832
- if (playlist == null ? void 0 : playlist.length) {
19833
- enableFallback = false;
19834
- }
19835
- const isRTMAutoTranscode = enableRTMAutoTranscode || ((_a = getUrlObject(url)) == null ? void 0 : _a.searchParams.get("enableRTMAutoTranscode")) === "true";
19836
- if (enableFallback) {
19837
- if (fallbackUrl) {
19838
- actualFallbackUrl = fallbackUrl;
19839
- } else if (isRTMAutoTranscode && url) {
19840
- actualFallbackUrl = generateFallbackUrl(url);
19841
- } else {
19842
- console.warn(
19843
- create(ErrorCode.EMPTY_RTM_FALLBACK_PARAMETER, i18n).message
19844
- );
19845
- }
19846
- }
19847
- const backupType = actualFallbackUrl && util.getStreamType(actualFallbackUrl);
19848
- if (backupType === "flv" && util.isMseSupported(Codec.H264)) {
19849
- backupStrategy = createFlvMseStrategy(options);
19850
- } else if (backupType === "hls" && (sniffer$1.device !== "mobile" || ((_b = options == null ? void 0 : options.hls) == null ? void 0 : _b.enableMSE)) && util.isMseSupported(Codec.H264)) {
19851
- backupStrategy = createHlsMseStrategy(options);
19852
- }
19853
- const [rtmCdn, backupCdn] = await Promise.all([
19854
- load(rtmStrategy.module).then((module2) => {
19855
- return module2.RtmPlugin;
19856
- }).catch(() => void 0),
19857
- backupStrategy && load(backupStrategy.module).then((module2) => {
19858
- if ((backupStrategy == null ? void 0 : backupStrategy.module) === DynamicModule.PluginFlv) {
19859
- return module2.FlvPlugin;
19860
- } else if ((backupStrategy == null ? void 0 : backupStrategy.module) === DynamicModule.PluginHls) {
19861
- return module2.HlsPlugin;
19862
- }
19863
- }).catch(() => void 0)
19864
- ]);
19865
- if (actualFallbackUrl) {
19866
- const [RTMSupported, RTMSupportCodec] = await Promise.all([
19867
- isRTMSupported(),
19868
- isRTMSupportCodec()
19869
- ]);
19870
- if (!RTMSupported || !RTMSupportCodec) {
19871
- if (player) {
19872
- player.emit("degrade", {
19873
- url: actualFallbackUrl,
19874
- originRtmUrl: url,
19875
- code: "NOT_SUPPORT",
19876
- message: "not support rtm or h264",
19877
- isRTMSupported: RTMSupported,
19878
- isRTMSupportCodec: RTMSupportCodec
19879
- });
19880
- }
19881
- return {
19882
- options: {
19883
- ...(backupStrategy == null ? void 0 : backupStrategy.options) || {},
19884
- url: actualFallbackUrl,
19885
- _RTMdegrade: {
19886
- _originRtmUrl: url,
19887
- _isRTMSupported: RTMSupported,
19888
- _isRTMSupportCodec: RTMSupportCodec
19889
- }
19890
- },
19891
- plugins: backupCdn ? [backupCdn] : []
19892
- };
19893
- }
19894
- }
19895
- return {
19896
- options: {
19897
- ...(backupStrategy == null ? void 0 : backupStrategy.options) || {},
19898
- url: enableRTMAutoTranscode ? util.appendSearchParams(url, { enableRTMAutoTranscode: "true" }) : void 0,
19899
- _RTMdegrade: void 0,
19900
- rts: {
19901
- retryCount: 0,
19902
- ...ret,
19903
- backupURL: actualFallbackUrl,
19904
- backupConstruct: backupCdn
19905
- }
19906
- },
19907
- plugins: rtmCdn ? [rtmCdn] : []
19908
- };
19909
- };
19910
- var DrmType = /* @__PURE__ */ ((DrmType2) => {
19911
- DrmType2["Fairplay"] = "fairplay";
19912
- return DrmType2;
19913
- })(DrmType || {});
19914
- function getDrmType(drm) {
19915
- if ((drm == null ? void 0 : drm.fairplay) && (sniffer$1.browser === "safari" || sniffer$1.os.isIos)) {
19916
- return "fairplay";
19917
- }
19918
- return;
19919
- }
19920
- function isMseSupportedWithDrm({
19921
- drm,
19922
- streamType
19923
- }) {
19924
- const drmType = getDrmType(drm);
19925
- if (!drmType) {
19926
- return true;
19927
- }
19928
- if (drmType === "fairplay" && streamType === "hls") {
19929
- return false;
19930
- }
19931
- return true;
19932
- }
19933
- const { isMMSSupported, isMseSupported } = util;
19934
- function enableMMS() {
19935
- return sniffer$1.os.isIos;
19936
- }
19937
- function isFLVSupported(codec = Codec.H264) {
19938
- const isMediaSourceSupported = enableMMS() ? isMMSSupported : isMseSupported;
19939
- return isMediaSourceSupported(codec);
19940
- }
19941
- const { appendSearchParams } = util;
19942
- const getFlvStrategy = async (options) => {
19943
- var _a, _b, _c, _d, _e, _f;
19944
- let mseStrategy;
19945
- let softStrategy;
19946
- const enableLowLatency = (_a = options == null ? void 0 : options.flv) == null ? void 0 : _a.enableLowLatency;
19947
- const enableFrameChasing = ((_c = (_b = options == null ? void 0 : options.flv) == null ? void 0 : _b.lowLatency) == null ? void 0 : _c.enableFrameChasing) ?? true;
19948
- const abrPts = ((_e = (_d = options == null ? void 0 : options.flv) == null ? void 0 : _d.lowLatency) == null ? void 0 : _e.abrPts) ?? "-800";
19949
- const codec = await getCodec(options);
19950
- const isSoftDecode$1 = await isSoftDecode(options, codec);
19951
- if (isSoftDecode$1) {
19952
- softStrategy = codec === Codec.H265 ? createSoftDecodeH265Strategy() : createSoftDecodeH264Strategy();
19953
- mseStrategy = createFlvMseStrategy(options);
19954
- }
19955
- if (codec === "unknown" ? isFLVSupported(Codec.H264) : isFLVSupported(codec)) {
19956
- mseStrategy = enableMMS() ? createFlvMssStrategy(options) : createFlvMseStrategy(options);
19957
- }
19958
- if (!mseStrategy && !softStrategy) {
19959
- return {};
19960
- }
19961
- const [mseModule, softModule] = await Promise.all([
19962
- (mseStrategy == null ? void 0 : mseStrategy.module) && load(mseStrategy.module).catch(() => void 0),
19963
- (softStrategy == null ? void 0 : softStrategy.module) && load(softStrategy.module).catch(() => void 0)
19964
- ]);
19965
- (softModule == null ? void 0 : softModule.XGVideoPlugin) && ((_f = softStrategy == null ? void 0 : softStrategy.afterLoad) == null ? void 0 : _f.call(softStrategy, softModule == null ? void 0 : softModule.XGVideoPlugin));
19966
- const combineOptions$1 = combineOptions([mseStrategy, softStrategy]);
19967
- const plugins = [];
19968
- if (enableLowLatency) {
19969
- combineOptions$1.url = appendSearchParams(options.url, { abr_pts: abrPts });
19970
- }
19971
- if (mseModule) {
19972
- plugins.push(mseModule.FlvPlugin);
19973
- if (enableLowLatency && enableFrameChasing) {
19974
- plugins.push(mseModule.Adaptive);
19975
- }
19976
- }
19977
- return {
19978
- options: combineOptions$1,
19979
- plugins
19980
- };
19981
- };
19982
- const getTypeStrategy = async (options, player, i18n) => {
19983
- const type = options.url ? util.getStreamType(options.url) : "";
19984
- if (!type || type === "unknown") {
19985
- return { options: {}, plugins: [] };
19986
- }
19987
- if (type === "rtm") {
19988
- return await getRtmStrategy(options, player, i18n);
19989
- }
19990
- if (type === "flv") {
19991
- return await getFlvStrategy(options);
19992
- }
19993
- if (type === "hls") {
19994
- if (!isMseSupportedWithDrm({ drm: options.drm, streamType: type })) {
19995
- return { options: {}, plugins: [] };
19996
- }
19997
- return await getHlsStrategy(options);
19998
- }
19999
- return { options: {}, plugins: [] };
20000
- };
20001
19782
  var FUNC_ERROR_TEXT = "Expected a function";
20002
19783
  var NAN = 0 / 0;
20003
19784
  var symbolTag = "[object Symbol]";
@@ -22810,7 +22591,7 @@ var __publicField = (obj, key, value) => {
22810
22591
  device_id: this._deviceId,
22811
22592
  error_report_stop: true,
22812
22593
  ext: {
22813
- veplayer_version: "2.6.2",
22594
+ veplayer_version: "2.7.0",
22814
22595
  flv_version: "3.0.21-rc.21",
22815
22596
  hls_version: "3.0.21-rc.21",
22816
22597
  rts_version: "0.2.1-alpha.14"
@@ -23089,16 +22870,326 @@ var __publicField = (obj, key, value) => {
23089
22870
  DECODE_INFO: "软解信息",
23090
22871
  REFRESH: "刷新"
23091
22872
  };
23092
- const getDrmStrategy = async (options, player) => {
23093
- var _a;
23094
- const drmType = getDrmType(options.drm);
23095
- if (options.url && drmType === DrmType.Fairplay) {
23096
- try {
23097
- const { getDrmConfig, ...originFairplayConfig } = ((_a = options == null ? void 0 : options.drm) == null ? void 0 : _a.fairplay) ?? {};
23098
- const [drmPlugin, drmConfig] = await Promise.all([
23099
- load(DynamicModule.PluginDrm).then((module2) => module2.DrmPlugin).catch(() => void 0),
23100
- getDrmConfig == null ? void 0 : getDrmConfig({
23101
- url: options.url
22873
+ const LiveUrlType = {
22874
+ Hls: "hls",
22875
+ LLHls: "ll-hls",
22876
+ Flv: "flv",
22877
+ Rtm: "rtm",
22878
+ LLFlv: "ll-flv"
22879
+ };
22880
+ const { isMMSSupported, isMseSupported: isMseSupported$1 } = util;
22881
+ function enableMMS() {
22882
+ return sniffer$1.os.isIos;
22883
+ }
22884
+ function isFLVSupported(codec = Codec.H264) {
22885
+ const isMediaSourceSupported = enableMMS() ? isMMSSupported : isMseSupported$1;
22886
+ return isMediaSourceSupported(codec);
22887
+ }
22888
+ var FallbackKind = /* @__PURE__ */ ((FallbackKind2) => {
22889
+ FallbackKind2["Error"] = "Error";
22890
+ FallbackKind2["Stall"] = "Stall";
22891
+ return FallbackKind2;
22892
+ })(FallbackKind || {});
22893
+ class BaseProtocol {
22894
+ constructor(options) {
22895
+ // 下一个 protocol 类
22896
+ __publicField(this, "nextProtocol");
22897
+ __publicField(this, "preProtocol");
22898
+ __publicField(this, "protocolStrategy");
22899
+ __publicField(this, "_fallback");
22900
+ this._fallback = options.fallback;
22901
+ }
22902
+ _getKindFallbackStrategy(kind) {
22903
+ var _a, _b, _c, _d, _e, _f, _g;
22904
+ return ((_c = (_b = (_a = this._fallback) == null ? void 0 : _a.fallbackStrategy) == null ? void 0 : _b[this.protocolType]) == null ? void 0 : _c[kind]) ?? ((_f = (_e = (_d = this._fallback) == null ? void 0 : _d.fallbackStrategy) == null ? void 0 : _e["all"]) == null ? void 0 : _f[kind]) ?? ((_g = this.defaultFallbackStrategy) == null ? void 0 : _g[kind]);
22905
+ }
22906
+ // eslint-disable-next-line @typescript-eslint/member-ordering
22907
+ get errorFallbackStrategy() {
22908
+ return this._getKindFallbackStrategy(
22909
+ "Error"
22910
+ /* Error */
22911
+ );
22912
+ }
22913
+ // eslint-disable-next-line @typescript-eslint/member-ordering
22914
+ get stallFallbackStrategy() {
22915
+ return this._getKindFallbackStrategy(
22916
+ "Stall"
22917
+ /* Stall */
22918
+ );
22919
+ }
22920
+ // eslint-disable-next-line @typescript-eslint/member-ordering
22921
+ shouldFallbackWhenError(params) {
22922
+ var _a, _b, _c;
22923
+ if ((_a = this.errorFallbackStrategy) == null ? void 0 : _a.shouldFallback) {
22924
+ return (_b = this.errorFallbackStrategy) == null ? void 0 : _b.shouldFallback(
22925
+ this.protocolType,
22926
+ params
22927
+ );
22928
+ }
22929
+ if ((_c = this.errorFallbackStrategy) == null ? void 0 : _c.excludeList) {
22930
+ return !this.errorFallbackStrategy.excludeList.includes(
22931
+ params.error.errorCode
22932
+ );
22933
+ }
22934
+ return false;
22935
+ }
22936
+ }
22937
+ const { appendSearchParams } = util;
22938
+ const getFlvStrategy = async (options) => {
22939
+ var _a, _b, _c, _d, _e, _f;
22940
+ let mseStrategy;
22941
+ let softStrategy;
22942
+ const enableLowLatency = (_a = options == null ? void 0 : options.flv) == null ? void 0 : _a.enableLowLatency;
22943
+ const enableFrameChasing = ((_c = (_b = options == null ? void 0 : options.flv) == null ? void 0 : _b.lowLatency) == null ? void 0 : _c.enableFrameChasing) ?? true;
22944
+ const abrPts = ((_e = (_d = options == null ? void 0 : options.flv) == null ? void 0 : _d.lowLatency) == null ? void 0 : _e.abrPts) ?? "-800";
22945
+ const codec = await getCodec(options);
22946
+ const isSoftDecode$1 = await isSoftDecode(options, codec);
22947
+ if (isSoftDecode$1) {
22948
+ softStrategy = codec === Codec.H265 ? createSoftDecodeH265Strategy() : createSoftDecodeH264Strategy();
22949
+ mseStrategy = createFlvMseStrategy(options);
22950
+ }
22951
+ if (codec === "unknown" ? isFLVSupported(Codec.H264) : isFLVSupported(codec)) {
22952
+ mseStrategy = enableMMS() ? createFlvMssStrategy(options) : createFlvMseStrategy(options);
22953
+ }
22954
+ if (!mseStrategy && !softStrategy) {
22955
+ return {};
22956
+ }
22957
+ const [mseModule, softModule] = await Promise.all([
22958
+ (mseStrategy == null ? void 0 : mseStrategy.module) && load(mseStrategy.module).catch(() => void 0),
22959
+ (softStrategy == null ? void 0 : softStrategy.module) && load(softStrategy.module).catch(() => void 0)
22960
+ ]);
22961
+ (softModule == null ? void 0 : softModule.XGVideoPlugin) && ((_f = softStrategy == null ? void 0 : softStrategy.afterLoad) == null ? void 0 : _f.call(softStrategy, softModule == null ? void 0 : softModule.XGVideoPlugin));
22962
+ const combineOptions$1 = combineOptions([mseStrategy, softStrategy]);
22963
+ const plugins = [];
22964
+ if (enableLowLatency) {
22965
+ combineOptions$1.url = appendSearchParams(options.url, { abr_pts: abrPts });
22966
+ }
22967
+ if (mseModule) {
22968
+ plugins.push(mseModule.FlvPlugin);
22969
+ if (enableLowLatency && enableFrameChasing) {
22970
+ plugins.push(mseModule.Adaptive);
22971
+ }
22972
+ }
22973
+ return {
22974
+ options: combineOptions$1,
22975
+ plugins
22976
+ };
22977
+ };
22978
+ class FlvProtocol extends BaseProtocol {
22979
+ static get suffix() {
22980
+ return ".flv";
22981
+ }
22982
+ get protocolType() {
22983
+ return LiveUrlType.Flv;
22984
+ }
22985
+ get defaultFallbackStrategy() {
22986
+ return {};
22987
+ }
22988
+ static generateUrl(urls, {
22989
+ generateUrlFromOtherProtocol: generateUrlFromOtherProtocol2
22990
+ }) {
22991
+ return urls[LiveUrlType.Flv] ?? generateUrlFromOtherProtocol2();
22992
+ }
22993
+ static canGenerateOtherProtocol() {
22994
+ return true;
22995
+ }
22996
+ async canPlay() {
22997
+ return {
22998
+ canPlay: isFLVSupported()
22999
+ };
23000
+ }
23001
+ shouldFallbackWhenStall() {
23002
+ return false;
23003
+ }
23004
+ async getProtocolStrategy(options, {
23005
+ enableSelector
23006
+ }) {
23007
+ return getFlvStrategy(
23008
+ enableSelector ? {
23009
+ ...options,
23010
+ flv: {
23011
+ ...options.flv,
23012
+ enableLowLatency: false
23013
+ }
23014
+ } : options
23015
+ );
23016
+ }
23017
+ async getAbrStrategy(options) {
23018
+ var _a;
23019
+ const abrOptions = (_a = options == null ? void 0 : options.flv) == null ? void 0 : _a.abr;
23020
+ if (!abrOptions) {
23021
+ return {};
23022
+ }
23023
+ const abrPlugin = await load(DynamicModule.PluginAbr).catch(
23024
+ () => void 0
23025
+ );
23026
+ return {
23027
+ options: {
23028
+ abr: {
23029
+ ...abrOptions,
23030
+ open: abrOptions.enable ?? true
23031
+ }
23032
+ },
23033
+ plugins: [abrPlugin == null ? void 0 : abrPlugin.AbrPlugin]
23034
+ };
23035
+ }
23036
+ getDrmStrategy() {
23037
+ return void 0;
23038
+ }
23039
+ }
23040
+ class FlvLowLatencyProtocol extends FlvProtocol {
23041
+ get protocolType() {
23042
+ return LiveUrlType.LLFlv;
23043
+ }
23044
+ async getProtocolStrategy(options) {
23045
+ return getFlvStrategy({
23046
+ ...options,
23047
+ flv: {
23048
+ ...options.flv,
23049
+ enableLowLatency: true
23050
+ }
23051
+ });
23052
+ }
23053
+ }
23054
+ var DrmType = /* @__PURE__ */ ((DrmType2) => {
23055
+ DrmType2["Fairplay"] = "fairplay";
23056
+ return DrmType2;
23057
+ })(DrmType || {});
23058
+ function getDrmType(drm) {
23059
+ if ((drm == null ? void 0 : drm.fairplay) && (sniffer$1.browser === "safari" || sniffer$1.os.isIos)) {
23060
+ return "fairplay";
23061
+ }
23062
+ return;
23063
+ }
23064
+ function isMseSupportedWithDrm({
23065
+ drm,
23066
+ streamType
23067
+ }) {
23068
+ const drmType = getDrmType(drm);
23069
+ if (!drmType) {
23070
+ return true;
23071
+ }
23072
+ if (drmType === "fairplay" && streamType === "hls") {
23073
+ return false;
23074
+ }
23075
+ return true;
23076
+ }
23077
+ const { isMseSupported } = util;
23078
+ function enableHlsJs(options) {
23079
+ var _a, _b;
23080
+ if ((_a = options == null ? void 0 : options.hls) == null ? void 0 : _a.enableHlsJs) {
23081
+ return true;
23082
+ }
23083
+ if (((_b = options == null ? void 0 : options.ad) == null ? void 0 : _b.adType) === "ssai") {
23084
+ return true;
23085
+ }
23086
+ return false;
23087
+ }
23088
+ const getHlsStrategy = async (options) => {
23089
+ var _a, _b;
23090
+ let mseStrategy;
23091
+ let softStrategy;
23092
+ if (!isMseSupportedWithDrm({ drm: options.drm, streamType: "hls" })) {
23093
+ return { options: {}, plugins: [] };
23094
+ }
23095
+ const codec = await getCodec(options);
23096
+ const isSoftDecode$1 = await isSoftDecode(options, codec);
23097
+ const useHlsJs = enableHlsJs(options);
23098
+ if (isSoftDecode$1) {
23099
+ softStrategy = codec === Codec.H265 ? createSoftDecodeH265Strategy() : createSoftDecodeH264Strategy();
23100
+ mseStrategy = createHlsMseStrategy(options, useHlsJs);
23101
+ }
23102
+ if ((sniffer$1.device !== "mobile" || ((_a = options == null ? void 0 : options.hls) == null ? void 0 : _a.enableMSE)) && (codec === "unknown" ? isMseSupported(Codec.H264) : isMseSupported(codec))) {
23103
+ mseStrategy = createHlsMseStrategy(options, useHlsJs);
23104
+ }
23105
+ if (!mseStrategy && !softStrategy) {
23106
+ return {};
23107
+ }
23108
+ const [mseModule, softModule] = await Promise.all([
23109
+ (mseStrategy == null ? void 0 : mseStrategy.module) && load(mseStrategy.module).catch(() => void 0),
23110
+ (softStrategy == null ? void 0 : softStrategy.module) && load(softStrategy.module).catch(() => void 0)
23111
+ ]);
23112
+ (softModule == null ? void 0 : softModule.XGVideoPlugin) && ((_b = softStrategy == null ? void 0 : softStrategy.afterLoad) == null ? void 0 : _b.call(softStrategy, softModule == null ? void 0 : softModule.XGVideoPlugin));
23113
+ const combineOptions$1 = combineOptions([mseStrategy, softStrategy]);
23114
+ return {
23115
+ options: combineOptions$1,
23116
+ plugins: (mseModule == null ? void 0 : mseModule.HlsPlugin) ? [mseModule.HlsPlugin] : []
23117
+ };
23118
+ };
23119
+ function getType(definition) {
23120
+ if (typeof definition === "string") {
23121
+ return getStreamType(definition);
23122
+ }
23123
+ if (definition.type) {
23124
+ return definition.type;
23125
+ }
23126
+ return getStreamType(definition.url);
23127
+ }
23128
+ function pushToEmpty(obj, key, value) {
23129
+ if (!obj[key]) {
23130
+ obj[key] = [];
23131
+ }
23132
+ obj[key].push(value);
23133
+ }
23134
+ function splitPlaylist(playlist) {
23135
+ return playlist.reduce((pre, source) => {
23136
+ const definitionMap = source.definitions.reduce(
23137
+ (preDefinition, definition) => {
23138
+ const type = getType(definition);
23139
+ pushToEmpty(preDefinition, type, definition);
23140
+ return preDefinition;
23141
+ },
23142
+ {}
23143
+ );
23144
+ Object.keys(definitionMap).map((type) => {
23145
+ pushToEmpty(pre, type, {
23146
+ ...source,
23147
+ definitions: definitionMap[type]
23148
+ });
23149
+ });
23150
+ return pre;
23151
+ }, {});
23152
+ }
23153
+ function generateUrlFromOtherProtocol(playlist, suffix, targetSuffix) {
23154
+ return modifyPlaylistUrl(playlist, (url) => {
23155
+ return url.replace(suffix, targetSuffix);
23156
+ });
23157
+ }
23158
+ function modifyPlaylistUrl(playlist, callback) {
23159
+ const newPlaylist = [];
23160
+ playlist == null ? void 0 : playlist.forEach((source) => {
23161
+ const definitions = [];
23162
+ source.definitions.forEach((definition) => {
23163
+ var _a;
23164
+ if (typeof definition === "string") {
23165
+ definitions.push(callback(definition));
23166
+ } else {
23167
+ definitions.push({
23168
+ ...definition,
23169
+ url: callback(definition.url),
23170
+ fallbackUrls: (_a = definition.fallbackUrls) == null ? void 0 : _a.map(
23171
+ (fallbackUrl) => callback(fallbackUrl)
23172
+ )
23173
+ });
23174
+ }
23175
+ });
23176
+ newPlaylist.push({
23177
+ ...source,
23178
+ definitions
23179
+ });
23180
+ });
23181
+ return newPlaylist;
23182
+ }
23183
+ const getDrmStrategy = async (options, player) => {
23184
+ var _a;
23185
+ const drmType = getDrmType(options.drm);
23186
+ if (options.url && drmType === DrmType.Fairplay) {
23187
+ try {
23188
+ const { getDrmConfig, ...originFairplayConfig } = ((_a = options == null ? void 0 : options.drm) == null ? void 0 : _a.fairplay) ?? {};
23189
+ const [drmPlugin, drmConfig] = await Promise.all([
23190
+ load(DynamicModule.PluginDrm).then((module2) => module2.DrmPlugin).catch(() => void 0),
23191
+ getDrmConfig == null ? void 0 : getDrmConfig({
23192
+ url: options.url
23102
23193
  })
23103
23194
  ]);
23104
23195
  const fairplayDrmConfig = Object.assign(
@@ -23120,29 +23211,547 @@ var __publicField = (obj, key, value) => {
23120
23211
  }
23121
23212
  return {};
23122
23213
  };
23123
- const getAbrStrategy = async (options) => {
23124
- var _a, _b;
23125
- const streamType = options.url && getStreamType(options.url);
23126
- if (streamType === "rtm") {
23214
+ class HlsProtocol extends BaseProtocol {
23215
+ static get suffix() {
23216
+ return ".m3u8";
23217
+ }
23218
+ get protocolType() {
23219
+ return LiveUrlType.Hls;
23220
+ }
23221
+ get defaultFallbackStrategy() {
23127
23222
  return {};
23128
23223
  }
23129
- const abrOptions = streamType === "flv" ? (_a = options == null ? void 0 : options.flv) == null ? void 0 : _a.abr : (_b = options == null ? void 0 : options.hls) == null ? void 0 : _b.abr;
23130
- if (!abrOptions) {
23224
+ static canGenerateOtherProtocol() {
23225
+ return true;
23226
+ }
23227
+ static generateUrl(urls, {
23228
+ generateUrlFromOtherProtocol: generateUrlFromOtherProtocol2
23229
+ }) {
23230
+ if (urls[LiveUrlType.Hls]) {
23231
+ return urls[LiveUrlType.Hls];
23232
+ }
23233
+ if (urls[LiveUrlType.LLHls]) {
23234
+ return modifyPlaylistUrl(urls[LiveUrlType.LLHls], (url) => {
23235
+ return util.appendSearchParams(url, {
23236
+ fpkey_normal_hls: "1"
23237
+ });
23238
+ });
23239
+ }
23240
+ return generateUrlFromOtherProtocol2();
23241
+ }
23242
+ async canPlay() {
23243
+ return { canPlay: true };
23244
+ }
23245
+ shouldFallbackWhenStall() {
23246
+ return false;
23247
+ }
23248
+ async getProtocolStrategy(options) {
23249
+ return getHlsStrategy(options);
23250
+ }
23251
+ async getAbrStrategy(options) {
23252
+ var _a;
23253
+ const abrOptions = (_a = options == null ? void 0 : options.hls) == null ? void 0 : _a.abr;
23254
+ if (!abrOptions) {
23255
+ return {};
23256
+ }
23257
+ const abrPlugin = await load(DynamicModule.PluginAbr).catch(
23258
+ () => void 0
23259
+ );
23260
+ return {
23261
+ options: {
23262
+ hlsabr: {
23263
+ ...abrOptions,
23264
+ open: abrOptions.enable ?? true
23265
+ }
23266
+ },
23267
+ plugins: [abrPlugin == null ? void 0 : abrPlugin.HlsAbrPlugin]
23268
+ };
23269
+ }
23270
+ getDrmStrategy(options, player) {
23271
+ return getDrmStrategy(options, player);
23272
+ }
23273
+ }
23274
+ class HlsLowLatencyProtocol extends BaseProtocol {
23275
+ static get suffix() {
23276
+ return ".m3u8";
23277
+ }
23278
+ get protocolType() {
23279
+ return LiveUrlType.LLHls;
23280
+ }
23281
+ get defaultFallbackStrategy() {
23131
23282
  return {};
23132
23283
  }
23133
- const abrPlugin = await load(DynamicModule.PluginAbr).catch(() => void 0);
23284
+ static generateUrl(urls) {
23285
+ return urls[LiveUrlType.LLHls];
23286
+ }
23287
+ static canGenerateOtherProtocol() {
23288
+ return true;
23289
+ }
23290
+ async canPlay() {
23291
+ return { canPlay: true };
23292
+ }
23293
+ shouldFallbackWhenStall() {
23294
+ return false;
23295
+ }
23296
+ async getProtocolStrategy(options) {
23297
+ return getHlsStrategy(options);
23298
+ }
23299
+ getAbrStrategy() {
23300
+ return void 0;
23301
+ }
23302
+ getDrmStrategy() {
23303
+ return void 0;
23304
+ }
23305
+ }
23306
+ async function isRTMSupported() {
23307
+ const { RtmPlugin } = await load(DynamicModule.PluginRtm);
23308
+ return RtmPlugin.isSupported();
23309
+ }
23310
+ async function isRTMSupportCodec(codec = RTMCodec.H264) {
23311
+ const { RtmPlugin } = await load(DynamicModule.PluginRtm);
23312
+ if (codec === RTMCodec.H264)
23313
+ return RtmPlugin.isSupportedH264();
23314
+ return false;
23315
+ }
23316
+ const rtmStrategy = {
23317
+ options: {},
23318
+ module: DynamicModule.PluginRtm
23319
+ };
23320
+ const generateFallbackUrl = (url) => {
23321
+ if (sniffer$1.device === "pc") {
23322
+ return url.replace(".sdp", ".flv");
23323
+ } else {
23324
+ return url.replace(".sdp", ".m3u8");
23325
+ }
23326
+ };
23327
+ const getRtmStrategy = async (options, player, i18n) => {
23328
+ var _a, _b;
23329
+ let backupStrategy;
23330
+ let actualFallbackUrl = "";
23331
+ const { url, playlist } = options;
23332
+ const { fallbackUrl, enableRTMAutoTranscode, ...ret } = options.rtm || {};
23333
+ let { enableFallback = true } = options.rtm || {};
23334
+ if (playlist == null ? void 0 : playlist.length) {
23335
+ enableFallback = false;
23336
+ }
23337
+ const isRTMAutoTranscode = enableRTMAutoTranscode || ((_a = getUrlObject(url)) == null ? void 0 : _a.searchParams.get("enableRTMAutoTranscode")) === "true";
23338
+ if (enableFallback) {
23339
+ if (fallbackUrl) {
23340
+ actualFallbackUrl = fallbackUrl;
23341
+ } else if (isRTMAutoTranscode && url) {
23342
+ actualFallbackUrl = generateFallbackUrl(url);
23343
+ } else {
23344
+ console.warn(
23345
+ create(ErrorCode.EMPTY_RTM_FALLBACK_PARAMETER, i18n).message
23346
+ );
23347
+ }
23348
+ }
23349
+ const backupType = actualFallbackUrl && util.getStreamType(actualFallbackUrl);
23350
+ if (backupType === "flv" && util.isMseSupported(Codec.H264)) {
23351
+ backupStrategy = createFlvMseStrategy(options);
23352
+ } else if (backupType === "hls" && (sniffer$1.device !== "mobile" || ((_b = options == null ? void 0 : options.hls) == null ? void 0 : _b.enableMSE)) && util.isMseSupported(Codec.H264)) {
23353
+ backupStrategy = createHlsMseStrategy(options);
23354
+ }
23355
+ const [rtmCdn, backupCdn] = await Promise.all([
23356
+ load(rtmStrategy.module).then((module2) => {
23357
+ return module2.RtmPlugin;
23358
+ }).catch(() => void 0),
23359
+ backupStrategy && load(backupStrategy.module).then((module2) => {
23360
+ if ((backupStrategy == null ? void 0 : backupStrategy.module) === DynamicModule.PluginFlv) {
23361
+ return module2.FlvPlugin;
23362
+ } else if ((backupStrategy == null ? void 0 : backupStrategy.module) === DynamicModule.PluginHls) {
23363
+ return module2.HlsPlugin;
23364
+ }
23365
+ }).catch(() => void 0)
23366
+ ]);
23367
+ if (actualFallbackUrl) {
23368
+ const [RTMSupported, RTMSupportCodec] = await Promise.all([
23369
+ isRTMSupported(),
23370
+ isRTMSupportCodec()
23371
+ ]);
23372
+ if (!RTMSupported || !RTMSupportCodec) {
23373
+ if (player) {
23374
+ player.emit("degrade", {
23375
+ url: actualFallbackUrl,
23376
+ originRtmUrl: url,
23377
+ code: "NOT_SUPPORT",
23378
+ message: "not support rtm or h264",
23379
+ isRTMSupported: RTMSupported,
23380
+ isRTMSupportCodec: RTMSupportCodec
23381
+ });
23382
+ }
23383
+ return {
23384
+ options: {
23385
+ ...(backupStrategy == null ? void 0 : backupStrategy.options) || {},
23386
+ url: actualFallbackUrl,
23387
+ _RTMdegrade: {
23388
+ _originRtmUrl: url,
23389
+ _isRTMSupported: RTMSupported,
23390
+ _isRTMSupportCodec: RTMSupportCodec
23391
+ }
23392
+ },
23393
+ plugins: backupCdn ? [backupCdn] : []
23394
+ };
23395
+ }
23396
+ }
23134
23397
  return {
23135
23398
  options: {
23136
- [streamType === "flv" ? "abr" : "hlsabr"]: {
23137
- ...abrOptions,
23138
- open: abrOptions.enable ?? true
23399
+ ...(backupStrategy == null ? void 0 : backupStrategy.options) || {},
23400
+ url: enableRTMAutoTranscode ? util.appendSearchParams(url, { enableRTMAutoTranscode: "true" }) : void 0,
23401
+ _RTMdegrade: void 0,
23402
+ rts: {
23403
+ retryCount: 0,
23404
+ ...ret,
23405
+ backupURL: actualFallbackUrl,
23406
+ backupConstruct: backupCdn
23139
23407
  }
23140
23408
  },
23141
- plugins: [
23142
- streamType === "flv" ? abrPlugin == null ? void 0 : abrPlugin.AbrPlugin : abrPlugin == null ? void 0 : abrPlugin.HlsAbrPlugin
23143
- ]
23409
+ plugins: rtmCdn ? [rtmCdn] : []
23144
23410
  };
23145
23411
  };
23412
+ class RtmProtocol extends BaseProtocol {
23413
+ static get suffix() {
23414
+ return ".sdp";
23415
+ }
23416
+ get protocolType() {
23417
+ return LiveUrlType.Rtm;
23418
+ }
23419
+ get defaultFallbackStrategy() {
23420
+ return { [FallbackKind.Error]: { shouldFallback: () => true } };
23421
+ }
23422
+ static canGenerateOtherProtocol(options) {
23423
+ var _a;
23424
+ return (_a = options.rtm) == null ? void 0 : _a.enableRTMAutoTranscode;
23425
+ }
23426
+ static generateUrl(urls, {
23427
+ generateUrlFromOtherProtocol: generateUrlFromOtherProtocol2,
23428
+ options
23429
+ }) {
23430
+ var _a;
23431
+ if (urls[LiveUrlType.Rtm]) {
23432
+ return urls[LiveUrlType.Rtm];
23433
+ }
23434
+ if ((_a = options.rtm) == null ? void 0 : _a.enableRTMAutoTranscode) {
23435
+ return generateUrlFromOtherProtocol2();
23436
+ }
23437
+ console.warn("生成 rtm 地址失败。请传入 rtm 播放地址,或开启自动转码");
23438
+ return;
23439
+ }
23440
+ async canPlay() {
23441
+ const [isSupported, isSupportCodec] = await Promise.all([
23442
+ isRTMSupported(),
23443
+ isRTMSupportCodec()
23444
+ ]);
23445
+ return {
23446
+ canPlay: isSupported && isSupportCodec
23447
+ };
23448
+ }
23449
+ shouldFallbackWhenStall() {
23450
+ return false;
23451
+ }
23452
+ async getProtocolStrategy(options, {
23453
+ player,
23454
+ i18n,
23455
+ enableSelector
23456
+ }) {
23457
+ this.protocolStrategy = await getRtmStrategy(
23458
+ enableSelector ? {
23459
+ options,
23460
+ rtm: {
23461
+ ...options.rtm,
23462
+ enableFallback: false
23463
+ }
23464
+ } : options,
23465
+ player,
23466
+ i18n
23467
+ );
23468
+ return this.protocolStrategy;
23469
+ }
23470
+ getAbrStrategy() {
23471
+ return void 0;
23472
+ }
23473
+ getDrmStrategy() {
23474
+ return void 0;
23475
+ }
23476
+ }
23477
+ class ProtocolSelector {
23478
+ constructor({ queue, streams, options }) {
23479
+ // 链开始的类
23480
+ // start?: AbstractProtocol;
23481
+ // 链结束的类,也是当前正在播放的类型
23482
+ __publicField(this, "current");
23483
+ // 降级顺序
23484
+ __publicField(this, "_queue");
23485
+ __publicField(this, "_streams");
23486
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
23487
+ // @ts-ignore
23488
+ __publicField(this, "_options");
23489
+ this._queue = queue;
23490
+ this._streams = streams;
23491
+ this._options = options;
23492
+ this.current = this._getStartProtocol();
23493
+ }
23494
+ // 获取最终返回的播放类型和参数。
23495
+ async getProtocol() {
23496
+ if (!this.current) {
23497
+ return;
23498
+ }
23499
+ const { canPlay } = await this.current.canPlay() ?? {};
23500
+ if (canPlay) {
23501
+ return this.current;
23502
+ }
23503
+ this.next();
23504
+ return this.getProtocol();
23505
+ }
23506
+ // 降级时,将指针指到上次结束的位置
23507
+ next() {
23508
+ var _a;
23509
+ this.current = (_a = this.current) == null ? void 0 : _a.nextProtocol;
23510
+ }
23511
+ // 生成责任链
23512
+ _getStartProtocol() {
23513
+ let nextProtocol;
23514
+ for (let index = this._queue.length - 1; index >= 0; index--) {
23515
+ const type = this._queue[index];
23516
+ const protocol = this._streams[type];
23517
+ if (protocol) {
23518
+ if (nextProtocol) {
23519
+ nextProtocol.preProtocol = protocol;
23520
+ protocol.nextProtocol = nextProtocol;
23521
+ }
23522
+ nextProtocol = protocol;
23523
+ }
23524
+ }
23525
+ return nextProtocol;
23526
+ }
23527
+ }
23528
+ const _LowLatencySelector = class extends ProtocolSelector {
23529
+ // 目前默认传入了默认的低延迟选择顺序,
23530
+ // 也可以支持自定义配置
23531
+ constructor({
23532
+ streams,
23533
+ options
23534
+ }) {
23535
+ super({
23536
+ queue: _LowLatencySelector.queue,
23537
+ streams,
23538
+ options
23539
+ });
23540
+ }
23541
+ };
23542
+ let LowLatencySelector = _LowLatencySelector;
23543
+ __publicField(LowLatencySelector, "queue", [
23544
+ LiveUrlType.Rtm,
23545
+ LiveUrlType.LLFlv,
23546
+ LiveUrlType.Flv,
23547
+ LiveUrlType.LLHls,
23548
+ LiveUrlType.Hls
23549
+ ]);
23550
+ class CustomSelector extends ProtocolSelector {
23551
+ constructor({
23552
+ streams,
23553
+ options
23554
+ }) {
23555
+ var _a;
23556
+ super({
23557
+ queue: (_a = options.fallback) == null ? void 0 : _a.fallbackOrder,
23558
+ streams,
23559
+ options
23560
+ });
23561
+ }
23562
+ }
23563
+ __publicField(CustomSelector, "queue");
23564
+ const _ProtocolManager = class {
23565
+ constructor(options) {
23566
+ __publicField(this, "_options");
23567
+ __publicField(this, "_selector");
23568
+ __publicField(this, "_protocol");
23569
+ __publicField(this, "_playlistMap", {});
23570
+ this._options = options;
23571
+ this._init({
23572
+ url: options.url,
23573
+ playlist: options.playlist
23574
+ });
23575
+ }
23576
+ get enableSelector() {
23577
+ return !!this._selector;
23578
+ }
23579
+ get protocol() {
23580
+ return this._protocol;
23581
+ }
23582
+ get playlist() {
23583
+ var _a;
23584
+ return ((_a = this._protocol) == null ? void 0 : _a.protocolType) && this._playlistMap ? this._playlistMap[this._protocol.protocolType] : void 0;
23585
+ }
23586
+ static async create(options) {
23587
+ const protocolManager = new _ProtocolManager(options);
23588
+ await protocolManager.getProtocol();
23589
+ return protocolManager;
23590
+ }
23591
+ static _generateProtocolMap(queue, splittedPlaylist, options) {
23592
+ const protocolMap = {};
23593
+ const playlistMap = {};
23594
+ const baseGenerateProtocol = queue.find((type) => {
23595
+ return _ProtocolManager._protocolMap[type].canGenerateOtherProtocol(options) && splittedPlaylist[type];
23596
+ });
23597
+ queue.forEach((protocolType) => {
23598
+ var _a;
23599
+ const playlist = ((_a = _ProtocolManager._protocolMap[protocolType]) == null ? void 0 : _a.generateUrl(
23600
+ splittedPlaylist,
23601
+ {
23602
+ generateUrlFromOtherProtocol: () => {
23603
+ if (!baseGenerateProtocol) {
23604
+ return;
23605
+ }
23606
+ return generateUrlFromOtherProtocol(
23607
+ splittedPlaylist[baseGenerateProtocol],
23608
+ _ProtocolManager._protocolMap[baseGenerateProtocol].suffix,
23609
+ _ProtocolManager._protocolMap[protocolType].suffix
23610
+ );
23611
+ },
23612
+ options
23613
+ }
23614
+ )) ?? splittedPlaylist[protocolType];
23615
+ if (playlist) {
23616
+ playlistMap[protocolType] = playlist;
23617
+ protocolMap[protocolType] = new _ProtocolManager._protocolMap[protocolType](options);
23618
+ }
23619
+ });
23620
+ return { protocolMap, playlistMap };
23621
+ }
23622
+ async getProtocol() {
23623
+ if (this._selector) {
23624
+ this._protocol = await this._selector.getProtocol();
23625
+ }
23626
+ return this._protocol;
23627
+ }
23628
+ async update({
23629
+ url,
23630
+ playlist
23631
+ }) {
23632
+ this._options = { ...this._options, url, playlist };
23633
+ this._init({
23634
+ url,
23635
+ playlist
23636
+ });
23637
+ await this.getProtocol();
23638
+ }
23639
+ async next() {
23640
+ if (!this._selector) {
23641
+ return;
23642
+ }
23643
+ this._selector.next();
23644
+ await this.getProtocol();
23645
+ return this._protocol;
23646
+ }
23647
+ async getStrategy(player, i18n) {
23648
+ var _a, _b, _c;
23649
+ const protocol = this._protocol;
23650
+ const [typeStrategy, drmStrategy, abrStrategy] = await Promise.all([
23651
+ protocol == null ? void 0 : protocol.getProtocolStrategy(this._options, {
23652
+ player,
23653
+ i18n,
23654
+ enableSelector: !!this._selector
23655
+ }),
23656
+ (_a = protocol == null ? void 0 : protocol.getDrmStrategy) == null ? void 0 : _a.call(protocol, this._options, player),
23657
+ (_b = protocol == null ? void 0 : protocol.getAbrStrategy) == null ? void 0 : _b.call(protocol, this._options)
23658
+ ]);
23659
+ const { options, plugins } = typeStrategy ?? {};
23660
+ const { options: drmOptions, plugins: drmPlugins } = drmStrategy ?? {};
23661
+ const { options: abrOptions, plugins: abrPlugins } = abrStrategy ?? {};
23662
+ return {
23663
+ options: Object.assign({}, options, drmOptions, abrOptions),
23664
+ plugins: [
23665
+ ...plugins ?? [],
23666
+ ...drmPlugins ?? [],
23667
+ ...abrPlugins ?? []
23668
+ ],
23669
+ useSrc: !((_c = typeStrategy == null ? void 0 : typeStrategy.plugins) == null ? void 0 : _c.length),
23670
+ protocol: protocol == null ? void 0 : protocol.protocolType
23671
+ };
23672
+ }
23673
+ _init({
23674
+ url,
23675
+ playlist
23676
+ }) {
23677
+ var _a;
23678
+ if (playlist) {
23679
+ const splittedPlaylist = splitPlaylist(playlist);
23680
+ const Selector = this._options.latencyMode === "low" ? LowLatencySelector : CustomSelector;
23681
+ const queue = (Selector == null ? void 0 : Selector.queue) ?? ((_a = this._options.fallback) == null ? void 0 : _a.fallbackOrder);
23682
+ if (queue == null ? void 0 : queue.length) {
23683
+ const { protocolMap, playlistMap } = _ProtocolManager._generateProtocolMap(
23684
+ queue,
23685
+ splittedPlaylist,
23686
+ this._options
23687
+ );
23688
+ this._playlistMap = playlistMap;
23689
+ this._selector = new Selector({
23690
+ streams: protocolMap,
23691
+ options: this._options
23692
+ });
23693
+ return;
23694
+ }
23695
+ this._playlistMap = splittedPlaylist;
23696
+ this._initSingleProtocol(Object.keys(splittedPlaylist)[0]);
23697
+ } else if (url) {
23698
+ this._initSingleProtocol(getStreamType(url));
23699
+ }
23700
+ }
23701
+ _initSingleProtocol(protocol) {
23702
+ if (protocol) {
23703
+ this._protocol = new _ProtocolManager._protocolMap[protocol](
23704
+ this._options
23705
+ );
23706
+ }
23707
+ }
23708
+ };
23709
+ let ProtocolManager = _ProtocolManager;
23710
+ __publicField(ProtocolManager, "_protocolMap", {
23711
+ [LiveUrlType.Flv]: FlvProtocol,
23712
+ [LiveUrlType.LLFlv]: FlvLowLatencyProtocol,
23713
+ [LiveUrlType.Hls]: HlsProtocol,
23714
+ [LiveUrlType.LLHls]: HlsLowLatencyProtocol,
23715
+ [LiveUrlType.Rtm]: RtmProtocol
23716
+ });
23717
+ class Fallback {
23718
+ constructor() {
23719
+ __publicField(this, "player");
23720
+ __publicField(this, "protocolManager");
23721
+ __publicField(this, "beforeFallbackError", async (error2) => {
23722
+ var _a, _b, _c, _d, _e, _f;
23723
+ if (!((_b = (_a = this.protocolManager) == null ? void 0 : _a.protocol) == null ? void 0 : _b.shouldFallbackWhenError({ error: error2 })) || !((_d = (_c = this.protocolManager) == null ? void 0 : _c.protocol) == null ? void 0 : _d.nextProtocol)) {
23724
+ return { canEmitError: true };
23725
+ }
23726
+ const nextProtocol = await ((_e = this.protocolManager) == null ? void 0 : _e.next());
23727
+ if (!nextProtocol || !((_f = this.protocolManager) == null ? void 0 : _f.playlist)) {
23728
+ return { canEmitError: true };
23729
+ }
23730
+ this.fallback();
23731
+ return { canEmitError: false };
23732
+ });
23733
+ }
23734
+ initErrorFallback(player, protocolManager) {
23735
+ this.player = player;
23736
+ this.protocolManager = protocolManager;
23737
+ }
23738
+ async fallback() {
23739
+ var _a, _b, _c, _d;
23740
+ if (!((_a = this.protocolManager) == null ? void 0 : _a.playlist))
23741
+ return;
23742
+ const definition = (_b = this.player) == null ? void 0 : _b.definition;
23743
+ const source = (_c = this.player) == null ? void 0 : _c.source;
23744
+ (_d = this.player) == null ? void 0 : _d.updatePlaylist(
23745
+ this.protocolManager.playlist,
23746
+ {
23747
+ definition,
23748
+ source
23749
+ },
23750
+ false
23751
+ );
23752
+ }
23753
+ }
23754
+ const fallback = new Fallback();
23146
23755
  VeI18n.extend([
23147
23756
  {
23148
23757
  LANG: "zh-cn",
@@ -23174,6 +23783,7 @@ var __publicField = (obj, key, value) => {
23174
23783
  */
23175
23784
  constructor(options) {
23176
23785
  super(options);
23786
+ __publicField(this, "_protocolManager");
23177
23787
  }
23178
23788
  /** {zh}
23179
23789
  * @brief 获取已经播放的时长,不包含暂停和等待时间,单位为秒。
@@ -23364,6 +23974,13 @@ var __publicField = (obj, key, value) => {
23364
23974
  var _a, _b, _c;
23365
23975
  return (_c = (_b = (_a = this._player) == null ? void 0 : _a.plugins) == null ? void 0 : _b.hls) == null ? void 0 : _c.getStats();
23366
23976
  }
23977
+ async updatePlaylist(playlist, target, needUpdateProtocol = true) {
23978
+ var _a;
23979
+ if (needUpdateProtocol) {
23980
+ await ((_a = this._protocolManager) == null ? void 0 : _a.update({ playlist }));
23981
+ }
23982
+ return super.updatePlaylist(playlist, target);
23983
+ }
23367
23984
  }
23368
23985
  async function createLivePlayer(options) {
23369
23986
  var _a, _b, _c, _d;
@@ -23382,10 +23999,16 @@ var __publicField = (obj, key, value) => {
23382
23999
  ...options,
23383
24000
  plugins: [...LIVE_DEFAULT_PLUGINS, ...options.plugins ?? []]
23384
24001
  };
24002
+ const protocolManager = await ProtocolManager.create(finalOptions);
24003
+ if (!options.url && !(protocolManager == null ? void 0 : protocolManager.playlist)) {
24004
+ throw create(ErrorCode.INVALID_PARAMETER, i18n);
24005
+ }
23385
24006
  player = await VePlayerBase.create(
23386
24007
  {
23387
24008
  ...LIVE_DEFAULT_OPTIONS,
23388
24009
  ...finalOptions,
24010
+ playlist: protocolManager == null ? void 0 : protocolManager.playlist,
24011
+ beforeFallbackError: fallback.beforeFallbackError,
23389
24012
  isLive: true,
23390
24013
  i18nManager: i18n,
23391
24014
  preProcessUrl: (url) => {
@@ -23397,44 +24020,16 @@ var __publicField = (obj, key, value) => {
23397
24020
  };
23398
24021
  },
23399
24022
  async preparePlugins(url) {
23400
- var _a2;
23401
- const [typeStrategy, drmStrategy, abrStrategy] = await Promise.all([
23402
- getTypeStrategy(
23403
- {
23404
- ...finalOptions,
23405
- url
23406
- },
23407
- player,
23408
- i18n
23409
- ),
23410
- getDrmStrategy(
23411
- {
23412
- ...finalOptions,
23413
- url
23414
- },
23415
- player
23416
- ),
23417
- getAbrStrategy({
23418
- ...finalOptions,
23419
- url
23420
- })
23421
- ]);
23422
- const { options: options2, plugins } = typeStrategy ?? {};
23423
- const { options: drmOptions, plugins: drmPlugins } = drmStrategy ?? {};
23424
- const { options: abrOptions, plugins: abrPlugins } = abrStrategy ?? {};
23425
- return {
23426
- options: Object.assign({}, options2, drmOptions, abrOptions),
23427
- plugins: [
23428
- ...plugins ?? [],
23429
- ...drmPlugins ?? [],
23430
- ...abrPlugins ?? []
23431
- ],
23432
- useSrc: !((_a2 = typeStrategy.plugins) == null ? void 0 : _a2.length)
23433
- };
24023
+ if (!protocolManager.enableSelector) {
24024
+ await protocolManager.update({ url });
24025
+ }
24026
+ return protocolManager.getStrategy(player, i18n);
23434
24027
  }
23435
24028
  },
23436
24029
  VePlayerLive
23437
24030
  );
24031
+ player._protocolManager = protocolManager;
24032
+ fallback.initErrorFallback(player, protocolManager);
23438
24033
  if (player) {
23439
24034
  const RTMDegrade = (_d = (_c = player == null ? void 0 : player._player) == null ? void 0 : _c.config) == null ? void 0 : _d._RTMdegrade;
23440
24035
  if (RTMDegrade) {
@@ -23473,7 +24068,7 @@ var __publicField = (obj, key, value) => {
23473
24068
  exports2.createLivePlayer = createLivePlayer;
23474
24069
  exports2.isFLVSupported = isFLVSupported;
23475
24070
  exports2.isMMSSupported = isMMSSupported$1;
23476
- exports2.isMseSupported = isMseSupported$1;
24071
+ exports2.isMseSupported = isMseSupported$2;
23477
24072
  exports2.isRTMSupportCodec = isRTMSupportCodec;
23478
24073
  exports2.isRTMSupported = isRTMSupported;
23479
24074
  exports2.isSoftDecodeSupported = isSoftDecodeSupported;