trtc-sdk-v5 5.14.2-beta.8 → 5.14.2-beta.9
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.
- package/assets/debug-dialog.js +1 -1
- package/index.d.ts +5 -1
- package/package.json +1 -1
- package/plugins/cdn-streaming/package.json +1 -1
- package/plugins/chorus/package.json +1 -1
- package/plugins/cross-room/package.json +1 -1
- package/plugins/custom-encryption/package.json +1 -1
- package/plugins/device-detector/package.json +1 -1
- package/plugins/lebplayer/lebplayer.esm.d.ts +254 -21
- package/plugins/lebplayer/lebplayer.esm.js +1 -1
- package/plugins/lebplayer/lebplayer.umd.js +1 -1
- package/plugins/lebplayer/package.json +1 -1
- package/plugins/small-stream-auto-switcher/package.json +1 -1
- package/plugins/video-decoder/package.json +1 -1
- package/plugins/video-effect/basic-beauty/package.json +1 -1
- package/plugins/video-effect/beauty/package.json +1 -1
- package/plugins/video-effect/video-mixer/package.json +1 -1
- package/plugins/video-effect/virtual-background/package.json +1 -1
- package/plugins/video-effect/watermark/package.json +1 -1
- package/plugins/voice-changer/package.json +1 -1
- package/trtc.esm.js +4 -4
- package/trtc.js +1 -1
package/index.d.ts
CHANGED
|
@@ -9,9 +9,10 @@ import { CustomEncryption, EncryptionOptions } from './plugins/custom-encryption
|
|
|
9
9
|
import { VideoMixerOptions, UpdateVideoMixerOptions, VideoMixer } from './plugins/video-effect/video-mixer';
|
|
10
10
|
import { SmallStreamAutoSwitcher, SmallStreamAutoSwitcherOptions } from './plugins/small-stream-auto-switcher';
|
|
11
11
|
import { Chorus, StartChorusOption, UpdateChorusOption } from './plugins/chorus';
|
|
12
|
+
import { LEBPlayer, StartLEBPlayerOption, UpdateLEBPlayerOption } from './plugins/lebplayer';
|
|
12
13
|
|
|
13
14
|
export { CDNStreamingOptions, DeviceDetectorOptions, VirtualBackgroundOptions, UpdateVirtualBackgroundOptions, WatermarkOptions, BeautyOptions, UpdateBeautyOptions, BasicBeautyOptions, StartCrossRoomOption, UpdateCrossRoomOption, StopCrossRoomOption, SmallStreamAutoSwitcherOptions, VideoMixerOptions, UpdateVideoMixerOptions };
|
|
14
|
-
type TRTCPlugin = typeof CrossRoom | typeof CDNStreaming | typeof DeviceDetector | typeof VirtualBackground | typeof Watermark | typeof Beauty | typeof BasicBeauty | typeof CustomEncryption | typeof SmallStreamAutoSwitcher | typeof VideoMixer | typeof Chorus;
|
|
15
|
+
type TRTCPlugin = typeof CrossRoom | typeof CDNStreaming | typeof DeviceDetector | typeof VirtualBackground | typeof Watermark | typeof Beauty | typeof BasicBeauty | typeof CustomEncryption | typeof SmallStreamAutoSwitcher | typeof VideoMixer | typeof Chorus | typeof LEBPlayer;
|
|
15
16
|
export type ExperimentalAPIFunctionMap = {
|
|
16
17
|
'enableAudioFrameEvent': EnableAudioFrameEventOptions;
|
|
17
18
|
'resumeRemotePlayer': RemotePlayerOptions;
|
|
@@ -36,6 +37,7 @@ export declare type PluginStartOptionsMap = {
|
|
|
36
37
|
'SmallStreamAutoSwitcher': SmallStreamAutoSwitcherOptions;
|
|
37
38
|
'AudioProcessor': InitAudioProcessorOptions;
|
|
38
39
|
'Chorus': StartChorusOption;
|
|
40
|
+
'LEBPlayer': StartLEBPlayerOption;
|
|
39
41
|
};
|
|
40
42
|
|
|
41
43
|
export declare type PluginUpdateOptionsMap = {
|
|
@@ -51,6 +53,7 @@ export declare type PluginUpdateOptionsMap = {
|
|
|
51
53
|
'AudioProcessor': UpdateAudioProcessorOptions;
|
|
52
54
|
'Debug': UpdateDebugOptions;
|
|
53
55
|
'Chorus': UpdateChorusOption;
|
|
56
|
+
'LEBPlayer': UpdateLEBPlayerOption;
|
|
54
57
|
};
|
|
55
58
|
|
|
56
59
|
export declare type PluginStopOptionsMap = {
|
|
@@ -69,6 +72,7 @@ export declare type PluginStopOptionsMap = {
|
|
|
69
72
|
'AudioProcessor': undefined;
|
|
70
73
|
'CustomEncryption': undefined;
|
|
71
74
|
'Chorus': undefined;
|
|
75
|
+
'LEBPlayer': undefined;
|
|
72
76
|
};
|
|
73
77
|
|
|
74
78
|
export declare class RtcError extends Error implements RTCErrorInterface {
|
package/package.json
CHANGED
|
@@ -1,27 +1,260 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* LEBPlayer Type Definitions
|
|
3
|
+
* 快直播拉流播放器类型声明
|
|
4
|
+
*/
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
/**
|
|
7
|
+
* License 配置
|
|
8
|
+
*/
|
|
9
|
+
export interface LicenseConfig {
|
|
10
|
+
/** 密钥 */
|
|
11
|
+
secretKey: string;
|
|
12
|
+
/** 加密数据 */
|
|
13
|
+
encrypted: string;
|
|
14
|
+
/** 签名 */
|
|
15
|
+
signature: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 音频统计信息
|
|
20
|
+
*/
|
|
21
|
+
export interface AudioStat {
|
|
22
|
+
/** 接收码率 (kbps) */
|
|
23
|
+
bitrate: number;
|
|
24
|
+
/** 音量 (0-1) */
|
|
25
|
+
volume: number;
|
|
26
|
+
/** 丢包率 (0-100) */
|
|
27
|
+
packetLossRate: number;
|
|
28
|
+
/** jitter buffer 缓冲延迟 (ms) */
|
|
29
|
+
jitterBufferDelay: number;
|
|
30
|
+
/** 总接收字节数 */
|
|
31
|
+
bytesReceived: number;
|
|
32
|
+
/** 总接收包数 */
|
|
33
|
+
packetsReceived: number;
|
|
34
|
+
/** 总丢包数 */
|
|
35
|
+
packetsLost: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 视频统计信息
|
|
40
|
+
*/
|
|
41
|
+
export interface VideoStat {
|
|
42
|
+
/** 接收码率 (kbps) */
|
|
43
|
+
bitrate: number;
|
|
44
|
+
/** 解码帧率 (fps) */
|
|
45
|
+
frameRate: number;
|
|
46
|
+
/** 分辨率宽度 */
|
|
47
|
+
width: number;
|
|
48
|
+
/** 分辨率高度 */
|
|
49
|
+
height: number;
|
|
50
|
+
/** 丢包率 (0-100) */
|
|
51
|
+
packetLossRate: number;
|
|
52
|
+
/** jitter buffer 缓冲延迟 (ms) */
|
|
53
|
+
jitterBufferDelay: number;
|
|
54
|
+
/** 总接收字节数 */
|
|
55
|
+
bytesReceived: number;
|
|
56
|
+
/** 总接收包数 */
|
|
57
|
+
packetsReceived: number;
|
|
58
|
+
/** 总丢包数 */
|
|
59
|
+
packetsLost: number;
|
|
60
|
+
/** 总解码帧数 */
|
|
61
|
+
framesDecoded: number;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 网络统计信息
|
|
66
|
+
*/
|
|
67
|
+
export interface NetworkStat {
|
|
68
|
+
/** 往返时延 (ms) */
|
|
69
|
+
rtt: number;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 媒体统计数据
|
|
74
|
+
*/
|
|
75
|
+
export interface MediaStats {
|
|
76
|
+
/** 音频统计 */
|
|
77
|
+
audio: AudioStat;
|
|
78
|
+
/** 视频统计 */
|
|
79
|
+
video: VideoStat;
|
|
80
|
+
/** 网络统计 */
|
|
81
|
+
network: NetworkStat;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 播放状态
|
|
86
|
+
*/
|
|
87
|
+
export type PlayState = 'PLAYING' | 'PAUSED' | 'STOPPED';
|
|
12
88
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
89
|
+
/**
|
|
90
|
+
* 媒体类型
|
|
91
|
+
*/
|
|
92
|
+
export type MediaType = 'audio' | 'video';
|
|
16
93
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
94
|
+
/**
|
|
95
|
+
* 填充模式
|
|
96
|
+
*/
|
|
97
|
+
export type FillMode = 'contain' | 'cover' | 'fill';
|
|
21
98
|
|
|
99
|
+
/**
|
|
100
|
+
* 播放器动作
|
|
101
|
+
*/
|
|
102
|
+
export type PlayerAction = 'pause' | 'resume';
|
|
22
103
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
104
|
+
/**
|
|
105
|
+
* 事件回调接口
|
|
106
|
+
*/
|
|
107
|
+
export interface CallBack {
|
|
108
|
+
/**
|
|
109
|
+
* 加载开始回调
|
|
110
|
+
* @param type 媒体类型
|
|
111
|
+
*/
|
|
112
|
+
onLoadStart?: (type: MediaType) => void;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* 播放状态变更回调
|
|
116
|
+
* @param event 状态变更事件
|
|
117
|
+
*/
|
|
118
|
+
onPlayStateChanged?: (event: {
|
|
119
|
+
/** 媒体类型 */
|
|
120
|
+
type: MediaType;
|
|
121
|
+
/** 播放状态 */
|
|
122
|
+
state: PlayState;
|
|
123
|
+
/** 变更原因 */
|
|
124
|
+
reason?: string;
|
|
125
|
+
}) => void;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 自动播放失败回调
|
|
129
|
+
* @param event 自动播放失败事件
|
|
130
|
+
*/
|
|
131
|
+
onAutoPlayFailed?: (event: {
|
|
132
|
+
/** 媒体类型 */
|
|
133
|
+
type: MediaType;
|
|
134
|
+
/** 恢复播放函数 */
|
|
135
|
+
resume: () => Promise<void>;
|
|
136
|
+
}) => void;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 错误回调
|
|
140
|
+
* @param error 错误对象
|
|
141
|
+
*/
|
|
142
|
+
onError?: (error: any) => void;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* SEI 消息回调
|
|
146
|
+
* @param event SEI 消息事件
|
|
147
|
+
*/
|
|
148
|
+
onSEIMessage?: (event: {
|
|
149
|
+
/** SEI 消息数据 */
|
|
150
|
+
data: ArrayBuffer;
|
|
151
|
+
/** SEI payload 类型 */
|
|
152
|
+
seiPayloadType: number;
|
|
153
|
+
}) => void;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 统计信息回调
|
|
157
|
+
* @param stats 媒体统计数据
|
|
158
|
+
*/
|
|
159
|
+
onStats?: (stats: MediaStats) => void;
|
|
27
160
|
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 启动 LEBPlayer 配置选项
|
|
164
|
+
*/
|
|
165
|
+
export interface StartLEBPlayerOption {
|
|
166
|
+
/** 播放容器,可以是容器 ID 或 HTMLElement */
|
|
167
|
+
view: string | HTMLElement;
|
|
168
|
+
|
|
169
|
+
/** 快直播拉流地址 */
|
|
170
|
+
url: string;
|
|
171
|
+
|
|
172
|
+
/** License 配置(可选) */
|
|
173
|
+
licenseConfig?: LicenseConfig;
|
|
174
|
+
|
|
175
|
+
/** 是否静音,默认 false */
|
|
176
|
+
muted?: boolean;
|
|
177
|
+
|
|
178
|
+
/** 音量大小,范围 0-500,默认 100 */
|
|
179
|
+
volume?: number;
|
|
180
|
+
|
|
181
|
+
/** 填充模式,默认 'contain' */
|
|
182
|
+
fillMode?: FillMode;
|
|
183
|
+
|
|
184
|
+
/** 日志配置 */
|
|
185
|
+
loggerConfig: {
|
|
186
|
+
/** SDK 应用 ID */
|
|
187
|
+
sdkAppId: number;
|
|
188
|
+
/** 用户 ID */
|
|
189
|
+
userId: string;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
/** 事件回调 */
|
|
193
|
+
callback?: CallBack;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* 更新 LEBPlayer 配置选项
|
|
198
|
+
*/
|
|
199
|
+
export interface UpdateLEBPlayerOption {
|
|
200
|
+
/** 播放容器 */
|
|
201
|
+
view?: string | HTMLElement;
|
|
202
|
+
|
|
203
|
+
/** 音量大小,范围 0-500 */
|
|
204
|
+
volume?: number;
|
|
205
|
+
|
|
206
|
+
/** 是否静音 */
|
|
207
|
+
muted?: boolean;
|
|
208
|
+
|
|
209
|
+
/** 填充模式 */
|
|
210
|
+
fillMode?: FillMode;
|
|
211
|
+
|
|
212
|
+
/** 播放器动作 */
|
|
213
|
+
action?: PlayerAction;
|
|
214
|
+
|
|
215
|
+
/** 是否全屏 */
|
|
216
|
+
fullScreen?: boolean;
|
|
217
|
+
|
|
218
|
+
/** 是否画中画 */
|
|
219
|
+
pictureInPicture?: boolean;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* 停止 LEBPlayer 配置选项
|
|
224
|
+
*/
|
|
225
|
+
// export interface StopLEBPlayerOption {}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* LEBPlayer 类
|
|
229
|
+
* 快直播拉流播放器
|
|
230
|
+
*/
|
|
231
|
+
export declare class LEBPlayer {
|
|
232
|
+
/** 插件名称 */
|
|
233
|
+
static Name: string;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* 启动快直播拉流
|
|
237
|
+
* @param option 启动配置选项
|
|
238
|
+
* @returns Promise
|
|
239
|
+
*/
|
|
240
|
+
start(option: StartLEBPlayerOption): Promise<void>;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* 更新播放器配置
|
|
244
|
+
* @param option 更新配置选项
|
|
245
|
+
* @returns Promise
|
|
246
|
+
*/
|
|
247
|
+
update(option: UpdateLEBPlayerOption): Promise<void>;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* 停止快直播拉流
|
|
251
|
+
* @param option 停止配置选项
|
|
252
|
+
* @returns Promise
|
|
253
|
+
*/
|
|
254
|
+
stop(): Promise<void>;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* 默认导出
|
|
259
|
+
*/
|
|
260
|
+
export default LEBPlayer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,r)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,__spreadValues=(e,t)=>{for(var r in t||(t={}))__hasOwnProp.call(t,r)&&__defNormalProp(e,r,t[r]);if(__getOwnPropSymbols)for(var r of __getOwnPropSymbols(t))__propIsEnum.call(t,r)&&__defNormalProp(e,r,t[r]);return e},__decorateClass=(e,t,r,i)=>{for(var o,n=i>1?void 0:i?__getOwnPropDesc(t,r):t,s=e.length-1;s>=0;s--)(o=e[s])&&(n=(i?o(t,r,n):o(n))||n);return i&&n&&__defProp(t,r,n),n},__publicField=(e,t,r)=>__defNormalProp(e,"symbol"!=typeof t?t+"":t,r),StartValidateRule={name:"option",required:!0,properties:{view:{type:["string",HTMLElement],required:!0},url:{type:"string",required:!0},licenseConfig:{type:"object",required:!1,properties:{secretKey:{type:"string",required:!0},encrypted:{type:"string",required:!0},signature:{type:"string",required:!0}}}}},updateSdpForFirefox=e=>{if(!navigator.userAgent.includes("Firefox"))return e;const t=e.split("\r\n"),r=[],i=[];t.forEach((e=>{const t=e.toLowerCase();t.includes("a=rtpmap")&&t.includes("h264")&&r.push(e)})),r.length>1&&i.push(...r.slice(1));const o=i.map((e=>{const t=/a=rtpmap:(\d+)\s/.exec(e);return t&&t.length>1?t[1]:null})).filter((e=>null!==e)),n=[];return t.forEach((e=>{let t=e;if(e.includes("a=setup")&&(t="a=setup:passive"),(e.includes("m=audio")||e.includes("m=video"))&&(t=e.split(" ").filter(((e,t)=>t<3||!o.includes(e))).join(" ")),e.includes("a=fmtp")||e.includes("a=rtcp-fb")||e.includes("a=rtpmap")){const t=/a=(?:fmtp|rtcp-fb|rtpmap):(\d+)\s/.exec(e);if(t&&t.length>1&&o.includes(t[1]))return}n.push(t)})),n.join("\r\n")},updateSdpRestriction=e=>{const t=e.split("\r\n"),r=[];t.forEach((e=>{const t=e.toLowerCase();t.includes("a=rtpmap")&&t.includes("h264")&&r.push(e)}));const i=r.map((e=>{const t=/a=rtpmap:(\d+)\s/.exec(e);return t&&t.length>1?t[1]:null})).filter((e=>null!==e)),o=[];t.forEach((e=>{let t=e;if(e.includes("a=fmtp:111")&&(t=`${e};stereo=1`),e.includes("a=fmtp")){const r=/a=fmtp:(\d+)\s/.exec(e);r&&r.length>1&&i.includes(r[1])&&(t=`${e};sps-pps-idr-in-keyframe=1`)}o.push(t)}));const n=o.join("\r\n");return updateSdpForFirefox(n)},urlAlphabet="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",nanoid=(e=21)=>{let t="",r=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=urlAlphabet[63&r[e]];return t},isFunction=e=>"function"==typeof e,RETRY_STATE_NOT_START=0,RETRY_STATE_STARTED=1,RETRY_STATE_STOPPED=2;function promiseRetry({retryFunction:e,settings:t,onError:r,onRetrying:i,onRetryFailed:o,onRetrySuccess:n,context:s}){return function(...a){const{retries:l=5,timeout:c=1e3}=t;let d=0,u=-1,p=RETRY_STATE_NOT_START;const h=async(t,y)=>{const m=s||this;try{const r=await e.apply(m,a);d>0&&n&&n.call(this,d),d=0,t(r)}catch(e){const n=()=>{clearTimeout(u),d=0,p=RETRY_STATE_STOPPED,y(e)},s=()=>{p!==RETRY_STATE_STOPPED&&d<(isFunction(l)?l():l)?(d++,p=RETRY_STATE_STARTED,isFunction(i)&&i.call(this,d,n),u=window.setTimeout((()=>{u=-1,h(t,y)}),isFunction(c)?c(d):c)):(n(),isFunction(o)&&o.call(this,e))};isFunction(r)?r.call(this,{error:e,retry:s,reject:y,retryFuncArgs:a,retriedCount:d}):s()}};return new Promise(h)}}var retry_default=promiseRetry,retryingMap=new WeakMap;function addPromiseRetry({settings:e={retries:5,timeout:2e3},onError:t,onRetrying:r,onRetryFailed:i}){return function(o,n,s){const a=retry_default({retryFunction:s.value,settings:e,onError({error:e,retry:r,reject:i,retryFuncArgs:s}){var a;t?t.call(this,e,(()=>{var t;(null==(t=retryingMap.get(o))?void 0:t.has(n))?r():i(e)}),i,s):(null==(a=retryingMap.get(o))?void 0:a.has(n))?r():i(e)},onRetrying(e,t){var i;isFunction(r)&&r.call(this,e,t),(null==(i=retryingMap.get(o))?void 0:i.has(n))&&(retryingMap.get(o).get(n).stopRetry=t)},onRetryFailed:i});return s.value=function(...e){const t=retryingMap.get(o);return t?t.set(n,{args:e}):retryingMap.set(o,new Map([[n,{args:e}]])),a.apply(this,e).finally((()=>{var e;return null==(e=retryingMap.get(o))?void 0:e.delete(n)}))},s}}function removePromiseRetry({fnName:e,callback:t,validateArgs:r=!0}){return function(i,o,n){const s=n.value;return n.value=function(...o){var n,a;if(null==(n=retryingMap.get(i))?void 0:n.has(e)){const{stopRetry:n,args:s}=retryingMap.get(i).get(e);let l=!0;if(r)for(const e of s)if(!o.find((t=>t===e))){l=!1;break}l&&(t&&t.apply(this,o),n&&n(),null==(a=retryingMap.get(i))||a.delete(e))}return s.apply(this,o)},n}}var SIGNAL_DOMAIN_NAME_LIST=["overseas-webrtc.tlivewebrtc.com","oswebrtc-lint.tliveplay.com"],_LEBPlayer=class e{constructor(e){this.core=e,__publicField(this,"connectedRoomIdSet",new Set),__publicField(this,"updateSeq",0),__publicField(this,"_log"),__publicField(this,"audioPlayer"),__publicField(this,"videoPlayer"),__publicField(this,"peerConnection"),__publicField(this,"svrSig"),__publicField(this,"streamURL"),__publicField(this,"signalURL"),__publicField(this,"insertableStreamsAbortMap",new Map),__publicField(this,"scriptTransformWorker"),__publicField(this,"connectionState","disconnected"),__publicField(this,"isStarted",!1),__publicField(this,"isStopped",!0),__publicField(this,"isReconnecting",!1),__publicField(this,"callback"),e.loggerManager.startUpload(),this._log=this.core.log.createChild({id:`${this.getAlias()}`}),this.videoPlayer=new e.VideoPlayer({id:"vp",log:this._log.createChild({id:"vp"}),track:null,muted:!1,container:null}),this.audioPlayer=new e.RemoteAudioPlayer({id:"ap",log:this._log.createChild({id:"ap"}),track:null,muted:!1,container:null,enableVolumeControlInIOS:!0}),this.videoPlayer.on("loadstart",(()=>{var e,t;return null==(t=null==(e=this.callback)?void 0:e.onLoadStart)?void 0:t.call(e,"video")})),this.audioPlayer.on("loadstart",(()=>{var e,t;return null==(t=null==(e=this.callback)?void 0:e.onLoadStart)?void 0:t.call(e,"audio")})),this.videoPlayer.on("player-state-changed",(e=>{var t,r;null==(r=null==(t=this.callback)?void 0:t.onVideoPlayStateChanged)||r.call(t,{state:e.state,reason:e.reason})})),this.audioPlayer.on("player-state-changed",(e=>{var t,r;null==(r=null==(t=this.callback)?void 0:t.onAudioPlayStateChanged)||r.call(t,{state:e.state,reason:e.reason})})),e.innerEmitter.on(e.INNER_EVENT.SEI_MESSAGE,this.onSEIMessage,this)}getName(){return e.Name}getAlias(){return"LEB"}getGroup(){return""}getValidateRule(e){switch(e){case"start":return StartValidateRule;case"update":case"stop":return{}}}get enableSEI(){return this.core.room.enableSEI&&(this.core.rtcDectection.IS_INSERTABLE_STREAM_SUPPORTED||this.core.rtcDectection.IS_SCRIPT_TRANSFORM_SUPPORTED)}async start(e){this.isStopped=!1;const{view:t,url:r,volume:i,muted:o,fillMode:n,loggerConfig:s,callback:a}=e;if(this.callback=a,this.core.loggerManager.addJoinedUser(s),this.core.utils.isString(t)){const e=document.getElementById(t);e&&this.videoPlayer.setContainer(e)}this.setMuted(o),this.setVolume(i),n&&this.videoPlayer.setObjectFit(n),await this.connect(r),this.videoPlayer.play().catch((e=>{var t,r;this.handleAutoPlayFailed(this.audioPlayer,e),null==(r=null==(t=this.callback)?void 0:t.onAutoPlayFailed)||r.call(t,{type:"video",resume:()=>this.videoPlayer.resume()})})),this.audioPlayer.play().catch((e=>{var t,r;this.handleAutoPlayFailed(this.audioPlayer,e),null==(r=null==(t=this.callback)?void 0:t.onAutoPlayFailed)||r.call(t,{type:"audio",resume:()=>this.audioPlayer.resume()})})),this.isStarted=!0}handleAutoPlayFailed(e,t){this._log.warn("handleAutoPlayFailed",t);const r=()=>{this.audioPlayer.resume().then((()=>{document.removeEventListener("click",r,!0)}))};document.addEventListener("click",r,!0)}async connect(e){return new Promise((async(t,r)=>{this.initScriptTransformWorker();const i=new RTCPeerConnection({iceServers:[],sdpSemantics:"unified-plan",bundlePolicy:"max-bundle",rtcpMuxPolicy:"require",tcpCandidatePolicy:"disable",IceTransportsType:"nohost",enableInsertableStreams:this.enableSEI});this.peerConnection=i,i.onconnectionstatechange=()=>{this.connectionState=i.connectionState,this._log.info("connectionState",i.connectionState),"failed"!==i.connectionState&&"closed"!==i.connectionState||(this.isStarted?this.reconnect(e):r(`connection is ${i.connectionState}`)),"connected"===i.connectionState&&(this.logSelectedCandidate(),t())},i.ontrack=this.onTrack.bind(this);const o=i.addTransceiver("audio",{direction:"recvonly"}),n=i.addTransceiver("video",{direction:"recvonly"});this.createEncodedStreams(o.receiver),this.createEncodedStreams(n.receiver),this.initReceiverTransform(o.receiver,!0),this.initReceiverTransform(n.receiver,!1),this._log.info("createOffer");const s=await i.createOffer({offerToReceiveAudio:!0,offerToReceiveVideo:!0,voiceActivityDetection:!1});s.sdp=updateSdpRestriction(s.sdp),this._log.info("setOffer"),await i.setLocalDescription(s);const a={sessionId:nanoid(),streamurl:e,clientinfo:this.core.environment.getOSString(),localsdp:i.localDescription},{url:l,remoteSdp:c,svrSig:d}=await this.core.utils.promiseAny(SIGNAL_DOMAIN_NAME_LIST.map((e=>this.exchangeSDP(`https://${e}`,a,3))));this.streamURL=e,this.signalURL=l,this.svrSig=d,this._log.info("setAnswer"),await i.setRemoteDescription(c),setTimeout((()=>r("connection timeout")),1e4)}))}async reconnect(e){if(!this.isReconnecting){this.isReconnecting=!0;try{this._log.warn("start reconnect"),await this.connect(e),this._log.warn("reconnect success")}catch(e){this._log.error("reconnect error",e)}finally{this.isReconnecting=!1}}}async logSelectedCandidate(){if(!this.peerConnection)return;const e=await this.peerConnection.getStats();for(const[t,r]of e)if(this.core.rtcDectection.isSelectedCandidatePair(r)){const t=e.get(r.localCandidateId),i=e.get(r.remoteCandidateId);t&&this._log.info(`local candidate: ${t.candidateType} ${t.protocol}:${t.ip||t.address}:${t.port} ${t.networkType||""} ${t.relayProtocol?`relayProtocol:${t.relayProtocol} url: ${t.url}`:""}`),i&&this._log.info(`remote candidate: ${i.candidateType} ${i.protocol}:${i.ip||i.address}:${i.port}`);break}}async exchangeSDP(e,t,r){const i=`${e}/webrtc/v1/pullstream`,o=await fetchPost(i,t,{timeout:r}),{errcode:n,errmsg:s,remotesdp:a,svrsig:l}=o;if(0!==n){const e=new Error(`errCode:${n}, errMsg:${s}`);throw e.name="RequestSignalError",e}return{url:e,remoteSdp:a,svrSig:l}}createEncodedStreams(e){var t;if(this.core.rtcDectection.IS_INSERTABLE_STREAM_SUPPORTED&&!this.insertableStreamsAbortMap.has(e)){const r=e.createEncodedStreams(),i=new AbortController,o={abortController:i,enqueue:t=>"audio"===e.track.kind?t:this.decodeVideoFrame(t)};r.readable.pipeThrough(new TransformStream({transform:(e,t)=>{const r=o.enqueue(e);r&&t.enqueue(r)}})).pipeTo(r.writable,i).catch((e=>{"destroy"!==e&&this._log.warn(e)})),null==(t=this.insertableStreamsAbortMap.get(e))||t.abort("destroy"),this.insertableStreamsAbortMap.set(e,i)}}initReceiverTransform(e,t){this.peerConnection&&this.scriptTransformWorker&&!e.transform&&(e.transform=new RTCRtpScriptTransform(this.scriptTransformWorker,{isReceiver:!0,isAudio:t,userId:"",streamType:this.core.enums.RemoteStreamType.Main}))}initScriptTransformWorker(){const{room:e,rtcDectection:t,createScriptTransformWorker:r,trtc:i,TRTC:o}=this.core;!this.enableSEI||t.IS_INSERTABLE_STREAM_SUPPORTED||this.scriptTransformWorker||t.IS_SCRIPT_TRANSFORM_SUPPORTED&&(this.scriptTransformWorker=r({videoEncodePipeline:e.videoManager.encodePipeline,videoDecodePipeline:e.videoManager.decodePipeline,audioEncodePipeline:e.audioManager.encodePipeline,audioDecodePipeline:e.audioManager.decodePipeline}),this.scriptTransformWorker.onmessage=e=>{"sei"===e.data.type&&i.emit(o.EVENT.SEI_MESSAGE,e.data)},this.scriptTransformWorker.onerror=e=>{this._log.error("scriptTransformWorker error: ",e.message)})}decodeVideoFrame(e){if(!this.core.room.videoManager)return e;for(const t of this.core.room.videoManager.decodePipeline)if(t&&!(e=t({frame:e})))return;return e}async fetchStopStream(){if(!this.streamURL||!this.svrSig||!this.signalURL)return;const e=`${this.signalURL}/webrtc/v1/stopstream`,t=await fetchPost(e,{streamurl:this.streamURL,svrsig:this.svrSig},{timeout:3}),{errcode:r,errmsg:i}=t;if(0!==r)throw new Error(`errCode:${r}, errmsg:${i}`);return t}onTrack(e){const{track:t}=e;"audio"===t.kind?this.audioPlayer.setTrack(t):this.videoPlayer.setTrack(t)}async update(e){const{volume:t,muted:r,fillMode:i,action:o,fullScreen:n,pictureInPicture:s}=e;this.setMuted(r),this.setVolume(t),i&&this.videoPlayer.setObjectFit(i),"pause"===o?(this.videoPlayer.pause(),this.audioPlayer.pause()):"resume"===o&&(this.videoPlayer.resume(),this.audioPlayer.resume()),this.core.utils.isBoolean(n)&&(n?await this.videoPlayer.enterFullscreen():await this.videoPlayer.exitFullscreen()),this.core.utils.isBoolean(s)&&(s?await this.videoPlayer.enterPictureInPicture():await this.videoPlayer.exitPictureInPicture())}async stop(){this.isStopped=!0,this.videoPlayer&&this.videoPlayer.stop(),this.audioPlayer&&this.audioPlayer.stop(),this.peerConnection&&(this.peerConnection.close(),delete this.peerConnection,await this.fetchStopStream(),delete this.streamURL,delete this.signalURL,delete this.svrSig)}setVolume(e){this.core.utils.isUndefined(e)||this.audioPlayer.setVolume(e/100)}setMuted(e){this.core.utils.isUndefined(e)||this.audioPlayer.setMuted(e)}destroy(){this.stop(),this.core.innerEmitter.off(this.core.INNER_EVENT.SEI_MESSAGE,this.onSEIMessage,this)}onSEIMessage({room:e,nalu:t}){var r,i;e===this.core.room&&(null==(i=null==(r=this.callback)?void 0:r.onSEIMessage)||i.call(r,{data:t.seiPayload.buffer,seiPayloadType:t.seiPayloadType}))}};__publicField(_LEBPlayer,"Name","LEBPlayer"),__decorateClass([addPromiseRetry({settings:{retries:1/0,timeout:2e3},onRetrying(e){this._log.warn(`retry connect ${e}`)},onError(e,t,r,i){this._log.warn("connect failed",e),this.peerConnection&&(this.peerConnection.close(),delete this.peerConnection),this.isStopped||t()}})],_LEBPlayer.prototype,"connect",1),__decorateClass([removePromiseRetry({fnName:"connect"})],_LEBPlayer.prototype,"stop",1);var LEBPlayer=_LEBPlayer,fetchPost=async(e,t,r={})=>{const{timeout:i=10}=r;let o,n=0,s={};window.AbortController&&(o=new window.AbortController,s={signal:o.signal},n=window.setTimeout((()=>o.abort()),1e3*i));const a=await fetch(e,__spreadValues({body:JSON.stringify(t),cache:"no-cache",credentials:"same-origin",headers:{"content-type":"text/plain;charset=utf-8"},method:"POST",mode:"cors"},s));if(n&&window.clearTimeout(n),200!==a.status)throw new Error(`Network Error, status code:${a.status}`);return a.json()},index_default=LEBPlayer;export{index_default as default};export{LEBPlayer};
|
|
1
|
+
var __create=Object.create,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__getOwnPropSymbols=Object.getOwnPropertySymbols,__getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,r)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,__spreadValues=(e,t)=>{for(var r in t||(t={}))__hasOwnProp.call(t,r)&&__defNormalProp(e,r,t[r]);if(__getOwnPropSymbols)for(var r of __getOwnPropSymbols(t))__propIsEnum.call(t,r)&&__defNormalProp(e,r,t[r]);return e},__commonJS=(e,t)=>function(){return t||(0,e[__getOwnPropNames(e)[0]])((t={exports:{}}).exports,t),t.exports},__copyProps=(e,t,r,i)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let s of __getOwnPropNames(t))__hasOwnProp.call(e,s)||s===r||__defProp(e,s,{get:()=>t[s],enumerable:!(i=__getOwnPropDesc(t,s))||i.enumerable});return e},__toESM=(e,t,r)=>(r=null!=e?__create(__getProtoOf(e)):{},__copyProps(!t&&e&&e.__esModule?r:__defProp(r,"default",{value:e,enumerable:!0}),e)),__decorateClass=(e,t,r,i)=>{for(var s,o=i>1?void 0:i?__getOwnPropDesc(t,r):t,a=e.length-1;a>=0;a--)(s=e[a])&&(o=(i?s(t,r,o):s(o))||o);return i&&o&&__defProp(t,r,o),o},__publicField=(e,t,r)=>__defNormalProp(e,"symbol"!=typeof t?t+"":t,r),require_eventemitter3=__commonJS({"../node_modules/.pnpm/eventemitter3@4.0.7/node_modules/eventemitter3/index.js"(e,t){"use strict";var r=Object.prototype.hasOwnProperty,i="~";function s(){}function o(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function a(e,t,r,s,a){if("function"!=typeof r)throw new TypeError("The listener must be a function");var n=new o(r,s||e,a),c=i?i+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],n]:e._events[c].push(n):(e._events[c]=n,e._eventsCount++),e}function n(e,t){0==--e._eventsCount?e._events=new s:delete e._events[t]}function c(){this._events=new s,this._eventsCount=0}Object.create&&(s.prototype=Object.create(null),(new s).__proto__||(i=!1)),c.prototype.eventNames=function(){var e,t,s=[];if(0===this._eventsCount)return s;for(t in e=this._events)r.call(e,t)&&s.push(i?t.slice(1):t);return Object.getOwnPropertySymbols?s.concat(Object.getOwnPropertySymbols(e)):s},c.prototype.listeners=function(e){var t=i?i+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var s=0,o=r.length,a=new Array(o);s<o;s++)a[s]=r[s].fn;return a},c.prototype.listenerCount=function(e){var t=i?i+e:e,r=this._events[t];return r?r.fn?1:r.length:0},c.prototype.emit=function(e,t,r,s,o,a){var n=i?i+e:e;if(!this._events[n])return!1;var c,l,d=this._events[n],u=arguments.length;if(d.fn){switch(d.once&&this.removeListener(e,d.fn,void 0,!0),u){case 1:return d.fn.call(d.context),!0;case 2:return d.fn.call(d.context,t),!0;case 3:return d.fn.call(d.context,t,r),!0;case 4:return d.fn.call(d.context,t,r,s),!0;case 5:return d.fn.call(d.context,t,r,s,o),!0;case 6:return d.fn.call(d.context,t,r,s,o,a),!0}for(l=1,c=new Array(u-1);l<u;l++)c[l-1]=arguments[l];d.fn.apply(d.context,c)}else{var p,h=d.length;for(l=0;l<h;l++)switch(d[l].once&&this.removeListener(e,d[l].fn,void 0,!0),u){case 1:d[l].fn.call(d[l].context);break;case 2:d[l].fn.call(d[l].context,t);break;case 3:d[l].fn.call(d[l].context,t,r);break;case 4:d[l].fn.call(d[l].context,t,r,s);break;default:if(!c)for(p=1,c=new Array(u-1);p<u;p++)c[p-1]=arguments[p];d[l].fn.apply(d[l].context,c)}}return!0},c.prototype.on=function(e,t,r){return a(this,e,t,r,!1)},c.prototype.once=function(e,t,r){return a(this,e,t,r,!0)},c.prototype.removeListener=function(e,t,r,s){var o=i?i+e:e;if(!this._events[o])return this;if(!t)return n(this,o),this;var a=this._events[o];if(a.fn)a.fn!==t||s&&!a.once||r&&a.context!==r||n(this,o);else{for(var c=0,l=[],d=a.length;c<d;c++)(a[c].fn!==t||s&&!a[c].once||r&&a[c].context!==r)&&l.push(a[c]);l.length?this._events[o]=1===l.length?l[0]:l:n(this,o)}return this},c.prototype.removeAllListeners=function(e){var t;return e?(t=i?i+e:e,this._events[t]&&n(this,t)):(this._events=new s,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=i,c.EventEmitter=c,void 0!==t&&(t.exports=c)}}),StartValidateRule={name:"option",required:!0,properties:{view:{type:["string",HTMLElement],required:!0},url:{type:"string",required:!0},muted:{type:"boolean",required:!1},volume:{type:"number",required:!1},fillMode:{type:"string",required:!1,values:["contain","cover","fill"]},loggerConfig:{type:"object",required:!0,properties:{sdkAppId:{type:"number",required:!0},userId:{type:"string",required:!0}}}}},UpdateValidateRule={name:"option",required:!0,properties:{view:{type:["string",HTMLElement],required:!1},volume:{type:"number",required:!1},muted:{type:"boolean",required:!1},fillMode:{type:"string",required:!1,values:["contain","cover","fill"]},action:{type:"string",required:!1,values:["pause","resume"]},fullScreen:{type:"boolean",required:!1},pictureInPicture:{type:"boolean",required:!1}}},updateSdpForFirefox=e=>{if(!navigator.userAgent.includes("Firefox"))return e;const t=e.split("\r\n"),r=[],i=[];t.forEach((e=>{const t=e.toLowerCase();t.includes("a=rtpmap")&&t.includes("h264")&&r.push(e)})),r.length>1&&i.push(...r.slice(1));const s=i.map((e=>{const t=/a=rtpmap:(\d+)\s/.exec(e);return t&&t.length>1?t[1]:null})).filter((e=>null!==e)),o=[];return t.forEach((e=>{let t=e;if(e.includes("a=setup")&&(t="a=setup:passive"),(e.includes("m=audio")||e.includes("m=video"))&&(t=e.split(" ").filter(((e,t)=>t<3||!s.includes(e))).join(" ")),e.includes("a=fmtp")||e.includes("a=rtcp-fb")||e.includes("a=rtpmap")){const t=/a=(?:fmtp|rtcp-fb|rtpmap):(\d+)\s/.exec(e);if(t&&t.length>1&&s.includes(t[1]))return}o.push(t)})),o.join("\r\n")},updateSdpRestriction=e=>{const t=e.split("\r\n"),r=[];t.forEach((e=>{const t=e.toLowerCase();t.includes("a=rtpmap")&&t.includes("h264")&&r.push(e)}));const i=r.map((e=>{const t=/a=rtpmap:(\d+)\s/.exec(e);return t&&t.length>1?t[1]:null})).filter((e=>null!==e)),s=[];t.forEach((e=>{let t=e;if(e.includes("a=fmtp:111")&&(t=`${e};stereo=1`),e.includes("a=fmtp")){const r=/a=fmtp:(\d+)\s/.exec(e);r&&r.length>1&&i.includes(r[1])&&(t=`${e};sps-pps-idr-in-keyframe=1`)}s.push(t)}));const o=s.join("\r\n");return updateSdpForFirefox(o)},urlAlphabet="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",nanoid=(e=21)=>{let t="",r=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=urlAlphabet[63&r[e]];return t},isFunction=e=>"function"==typeof e,RETRY_STATE_NOT_START=0,RETRY_STATE_STARTED=1,RETRY_STATE_STOPPED=2;function promiseRetry({retryFunction:e,settings:t,onError:r,onRetrying:i,onRetryFailed:s,onRetrySuccess:o,context:a}){return function(...n){const{retries:c=5,timeout:l=1e3}=t;let d=0,u=-1,p=RETRY_STATE_NOT_START;const h=async(t,f)=>{const v=a||this;try{const r=await e.apply(v,n);d>0&&o&&o.call(this,d),d=0,t(r)}catch(e){const o=()=>{clearTimeout(u),d=0,p=RETRY_STATE_STOPPED,f(e)},a=()=>{p!==RETRY_STATE_STOPPED&&d<(isFunction(c)?c():c)?(d++,p=RETRY_STATE_STARTED,isFunction(i)&&i.call(this,d,o),u=window.setTimeout((()=>{u=-1,h(t,f)}),isFunction(l)?l(d):l)):(o(),isFunction(s)&&s.call(this,e))};isFunction(r)?r.call(this,{error:e,retry:a,reject:f,retryFuncArgs:n,retriedCount:d}):a()}};return new Promise(h)}}var retry_default=promiseRetry,retryingMap=new WeakMap;function addPromiseRetry({settings:e={retries:5,timeout:2e3},onError:t,onRetrying:r,onRetryFailed:i}){return function(s,o,a){const n=retry_default({retryFunction:a.value,settings:e,onError({error:e,retry:r,reject:i,retryFuncArgs:a}){var n;t?t.call(this,e,(()=>{var t;(null==(t=retryingMap.get(s))?void 0:t.has(o))?r():i(e)}),i,a):(null==(n=retryingMap.get(s))?void 0:n.has(o))?r():i(e)},onRetrying(e,t){var i;isFunction(r)&&r.call(this,e,t),(null==(i=retryingMap.get(s))?void 0:i.has(o))&&(retryingMap.get(s).get(o).stopRetry=t)},onRetryFailed:i});return a.value=function(...e){const t=retryingMap.get(s);return t?t.set(o,{args:e}):retryingMap.set(s,new Map([[o,{args:e}]])),n.apply(this,e).finally((()=>{var e;return null==(e=retryingMap.get(s))?void 0:e.delete(o)}))},a}}function removePromiseRetry({fnName:e,callback:t,validateArgs:r=!0}){return function(i,s,o){const a=o.value;return o.value=function(...s){var o,n;if(null==(o=retryingMap.get(i))?void 0:o.has(e)){const{stopRetry:o,args:a}=retryingMap.get(i).get(e);let c=!0;if(r)for(const e of a)if(!s.find((t=>t===e))){c=!1;break}c&&(t&&t.apply(this,s),o&&o(),null==(n=retryingMap.get(i))||n.delete(e))}return a.apply(this,s)},o}}var Stat=class{constructor(e,t){this.core=t,__publicField(this,"peerConnection"),__publicField(this,"audioTransceiver",null),__publicField(this,"videoTransceiver",null),__publicField(this,"timerId",null),__publicField(this,"callback",null),__publicField(this,"previousRawStats",null),__publicField(this,"_prevReportTime",0),__publicField(this,"_prevDecoderImplementation",""),__publicField(this,"_decodeMap",new Map),this.peerConnection=e,this.findTransceivers()}get statInterval(){return 0===this._prevReportTime?2:(Date.now()-this._prevReportTime)/1e3}findTransceivers(){const e=this.peerConnection.getTransceivers();for(const t of e)if(t.receiver&&t.receiver.track){const{track:e}=t.receiver;"audio"===e.kind?this.audioTransceiver=t:"video"===e.kind&&(this.videoTransceiver=t)}}start(e,t=2e3){this.stop(),this.callback=e,this.collectStats(),this.timerId=window.setInterval((()=>{this.collectStats()}),t)}stop(){null!==this.timerId&&(clearInterval(this.timerId),this.timerId=null),this.callback=null,this.previousRawStats=null,this._prevReportTime=0}async collectStats(){if(this.callback)try{const e=await this.peerConnection.getStats(),t=new Set(["inbound-rtp","track","candidate-pair","media-source","codec"]),r=[];e.forEach((e=>t.has(e.type)&&r.push(e)));const i=Date.now(),s=this.parseAudioStats(r),o=this.parseVideoStats(r),a=this.parseNetworkStats(r);this._prevReportTime=i,this.callback({audio:s,video:o,network:a})}catch(e){this.core.log.error("Failed to collect WebRTC stats:",e)}}getDifferenceValue(e,t){if(this.core.utils.isUndefined(e))return t;const r=(t||0)-e;return r<0?0:r}parseAudioStats(e){var t,r,i,s;const o={bitrate:0,volume:0,packetLossRate:0,jitterBufferDelay:0,bytesReceived:0,packetsReceived:0,packetsLost:0};for(const a of e){if("inbound-rtp"===a.type&&("audio"===a.mediaType||"audio"===a.kind)){if(o.bytesReceived=a.bytesReceived||0,o.packetsReceived=a.packetsReceived||0,o.packetsLost=a.packetsLost||0,this.previousRawStats&&this.previousRawStats.audio){const e=this.getDifferenceValue(this.previousRawStats.audio.bytesReceived,o.bytesReceived);o.bitrate=Math.round(8*e/this.statInterval/1e3)}const e=this.getDifferenceValue(null==(t=this.previousRawStats)?void 0:t.audio.packetsLost,o.packetsLost),s=this.getDifferenceValue(null==(r=this.previousRawStats)?void 0:r.audio.packetsReceived,o.packetsReceived)+e;if(s>0&&(o.packetLossRate=Math.round(e/s*100)),this.core.utils.isUndefined(a.audioLevel)||(o.volume=a.audioLevel||0),a.jitterBufferDelay&&a.jitterBufferEmittedCount){let{jitterBufferEmittedCount:e}=a,{jitterBufferDelay:t}=a;(null==(i=this.previousRawStats)?void 0:i.audio)&&(e=this.getDifferenceValue(this.previousRawStats.audio.jitterBufferEmittedCount,a.jitterBufferEmittedCount),t=this.getDifferenceValue(this.previousRawStats.audio.jitterBufferDelay,a.jitterBufferDelay)),e>0&&(o.jitterBufferDelay=Math.floor(t/e*1e3)),this.previousRawStats||this.initPreviousRawStats(),this.previousRawStats.audio.jitterBufferDelay=a.jitterBufferDelay,this.previousRawStats.audio.jitterBufferEmittedCount=a.jitterBufferEmittedCount}this.previousRawStats||this.initPreviousRawStats(),this.previousRawStats.audio.bytesReceived=o.bytesReceived,this.previousRawStats.audio.packetsReceived=o.packetsReceived,this.previousRawStats.audio.packetsLost=o.packetsLost}!this.core.utils.isUndefined(a.audioLevel)&&(null==(s=this.audioTransceiver)?void 0:s.receiver.track)&&a.trackIdentifier===this.audioTransceiver.receiver.track.id&&(o.volume=a.audioLevel||0)}return o}parseVideoStats(e){var t,r,i,s,o;const a={bitrate:0,frameRate:0,width:0,height:0,packetLossRate:0,jitterBufferDelay:0,bytesReceived:0,packetsReceived:0,packetsLost:0,framesDecoded:0};for(const n of e){if("codec"===n.type&&this._decodeMap.set(n.id,n),"inbound-rtp"===n.type&&("video"===n.mediaType||"video"===n.kind)){if(a.bytesReceived=n.bytesReceived||0,a.packetsReceived=n.packetsReceived||0,a.packetsLost=n.packetsLost||0,a.framesDecoded=n.framesDecoded||0,this.core.utils.isUndefined(n.framesPerSecond)||(a.frameRate=Math.round(n.framesPerSecond)),n.decoderImplementation&&this._prevDecoderImplementation!==n.decoderImplementation){const e=this._decodeMap.get(n.codecId),r=(null==(t=null==e?void 0:e.mimeType)?void 0:t.split("/")[1])||"unknown",i=n.powerEfficientDecoder;this.core.log.info(`decoderImplementation change to ${n.decoderImplementation}(${r}) HWDecoder: ${i}`),this._prevDecoderImplementation=n.decoderImplementation}if(this.previousRawStats&&this.previousRawStats.video){const e=this.getDifferenceValue(this.previousRawStats.video.bytesReceived,a.bytesReceived);a.bitrate=Math.round(8*e/this.statInterval/1e3)}const e=this.getDifferenceValue(null==(r=this.previousRawStats)?void 0:r.video.packetsLost,a.packetsLost),o=this.getDifferenceValue(null==(i=this.previousRawStats)?void 0:i.video.packetsReceived,a.packetsReceived)+e;if(o>0&&(a.packetLossRate=Math.round(e/o*100)),n.jitterBufferDelay&&n.jitterBufferEmittedCount){let{jitterBufferEmittedCount:e}=n,{jitterBufferDelay:t}=n;(null==(s=this.previousRawStats)?void 0:s.video)&&(e=this.getDifferenceValue(this.previousRawStats.video.jitterBufferEmittedCount,n.jitterBufferEmittedCount),t=this.getDifferenceValue(this.previousRawStats.video.jitterBufferDelay,n.jitterBufferDelay)),e>0&&(a.jitterBufferDelay=Math.floor(t/e*1e3)),this.previousRawStats||this.initPreviousRawStats(),this.previousRawStats.video.jitterBufferDelay=n.jitterBufferDelay,this.previousRawStats.video.jitterBufferEmittedCount=n.jitterBufferEmittedCount}this.previousRawStats||this.initPreviousRawStats(),this.previousRawStats.video.bytesReceived=a.bytesReceived,this.previousRawStats.video.packetsReceived=a.packetsReceived,this.previousRawStats.video.packetsLost=a.packetsLost}!this.core.utils.isUndefined(n.frameWidth)&&(null==(o=this.videoTransceiver)?void 0:o.receiver.track)&&n.trackIdentifier===this.videoTransceiver.receiver.track.id&&(a.width=n.frameWidth,a.height=n.frameHeight)}return a}parseNetworkStats(e){const t={rtt:0};for(const r of e)if("candidate-pair"===r.type){if((r.selected||"succeeded"===r.state)&&this.core.utils.isNumber(r.currentRoundTripTime)){t.rtt=Math.floor(1e3*r.currentRoundTripTime);break}}return t}initPreviousRawStats(){this.previousRawStats={timestamp:Date.now(),audio:{bytesReceived:0,packetsReceived:0,packetsLost:0},video:{bytesReceived:0,packetsReceived:0,packetsLost:0}}}},import_eventemitter3=__toESM(require_eventemitter3(),1),instance=Symbol("instance"),abortCtrl=Symbol("abortCtrl"),cacheResult=Symbol("cacheResult"),MiddleState=class{constructor(e,t,r){this.oldState=e,this.newState=t,this.action=r,this.aborted=!1}abort(e){this.aborted=!0,setState.call(e,this.oldState,new Error(`action '${this.action}' aborted`))}toString(){return`${this.action}ing`}},FSMError=class extends Error{constructor(e,t,r){super(t),this.state=e,this.message=t,this.cause=r}};function thenAble(e){return"object"==typeof e&&e&&"then"in e}var stateDiagram=new Map;function ChangeState(e,t,r={}){return(i,s,o)=>{const a=r.action||s;if(!r.context){const r=stateDiagram.get(i)||[];stateDiagram.has(i)||stateDiagram.set(i,r),r.push({from:e,to:t,action:a})}const n=o.value;o.value=function(...i){let s=this;if(r.context&&(s=FSM.get("function"==typeof r.context?r.context.call(this,...i):r.context)),s.state===t)return r.sync?s[cacheResult]:Promise.resolve(s[cacheResult]);s.state instanceof MiddleState&&s.state.action==r.abortAction&&s.state.abort(s);let o=null;Array.isArray(e)?0==e.length?s.state instanceof MiddleState&&s.state.abort(s):"string"==typeof s.state&&e.includes(s.state)||(o=new FSMError(s._state,`${s.name} ${a} to ${t} failed: current state ${s._state} not from ${e.join("|")}`)):e!==s.state&&(o=new FSMError(s._state,`${s.name} ${a} to ${t} failed: current state ${s._state} not from ${e}`));const c=e=>{if(r.fail&&r.fail.call(this,e),r.sync){if(r.ignoreError)return e;throw e}return r.ignoreError?Promise.resolve(e):Promise.reject(e)};if(o)return c(o);const l=s.state,d=new MiddleState(l,t,a);setState.call(s,d);const u=e=>{var i;return s[cacheResult]=e,d.aborted||(setState.call(s,t),null===(i=r.success)||void 0===i||i.call(this,s[cacheResult])),e},p=e=>(setState.call(s,l,e),c(e));try{const e=n.apply(this,i);return thenAble(e)?e.then(u).catch(p):r.sync?u(e):Promise.resolve(u(e))}catch(r){return p(new FSMError(s._state,`${s.name} ${a} from ${e} to ${t} failed: ${r}`,r instanceof Error?r:new Error(String(r))))}}}}var sendDevTools=(()=>{const e="undefined"!=typeof window&&window.__AFSM__,t="undefined"!=typeof importScripts;return e?(e,t)=>{window.dispatchEvent(new CustomEvent(e,{detail:t}))}:t?(e,t)=>{postMessage({type:e,payload:t})}:()=>{}})();function setState(e,t){const r=this._state;this._state=e;const i=e.toString();e&&this.emit(i,r),this.emit(FSM.STATECHANGED,e,r,t),this.updateDevTools({value:e,old:r,err:t instanceof Error?t.message:String(t)})}var FSM=class e extends import_eventemitter3.default{constructor(t,r,i){super(),this.name=t,this.groupName=r,this._state=e.INIT,t||(t=Date.now().toString(36)),i?Object.setPrototypeOf(this,i):i=Object.getPrototypeOf(this),r||(this.groupName=this.constructor.name);const s=i[instance];s?this.name=s.name+"-"+s.count++:i[instance]={name:this.name,count:0},this.updateDevTools({diagram:this.stateDiagram})}get stateDiagram(){const e=Object.getPrototypeOf(this),t=stateDiagram.get(e)||[];let r=new Set,i=[],s=[];const o=new Set,a=Object.getPrototypeOf(e);stateDiagram.has(a)&&(a.stateDiagram.forEach((e=>r.add(e))),a.allStates.forEach((e=>o.add(e)))),t.forEach((({from:e,to:t,action:r})=>{"string"==typeof e?i.push({from:e,to:t,action:r}):e.length?e.forEach((e=>{i.push({from:e,to:t,action:r})})):s.push({to:t,action:r})})),i.forEach((({from:e,to:t,action:i})=>{o.add(e),o.add(t),o.add(i+"ing"),r.add(`${e} --\x3e ${i}ing : ${i}`),r.add(`${i}ing --\x3e ${t} : ${i} 🟢`),r.add(`${i}ing --\x3e ${e} : ${i} 🔴`)})),s.forEach((({to:e,action:t})=>{r.add(`${t}ing --\x3e ${e} : ${t} 🟢`),o.forEach((i=>{i!==e&&r.add(`${i} --\x3e ${t}ing : ${t}`)}))}));const n=[...r];return Object.defineProperties(e,{stateDiagram:{value:n},allStates:{value:o}}),n}static get(t){let r;return"string"==typeof t?(r=e.instances.get(t),r||e.instances.set(t,r=new e(t,void 0,Object.create(e.prototype)))):(r=e.instances2.get(t),r||e.instances2.set(t,r=new e(t.constructor.name,void 0,Object.create(e.prototype)))),r}static getState(t){var r;return null===(r=e.get(t))||void 0===r?void 0:r.state}updateDevTools(t={}){sendDevTools(e.UPDATEAFSM,Object.assign({name:this.name,group:this.groupName},t))}get state(){return this._state}set state(e){setState.call(this,e)}};FSM.STATECHANGED="stateChanged",FSM.UPDATEAFSM="updateAFSM",FSM.INIT="[*]",FSM.ON="on",FSM.OFF="off",FSM.instances=new Map,FSM.instances2=new WeakMap;var Player=class extends FSM{constructor(e,t){super(),this.core=e,__publicField(this,"audioPlayer"),__publicField(this,"videoPlayer"),__publicField(this,"callback"),__publicField(this,"_log"),__publicField(this,"lastPausedReason"),this._log=t,this.videoPlayer=new e.VideoPlayer({id:"vp",log:this._log.createChild({id:"vp"}),track:null,muted:!1,container:null,enableLogTrackState:!0}),this.audioPlayer=new e.RemoteAudioPlayer({id:"ap",log:this._log.createChild({id:"ap"}),track:null,muted:!1,container:null,enableVolumeControlInIOS:!0,enableLogTrackState:!0}),this.videoPlayer.on("loadstart",(()=>this.handleLoadStart("video"))),this.audioPlayer.on("loadstart",(()=>this.handleLoadStart("audio"))),this.videoPlayer.on("player-state-changed",this.handlePlayerStateChanged,this),this.audioPlayer.on("player-state-changed",this.handlePlayerStateChanged,this)}get isPlaying(){return this.videoPlayer.isPlaying&&this.audioPlayer.isPlaying}get isPaused(){return this.videoPlayer.isPaused&&this.audioPlayer.isPaused}get isStopped(){return this.videoPlayer.isStopped&&this.audioPlayer.isStopped}setCallback(e){this.callback=e}handleLoadStart(e){this.onLoadStart()}handlePlayerStateChanged(e){"PLAYING"===e.state&&this.isPlaying&&this.onPlaying(),"PAUSED"===e.state&&this.isPaused&&this.onPaused(e.reason),"STOPPED"===e.state&&this.isStopped&&this.onStopped()}onLoadStart(){}onPlaying(){}onPaused(e){this.lastPausedReason=e}onStopped(){}setVideoContainer(e){if(this.core.utils.isString(e)){const t=document.getElementById(e);t&&this.videoPlayer.setContainer(t)}else this.videoPlayer.setContainer(e)}setVolume(e){this.core.utils.isUndefined(e)||this.audioPlayer.setVolume(e/100)}setMuted(e){this.core.utils.isUndefined(e)||this.audioPlayer.setMuted(e)}setFillMode(e){e&&this.videoPlayer.setObjectFit(e)}setAudioTrack(e){this.audioPlayer.setTrack(e)}setVideoTrack(e){this.videoPlayer.setTrack(e)}async play(){const e=this.videoPlayer.play().catch((e=>{var t,r;this.handleAutoPlayFailed(this.videoPlayer,e),null==(r=null==(t=this.callback)?void 0:t.onAutoPlayFailed)||r.call(t,{type:"video",resume:()=>this.videoPlayer.resume()})})),t=this.audioPlayer.play().catch((e=>{var t,r;this.handleAutoPlayFailed(this.audioPlayer,e),null==(r=null==(t=this.callback)?void 0:t.onAutoPlayFailed)||r.call(t,{type:"audio",resume:()=>this.audioPlayer.resume()})}));await Promise.all([e,t])}handleAutoPlayFailed(e,t){this._log.warn("handleAutoPlayFailed",t);const r=()=>{this.audioPlayer.resume().then((()=>{document.removeEventListener("click",r,!0)}))};document.addEventListener("click",r,!0)}pause(){this.videoPlayer.pause(!1),this.audioPlayer.pause()}resume(){this.videoPlayer.resume(),this.audioPlayer.resume()}async enterFullscreen(){await this.videoPlayer.enterFullscreen()}async exitFullscreen(){await this.videoPlayer.exitFullscreen()}async enterPictureInPicture(){await this.videoPlayer.enterPictureInPicture()}async exitPictureInPicture(){await this.videoPlayer.exitPictureInPicture()}stop(){this.videoPlayer&&this.videoPlayer.stop(),this.audioPlayer&&this.audioPlayer.stop()}};__decorateClass([ChangeState([FSM.INIT,"PAUSED"],"LOADSTART",{sync:!0,success(){var e,t;null==(t=null==(e=this.callback)?void 0:e.onLoadStart)||t.call(e)},fail(e){this._log.warn(e)}})],Player.prototype,"onLoadStart",1),__decorateClass([ChangeState(["LOADSTART","PAUSED"],"PLAYING",{ignoreError:!1,sync:!0,success(){var e,t;null==(t=null==(e=this.callback)?void 0:e.onPlaying)||t.call(e)},fail(e){this._log.warn(e)}})],Player.prototype,"onPlaying",1),__decorateClass([ChangeState("PLAYING","PAUSED",{ignoreError:!1,sync:!0,success(){var e,t;null==(t=null==(e=this.callback)?void 0:e.onPaused)||t.call(e,{reason:this.lastPausedReason})}})],Player.prototype,"onPaused",1),__decorateClass([ChangeState([],FSM.INIT,{ignoreError:!0,sync:!0,success(){var e,t;null==(t=null==(e=this.callback)?void 0:e.onStopped)||t.call(e)}})],Player.prototype,"onStopped",1);var player_default=Player,SIGNAL_DOMAIN_NAME_LIST=["overseas-webrtc.tlivewebrtc.com","oswebrtc-lint.tliveplay.com"],_LEBPlayer=class e{constructor(e){this.core=e,__publicField(this,"connectedRoomIdSet",new Set),__publicField(this,"updateSeq",0),__publicField(this,"_log"),__publicField(this,"player"),__publicField(this,"peerConnection"),__publicField(this,"svrSig"),__publicField(this,"streamURL"),__publicField(this,"signalURL"),__publicField(this,"insertableStreamsAbortMap",new Map),__publicField(this,"scriptTransformWorker"),__publicField(this,"connectionState","disconnected"),__publicField(this,"isStarted",!1),__publicField(this,"isStopped",!0),__publicField(this,"isReconnecting",!1),__publicField(this,"callback"),__publicField(this,"isFireWallErrorEmitted",!1),__publicField(this,"stat"),e.loggerManager.startUpload(),this._log=this.core.log.createChild({id:`${this.getAlias()}`}),this.player=new player_default(e,this._log),e.innerEmitter.on(e.INNER_EVENT.SEI_MESSAGE,this.onSEIMessage,this)}getName(){return e.Name}getAlias(){return"LEB"}getGroup(){return""}getValidateRule(e){switch(e){case"start":return StartValidateRule;case"update":case"stop":return{}}}get enableSEI(){return this.core.room.enableSEI&&(this.core.rtcDectection.IS_INSERTABLE_STREAM_SUPPORTED||this.core.rtcDectection.IS_SCRIPT_TRANSFORM_SUPPORTED)}async start(e){var t;this.isStopped=!1;const{view:r,url:i,volume:s,muted:o,fillMode:a,loggerConfig:n,callback:c}=e;this.callback=c,this.player.setCallback(c);const{errorModule:{RtcError:l,ErrorCode:d,ErrorCodeDictionary:u},loggerManager:p,rtcDectection:h}=this.core;p.addJoinedUser(n),!h.IS_SEI_SUPPORTED&&(null==c?void 0:c.onSEIMessage)&&(null==(t=c.onError)||t.call(c,new l({code:d.ENV_NOT_SUPPORTED,extraCode:u.NOT_SUPPORTED_SEI,message:"sei not supported"}))),this.player.setVideoContainer(r),this.player.setMuted(o),this.player.setVolume(s),this.player.setFillMode(a),await this.connect(i),this.stat=new Stat(this.peerConnection,this.core),this.stat.start((e=>{var t,r;return null==(r=null==(t=this.callback)?void 0:t.onStats)?void 0:r.call(t,e)})),await this.player.play(),this.isStarted=!0}async connect(e){return new Promise((async(t,r)=>{this.initScriptTransformWorker();const i=new RTCPeerConnection({iceServers:[],sdpSemantics:"unified-plan",bundlePolicy:"max-bundle",rtcpMuxPolicy:"require",tcpCandidatePolicy:"disable",IceTransportsType:"nohost",enableInsertableStreams:this.enableSEI});this.peerConnection=i,i.onconnectionstatechange=()=>{this.connectionState=i.connectionState,this._log.info("connectionState",i.connectionState),"failed"!==i.connectionState&&"closed"!==i.connectionState||(this.isStarted?this.reconnect(e):r(new Error(`connection is ${i.connectionState}`))),"connected"===i.connectionState&&(this.logSelectedCandidate(),t())},i.ontrack=this.onTrack.bind(this);const s=i.addTransceiver("audio",{direction:"recvonly"}),o=i.addTransceiver("video",{direction:"recvonly"});this.createEncodedStreams(s.receiver),this.createEncodedStreams(o.receiver),this.initReceiverTransform(s.receiver,!0),this.initReceiverTransform(o.receiver,!1),this._log.info("createOffer");const a=await i.createOffer({offerToReceiveAudio:!0,offerToReceiveVideo:!0,voiceActivityDetection:!1});a.sdp=updateSdpRestriction(a.sdp),this._log.info("setOffer"),await i.setLocalDescription(a);const n={sessionId:nanoid(),streamurl:e,clientinfo:this.core.environment.getOSString(),localsdp:i.localDescription},{url:c,remoteSdp:l,svrSig:d}=await this.core.utils.promiseAny(SIGNAL_DOMAIN_NAME_LIST.map((e=>this.exchangeSDP(`https://${e}`,n,3))));this.streamURL=e,this.signalURL=c,this.svrSig=d,this._log.info("setAnswer"),await i.setRemoteDescription(l),setTimeout((()=>r(new Error("connection timeout"))),1e4)}))}async reconnect(e){if(!this.isReconnecting){this.isReconnecting=!0;try{this._log.warn("start reconnect"),await this.connect(e),this._log.warn("reconnect success")}catch(e){this._log.error("reconnect error",e)}finally{this.isReconnecting=!1}}}async logSelectedCandidate(){if(!this.peerConnection)return;const e=await this.peerConnection.getStats();for(const[t,r]of e)if(this.core.rtcDectection.isSelectedCandidatePair(r)){const t=e.get(r.localCandidateId),i=e.get(r.remoteCandidateId);t&&this._log.info(`local candidate: ${t.candidateType} ${t.protocol}:${t.ip||t.address}:${t.port} ${t.networkType||""} ${t.relayProtocol?`relayProtocol:${t.relayProtocol} url: ${t.url}`:""}`),i&&this._log.info(`remote candidate: ${i.candidateType} ${i.protocol}:${i.ip||i.address}:${i.port}`);break}}async exchangeSDP(e,t,r){const i=`${e}/webrtc/v1/pullstream`,s=await fetchPost(i,t,{timeout:r}),{errcode:o,errmsg:a,remotesdp:n,svrsig:c}=s;if(0!==o){const e=new Error(`errCode:${o}, errMsg:${a}`);throw e.name="RequestSignalError",e}return{url:e,remoteSdp:n,svrSig:c}}createEncodedStreams(e){var t;if(this.core.rtcDectection.IS_INSERTABLE_STREAM_SUPPORTED&&!this.insertableStreamsAbortMap.has(e)){const r=e.createEncodedStreams(),i=new AbortController,s={abortController:i,enqueue:t=>"audio"===e.track.kind?t:this.decodeVideoFrame(t)};r.readable.pipeThrough(new TransformStream({transform:(e,t)=>{const r=s.enqueue(e);r&&t.enqueue(r)}})).pipeTo(r.writable,i).catch((e=>{"destroy"!==e&&this._log.warn(e)})),null==(t=this.insertableStreamsAbortMap.get(e))||t.abort("destroy"),this.insertableStreamsAbortMap.set(e,i)}}initReceiverTransform(e,t){this.peerConnection&&this.scriptTransformWorker&&!e.transform&&(e.transform=new RTCRtpScriptTransform(this.scriptTransformWorker,{isReceiver:!0,isAudio:t,userId:"",streamType:this.core.enums.RemoteStreamType.Main}))}initScriptTransformWorker(){const{room:e,rtcDectection:t,createScriptTransformWorker:r,trtc:i,TRTC:s}=this.core;!this.enableSEI||t.IS_INSERTABLE_STREAM_SUPPORTED||this.scriptTransformWorker||t.IS_SCRIPT_TRANSFORM_SUPPORTED&&(this.scriptTransformWorker=r({videoEncodePipeline:e.videoManager.encodePipeline,videoDecodePipeline:e.videoManager.decodePipeline,audioEncodePipeline:e.audioManager.encodePipeline,audioDecodePipeline:e.audioManager.decodePipeline}),this.scriptTransformWorker.onmessage=e=>{var t,r;"sei"===e.data.type&&(null==(r=null==(t=this.callback)?void 0:t.onSEIMessage)||r.call(t,{data:e.data.data,seiPayloadType:e.data.seiPayloadType}))},this.scriptTransformWorker.onerror=e=>{this._log.error("scriptTransformWorker error: ",e.message)})}decodeVideoFrame(e){if(!this.core.room.videoManager)return e;for(const t of this.core.room.videoManager.decodePipeline)if(t&&!(e=t({frame:e})))return;return e}async fetchStopStream(){if(this.streamURL&&this.svrSig&&this.signalURL)try{const e=`${this.signalURL}/webrtc/v1/stopstream`,t=await fetchPost(e,{streamurl:this.streamURL,svrsig:this.svrSig},{timeout:3}),{errcode:r,errmsg:i}=t;if(0!==r)throw new Error(`errCode:${r}, errmsg:${i}`);return t}catch(e){this._log.error("fetchStopStream error",e)}}onTrack(e){const{track:t}=e;"audio"===t.kind?this.player.setAudioTrack(t):this.player.setVideoTrack(t)}async update(e){const{volume:t,muted:r,fillMode:i,action:s,fullScreen:o,pictureInPicture:a}=e;this.player.setMuted(r),this.player.setVolume(t),this.player.setFillMode(i),"pause"===s?this.player.pause():"resume"===s&&this.player.resume(),this.core.utils.isBoolean(o)&&(o?await this.player.enterFullscreen():await this.player.exitFullscreen()),this.core.utils.isBoolean(a)&&(a?await this.player.enterPictureInPicture():await this.player.exitPictureInPicture())}async stop(){this.isStopped=!0,this.player.stop(),this.peerConnection&&(this.peerConnection.close(),delete this.peerConnection,await this.fetchStopStream(),delete this.streamURL,delete this.signalURL,delete this.svrSig),this.stat&&this.stat.stop()}destroy(){this.stop(),this.core.innerEmitter.off(this.core.INNER_EVENT.SEI_MESSAGE,this.onSEIMessage,this)}onSEIMessage({room:e,nalu:t}){var r,i;e===this.core.room&&(null==(i=null==(r=this.callback)?void 0:r.onSEIMessage)||i.call(r,{data:t.seiPayload.buffer,seiPayloadType:t.seiPayloadType}))}};__publicField(_LEBPlayer,"Name","LEBPlayer"),__decorateClass([addPromiseRetry({settings:{retries:1/0,timeout:2e3},onRetrying(e){var t;if(this._log.warn(`retry connect ${e}`),e>=3&&(null==(t=this.callback)?void 0:t.onError)&&!this.isFireWallErrorEmitted){const{RtcError:e,ErrorCode:t,ErrorCodeDictionary:r}=this.core.errorModule;this.isFireWallErrorEmitted=!0,this.callback.onError(new e({code:t.OPERATION_FAILED,extraCode:r.FIREWALL_RESTRICTION,message:"firewall restriction"}))}},onError(e,t,r,i){if(this._log.warn("connect failed",e),this.peerConnection&&(this.peerConnection.close(),delete this.peerConnection),!this.isStopped&&e.message.includes("connection"))t();else{const{RtcError:t,ErrorCode:i}=this.core.errorModule;r(new t({code:i.UNKNOWN_ERROR,message:e.message}))}}})],_LEBPlayer.prototype,"connect",1),__decorateClass([removePromiseRetry({fnName:"connect"})],_LEBPlayer.prototype,"stop",1);var LEBPlayer=_LEBPlayer,fetchPost=async(e,t,r={})=>{const{timeout:i=10}=r;let s,o=0,a={};window.AbortController&&(s=new window.AbortController,a={signal:s.signal},o=window.setTimeout((()=>s.abort()),1e3*i));const n=await fetch(e,__spreadValues({body:JSON.stringify(t),cache:"no-cache",credentials:"same-origin",headers:{"content-type":"text/plain;charset=utf-8"},method:"POST",mode:"cors"},a));if(o&&window.clearTimeout(o),200!==n.status)throw new Error(`Network Error, status code:${n.status}`);return n.json()},index_default=LEBPlayer;export{index_default as default};export{LEBPlayer};
|