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