@seastart/srtc-web-sdk 0.4.5 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/srtc.d.mts +1567 -78
- package/srtc.d.ts +1567 -78
- package/srtc.js +1 -1
- package/srtc.mjs +1 -1
package/srtc.d.mts
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
|
* 本地音频流轨道
|
|
@@ -521,6 +1326,21 @@ export declare class RemoteVideoTrack extends BaseWebrtcTrack {
|
|
|
521
1326
|
isPopOut(container: HTMLElement): boolean;
|
|
522
1327
|
}
|
|
523
1328
|
export declare class SRTC extends BaseSRTC {
|
|
1329
|
+
/** 窄化父类的 channel 类型到 webrtc Channel,便于访问 webrtc 特有方法 */
|
|
1330
|
+
protected channel?: Channel | null;
|
|
1331
|
+
/**
|
|
1332
|
+
* 获取流媒体引擎的metric快照(全量,含每条轨道的统计)
|
|
1333
|
+
*/
|
|
1334
|
+
getStreamMetric(): StreamMetric | undefined;
|
|
1335
|
+
/**
|
|
1336
|
+
* 获取当前网络总体统计,只关心网络全景时用,比 getStreamMetric 更轻量
|
|
1337
|
+
*/
|
|
1338
|
+
getNetworkStats(): NetworkStats | undefined;
|
|
1339
|
+
/**
|
|
1340
|
+
* 获取当前连接质量评估结果(等级 / MOS / 触发原因)
|
|
1341
|
+
* 配合 ChannelEventType.CONNECTION_QUALITY_CHANGED 事件使用
|
|
1342
|
+
*/
|
|
1343
|
+
getConnectionQuality(): QualityEvaluation | undefined;
|
|
524
1344
|
buildInfo(): BuildInfo;
|
|
525
1345
|
/**
|
|
526
1346
|
* 获取web运行环境信息,如是否支持webrtc等
|
|
@@ -721,9 +1541,7 @@ export declare enum DeviceType {
|
|
|
721
1541
|
*/
|
|
722
1542
|
XCX = 7
|
|
723
1543
|
}
|
|
724
|
-
/**
|
|
725
|
-
* 用户离开频道的原因
|
|
726
|
-
*/
|
|
1544
|
+
/** 用户离开频道的原因 */
|
|
727
1545
|
export declare enum DisconnectReason {
|
|
728
1546
|
/** 错误 */
|
|
729
1547
|
Error = -1,
|
|
@@ -738,9 +1556,7 @@ export declare enum DisconnectReason {
|
|
|
738
1556
|
/** 频道销毁离开 */
|
|
739
1557
|
Destroy = 5
|
|
740
1558
|
}
|
|
741
|
-
/**
|
|
742
|
-
* 用户断开im的原因
|
|
743
|
-
*/
|
|
1559
|
+
/** 用户断开im的原因 */
|
|
744
1560
|
export declare enum ImDisconnectReason {
|
|
745
1561
|
/** 错误 */
|
|
746
1562
|
Error = -1,
|
|
@@ -788,6 +1604,40 @@ export declare function codec2str(codec: Codec): string;
|
|
|
788
1604
|
* 创建混音后的音频轨
|
|
789
1605
|
*/
|
|
790
1606
|
export declare function createMixedAudioMediaStreamTrack(canvasContext?: CanvasRenderingContext2D): MixedAudioMediaStreamTrack;
|
|
1607
|
+
/**
|
|
1608
|
+
* MessageIdProvider
|
|
1609
|
+
*/
|
|
1610
|
+
export declare interface IMessageIdProvider {
|
|
1611
|
+
/**
|
|
1612
|
+
* Allocate the first vacant messageId. The messageId become occupied status.
|
|
1613
|
+
* @return {Number} - The first vacant messageId. If all messageIds are occupied, return null.
|
|
1614
|
+
*/
|
|
1615
|
+
allocate(): Number | null;
|
|
1616
|
+
/**
|
|
1617
|
+
* Get the last allocated messageId.
|
|
1618
|
+
* @return {Number} - messageId.
|
|
1619
|
+
*/
|
|
1620
|
+
getLastAllocated(): Number | null;
|
|
1621
|
+
/**
|
|
1622
|
+
* Register the messageId. The messageId become occupied status.
|
|
1623
|
+
* If the messageId has already been occupied, then return false.
|
|
1624
|
+
* @param {Number} num - The messageId to request use.
|
|
1625
|
+
* @return {Boolean} - If `num` was not occupied, then return true, otherwise return false.
|
|
1626
|
+
*/
|
|
1627
|
+
register(num: Number): Boolean;
|
|
1628
|
+
/**
|
|
1629
|
+
* Deallocate the messageId. The messageId become vacant status.
|
|
1630
|
+
* @param {Number} num - The messageId to deallocate. The messageId must be occupied status.
|
|
1631
|
+
* In other words, the messageId must be allocated by allocate() or
|
|
1632
|
+
* occupied by register().
|
|
1633
|
+
*/
|
|
1634
|
+
deallocate(num: Number): void;
|
|
1635
|
+
/**
|
|
1636
|
+
* Clear all occupied messageIds.
|
|
1637
|
+
* The all messageIds are set to vacant status.
|
|
1638
|
+
*/
|
|
1639
|
+
clear(): void;
|
|
1640
|
+
}
|
|
791
1641
|
export declare namespace __INNER__ {
|
|
792
1642
|
const BaseSRTC_I: typeof BaseSRTC;
|
|
793
1643
|
const CommonChannelEventType_I: typeof CommonChannelEventType;
|
|
@@ -805,6 +1655,80 @@ export declare namespace __INNER__ {
|
|
|
805
1655
|
const dct_I: typeof dct;
|
|
806
1656
|
function hmac_I(msg: string, key: string): string;
|
|
807
1657
|
}
|
|
1658
|
+
export declare type ClientSubscribeCallback = (err: Error, granted: ISubscriptionGrant[]) => void;
|
|
1659
|
+
export declare type CloseCallback = (error?: Error) => void;
|
|
1660
|
+
export declare type OnCloseCallback = () => void;
|
|
1661
|
+
export declare type OnConnectCallback = (packet: IConnackPacket) => void;
|
|
1662
|
+
export declare type OnDisconnectCallback = (packet: IDisconnectPacket) => void;
|
|
1663
|
+
export declare type OnErrorCallback = (error: Error) => void;
|
|
1664
|
+
export declare type OnMessageCallback = (topic: string, payload: Buffer, packet: IPublishPacket) => void;
|
|
1665
|
+
export declare type OnPacketCallback = (packet: Packet) => void;
|
|
1666
|
+
export declare type PacketCallback = (error?: Error, packet?: Packet) => any;
|
|
1667
|
+
export declare type StorePutCallback = () => void;
|
|
1668
|
+
/**
|
|
1669
|
+
* Active speaker(说话中的用户)相关类型 / 事件枚举。
|
|
1670
|
+
*
|
|
1671
|
+
* 对应 SFU `audio_level.go` 通过 signal DataChannel 下发的 `active-speakers` 协议。
|
|
1672
|
+
* SDK 在 SeaStartWebrtc 内把服务端的**增量**事件合并成**全量**快照再对外广播,
|
|
1673
|
+
* 业务侧拿到的 `ActiveSpeakersEventData.speakers` 始终是当前正在说话的全量列表,
|
|
1674
|
+
* 不需要自己维护增量状态——这与 livekit-client `RoomEvent.ActiveSpeakersChanged` 一致。
|
|
1675
|
+
*/
|
|
1676
|
+
/**
|
|
1677
|
+
* 单个说话中的用户信息。
|
|
1678
|
+
*/
|
|
1679
|
+
export interface ActiveSpeakerInfo {
|
|
1680
|
+
/** 用户 id(对齐频道内 uid) */
|
|
1681
|
+
uid: string;
|
|
1682
|
+
/**
|
|
1683
|
+
* 对应的 audio track id。
|
|
1684
|
+
* 同一个 uid 理论上可能同时发布多条 audio track(极少见,比如左右声道独立),
|
|
1685
|
+
* 通过 trackId 区分避免 UI 合并。
|
|
1686
|
+
*/
|
|
1687
|
+
trackId: string;
|
|
1688
|
+
/**
|
|
1689
|
+
* 当前音量,归一化线性值 0~1。
|
|
1690
|
+
* 1 对应 0 dBov 理论最大,0 对应静音。
|
|
1691
|
+
* 服务端已量化到 1/8 的档位(对齐 livekit),UI 直接映射音柱宽度即可;
|
|
1692
|
+
* 若想转 dB,用 `20 * Math.log10(level)`。
|
|
1693
|
+
*/
|
|
1694
|
+
level: number;
|
|
1695
|
+
}
|
|
1696
|
+
/**
|
|
1697
|
+
* ACTIVE_SPEAKERS_CHANGED 事件的 data。
|
|
1698
|
+
*
|
|
1699
|
+
* 语义:**每次都是当前房间正在说话的全量快照**(按 level 降序)。
|
|
1700
|
+
* - 有人开始说话:speakers 新增一项;
|
|
1701
|
+
* - 有人停止说话:speakers 相应条目消失;
|
|
1702
|
+
* - 无人说话:speakers 为 []。
|
|
1703
|
+
*
|
|
1704
|
+
* 业务侧典型用法:
|
|
1705
|
+
* channel.on(ChannelEventType.ACTIVE_SPEAKERS_CHANGED, (data) => {
|
|
1706
|
+
* renderAudioBars(data.speakers)
|
|
1707
|
+
* })
|
|
1708
|
+
*/
|
|
1709
|
+
export interface ActiveSpeakersEventData {
|
|
1710
|
+
/** 服务端下发时间戳(unix 毫秒),用于排序/诊断 */
|
|
1711
|
+
ts: number;
|
|
1712
|
+
/** 当前正在说话的用户列表,按 level 从大到小排序 */
|
|
1713
|
+
speakers: ActiveSpeakerInfo[];
|
|
1714
|
+
}
|
|
1715
|
+
/**
|
|
1716
|
+
* 远端视频自适应流配置。
|
|
1717
|
+
* 设计上对齐 LiveKit 的 adaptive stream,但先聚焦于当前 SDK 已具备的“主动切层”能力。
|
|
1718
|
+
*/
|
|
1719
|
+
export interface AdaptiveStreamOptions {
|
|
1720
|
+
/**
|
|
1721
|
+
* 像素密度倍率。
|
|
1722
|
+
* - `screen`:使用真实 `window.devicePixelRatio`
|
|
1723
|
+
* - 不传:高密屏默认取 2,其余取 1
|
|
1724
|
+
*/
|
|
1725
|
+
pixelDensity?: number | "screen";
|
|
1726
|
+
/**
|
|
1727
|
+
* 页面切到后台时,是否按“不可见”处理远端视频,默认 true。
|
|
1728
|
+
* 当前实现没有“暂停下行”协议,因此后台时会切到最低候选层,而不是直接停流。
|
|
1729
|
+
*/
|
|
1730
|
+
pauseVideoInBackground?: boolean;
|
|
1731
|
+
}
|
|
808
1732
|
/**
|
|
809
1733
|
* 扬声器配置
|
|
810
1734
|
*/
|
|
@@ -873,6 +1797,59 @@ export interface AudioSenderStats extends SenderStats {
|
|
|
873
1797
|
/** 音频电平 */
|
|
874
1798
|
audioLevel?: number;
|
|
875
1799
|
}
|
|
1800
|
+
/** 重连时刷新auth */
|
|
1801
|
+
export interface AuthReconnect {
|
|
1802
|
+
(url: string, options: IClientOptions, client: MqttClient): string;
|
|
1803
|
+
}
|
|
1804
|
+
/**
|
|
1805
|
+
* 频道基类
|
|
1806
|
+
*
|
|
1807
|
+
* 事件类型通过 `ChannelEventDataMap` 与 data 类型强关联,
|
|
1808
|
+
* 子类如 webrtc / wx 通过 `declare module '../base/event'` 合并扩展事件。
|
|
1809
|
+
* 下面这段 interface 声明不是另起炉灶,而是用 TS declaration merging 在 EventEmitter
|
|
1810
|
+
* 的 `on/once/off/addListener/removeListener/emit` 上加强类型化重载;保留父类宽松签名
|
|
1811
|
+
* 作为兜底,不影响内部既有 `this.rtcSocket.on(SocketEvent.XXX)` 等用法。
|
|
1812
|
+
*/
|
|
1813
|
+
export interface BaseChannel {
|
|
1814
|
+
on<K extends keyof ChannelEventDataMap>(type: K, listener: (event: ChannelEventOf<K>) => void): this;
|
|
1815
|
+
once<K extends keyof ChannelEventDataMap>(type: K, listener: (event: ChannelEventOf<K>) => void): this;
|
|
1816
|
+
off<K extends keyof ChannelEventDataMap>(type: K, listener: (event: ChannelEventOf<K>) => void): this;
|
|
1817
|
+
addListener<K extends keyof ChannelEventDataMap>(type: K, listener: (event: ChannelEventOf<K>) => void): this;
|
|
1818
|
+
removeListener<K extends keyof ChannelEventDataMap>(type: K, listener: (event: ChannelEventOf<K>) => void): this;
|
|
1819
|
+
emit<K extends keyof ChannelEventDataMap>(type: K, event: ChannelEventOf<K>): boolean;
|
|
1820
|
+
}
|
|
1821
|
+
/**
|
|
1822
|
+
* 流轨道
|
|
1823
|
+
*
|
|
1824
|
+
* 轨道事件(MUTED/UNMUTED/ENDED/INFO_UPDATE 等)的 data 类型通过 `TrackEventDataMap` 和
|
|
1825
|
+
* type 强关联;webrtc / wx 子模块通过 `declare module '../base/event'` 扩展。
|
|
1826
|
+
* 下面这段 interface 是 declaration merging,为 EventEmitter 的事件方法加类型化重载。
|
|
1827
|
+
*/
|
|
1828
|
+
export interface BaseTrack {
|
|
1829
|
+
on<K extends keyof TrackEventDataMap>(type: K, listener: (data: TrackEventDataMap[K]) => void): this;
|
|
1830
|
+
on(type: string | symbol, listener: (...args: any[]) => void): this;
|
|
1831
|
+
once<K extends keyof TrackEventDataMap>(type: K, listener: (data: TrackEventDataMap[K]) => void): this;
|
|
1832
|
+
once(type: string | symbol, listener: (...args: any[]) => void): this;
|
|
1833
|
+
off<K extends keyof TrackEventDataMap>(type: K, listener: (data: TrackEventDataMap[K]) => void): this;
|
|
1834
|
+
off(type: string | symbol, listener: (...args: any[]) => void): this;
|
|
1835
|
+
addListener<K extends keyof TrackEventDataMap>(type: K, listener: (data: TrackEventDataMap[K]) => void): this;
|
|
1836
|
+
addListener(type: string | symbol, listener: (...args: any[]) => void): this;
|
|
1837
|
+
removeListener<K extends keyof TrackEventDataMap>(type: K, listener: (data: TrackEventDataMap[K]) => void): this;
|
|
1838
|
+
removeListener(type: string | symbol, listener: (...args: any[]) => void): this;
|
|
1839
|
+
emit<K extends keyof TrackEventDataMap>(type: K, data: TrackEventDataMap[K]): boolean;
|
|
1840
|
+
emit(type: string | symbol, ...args: any[]): boolean;
|
|
1841
|
+
listeners<K extends keyof TrackEventDataMap>(type: K): ((data: TrackEventDataMap[K]) => void)[];
|
|
1842
|
+
listeners(type: string | symbol): Function[];
|
|
1843
|
+
}
|
|
1844
|
+
/**
|
|
1845
|
+
* track临时扩展,方便统一管理
|
|
1846
|
+
*/
|
|
1847
|
+
export interface BaseTrackEx {
|
|
1848
|
+
kind: TrackKind;
|
|
1849
|
+
track: BaseTrack;
|
|
1850
|
+
opt?: AudioPublishOptions | VideoPublishOptions;
|
|
1851
|
+
exopt: Record<string, any>;
|
|
1852
|
+
}
|
|
876
1853
|
/**
|
|
877
1854
|
* sdk编译信息
|
|
878
1855
|
*/
|
|
@@ -915,6 +1892,82 @@ export interface CameraPreset {
|
|
|
915
1892
|
capture: CameraCaptureOptions;
|
|
916
1893
|
publish: VideoPublishOptions;
|
|
917
1894
|
}
|
|
1895
|
+
export interface ChannelEventDataMap {
|
|
1896
|
+
[ChannelEventType.DEVICE_ADD]: MediaDeviceInfo;
|
|
1897
|
+
[ChannelEventType.DEVICE_REMOVE]: MediaDeviceInfo;
|
|
1898
|
+
[ChannelEventType.TRACK_AUTOPLAY_FAIL]: BaseTrack;
|
|
1899
|
+
[ChannelEventType.TRACK_PIP_ENTER]: BaseTrack;
|
|
1900
|
+
[ChannelEventType.TRACK_PIP_EXIT]: BaseTrack;
|
|
1901
|
+
[ChannelEventType.TRACK_POPOUT_OPEN]: BaseTrack;
|
|
1902
|
+
[ChannelEventType.TRACK_POPOUT_CLOSE]: BaseTrack;
|
|
1903
|
+
[ChannelEventType.CONNECTION_QUALITY_CHANGED]: ConnectionQualityEventData;
|
|
1904
|
+
[ChannelEventType.CPU_CONSTRAINED]: QualityEvaluation;
|
|
1905
|
+
[ChannelEventType.BANDWIDTH_CONSTRAINED]: QualityEvaluation;
|
|
1906
|
+
[ChannelEventType.ACTIVE_SPEAKERS_CHANGED]: ActiveSpeakersEventData;
|
|
1907
|
+
}
|
|
1908
|
+
/**
|
|
1909
|
+
* 频道事件 type → data 类型的**中央映射**。
|
|
1910
|
+
*
|
|
1911
|
+
* 为什么要这个?
|
|
1912
|
+
* 旧版 `ChannelEvent.data: any`,事件类型和 data 形状的对应关系只能靠注释维护,
|
|
1913
|
+
* 上层既无补全也无校验。把关系搬进 TS 类型系统后:
|
|
1914
|
+
* - `channel.on(type, listener)`:listener 的 `evt.data` 自动推断到精确类型;
|
|
1915
|
+
* - `switch(evt.type)` 判别联合:分支内 `evt.data` 自动收窄;
|
|
1916
|
+
* - 新增事件时**必须**在这里(或子模块合并里)补齐 data 类型,再也不能漏。
|
|
1917
|
+
*
|
|
1918
|
+
* 扩展方式(子模块 webrtc / wx):用 TS interface merging(`declare module`)往里加事件:
|
|
1919
|
+
* ```
|
|
1920
|
+
* declare module '../base/event' {
|
|
1921
|
+
* interface ChannelEventDataMap {
|
|
1922
|
+
* [ChannelEventType.DEVICE_ADD]: MediaDeviceInfo;
|
|
1923
|
+
* }
|
|
1924
|
+
* }
|
|
1925
|
+
* ```
|
|
1926
|
+
*/
|
|
1927
|
+
export interface ChannelEventDataMap {
|
|
1928
|
+
[CommonChannelEventType.CHANNEL_UPDATE]: BaseChannelInfo;
|
|
1929
|
+
[CommonChannelEventType.JOIN_SUCCEED]: BaseChannelInfo;
|
|
1930
|
+
[CommonChannelEventType.ME_UPDATE]: BaseUserInfo;
|
|
1931
|
+
[CommonChannelEventType.RECONNECTING]: undefined;
|
|
1932
|
+
[CommonChannelEventType.RECONNECTED]: undefined;
|
|
1933
|
+
[CommonChannelEventType.DISCONNECTED]: DisconnectEventData;
|
|
1934
|
+
[CommonChannelEventType.USER_JOIN]: BaseUserInfo;
|
|
1935
|
+
[CommonChannelEventType.USER_UPDATE]: BaseUserInfo;
|
|
1936
|
+
[CommonChannelEventType.USER_LEAVE]: UserLeaveEventData;
|
|
1937
|
+
[CommonChannelEventType.USER_TRACK_ADD]: UserTrackEventData;
|
|
1938
|
+
[CommonChannelEventType.USER_TRACK_UPDATE]: UserTrackEventData;
|
|
1939
|
+
[CommonChannelEventType.USER_TRACK_REMOVE]: UserTrackEventData;
|
|
1940
|
+
[CommonChannelEventType.CUSTOM_MSG]: CustomMsgData;
|
|
1941
|
+
[CommonChannelEventType.TRACK_MUTED]: BaseTrack;
|
|
1942
|
+
[CommonChannelEventType.TRACK_UNMUTED]: BaseTrack;
|
|
1943
|
+
[CommonChannelEventType.TRACK_ENDED]: BaseTrack;
|
|
1944
|
+
}
|
|
1945
|
+
/**
|
|
1946
|
+
* 加入频道api返回
|
|
1947
|
+
*/
|
|
1948
|
+
export interface ChannelJoinRsp extends ReconnectRsp {
|
|
1949
|
+
/** 应用ID */
|
|
1950
|
+
app_id: string;
|
|
1951
|
+
/** 用户ID */
|
|
1952
|
+
uid: string;
|
|
1953
|
+
/** 会话ID */
|
|
1954
|
+
sid: string;
|
|
1955
|
+
/** 频道名 */
|
|
1956
|
+
channel: string;
|
|
1957
|
+
/** 网络 */
|
|
1958
|
+
net: string;
|
|
1959
|
+
/** 流媒体服务方 */
|
|
1960
|
+
stream_vendor: string;
|
|
1961
|
+
/** 频道流媒体连接id */
|
|
1962
|
+
channel_link_id: string;
|
|
1963
|
+
/** 用户流媒体连接id */
|
|
1964
|
+
link_id: number;
|
|
1965
|
+
/** 用户流媒体授权key */
|
|
1966
|
+
session_key: string;
|
|
1967
|
+
device_type: DeviceType;
|
|
1968
|
+
device_id: string;
|
|
1969
|
+
version: string;
|
|
1970
|
+
}
|
|
918
1971
|
/**
|
|
919
1972
|
* 连接质量变化事件 data
|
|
920
1973
|
*/
|
|
@@ -941,9 +1994,7 @@ export interface CustomMsgData {
|
|
|
941
1994
|
/** 是否私发 */
|
|
942
1995
|
private: boolean;
|
|
943
1996
|
}
|
|
944
|
-
/**
|
|
945
|
-
* 强制离开事件data
|
|
946
|
-
*/
|
|
1997
|
+
/** 强制离开事件data */
|
|
947
1998
|
export interface DisconnectEventData {
|
|
948
1999
|
/** 离开原因 */
|
|
949
2000
|
reason: DisconnectReason;
|
|
@@ -1035,6 +2086,203 @@ export interface EnvWebInfo extends Bowser$1.Parser.ParsedResult {
|
|
|
1035
2086
|
*/
|
|
1036
2087
|
devicePixelRatio: number;
|
|
1037
2088
|
}
|
|
2089
|
+
export interface IClientOptions extends ISecureClientOptions {
|
|
2090
|
+
port?: number; // port is made into a number subsequently
|
|
2091
|
+
host?: string; // host does NOT include port
|
|
2092
|
+
hostname?: string;
|
|
2093
|
+
path?: string;
|
|
2094
|
+
protocol?: "wss" | "ws" | "mqtt" | "mqtts" | "tcp" | "ssl" | "wx" | "wxs";
|
|
2095
|
+
wsOptions?: ClientOptions | ClientRequestArgs;
|
|
2096
|
+
/**
|
|
2097
|
+
* 10 seconds, set to 0 to disable
|
|
2098
|
+
*/
|
|
2099
|
+
keepalive?: number;
|
|
2100
|
+
/**
|
|
2101
|
+
* 'mqttjs_' + Math.random().toString(16).substr(2, 8)
|
|
2102
|
+
*/
|
|
2103
|
+
clientId?: string;
|
|
2104
|
+
/**
|
|
2105
|
+
* 'MQTT'
|
|
2106
|
+
*/
|
|
2107
|
+
protocolId?: string;
|
|
2108
|
+
/**
|
|
2109
|
+
* 4
|
|
2110
|
+
*/
|
|
2111
|
+
protocolVersion?: number;
|
|
2112
|
+
/**
|
|
2113
|
+
* true, set to false to receive QoS 1 and 2 messages while offline
|
|
2114
|
+
*/
|
|
2115
|
+
clean?: boolean;
|
|
2116
|
+
/**
|
|
2117
|
+
* 1000 milliseconds, interval between two reconnections
|
|
2118
|
+
*/
|
|
2119
|
+
reconnectPeriod?: number;
|
|
2120
|
+
/**
|
|
2121
|
+
* 30 * 1000 milliseconds, time to wait before a CONNACK is received
|
|
2122
|
+
*/
|
|
2123
|
+
connectTimeout?: number;
|
|
2124
|
+
/**
|
|
2125
|
+
* the username required by your broker, if any
|
|
2126
|
+
*/
|
|
2127
|
+
username?: string;
|
|
2128
|
+
/**
|
|
2129
|
+
* the password required by your broker, if any
|
|
2130
|
+
*/
|
|
2131
|
+
password?: string;
|
|
2132
|
+
/**
|
|
2133
|
+
* a Store for the incoming packets
|
|
2134
|
+
*/
|
|
2135
|
+
incomingStore?: Store;
|
|
2136
|
+
/**
|
|
2137
|
+
* a Store for the outgoing packets
|
|
2138
|
+
*/
|
|
2139
|
+
outgoingStore?: Store;
|
|
2140
|
+
queueQoSZero?: boolean;
|
|
2141
|
+
reschedulePings?: boolean;
|
|
2142
|
+
servers?: Array<{
|
|
2143
|
+
host: string;
|
|
2144
|
+
port: number;
|
|
2145
|
+
protocol?: "wss" | "ws" | "mqtt" | "mqtts" | "tcp" | "ssl" | "wx" | "wxs";
|
|
2146
|
+
}>;
|
|
2147
|
+
/**
|
|
2148
|
+
* true, set to false to disable re-subscribe functionality
|
|
2149
|
+
*/
|
|
2150
|
+
resubscribe?: boolean;
|
|
2151
|
+
/**
|
|
2152
|
+
* a message that will sent by the broker automatically when the client disconnect badly.
|
|
2153
|
+
*/
|
|
2154
|
+
will?: {
|
|
2155
|
+
/**
|
|
2156
|
+
* the topic to publish
|
|
2157
|
+
*/
|
|
2158
|
+
topic: string;
|
|
2159
|
+
/**
|
|
2160
|
+
* the message to publish
|
|
2161
|
+
*/
|
|
2162
|
+
payload: Buffer | string;
|
|
2163
|
+
/**
|
|
2164
|
+
* the QoS
|
|
2165
|
+
*/
|
|
2166
|
+
qos: QoS;
|
|
2167
|
+
/**
|
|
2168
|
+
* the retain flag
|
|
2169
|
+
*/
|
|
2170
|
+
retain: boolean;
|
|
2171
|
+
/*
|
|
2172
|
+
* properies object of will
|
|
2173
|
+
* */
|
|
2174
|
+
properties?: {
|
|
2175
|
+
willDelayInterval?: number;
|
|
2176
|
+
payloadFormatIndicator?: boolean;
|
|
2177
|
+
messageExpiryInterval?: number;
|
|
2178
|
+
contentType?: string;
|
|
2179
|
+
responseTopic?: string;
|
|
2180
|
+
correlationData?: Buffer;
|
|
2181
|
+
userProperties?: UserProperties;
|
|
2182
|
+
};
|
|
2183
|
+
};
|
|
2184
|
+
transformWsUrl?: (url: string, options: IClientOptions, client: MqttClient) => string;
|
|
2185
|
+
properties?: {
|
|
2186
|
+
sessionExpiryInterval?: number;
|
|
2187
|
+
receiveMaximum?: number;
|
|
2188
|
+
maximumPacketSize?: number;
|
|
2189
|
+
topicAliasMaximum?: number;
|
|
2190
|
+
requestResponseInformation?: boolean;
|
|
2191
|
+
requestProblemInformation?: boolean;
|
|
2192
|
+
userProperties?: UserProperties;
|
|
2193
|
+
authenticationMethod?: string;
|
|
2194
|
+
authenticationData?: Buffer;
|
|
2195
|
+
};
|
|
2196
|
+
messageIdProvider?: IMessageIdProvider;
|
|
2197
|
+
}
|
|
2198
|
+
export interface IClientPublishOptions {
|
|
2199
|
+
/**
|
|
2200
|
+
* the QoS
|
|
2201
|
+
*/
|
|
2202
|
+
qos?: QoS;
|
|
2203
|
+
/**
|
|
2204
|
+
* the retain flag
|
|
2205
|
+
*/
|
|
2206
|
+
retain?: boolean;
|
|
2207
|
+
/**
|
|
2208
|
+
* whether or not mark a message as duplicate
|
|
2209
|
+
*/
|
|
2210
|
+
dup?: boolean;
|
|
2211
|
+
/*
|
|
2212
|
+
* MQTT 5.0 properties object
|
|
2213
|
+
*/
|
|
2214
|
+
properties?: {
|
|
2215
|
+
payloadFormatIndicator?: boolean;
|
|
2216
|
+
messageExpiryInterval?: number;
|
|
2217
|
+
topicAlias?: number;
|
|
2218
|
+
responseTopic?: string;
|
|
2219
|
+
correlationData?: Buffer;
|
|
2220
|
+
userProperties?: UserProperties;
|
|
2221
|
+
subscriptionIdentifier?: number;
|
|
2222
|
+
contentType?: string;
|
|
2223
|
+
};
|
|
2224
|
+
/**
|
|
2225
|
+
* callback called when message is put into `outgoingStore`
|
|
2226
|
+
*/
|
|
2227
|
+
cbStorePut?: StorePutCallback;
|
|
2228
|
+
}
|
|
2229
|
+
export interface IClientReconnectOptions {
|
|
2230
|
+
/**
|
|
2231
|
+
* a Store for the incoming packets
|
|
2232
|
+
*/
|
|
2233
|
+
incomingStore?: Store;
|
|
2234
|
+
/**
|
|
2235
|
+
* a Store for the outgoing packets
|
|
2236
|
+
*/
|
|
2237
|
+
outgoingStore?: Store;
|
|
2238
|
+
}
|
|
2239
|
+
export interface IClientSubscribeOptions {
|
|
2240
|
+
/**
|
|
2241
|
+
* the QoS
|
|
2242
|
+
*/
|
|
2243
|
+
qos: QoS;
|
|
2244
|
+
/*
|
|
2245
|
+
* no local flag
|
|
2246
|
+
* */
|
|
2247
|
+
nl?: boolean;
|
|
2248
|
+
/*
|
|
2249
|
+
* Retain As Published flag
|
|
2250
|
+
* */
|
|
2251
|
+
rap?: boolean;
|
|
2252
|
+
/*
|
|
2253
|
+
* Retain Handling option
|
|
2254
|
+
* */
|
|
2255
|
+
rh?: number;
|
|
2256
|
+
/*
|
|
2257
|
+
* MQTT 5.0 properies object of subscribe
|
|
2258
|
+
* */
|
|
2259
|
+
properties?: {
|
|
2260
|
+
subscriptionIdentifier?: number;
|
|
2261
|
+
userProperties?: UserProperties;
|
|
2262
|
+
};
|
|
2263
|
+
}
|
|
2264
|
+
/** 本地模拟远端混音流轨接口 */
|
|
2265
|
+
export interface IMockRemoteAudioMixTrack {
|
|
2266
|
+
readonly __type: "MockRemoteAudioMixTrack";
|
|
2267
|
+
/**
|
|
2268
|
+
* 检查是否要过滤某track
|
|
2269
|
+
* @param track
|
|
2270
|
+
* @returns
|
|
2271
|
+
*/
|
|
2272
|
+
checkFilter(track: BaseTrack): boolean;
|
|
2273
|
+
/**
|
|
2274
|
+
* 添加轨道
|
|
2275
|
+
*/
|
|
2276
|
+
addTrack(track: BaseTrack): void;
|
|
2277
|
+
/**
|
|
2278
|
+
* 移除轨道
|
|
2279
|
+
*/
|
|
2280
|
+
removeTrack(track: BaseTrack): void;
|
|
2281
|
+
/**
|
|
2282
|
+
* 停止混音
|
|
2283
|
+
*/
|
|
2284
|
+
stop(): void;
|
|
2285
|
+
}
|
|
1038
2286
|
/** 远端混音流轨接口 */
|
|
1039
2287
|
export interface IRemoteAudioMixTrack {
|
|
1040
2288
|
readonly __type: "RemoteAudioMixTrack";
|
|
@@ -1043,15 +2291,91 @@ export interface IRemoteAudioMixTrack {
|
|
|
1043
2291
|
*/
|
|
1044
2292
|
getFilterUids(): string[];
|
|
1045
2293
|
}
|
|
2294
|
+
export interface ISecureClientOptions {
|
|
2295
|
+
/**
|
|
2296
|
+
* optional private keys in PEM format
|
|
2297
|
+
*/
|
|
2298
|
+
key?: string | string[] | Buffer | Buffer[] | Object[];
|
|
2299
|
+
/**
|
|
2300
|
+
* optional cert chains in PEM format
|
|
2301
|
+
*/
|
|
2302
|
+
cert?: string | string[] | Buffer | Buffer[];
|
|
2303
|
+
/**
|
|
2304
|
+
* Optionally override the trusted CA certificates in PEM format
|
|
2305
|
+
*/
|
|
2306
|
+
ca?: string | string[] | Buffer | Buffer[];
|
|
2307
|
+
rejectUnauthorized?: boolean;
|
|
2308
|
+
/**
|
|
2309
|
+
* optional alpn's
|
|
2310
|
+
*/
|
|
2311
|
+
ALPNProtocols?: string[] | Buffer[] | Uint8Array[] | Buffer | Uint8Array;
|
|
2312
|
+
}
|
|
2313
|
+
export interface IStoreOptions {
|
|
2314
|
+
/**
|
|
2315
|
+
* true, clear _inflights at close
|
|
2316
|
+
*/
|
|
2317
|
+
clean?: boolean;
|
|
2318
|
+
}
|
|
2319
|
+
export interface IStream extends EventEmitter {
|
|
2320
|
+
pipe(to: any): any;
|
|
2321
|
+
destroy(): any;
|
|
2322
|
+
end(): any;
|
|
2323
|
+
}
|
|
2324
|
+
export interface ISubscriptionGrant {
|
|
2325
|
+
/**
|
|
2326
|
+
* is a subscribed to topic
|
|
2327
|
+
*/
|
|
2328
|
+
topic: string;
|
|
2329
|
+
/**
|
|
2330
|
+
* is the granted qos level on it, may return 128 on error
|
|
2331
|
+
*/
|
|
2332
|
+
qos: QoS | number;
|
|
2333
|
+
/*
|
|
2334
|
+
* no local flag
|
|
2335
|
+
* */
|
|
2336
|
+
nl?: boolean;
|
|
2337
|
+
/*
|
|
2338
|
+
* Retain As Published flag
|
|
2339
|
+
* */
|
|
2340
|
+
rap?: boolean;
|
|
2341
|
+
/*
|
|
2342
|
+
* Retain Handling option
|
|
2343
|
+
* */
|
|
2344
|
+
rh?: number;
|
|
2345
|
+
}
|
|
2346
|
+
export interface ISubscriptionMap {
|
|
2347
|
+
/**
|
|
2348
|
+
* object which has topic names as object keys and as value the options, like {'test1': {qos: 0}, 'test2': {qos: 2}}.
|
|
2349
|
+
*/
|
|
2350
|
+
[topic: string]: {
|
|
2351
|
+
qos: QoS;
|
|
2352
|
+
nl?: boolean;
|
|
2353
|
+
rap?: boolean;
|
|
2354
|
+
rh?: number;
|
|
2355
|
+
};
|
|
2356
|
+
}
|
|
1046
2357
|
/**
|
|
1047
|
-
* im
|
|
2358
|
+
* im频道外消息连接/重连api返回
|
|
1048
2359
|
*/
|
|
2360
|
+
export interface ImConnectRsp {
|
|
2361
|
+
/** mqtt信息 */
|
|
2362
|
+
mqtt: MqttServer;
|
|
2363
|
+
}
|
|
2364
|
+
/** im强制断开事件data */
|
|
1049
2365
|
export interface ImDisconnectEventData {
|
|
1050
2366
|
/** 断开原因 */
|
|
1051
2367
|
reason: ImDisconnectReason;
|
|
1052
2368
|
/** 错误 */
|
|
1053
2369
|
error?: any;
|
|
1054
2370
|
}
|
|
2371
|
+
/** im 事件 type → data 类型映射。扩展方式同 `ChannelEventDataMap` */
|
|
2372
|
+
export interface ImEventDataMap {
|
|
2373
|
+
[CommonImEventType.ENABLE_SUCCEED]: undefined;
|
|
2374
|
+
[CommonImEventType.RECONNECTING]: undefined;
|
|
2375
|
+
[CommonImEventType.RECONNECTED]: undefined;
|
|
2376
|
+
[CommonImEventType.DISCONNECTED]: ImDisconnectEventData;
|
|
2377
|
+
[CommonImEventType.IM_MSG]: ImMsgData;
|
|
2378
|
+
}
|
|
1055
2379
|
/**
|
|
1056
2380
|
* im频道外消息
|
|
1057
2381
|
*/
|
|
@@ -1087,6 +2411,17 @@ export interface JoinOptions {
|
|
|
1087
2411
|
* 希望的优先音频编码类型
|
|
1088
2412
|
*/
|
|
1089
2413
|
preferAudioCodec?: Codec;
|
|
2414
|
+
/**
|
|
2415
|
+
* 是否启用远端视频自适应流。
|
|
2416
|
+
* 启用后,SDK 会根据 video 容器的显示/隐藏、尺寸变化,以及页面前后台状态,
|
|
2417
|
+
* 自动为远端视频选择更合适的 simulcast 层。
|
|
2418
|
+
*
|
|
2419
|
+
* 说明:
|
|
2420
|
+
* - 当前仅 WebRTC Seastart SFU 生效
|
|
2421
|
+
* - `true` 表示使用默认策略
|
|
2422
|
+
* - 传对象可进一步调整像素密度和后台页面策略
|
|
2423
|
+
*/
|
|
2424
|
+
adaptiveStream?: boolean | AdaptiveStreamOptions;
|
|
1090
2425
|
}
|
|
1091
2426
|
/**
|
|
1092
2427
|
* 麦克风采集配置
|
|
@@ -1141,6 +2476,29 @@ export interface MixedAudioMediaStreamTrack extends MediaStreamTrack {
|
|
|
1141
2476
|
removeTrack(track: MediaStreamTrack): void;
|
|
1142
2477
|
trackCount: number;
|
|
1143
2478
|
}
|
|
2479
|
+
/**
|
|
2480
|
+
* MQTT 服务器配置
|
|
2481
|
+
*/
|
|
2482
|
+
export interface MqttServer {
|
|
2483
|
+
/** MQTT 服务名称 */
|
|
2484
|
+
name: string;
|
|
2485
|
+
/** mqtt 客户端连接通过 jwt 验证授权,username 用 uid,clientid 用 sid */
|
|
2486
|
+
/** https://www.emqx.io/docs/zh/latest/access-control/authn/jwt.html */
|
|
2487
|
+
/** jwt 里加上权限控制,仅允许订阅特定 topic(不允许发送) */
|
|
2488
|
+
jwt_token: string;
|
|
2489
|
+
/** jwt token过期时间 */
|
|
2490
|
+
token_exp_at: number;
|
|
2491
|
+
/** tcp 连接地址 */
|
|
2492
|
+
tcp: string;
|
|
2493
|
+
/** ws 连接地址 */
|
|
2494
|
+
ws: string;
|
|
2495
|
+
/** 连接用的client id */
|
|
2496
|
+
client_id: string;
|
|
2497
|
+
/** 连接用的username */
|
|
2498
|
+
username: string;
|
|
2499
|
+
/** 监听的 topics */
|
|
2500
|
+
topics: string[];
|
|
2501
|
+
}
|
|
1144
2502
|
/**
|
|
1145
2503
|
* 网络总体统计
|
|
1146
2504
|
*/
|
|
@@ -1165,8 +2523,10 @@ export interface NetworkStats {
|
|
|
1165
2523
|
available_outgoing_bitrate?: number;
|
|
1166
2524
|
/** SFU/BWE 估算的可用下行带宽 kb/s,来自 candidate-pair */
|
|
1167
2525
|
available_incoming_bitrate?: number;
|
|
1168
|
-
/**
|
|
1169
|
-
|
|
2526
|
+
/** 发布连接观测到的 RTT,单位 ms */
|
|
2527
|
+
rtt_up?: number;
|
|
2528
|
+
/** 订阅连接观测到的 RTT,单位 ms */
|
|
2529
|
+
rtt_down?: number;
|
|
1170
2530
|
}
|
|
1171
2531
|
/** 画中画句柄,用于控制画中画状态 */
|
|
1172
2532
|
export interface PipHandle {
|
|
@@ -1232,7 +2592,7 @@ export interface QualityEvaluation {
|
|
|
1232
2592
|
downlink: ConnectionQuality;
|
|
1233
2593
|
/** 总体质量,取上下行中较差的一档 */
|
|
1234
2594
|
overall: ConnectionQuality;
|
|
1235
|
-
/**
|
|
2595
|
+
/** 音视频 MOS 估算,范围 1.0 ~ 4.5 */
|
|
1236
2596
|
mos: number;
|
|
1237
2597
|
/** 触发当前等级的主要原因描述,便于排查 */
|
|
1238
2598
|
reasons: string[];
|
|
@@ -1243,21 +2603,47 @@ export interface QualityEvaluation {
|
|
|
1243
2603
|
* 接收数据统计
|
|
1244
2604
|
*/
|
|
1245
2605
|
export interface ReceiverStats {
|
|
1246
|
-
/**
|
|
2606
|
+
/** 接收端抗抖动缓冲区延迟,单位 ms */
|
|
1247
2607
|
jitterBufferDelay?: number;
|
|
1248
|
-
/**
|
|
2608
|
+
/** 累计丢包数(基于 RTP 序列号间隙统计) */
|
|
1249
2609
|
packetsLost?: number;
|
|
1250
|
-
/**
|
|
2610
|
+
/** 累计接收 RTP 包数 */
|
|
1251
2611
|
packetsReceived?: number;
|
|
1252
|
-
/**
|
|
2612
|
+
/** 累计接收字节数(含 RTP 头) */
|
|
1253
2613
|
bytesReceived?: number;
|
|
1254
|
-
/**
|
|
2614
|
+
/** 媒体流标识(通常对应远端 SSRC) */
|
|
1255
2615
|
streamId?: string;
|
|
1256
|
-
/**
|
|
2616
|
+
/** 网络层 RTP 抖动(RFC 3550 定义),单位 ms */
|
|
1257
2617
|
jitter?: number;
|
|
1258
|
-
/**
|
|
2618
|
+
/** 本组 stats 的采集时间戳,单位 ms */
|
|
1259
2619
|
timestamp: number;
|
|
1260
2620
|
}
|
|
2621
|
+
/**
|
|
2622
|
+
* 断线重连api返回
|
|
2623
|
+
*/
|
|
2624
|
+
export interface ReconnectRsp {
|
|
2625
|
+
/** mqtt信息 */
|
|
2626
|
+
mqtt: MqttServer;
|
|
2627
|
+
/** 流媒体直连信息 */
|
|
2628
|
+
upload: UploadServer;
|
|
2629
|
+
/** rtmp网关信息 */
|
|
2630
|
+
rtmp: RtmpServer;
|
|
2631
|
+
/** webrtc网关信息 */
|
|
2632
|
+
webrtc: WebrtcServer;
|
|
2633
|
+
}
|
|
2634
|
+
/**
|
|
2635
|
+
* 程博 RTMP 网关连接信息
|
|
2636
|
+
*/
|
|
2637
|
+
export interface RtmpServer {
|
|
2638
|
+
/** RTMP 服务名称 */
|
|
2639
|
+
name: string;
|
|
2640
|
+
/** RTMP 推流前缀 */
|
|
2641
|
+
push_url: string;
|
|
2642
|
+
/** RTMP 拉流前缀 */
|
|
2643
|
+
pull_url: string;
|
|
2644
|
+
/** 对应upload服务的相对rtmp网关连接地址 */
|
|
2645
|
+
upload_host: string;
|
|
2646
|
+
}
|
|
1261
2647
|
/**
|
|
1262
2648
|
* 屏幕采集音频配置
|
|
1263
2649
|
*/
|
|
@@ -1329,17 +2715,38 @@ export interface SenderStats {
|
|
|
1329
2715
|
packetsSent?: number;
|
|
1330
2716
|
/** 已发送的字节数 */
|
|
1331
2717
|
bytesSent?: number;
|
|
1332
|
-
/**
|
|
2718
|
+
/** 远端感知到的网络抖动,单位 ms */
|
|
1333
2719
|
jitter?: number;
|
|
1334
2720
|
/** 远端报告的丢包数 */
|
|
1335
2721
|
packetsLost?: number;
|
|
1336
|
-
/**
|
|
2722
|
+
/** 远端报告的往返时延,单位 ms */
|
|
1337
2723
|
roundTripTime?: number;
|
|
1338
2724
|
/** 出站流ID */
|
|
1339
2725
|
streamId?: string;
|
|
1340
2726
|
/** 时间戳 */
|
|
1341
2727
|
timestamp: number;
|
|
1342
2728
|
}
|
|
2729
|
+
/**
|
|
2730
|
+
* 流媒体引擎能力
|
|
2731
|
+
*/
|
|
2732
|
+
export interface StreamEngineAbility {
|
|
2733
|
+
/** 支持的音频编解码 */
|
|
2734
|
+
audioCodecs: Codec[];
|
|
2735
|
+
/** 支持的视频编解码 */
|
|
2736
|
+
videoCodecs: Codec[];
|
|
2737
|
+
/** 最大支持的音频轨道发布数 */
|
|
2738
|
+
audioMaxPub: number;
|
|
2739
|
+
/** 最大支持的视频轨道发布数 */
|
|
2740
|
+
videoMaxPub: number;
|
|
2741
|
+
/** 最大支持的音频轨道订阅数 */
|
|
2742
|
+
audioMaxSub: number;
|
|
2743
|
+
/** 最大支持的音频轨道订阅数 */
|
|
2744
|
+
videoMaxSub: number;
|
|
2745
|
+
/** 希望的优先音频编码类型 */
|
|
2746
|
+
preferAudioCodec?: Codec;
|
|
2747
|
+
/** 希望的优先视频编码类型 */
|
|
2748
|
+
preferVideoCodec?: Codec;
|
|
2749
|
+
}
|
|
1343
2750
|
/**
|
|
1344
2751
|
* 流媒体引擎周期性输出的 metric 快照
|
|
1345
2752
|
*/
|
|
@@ -1355,6 +2762,25 @@ export interface StreamMetric {
|
|
|
1355
2762
|
/** 订阅的远端视频轨道 */
|
|
1356
2763
|
remote_videos: TrackMetric[];
|
|
1357
2764
|
}
|
|
2765
|
+
/**
|
|
2766
|
+
* 轨道事件 type → data 类型映射。
|
|
2767
|
+
*
|
|
2768
|
+
* 和频道事件不同,轨道事件的 data 绝大多数就是 track 自身(`BaseTrack`)。
|
|
2769
|
+
* 子模块(webrtc / wx)可通过 interface merging 扩展。
|
|
2770
|
+
*/
|
|
2771
|
+
export interface TrackEventDataMap {
|
|
2772
|
+
[CommonTrackEventType.INFO_UPDATE]: BaseTrack;
|
|
2773
|
+
[CommonTrackEventType.MUTED]: BaseTrack;
|
|
2774
|
+
[CommonTrackEventType.UNMUTED]: BaseTrack;
|
|
2775
|
+
[CommonTrackEventType.ENDED]: BaseTrack;
|
|
2776
|
+
}
|
|
2777
|
+
export interface TrackEventDataMap {
|
|
2778
|
+
[TrackEventType.AUTOPLAY_FAIL]: BaseTrack;
|
|
2779
|
+
[TrackEventType.PIP_ENTER]: BaseTrack;
|
|
2780
|
+
[TrackEventType.PIP_EXIT]: BaseTrack;
|
|
2781
|
+
[TrackEventType.POPOUT_OPEN]: BaseTrack;
|
|
2782
|
+
[TrackEventType.POPOUT_CLOSE]: BaseTrack;
|
|
2783
|
+
}
|
|
1358
2784
|
/**
|
|
1359
2785
|
* 单条轨道的实时 metric 快照
|
|
1360
2786
|
* 由 BaseTrack.getInfo() 展开 + 运行时计算字段
|
|
@@ -1378,14 +2804,30 @@ export interface TrackMetric {
|
|
|
1378
2804
|
[key: string]: any;
|
|
1379
2805
|
}
|
|
1380
2806
|
/**
|
|
1381
|
-
*
|
|
2807
|
+
* 程博流媒体服务连接信息
|
|
1382
2808
|
*/
|
|
2809
|
+
export interface UploadServer {
|
|
2810
|
+
/** 流媒体服务名称 */
|
|
2811
|
+
name: string;
|
|
2812
|
+
/** 流媒体服务器地址 */
|
|
2813
|
+
address: string;
|
|
2814
|
+
/** 流媒体服务器端口 */
|
|
2815
|
+
port: string;
|
|
2816
|
+
}
|
|
2817
|
+
/** 用户离开事件data */
|
|
1383
2818
|
export interface UserLeaveEventData {
|
|
1384
2819
|
/** 用户id */
|
|
1385
2820
|
uid: string;
|
|
1386
2821
|
/** 离开原因 */
|
|
1387
2822
|
reason: DisconnectReason;
|
|
1388
2823
|
}
|
|
2824
|
+
/** USER_TRACK_ADD / USER_TRACK_UPDATE / USER_TRACK_REMOVE 事件 data */
|
|
2825
|
+
export interface UserTrackEventData {
|
|
2826
|
+
/** 所属用户 */
|
|
2827
|
+
user: BaseUserInfo;
|
|
2828
|
+
/** 变化的流轨道 */
|
|
2829
|
+
track: BaseTrackInfo;
|
|
2830
|
+
}
|
|
1389
2831
|
/**
|
|
1390
2832
|
* 视频发布配置
|
|
1391
2833
|
*/
|
|
@@ -1493,6 +2935,53 @@ export interface VideoSenderStats extends SenderStats {
|
|
|
1493
2935
|
/** 目标码率 */
|
|
1494
2936
|
targetBitrate: number;
|
|
1495
2937
|
}
|
|
2938
|
+
/**
|
|
2939
|
+
* 程博 WebRTC 网关连接信息
|
|
2940
|
+
*/
|
|
2941
|
+
export interface WebrtcServer {
|
|
2942
|
+
/** WebRTC 服务名称 */
|
|
2943
|
+
name: string;
|
|
2944
|
+
/** WebRTC 接口前缀 */
|
|
2945
|
+
cmd_url: string;
|
|
2946
|
+
/** 对应upload服务的相对webrtc网关连接地址 */
|
|
2947
|
+
upload_host: string;
|
|
2948
|
+
}
|
|
2949
|
+
/**
|
|
2950
|
+
* 频道事件通知(判别联合类型:`type` 决定 `data` 的精确形状)。
|
|
2951
|
+
*
|
|
2952
|
+
* 使用姿势:
|
|
2953
|
+
* ```
|
|
2954
|
+
* srtc.onNotifyChannelEvent = (evt) => {
|
|
2955
|
+
* switch (evt.type) {
|
|
2956
|
+
* case ChannelEventType.USER_JOIN:
|
|
2957
|
+
* // evt.data 自动收窄为 BaseUserInfo
|
|
2958
|
+
* break;
|
|
2959
|
+
* case ChannelEventType.DISCONNECTED:
|
|
2960
|
+
* // evt.data 自动收窄为 DisconnectEventData
|
|
2961
|
+
* break;
|
|
2962
|
+
* }
|
|
2963
|
+
* };
|
|
2964
|
+
* ```
|
|
2965
|
+
*/
|
|
2966
|
+
export type ChannelEvent = {
|
|
2967
|
+
[K in keyof ChannelEventDataMap]: {
|
|
2968
|
+
/** 事件类型 */
|
|
2969
|
+
readonly type: K;
|
|
2970
|
+
/** 事件携带的数据(类型由 type 决定) */
|
|
2971
|
+
readonly data: ChannelEventDataMap[K];
|
|
2972
|
+
};
|
|
2973
|
+
}[keyof ChannelEventDataMap];
|
|
2974
|
+
/** 从事件 type 反查对应 ChannelEvent 的具体形态 */
|
|
2975
|
+
export type ChannelEventOf<K extends keyof ChannelEventDataMap> = Extract<ChannelEvent, {
|
|
2976
|
+
type: K;
|
|
2977
|
+
}>;
|
|
2978
|
+
/** 频道外事件通知(判别联合) */
|
|
2979
|
+
export type ImEvent = {
|
|
2980
|
+
[K in keyof ImEventDataMap]: {
|
|
2981
|
+
readonly type: K;
|
|
2982
|
+
readonly data: ImEventDataMap[K];
|
|
2983
|
+
};
|
|
2984
|
+
}[keyof ImEventDataMap];
|
|
1496
2985
|
/**
|
|
1497
2986
|
* 重试执行器函数:直接调用开始执行,.cancel()取消重试,函数失败会返回maxretry或canceled
|
|
1498
2987
|
*/
|