@volcengine/veplayer 2.6.2 → 2.7.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/esm/index.d.ts +16 -19
  2. package/esm/veplayer.biz.live.development.css +1 -2
  3. package/esm/veplayer.biz.live.development.js +953 -345
  4. package/esm/veplayer.biz.live.production.css +1 -1
  5. package/esm/veplayer.biz.live.production.js +1 -1
  6. package/esm/veplayer.d.ts +285 -93
  7. package/esm/veplayer.development.css +1 -2
  8. package/esm/veplayer.development.js +912 -332
  9. package/esm/veplayer.live.d.ts +285 -93
  10. package/esm/veplayer.live.development.css +1 -2
  11. package/esm/veplayer.live.development.js +911 -331
  12. package/esm/veplayer.live.production.css +1 -1
  13. package/esm/veplayer.live.production.js +3 -3
  14. package/esm/veplayer.production.css +1 -1
  15. package/esm/veplayer.production.js +3 -3
  16. package/esm/veplayer.vod.d.ts +16 -19
  17. package/esm/veplayer.vod.development.js +36 -20
  18. package/esm/veplayer.vod.production.js +2 -2
  19. package/package.json +1 -1
  20. package/umd/index.d.ts +16 -19
  21. package/umd/veplayer.biz.live.development.css +1 -2
  22. package/umd/veplayer.biz.live.development.js +953 -345
  23. package/umd/veplayer.biz.live.production.css +1 -1
  24. package/umd/veplayer.biz.live.production.js +1 -1
  25. package/umd/veplayer.d.ts +285 -93
  26. package/umd/veplayer.development.css +1 -2
  27. package/umd/veplayer.development.js +912 -332
  28. package/umd/veplayer.live.d.ts +285 -93
  29. package/umd/veplayer.live.development.css +1 -2
  30. package/umd/veplayer.live.development.js +911 -331
  31. package/umd/veplayer.live.production.css +1 -1
  32. package/umd/veplayer.live.production.js +1 -1
  33. package/umd/veplayer.production.css +1 -1
  34. package/umd/veplayer.production.js +1 -1
  35. package/umd/veplayer.vod.d.ts +16 -19
  36. package/umd/veplayer.vod.development.js +36 -20
  37. package/umd/veplayer.vod.production.js +1 -1
  38. package/veplayer.d.ts +285 -93
  39. package/veplayer.live.d.ts +285 -93
  40. package/veplayer.vod.d.ts +16 -19
@@ -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
  };
@@ -3105,7 +2876,7 @@ var __publicField = (obj, key, value) => {
3105
2876
  device_id: this._deviceId,
3106
2877
  error_report_stop: true,
3107
2878
  ext: {
3108
- veplayer_version: "2.3.0",
2879
+ veplayer_version: "2.3.1-rc.1",
3109
2880
  flv_version: "3.0.21-rc.21",
3110
2881
  hls_version: "3.0.21-rc.21",
3111
2882
  rts_version: "0.2.1-alpha.14"
@@ -3119,7 +2890,6 @@ var __publicField = (obj, key, value) => {
3119
2890
  return transform ? transform(value) : value.toString();
3120
2891
  }
3121
2892
  function getDefaultRow(data) {
3122
- var _a;
3123
2893
  return {
3124
2894
  rows: [
3125
2895
  {
@@ -3135,10 +2905,7 @@ var __publicField = (obj, key, value) => {
3135
2905
  {
3136
2906
  key: "bitrate",
3137
2907
  labelTextKey: "BITRATE",
3138
- value: normalizeNumber(
3139
- data.bitrate,
3140
- (value) => `${(value / 1e3).toFixed(2)} kbps`
3141
- )
2908
+ value: normalizeNumber(data.bitrate, (value) => `${value / 1e3} kbps`)
3142
2909
  },
3143
2910
  {
3144
2911
  key: "gop",
@@ -3148,7 +2915,7 @@ var __publicField = (obj, key, value) => {
3148
2915
  {
3149
2916
  key: "resolution",
3150
2917
  labelTextKey: "RESOLUTION",
3151
- value: `${normalizeNumber(data.width)} * ${normalizeNumber(
2918
+ value: `${normalizeNumber(data.height)} * ${normalizeNumber(
3152
2919
  data.height
3153
2920
  )}`
3154
2921
  },
@@ -3160,14 +2927,14 @@ var __publicField = (obj, key, value) => {
3160
2927
  {
3161
2928
  key: "bufferEnd",
3162
2929
  labelTextKey: "BUFFER_END",
3163
- value: normalizeNumber(Number((_a = data.bufferEnd) == null ? void 0 : _a.toFixed(2)))
2930
+ value: normalizeNumber(data.bufferEnd)
3164
2931
  },
3165
2932
  {
3166
2933
  key: "currentTime",
3167
2934
  labelTextKey: "CURRENT_TIME",
3168
2935
  value: normalizeNumber(
3169
2936
  data.currentTime,
3170
- (value) => value.toFixed(4) + "s"
2937
+ (value) => value.toFixed(6) + "s"
3171
2938
  )
3172
2939
  }
3173
2940
  ]
@@ -3180,7 +2947,7 @@ var __publicField = (obj, key, value) => {
3180
2947
  {
3181
2948
  key: "decodeEfficiency",
3182
2949
  labelTextKey: "DECODE_EFFICIENCY",
3183
- value: normalizeNumber(data.decodeFps, (value) => value + " frames/s")
2950
+ value: normalizeNumber(data.decodeFps, (value) => value + "frames/s")
3184
2951
  },
3185
2952
  {
3186
2953
  key: "decodeCost",
@@ -3194,7 +2961,7 @@ var __publicField = (obj, key, value) => {
3194
2961
  };
3195
2962
  }
3196
2963
  var infoPanel = "";
3197
- const util$1 = window["VePlayer"].util;
2964
+ const util$6 = window["VePlayer"].util;
3198
2965
  const Plugin$1 = window["VePlayer"].Plugin;
3199
2966
  const XGUtil = window["VePlayer"].XGUtil;
3200
2967
  class InfoPanel extends Plugin$1 {
@@ -3214,7 +2981,7 @@ var __publicField = (obj, key, value) => {
3214
2981
  };
3215
2982
  }
3216
2983
  get _streamType() {
3217
- return util$1.getStreamType(this.player.config.url);
2984
+ return util$6.getStreamType(this.player.config.url);
3218
2985
  }
3219
2986
  afterCreate() {
3220
2987
  this._playPlugin = this.player.plugins[this._streamType];
@@ -3389,39 +3156,6 @@ var __publicField = (obj, key, value) => {
3389
3156
  DECODE_INFO: "软解信息",
3390
3157
  REFRESH: "刷新"
3391
3158
  };
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
3159
  var FUNC_ERROR_TEXT = "Expected a function";
3426
3160
  var PLACEHOLDER = "__lodash_placeholder__";
3427
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;
@@ -3911,6 +3645,20 @@ var __publicField = (obj, key, value) => {
3911
3645
  curry.placeholder = {};
3912
3646
  var lodash_curry = curry;
3913
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
+ };
3914
3662
  const isType = curry$1(function(suffix, url) {
3915
3663
  return url == null ? void 0 : url.split("?")[0].toLowerCase().includes(suffix);
3916
3664
  });
@@ -3937,31 +3685,916 @@ var __publicField = (obj, key, value) => {
3937
3685
  }
3938
3686
  return "unknown";
3939
3687
  }
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
- }
3688
+ const LiveUrlType = {
3689
+ Hls: "hls",
3690
+ LLHls: "ll-hls",
3691
+ Flv: "flv",
3692
+ Rtm: "rtm",
3693
+ LLFlv: "ll-flv"
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((module2) => module2.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((module2) => {
4200
+ return module2.RtmPlugin;
4201
+ }).catch(() => void 0),
4202
+ backupStrategy && load$1(backupStrategy.module).then((module2) => {
4203
+ if ((backupStrategy == null ? void 0 : backupStrategy.module) === DynamicModule$1.PluginFlv) {
4204
+ return module2.FlvPlugin;
4205
+ } else if ((backupStrategy == null ? void 0 : backupStrategy.module) === DynamicModule$1.PluginHls) {
4206
+ return module2.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
+ }
3959
4251
  },
3960
- plugins: [
3961
- streamType === "flv" ? abrPlugin == null ? void 0 : abrPlugin.AbrPlugin : abrPlugin == null ? void 0 : abrPlugin.HlsAbrPlugin
3962
- ]
4252
+ plugins: rtmCdn ? [rtmCdn] : []
3963
4253
  };
3964
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();
3965
4598
  const DEFAULT_PLUGINS = window["VePlayer"].DEFAULT_PLUGINS;
3966
4599
  const VePlayerBase = window["VePlayer"].VePlayerBase;
3967
4600
  const VeI18n = window["VePlayer"].VeI18n;
@@ -3996,6 +4629,7 @@ var __publicField = (obj, key, value) => {
3996
4629
  */
3997
4630
  constructor(options) {
3998
4631
  super(options);
4632
+ __publicField(this, "_protocolManager");
3999
4633
  }
4000
4634
  /** {zh}
4001
4635
  * @brief 获取已经播放的时长,不包含暂停和等待时间,单位为秒。
@@ -4175,16 +4809,12 @@ var __publicField = (obj, key, value) => {
4175
4809
  var _a, _b, _c;
4176
4810
  return (_c = (_b = (_a = this._player) == null ? void 0 : _a.plugins) == null ? void 0 : _b.flv) == null ? void 0 : _c.getStats();
4177
4811
  }
4178
- /** {zh}
4179
- * @brief 获取 HLS 拉流的播放信息。
4180
- * @returns
4181
- */
4182
- /** {en}
4183
- * @brief Obtain the playback information of HLS pull streaming.
4184
- */
4185
- getHLSStats() {
4186
- var _a, _b, _c;
4187
- return (_c = (_b = (_a = this._player) == null ? void 0 : _a.plugins) == null ? void 0 : _b.hls) == null ? void 0 : _c.getStats();
4812
+ async updatePlaylist(playlist, target, needUpdateProtocol = true) {
4813
+ var _a;
4814
+ if (needUpdateProtocol) {
4815
+ await ((_a = this._protocolManager) == null ? void 0 : _a.update({ playlist }));
4816
+ }
4817
+ return super.updatePlaylist(playlist, target);
4188
4818
  }
4189
4819
  }
4190
4820
  async function createLivePlayer(options) {
@@ -4204,10 +4834,16 @@ var __publicField = (obj, key, value) => {
4204
4834
  ...options,
4205
4835
  plugins: [...LIVE_DEFAULT_PLUGINS, ...options.plugins ?? []]
4206
4836
  };
4837
+ const protocolManager = await ProtocolManager.create(finalOptions);
4838
+ if (!options.url && !(protocolManager == null ? void 0 : protocolManager.playlist)) {
4839
+ throw create(ErrorCode.INVALID_PARAMETER, i18n);
4840
+ }
4207
4841
  player = await VePlayerBase.create(
4208
4842
  {
4209
4843
  ...LIVE_DEFAULT_OPTIONS,
4210
4844
  ...finalOptions,
4845
+ playlist: protocolManager == null ? void 0 : protocolManager.playlist,
4846
+ beforeFallbackError: fallback.beforeFallbackError,
4211
4847
  isLive: true,
4212
4848
  i18nManager: i18n,
4213
4849
  preProcessUrl: (url) => {
@@ -4219,44 +4855,16 @@ var __publicField = (obj, key, value) => {
4219
4855
  };
4220
4856
  },
4221
4857
  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
- };
4858
+ if (!protocolManager.enableSelector) {
4859
+ await protocolManager.update({ url });
4860
+ }
4861
+ return protocolManager.getStrategy(player, i18n);
4256
4862
  }
4257
4863
  },
4258
4864
  VePlayerLive
4259
4865
  );
4866
+ player._protocolManager = protocolManager;
4867
+ fallback.initErrorFallback(player, protocolManager);
4260
4868
  if (player) {
4261
4869
  const RTMDegrade = (_d = (_c = player == null ? void 0 : player._player) == null ? void 0 : _c.config) == null ? void 0 : _d._RTMdegrade;
4262
4870
  if (RTMDegrade) {