@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.
@@ -50,235 +50,6 @@ function create(errorCode, i18n) {
50
50
  i18n
51
51
  );
52
52
  }
53
- const DynamicModule$4 = window["VePlayer"].DynamicModule;
54
- const load$5 = window["VePlayer"].load;
55
- async function isRTMSupported() {
56
- const { RtmPlugin } = await load$5(DynamicModule$4.PluginRtm);
57
- return RtmPlugin.isSupported();
58
- }
59
- async function isRTMSupportCodec(codec = RTMCodec.H264) {
60
- const { RtmPlugin } = await load$5(DynamicModule$4.PluginRtm);
61
- if (codec === RTMCodec.H264)
62
- return RtmPlugin.isSupportedH264();
63
- return false;
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
- };
79
- const strategy$2 = window["VePlayer"].strategy;
80
- const util$6 = window["VePlayer"].util;
81
- const DynamicModule$3 = window["VePlayer"].DynamicModule;
82
- const load$4 = window["VePlayer"].load;
83
- const Codec$3 = window["VePlayer"].Codec;
84
- const Sniffer$4 = window["VePlayer"].Sniffer;
85
- const rtmStrategy = {
86
- options: {},
87
- module: DynamicModule$3.PluginRtm
88
- };
89
- const generateFallbackUrl = (url) => {
90
- if (Sniffer$4.device === "pc") {
91
- return url.replace(".sdp", ".flv");
92
- } else {
93
- return url.replace(".sdp", ".m3u8");
94
- }
95
- };
96
- const getRtmStrategy = async (options, player, i18n) => {
97
- var _a, _b;
98
- let backupStrategy;
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
- }
118
- const backupType = actualFallbackUrl && util$6.getStreamType(actualFallbackUrl);
119
- if (backupType === "flv" && util$6.isMseSupported(Codec$3.H264)) {
120
- backupStrategy = strategy$2.createFlvMseStrategy(options);
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)) {
122
- backupStrategy = strategy$2.createHlsMseStrategy(options);
123
- }
124
- const [rtmCdn, backupCdn] = await Promise.all([
125
- load$4(rtmStrategy.module).then((module) => {
126
- return module.RtmPlugin;
127
- }).catch(() => void 0),
128
- backupStrategy && load$4(backupStrategy.module).then((module) => {
129
- if ((backupStrategy == null ? void 0 : backupStrategy.module) === DynamicModule$3.PluginFlv) {
130
- return module.FlvPlugin;
131
- } else if ((backupStrategy == null ? void 0 : backupStrategy.module) === DynamicModule$3.PluginHls) {
132
- return module.HlsPlugin;
133
- }
134
- }).catch(() => void 0)
135
- ]);
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
- };
164
- }
165
- }
166
- return {
167
- options: {
168
- ...(backupStrategy == null ? void 0 : backupStrategy.options) || {},
169
- url: enableRTMAutoTranscode ? util$6.appendSearchParams(url, { enableRTMAutoTranscode: "true" }) : void 0,
170
- _RTMdegrade: void 0,
171
- rts: {
172
- retryCount: 0,
173
- ...ret,
174
- backupURL: actualFallbackUrl,
175
- backupConstruct: backupCdn
176
- }
177
- },
178
- plugins: rtmCdn ? [rtmCdn] : []
179
- };
180
- };
181
- const Sniffer$3 = window["VePlayer"].Sniffer;
182
- var DrmType = /* @__PURE__ */ ((DrmType2) => {
183
- DrmType2["Fairplay"] = "fairplay";
184
- return DrmType2;
185
- })(DrmType || {});
186
- function getDrmType(drm) {
187
- if ((drm == null ? void 0 : drm.fairplay) && (Sniffer$3.browser === "safari" || Sniffer$3.os.isIos)) {
188
- return "fairplay";
189
- }
190
- return;
191
- }
192
- function isMseSupportedWithDrm({
193
- drm,
194
- streamType
195
- }) {
196
- const drmType = getDrmType(drm);
197
- if (!drmType) {
198
- return true;
199
- }
200
- if (drmType === "fairplay" && streamType === "hls") {
201
- return false;
202
- }
203
- return true;
204
- }
205
- const Sniffer$2 = window["VePlayer"].Sniffer;
206
- const Codec$2 = window["VePlayer"].Codec;
207
- const util$5 = window["VePlayer"].util;
208
- const { isMMSSupported: isMMSSupported$1, isMseSupported: isMseSupported$1 } = util$5;
209
- function enableMMS() {
210
- return Sniffer$2.os.isIos;
211
- }
212
- function isFLVSupported(codec = Codec$2.H264) {
213
- const isMediaSourceSupported = enableMMS() ? isMMSSupported$1 : isMseSupported$1;
214
- return isMediaSourceSupported(codec);
215
- }
216
- const strategy$1 = window["VePlayer"].strategy;
217
- const load$3 = window["VePlayer"].load;
218
- const Codec$1 = window["VePlayer"].Codec;
219
- const util$4 = window["VePlayer"].util;
220
- const { appendSearchParams } = util$4;
221
- const getFlvStrategy = async (options) => {
222
- var _a, _b, _c, _d, _e, _f;
223
- let mseStrategy;
224
- let softStrategy;
225
- const enableLowLatency = (_a = options == null ? void 0 : options.flv) == null ? void 0 : _a.enableLowLatency;
226
- const enableFrameChasing = ((_c = (_b = options == null ? void 0 : options.flv) == null ? void 0 : _b.lowLatency) == null ? void 0 : _c.enableFrameChasing) ?? true;
227
- const abrPts = ((_e = (_d = options == null ? void 0 : options.flv) == null ? void 0 : _d.lowLatency) == null ? void 0 : _e.abrPts) ?? "-800";
228
- const codec = await strategy$1.getCodec(options);
229
- const isSoftDecode = await strategy$1.isSoftDecode(options, codec);
230
- if (isSoftDecode) {
231
- softStrategy = codec === Codec$1.H265 ? strategy$1.createSoftDecodeH265Strategy() : strategy$1.createSoftDecodeH264Strategy();
232
- mseStrategy = strategy$1.createFlvMseStrategy(options);
233
- }
234
- if (codec === "unknown" ? isFLVSupported(Codec$1.H264) : isFLVSupported(codec)) {
235
- mseStrategy = enableMMS() ? strategy$1.createFlvMssStrategy(options) : strategy$1.createFlvMseStrategy(options);
236
- }
237
- if (!mseStrategy && !softStrategy) {
238
- return {};
239
- }
240
- const [mseModule, softModule] = await Promise.all([
241
- (mseStrategy == null ? void 0 : mseStrategy.module) && load$3(mseStrategy.module).catch(() => void 0),
242
- (softStrategy == null ? void 0 : softStrategy.module) && load$3(softStrategy.module).catch(() => void 0)
243
- ]);
244
- (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));
245
- const combineOptions = strategy$1.combineOptions([mseStrategy, softStrategy]);
246
- const plugins = [];
247
- if (enableLowLatency) {
248
- combineOptions.url = appendSearchParams(options.url, { abr_pts: abrPts });
249
- }
250
- if (mseModule) {
251
- plugins.push(mseModule.FlvPlugin);
252
- if (enableLowLatency && enableFrameChasing) {
253
- plugins.push(mseModule.Adaptive);
254
- }
255
- }
256
- return {
257
- options: combineOptions,
258
- plugins
259
- };
260
- };
261
- const util$3 = window["VePlayer"].util;
262
- const strategy = window["VePlayer"].strategy;
263
- const getTypeStrategy = async (options, player, i18n) => {
264
- const type = options.url ? util$3.getStreamType(options.url) : "";
265
- if (!type || type === "unknown") {
266
- return { options: {}, plugins: [] };
267
- }
268
- if (type === "rtm") {
269
- return await getRtmStrategy(options, player, i18n);
270
- }
271
- if (type === "flv") {
272
- return await getFlvStrategy(options);
273
- }
274
- if (type === "hls") {
275
- if (!isMseSupportedWithDrm({ drm: options.drm, streamType: type })) {
276
- return { options: {}, plugins: [] };
277
- }
278
- return await strategy.getHlsStrategy(options);
279
- }
280
- return { options: {}, plugins: [] };
281
- };
282
53
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
283
54
  function getDefaultExportFromCjs(x2) {
284
55
  return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
@@ -424,7 +195,7 @@ function RefreshIcon() {
424
195
  }
425
196
  var refresh = "";
426
197
  const Plugin$3 = window["VePlayer"].Plugin;
427
- const Sniffer$1 = window["VePlayer"].Sniffer;
198
+ const Sniffer$5 = window["VePlayer"].Sniffer;
428
199
  const XGEvents = window["VePlayer"].XGEvents;
429
200
  const { POSITIONS: POSITIONS$1 } = Plugin$3;
430
201
  class Refresh extends Plugin$3 {
@@ -488,7 +259,7 @@ class Refresh extends Plugin$3 {
488
259
  }
489
260
  _initEvents() {
490
261
  this._handleRefresh = debounce$1(this._handleRefresh.bind(this), 200);
491
- const event2 = Sniffer$1.device === "mobile" ? "touchend" : "click";
262
+ const event2 = Sniffer$5.device === "mobile" ? "touchend" : "click";
492
263
  this.bind(event2, this._handleRefresh);
493
264
  this.show();
494
265
  }
@@ -2969,7 +2740,7 @@ function v4(options, buf, offset) {
2969
2740
  }
2970
2741
  return unsafeStringify(rnds);
2971
2742
  }
2972
- const util$2 = window["VePlayer"].util;
2743
+ const util$7 = window["VePlayer"].util;
2973
2744
  const DEVICE_ID_KEY = "veplayer_live_device_id";
2974
2745
  const USER_ID_Key = "veplayer_live_user_id";
2975
2746
  const genRandomID2 = (length) => {
@@ -2996,12 +2767,12 @@ const getUserId2 = () => {
2996
2767
  return userId;
2997
2768
  };
2998
2769
  const generateUrlWithSessionId = (url) => {
2999
- const urlObject = util$2.getUrlObject(url);
2770
+ const urlObject = util$7.getUrlObject(url);
3000
2771
  if (!urlObject) {
3001
2772
  return url ?? "";
3002
2773
  }
3003
2774
  if (!(urlObject == null ? void 0 : urlObject.searchParams.get("_session_id"))) {
3004
- return util$2.appendSearchParams(url, { _session_id: generateSessionId() });
2775
+ return util$7.appendSearchParams(url, { _session_id: generateSessionId() });
3005
2776
  }
3006
2777
  return url;
3007
2778
  };
@@ -3190,7 +2961,7 @@ function getSoftDecodeRow(data) {
3190
2961
  };
3191
2962
  }
3192
2963
  var infoPanel = "";
3193
- const util$1 = window["VePlayer"].util;
2964
+ const util$6 = window["VePlayer"].util;
3194
2965
  const Plugin$1 = window["VePlayer"].Plugin;
3195
2966
  const XGUtil = window["VePlayer"].XGUtil;
3196
2967
  class InfoPanel extends Plugin$1 {
@@ -3210,7 +2981,7 @@ class InfoPanel extends Plugin$1 {
3210
2981
  };
3211
2982
  }
3212
2983
  get _streamType() {
3213
- return util$1.getStreamType(this.player.config.url);
2984
+ return util$6.getStreamType(this.player.config.url);
3214
2985
  }
3215
2986
  afterCreate() {
3216
2987
  this._playPlugin = this.player.plugins[this._streamType];
@@ -3385,39 +3156,6 @@ const ZH_CN$1 = {
3385
3156
  DECODE_INFO: "软解信息",
3386
3157
  REFRESH: "刷新"
3387
3158
  };
3388
- const DynamicModule$2 = window["VePlayer"].DynamicModule;
3389
- const load$2 = window["VePlayer"].load;
3390
- const getDrmStrategy = async (options, player) => {
3391
- var _a;
3392
- const drmType = getDrmType(options.drm);
3393
- if (options.url && drmType === DrmType.Fairplay) {
3394
- try {
3395
- const { getDrmConfig, ...originFairplayConfig } = ((_a = options == null ? void 0 : options.drm) == null ? void 0 : _a.fairplay) ?? {};
3396
- const [drmPlugin, drmConfig] = await Promise.all([
3397
- load$2(DynamicModule$2.PluginDrm).then((module) => module.DrmPlugin).catch(() => void 0),
3398
- getDrmConfig == null ? void 0 : getDrmConfig({
3399
- url: options.url
3400
- })
3401
- ]);
3402
- const fairplayDrmConfig = Object.assign(
3403
- {},
3404
- originFairplayConfig,
3405
- options == null ? void 0 : options.drm,
3406
- drmConfig
3407
- );
3408
- drmConfig && (player == null ? void 0 : player.updateDrmConfig(drmConfig));
3409
- return {
3410
- options: {
3411
- drm: fairplayDrmConfig
3412
- },
3413
- plugins: drmPlugin ? [drmPlugin] : []
3414
- };
3415
- } catch (error2) {
3416
- console.log(error2);
3417
- }
3418
- }
3419
- return {};
3420
- };
3421
3159
  var FUNC_ERROR_TEXT = "Expected a function";
3422
3160
  var PLACEHOLDER = "__lodash_placeholder__";
3423
3161
  var BIND_FLAG = 1, BIND_KEY_FLAG = 2, CURRY_BOUND_FLAG = 4, CURRY_FLAG = 8, CURRY_RIGHT_FLAG = 16, PARTIAL_FLAG = 32, PARTIAL_RIGHT_FLAG = 64, ARY_FLAG = 128, REARG_FLAG = 256, FLIP_FLAG = 512;
@@ -3907,6 +3645,20 @@ function identity(value) {
3907
3645
  curry.placeholder = {};
3908
3646
  var lodash_curry = curry;
3909
3647
  var curry$1 = /* @__PURE__ */ getDefaultExportFromCjs(lodash_curry);
3648
+ const getUrlObject = (url) => {
3649
+ if (!url) {
3650
+ return;
3651
+ }
3652
+ const withoutProtocol = url.startsWith("//");
3653
+ if (withoutProtocol) {
3654
+ url = location.protocol + url;
3655
+ }
3656
+ try {
3657
+ return new URL(url);
3658
+ } catch (error2) {
3659
+ return;
3660
+ }
3661
+ };
3910
3662
  const isType = curry$1(function(suffix, url) {
3911
3663
  return url == null ? void 0 : url.split("?")[0].toLowerCase().includes(suffix);
3912
3664
  });
@@ -3933,31 +3685,916 @@ function getStreamType(url) {
3933
3685
  }
3934
3686
  return "unknown";
3935
3687
  }
3936
- const DynamicModule$1 = window["VePlayer"].DynamicModule;
3937
- const load$1 = window["VePlayer"].load;
3938
- const getAbrStrategy = async (options) => {
3939
- var _a, _b;
3940
- const streamType = options.url && getStreamType(options.url);
3941
- if (streamType === "rtm") {
3942
- return {};
3943
- }
3944
- 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;
3945
- if (!abrOptions) {
3946
- return {};
3947
- }
3948
- const abrPlugin = await load$1(DynamicModule$1.PluginAbr).catch(() => void 0);
3949
- return {
3950
- options: {
3951
- [streamType === "flv" ? "abr" : "hlsabr"]: {
3952
- ...abrOptions,
3953
- open: abrOptions.enable ?? true
3954
- }
3955
- },
3956
- plugins: [
3957
- streamType === "flv" ? abrPlugin == null ? void 0 : abrPlugin.AbrPlugin : abrPlugin == null ? void 0 : abrPlugin.HlsAbrPlugin
3958
- ]
3959
- };
3688
+ const LiveUrlType = {
3689
+ Hls: "hls",
3690
+ LLHls: "ll-hls",
3691
+ Flv: "flv",
3692
+ Rtm: "rtm",
3693
+ LLFlv: "ll-flv"
3960
3694
  };
3695
+ const Sniffer$4 = window["VePlayer"].Sniffer;
3696
+ const Codec$4 = window["VePlayer"].Codec;
3697
+ const util$5 = window["VePlayer"].util;
3698
+ const { isMMSSupported: isMMSSupported$1, isMseSupported: isMseSupported$2 } = util$5;
3699
+ function enableMMS() {
3700
+ return Sniffer$4.os.isIos;
3701
+ }
3702
+ function isFLVSupported(codec = Codec$4.H264) {
3703
+ const isMediaSourceSupported = enableMMS() ? isMMSSupported$1 : isMseSupported$2;
3704
+ return isMediaSourceSupported(codec);
3705
+ }
3706
+ var FallbackKind = /* @__PURE__ */ ((FallbackKind2) => {
3707
+ FallbackKind2["Error"] = "Error";
3708
+ FallbackKind2["Stall"] = "Stall";
3709
+ return FallbackKind2;
3710
+ })(FallbackKind || {});
3711
+ class BaseProtocol {
3712
+ constructor(options) {
3713
+ // 下一个 protocol 类
3714
+ __publicField(this, "nextProtocol");
3715
+ __publicField(this, "preProtocol");
3716
+ __publicField(this, "protocolStrategy");
3717
+ __publicField(this, "_fallback");
3718
+ this._fallback = options.fallback;
3719
+ }
3720
+ _getKindFallbackStrategy(kind) {
3721
+ var _a, _b, _c, _d, _e, _f, _g;
3722
+ 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]);
3723
+ }
3724
+ // eslint-disable-next-line @typescript-eslint/member-ordering
3725
+ get errorFallbackStrategy() {
3726
+ return this._getKindFallbackStrategy(
3727
+ "Error"
3728
+ /* Error */
3729
+ );
3730
+ }
3731
+ // eslint-disable-next-line @typescript-eslint/member-ordering
3732
+ get stallFallbackStrategy() {
3733
+ return this._getKindFallbackStrategy(
3734
+ "Stall"
3735
+ /* Stall */
3736
+ );
3737
+ }
3738
+ // eslint-disable-next-line @typescript-eslint/member-ordering
3739
+ shouldFallbackWhenError(params) {
3740
+ var _a, _b, _c;
3741
+ if ((_a = this.errorFallbackStrategy) == null ? void 0 : _a.shouldFallback) {
3742
+ return (_b = this.errorFallbackStrategy) == null ? void 0 : _b.shouldFallback(
3743
+ this.protocolType,
3744
+ params
3745
+ );
3746
+ }
3747
+ if ((_c = this.errorFallbackStrategy) == null ? void 0 : _c.excludeList) {
3748
+ return !this.errorFallbackStrategy.excludeList.includes(
3749
+ params.error.errorCode
3750
+ );
3751
+ }
3752
+ return false;
3753
+ }
3754
+ }
3755
+ const strategy$2 = window["VePlayer"].strategy;
3756
+ const load$7 = window["VePlayer"].load;
3757
+ const Codec$3 = window["VePlayer"].Codec;
3758
+ const util$4 = window["VePlayer"].util;
3759
+ const { appendSearchParams } = util$4;
3760
+ const getFlvStrategy = async (options) => {
3761
+ var _a, _b, _c, _d, _e, _f;
3762
+ let mseStrategy;
3763
+ let softStrategy;
3764
+ const enableLowLatency = (_a = options == null ? void 0 : options.flv) == null ? void 0 : _a.enableLowLatency;
3765
+ const enableFrameChasing = ((_c = (_b = options == null ? void 0 : options.flv) == null ? void 0 : _b.lowLatency) == null ? void 0 : _c.enableFrameChasing) ?? true;
3766
+ const abrPts = ((_e = (_d = options == null ? void 0 : options.flv) == null ? void 0 : _d.lowLatency) == null ? void 0 : _e.abrPts) ?? "-800";
3767
+ const codec = await strategy$2.getCodec(options);
3768
+ const isSoftDecode = await strategy$2.isSoftDecode(options, codec);
3769
+ if (isSoftDecode) {
3770
+ softStrategy = codec === Codec$3.H265 ? strategy$2.createSoftDecodeH265Strategy() : strategy$2.createSoftDecodeH264Strategy();
3771
+ mseStrategy = strategy$2.createFlvMseStrategy(options);
3772
+ }
3773
+ if (codec === "unknown" ? isFLVSupported(Codec$3.H264) : isFLVSupported(codec)) {
3774
+ mseStrategy = enableMMS() ? strategy$2.createFlvMssStrategy(options) : strategy$2.createFlvMseStrategy(options);
3775
+ }
3776
+ if (!mseStrategy && !softStrategy) {
3777
+ return {};
3778
+ }
3779
+ const [mseModule, softModule] = await Promise.all([
3780
+ (mseStrategy == null ? void 0 : mseStrategy.module) && load$7(mseStrategy.module).catch(() => void 0),
3781
+ (softStrategy == null ? void 0 : softStrategy.module) && load$7(softStrategy.module).catch(() => void 0)
3782
+ ]);
3783
+ (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));
3784
+ const combineOptions = strategy$2.combineOptions([mseStrategy, softStrategy]);
3785
+ const plugins = [];
3786
+ if (enableLowLatency) {
3787
+ combineOptions.url = appendSearchParams(options.url, { abr_pts: abrPts });
3788
+ }
3789
+ if (mseModule) {
3790
+ plugins.push(mseModule.FlvPlugin);
3791
+ if (enableLowLatency && enableFrameChasing) {
3792
+ plugins.push(mseModule.Adaptive);
3793
+ }
3794
+ }
3795
+ return {
3796
+ options: combineOptions,
3797
+ plugins
3798
+ };
3799
+ };
3800
+ const DynamicModule$5 = window["VePlayer"].DynamicModule;
3801
+ const load$6 = window["VePlayer"].load;
3802
+ class FlvProtocol extends BaseProtocol {
3803
+ static get suffix() {
3804
+ return ".flv";
3805
+ }
3806
+ get protocolType() {
3807
+ return LiveUrlType.Flv;
3808
+ }
3809
+ get defaultFallbackStrategy() {
3810
+ return {};
3811
+ }
3812
+ static generateUrl(urls, {
3813
+ generateUrlFromOtherProtocol: generateUrlFromOtherProtocol2
3814
+ }) {
3815
+ return urls[LiveUrlType.Flv] ?? generateUrlFromOtherProtocol2();
3816
+ }
3817
+ static canGenerateOtherProtocol() {
3818
+ return true;
3819
+ }
3820
+ async canPlay() {
3821
+ return {
3822
+ canPlay: isFLVSupported()
3823
+ };
3824
+ }
3825
+ shouldFallbackWhenStall() {
3826
+ return false;
3827
+ }
3828
+ async getProtocolStrategy(options, {
3829
+ enableSelector
3830
+ }) {
3831
+ return getFlvStrategy(
3832
+ enableSelector ? {
3833
+ ...options,
3834
+ flv: {
3835
+ ...options.flv,
3836
+ enableLowLatency: false
3837
+ }
3838
+ } : options
3839
+ );
3840
+ }
3841
+ async getAbrStrategy(options) {
3842
+ var _a;
3843
+ const abrOptions = (_a = options == null ? void 0 : options.flv) == null ? void 0 : _a.abr;
3844
+ if (!abrOptions) {
3845
+ return {};
3846
+ }
3847
+ const abrPlugin = await load$6(DynamicModule$5.PluginAbr).catch(
3848
+ () => void 0
3849
+ );
3850
+ return {
3851
+ options: {
3852
+ abr: {
3853
+ ...abrOptions,
3854
+ open: abrOptions.enable ?? true
3855
+ }
3856
+ },
3857
+ plugins: [abrPlugin == null ? void 0 : abrPlugin.AbrPlugin]
3858
+ };
3859
+ }
3860
+ getDrmStrategy() {
3861
+ return void 0;
3862
+ }
3863
+ }
3864
+ class FlvLowLatencyProtocol extends FlvProtocol {
3865
+ get protocolType() {
3866
+ return LiveUrlType.LLFlv;
3867
+ }
3868
+ async getProtocolStrategy(options) {
3869
+ return getFlvStrategy({
3870
+ ...options,
3871
+ flv: {
3872
+ ...options.flv,
3873
+ enableLowLatency: true
3874
+ }
3875
+ });
3876
+ }
3877
+ }
3878
+ const Sniffer$3 = window["VePlayer"].Sniffer;
3879
+ var DrmType = /* @__PURE__ */ ((DrmType2) => {
3880
+ DrmType2["Fairplay"] = "fairplay";
3881
+ return DrmType2;
3882
+ })(DrmType || {});
3883
+ function getDrmType(drm) {
3884
+ if ((drm == null ? void 0 : drm.fairplay) && (Sniffer$3.browser === "safari" || Sniffer$3.os.isIos)) {
3885
+ return "fairplay";
3886
+ }
3887
+ return;
3888
+ }
3889
+ function isMseSupportedWithDrm({
3890
+ drm,
3891
+ streamType
3892
+ }) {
3893
+ const drmType = getDrmType(drm);
3894
+ if (!drmType) {
3895
+ return true;
3896
+ }
3897
+ if (drmType === "fairplay" && streamType === "hls") {
3898
+ return false;
3899
+ }
3900
+ return true;
3901
+ }
3902
+ const Codec$2 = window["VePlayer"].Codec;
3903
+ const strategy$1 = window["VePlayer"].strategy;
3904
+ const load$5 = window["VePlayer"].load;
3905
+ const Sniffer$2 = window["VePlayer"].Sniffer;
3906
+ const util$3 = window["VePlayer"].util;
3907
+ const { isMseSupported: isMseSupported$1 } = util$3;
3908
+ function enableHlsJs(options) {
3909
+ var _a, _b;
3910
+ if ((_a = options == null ? void 0 : options.hls) == null ? void 0 : _a.enableHlsJs) {
3911
+ return true;
3912
+ }
3913
+ if (((_b = options == null ? void 0 : options.ad) == null ? void 0 : _b.adType) === "ssai") {
3914
+ return true;
3915
+ }
3916
+ return false;
3917
+ }
3918
+ const getHlsStrategy = async (options) => {
3919
+ var _a, _b;
3920
+ let mseStrategy;
3921
+ let softStrategy;
3922
+ if (!isMseSupportedWithDrm({ drm: options.drm, streamType: "hls" })) {
3923
+ return { options: {}, plugins: [] };
3924
+ }
3925
+ const codec = await strategy$1.getCodec(options);
3926
+ const isSoftDecode = await strategy$1.isSoftDecode(options, codec);
3927
+ const useHlsJs = enableHlsJs(options);
3928
+ if (isSoftDecode) {
3929
+ softStrategy = codec === Codec$2.H265 ? strategy$1.createSoftDecodeH265Strategy() : strategy$1.createSoftDecodeH264Strategy();
3930
+ mseStrategy = strategy$1.createHlsMseStrategy(options, useHlsJs);
3931
+ }
3932
+ if ((Sniffer$2.device !== "mobile" || ((_a = options == null ? void 0 : options.hls) == null ? void 0 : _a.enableMSE)) && (codec === "unknown" ? isMseSupported$1(Codec$2.H264) : isMseSupported$1(codec))) {
3933
+ mseStrategy = strategy$1.createHlsMseStrategy(options, useHlsJs);
3934
+ }
3935
+ if (!mseStrategy && !softStrategy) {
3936
+ return {};
3937
+ }
3938
+ const [mseModule, softModule] = await Promise.all([
3939
+ (mseStrategy == null ? void 0 : mseStrategy.module) && load$5(mseStrategy.module).catch(() => void 0),
3940
+ (softStrategy == null ? void 0 : softStrategy.module) && load$5(softStrategy.module).catch(() => void 0)
3941
+ ]);
3942
+ (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));
3943
+ const combineOptions = strategy$1.combineOptions([mseStrategy, softStrategy]);
3944
+ return {
3945
+ options: combineOptions,
3946
+ plugins: (mseModule == null ? void 0 : mseModule.HlsPlugin) ? [mseModule.HlsPlugin] : []
3947
+ };
3948
+ };
3949
+ function getType(definition) {
3950
+ if (typeof definition === "string") {
3951
+ return getStreamType(definition);
3952
+ }
3953
+ if (definition.type) {
3954
+ return definition.type;
3955
+ }
3956
+ return getStreamType(definition.url);
3957
+ }
3958
+ function pushToEmpty(obj, key, value) {
3959
+ if (!obj[key]) {
3960
+ obj[key] = [];
3961
+ }
3962
+ obj[key].push(value);
3963
+ }
3964
+ function splitPlaylist(playlist) {
3965
+ return playlist.reduce((pre, source) => {
3966
+ const definitionMap = source.definitions.reduce(
3967
+ (preDefinition, definition) => {
3968
+ const type = getType(definition);
3969
+ pushToEmpty(preDefinition, type, definition);
3970
+ return preDefinition;
3971
+ },
3972
+ {}
3973
+ );
3974
+ Object.keys(definitionMap).map((type) => {
3975
+ pushToEmpty(pre, type, {
3976
+ ...source,
3977
+ definitions: definitionMap[type]
3978
+ });
3979
+ });
3980
+ return pre;
3981
+ }, {});
3982
+ }
3983
+ function generateUrlFromOtherProtocol(playlist, suffix, targetSuffix) {
3984
+ return modifyPlaylistUrl(playlist, (url) => {
3985
+ return url.replace(suffix, targetSuffix);
3986
+ });
3987
+ }
3988
+ function modifyPlaylistUrl(playlist, callback) {
3989
+ const newPlaylist = [];
3990
+ playlist == null ? void 0 : playlist.forEach((source) => {
3991
+ const definitions = [];
3992
+ source.definitions.forEach((definition) => {
3993
+ var _a;
3994
+ if (typeof definition === "string") {
3995
+ definitions.push(callback(definition));
3996
+ } else {
3997
+ definitions.push({
3998
+ ...definition,
3999
+ url: callback(definition.url),
4000
+ fallbackUrls: (_a = definition.fallbackUrls) == null ? void 0 : _a.map(
4001
+ (fallbackUrl) => callback(fallbackUrl)
4002
+ )
4003
+ });
4004
+ }
4005
+ });
4006
+ newPlaylist.push({
4007
+ ...source,
4008
+ definitions
4009
+ });
4010
+ });
4011
+ return newPlaylist;
4012
+ }
4013
+ const DynamicModule$4 = window["VePlayer"].DynamicModule;
4014
+ const load$4 = window["VePlayer"].load;
4015
+ const getDrmStrategy = async (options, player) => {
4016
+ var _a;
4017
+ const drmType = getDrmType(options.drm);
4018
+ if (options.url && drmType === DrmType.Fairplay) {
4019
+ try {
4020
+ const { getDrmConfig, ...originFairplayConfig } = ((_a = options == null ? void 0 : options.drm) == null ? void 0 : _a.fairplay) ?? {};
4021
+ const [drmPlugin, drmConfig] = await Promise.all([
4022
+ load$4(DynamicModule$4.PluginDrm).then((module) => module.DrmPlugin).catch(() => void 0),
4023
+ getDrmConfig == null ? void 0 : getDrmConfig({
4024
+ url: options.url
4025
+ })
4026
+ ]);
4027
+ const fairplayDrmConfig = Object.assign(
4028
+ {},
4029
+ originFairplayConfig,
4030
+ options == null ? void 0 : options.drm,
4031
+ drmConfig
4032
+ );
4033
+ drmConfig && (player == null ? void 0 : player.updateDrmConfig(drmConfig));
4034
+ return {
4035
+ options: {
4036
+ drm: fairplayDrmConfig
4037
+ },
4038
+ plugins: drmPlugin ? [drmPlugin] : []
4039
+ };
4040
+ } catch (error2) {
4041
+ console.log(error2);
4042
+ }
4043
+ }
4044
+ return {};
4045
+ };
4046
+ const DynamicModule$3 = window["VePlayer"].DynamicModule;
4047
+ const load$3 = window["VePlayer"].load;
4048
+ const util$2 = window["VePlayer"].util;
4049
+ class HlsProtocol extends BaseProtocol {
4050
+ static get suffix() {
4051
+ return ".m3u8";
4052
+ }
4053
+ get protocolType() {
4054
+ return LiveUrlType.Hls;
4055
+ }
4056
+ get defaultFallbackStrategy() {
4057
+ return {};
4058
+ }
4059
+ static canGenerateOtherProtocol() {
4060
+ return true;
4061
+ }
4062
+ static generateUrl(urls, {
4063
+ generateUrlFromOtherProtocol: generateUrlFromOtherProtocol2
4064
+ }) {
4065
+ if (urls[LiveUrlType.Hls]) {
4066
+ return urls[LiveUrlType.Hls];
4067
+ }
4068
+ if (urls[LiveUrlType.LLHls]) {
4069
+ return modifyPlaylistUrl(urls[LiveUrlType.LLHls], (url) => {
4070
+ return util$2.appendSearchParams(url, {
4071
+ fpkey_normal_hls: "1"
4072
+ });
4073
+ });
4074
+ }
4075
+ return generateUrlFromOtherProtocol2();
4076
+ }
4077
+ async canPlay() {
4078
+ return { canPlay: true };
4079
+ }
4080
+ shouldFallbackWhenStall() {
4081
+ return false;
4082
+ }
4083
+ async getProtocolStrategy(options) {
4084
+ return getHlsStrategy(options);
4085
+ }
4086
+ async getAbrStrategy(options) {
4087
+ var _a;
4088
+ const abrOptions = (_a = options == null ? void 0 : options.hls) == null ? void 0 : _a.abr;
4089
+ if (!abrOptions) {
4090
+ return {};
4091
+ }
4092
+ const abrPlugin = await load$3(DynamicModule$3.PluginAbr).catch(
4093
+ () => void 0
4094
+ );
4095
+ return {
4096
+ options: {
4097
+ hlsabr: {
4098
+ ...abrOptions,
4099
+ open: abrOptions.enable ?? true
4100
+ }
4101
+ },
4102
+ plugins: [abrPlugin == null ? void 0 : abrPlugin.HlsAbrPlugin]
4103
+ };
4104
+ }
4105
+ getDrmStrategy(options, player) {
4106
+ return getDrmStrategy(options, player);
4107
+ }
4108
+ }
4109
+ class HlsLowLatencyProtocol extends BaseProtocol {
4110
+ static get suffix() {
4111
+ return ".m3u8";
4112
+ }
4113
+ get protocolType() {
4114
+ return LiveUrlType.LLHls;
4115
+ }
4116
+ get defaultFallbackStrategy() {
4117
+ return {};
4118
+ }
4119
+ static generateUrl(urls) {
4120
+ return urls[LiveUrlType.LLHls];
4121
+ }
4122
+ static canGenerateOtherProtocol() {
4123
+ return true;
4124
+ }
4125
+ async canPlay() {
4126
+ return { canPlay: true };
4127
+ }
4128
+ shouldFallbackWhenStall() {
4129
+ return false;
4130
+ }
4131
+ async getProtocolStrategy(options) {
4132
+ return getHlsStrategy(options);
4133
+ }
4134
+ getAbrStrategy() {
4135
+ return void 0;
4136
+ }
4137
+ getDrmStrategy() {
4138
+ return void 0;
4139
+ }
4140
+ }
4141
+ const DynamicModule$2 = window["VePlayer"].DynamicModule;
4142
+ const load$2 = window["VePlayer"].load;
4143
+ async function isRTMSupported() {
4144
+ const { RtmPlugin } = await load$2(DynamicModule$2.PluginRtm);
4145
+ return RtmPlugin.isSupported();
4146
+ }
4147
+ async function isRTMSupportCodec(codec = RTMCodec.H264) {
4148
+ const { RtmPlugin } = await load$2(DynamicModule$2.PluginRtm);
4149
+ if (codec === RTMCodec.H264)
4150
+ return RtmPlugin.isSupportedH264();
4151
+ return false;
4152
+ }
4153
+ const strategy = window["VePlayer"].strategy;
4154
+ const util$1 = window["VePlayer"].util;
4155
+ const DynamicModule$1 = window["VePlayer"].DynamicModule;
4156
+ const load$1 = window["VePlayer"].load;
4157
+ const Codec$1 = window["VePlayer"].Codec;
4158
+ const Sniffer$1 = window["VePlayer"].Sniffer;
4159
+ const rtmStrategy = {
4160
+ options: {},
4161
+ module: DynamicModule$1.PluginRtm
4162
+ };
4163
+ const generateFallbackUrl = (url) => {
4164
+ if (Sniffer$1.device === "pc") {
4165
+ return url.replace(".sdp", ".flv");
4166
+ } else {
4167
+ return url.replace(".sdp", ".m3u8");
4168
+ }
4169
+ };
4170
+ const getRtmStrategy = async (options, player, i18n) => {
4171
+ var _a, _b;
4172
+ let backupStrategy;
4173
+ let actualFallbackUrl = "";
4174
+ const { url, playlist } = options;
4175
+ const { fallbackUrl, enableRTMAutoTranscode, ...ret } = options.rtm || {};
4176
+ let { enableFallback = true } = options.rtm || {};
4177
+ if (playlist == null ? void 0 : playlist.length) {
4178
+ enableFallback = false;
4179
+ }
4180
+ const isRTMAutoTranscode = enableRTMAutoTranscode || ((_a = getUrlObject(url)) == null ? void 0 : _a.searchParams.get("enableRTMAutoTranscode")) === "true";
4181
+ if (enableFallback) {
4182
+ if (fallbackUrl) {
4183
+ actualFallbackUrl = fallbackUrl;
4184
+ } else if (isRTMAutoTranscode && url) {
4185
+ actualFallbackUrl = generateFallbackUrl(url);
4186
+ } else {
4187
+ console.warn(
4188
+ create(ErrorCode.EMPTY_RTM_FALLBACK_PARAMETER, i18n).message
4189
+ );
4190
+ }
4191
+ }
4192
+ const backupType = actualFallbackUrl && util$1.getStreamType(actualFallbackUrl);
4193
+ if (backupType === "flv" && util$1.isMseSupported(Codec$1.H264)) {
4194
+ backupStrategy = strategy.createFlvMseStrategy(options);
4195
+ } else if (backupType === "hls" && (Sniffer$1.device !== "mobile" || ((_b = options == null ? void 0 : options.hls) == null ? void 0 : _b.enableMSE)) && util$1.isMseSupported(Codec$1.H264)) {
4196
+ backupStrategy = strategy.createHlsMseStrategy(options);
4197
+ }
4198
+ const [rtmCdn, backupCdn] = await Promise.all([
4199
+ load$1(rtmStrategy.module).then((module) => {
4200
+ return module.RtmPlugin;
4201
+ }).catch(() => void 0),
4202
+ backupStrategy && load$1(backupStrategy.module).then((module) => {
4203
+ if ((backupStrategy == null ? void 0 : backupStrategy.module) === DynamicModule$1.PluginFlv) {
4204
+ return module.FlvPlugin;
4205
+ } else if ((backupStrategy == null ? void 0 : backupStrategy.module) === DynamicModule$1.PluginHls) {
4206
+ return module.HlsPlugin;
4207
+ }
4208
+ }).catch(() => void 0)
4209
+ ]);
4210
+ if (actualFallbackUrl) {
4211
+ const [RTMSupported, RTMSupportCodec] = await Promise.all([
4212
+ isRTMSupported(),
4213
+ isRTMSupportCodec()
4214
+ ]);
4215
+ if (!RTMSupported || !RTMSupportCodec) {
4216
+ if (player) {
4217
+ player.emit("degrade", {
4218
+ url: actualFallbackUrl,
4219
+ originRtmUrl: url,
4220
+ code: "NOT_SUPPORT",
4221
+ message: "not support rtm or h264",
4222
+ isRTMSupported: RTMSupported,
4223
+ isRTMSupportCodec: RTMSupportCodec
4224
+ });
4225
+ }
4226
+ return {
4227
+ options: {
4228
+ ...(backupStrategy == null ? void 0 : backupStrategy.options) || {},
4229
+ url: actualFallbackUrl,
4230
+ _RTMdegrade: {
4231
+ _originRtmUrl: url,
4232
+ _isRTMSupported: RTMSupported,
4233
+ _isRTMSupportCodec: RTMSupportCodec
4234
+ }
4235
+ },
4236
+ plugins: backupCdn ? [backupCdn] : []
4237
+ };
4238
+ }
4239
+ }
4240
+ return {
4241
+ options: {
4242
+ ...(backupStrategy == null ? void 0 : backupStrategy.options) || {},
4243
+ url: enableRTMAutoTranscode ? util$1.appendSearchParams(url, { enableRTMAutoTranscode: "true" }) : void 0,
4244
+ _RTMdegrade: void 0,
4245
+ rts: {
4246
+ retryCount: 0,
4247
+ ...ret,
4248
+ backupURL: actualFallbackUrl,
4249
+ backupConstruct: backupCdn
4250
+ }
4251
+ },
4252
+ plugins: rtmCdn ? [rtmCdn] : []
4253
+ };
4254
+ };
4255
+ class RtmProtocol extends BaseProtocol {
4256
+ static get suffix() {
4257
+ return ".sdp";
4258
+ }
4259
+ get protocolType() {
4260
+ return LiveUrlType.Rtm;
4261
+ }
4262
+ get defaultFallbackStrategy() {
4263
+ return { [FallbackKind.Error]: { shouldFallback: () => true } };
4264
+ }
4265
+ static canGenerateOtherProtocol(options) {
4266
+ var _a;
4267
+ return (_a = options.rtm) == null ? void 0 : _a.enableRTMAutoTranscode;
4268
+ }
4269
+ static generateUrl(urls, {
4270
+ generateUrlFromOtherProtocol: generateUrlFromOtherProtocol2,
4271
+ options
4272
+ }) {
4273
+ var _a;
4274
+ if (urls[LiveUrlType.Rtm]) {
4275
+ return urls[LiveUrlType.Rtm];
4276
+ }
4277
+ if ((_a = options.rtm) == null ? void 0 : _a.enableRTMAutoTranscode) {
4278
+ return generateUrlFromOtherProtocol2();
4279
+ }
4280
+ console.warn("生成 rtm 地址失败。请传入 rtm 播放地址,或开启自动转码");
4281
+ return;
4282
+ }
4283
+ async canPlay() {
4284
+ const [isSupported, isSupportCodec] = await Promise.all([
4285
+ isRTMSupported(),
4286
+ isRTMSupportCodec()
4287
+ ]);
4288
+ return {
4289
+ canPlay: isSupported && isSupportCodec
4290
+ };
4291
+ }
4292
+ shouldFallbackWhenStall() {
4293
+ return false;
4294
+ }
4295
+ async getProtocolStrategy(options, {
4296
+ player,
4297
+ i18n,
4298
+ enableSelector
4299
+ }) {
4300
+ this.protocolStrategy = await getRtmStrategy(
4301
+ enableSelector ? {
4302
+ options,
4303
+ rtm: {
4304
+ ...options.rtm,
4305
+ enableFallback: false
4306
+ }
4307
+ } : options,
4308
+ player,
4309
+ i18n
4310
+ );
4311
+ return this.protocolStrategy;
4312
+ }
4313
+ getAbrStrategy() {
4314
+ return void 0;
4315
+ }
4316
+ getDrmStrategy() {
4317
+ return void 0;
4318
+ }
4319
+ }
4320
+ class ProtocolSelector {
4321
+ constructor({ queue, streams, options }) {
4322
+ // 链开始的类
4323
+ // start?: AbstractProtocol;
4324
+ // 链结束的类,也是当前正在播放的类型
4325
+ __publicField(this, "current");
4326
+ // 降级顺序
4327
+ __publicField(this, "_queue");
4328
+ __publicField(this, "_streams");
4329
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
4330
+ // @ts-ignore
4331
+ __publicField(this, "_options");
4332
+ this._queue = queue;
4333
+ this._streams = streams;
4334
+ this._options = options;
4335
+ this.current = this._getStartProtocol();
4336
+ }
4337
+ // 获取最终返回的播放类型和参数。
4338
+ async getProtocol() {
4339
+ if (!this.current) {
4340
+ return;
4341
+ }
4342
+ const { canPlay } = await this.current.canPlay() ?? {};
4343
+ if (canPlay) {
4344
+ return this.current;
4345
+ }
4346
+ this.next();
4347
+ return this.getProtocol();
4348
+ }
4349
+ // 降级时,将指针指到上次结束的位置
4350
+ next() {
4351
+ var _a;
4352
+ this.current = (_a = this.current) == null ? void 0 : _a.nextProtocol;
4353
+ }
4354
+ // 生成责任链
4355
+ _getStartProtocol() {
4356
+ let nextProtocol;
4357
+ for (let index = this._queue.length - 1; index >= 0; index--) {
4358
+ const type = this._queue[index];
4359
+ const protocol = this._streams[type];
4360
+ if (protocol) {
4361
+ if (nextProtocol) {
4362
+ nextProtocol.preProtocol = protocol;
4363
+ protocol.nextProtocol = nextProtocol;
4364
+ }
4365
+ nextProtocol = protocol;
4366
+ }
4367
+ }
4368
+ return nextProtocol;
4369
+ }
4370
+ }
4371
+ const _LowLatencySelector = class extends ProtocolSelector {
4372
+ // 目前默认传入了默认的低延迟选择顺序,
4373
+ // 也可以支持自定义配置
4374
+ constructor({
4375
+ streams,
4376
+ options
4377
+ }) {
4378
+ super({
4379
+ queue: _LowLatencySelector.queue,
4380
+ streams,
4381
+ options
4382
+ });
4383
+ }
4384
+ };
4385
+ let LowLatencySelector = _LowLatencySelector;
4386
+ __publicField(LowLatencySelector, "queue", [
4387
+ LiveUrlType.Rtm,
4388
+ LiveUrlType.LLFlv,
4389
+ LiveUrlType.Flv,
4390
+ LiveUrlType.LLHls,
4391
+ LiveUrlType.Hls
4392
+ ]);
4393
+ class CustomSelector extends ProtocolSelector {
4394
+ constructor({
4395
+ streams,
4396
+ options
4397
+ }) {
4398
+ var _a;
4399
+ super({
4400
+ queue: (_a = options.fallback) == null ? void 0 : _a.fallbackOrder,
4401
+ streams,
4402
+ options
4403
+ });
4404
+ }
4405
+ }
4406
+ __publicField(CustomSelector, "queue");
4407
+ const _ProtocolManager = class {
4408
+ constructor(options) {
4409
+ __publicField(this, "_options");
4410
+ __publicField(this, "_selector");
4411
+ __publicField(this, "_protocol");
4412
+ __publicField(this, "_playlistMap", {});
4413
+ this._options = options;
4414
+ this._init({
4415
+ url: options.url,
4416
+ playlist: options.playlist
4417
+ });
4418
+ }
4419
+ get enableSelector() {
4420
+ return !!this._selector;
4421
+ }
4422
+ get protocol() {
4423
+ return this._protocol;
4424
+ }
4425
+ get playlist() {
4426
+ var _a;
4427
+ return ((_a = this._protocol) == null ? void 0 : _a.protocolType) && this._playlistMap ? this._playlistMap[this._protocol.protocolType] : void 0;
4428
+ }
4429
+ static async create(options) {
4430
+ const protocolManager = new _ProtocolManager(options);
4431
+ await protocolManager.getProtocol();
4432
+ return protocolManager;
4433
+ }
4434
+ static _generateProtocolMap(queue, splittedPlaylist, options) {
4435
+ const protocolMap = {};
4436
+ const playlistMap = {};
4437
+ const baseGenerateProtocol = queue.find((type) => {
4438
+ return _ProtocolManager._protocolMap[type].canGenerateOtherProtocol(options) && splittedPlaylist[type];
4439
+ });
4440
+ queue.forEach((protocolType) => {
4441
+ var _a;
4442
+ const playlist = ((_a = _ProtocolManager._protocolMap[protocolType]) == null ? void 0 : _a.generateUrl(
4443
+ splittedPlaylist,
4444
+ {
4445
+ generateUrlFromOtherProtocol: () => {
4446
+ if (!baseGenerateProtocol) {
4447
+ return;
4448
+ }
4449
+ return generateUrlFromOtherProtocol(
4450
+ splittedPlaylist[baseGenerateProtocol],
4451
+ _ProtocolManager._protocolMap[baseGenerateProtocol].suffix,
4452
+ _ProtocolManager._protocolMap[protocolType].suffix
4453
+ );
4454
+ },
4455
+ options
4456
+ }
4457
+ )) ?? splittedPlaylist[protocolType];
4458
+ if (playlist) {
4459
+ playlistMap[protocolType] = playlist;
4460
+ protocolMap[protocolType] = new _ProtocolManager._protocolMap[protocolType](options);
4461
+ }
4462
+ });
4463
+ return { protocolMap, playlistMap };
4464
+ }
4465
+ async getProtocol() {
4466
+ if (this._selector) {
4467
+ this._protocol = await this._selector.getProtocol();
4468
+ }
4469
+ return this._protocol;
4470
+ }
4471
+ async update({
4472
+ url,
4473
+ playlist
4474
+ }) {
4475
+ this._options = { ...this._options, url, playlist };
4476
+ this._init({
4477
+ url,
4478
+ playlist
4479
+ });
4480
+ await this.getProtocol();
4481
+ }
4482
+ async next() {
4483
+ if (!this._selector) {
4484
+ return;
4485
+ }
4486
+ this._selector.next();
4487
+ await this.getProtocol();
4488
+ return this._protocol;
4489
+ }
4490
+ async getStrategy(player, i18n) {
4491
+ var _a, _b, _c;
4492
+ const protocol = this._protocol;
4493
+ const [typeStrategy, drmStrategy, abrStrategy] = await Promise.all([
4494
+ protocol == null ? void 0 : protocol.getProtocolStrategy(this._options, {
4495
+ player,
4496
+ i18n,
4497
+ enableSelector: !!this._selector
4498
+ }),
4499
+ (_a = protocol == null ? void 0 : protocol.getDrmStrategy) == null ? void 0 : _a.call(protocol, this._options, player),
4500
+ (_b = protocol == null ? void 0 : protocol.getAbrStrategy) == null ? void 0 : _b.call(protocol, this._options)
4501
+ ]);
4502
+ const { options, plugins } = typeStrategy ?? {};
4503
+ const { options: drmOptions, plugins: drmPlugins } = drmStrategy ?? {};
4504
+ const { options: abrOptions, plugins: abrPlugins } = abrStrategy ?? {};
4505
+ return {
4506
+ options: Object.assign({}, options, drmOptions, abrOptions),
4507
+ plugins: [
4508
+ ...plugins ?? [],
4509
+ ...drmPlugins ?? [],
4510
+ ...abrPlugins ?? []
4511
+ ],
4512
+ useSrc: !((_c = typeStrategy == null ? void 0 : typeStrategy.plugins) == null ? void 0 : _c.length),
4513
+ protocol: protocol == null ? void 0 : protocol.protocolType
4514
+ };
4515
+ }
4516
+ _init({
4517
+ url,
4518
+ playlist
4519
+ }) {
4520
+ var _a;
4521
+ if (playlist) {
4522
+ const splittedPlaylist = splitPlaylist(playlist);
4523
+ const Selector = this._options.latencyMode === "low" ? LowLatencySelector : CustomSelector;
4524
+ const queue = (Selector == null ? void 0 : Selector.queue) ?? ((_a = this._options.fallback) == null ? void 0 : _a.fallbackOrder);
4525
+ if (queue == null ? void 0 : queue.length) {
4526
+ const { protocolMap, playlistMap } = _ProtocolManager._generateProtocolMap(
4527
+ queue,
4528
+ splittedPlaylist,
4529
+ this._options
4530
+ );
4531
+ this._playlistMap = playlistMap;
4532
+ this._selector = new Selector({
4533
+ streams: protocolMap,
4534
+ options: this._options
4535
+ });
4536
+ return;
4537
+ }
4538
+ this._playlistMap = splittedPlaylist;
4539
+ this._initSingleProtocol(Object.keys(splittedPlaylist)[0]);
4540
+ } else if (url) {
4541
+ this._initSingleProtocol(getStreamType(url));
4542
+ }
4543
+ }
4544
+ _initSingleProtocol(protocol) {
4545
+ if (protocol) {
4546
+ this._protocol = new _ProtocolManager._protocolMap[protocol](
4547
+ this._options
4548
+ );
4549
+ }
4550
+ }
4551
+ };
4552
+ let ProtocolManager = _ProtocolManager;
4553
+ __publicField(ProtocolManager, "_protocolMap", {
4554
+ [LiveUrlType.Flv]: FlvProtocol,
4555
+ [LiveUrlType.LLFlv]: FlvLowLatencyProtocol,
4556
+ [LiveUrlType.Hls]: HlsProtocol,
4557
+ [LiveUrlType.LLHls]: HlsLowLatencyProtocol,
4558
+ [LiveUrlType.Rtm]: RtmProtocol
4559
+ });
4560
+ class Fallback {
4561
+ constructor() {
4562
+ __publicField(this, "player");
4563
+ __publicField(this, "protocolManager");
4564
+ __publicField(this, "beforeFallbackError", async (error2) => {
4565
+ var _a, _b, _c, _d, _e, _f;
4566
+ 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)) {
4567
+ return { canEmitError: true };
4568
+ }
4569
+ const nextProtocol = await ((_e = this.protocolManager) == null ? void 0 : _e.next());
4570
+ if (!nextProtocol || !((_f = this.protocolManager) == null ? void 0 : _f.playlist)) {
4571
+ return { canEmitError: true };
4572
+ }
4573
+ this.fallback();
4574
+ return { canEmitError: false };
4575
+ });
4576
+ }
4577
+ initErrorFallback(player, protocolManager) {
4578
+ this.player = player;
4579
+ this.protocolManager = protocolManager;
4580
+ }
4581
+ async fallback() {
4582
+ var _a, _b, _c, _d;
4583
+ if (!((_a = this.protocolManager) == null ? void 0 : _a.playlist))
4584
+ return;
4585
+ const definition = (_b = this.player) == null ? void 0 : _b.definition;
4586
+ const source = (_c = this.player) == null ? void 0 : _c.source;
4587
+ (_d = this.player) == null ? void 0 : _d.updatePlaylist(
4588
+ this.protocolManager.playlist,
4589
+ {
4590
+ definition,
4591
+ source
4592
+ },
4593
+ false
4594
+ );
4595
+ }
4596
+ }
4597
+ const fallback = new Fallback();
3961
4598
  const DEFAULT_PLUGINS = window["VePlayer"].DEFAULT_PLUGINS;
3962
4599
  const VePlayerBase = window["VePlayer"].VePlayerBase;
3963
4600
  const VeI18n = window["VePlayer"].VeI18n;
@@ -3992,6 +4629,7 @@ class VePlayerLive extends VePlayerBase {
3992
4629
  */
3993
4630
  constructor(options) {
3994
4631
  super(options);
4632
+ __publicField(this, "_protocolManager");
3995
4633
  }
3996
4634
  /** {zh}
3997
4635
  * @brief 获取已经播放的时长,不包含暂停和等待时间,单位为秒。
@@ -4182,6 +4820,13 @@ class VePlayerLive extends VePlayerBase {
4182
4820
  var _a, _b, _c;
4183
4821
  return (_c = (_b = (_a = this._player) == null ? void 0 : _a.plugins) == null ? void 0 : _b.hls) == null ? void 0 : _c.getStats();
4184
4822
  }
4823
+ async updatePlaylist(playlist, target, needUpdateProtocol = true) {
4824
+ var _a;
4825
+ if (needUpdateProtocol) {
4826
+ await ((_a = this._protocolManager) == null ? void 0 : _a.update({ playlist }));
4827
+ }
4828
+ return super.updatePlaylist(playlist, target);
4829
+ }
4185
4830
  }
4186
4831
  async function createLivePlayer(options) {
4187
4832
  var _a, _b, _c, _d;
@@ -4200,10 +4845,16 @@ async function createLivePlayer(options) {
4200
4845
  ...options,
4201
4846
  plugins: [...LIVE_DEFAULT_PLUGINS, ...options.plugins ?? []]
4202
4847
  };
4848
+ const protocolManager = await ProtocolManager.create(finalOptions);
4849
+ if (!options.url && !(protocolManager == null ? void 0 : protocolManager.playlist)) {
4850
+ throw create(ErrorCode.INVALID_PARAMETER, i18n);
4851
+ }
4203
4852
  player = await VePlayerBase.create(
4204
4853
  {
4205
4854
  ...LIVE_DEFAULT_OPTIONS,
4206
4855
  ...finalOptions,
4856
+ playlist: protocolManager == null ? void 0 : protocolManager.playlist,
4857
+ beforeFallbackError: fallback.beforeFallbackError,
4207
4858
  isLive: true,
4208
4859
  i18nManager: i18n,
4209
4860
  preProcessUrl: (url) => {
@@ -4215,44 +4866,16 @@ async function createLivePlayer(options) {
4215
4866
  };
4216
4867
  },
4217
4868
  async preparePlugins(url) {
4218
- var _a2;
4219
- const [typeStrategy, drmStrategy, abrStrategy] = await Promise.all([
4220
- getTypeStrategy(
4221
- {
4222
- ...finalOptions,
4223
- url
4224
- },
4225
- player,
4226
- i18n
4227
- ),
4228
- getDrmStrategy(
4229
- {
4230
- ...finalOptions,
4231
- url
4232
- },
4233
- player
4234
- ),
4235
- getAbrStrategy({
4236
- ...finalOptions,
4237
- url
4238
- })
4239
- ]);
4240
- const { options: options2, plugins } = typeStrategy ?? {};
4241
- const { options: drmOptions, plugins: drmPlugins } = drmStrategy ?? {};
4242
- const { options: abrOptions, plugins: abrPlugins } = abrStrategy ?? {};
4243
- return {
4244
- options: Object.assign({}, options2, drmOptions, abrOptions),
4245
- plugins: [
4246
- ...plugins ?? [],
4247
- ...drmPlugins ?? [],
4248
- ...abrPlugins ?? []
4249
- ],
4250
- useSrc: !((_a2 = typeStrategy.plugins) == null ? void 0 : _a2.length)
4251
- };
4869
+ if (!protocolManager.enableSelector) {
4870
+ await protocolManager.update({ url });
4871
+ }
4872
+ return protocolManager.getStrategy(player, i18n);
4252
4873
  }
4253
4874
  },
4254
4875
  VePlayerLive
4255
4876
  );
4877
+ player._protocolManager = protocolManager;
4878
+ fallback.initErrorFallback(player, protocolManager);
4256
4879
  if (player) {
4257
4880
  const RTMDegrade = (_d = (_c = player == null ? void 0 : player._player) == null ? void 0 : _c.config) == null ? void 0 : _d._RTMdegrade;
4258
4881
  if (RTMDegrade) {