@seastart/srtc-web-sdk 0.4.5 → 0.5.1
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/CHANGELOG.md +12 -0
- package/package.json +1 -1
- package/srtc.d.mts +1594 -78
- package/srtc.d.ts +1594 -78
- package/srtc.js +1 -1
- package/srtc.mjs +1 -1
package/srtc.d.ts
CHANGED
|
@@ -1,6 +1,302 @@
|
|
|
1
1
|
import Bowser$1 from 'bowser';
|
|
2
2
|
import EventEmitter from 'events';
|
|
3
|
+
import { ClientRequestArgs } from 'http';
|
|
4
|
+
import { IAuthPacket, IConnackPacket, IConnectPacket, IDisconnectPacket, IPacket, IPingreqPacket, IPingrespPacket, IPubackPacket, IPubcompPacket, IPublishPacket, IPubrecPacket, IPubrelPacket, ISubackPacket, ISubscribePacket, ISubscription, IUnsubackPacket, IUnsubscribePacket, Packet, PacketCmd, QoS, UserProperties } from 'mqtt-packet';
|
|
5
|
+
import { ClientOptions } from 'ws';
|
|
3
6
|
|
|
7
|
+
declare abstract class BaseChannel extends EventEmitter {
|
|
8
|
+
/** 加入频道选项 */
|
|
9
|
+
protected options: JoinOptions;
|
|
10
|
+
/** 加入频道api返回的数据 */
|
|
11
|
+
protected joinRsp: ChannelJoinRsp;
|
|
12
|
+
/** 我自己 */
|
|
13
|
+
protected me?: BaseUser;
|
|
14
|
+
/** 频道成员 */
|
|
15
|
+
protected users: UserContainer;
|
|
16
|
+
/** 频道信息 */
|
|
17
|
+
protected info?: BaseChannelInfo;
|
|
18
|
+
/** 心跳定时器id */
|
|
19
|
+
protected heartbeatIntervalID?: number;
|
|
20
|
+
/** 频道连接状态 */
|
|
21
|
+
protected connectState: ChannelConnectState;
|
|
22
|
+
/** rtc http api */
|
|
23
|
+
protected rtcApi: BaseRtcApi;
|
|
24
|
+
/** rtc socket*/
|
|
25
|
+
protected rtcSocket: BaseRtcSocket;
|
|
26
|
+
/**
|
|
27
|
+
* 当前的媒体引擎
|
|
28
|
+
*/
|
|
29
|
+
protected rtcStreamEngine: BaseStreamEngine;
|
|
30
|
+
/** 混音流 */
|
|
31
|
+
protected audioMixTrack?: BaseTrack & (IMockRemoteAudioMixTrack | IRemoteAudioMixTrack);
|
|
32
|
+
/** 视频合成流 */
|
|
33
|
+
protected videoMcuTrack?: BaseTrack;
|
|
34
|
+
/** 兼容回调方式的事件响应 */
|
|
35
|
+
protected eventCB: ((evt: ChannelEvent) => void) | null;
|
|
36
|
+
/**
|
|
37
|
+
* 根据userinfo实例化user
|
|
38
|
+
* @param info
|
|
39
|
+
*/
|
|
40
|
+
protected abstract newUser(info: BaseUserInfo): BaseUser;
|
|
41
|
+
/**
|
|
42
|
+
* 进行中的流订阅/取消订阅等互斥操作mutex
|
|
43
|
+
*/
|
|
44
|
+
private trackMutex;
|
|
45
|
+
/**
|
|
46
|
+
* 流订阅/取消订阅防抖动
|
|
47
|
+
*/
|
|
48
|
+
private trackDebounce;
|
|
49
|
+
constructor(options: JoinOptions, rsp: ChannelJoinRsp, api: BaseRtcApi, streamEngine: BaseStreamEngine, socket: BaseRtcSocket, eventCB?: ((evt: ChannelEvent) => void) | null);
|
|
50
|
+
/**
|
|
51
|
+
* 刷新频道详情
|
|
52
|
+
*/
|
|
53
|
+
protected refresh(isReconnected: boolean): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* 入会时对已有远端轨道进行自动订阅
|
|
56
|
+
*/
|
|
57
|
+
private autoSubscribeExistingTracks;
|
|
58
|
+
/**
|
|
59
|
+
* 检查频道是否是已连接状态,不是则抛出错误
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
protected checkConnected(): void;
|
|
63
|
+
/**
|
|
64
|
+
* 监听socket
|
|
65
|
+
*/
|
|
66
|
+
private addSocketListeners;
|
|
67
|
+
/**
|
|
68
|
+
* 取消监听socket
|
|
69
|
+
*/
|
|
70
|
+
private removeSocketListeners;
|
|
71
|
+
/**
|
|
72
|
+
* 触发频道事件。
|
|
73
|
+
*
|
|
74
|
+
* 用 rest-tuple 技巧把 data 是否必填和 map 绑定起来:
|
|
75
|
+
* - 当 `ChannelEventDataMap[K]` 是 `undefined`(如 RECONNECTING):调用处省略第二个参数;
|
|
76
|
+
* - 其余情况:调用处**必须**传入与 map 对应的 data 类型。
|
|
77
|
+
* 这样新增事件类型时 TS 会卡在对应 emit 位置,避免 data 漂移。
|
|
78
|
+
*
|
|
79
|
+
* @param type 事件类型
|
|
80
|
+
* @param args 事件 data(类型由 map 决定)
|
|
81
|
+
*/
|
|
82
|
+
protected triggerEvent<K extends keyof ChannelEventDataMap>(type: K, ...args: ChannelEventDataMap[K] extends undefined ? [
|
|
83
|
+
] : [
|
|
84
|
+
data: ChannelEventDataMap[K]
|
|
85
|
+
]): void;
|
|
86
|
+
/**
|
|
87
|
+
* 心跳
|
|
88
|
+
*/
|
|
89
|
+
private heartbeat;
|
|
90
|
+
/**
|
|
91
|
+
* socket连接成功
|
|
92
|
+
*/
|
|
93
|
+
private onConnected;
|
|
94
|
+
/**
|
|
95
|
+
* socket开始重连
|
|
96
|
+
*/
|
|
97
|
+
private onStartReconnect;
|
|
98
|
+
/**
|
|
99
|
+
* 收到频道内消息
|
|
100
|
+
* @param pkt 消息体
|
|
101
|
+
*/
|
|
102
|
+
private onChannelMessage;
|
|
103
|
+
/**
|
|
104
|
+
* 获取自己
|
|
105
|
+
* @returns
|
|
106
|
+
*/
|
|
107
|
+
getMe(): BaseUser;
|
|
108
|
+
/**
|
|
109
|
+
* 获取某用户
|
|
110
|
+
* @param uid 用户id
|
|
111
|
+
*/
|
|
112
|
+
getUser(uid: string): BaseUser;
|
|
113
|
+
/**
|
|
114
|
+
* 获取用户信息列表
|
|
115
|
+
*/
|
|
116
|
+
getUsersInfo(map: boolean): BaseUserInfo[] | Record<string, BaseUserInfo>;
|
|
117
|
+
/**
|
|
118
|
+
* 离开频道
|
|
119
|
+
*/
|
|
120
|
+
leave(reason: DisconnectReason, error?: any): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* 获取对sdk外部展现的频道信息
|
|
123
|
+
* @returns
|
|
124
|
+
*/
|
|
125
|
+
getInfo(): BaseChannelInfo;
|
|
126
|
+
/**
|
|
127
|
+
* 监听流媒体引擎事件(如质量/active speakers 等)。
|
|
128
|
+
* 基类默认空实现;具体引擎的 Channel 子类 override 注册自己的事件转发。
|
|
129
|
+
*/
|
|
130
|
+
protected addStreamEngineListeners(): void;
|
|
131
|
+
/**
|
|
132
|
+
* 获取流媒体引擎供应商
|
|
133
|
+
*/
|
|
134
|
+
getStreamEngineVendor(): string;
|
|
135
|
+
/**
|
|
136
|
+
* 获取轨道发布额外参数
|
|
137
|
+
*/
|
|
138
|
+
protected getPublishExOption(track: BaseTrack, opt: AudioPublishOptions | VideoPublishOptions): Promise<Record<string, any>>;
|
|
139
|
+
/**
|
|
140
|
+
* 获取发布后新增的tracks
|
|
141
|
+
* 之所以是数组是因为自研引擎支持发布流时自动simucast
|
|
142
|
+
*/
|
|
143
|
+
protected getAddedTracksAfterPublish(track: BaseTrack, opt: AudioPublishOptions | VideoPublishOptions): BaseTrack[];
|
|
144
|
+
/**
|
|
145
|
+
* 获取取消发布后删除的tracks
|
|
146
|
+
*/
|
|
147
|
+
protected getDeletedTracksAfterUnpublish(track: BaseTrack): BaseTrack[];
|
|
148
|
+
/**
|
|
149
|
+
* 发布本地流轨道
|
|
150
|
+
* @param track
|
|
151
|
+
* @returns
|
|
152
|
+
*/
|
|
153
|
+
publishLocalTrack(track: BaseTrack, opt: AudioPublishOptions | VideoPublishOptions): Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* 取消发布本地流
|
|
156
|
+
* @param track
|
|
157
|
+
*/
|
|
158
|
+
unpublishLocalTrack(track: BaseTrack): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* 获取轨道订阅额外参数
|
|
161
|
+
*/
|
|
162
|
+
protected getSubscribeExOption(track: BaseTrack): Promise<Record<string, any>>;
|
|
163
|
+
/**
|
|
164
|
+
* 生成远端频道混音流
|
|
165
|
+
*/
|
|
166
|
+
protected abstract newRemoteAudioMixTrack(filter?: ((track: BaseTrack) => boolean) | string[]): BaseTrack & (IMockRemoteAudioMixTrack | IRemoteAudioMixTrack);
|
|
167
|
+
/**
|
|
168
|
+
* 生成远端视频合成流
|
|
169
|
+
*/
|
|
170
|
+
protected abstract newRemoteVideoMcuTrack(): BaseTrack;
|
|
171
|
+
/**
|
|
172
|
+
* 获取远端频道混音流
|
|
173
|
+
* @param filter 音频轨道过滤器,传递string[]时,根据uid过滤
|
|
174
|
+
*/
|
|
175
|
+
subscribeRemoteAudioMixTrack(filter?: ((track: BaseTrack) => boolean) | string[]): Promise<BaseTrack & (IMockRemoteAudioMixTrack | IRemoteAudioMixTrack)>;
|
|
176
|
+
/**
|
|
177
|
+
* 订阅远端用户音频流
|
|
178
|
+
* @param uid 用户id
|
|
179
|
+
* @param id 流轨道id
|
|
180
|
+
*/
|
|
181
|
+
subscribeRemoteAudioTrack(uid: string, id: string): Promise<BaseTrack>;
|
|
182
|
+
/**
|
|
183
|
+
* 订阅远端视频合成流
|
|
184
|
+
*/
|
|
185
|
+
subscribeRemoteVideoMcuTrack(): Promise<BaseTrack>;
|
|
186
|
+
/**
|
|
187
|
+
* 订阅远端用户视频流
|
|
188
|
+
* @param uid 用户id
|
|
189
|
+
* @param id 流轨道id
|
|
190
|
+
*/
|
|
191
|
+
subscribeRemoteVideoTrack(uid: string, id: string): Promise<BaseTrack>;
|
|
192
|
+
/**
|
|
193
|
+
* 取消订阅远端流
|
|
194
|
+
* @param track 流轨道
|
|
195
|
+
* @param debounceWaitMs 防取消订阅/订阅抖动ms数
|
|
196
|
+
*/
|
|
197
|
+
unsubscribeRemoteTrack(track: BaseTrack, debounceWaitMs?: number): Promise<void>;
|
|
198
|
+
}
|
|
199
|
+
declare abstract class BaseRtcApi {
|
|
200
|
+
/** rtc AppID */
|
|
201
|
+
protected appID: string;
|
|
202
|
+
/** rtc sid */
|
|
203
|
+
protected sid: string;
|
|
204
|
+
/** 客户端密钥 */
|
|
205
|
+
protected clientKey: string;
|
|
206
|
+
/** 服务器地址头部 */
|
|
207
|
+
protected serverPrefix?: string;
|
|
208
|
+
/**
|
|
209
|
+
* 发起rtc api http请求
|
|
210
|
+
*/
|
|
211
|
+
protected abstract http(api: string, params: Record<string, any>, headers: Record<string, string>): Promise<any>;
|
|
212
|
+
constructor(appID: string, sid: string, clientKey: string, serverPrefix: string);
|
|
213
|
+
/**
|
|
214
|
+
* 加入频道
|
|
215
|
+
* @see https://doc.apipost.net/docs/detail/2be86df99864000?target_id=51c6ed8
|
|
216
|
+
*/
|
|
217
|
+
join(params: {
|
|
218
|
+
deviceType: DeviceType;
|
|
219
|
+
deviceID: string;
|
|
220
|
+
version: string;
|
|
221
|
+
}): Promise<ChannelJoinRsp>;
|
|
222
|
+
/**
|
|
223
|
+
* 频道详情
|
|
224
|
+
* @see https://doc.apipost.net/docs/detail/2be86df99864000?target_id=520ba1f
|
|
225
|
+
* @param listuser 是否包括在线用户列表,true则返回所有在线用户
|
|
226
|
+
* @returns
|
|
227
|
+
*/
|
|
228
|
+
detail(listuser: boolean): Promise<{
|
|
229
|
+
channelinfo: BaseChannelInfo;
|
|
230
|
+
userinfos: BaseUserInfo[] | null;
|
|
231
|
+
}>;
|
|
232
|
+
/**
|
|
233
|
+
* 离开频道
|
|
234
|
+
* @see https://doc.apipost.net/docs/detail/2be86df99864000?target_id=51d732b
|
|
235
|
+
* @returns
|
|
236
|
+
*/
|
|
237
|
+
leave(): Promise<void>;
|
|
238
|
+
/**
|
|
239
|
+
* 发送心跳
|
|
240
|
+
* @see https://doc.apipost.net/docs/detail/2be86df99864000?target_id=51d38e3
|
|
241
|
+
* @returns
|
|
242
|
+
*/
|
|
243
|
+
heartbeat(): Promise<void>;
|
|
244
|
+
/**
|
|
245
|
+
* 断线重连
|
|
246
|
+
* @see https://doc.apipost.net/docs/detail/2be86df99864000?target_id=52602cf
|
|
247
|
+
* @returns
|
|
248
|
+
*/
|
|
249
|
+
reconnect(params: {
|
|
250
|
+
type: number;
|
|
251
|
+
}): Promise<ReconnectRsp>;
|
|
252
|
+
/**
|
|
253
|
+
* 更新流信息
|
|
254
|
+
* @see https://doc.apipost.net/docs/detail/2be86df99864000?target_id=51c6eae
|
|
255
|
+
* @returns
|
|
256
|
+
*/
|
|
257
|
+
updateStream(trackinfos: BaseTrackInfo[]): Promise<void>;
|
|
258
|
+
/**
|
|
259
|
+
* im连接
|
|
260
|
+
* @see https://doc.apipost.net/docs/detail/2be86df99864000?target_id=25c1132f700054
|
|
261
|
+
* @returns
|
|
262
|
+
*/
|
|
263
|
+
imConnect(params: {
|
|
264
|
+
deviceType: DeviceType;
|
|
265
|
+
deviceID: string;
|
|
266
|
+
version: string;
|
|
267
|
+
}): Promise<ImConnectRsp>;
|
|
268
|
+
/**
|
|
269
|
+
* im重连
|
|
270
|
+
* @see https://doc.apipost.net/docs/detail/2be86df99864000?target_id=25c2a79e70007f
|
|
271
|
+
* @returns
|
|
272
|
+
*/
|
|
273
|
+
imReconnect(): Promise<ImConnectRsp>;
|
|
274
|
+
/**
|
|
275
|
+
* im发送心跳
|
|
276
|
+
* @see https://doc.apipost.net/docs/detail/2be86df99864000?target_id=25c2da5cb00081
|
|
277
|
+
* @returns
|
|
278
|
+
*/
|
|
279
|
+
imHeartbeat(): Promise<void>;
|
|
280
|
+
/**
|
|
281
|
+
* im断开连接
|
|
282
|
+
* @see https://doc.apipost.net/docs/detail/2be86df99864000?target_id=25c356d2300092
|
|
283
|
+
* @returns
|
|
284
|
+
*/
|
|
285
|
+
imDisconnect(): Promise<void>;
|
|
286
|
+
/**
|
|
287
|
+
* 发送rtc sdk api请求
|
|
288
|
+
* @param api api接口
|
|
289
|
+
* @param params 数据
|
|
290
|
+
* @param headers 额外http头
|
|
291
|
+
*/
|
|
292
|
+
protected req(api: string, params?: Record<string, any>, headers?: Record<string, string>): Promise<any>;
|
|
293
|
+
/**
|
|
294
|
+
* 签名
|
|
295
|
+
* @param params
|
|
296
|
+
* @returns
|
|
297
|
+
*/
|
|
298
|
+
private signature;
|
|
299
|
+
}
|
|
4
300
|
declare abstract class BaseSRTC {
|
|
5
301
|
/**
|
|
6
302
|
* 获取sdk编译信息
|
|
@@ -39,19 +335,6 @@ declare abstract class BaseSRTC {
|
|
|
39
335
|
* @returns
|
|
40
336
|
*/
|
|
41
337
|
getChannelInfo(): BaseChannelInfo | null;
|
|
42
|
-
/**
|
|
43
|
-
* 获取流媒体引擎的metric快照(全量,含每条轨道的统计)
|
|
44
|
-
*/
|
|
45
|
-
getStreamMetric(): StreamMetric | undefined;
|
|
46
|
-
/**
|
|
47
|
-
* 获取当前网络总体统计,只关心网络全景时用,比 getStreamMetric 更轻量
|
|
48
|
-
*/
|
|
49
|
-
getNetworkStats(): NetworkStats | undefined;
|
|
50
|
-
/**
|
|
51
|
-
* 获取当前连接质量评估结果(等级 / MOS / 触发原因)
|
|
52
|
-
* 配合 CONNECTION_QUALITY_CHANGED 事件使用
|
|
53
|
-
*/
|
|
54
|
-
getConnectionQuality(): QualityEvaluation | undefined;
|
|
55
338
|
/**
|
|
56
339
|
* 获取某用户信息
|
|
57
340
|
* @returns
|
|
@@ -106,6 +389,81 @@ declare abstract class BaseSRTC {
|
|
|
106
389
|
*/
|
|
107
390
|
disableIm(): Promise<void>;
|
|
108
391
|
}
|
|
392
|
+
declare abstract class BaseStreamEngine extends EventEmitter {
|
|
393
|
+
/** 加入频道api返回的数据 */
|
|
394
|
+
protected joinRsp: ChannelJoinRsp;
|
|
395
|
+
/** 已发布轨道 */
|
|
396
|
+
protected published: Record<string, BaseTrackEx>;
|
|
397
|
+
/** 已订阅轨道 */
|
|
398
|
+
protected subscribed: Record<string, BaseTrackEx>;
|
|
399
|
+
/** 能力 */
|
|
400
|
+
protected ability?: StreamEngineAbility;
|
|
401
|
+
/** 采集metric指标定时器(用于日志上报) */
|
|
402
|
+
protected monitorInterval?: number;
|
|
403
|
+
constructor(rsp: ChannelJoinRsp, ability?: Partial<StreamEngineAbility>);
|
|
404
|
+
/**
|
|
405
|
+
* 流媒体服务商名
|
|
406
|
+
*/
|
|
407
|
+
abstract vendor(): string;
|
|
408
|
+
/**
|
|
409
|
+
* 连接流媒体服务(如果需要,程博webrtc流媒体就需要)
|
|
410
|
+
*/
|
|
411
|
+
connect(): Promise<void>;
|
|
412
|
+
/**
|
|
413
|
+
* 发布本地流
|
|
414
|
+
* @param track
|
|
415
|
+
* @param opt 通用发布参数
|
|
416
|
+
* @param exopt 该引擎特有的发布参数
|
|
417
|
+
*/
|
|
418
|
+
publish(track: BaseTrack, opt: AudioPublishOptions | VideoPublishOptions, exopt: Record<string, any>): Promise<void>;
|
|
419
|
+
/**
|
|
420
|
+
* 取消发布本地流
|
|
421
|
+
* @param track
|
|
422
|
+
*/
|
|
423
|
+
abstract unpublish(track: BaseTrack): Promise<void>;
|
|
424
|
+
/**
|
|
425
|
+
* 订阅远端流
|
|
426
|
+
* @param track
|
|
427
|
+
* @param exopt 该引擎特有的订阅参数
|
|
428
|
+
*/
|
|
429
|
+
subscribe(track: BaseTrack, exopt: Record<string, any>): Promise<void>;
|
|
430
|
+
/**
|
|
431
|
+
* 是否已订阅某轨道
|
|
432
|
+
* @param track
|
|
433
|
+
* @returns
|
|
434
|
+
*/
|
|
435
|
+
haveSubscribed(track: BaseTrack): boolean;
|
|
436
|
+
/**
|
|
437
|
+
* 取消订阅远端流
|
|
438
|
+
* @param track
|
|
439
|
+
* @param exopt 该引擎特有的取消订阅参数
|
|
440
|
+
*/
|
|
441
|
+
abstract unsubscribe(track: BaseTrack): Promise<void>;
|
|
442
|
+
/**
|
|
443
|
+
* 断开流媒体服务
|
|
444
|
+
*/
|
|
445
|
+
disconnect(): Promise<void>;
|
|
446
|
+
/**
|
|
447
|
+
* 获取当前metric快照
|
|
448
|
+
*/
|
|
449
|
+
getMetricSnapshot(): Record<string, any> | undefined;
|
|
450
|
+
/**
|
|
451
|
+
* 开始metric采集
|
|
452
|
+
*
|
|
453
|
+
* 基类只做 10s 低频日志上报。
|
|
454
|
+
* 若子类需要更高频采样(例如 webrtc 引擎的质量评分),可 override 后 `super.startMonitor()`。
|
|
455
|
+
*/
|
|
456
|
+
protected startMonitor(): void;
|
|
457
|
+
/**
|
|
458
|
+
* 获取metric数据
|
|
459
|
+
* @returns
|
|
460
|
+
*/
|
|
461
|
+
protected abstract getMetric(): Promise<Record<string, any>>;
|
|
462
|
+
/**
|
|
463
|
+
* 结束metric采集
|
|
464
|
+
*/
|
|
465
|
+
protected stopMonitor(): void;
|
|
466
|
+
}
|
|
109
467
|
declare abstract class BaseTrack extends EventEmitter {
|
|
110
468
|
constructor(info: BaseTrackInfo, uid: string);
|
|
111
469
|
/**
|
|
@@ -136,65 +494,232 @@ declare abstract class BaseTrack extends EventEmitter {
|
|
|
136
494
|
getUid(): string;
|
|
137
495
|
toString(): string;
|
|
138
496
|
}
|
|
497
|
+
declare abstract class BaseUser {
|
|
498
|
+
/** track 数组 */
|
|
499
|
+
protected tracks: Record<string, BaseTrack>;
|
|
500
|
+
/** 对外输出的info */
|
|
501
|
+
protected info: BaseUserInfo;
|
|
502
|
+
/**
|
|
503
|
+
* 根据trackinfo实例化track
|
|
504
|
+
* @param trackinfo
|
|
505
|
+
*/
|
|
506
|
+
protected abstract newTrack(info: BaseTrackInfo): BaseTrack;
|
|
507
|
+
constructor(info: BaseUserInfo);
|
|
508
|
+
/**
|
|
509
|
+
* 获取某轨道
|
|
510
|
+
*/
|
|
511
|
+
getTrack(id: string): BaseTrack | undefined;
|
|
512
|
+
/**
|
|
513
|
+
* 根据desc获取某轨道
|
|
514
|
+
*/
|
|
515
|
+
getTrackByDesc(desc: string): BaseTrack | undefined;
|
|
516
|
+
/**
|
|
517
|
+
* 获取所有轨道
|
|
518
|
+
* @returns
|
|
519
|
+
*/
|
|
520
|
+
getTracks(): Record<string, BaseTrack>;
|
|
521
|
+
/**
|
|
522
|
+
* 全量更新tracks,目前会控只有全量更新某用户的所有track
|
|
523
|
+
* @param trackinfos 新的全量trackinfos
|
|
524
|
+
*/
|
|
525
|
+
updateTracks(trackinfos: BaseTrackInfo[]): {
|
|
526
|
+
added: BaseTrack[];
|
|
527
|
+
updated: BaseTrack[];
|
|
528
|
+
deleted: BaseTrack[];
|
|
529
|
+
};
|
|
530
|
+
/**
|
|
531
|
+
* 第三方用户id
|
|
532
|
+
*/
|
|
533
|
+
get uid(): string;
|
|
534
|
+
/**
|
|
535
|
+
* 会话id
|
|
536
|
+
*/
|
|
537
|
+
get sid(): string;
|
|
538
|
+
/**
|
|
539
|
+
* 设备类型
|
|
540
|
+
*/
|
|
541
|
+
get device_type(): number;
|
|
542
|
+
/**
|
|
543
|
+
* 设备id
|
|
544
|
+
*/
|
|
545
|
+
get device_id(): string;
|
|
546
|
+
/**
|
|
547
|
+
* 流媒体连接id
|
|
548
|
+
*/
|
|
549
|
+
get link_id(): number;
|
|
550
|
+
/**
|
|
551
|
+
* 获取对sdk外部展现的用户信息
|
|
552
|
+
* @returns
|
|
553
|
+
*/
|
|
554
|
+
getInfo(): BaseUserInfo;
|
|
555
|
+
/**
|
|
556
|
+
* 更新描述信息
|
|
557
|
+
* @param info
|
|
558
|
+
*/
|
|
559
|
+
updateInfo(info: Partial<BaseUserInfo>): void;
|
|
560
|
+
}
|
|
139
561
|
declare abstract class BaseWebrtcTrack extends BaseTrack {
|
|
140
562
|
constructor(info: BaseTrackInfo, uid: string);
|
|
141
563
|
setMediaStreamTrack(mediaStreamTrack?: MediaStreamTrack): void;
|
|
142
564
|
getMediaStreamTrack(): MediaStreamTrack | undefined;
|
|
143
565
|
getMediaStream(): MediaStream;
|
|
144
566
|
}
|
|
567
|
+
declare class BaseRtcSocket extends EventEmitter {
|
|
568
|
+
/** mqtt客户端 */
|
|
569
|
+
private client;
|
|
570
|
+
/** 会控协议版本头 */
|
|
571
|
+
private version;
|
|
572
|
+
/** 已订阅topics:qos */
|
|
573
|
+
private ssTopics;
|
|
574
|
+
/** 重连时刷新auth */
|
|
575
|
+
protected authReconnect?: AuthReconnect;
|
|
576
|
+
/** 是否首次连接 */
|
|
577
|
+
private isFirstConnect;
|
|
578
|
+
/** 消息解析 */
|
|
579
|
+
private unpacker;
|
|
580
|
+
constructor(authReconnect?: AuthReconnect);
|
|
581
|
+
/**
|
|
582
|
+
* 初始化mqtt客户端
|
|
583
|
+
* @param server
|
|
584
|
+
*/
|
|
585
|
+
private initClient;
|
|
586
|
+
/**
|
|
587
|
+
* 转换websocket地址,主要小程序需要用wxs前缀
|
|
588
|
+
* @param ws
|
|
589
|
+
* @returns
|
|
590
|
+
*/
|
|
591
|
+
protected getBrokerUrl(ws: string): string;
|
|
592
|
+
/**
|
|
593
|
+
* 连接mqtt服务器
|
|
594
|
+
* @param server
|
|
595
|
+
*/
|
|
596
|
+
connect(server: MqttServer): Promise<void>;
|
|
597
|
+
/**
|
|
598
|
+
* 添加socket常驻监听
|
|
599
|
+
*/
|
|
600
|
+
private addListeners;
|
|
601
|
+
/**
|
|
602
|
+
* 封装mqtt的subscribe为promise
|
|
603
|
+
* @param topic 话题或者话题数组
|
|
604
|
+
*/
|
|
605
|
+
subscribe(topic: string | string[], qos?: QoS): Promise<void>;
|
|
606
|
+
/**
|
|
607
|
+
* 封装mqtt的unsubscribe为promise
|
|
608
|
+
* @param topic 话题或者话题数组
|
|
609
|
+
*/
|
|
610
|
+
unsubscribe(topic: string | string[]): Promise<void>;
|
|
611
|
+
/**
|
|
612
|
+
* 关闭socket
|
|
613
|
+
* @param force 是否强制退出(不等待ack),对应mqttclient的end里的force
|
|
614
|
+
* @returns
|
|
615
|
+
*/
|
|
616
|
+
close(force?: boolean): Promise<void>;
|
|
617
|
+
/**
|
|
618
|
+
* 发送消息
|
|
619
|
+
* @param data 数据
|
|
620
|
+
* @param type 消息类型
|
|
621
|
+
*/
|
|
622
|
+
sendMsg(msg: string | Buffer, topic: string, qos?: QoS): Promise<void>;
|
|
623
|
+
/**
|
|
624
|
+
* 收到mqtt消息响应
|
|
625
|
+
* @param topic mqtt主题
|
|
626
|
+
* @param payload 消息载荷
|
|
627
|
+
* @param packet
|
|
628
|
+
* @returns
|
|
629
|
+
*/
|
|
630
|
+
private onMsg;
|
|
631
|
+
}
|
|
632
|
+
declare class Channel extends BaseChannel {
|
|
633
|
+
/**
|
|
634
|
+
* override:注册 webrtc 引擎特有的质量 / active speakers 事件转发。
|
|
635
|
+
*/
|
|
636
|
+
protected addStreamEngineListeners(): void;
|
|
637
|
+
/**
|
|
638
|
+
* 获取流媒体引擎的metric快照(全量,包含每条轨道的统计)
|
|
639
|
+
*/
|
|
640
|
+
getStreamMetric(): StreamMetric | undefined;
|
|
641
|
+
/**
|
|
642
|
+
* 获取当前网络总体统计,轻量接口,只关心网络整体指标时使用
|
|
643
|
+
*/
|
|
644
|
+
getNetworkStats(): NetworkStats | undefined;
|
|
645
|
+
/**
|
|
646
|
+
* 获取当前连接质量评估结果(等级、MOS、原因等)
|
|
647
|
+
*/
|
|
648
|
+
getConnectionQuality(): QualityEvaluation | undefined;
|
|
649
|
+
protected getPublishExOption(track: BaseTrack, opt: AudioPublishOptions | VideoPublishOptions): Promise<Record<string, any>>;
|
|
650
|
+
protected getAddedTracksAfterPublish(track: BaseTrack, opt: AudioPublishOptions | VideoPublishOptions): BaseTrack[];
|
|
651
|
+
protected getDeletedTracksAfterUnpublish(track: BaseTrack): BaseTrack[];
|
|
652
|
+
protected getSubscribeExOption(track: BaseTrack): Promise<Record<string, any>>;
|
|
653
|
+
protected newRemoteAudioMixTrack(filter?: ((track: BaseTrack) => boolean) | string[]): RemoteAudioMixTrack | MockRemoteAudioMixTrack;
|
|
654
|
+
protected newRemoteVideoMcuTrack(): RemoteVideoMcuTrack;
|
|
655
|
+
subscribeRemoteVideoTrack(uid: string, id: string): Promise<BaseTrack>;
|
|
656
|
+
unsubscribeRemoteTrack(track: BaseTrack, debounceWaitMs?: number): Promise<void>;
|
|
657
|
+
/** 自适应流管理器。懒初始化,避免父类构造期还未准备好 rtcStreamEngine/options 的问题。 */
|
|
658
|
+
private adaptiveStream?;
|
|
659
|
+
private getAdaptiveStream;
|
|
660
|
+
/**
|
|
661
|
+
* 解析某路远端视频订阅的完整候选层,顺序"高到低"。
|
|
662
|
+
* 这一步依赖 user 结构,所以留在 Channel 里作为解析器喂给 Manager。
|
|
663
|
+
*/
|
|
664
|
+
private getAdaptiveVideoCandidates;
|
|
665
|
+
}
|
|
145
666
|
declare class CommonChannelEventType {
|
|
146
|
-
/** 频道自定义props
|
|
667
|
+
/** 频道自定义props更新 */
|
|
147
668
|
static readonly CHANNEL_UPDATE = "channel_update";
|
|
148
|
-
/**
|
|
669
|
+
/** 首次加入频道成功 */
|
|
149
670
|
static readonly JOIN_SUCCEED = "join_succeed";
|
|
150
|
-
/**
|
|
671
|
+
/** 自己信息被改变 */
|
|
151
672
|
static readonly ME_UPDATE = "me_update";
|
|
152
|
-
/**
|
|
673
|
+
/** 开始断线自动重连 */
|
|
153
674
|
static readonly RECONNECTING = "reconnecting";
|
|
154
675
|
/** 重连成功,断线重连成功后会触发 */
|
|
155
676
|
static readonly RECONNECTED = "reconnected";
|
|
156
|
-
/**
|
|
677
|
+
/** 自己被强制离开频道 */
|
|
157
678
|
static readonly DISCONNECTED = "disconnected";
|
|
158
|
-
/**
|
|
679
|
+
/** 其他用户加入频道 */
|
|
159
680
|
static readonly USER_JOIN = "user_join";
|
|
160
|
-
/**
|
|
681
|
+
/** 其他用户信息改变 */
|
|
161
682
|
static readonly USER_UPDATE = "user_update";
|
|
162
|
-
/**
|
|
683
|
+
/** 其他用户离开频道 */
|
|
163
684
|
static readonly USER_LEAVE = "user_leave";
|
|
164
|
-
/**
|
|
685
|
+
/** 其他用户发布流轨道 */
|
|
165
686
|
static readonly USER_TRACK_ADD = "user_track_add";
|
|
166
|
-
/**
|
|
687
|
+
/** 其他用户更新流轨道 */
|
|
167
688
|
static readonly USER_TRACK_UPDATE = "user_track_update";
|
|
168
|
-
/**
|
|
689
|
+
/** 其他用户删除流轨道 */
|
|
169
690
|
static readonly USER_TRACK_REMOVE = "user_track_remove";
|
|
170
|
-
/**
|
|
691
|
+
/** 频道内自定义消息 */
|
|
171
692
|
static readonly CUSTOM_MSG = "custom_msg";
|
|
172
|
-
/**
|
|
693
|
+
/** 流轨道没有数据 */
|
|
173
694
|
static readonly TRACK_MUTED = "track_muted";
|
|
174
|
-
/**
|
|
695
|
+
/** 流轨道恢复数据 */
|
|
175
696
|
static readonly TRACK_UNMUTED = "track_unmuted";
|
|
176
|
-
/**
|
|
697
|
+
/** 流轨道停止 */
|
|
177
698
|
static readonly TRACK_ENDED = "track_ended";
|
|
178
|
-
/** 连接质量等级变化,对应data为 ConnectionQualityEventData */
|
|
179
|
-
static readonly CONNECTION_QUALITY_CHANGED = "connection_quality_changed";
|
|
180
|
-
/** 发送端被CPU持续限制,对应data为 QualityEvaluation */
|
|
181
|
-
static readonly CPU_CONSTRAINED = "cpu_constrained";
|
|
182
|
-
/** 发送端被带宽持续限制,对应data为 QualityEvaluation */
|
|
183
|
-
static readonly BANDWIDTH_CONSTRAINED = "bandwidth_constrained";
|
|
184
699
|
}
|
|
185
700
|
/** 频道外事件类型 */
|
|
186
701
|
declare class CommonImEventType {
|
|
187
|
-
/** 首次连接im
|
|
702
|
+
/** 首次连接im成功 */
|
|
188
703
|
static readonly ENABLE_SUCCEED = "enable_succeed";
|
|
189
|
-
/** im
|
|
704
|
+
/** im开始断线自动重连 */
|
|
190
705
|
static readonly RECONNECTING = "reconnecting";
|
|
191
|
-
/** im
|
|
706
|
+
/** im重连成功 */
|
|
192
707
|
static readonly RECONNECTED = "reconnected";
|
|
193
|
-
/** 自己被强制断开im
|
|
708
|
+
/** 自己被强制断开im */
|
|
194
709
|
static readonly DISCONNECTED = "disconnected";
|
|
195
|
-
/** im
|
|
710
|
+
/** im消息 */
|
|
196
711
|
static readonly IM_MSG = "im_msg";
|
|
197
712
|
}
|
|
713
|
+
declare class CommonTrackEventType {
|
|
714
|
+
/** track info更新 */
|
|
715
|
+
static readonly INFO_UPDATE = "info_update";
|
|
716
|
+
/** temporarily unable to provide media data */
|
|
717
|
+
static readonly MUTED = "muted";
|
|
718
|
+
/** once again able to provide media data */
|
|
719
|
+
static readonly UNMUTED = "unmuted";
|
|
720
|
+
/** playback or streaming has stopped because the end of the media was reached or because no further data is available */
|
|
721
|
+
static readonly ENDED = "ended";
|
|
722
|
+
}
|
|
198
723
|
declare class Logger {
|
|
199
724
|
constructor(dp?: string, dclt?: string);
|
|
200
725
|
setTarget(target: LogTarget): void;
|
|
@@ -204,6 +729,180 @@ declare class Logger {
|
|
|
204
729
|
warn(...args: any[]): void;
|
|
205
730
|
error(...args: any[]): void;
|
|
206
731
|
}
|
|
732
|
+
declare class MockRemoteAudioMixTrack extends RemoteAudioTrack implements IMockRemoteAudioMixTrack {
|
|
733
|
+
constructor(info: BaseTrackInfo, filter?: (track: BaseTrack) => boolean);
|
|
734
|
+
/**
|
|
735
|
+
* 检查是否要过滤某track
|
|
736
|
+
* @param track
|
|
737
|
+
* @returns
|
|
738
|
+
*/
|
|
739
|
+
checkFilter(track: RemoteAudioTrack): boolean;
|
|
740
|
+
/**
|
|
741
|
+
* 添加track
|
|
742
|
+
* @param track
|
|
743
|
+
*/
|
|
744
|
+
addTrack(track: RemoteAudioTrack): void;
|
|
745
|
+
/**
|
|
746
|
+
* 移除track
|
|
747
|
+
* @param track
|
|
748
|
+
*/
|
|
749
|
+
removeTrack(track: RemoteAudioTrack): void;
|
|
750
|
+
/**
|
|
751
|
+
* 停止混音
|
|
752
|
+
*/
|
|
753
|
+
stop(): void;
|
|
754
|
+
}
|
|
755
|
+
declare class MqttClient extends EventEmitter {
|
|
756
|
+
public connected: boolean;
|
|
757
|
+
public disconnecting: boolean;
|
|
758
|
+
public disconnected: boolean;
|
|
759
|
+
public reconnecting: boolean;
|
|
760
|
+
public incomingStore: Store;
|
|
761
|
+
public outgoingStore: Store;
|
|
762
|
+
public options: IClientOptions;
|
|
763
|
+
public queueQoSZero: boolean;
|
|
764
|
+
constructor(streamBuilder: (client: MqttClient) => IStream, options: IClientOptions);
|
|
765
|
+
public on(event: "connect", cb: OnConnectCallback): this;
|
|
766
|
+
public on(event: "message", cb: OnMessageCallback): this;
|
|
767
|
+
public on(event: "packetsend" | "packetreceive", cb: OnPacketCallback): this;
|
|
768
|
+
public on(event: "disconnect", cb: OnDisconnectCallback): this;
|
|
769
|
+
public on(event: "error", cb: OnErrorCallback): this;
|
|
770
|
+
public on(event: "close", cb: OnCloseCallback): this;
|
|
771
|
+
public on(event: "end" | "reconnect" | "offline" | "outgoingEmpty", cb: () => void): this;
|
|
772
|
+
public on(event: string, cb: Function): this;
|
|
773
|
+
public once(event: "connect", cb: OnConnectCallback): this;
|
|
774
|
+
public once(event: "message", cb: OnMessageCallback): this;
|
|
775
|
+
public once(event: "packetsend" | "packetreceive", cb: OnPacketCallback): this;
|
|
776
|
+
public once(event: "disconnect", cb: OnDisconnectCallback): this;
|
|
777
|
+
public once(event: "error", cb: OnErrorCallback): this;
|
|
778
|
+
public once(event: "close", cb: OnCloseCallback): this;
|
|
779
|
+
public once(event: "end" | "reconnect" | "offline" | "outgoingEmpty", cb: () => void): this;
|
|
780
|
+
public once(event: string, cb: Function): this;
|
|
781
|
+
/**
|
|
782
|
+
* publish - publish <message> to <topic>
|
|
783
|
+
*
|
|
784
|
+
* @param {String} topic - topic to publish to
|
|
785
|
+
* @param {(String|Buffer)} message - message to publish
|
|
786
|
+
*
|
|
787
|
+
* @param {Object} [opts] - publish options, includes:
|
|
788
|
+
* @param {Number} [opts.qos] - qos level to publish on
|
|
789
|
+
* @param {Boolean} [opts.retain] - whether or not to retain the message
|
|
790
|
+
* @param {Function}[opts.cbStorePut] - function(){}
|
|
791
|
+
* called when message is put into `outgoingStore`
|
|
792
|
+
*
|
|
793
|
+
* @param {Function} [callback] - function(err){}
|
|
794
|
+
* called when publish succeeds or fails
|
|
795
|
+
*
|
|
796
|
+
* @returns {Client} this - for chaining
|
|
797
|
+
* @api public
|
|
798
|
+
*
|
|
799
|
+
* @example client.publish('topic', 'message')
|
|
800
|
+
* @example
|
|
801
|
+
* client.publish('topic', 'message', {qos: 1, retain: true})
|
|
802
|
+
* @example client.publish('topic', 'message', console.log)
|
|
803
|
+
*/
|
|
804
|
+
public publish(topic: string, message: string | Buffer, opts: IClientPublishOptions, callback?: PacketCallback): this;
|
|
805
|
+
public publish(topic: string, message: string | Buffer, callback?: PacketCallback): this;
|
|
806
|
+
/**
|
|
807
|
+
* subscribe - subscribe to <topic>
|
|
808
|
+
*
|
|
809
|
+
* @param {String, Array, Object} topic - topic(s) to subscribe to, supports objects in the form {'topic': qos}
|
|
810
|
+
* @param {Object} [opts] - optional subscription options, includes:
|
|
811
|
+
* @param {Number} [opts.qos] - subscribe qos level
|
|
812
|
+
* @param {Function} [callback] - function(err, granted){} where:
|
|
813
|
+
* {Error} err - subscription error (none at the moment!)
|
|
814
|
+
* {Array} granted - array of {topic: 't', qos: 0}
|
|
815
|
+
* @returns {MqttClient} this - for chaining
|
|
816
|
+
* @api public
|
|
817
|
+
* @example client.subscribe('topic')
|
|
818
|
+
* @example client.subscribe('topic', {qos: 1})
|
|
819
|
+
* @example client.subscribe({'topic': 0, 'topic2': 1}, console.log)
|
|
820
|
+
* @example client.subscribe('topic', console.log)
|
|
821
|
+
*/
|
|
822
|
+
public subscribe(topic: string | string[], opts: IClientSubscribeOptions, callback?: ClientSubscribeCallback): this;
|
|
823
|
+
public subscribe(topic: string | string[] | ISubscriptionMap, callback?: ClientSubscribeCallback): this;
|
|
824
|
+
/**
|
|
825
|
+
* unsubscribe - unsubscribe from topic(s)
|
|
826
|
+
*
|
|
827
|
+
* @param {String, Array} topic - topics to unsubscribe from
|
|
828
|
+
* @param {Object} opts - opts of unsubscribe
|
|
829
|
+
* @param {Function} [callback] - callback fired on unsuback
|
|
830
|
+
* @returns {MqttClient} this - for chaining
|
|
831
|
+
* @api public
|
|
832
|
+
* @example client.unsubscribe('topic')
|
|
833
|
+
* @example client.unsubscribe('topic', console.log)
|
|
834
|
+
* @example client.unsubscribe('topic', opts, console.log)
|
|
835
|
+
*/
|
|
836
|
+
public unsubscribe(topic: string | string[], opts?: Object, callback?: PacketCallback): this;
|
|
837
|
+
/**
|
|
838
|
+
* end - close connection
|
|
839
|
+
*
|
|
840
|
+
* @returns {MqttClient} this - for chaining
|
|
841
|
+
* @param {Boolean} force - do not wait for all in-flight messages to be acked
|
|
842
|
+
* @param {Object} opts - opts disconnect
|
|
843
|
+
* @param {Function} cb - called when the client has been closed
|
|
844
|
+
*
|
|
845
|
+
* @api public
|
|
846
|
+
*/
|
|
847
|
+
public end(force?: boolean, opts?: Object, cb?: CloseCallback): this;
|
|
848
|
+
/**
|
|
849
|
+
* removeOutgoingMessage - remove a message in outgoing store
|
|
850
|
+
* the outgoing callback will be called withe Error('Message removed') if the message is removed
|
|
851
|
+
*
|
|
852
|
+
* @param {Number} mid - messageId to remove message
|
|
853
|
+
* @returns {MqttClient} this - for chaining
|
|
854
|
+
* @api public
|
|
855
|
+
*
|
|
856
|
+
* @example client.removeOutgoingMessage(client.getLastMessageId());
|
|
857
|
+
*/
|
|
858
|
+
public removeOutgoingMessage(mid: number): this;
|
|
859
|
+
/**
|
|
860
|
+
* reconnect - connect again using the same options as connect()
|
|
861
|
+
*
|
|
862
|
+
* @param {Object} [opts] - optional reconnect options, includes:
|
|
863
|
+
* {Store} incomingStore - a store for the incoming packets
|
|
864
|
+
* {Store} outgoingStore - a store for the outgoing packets
|
|
865
|
+
* if opts is not given, current stores are used
|
|
866
|
+
*
|
|
867
|
+
* @returns {MqttClient} this - for chaining
|
|
868
|
+
*
|
|
869
|
+
* @api public
|
|
870
|
+
*/
|
|
871
|
+
public reconnect(opts?: IClientReconnectOptions): this;
|
|
872
|
+
/**
|
|
873
|
+
* Handle messages with backpressure support, one at a time.
|
|
874
|
+
* Override at will.
|
|
875
|
+
*
|
|
876
|
+
* @param packet packet the packet
|
|
877
|
+
* @param callback callback call when finished
|
|
878
|
+
* @api public
|
|
879
|
+
*/
|
|
880
|
+
public handleMessage(packet: Packet, callback: PacketCallback): void;
|
|
881
|
+
/**
|
|
882
|
+
* Handle auth packages for MQTT 5 enhanced authentication methods such
|
|
883
|
+
* as challenge response authentication.
|
|
884
|
+
*
|
|
885
|
+
* Challenge-response authentication flow would look something like this:
|
|
886
|
+
*
|
|
887
|
+
* --> CONNECT | authMethod = "mathChallenge" -->
|
|
888
|
+
* <-- AUTH | authMethod = "mathChallenge", authData = "12 + 34" <--
|
|
889
|
+
* --> AUTH | authMethod = "mathChallenge", authData = "46" -->
|
|
890
|
+
* <-- CONNACK | reasonCode = SUCCESS <--
|
|
891
|
+
*
|
|
892
|
+
* This form of authentication has several advantages over traditional
|
|
893
|
+
* credential-based approaches. For instance authentication without the direct
|
|
894
|
+
* exchange of authentication secrets.
|
|
895
|
+
*
|
|
896
|
+
* @param packet the auth packet to handle
|
|
897
|
+
* @param callback call when finished
|
|
898
|
+
* @api public
|
|
899
|
+
*/
|
|
900
|
+
public handleAuth(packet: IAuthPacket, callback: PacketCallback): void;
|
|
901
|
+
/**
|
|
902
|
+
* getLastMessageId
|
|
903
|
+
*/
|
|
904
|
+
public getLastMessageId(): number;
|
|
905
|
+
}
|
|
207
906
|
declare class RemoteVideoMcuTrack extends RemoteVideoTrack {
|
|
208
907
|
constructor(info: BaseTrackInfo);
|
|
209
908
|
}
|
|
@@ -227,6 +926,114 @@ declare class SdkError {
|
|
|
227
926
|
msg: string;
|
|
228
927
|
};
|
|
229
928
|
}
|
|
929
|
+
declare class Store {
|
|
930
|
+
/**
|
|
931
|
+
* Store constructor
|
|
932
|
+
*
|
|
933
|
+
* @param {Object} [options] - store options
|
|
934
|
+
*/
|
|
935
|
+
constructor(options: IStoreOptions);
|
|
936
|
+
/**
|
|
937
|
+
* Adds a packet to the store, a packet is
|
|
938
|
+
* anything that has a messageId property.
|
|
939
|
+
*
|
|
940
|
+
*/
|
|
941
|
+
public put(packet: any, cb?: Function): this;
|
|
942
|
+
/**
|
|
943
|
+
* Creates a stream with all the packets in the store
|
|
944
|
+
*
|
|
945
|
+
*/
|
|
946
|
+
public createStream(): any;
|
|
947
|
+
/**
|
|
948
|
+
* deletes a packet from the store.
|
|
949
|
+
*/
|
|
950
|
+
public del(packet: any, cb: Function): this;
|
|
951
|
+
/**
|
|
952
|
+
* get a packet from the store.
|
|
953
|
+
*/
|
|
954
|
+
public get(packet: any, cb: Function): this;
|
|
955
|
+
/**
|
|
956
|
+
* Close the store
|
|
957
|
+
*/
|
|
958
|
+
public close(cb: Function): void;
|
|
959
|
+
}
|
|
960
|
+
declare class TrackEventType extends CommonTrackEventType {
|
|
961
|
+
/** 轨道自动播放失败,对应data为BaseTrack */
|
|
962
|
+
static readonly AUTOPLAY_FAIL = "autoplay_fail";
|
|
963
|
+
/** mediastreamtrack轨道被替换,对应data为BaseTrack,oldMsTrack为旧的MediaStreamTrack */
|
|
964
|
+
static readonly MSTRACK_REPLACED = "mstrack_replaced";
|
|
965
|
+
/** 轨道流媒体开始断线自动重连,对应data为BaseTrack*/
|
|
966
|
+
static readonly RECONNECTING = "reconnecting";
|
|
967
|
+
/** 轨道流媒体重连成功,对应data为BaseTrack */
|
|
968
|
+
static readonly RECONNECTED = "reconnected";
|
|
969
|
+
/** 进入画中画模式,对应data为BaseTrack */
|
|
970
|
+
static readonly PIP_ENTER = "pip_enter";
|
|
971
|
+
/** 退出画中画模式,对应data为BaseTrack */
|
|
972
|
+
static readonly PIP_EXIT = "pip_exit";
|
|
973
|
+
/** 弹出独立窗口,对应data为BaseTrack */
|
|
974
|
+
static readonly POPOUT_OPEN = "popout_open";
|
|
975
|
+
/** 关闭独立窗口,对应data为BaseTrack */
|
|
976
|
+
static readonly POPOUT_CLOSE = "popout_close";
|
|
977
|
+
}
|
|
978
|
+
declare class UserContainer implements Iterable<[
|
|
979
|
+
string,
|
|
980
|
+
BaseUser
|
|
981
|
+
]> {
|
|
982
|
+
/** uid为key的user Map */
|
|
983
|
+
private ctn;
|
|
984
|
+
/** linkid为key,与uid的映射 */
|
|
985
|
+
private linkids;
|
|
986
|
+
/**
|
|
987
|
+
* 实现Iterator接口,支持for...of迭代
|
|
988
|
+
* @returns 返回迭代器,每次迭代返回[uid, user]键值对
|
|
989
|
+
*/
|
|
990
|
+
[Symbol.iterator](): Iterator<[
|
|
991
|
+
string,
|
|
992
|
+
BaseUser
|
|
993
|
+
]>;
|
|
994
|
+
/**
|
|
995
|
+
* 添加或覆盖某user
|
|
996
|
+
* @param uid
|
|
997
|
+
* @param user
|
|
998
|
+
*/
|
|
999
|
+
set(uid: string, user: BaseUser): void;
|
|
1000
|
+
/**
|
|
1001
|
+
* 获取某user
|
|
1002
|
+
* @param uid
|
|
1003
|
+
* @returns
|
|
1004
|
+
*/
|
|
1005
|
+
get(uid: string): BaseUser;
|
|
1006
|
+
/**
|
|
1007
|
+
* 根据linkid获取某user
|
|
1008
|
+
* @param linkid
|
|
1009
|
+
* @returns
|
|
1010
|
+
*/
|
|
1011
|
+
getByLinkid(linkid: string): BaseUser;
|
|
1012
|
+
/**
|
|
1013
|
+
* 删除某account
|
|
1014
|
+
* @param uid
|
|
1015
|
+
*/
|
|
1016
|
+
del(uid: string): void;
|
|
1017
|
+
/**
|
|
1018
|
+
* 清空
|
|
1019
|
+
*/
|
|
1020
|
+
clear(): void;
|
|
1021
|
+
/**
|
|
1022
|
+
* 获取成员对外信息列表
|
|
1023
|
+
* @returns
|
|
1024
|
+
*/
|
|
1025
|
+
listInfo(map: boolean): BaseUserInfo[] | Record<string, BaseUserInfo>;
|
|
1026
|
+
}
|
|
1027
|
+
declare enum ChannelConnectState {
|
|
1028
|
+
/** 初始状态 */
|
|
1029
|
+
INIT = "init",
|
|
1030
|
+
/** 已连接 */
|
|
1031
|
+
CONNECTED = "connected",
|
|
1032
|
+
/** 重连中 */
|
|
1033
|
+
RECONNECTING = "reconnecting",
|
|
1034
|
+
/** 已离会 */
|
|
1035
|
+
LEAVED = "leaved"
|
|
1036
|
+
}
|
|
230
1037
|
declare function dateFormat(format: string, date?: Date): string;
|
|
231
1038
|
declare function dct(t: string): any;
|
|
232
1039
|
declare function genNonce(len?: number): string;
|
|
@@ -244,14 +1051,6 @@ declare function retry<T>(f: () => Promise<T>, opt: {
|
|
|
244
1051
|
onRetry?: (attempt: number, e?: any) => boolean | void;
|
|
245
1052
|
}): retryCallback<T>;
|
|
246
1053
|
declare function sleep(ms: number): Promise<void>;
|
|
247
|
-
/** 频道事件通知 */
|
|
248
|
-
export declare class ChannelEvent {
|
|
249
|
-
/** 事件类型 */
|
|
250
|
-
type: CommonChannelEventType;
|
|
251
|
-
/** 事件携带的数据 */
|
|
252
|
-
data?: any;
|
|
253
|
-
constructor(type: CommonChannelEventType, data?: any);
|
|
254
|
-
}
|
|
255
1054
|
/** 扩展的频道事件 */
|
|
256
1055
|
export declare class ChannelEventType extends CommonChannelEventType {
|
|
257
1056
|
/** 外设插入,对应data为MediaDeviceInfo */
|
|
@@ -268,14 +1067,20 @@ export declare class ChannelEventType extends CommonChannelEventType {
|
|
|
268
1067
|
static readonly TRACK_POPOUT_OPEN = "track_popout_open";
|
|
269
1068
|
/** 轨道关闭独立窗口,对应data为BaseTrack */
|
|
270
1069
|
static readonly TRACK_POPOUT_CLOSE = "track_popout_close";
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
1070
|
+
/** 连接质量等级变化,对应data为 ConnectionQualityEventData */
|
|
1071
|
+
static readonly CONNECTION_QUALITY_CHANGED = "connection_quality_changed";
|
|
1072
|
+
/** 发送端被CPU持续限制,对应data为 QualityEvaluation */
|
|
1073
|
+
static readonly CPU_CONSTRAINED = "cpu_constrained";
|
|
1074
|
+
/** 发送端被带宽持续限制,对应data为 QualityEvaluation */
|
|
1075
|
+
static readonly BANDWIDTH_CONSTRAINED = "bandwidth_constrained";
|
|
1076
|
+
/**
|
|
1077
|
+
* 活跃说话人列表变化,对应data为 ActiveSpeakersEventData(全量快照)。
|
|
1078
|
+
*
|
|
1079
|
+
* 仅 SeaStart SFU 引擎支持;其他引擎(OOK/WangsuCDN)不会触发此事件。
|
|
1080
|
+
* 每次事件 data.speakers 都是当前正在说话的完整列表,按 level 降序,
|
|
1081
|
+
* 业务侧**直接覆盖 UI**即可,不需要自己合并增量。无人说话时会收到空列表。
|
|
1082
|
+
*/
|
|
1083
|
+
static readonly ACTIVE_SPEAKERS_CHANGED = "active_speakers_changed";
|
|
279
1084
|
}
|
|
280
1085
|
/**
|
|
281
1086
|
* 本地音频流轨道
|
|
@@ -470,6 +1275,10 @@ export declare class RemoteAudioTrack extends BaseWebrtcTrack {
|
|
|
470
1275
|
* 远端视频流轨道
|
|
471
1276
|
*/
|
|
472
1277
|
export declare class RemoteVideoTrack extends BaseWebrtcTrack {
|
|
1278
|
+
/**
|
|
1279
|
+
* 业务期望的抖动缓冲目标延迟(ms)。undefined 表示使用浏览器默认自适应策略。
|
|
1280
|
+
*/
|
|
1281
|
+
private jitterBufferTargetMs?;
|
|
473
1282
|
constructor(info: BaseTrackInfo, uid: string);
|
|
474
1283
|
/**
|
|
475
1284
|
* 添加播放窗口
|
|
@@ -519,8 +1328,42 @@ export declare class RemoteVideoTrack extends BaseWebrtcTrack {
|
|
|
519
1328
|
* @param container 播放容器
|
|
520
1329
|
*/
|
|
521
1330
|
isPopOut(container: HTMLElement): boolean;
|
|
1331
|
+
/**
|
|
1332
|
+
* 设置接收端抗抖动缓冲的目标延迟(ms),命名与 W3C jitterBufferTarget 规范对齐。
|
|
1333
|
+
* - 0:低延迟优先,浏览器会保持最小可用 buffer
|
|
1334
|
+
* - 较大值(如 200~500):缓冲优先,更平滑但延迟更高
|
|
1335
|
+
* - undefined:清除设置,回到浏览器自适应
|
|
1336
|
+
* 实际生效需要 Chrome/Edge(同时兼容 jitterBufferTarget 与老的 playoutDelayHint),
|
|
1337
|
+
* Firefox/Safari 静默忽略。
|
|
1338
|
+
*/
|
|
1339
|
+
setJitterBufferTarget(ms?: number): void;
|
|
1340
|
+
/**
|
|
1341
|
+
* 获取业务当前设定的抖动缓冲目标延迟(ms);undefined 表示未设置。
|
|
1342
|
+
*/
|
|
1343
|
+
getJitterBufferTarget(): number | undefined;
|
|
1344
|
+
/**
|
|
1345
|
+
* 同时写 jitterBufferTarget(W3C 标准,Chrome 113+)和 playoutDelayHint
|
|
1346
|
+
* (Chrome 私有扩展,Chrome 70+),让新老浏览器都能生效。
|
|
1347
|
+
* 浏览器只支持其中一个时另一个不存在,'in' 判断后静默跳过。
|
|
1348
|
+
*/
|
|
1349
|
+
private applyJitterBufferTarget;
|
|
522
1350
|
}
|
|
523
1351
|
export declare class SRTC extends BaseSRTC {
|
|
1352
|
+
/** 窄化父类的 channel 类型到 webrtc Channel,便于访问 webrtc 特有方法 */
|
|
1353
|
+
protected channel?: Channel | null;
|
|
1354
|
+
/**
|
|
1355
|
+
* 获取流媒体引擎的metric快照(全量,含每条轨道的统计)
|
|
1356
|
+
*/
|
|
1357
|
+
getStreamMetric(): StreamMetric | undefined;
|
|
1358
|
+
/**
|
|
1359
|
+
* 获取当前网络总体统计,只关心网络全景时用,比 getStreamMetric 更轻量
|
|
1360
|
+
*/
|
|
1361
|
+
getNetworkStats(): NetworkStats | undefined;
|
|
1362
|
+
/**
|
|
1363
|
+
* 获取当前连接质量评估结果(等级 / MOS / 触发原因)
|
|
1364
|
+
* 配合 ChannelEventType.CONNECTION_QUALITY_CHANGED 事件使用
|
|
1365
|
+
*/
|
|
1366
|
+
getConnectionQuality(): QualityEvaluation | undefined;
|
|
524
1367
|
buildInfo(): BuildInfo;
|
|
525
1368
|
/**
|
|
526
1369
|
* 获取web运行环境信息,如是否支持webrtc等
|
|
@@ -721,9 +1564,7 @@ export declare enum DeviceType {
|
|
|
721
1564
|
*/
|
|
722
1565
|
XCX = 7
|
|
723
1566
|
}
|
|
724
|
-
/**
|
|
725
|
-
* 用户离开频道的原因
|
|
726
|
-
*/
|
|
1567
|
+
/** 用户离开频道的原因 */
|
|
727
1568
|
export declare enum DisconnectReason {
|
|
728
1569
|
/** 错误 */
|
|
729
1570
|
Error = -1,
|
|
@@ -738,9 +1579,7 @@ export declare enum DisconnectReason {
|
|
|
738
1579
|
/** 频道销毁离开 */
|
|
739
1580
|
Destroy = 5
|
|
740
1581
|
}
|
|
741
|
-
/**
|
|
742
|
-
* 用户断开im的原因
|
|
743
|
-
*/
|
|
1582
|
+
/** 用户断开im的原因 */
|
|
744
1583
|
export declare enum ImDisconnectReason {
|
|
745
1584
|
/** 错误 */
|
|
746
1585
|
Error = -1,
|
|
@@ -788,6 +1627,40 @@ export declare function codec2str(codec: Codec): string;
|
|
|
788
1627
|
* 创建混音后的音频轨
|
|
789
1628
|
*/
|
|
790
1629
|
export declare function createMixedAudioMediaStreamTrack(canvasContext?: CanvasRenderingContext2D): MixedAudioMediaStreamTrack;
|
|
1630
|
+
/**
|
|
1631
|
+
* MessageIdProvider
|
|
1632
|
+
*/
|
|
1633
|
+
export declare interface IMessageIdProvider {
|
|
1634
|
+
/**
|
|
1635
|
+
* Allocate the first vacant messageId. The messageId become occupied status.
|
|
1636
|
+
* @return {Number} - The first vacant messageId. If all messageIds are occupied, return null.
|
|
1637
|
+
*/
|
|
1638
|
+
allocate(): Number | null;
|
|
1639
|
+
/**
|
|
1640
|
+
* Get the last allocated messageId.
|
|
1641
|
+
* @return {Number} - messageId.
|
|
1642
|
+
*/
|
|
1643
|
+
getLastAllocated(): Number | null;
|
|
1644
|
+
/**
|
|
1645
|
+
* Register the messageId. The messageId become occupied status.
|
|
1646
|
+
* If the messageId has already been occupied, then return false.
|
|
1647
|
+
* @param {Number} num - The messageId to request use.
|
|
1648
|
+
* @return {Boolean} - If `num` was not occupied, then return true, otherwise return false.
|
|
1649
|
+
*/
|
|
1650
|
+
register(num: Number): Boolean;
|
|
1651
|
+
/**
|
|
1652
|
+
* Deallocate the messageId. The messageId become vacant status.
|
|
1653
|
+
* @param {Number} num - The messageId to deallocate. The messageId must be occupied status.
|
|
1654
|
+
* In other words, the messageId must be allocated by allocate() or
|
|
1655
|
+
* occupied by register().
|
|
1656
|
+
*/
|
|
1657
|
+
deallocate(num: Number): void;
|
|
1658
|
+
/**
|
|
1659
|
+
* Clear all occupied messageIds.
|
|
1660
|
+
* The all messageIds are set to vacant status.
|
|
1661
|
+
*/
|
|
1662
|
+
clear(): void;
|
|
1663
|
+
}
|
|
791
1664
|
export declare namespace __INNER__ {
|
|
792
1665
|
const BaseSRTC_I: typeof BaseSRTC;
|
|
793
1666
|
const CommonChannelEventType_I: typeof CommonChannelEventType;
|
|
@@ -805,6 +1678,80 @@ export declare namespace __INNER__ {
|
|
|
805
1678
|
const dct_I: typeof dct;
|
|
806
1679
|
function hmac_I(msg: string, key: string): string;
|
|
807
1680
|
}
|
|
1681
|
+
export declare type ClientSubscribeCallback = (err: Error, granted: ISubscriptionGrant[]) => void;
|
|
1682
|
+
export declare type CloseCallback = (error?: Error) => void;
|
|
1683
|
+
export declare type OnCloseCallback = () => void;
|
|
1684
|
+
export declare type OnConnectCallback = (packet: IConnackPacket) => void;
|
|
1685
|
+
export declare type OnDisconnectCallback = (packet: IDisconnectPacket) => void;
|
|
1686
|
+
export declare type OnErrorCallback = (error: Error) => void;
|
|
1687
|
+
export declare type OnMessageCallback = (topic: string, payload: Buffer, packet: IPublishPacket) => void;
|
|
1688
|
+
export declare type OnPacketCallback = (packet: Packet) => void;
|
|
1689
|
+
export declare type PacketCallback = (error?: Error, packet?: Packet) => any;
|
|
1690
|
+
export declare type StorePutCallback = () => void;
|
|
1691
|
+
/**
|
|
1692
|
+
* Active speaker(说话中的用户)相关类型 / 事件枚举。
|
|
1693
|
+
*
|
|
1694
|
+
* 对应 SFU `audio_level.go` 通过 signal DataChannel 下发的 `active-speakers` 协议。
|
|
1695
|
+
* SDK 在 SeaStartWebrtc 内把服务端的**增量**事件合并成**全量**快照再对外广播,
|
|
1696
|
+
* 业务侧拿到的 `ActiveSpeakersEventData.speakers` 始终是当前正在说话的全量列表,
|
|
1697
|
+
* 不需要自己维护增量状态——这与 livekit-client `RoomEvent.ActiveSpeakersChanged` 一致。
|
|
1698
|
+
*/
|
|
1699
|
+
/**
|
|
1700
|
+
* 单个说话中的用户信息。
|
|
1701
|
+
*/
|
|
1702
|
+
export interface ActiveSpeakerInfo {
|
|
1703
|
+
/** 用户 id(对齐频道内 uid) */
|
|
1704
|
+
uid: string;
|
|
1705
|
+
/**
|
|
1706
|
+
* 对应的 audio track id。
|
|
1707
|
+
* 同一个 uid 理论上可能同时发布多条 audio track(极少见,比如左右声道独立),
|
|
1708
|
+
* 通过 trackId 区分避免 UI 合并。
|
|
1709
|
+
*/
|
|
1710
|
+
trackId: string;
|
|
1711
|
+
/**
|
|
1712
|
+
* 当前音量,归一化线性值 0~1。
|
|
1713
|
+
* 1 对应 0 dBov 理论最大,0 对应静音。
|
|
1714
|
+
* 服务端已量化到 1/8 的档位(对齐 livekit),UI 直接映射音柱宽度即可;
|
|
1715
|
+
* 若想转 dB,用 `20 * Math.log10(level)`。
|
|
1716
|
+
*/
|
|
1717
|
+
level: number;
|
|
1718
|
+
}
|
|
1719
|
+
/**
|
|
1720
|
+
* ACTIVE_SPEAKERS_CHANGED 事件的 data。
|
|
1721
|
+
*
|
|
1722
|
+
* 语义:**每次都是当前房间正在说话的全量快照**(按 level 降序)。
|
|
1723
|
+
* - 有人开始说话:speakers 新增一项;
|
|
1724
|
+
* - 有人停止说话:speakers 相应条目消失;
|
|
1725
|
+
* - 无人说话:speakers 为 []。
|
|
1726
|
+
*
|
|
1727
|
+
* 业务侧典型用法:
|
|
1728
|
+
* channel.on(ChannelEventType.ACTIVE_SPEAKERS_CHANGED, (data) => {
|
|
1729
|
+
* renderAudioBars(data.speakers)
|
|
1730
|
+
* })
|
|
1731
|
+
*/
|
|
1732
|
+
export interface ActiveSpeakersEventData {
|
|
1733
|
+
/** 服务端下发时间戳(unix 毫秒),用于排序/诊断 */
|
|
1734
|
+
ts: number;
|
|
1735
|
+
/** 当前正在说话的用户列表,按 level 从大到小排序 */
|
|
1736
|
+
speakers: ActiveSpeakerInfo[];
|
|
1737
|
+
}
|
|
1738
|
+
/**
|
|
1739
|
+
* 远端视频自适应流配置。
|
|
1740
|
+
* 设计上对齐 LiveKit 的 adaptive stream,但先聚焦于当前 SDK 已具备的“主动切层”能力。
|
|
1741
|
+
*/
|
|
1742
|
+
export interface AdaptiveStreamOptions {
|
|
1743
|
+
/**
|
|
1744
|
+
* 像素密度倍率。
|
|
1745
|
+
* - `screen`:使用真实 `window.devicePixelRatio`
|
|
1746
|
+
* - 不传:高密屏默认取 2,其余取 1
|
|
1747
|
+
*/
|
|
1748
|
+
pixelDensity?: number | "screen";
|
|
1749
|
+
/**
|
|
1750
|
+
* 页面切到后台时,是否按“不可见”处理远端视频,默认 true。
|
|
1751
|
+
* 当前实现没有“暂停下行”协议,因此后台时会切到最低候选层,而不是直接停流。
|
|
1752
|
+
*/
|
|
1753
|
+
pauseVideoInBackground?: boolean;
|
|
1754
|
+
}
|
|
808
1755
|
/**
|
|
809
1756
|
* 扬声器配置
|
|
810
1757
|
*/
|
|
@@ -873,6 +1820,59 @@ export interface AudioSenderStats extends SenderStats {
|
|
|
873
1820
|
/** 音频电平 */
|
|
874
1821
|
audioLevel?: number;
|
|
875
1822
|
}
|
|
1823
|
+
/** 重连时刷新auth */
|
|
1824
|
+
export interface AuthReconnect {
|
|
1825
|
+
(url: string, options: IClientOptions, client: MqttClient): string;
|
|
1826
|
+
}
|
|
1827
|
+
/**
|
|
1828
|
+
* 频道基类
|
|
1829
|
+
*
|
|
1830
|
+
* 事件类型通过 `ChannelEventDataMap` 与 data 类型强关联,
|
|
1831
|
+
* 子类如 webrtc / wx 通过 `declare module '../base/event'` 合并扩展事件。
|
|
1832
|
+
* 下面这段 interface 声明不是另起炉灶,而是用 TS declaration merging 在 EventEmitter
|
|
1833
|
+
* 的 `on/once/off/addListener/removeListener/emit` 上加强类型化重载;保留父类宽松签名
|
|
1834
|
+
* 作为兜底,不影响内部既有 `this.rtcSocket.on(SocketEvent.XXX)` 等用法。
|
|
1835
|
+
*/
|
|
1836
|
+
export interface BaseChannel {
|
|
1837
|
+
on<K extends keyof ChannelEventDataMap>(type: K, listener: (event: ChannelEventOf<K>) => void): this;
|
|
1838
|
+
once<K extends keyof ChannelEventDataMap>(type: K, listener: (event: ChannelEventOf<K>) => void): this;
|
|
1839
|
+
off<K extends keyof ChannelEventDataMap>(type: K, listener: (event: ChannelEventOf<K>) => void): this;
|
|
1840
|
+
addListener<K extends keyof ChannelEventDataMap>(type: K, listener: (event: ChannelEventOf<K>) => void): this;
|
|
1841
|
+
removeListener<K extends keyof ChannelEventDataMap>(type: K, listener: (event: ChannelEventOf<K>) => void): this;
|
|
1842
|
+
emit<K extends keyof ChannelEventDataMap>(type: K, event: ChannelEventOf<K>): boolean;
|
|
1843
|
+
}
|
|
1844
|
+
/**
|
|
1845
|
+
* 流轨道
|
|
1846
|
+
*
|
|
1847
|
+
* 轨道事件(MUTED/UNMUTED/ENDED/INFO_UPDATE 等)的 data 类型通过 `TrackEventDataMap` 和
|
|
1848
|
+
* type 强关联;webrtc / wx 子模块通过 `declare module '../base/event'` 扩展。
|
|
1849
|
+
* 下面这段 interface 是 declaration merging,为 EventEmitter 的事件方法加类型化重载。
|
|
1850
|
+
*/
|
|
1851
|
+
export interface BaseTrack {
|
|
1852
|
+
on<K extends keyof TrackEventDataMap>(type: K, listener: (data: TrackEventDataMap[K]) => void): this;
|
|
1853
|
+
on(type: string | symbol, listener: (...args: any[]) => void): this;
|
|
1854
|
+
once<K extends keyof TrackEventDataMap>(type: K, listener: (data: TrackEventDataMap[K]) => void): this;
|
|
1855
|
+
once(type: string | symbol, listener: (...args: any[]) => void): this;
|
|
1856
|
+
off<K extends keyof TrackEventDataMap>(type: K, listener: (data: TrackEventDataMap[K]) => void): this;
|
|
1857
|
+
off(type: string | symbol, listener: (...args: any[]) => void): this;
|
|
1858
|
+
addListener<K extends keyof TrackEventDataMap>(type: K, listener: (data: TrackEventDataMap[K]) => void): this;
|
|
1859
|
+
addListener(type: string | symbol, listener: (...args: any[]) => void): this;
|
|
1860
|
+
removeListener<K extends keyof TrackEventDataMap>(type: K, listener: (data: TrackEventDataMap[K]) => void): this;
|
|
1861
|
+
removeListener(type: string | symbol, listener: (...args: any[]) => void): this;
|
|
1862
|
+
emit<K extends keyof TrackEventDataMap>(type: K, data: TrackEventDataMap[K]): boolean;
|
|
1863
|
+
emit(type: string | symbol, ...args: any[]): boolean;
|
|
1864
|
+
listeners<K extends keyof TrackEventDataMap>(type: K): ((data: TrackEventDataMap[K]) => void)[];
|
|
1865
|
+
listeners(type: string | symbol): Function[];
|
|
1866
|
+
}
|
|
1867
|
+
/**
|
|
1868
|
+
* track临时扩展,方便统一管理
|
|
1869
|
+
*/
|
|
1870
|
+
export interface BaseTrackEx {
|
|
1871
|
+
kind: TrackKind;
|
|
1872
|
+
track: BaseTrack;
|
|
1873
|
+
opt?: AudioPublishOptions | VideoPublishOptions;
|
|
1874
|
+
exopt: Record<string, any>;
|
|
1875
|
+
}
|
|
876
1876
|
/**
|
|
877
1877
|
* sdk编译信息
|
|
878
1878
|
*/
|
|
@@ -915,6 +1915,82 @@ export interface CameraPreset {
|
|
|
915
1915
|
capture: CameraCaptureOptions;
|
|
916
1916
|
publish: VideoPublishOptions;
|
|
917
1917
|
}
|
|
1918
|
+
export interface ChannelEventDataMap {
|
|
1919
|
+
[ChannelEventType.DEVICE_ADD]: MediaDeviceInfo;
|
|
1920
|
+
[ChannelEventType.DEVICE_REMOVE]: MediaDeviceInfo;
|
|
1921
|
+
[ChannelEventType.TRACK_AUTOPLAY_FAIL]: BaseTrack;
|
|
1922
|
+
[ChannelEventType.TRACK_PIP_ENTER]: BaseTrack;
|
|
1923
|
+
[ChannelEventType.TRACK_PIP_EXIT]: BaseTrack;
|
|
1924
|
+
[ChannelEventType.TRACK_POPOUT_OPEN]: BaseTrack;
|
|
1925
|
+
[ChannelEventType.TRACK_POPOUT_CLOSE]: BaseTrack;
|
|
1926
|
+
[ChannelEventType.CONNECTION_QUALITY_CHANGED]: ConnectionQualityEventData;
|
|
1927
|
+
[ChannelEventType.CPU_CONSTRAINED]: QualityEvaluation;
|
|
1928
|
+
[ChannelEventType.BANDWIDTH_CONSTRAINED]: QualityEvaluation;
|
|
1929
|
+
[ChannelEventType.ACTIVE_SPEAKERS_CHANGED]: ActiveSpeakersEventData;
|
|
1930
|
+
}
|
|
1931
|
+
/**
|
|
1932
|
+
* 频道事件 type → data 类型的**中央映射**。
|
|
1933
|
+
*
|
|
1934
|
+
* 为什么要这个?
|
|
1935
|
+
* 旧版 `ChannelEvent.data: any`,事件类型和 data 形状的对应关系只能靠注释维护,
|
|
1936
|
+
* 上层既无补全也无校验。把关系搬进 TS 类型系统后:
|
|
1937
|
+
* - `channel.on(type, listener)`:listener 的 `evt.data` 自动推断到精确类型;
|
|
1938
|
+
* - `switch(evt.type)` 判别联合:分支内 `evt.data` 自动收窄;
|
|
1939
|
+
* - 新增事件时**必须**在这里(或子模块合并里)补齐 data 类型,再也不能漏。
|
|
1940
|
+
*
|
|
1941
|
+
* 扩展方式(子模块 webrtc / wx):用 TS interface merging(`declare module`)往里加事件:
|
|
1942
|
+
* ```
|
|
1943
|
+
* declare module '../base/event' {
|
|
1944
|
+
* interface ChannelEventDataMap {
|
|
1945
|
+
* [ChannelEventType.DEVICE_ADD]: MediaDeviceInfo;
|
|
1946
|
+
* }
|
|
1947
|
+
* }
|
|
1948
|
+
* ```
|
|
1949
|
+
*/
|
|
1950
|
+
export interface ChannelEventDataMap {
|
|
1951
|
+
[CommonChannelEventType.CHANNEL_UPDATE]: BaseChannelInfo;
|
|
1952
|
+
[CommonChannelEventType.JOIN_SUCCEED]: BaseChannelInfo;
|
|
1953
|
+
[CommonChannelEventType.ME_UPDATE]: BaseUserInfo;
|
|
1954
|
+
[CommonChannelEventType.RECONNECTING]: undefined;
|
|
1955
|
+
[CommonChannelEventType.RECONNECTED]: undefined;
|
|
1956
|
+
[CommonChannelEventType.DISCONNECTED]: DisconnectEventData;
|
|
1957
|
+
[CommonChannelEventType.USER_JOIN]: BaseUserInfo;
|
|
1958
|
+
[CommonChannelEventType.USER_UPDATE]: BaseUserInfo;
|
|
1959
|
+
[CommonChannelEventType.USER_LEAVE]: UserLeaveEventData;
|
|
1960
|
+
[CommonChannelEventType.USER_TRACK_ADD]: UserTrackEventData;
|
|
1961
|
+
[CommonChannelEventType.USER_TRACK_UPDATE]: UserTrackEventData;
|
|
1962
|
+
[CommonChannelEventType.USER_TRACK_REMOVE]: UserTrackEventData;
|
|
1963
|
+
[CommonChannelEventType.CUSTOM_MSG]: CustomMsgData;
|
|
1964
|
+
[CommonChannelEventType.TRACK_MUTED]: BaseTrack;
|
|
1965
|
+
[CommonChannelEventType.TRACK_UNMUTED]: BaseTrack;
|
|
1966
|
+
[CommonChannelEventType.TRACK_ENDED]: BaseTrack;
|
|
1967
|
+
}
|
|
1968
|
+
/**
|
|
1969
|
+
* 加入频道api返回
|
|
1970
|
+
*/
|
|
1971
|
+
export interface ChannelJoinRsp extends ReconnectRsp {
|
|
1972
|
+
/** 应用ID */
|
|
1973
|
+
app_id: string;
|
|
1974
|
+
/** 用户ID */
|
|
1975
|
+
uid: string;
|
|
1976
|
+
/** 会话ID */
|
|
1977
|
+
sid: string;
|
|
1978
|
+
/** 频道名 */
|
|
1979
|
+
channel: string;
|
|
1980
|
+
/** 网络 */
|
|
1981
|
+
net: string;
|
|
1982
|
+
/** 流媒体服务方 */
|
|
1983
|
+
stream_vendor: string;
|
|
1984
|
+
/** 频道流媒体连接id */
|
|
1985
|
+
channel_link_id: string;
|
|
1986
|
+
/** 用户流媒体连接id */
|
|
1987
|
+
link_id: number;
|
|
1988
|
+
/** 用户流媒体授权key */
|
|
1989
|
+
session_key: string;
|
|
1990
|
+
device_type: DeviceType;
|
|
1991
|
+
device_id: string;
|
|
1992
|
+
version: string;
|
|
1993
|
+
}
|
|
918
1994
|
/**
|
|
919
1995
|
* 连接质量变化事件 data
|
|
920
1996
|
*/
|
|
@@ -941,9 +2017,7 @@ export interface CustomMsgData {
|
|
|
941
2017
|
/** 是否私发 */
|
|
942
2018
|
private: boolean;
|
|
943
2019
|
}
|
|
944
|
-
/**
|
|
945
|
-
* 强制离开事件data
|
|
946
|
-
*/
|
|
2020
|
+
/** 强制离开事件data */
|
|
947
2021
|
export interface DisconnectEventData {
|
|
948
2022
|
/** 离开原因 */
|
|
949
2023
|
reason: DisconnectReason;
|
|
@@ -1035,6 +2109,203 @@ export interface EnvWebInfo extends Bowser$1.Parser.ParsedResult {
|
|
|
1035
2109
|
*/
|
|
1036
2110
|
devicePixelRatio: number;
|
|
1037
2111
|
}
|
|
2112
|
+
export interface IClientOptions extends ISecureClientOptions {
|
|
2113
|
+
port?: number; // port is made into a number subsequently
|
|
2114
|
+
host?: string; // host does NOT include port
|
|
2115
|
+
hostname?: string;
|
|
2116
|
+
path?: string;
|
|
2117
|
+
protocol?: "wss" | "ws" | "mqtt" | "mqtts" | "tcp" | "ssl" | "wx" | "wxs";
|
|
2118
|
+
wsOptions?: ClientOptions | ClientRequestArgs;
|
|
2119
|
+
/**
|
|
2120
|
+
* 10 seconds, set to 0 to disable
|
|
2121
|
+
*/
|
|
2122
|
+
keepalive?: number;
|
|
2123
|
+
/**
|
|
2124
|
+
* 'mqttjs_' + Math.random().toString(16).substr(2, 8)
|
|
2125
|
+
*/
|
|
2126
|
+
clientId?: string;
|
|
2127
|
+
/**
|
|
2128
|
+
* 'MQTT'
|
|
2129
|
+
*/
|
|
2130
|
+
protocolId?: string;
|
|
2131
|
+
/**
|
|
2132
|
+
* 4
|
|
2133
|
+
*/
|
|
2134
|
+
protocolVersion?: number;
|
|
2135
|
+
/**
|
|
2136
|
+
* true, set to false to receive QoS 1 and 2 messages while offline
|
|
2137
|
+
*/
|
|
2138
|
+
clean?: boolean;
|
|
2139
|
+
/**
|
|
2140
|
+
* 1000 milliseconds, interval between two reconnections
|
|
2141
|
+
*/
|
|
2142
|
+
reconnectPeriod?: number;
|
|
2143
|
+
/**
|
|
2144
|
+
* 30 * 1000 milliseconds, time to wait before a CONNACK is received
|
|
2145
|
+
*/
|
|
2146
|
+
connectTimeout?: number;
|
|
2147
|
+
/**
|
|
2148
|
+
* the username required by your broker, if any
|
|
2149
|
+
*/
|
|
2150
|
+
username?: string;
|
|
2151
|
+
/**
|
|
2152
|
+
* the password required by your broker, if any
|
|
2153
|
+
*/
|
|
2154
|
+
password?: string;
|
|
2155
|
+
/**
|
|
2156
|
+
* a Store for the incoming packets
|
|
2157
|
+
*/
|
|
2158
|
+
incomingStore?: Store;
|
|
2159
|
+
/**
|
|
2160
|
+
* a Store for the outgoing packets
|
|
2161
|
+
*/
|
|
2162
|
+
outgoingStore?: Store;
|
|
2163
|
+
queueQoSZero?: boolean;
|
|
2164
|
+
reschedulePings?: boolean;
|
|
2165
|
+
servers?: Array<{
|
|
2166
|
+
host: string;
|
|
2167
|
+
port: number;
|
|
2168
|
+
protocol?: "wss" | "ws" | "mqtt" | "mqtts" | "tcp" | "ssl" | "wx" | "wxs";
|
|
2169
|
+
}>;
|
|
2170
|
+
/**
|
|
2171
|
+
* true, set to false to disable re-subscribe functionality
|
|
2172
|
+
*/
|
|
2173
|
+
resubscribe?: boolean;
|
|
2174
|
+
/**
|
|
2175
|
+
* a message that will sent by the broker automatically when the client disconnect badly.
|
|
2176
|
+
*/
|
|
2177
|
+
will?: {
|
|
2178
|
+
/**
|
|
2179
|
+
* the topic to publish
|
|
2180
|
+
*/
|
|
2181
|
+
topic: string;
|
|
2182
|
+
/**
|
|
2183
|
+
* the message to publish
|
|
2184
|
+
*/
|
|
2185
|
+
payload: Buffer | string;
|
|
2186
|
+
/**
|
|
2187
|
+
* the QoS
|
|
2188
|
+
*/
|
|
2189
|
+
qos: QoS;
|
|
2190
|
+
/**
|
|
2191
|
+
* the retain flag
|
|
2192
|
+
*/
|
|
2193
|
+
retain: boolean;
|
|
2194
|
+
/*
|
|
2195
|
+
* properies object of will
|
|
2196
|
+
* */
|
|
2197
|
+
properties?: {
|
|
2198
|
+
willDelayInterval?: number;
|
|
2199
|
+
payloadFormatIndicator?: boolean;
|
|
2200
|
+
messageExpiryInterval?: number;
|
|
2201
|
+
contentType?: string;
|
|
2202
|
+
responseTopic?: string;
|
|
2203
|
+
correlationData?: Buffer;
|
|
2204
|
+
userProperties?: UserProperties;
|
|
2205
|
+
};
|
|
2206
|
+
};
|
|
2207
|
+
transformWsUrl?: (url: string, options: IClientOptions, client: MqttClient) => string;
|
|
2208
|
+
properties?: {
|
|
2209
|
+
sessionExpiryInterval?: number;
|
|
2210
|
+
receiveMaximum?: number;
|
|
2211
|
+
maximumPacketSize?: number;
|
|
2212
|
+
topicAliasMaximum?: number;
|
|
2213
|
+
requestResponseInformation?: boolean;
|
|
2214
|
+
requestProblemInformation?: boolean;
|
|
2215
|
+
userProperties?: UserProperties;
|
|
2216
|
+
authenticationMethod?: string;
|
|
2217
|
+
authenticationData?: Buffer;
|
|
2218
|
+
};
|
|
2219
|
+
messageIdProvider?: IMessageIdProvider;
|
|
2220
|
+
}
|
|
2221
|
+
export interface IClientPublishOptions {
|
|
2222
|
+
/**
|
|
2223
|
+
* the QoS
|
|
2224
|
+
*/
|
|
2225
|
+
qos?: QoS;
|
|
2226
|
+
/**
|
|
2227
|
+
* the retain flag
|
|
2228
|
+
*/
|
|
2229
|
+
retain?: boolean;
|
|
2230
|
+
/**
|
|
2231
|
+
* whether or not mark a message as duplicate
|
|
2232
|
+
*/
|
|
2233
|
+
dup?: boolean;
|
|
2234
|
+
/*
|
|
2235
|
+
* MQTT 5.0 properties object
|
|
2236
|
+
*/
|
|
2237
|
+
properties?: {
|
|
2238
|
+
payloadFormatIndicator?: boolean;
|
|
2239
|
+
messageExpiryInterval?: number;
|
|
2240
|
+
topicAlias?: number;
|
|
2241
|
+
responseTopic?: string;
|
|
2242
|
+
correlationData?: Buffer;
|
|
2243
|
+
userProperties?: UserProperties;
|
|
2244
|
+
subscriptionIdentifier?: number;
|
|
2245
|
+
contentType?: string;
|
|
2246
|
+
};
|
|
2247
|
+
/**
|
|
2248
|
+
* callback called when message is put into `outgoingStore`
|
|
2249
|
+
*/
|
|
2250
|
+
cbStorePut?: StorePutCallback;
|
|
2251
|
+
}
|
|
2252
|
+
export interface IClientReconnectOptions {
|
|
2253
|
+
/**
|
|
2254
|
+
* a Store for the incoming packets
|
|
2255
|
+
*/
|
|
2256
|
+
incomingStore?: Store;
|
|
2257
|
+
/**
|
|
2258
|
+
* a Store for the outgoing packets
|
|
2259
|
+
*/
|
|
2260
|
+
outgoingStore?: Store;
|
|
2261
|
+
}
|
|
2262
|
+
export interface IClientSubscribeOptions {
|
|
2263
|
+
/**
|
|
2264
|
+
* the QoS
|
|
2265
|
+
*/
|
|
2266
|
+
qos: QoS;
|
|
2267
|
+
/*
|
|
2268
|
+
* no local flag
|
|
2269
|
+
* */
|
|
2270
|
+
nl?: boolean;
|
|
2271
|
+
/*
|
|
2272
|
+
* Retain As Published flag
|
|
2273
|
+
* */
|
|
2274
|
+
rap?: boolean;
|
|
2275
|
+
/*
|
|
2276
|
+
* Retain Handling option
|
|
2277
|
+
* */
|
|
2278
|
+
rh?: number;
|
|
2279
|
+
/*
|
|
2280
|
+
* MQTT 5.0 properies object of subscribe
|
|
2281
|
+
* */
|
|
2282
|
+
properties?: {
|
|
2283
|
+
subscriptionIdentifier?: number;
|
|
2284
|
+
userProperties?: UserProperties;
|
|
2285
|
+
};
|
|
2286
|
+
}
|
|
2287
|
+
/** 本地模拟远端混音流轨接口 */
|
|
2288
|
+
export interface IMockRemoteAudioMixTrack {
|
|
2289
|
+
readonly __type: "MockRemoteAudioMixTrack";
|
|
2290
|
+
/**
|
|
2291
|
+
* 检查是否要过滤某track
|
|
2292
|
+
* @param track
|
|
2293
|
+
* @returns
|
|
2294
|
+
*/
|
|
2295
|
+
checkFilter(track: BaseTrack): boolean;
|
|
2296
|
+
/**
|
|
2297
|
+
* 添加轨道
|
|
2298
|
+
*/
|
|
2299
|
+
addTrack(track: BaseTrack): void;
|
|
2300
|
+
/**
|
|
2301
|
+
* 移除轨道
|
|
2302
|
+
*/
|
|
2303
|
+
removeTrack(track: BaseTrack): void;
|
|
2304
|
+
/**
|
|
2305
|
+
* 停止混音
|
|
2306
|
+
*/
|
|
2307
|
+
stop(): void;
|
|
2308
|
+
}
|
|
1038
2309
|
/** 远端混音流轨接口 */
|
|
1039
2310
|
export interface IRemoteAudioMixTrack {
|
|
1040
2311
|
readonly __type: "RemoteAudioMixTrack";
|
|
@@ -1043,15 +2314,91 @@ export interface IRemoteAudioMixTrack {
|
|
|
1043
2314
|
*/
|
|
1044
2315
|
getFilterUids(): string[];
|
|
1045
2316
|
}
|
|
2317
|
+
export interface ISecureClientOptions {
|
|
2318
|
+
/**
|
|
2319
|
+
* optional private keys in PEM format
|
|
2320
|
+
*/
|
|
2321
|
+
key?: string | string[] | Buffer | Buffer[] | Object[];
|
|
2322
|
+
/**
|
|
2323
|
+
* optional cert chains in PEM format
|
|
2324
|
+
*/
|
|
2325
|
+
cert?: string | string[] | Buffer | Buffer[];
|
|
2326
|
+
/**
|
|
2327
|
+
* Optionally override the trusted CA certificates in PEM format
|
|
2328
|
+
*/
|
|
2329
|
+
ca?: string | string[] | Buffer | Buffer[];
|
|
2330
|
+
rejectUnauthorized?: boolean;
|
|
2331
|
+
/**
|
|
2332
|
+
* optional alpn's
|
|
2333
|
+
*/
|
|
2334
|
+
ALPNProtocols?: string[] | Buffer[] | Uint8Array[] | Buffer | Uint8Array;
|
|
2335
|
+
}
|
|
2336
|
+
export interface IStoreOptions {
|
|
2337
|
+
/**
|
|
2338
|
+
* true, clear _inflights at close
|
|
2339
|
+
*/
|
|
2340
|
+
clean?: boolean;
|
|
2341
|
+
}
|
|
2342
|
+
export interface IStream extends EventEmitter {
|
|
2343
|
+
pipe(to: any): any;
|
|
2344
|
+
destroy(): any;
|
|
2345
|
+
end(): any;
|
|
2346
|
+
}
|
|
2347
|
+
export interface ISubscriptionGrant {
|
|
2348
|
+
/**
|
|
2349
|
+
* is a subscribed to topic
|
|
2350
|
+
*/
|
|
2351
|
+
topic: string;
|
|
2352
|
+
/**
|
|
2353
|
+
* is the granted qos level on it, may return 128 on error
|
|
2354
|
+
*/
|
|
2355
|
+
qos: QoS | number;
|
|
2356
|
+
/*
|
|
2357
|
+
* no local flag
|
|
2358
|
+
* */
|
|
2359
|
+
nl?: boolean;
|
|
2360
|
+
/*
|
|
2361
|
+
* Retain As Published flag
|
|
2362
|
+
* */
|
|
2363
|
+
rap?: boolean;
|
|
2364
|
+
/*
|
|
2365
|
+
* Retain Handling option
|
|
2366
|
+
* */
|
|
2367
|
+
rh?: number;
|
|
2368
|
+
}
|
|
2369
|
+
export interface ISubscriptionMap {
|
|
2370
|
+
/**
|
|
2371
|
+
* object which has topic names as object keys and as value the options, like {'test1': {qos: 0}, 'test2': {qos: 2}}.
|
|
2372
|
+
*/
|
|
2373
|
+
[topic: string]: {
|
|
2374
|
+
qos: QoS;
|
|
2375
|
+
nl?: boolean;
|
|
2376
|
+
rap?: boolean;
|
|
2377
|
+
rh?: number;
|
|
2378
|
+
};
|
|
2379
|
+
}
|
|
1046
2380
|
/**
|
|
1047
|
-
* im
|
|
2381
|
+
* im频道外消息连接/重连api返回
|
|
1048
2382
|
*/
|
|
2383
|
+
export interface ImConnectRsp {
|
|
2384
|
+
/** mqtt信息 */
|
|
2385
|
+
mqtt: MqttServer;
|
|
2386
|
+
}
|
|
2387
|
+
/** im强制断开事件data */
|
|
1049
2388
|
export interface ImDisconnectEventData {
|
|
1050
2389
|
/** 断开原因 */
|
|
1051
2390
|
reason: ImDisconnectReason;
|
|
1052
2391
|
/** 错误 */
|
|
1053
2392
|
error?: any;
|
|
1054
2393
|
}
|
|
2394
|
+
/** im 事件 type → data 类型映射。扩展方式同 `ChannelEventDataMap` */
|
|
2395
|
+
export interface ImEventDataMap {
|
|
2396
|
+
[CommonImEventType.ENABLE_SUCCEED]: undefined;
|
|
2397
|
+
[CommonImEventType.RECONNECTING]: undefined;
|
|
2398
|
+
[CommonImEventType.RECONNECTED]: undefined;
|
|
2399
|
+
[CommonImEventType.DISCONNECTED]: ImDisconnectEventData;
|
|
2400
|
+
[CommonImEventType.IM_MSG]: ImMsgData;
|
|
2401
|
+
}
|
|
1055
2402
|
/**
|
|
1056
2403
|
* im频道外消息
|
|
1057
2404
|
*/
|
|
@@ -1087,6 +2434,17 @@ export interface JoinOptions {
|
|
|
1087
2434
|
* 希望的优先音频编码类型
|
|
1088
2435
|
*/
|
|
1089
2436
|
preferAudioCodec?: Codec;
|
|
2437
|
+
/**
|
|
2438
|
+
* 是否启用远端视频自适应流。
|
|
2439
|
+
* 启用后,SDK 会根据 video 容器的显示/隐藏、尺寸变化,以及页面前后台状态,
|
|
2440
|
+
* 自动为远端视频选择更合适的 simulcast 层。
|
|
2441
|
+
*
|
|
2442
|
+
* 说明:
|
|
2443
|
+
* - 当前仅 WebRTC Seastart SFU 生效
|
|
2444
|
+
* - `true` 表示使用默认策略
|
|
2445
|
+
* - 传对象可进一步调整像素密度和后台页面策略
|
|
2446
|
+
*/
|
|
2447
|
+
adaptiveStream?: boolean | AdaptiveStreamOptions;
|
|
1090
2448
|
}
|
|
1091
2449
|
/**
|
|
1092
2450
|
* 麦克风采集配置
|
|
@@ -1141,6 +2499,29 @@ export interface MixedAudioMediaStreamTrack extends MediaStreamTrack {
|
|
|
1141
2499
|
removeTrack(track: MediaStreamTrack): void;
|
|
1142
2500
|
trackCount: number;
|
|
1143
2501
|
}
|
|
2502
|
+
/**
|
|
2503
|
+
* MQTT 服务器配置
|
|
2504
|
+
*/
|
|
2505
|
+
export interface MqttServer {
|
|
2506
|
+
/** MQTT 服务名称 */
|
|
2507
|
+
name: string;
|
|
2508
|
+
/** mqtt 客户端连接通过 jwt 验证授权,username 用 uid,clientid 用 sid */
|
|
2509
|
+
/** https://www.emqx.io/docs/zh/latest/access-control/authn/jwt.html */
|
|
2510
|
+
/** jwt 里加上权限控制,仅允许订阅特定 topic(不允许发送) */
|
|
2511
|
+
jwt_token: string;
|
|
2512
|
+
/** jwt token过期时间 */
|
|
2513
|
+
token_exp_at: number;
|
|
2514
|
+
/** tcp 连接地址 */
|
|
2515
|
+
tcp: string;
|
|
2516
|
+
/** ws 连接地址 */
|
|
2517
|
+
ws: string;
|
|
2518
|
+
/** 连接用的client id */
|
|
2519
|
+
client_id: string;
|
|
2520
|
+
/** 连接用的username */
|
|
2521
|
+
username: string;
|
|
2522
|
+
/** 监听的 topics */
|
|
2523
|
+
topics: string[];
|
|
2524
|
+
}
|
|
1144
2525
|
/**
|
|
1145
2526
|
* 网络总体统计
|
|
1146
2527
|
*/
|
|
@@ -1165,8 +2546,10 @@ export interface NetworkStats {
|
|
|
1165
2546
|
available_outgoing_bitrate?: number;
|
|
1166
2547
|
/** SFU/BWE 估算的可用下行带宽 kb/s,来自 candidate-pair */
|
|
1167
2548
|
available_incoming_bitrate?: number;
|
|
1168
|
-
/**
|
|
1169
|
-
|
|
2549
|
+
/** 发布连接观测到的 RTT,单位 ms */
|
|
2550
|
+
rtt_up?: number;
|
|
2551
|
+
/** 订阅连接观测到的 RTT,单位 ms */
|
|
2552
|
+
rtt_down?: number;
|
|
1170
2553
|
}
|
|
1171
2554
|
/** 画中画句柄,用于控制画中画状态 */
|
|
1172
2555
|
export interface PipHandle {
|
|
@@ -1232,7 +2615,7 @@ export interface QualityEvaluation {
|
|
|
1232
2615
|
downlink: ConnectionQuality;
|
|
1233
2616
|
/** 总体质量,取上下行中较差的一档 */
|
|
1234
2617
|
overall: ConnectionQuality;
|
|
1235
|
-
/**
|
|
2618
|
+
/** 音视频 MOS 估算,范围 1.0 ~ 4.5 */
|
|
1236
2619
|
mos: number;
|
|
1237
2620
|
/** 触发当前等级的主要原因描述,便于排查 */
|
|
1238
2621
|
reasons: string[];
|
|
@@ -1243,21 +2626,51 @@ export interface QualityEvaluation {
|
|
|
1243
2626
|
* 接收数据统计
|
|
1244
2627
|
*/
|
|
1245
2628
|
export interface ReceiverStats {
|
|
1246
|
-
/**
|
|
2629
|
+
/** 接收端抗抖动缓冲区累计延迟(开播至今所有出 buffer 帧的延迟总和),单位 ms */
|
|
1247
2630
|
jitterBufferDelay?: number;
|
|
1248
|
-
/**
|
|
2631
|
+
/** 已从抖动缓冲区出列的帧/样本累计数;用于把累计 jitterBufferDelay 折算为均值 */
|
|
2632
|
+
jitterBufferEmittedCount?: number;
|
|
2633
|
+
/** 周期内(与上一次 stats 采样之间)平均每帧抖动缓冲延迟,单位 ms;体感延迟以此为准 */
|
|
2634
|
+
jitterBufferAvgDelay?: number;
|
|
2635
|
+
/** 累计丢包数(基于 RTP 序列号间隙统计) */
|
|
1249
2636
|
packetsLost?: number;
|
|
1250
|
-
/**
|
|
2637
|
+
/** 累计接收 RTP 包数 */
|
|
1251
2638
|
packetsReceived?: number;
|
|
1252
|
-
/**
|
|
2639
|
+
/** 累计接收字节数(含 RTP 头) */
|
|
1253
2640
|
bytesReceived?: number;
|
|
1254
|
-
/**
|
|
2641
|
+
/** 媒体流标识(通常对应远端 SSRC) */
|
|
1255
2642
|
streamId?: string;
|
|
1256
|
-
/**
|
|
2643
|
+
/** 网络层 RTP 抖动(RFC 3550 定义),单位 ms */
|
|
1257
2644
|
jitter?: number;
|
|
1258
|
-
/**
|
|
2645
|
+
/** 本组 stats 的采集时间戳,单位 ms */
|
|
1259
2646
|
timestamp: number;
|
|
1260
2647
|
}
|
|
2648
|
+
/**
|
|
2649
|
+
* 断线重连api返回
|
|
2650
|
+
*/
|
|
2651
|
+
export interface ReconnectRsp {
|
|
2652
|
+
/** mqtt信息 */
|
|
2653
|
+
mqtt: MqttServer;
|
|
2654
|
+
/** 流媒体直连信息 */
|
|
2655
|
+
upload: UploadServer;
|
|
2656
|
+
/** rtmp网关信息 */
|
|
2657
|
+
rtmp: RtmpServer;
|
|
2658
|
+
/** webrtc网关信息 */
|
|
2659
|
+
webrtc: WebrtcServer;
|
|
2660
|
+
}
|
|
2661
|
+
/**
|
|
2662
|
+
* 程博 RTMP 网关连接信息
|
|
2663
|
+
*/
|
|
2664
|
+
export interface RtmpServer {
|
|
2665
|
+
/** RTMP 服务名称 */
|
|
2666
|
+
name: string;
|
|
2667
|
+
/** RTMP 推流前缀 */
|
|
2668
|
+
push_url: string;
|
|
2669
|
+
/** RTMP 拉流前缀 */
|
|
2670
|
+
pull_url: string;
|
|
2671
|
+
/** 对应upload服务的相对rtmp网关连接地址 */
|
|
2672
|
+
upload_host: string;
|
|
2673
|
+
}
|
|
1261
2674
|
/**
|
|
1262
2675
|
* 屏幕采集音频配置
|
|
1263
2676
|
*/
|
|
@@ -1329,17 +2742,38 @@ export interface SenderStats {
|
|
|
1329
2742
|
packetsSent?: number;
|
|
1330
2743
|
/** 已发送的字节数 */
|
|
1331
2744
|
bytesSent?: number;
|
|
1332
|
-
/**
|
|
2745
|
+
/** 远端感知到的网络抖动,单位 ms */
|
|
1333
2746
|
jitter?: number;
|
|
1334
2747
|
/** 远端报告的丢包数 */
|
|
1335
2748
|
packetsLost?: number;
|
|
1336
|
-
/**
|
|
2749
|
+
/** 远端报告的往返时延,单位 ms */
|
|
1337
2750
|
roundTripTime?: number;
|
|
1338
2751
|
/** 出站流ID */
|
|
1339
2752
|
streamId?: string;
|
|
1340
2753
|
/** 时间戳 */
|
|
1341
2754
|
timestamp: number;
|
|
1342
2755
|
}
|
|
2756
|
+
/**
|
|
2757
|
+
* 流媒体引擎能力
|
|
2758
|
+
*/
|
|
2759
|
+
export interface StreamEngineAbility {
|
|
2760
|
+
/** 支持的音频编解码 */
|
|
2761
|
+
audioCodecs: Codec[];
|
|
2762
|
+
/** 支持的视频编解码 */
|
|
2763
|
+
videoCodecs: Codec[];
|
|
2764
|
+
/** 最大支持的音频轨道发布数 */
|
|
2765
|
+
audioMaxPub: number;
|
|
2766
|
+
/** 最大支持的视频轨道发布数 */
|
|
2767
|
+
videoMaxPub: number;
|
|
2768
|
+
/** 最大支持的音频轨道订阅数 */
|
|
2769
|
+
audioMaxSub: number;
|
|
2770
|
+
/** 最大支持的音频轨道订阅数 */
|
|
2771
|
+
videoMaxSub: number;
|
|
2772
|
+
/** 希望的优先音频编码类型 */
|
|
2773
|
+
preferAudioCodec?: Codec;
|
|
2774
|
+
/** 希望的优先视频编码类型 */
|
|
2775
|
+
preferVideoCodec?: Codec;
|
|
2776
|
+
}
|
|
1343
2777
|
/**
|
|
1344
2778
|
* 流媒体引擎周期性输出的 metric 快照
|
|
1345
2779
|
*/
|
|
@@ -1355,6 +2789,25 @@ export interface StreamMetric {
|
|
|
1355
2789
|
/** 订阅的远端视频轨道 */
|
|
1356
2790
|
remote_videos: TrackMetric[];
|
|
1357
2791
|
}
|
|
2792
|
+
/**
|
|
2793
|
+
* 轨道事件 type → data 类型映射。
|
|
2794
|
+
*
|
|
2795
|
+
* 和频道事件不同,轨道事件的 data 绝大多数就是 track 自身(`BaseTrack`)。
|
|
2796
|
+
* 子模块(webrtc / wx)可通过 interface merging 扩展。
|
|
2797
|
+
*/
|
|
2798
|
+
export interface TrackEventDataMap {
|
|
2799
|
+
[CommonTrackEventType.INFO_UPDATE]: BaseTrack;
|
|
2800
|
+
[CommonTrackEventType.MUTED]: BaseTrack;
|
|
2801
|
+
[CommonTrackEventType.UNMUTED]: BaseTrack;
|
|
2802
|
+
[CommonTrackEventType.ENDED]: BaseTrack;
|
|
2803
|
+
}
|
|
2804
|
+
export interface TrackEventDataMap {
|
|
2805
|
+
[TrackEventType.AUTOPLAY_FAIL]: BaseTrack;
|
|
2806
|
+
[TrackEventType.PIP_ENTER]: BaseTrack;
|
|
2807
|
+
[TrackEventType.PIP_EXIT]: BaseTrack;
|
|
2808
|
+
[TrackEventType.POPOUT_OPEN]: BaseTrack;
|
|
2809
|
+
[TrackEventType.POPOUT_CLOSE]: BaseTrack;
|
|
2810
|
+
}
|
|
1358
2811
|
/**
|
|
1359
2812
|
* 单条轨道的实时 metric 快照
|
|
1360
2813
|
* 由 BaseTrack.getInfo() 展开 + 运行时计算字段
|
|
@@ -1378,14 +2831,30 @@ export interface TrackMetric {
|
|
|
1378
2831
|
[key: string]: any;
|
|
1379
2832
|
}
|
|
1380
2833
|
/**
|
|
1381
|
-
*
|
|
2834
|
+
* 程博流媒体服务连接信息
|
|
1382
2835
|
*/
|
|
2836
|
+
export interface UploadServer {
|
|
2837
|
+
/** 流媒体服务名称 */
|
|
2838
|
+
name: string;
|
|
2839
|
+
/** 流媒体服务器地址 */
|
|
2840
|
+
address: string;
|
|
2841
|
+
/** 流媒体服务器端口 */
|
|
2842
|
+
port: string;
|
|
2843
|
+
}
|
|
2844
|
+
/** 用户离开事件data */
|
|
1383
2845
|
export interface UserLeaveEventData {
|
|
1384
2846
|
/** 用户id */
|
|
1385
2847
|
uid: string;
|
|
1386
2848
|
/** 离开原因 */
|
|
1387
2849
|
reason: DisconnectReason;
|
|
1388
2850
|
}
|
|
2851
|
+
/** USER_TRACK_ADD / USER_TRACK_UPDATE / USER_TRACK_REMOVE 事件 data */
|
|
2852
|
+
export interface UserTrackEventData {
|
|
2853
|
+
/** 所属用户 */
|
|
2854
|
+
user: BaseUserInfo;
|
|
2855
|
+
/** 变化的流轨道 */
|
|
2856
|
+
track: BaseTrackInfo;
|
|
2857
|
+
}
|
|
1389
2858
|
/**
|
|
1390
2859
|
* 视频发布配置
|
|
1391
2860
|
*/
|
|
@@ -1493,6 +2962,53 @@ export interface VideoSenderStats extends SenderStats {
|
|
|
1493
2962
|
/** 目标码率 */
|
|
1494
2963
|
targetBitrate: number;
|
|
1495
2964
|
}
|
|
2965
|
+
/**
|
|
2966
|
+
* 程博 WebRTC 网关连接信息
|
|
2967
|
+
*/
|
|
2968
|
+
export interface WebrtcServer {
|
|
2969
|
+
/** WebRTC 服务名称 */
|
|
2970
|
+
name: string;
|
|
2971
|
+
/** WebRTC 接口前缀 */
|
|
2972
|
+
cmd_url: string;
|
|
2973
|
+
/** 对应upload服务的相对webrtc网关连接地址 */
|
|
2974
|
+
upload_host: string;
|
|
2975
|
+
}
|
|
2976
|
+
/**
|
|
2977
|
+
* 频道事件通知(判别联合类型:`type` 决定 `data` 的精确形状)。
|
|
2978
|
+
*
|
|
2979
|
+
* 使用姿势:
|
|
2980
|
+
* ```
|
|
2981
|
+
* srtc.onNotifyChannelEvent = (evt) => {
|
|
2982
|
+
* switch (evt.type) {
|
|
2983
|
+
* case ChannelEventType.USER_JOIN:
|
|
2984
|
+
* // evt.data 自动收窄为 BaseUserInfo
|
|
2985
|
+
* break;
|
|
2986
|
+
* case ChannelEventType.DISCONNECTED:
|
|
2987
|
+
* // evt.data 自动收窄为 DisconnectEventData
|
|
2988
|
+
* break;
|
|
2989
|
+
* }
|
|
2990
|
+
* };
|
|
2991
|
+
* ```
|
|
2992
|
+
*/
|
|
2993
|
+
export type ChannelEvent = {
|
|
2994
|
+
[K in keyof ChannelEventDataMap]: {
|
|
2995
|
+
/** 事件类型 */
|
|
2996
|
+
readonly type: K;
|
|
2997
|
+
/** 事件携带的数据(类型由 type 决定) */
|
|
2998
|
+
readonly data: ChannelEventDataMap[K];
|
|
2999
|
+
};
|
|
3000
|
+
}[keyof ChannelEventDataMap];
|
|
3001
|
+
/** 从事件 type 反查对应 ChannelEvent 的具体形态 */
|
|
3002
|
+
export type ChannelEventOf<K extends keyof ChannelEventDataMap> = Extract<ChannelEvent, {
|
|
3003
|
+
type: K;
|
|
3004
|
+
}>;
|
|
3005
|
+
/** 频道外事件通知(判别联合) */
|
|
3006
|
+
export type ImEvent = {
|
|
3007
|
+
[K in keyof ImEventDataMap]: {
|
|
3008
|
+
readonly type: K;
|
|
3009
|
+
readonly data: ImEventDataMap[K];
|
|
3010
|
+
};
|
|
3011
|
+
}[keyof ImEventDataMap];
|
|
1496
3012
|
/**
|
|
1497
3013
|
* 重试执行器函数:直接调用开始执行,.cancel()取消重试,函数失败会返回maxretry或canceled
|
|
1498
3014
|
*/
|