@rongcloud/plugin-rtc 5.2.4 → 5.2.5
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/dist/async-task-queue.d.ts +15 -0
- package/dist/core/PolarisReporter.d.ts +35 -0
- package/dist/core/RCAudienceClient.d.ts +72 -0
- package/dist/core/RCRTCClient.d.ts +208 -0
- package/dist/core/constants.d.ts +2 -0
- package/dist/core/enums/BackgroundPictureFillMode.d.ts +14 -0
- package/dist/core/enums/MixLayoutMode.d.ts +18 -0
- package/dist/core/enums/MixVideoRenderMode.d.ts +14 -0
- package/dist/core/enums/RCFrameRate.d.ts +7 -0
- package/dist/core/enums/RCInnerCDNBroadcast.d.ts +5 -0
- package/dist/core/enums/RCInnerCDNModel.d.ts +5 -0
- package/dist/core/enums/RCInnerCDNPullIsHttps.d.ts +5 -0
- package/dist/core/enums/RCInnerCDNPullKind.d.ts +6 -0
- package/dist/core/enums/RCInnerCDNPushMode.d.ts +5 -0
- package/dist/core/enums/RCKickType.d.ts +11 -0
- package/dist/core/enums/RCLivingType.d.ts +14 -0
- package/dist/core/enums/RCMediaType.d.ts +18 -0
- package/dist/core/enums/RCRTCCode.d.ts +89 -0
- package/dist/core/enums/RCRTCLiveRole.d.ts +14 -0
- package/dist/core/enums/RCRTCPingResult.d.ts +5 -0
- package/dist/core/enums/RCRTCResolution.d.ts +100 -0
- package/dist/core/enums/RCResolution.d.ts +16 -0
- package/dist/core/enums/inner/PolarisRole.d.ts +14 -0
- package/dist/core/enums/inner/R2Action.d.ts +14 -0
- package/dist/core/enums/inner/R2Status.d.ts +11 -0
- package/dist/core/enums/inner/RCRTCMessageType.d.ts +42 -0
- package/dist/core/enums/inner/RCStreamType.d.ts +14 -0
- package/dist/core/enums/inner/TrackState.d.ts +14 -0
- package/dist/core/interfaces.d.ts +673 -0
- package/dist/core/room/Pinger.d.ts +32 -0
- package/dist/core/room/RCAbstractRoom.d.ts +351 -0
- package/dist/core/room/RCAudienceLivingRoom.d.ts +305 -0
- package/dist/core/room/RCAudioLevelReport.d.ts +17 -0
- package/dist/core/room/RCLivingRoom.d.ts +93 -0
- package/dist/core/room/RCLocalMediaStream.d.ts +8 -0
- package/dist/core/room/RCMCUConfigBuilder.d.ts +163 -0
- package/dist/core/room/RCRTCRoom.d.ts +11 -0
- package/dist/core/service/RCMediaService.d.ts +96 -0
- package/dist/core/service/helper.d.ts +8 -0
- package/dist/core/service/index.d.ts +6 -0
- package/dist/core/service/interface.d.ts +311 -0
- package/dist/core/service/mcu-interface.d.ts +263 -0
- package/dist/core/tracks/RCLocalTrack.d.ts +108 -0
- package/dist/core/tracks/RCRemoteTrack.d.ts +23 -0
- package/dist/core/tracks/RCTrack.d.ts +80 -0
- package/dist/core/webrtc/ASdpStrategy.d.ts +43 -0
- package/dist/core/webrtc/PlanBStrategy.d.ts +25 -0
- package/dist/core/webrtc/RCRTCPeerConnection.d.ts +80 -0
- package/dist/core/webrtc/UnifiedPlanStrategy.d.ts +20 -0
- package/dist/core/webrtc/helper.d.ts +26 -0
- package/dist/core/webrtc/stat-parser/AbstractStatParser.d.ts +116 -0
- package/dist/core/webrtc/stat-parser/ChromeStatParser.d.ts +14 -0
- package/dist/core/webrtc/stat-parser/FirefoxStatParser.d.ts +14 -0
- package/dist/core/webrtc/stat-parser/IStatParser.d.ts +24 -0
- package/dist/core/webrtc/stat-parser/SafariStatParser.d.ts +14 -0
- package/dist/device.d.ts +6 -0
- package/dist/helper.d.ts +168 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/logger.d.ts +4 -0
- package/package.json +2 -2
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { IJoinRTCRoomData, IReceivedMessage, RTCMode, RTCPluginContext, KVString, IRuntime } from '@rongcloud/engine';
|
|
2
|
+
import { IPublishedResource, IPublishAttrs, IRCRTCReportListener, IRoomEventListener, ISubscribeAttr, IRCRTCInitOptions, IAudioLevelChangeHandler, RoomData } from '../interfaces';
|
|
3
|
+
import { IExchangeReqBody, IRTCReqHeader, RCMediaService } from '../service';
|
|
4
|
+
import RCRTCPeerConnection from '../webrtc/RCRTCPeerConnection';
|
|
5
|
+
import PolarisReporter from '../PolarisReporter';
|
|
6
|
+
import { RCLocalTrack } from '../tracks/RCLocalTrack';
|
|
7
|
+
import { RCRemoteTrack } from '../tracks/RCRemoteTrack';
|
|
8
|
+
import { RCRTCCode } from '../enums/RCRTCCode';
|
|
9
|
+
import { RCLivingType } from '../enums/RCLivingType';
|
|
10
|
+
/**
|
|
11
|
+
* 房间抽象基类
|
|
12
|
+
*/
|
|
13
|
+
export default abstract class RCAbstractRoom {
|
|
14
|
+
protected readonly _context: RTCPluginContext;
|
|
15
|
+
private readonly _runtime;
|
|
16
|
+
readonly _roomId: string;
|
|
17
|
+
protected readonly _roomMode: RTCMode;
|
|
18
|
+
protected readonly _service: RCMediaService;
|
|
19
|
+
protected readonly _initOptions: IRCRTCInitOptions;
|
|
20
|
+
private readonly _ntfClearRoomItem;
|
|
21
|
+
/**
|
|
22
|
+
* 房间资源数据
|
|
23
|
+
*/
|
|
24
|
+
protected readonly _roomResources: RoomData;
|
|
25
|
+
/**
|
|
26
|
+
* 远端 track
|
|
27
|
+
*/
|
|
28
|
+
private _remoteTracks;
|
|
29
|
+
/**
|
|
30
|
+
* 已订阅参数
|
|
31
|
+
*/
|
|
32
|
+
private readonly _subscribedList;
|
|
33
|
+
/**
|
|
34
|
+
* 房间保活 rtcPing
|
|
35
|
+
*/
|
|
36
|
+
private readonly _pinger;
|
|
37
|
+
/**
|
|
38
|
+
* 与 MediaServer 交互需要的 token 信息
|
|
39
|
+
*/
|
|
40
|
+
protected readonly _token: string;
|
|
41
|
+
/**
|
|
42
|
+
* 每次加入房间后都会改变
|
|
43
|
+
*/
|
|
44
|
+
private readonly _sessionId;
|
|
45
|
+
/**
|
|
46
|
+
* PeerConnection 连接实例
|
|
47
|
+
*/
|
|
48
|
+
private readonly _pc;
|
|
49
|
+
private _destroyed;
|
|
50
|
+
/**
|
|
51
|
+
* 北极星上报实例
|
|
52
|
+
*/
|
|
53
|
+
protected _polarisReport: PolarisReporter | null;
|
|
54
|
+
/**
|
|
55
|
+
* 音量上报实例
|
|
56
|
+
*/
|
|
57
|
+
private _audioLevelReport;
|
|
58
|
+
constructor(_context: RTCPluginContext, _runtime: IRuntime, _roomId: string, data: IJoinRTCRoomData, _roomMode: RTCMode, _service: RCMediaService, _initOptions: IRCRTCInitOptions, _ntfClearRoomItem: Function, isUpgrade?: boolean);
|
|
59
|
+
private _initRemoteTracks;
|
|
60
|
+
private _handlePingResult;
|
|
61
|
+
/**
|
|
62
|
+
* 设置房间上行资源的总码率配置
|
|
63
|
+
* @description
|
|
64
|
+
* * 自 v5.1.0 版本开始,推荐使用 `RCLocalTrack.setBitrate` 对不同流分别指定码率。
|
|
65
|
+
* * 该方法仅在 SDP `plan-b` 协议下(Chrome 92 与 Safari 11 之前的版本)有效。
|
|
66
|
+
* @param max 音视频发送码率上限,不可小于 200 且不可小于 `min`
|
|
67
|
+
* @param min 音视频发送码率下限,默认值为 1,且不可小于 1,不可大于 `max`
|
|
68
|
+
* @param start 起始码率,默认为码率上限的 70%
|
|
69
|
+
*/
|
|
70
|
+
setBitrate(max: number, min: number, start?: number): void;
|
|
71
|
+
private _onTrackReady;
|
|
72
|
+
protected _callAppListener(eventType: keyof IRoomEventListener, ...attrs: any[]): void;
|
|
73
|
+
private _onUserUnpublish;
|
|
74
|
+
private _onTrackUnpublish;
|
|
75
|
+
private _unpublishPrev;
|
|
76
|
+
__parseInnerMessage(message: IReceivedMessage): boolean;
|
|
77
|
+
private msgTaskQueue;
|
|
78
|
+
/**
|
|
79
|
+
* 被踢出房间通知
|
|
80
|
+
* @param byServer
|
|
81
|
+
* * 当值为 false 时,说明本端 rtcPing 超时
|
|
82
|
+
* * 当值为 true 时,说明本端收到被踢出房间通知
|
|
83
|
+
*/
|
|
84
|
+
private _kickoff;
|
|
85
|
+
private _rtcpeerClosed;
|
|
86
|
+
/**
|
|
87
|
+
* 处理资源变更事件
|
|
88
|
+
* @param content
|
|
89
|
+
* @param messageType 消息类型
|
|
90
|
+
* @param userId 消息发送者
|
|
91
|
+
*/
|
|
92
|
+
protected _resourceHandle(content: {
|
|
93
|
+
/**
|
|
94
|
+
* 旧版本兼容参数,当收到非 `RTCMessageName.TOTAL_CONTENT_RESOURCE` 时:
|
|
95
|
+
* * ignore 值为 `true` 表示该消息由 signal server 向旧版本 RTCLib 提供的兼容消息,无需处理
|
|
96
|
+
* * 否则认为该消息是由旧版本 RTCLib 主动发出的增量变更消息,需要处理
|
|
97
|
+
*/
|
|
98
|
+
ignore?: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* 发布到房间内的资源列表,`RTCMessageName.TOTAL_CONTENT_RESOURCE` 消息携带全量数据,否则为增量数据
|
|
101
|
+
*/
|
|
102
|
+
uris: IPublishedResource[];
|
|
103
|
+
}, messageType: string, userId: string): Promise<void>;
|
|
104
|
+
private _onTrackPublish;
|
|
105
|
+
/**
|
|
106
|
+
* 处理 `RCRTCMessageType.STATE` 消息
|
|
107
|
+
* @param content
|
|
108
|
+
*/
|
|
109
|
+
private _stateHandle;
|
|
110
|
+
/**
|
|
111
|
+
* 获取房间 Id
|
|
112
|
+
*/
|
|
113
|
+
getRoomId(): string;
|
|
114
|
+
/**
|
|
115
|
+
* 获取当前 userId
|
|
116
|
+
*/
|
|
117
|
+
getCrtUserId(): string;
|
|
118
|
+
/**
|
|
119
|
+
* 获取 _pc 实例
|
|
120
|
+
*/
|
|
121
|
+
__getPC(): RCRTCPeerConnection;
|
|
122
|
+
/**
|
|
123
|
+
* 获取远程用户列表,不包含当前用户
|
|
124
|
+
*/
|
|
125
|
+
getRemoteUserIds(): string[];
|
|
126
|
+
/**
|
|
127
|
+
* 获取所有房间已发布的远端资源列表
|
|
128
|
+
* @returns
|
|
129
|
+
*/
|
|
130
|
+
getRemoteTracks(): RCRemoteTrack[];
|
|
131
|
+
/**
|
|
132
|
+
* 获取远端用户的资源列表
|
|
133
|
+
* @param userId
|
|
134
|
+
* @returns
|
|
135
|
+
*/
|
|
136
|
+
getRemoteTracksByUserId(userId: string): RCRemoteTrack[];
|
|
137
|
+
/**
|
|
138
|
+
* 获取房间当前会话 Id,当房间内已无成员时房间会回收,重新加入时 sessionId 将更新
|
|
139
|
+
*/
|
|
140
|
+
getSessionId(): string;
|
|
141
|
+
/**
|
|
142
|
+
* 向房间内发消息
|
|
143
|
+
* @param name 消息名称
|
|
144
|
+
* @param content 消息内容
|
|
145
|
+
*/
|
|
146
|
+
sendMessage(name: string, content: any): Promise<{
|
|
147
|
+
code: RCRTCCode;
|
|
148
|
+
}>;
|
|
149
|
+
/**
|
|
150
|
+
* 设置房间属性
|
|
151
|
+
* @param key 属性名
|
|
152
|
+
* @param value 属性值
|
|
153
|
+
* @param message 是否在设置属性的时候携带消息内容,传空则不往房间中发送消息
|
|
154
|
+
* @param isInner RTC 业务内部使用参数,用户忽略
|
|
155
|
+
*/
|
|
156
|
+
setRoomAttribute(key: string, value: string, message?: {
|
|
157
|
+
name: string;
|
|
158
|
+
content: string;
|
|
159
|
+
}, isInner?: boolean): Promise<{
|
|
160
|
+
code: RCRTCCode;
|
|
161
|
+
}>;
|
|
162
|
+
/**
|
|
163
|
+
* 删除房间属性
|
|
164
|
+
* @param keys 待删除的属性名数组
|
|
165
|
+
* @param message 是否在删除属性的时候携带消息内容,传空则不往房间中发送消息
|
|
166
|
+
* @param isInner RTC 业务内部使用参数,用户忽略
|
|
167
|
+
*/
|
|
168
|
+
deleteRoomAttributes(keys: string[], message?: {
|
|
169
|
+
name: string;
|
|
170
|
+
content: string;
|
|
171
|
+
}, isInner?: boolean): Promise<{
|
|
172
|
+
code: RCRTCCode;
|
|
173
|
+
}>;
|
|
174
|
+
/**
|
|
175
|
+
* 获取房间属性
|
|
176
|
+
* @param keys 要查询的属性名数组,当数组长度为空时,取所有已设置的 kv 值
|
|
177
|
+
* @param isInner RTC 业务内部使用参数,用户忽略
|
|
178
|
+
*/
|
|
179
|
+
getRoomAttributes(keys?: string[], isInner?: boolean): Promise<{
|
|
180
|
+
code: RCRTCCode;
|
|
181
|
+
data?: KVString;
|
|
182
|
+
}>;
|
|
183
|
+
/**
|
|
184
|
+
* 设置当前用户属性(暂不开放)
|
|
185
|
+
* @param key 属性名
|
|
186
|
+
* @param value 属性值
|
|
187
|
+
* @param message 是否在设置属性的时候携带消息内容,传空则不往房间中发送消息
|
|
188
|
+
*/
|
|
189
|
+
private _setUserAttributeValue;
|
|
190
|
+
/**
|
|
191
|
+
* 删除当前用户属性(暂不开放)
|
|
192
|
+
* @param keys 待删除的属性名数组
|
|
193
|
+
* @param message 是否在删除属性的时候携带消息内容,传空则不往房间中发送消息
|
|
194
|
+
*/
|
|
195
|
+
private _deleteUserAttributes;
|
|
196
|
+
/**
|
|
197
|
+
* 获取当前用户属性(暂不开放)
|
|
198
|
+
* @param keys 要查询的属性名数组
|
|
199
|
+
*/
|
|
200
|
+
private _getUserAttributes;
|
|
201
|
+
/**
|
|
202
|
+
* 查询房间是否已销毁
|
|
203
|
+
*/
|
|
204
|
+
isDestroyed(): boolean;
|
|
205
|
+
/**
|
|
206
|
+
* 退出并销毁当前房间实例,退出后该房间的所有方法将不可用
|
|
207
|
+
*/
|
|
208
|
+
__destroy(quitRoom: boolean): Promise<void>;
|
|
209
|
+
private _leaveHandle;
|
|
210
|
+
private _onLocalTrackDestroied;
|
|
211
|
+
/**
|
|
212
|
+
* 本端流状态修改,需通知房间内其他成员
|
|
213
|
+
* @param localTrack
|
|
214
|
+
*/
|
|
215
|
+
private _onLocalTrackMuted;
|
|
216
|
+
/**
|
|
217
|
+
* 发布默认流,默认流的 TAG 为 `RongCloudRTC`,分辨率 640*480,帧率 15 帧
|
|
218
|
+
* @param pubTiny 是否同步发小流
|
|
219
|
+
*/
|
|
220
|
+
/**
|
|
221
|
+
* 从 pc 移除当次发布失败的资源
|
|
222
|
+
*/
|
|
223
|
+
private _removePubFailedTracks;
|
|
224
|
+
/**
|
|
225
|
+
* 增量发布资源,若发布的资源 tag 及媒体类型重复,后者将覆盖前者进行发布。
|
|
226
|
+
* @param tracks 待发布的 RCLocalTrack 实例
|
|
227
|
+
* @returns
|
|
228
|
+
*/
|
|
229
|
+
publish(tracks: (RCLocalTrack | IPublishAttrs)[]): Promise<{
|
|
230
|
+
code: RCRTCCode;
|
|
231
|
+
liveUrl?: string;
|
|
232
|
+
}>;
|
|
233
|
+
private __publish;
|
|
234
|
+
/**
|
|
235
|
+
* ice 断线后,尝试重新走 exchange
|
|
236
|
+
*/
|
|
237
|
+
protected _reTryExchange(): Promise<void>;
|
|
238
|
+
protected _exchangeHandle(body: IExchangeReqBody): Promise<{
|
|
239
|
+
code: RCRTCCode;
|
|
240
|
+
data?: import("../service").IExchangeResponse | undefined;
|
|
241
|
+
}>;
|
|
242
|
+
protected _getRTCReqestHeaders(): IRTCReqHeader;
|
|
243
|
+
/**
|
|
244
|
+
* 获取 exchange 接口的请求体数据
|
|
245
|
+
* @param subscribeList 订阅清单
|
|
246
|
+
* @param iceRestart
|
|
247
|
+
*/
|
|
248
|
+
protected _createExchangeParams(subscribeList: ISubscribeAttr[], iceRestart: boolean): Promise<IExchangeReqBody>;
|
|
249
|
+
/**
|
|
250
|
+
* 获取已发布资源的 state 数据
|
|
251
|
+
* @param trackId
|
|
252
|
+
*/
|
|
253
|
+
private _getResourceState;
|
|
254
|
+
/**
|
|
255
|
+
* 增量取消资源发布,若相应资源中存在小流资源,则同时取消发布
|
|
256
|
+
* @param resourceIds 取消发布的资源 Id 列表
|
|
257
|
+
*/
|
|
258
|
+
unpublish(tracks: RCLocalTrack[]): Promise<{
|
|
259
|
+
code: RCRTCCode;
|
|
260
|
+
}>;
|
|
261
|
+
private __unpublish;
|
|
262
|
+
/**
|
|
263
|
+
* 根据资源 Id 获取资源数据
|
|
264
|
+
* @param resourceId
|
|
265
|
+
*/
|
|
266
|
+
private _getResourceById;
|
|
267
|
+
/**
|
|
268
|
+
* resourceId 有效性验证
|
|
269
|
+
* @param resourceId
|
|
270
|
+
*/
|
|
271
|
+
protected _isValidResourceId(resourceId: string): boolean;
|
|
272
|
+
/**
|
|
273
|
+
* 订阅资源
|
|
274
|
+
* @param tracks
|
|
275
|
+
*/
|
|
276
|
+
subscribe(tracks: (RCRemoteTrack | ISubscribeAttr)[]): Promise<{
|
|
277
|
+
code: RCRTCCode;
|
|
278
|
+
failedList?: ISubscribeAttr[];
|
|
279
|
+
}>;
|
|
280
|
+
private __subscribe;
|
|
281
|
+
/**
|
|
282
|
+
* 取消订阅资源
|
|
283
|
+
* @param tracks 预取消远端资源
|
|
284
|
+
*/
|
|
285
|
+
unsubscribe(tracks: RCRemoteTrack[]): Promise<{
|
|
286
|
+
code: RCRTCCode;
|
|
287
|
+
failedList?: ISubscribeAttr[];
|
|
288
|
+
}>;
|
|
289
|
+
private __unsubscribe;
|
|
290
|
+
protected _assertRoomDestroyed(): RCRTCCode | undefined;
|
|
291
|
+
/**
|
|
292
|
+
* 获取已发布的本地资源
|
|
293
|
+
* @param trackId
|
|
294
|
+
* @returns
|
|
295
|
+
*/
|
|
296
|
+
getLocalTrack(trackId: string): RCLocalTrack | null;
|
|
297
|
+
/**
|
|
298
|
+
* 获取所有已发布的资源
|
|
299
|
+
*/
|
|
300
|
+
getLocalTracks(): RCLocalTrack[];
|
|
301
|
+
/**
|
|
302
|
+
* 根据 trackId 获取房间内的远端资源
|
|
303
|
+
* @param trackId
|
|
304
|
+
* @returns
|
|
305
|
+
*/
|
|
306
|
+
getRemoteTrack(trackId: string): RCRemoteTrack | null;
|
|
307
|
+
/**
|
|
308
|
+
* 强制修改订阅列表,仅订阅数组中的资源,取消订阅其他已订阅资源。
|
|
309
|
+
* 当参数为 `[]` 时,意味着不再订阅任何资源
|
|
310
|
+
* @param tracks 变更的资源列表
|
|
311
|
+
*/
|
|
312
|
+
updateSubList(tracks: (RCRemoteTrack | ISubscribeAttr)[]): Promise<{
|
|
313
|
+
code: RCRTCCode;
|
|
314
|
+
}>;
|
|
315
|
+
private _updateSubListHandle;
|
|
316
|
+
private _appListener;
|
|
317
|
+
/**
|
|
318
|
+
* 注册事件监听器,多次注册会导致后者覆盖前者,可以通过使用 `registerRoomEventListener(null)` 取消注册
|
|
319
|
+
* @param listener
|
|
320
|
+
*/
|
|
321
|
+
registerRoomEventListener(listener: IRoomEventListener | null): void;
|
|
322
|
+
/**
|
|
323
|
+
* 注册房间数据监控
|
|
324
|
+
* @param listener
|
|
325
|
+
* @description 该方法暂仅支持 Chrome 浏览器
|
|
326
|
+
*/
|
|
327
|
+
registerReportListener(listener: IRCRTCReportListener | null): void;
|
|
328
|
+
/**
|
|
329
|
+
* 音量上报
|
|
330
|
+
* @param handler 业务端传入的音量上报事件
|
|
331
|
+
* @param gap 上报时间间隔
|
|
332
|
+
*/
|
|
333
|
+
onAudioLevelChange(handler: IAudioLevelChangeHandler | null, gap?: number): void;
|
|
334
|
+
/**
|
|
335
|
+
* 断线重连后尝试补发断线过程中的通知信息
|
|
336
|
+
*/
|
|
337
|
+
__onReconnected(livingType?: RCLivingType): Promise<{
|
|
338
|
+
data: IJoinRTCRoomData | undefined;
|
|
339
|
+
} | void>;
|
|
340
|
+
private _onAudioMuteChange;
|
|
341
|
+
private _onVideoMuteChange;
|
|
342
|
+
/**
|
|
343
|
+
* 观众切换为主播后直接处理人员变更及资源变更
|
|
344
|
+
*/
|
|
345
|
+
protected _afterChangedRole(data: IJoinRTCRoomData): void;
|
|
346
|
+
/**
|
|
347
|
+
* 销毁远端资源
|
|
348
|
+
*/
|
|
349
|
+
private _removeRemoteTracks;
|
|
350
|
+
}
|
|
351
|
+
//# sourceMappingURL=RCAbstractRoom.d.ts.map
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { RTCPluginContext, IRuntime, IServerRTCRoomEntry } from '@rongcloud/engine';
|
|
2
|
+
import { RCRemoteAudioTrack, RCRemoteTrack, RCRemoteVideoTrack } from '../tracks/RCRemoteTrack';
|
|
3
|
+
import { RCRTCCode } from '../enums/RCRTCCode';
|
|
4
|
+
import { IRCRTCInitOptions, IRCRTCReportListener, IRCRTCTrackEventListener, ISubscribeAttr, IAudioLevelChangeHandler } from '../interfaces';
|
|
5
|
+
import PolarisReporter from '../PolarisReporter';
|
|
6
|
+
import { IBroadcastSubReqBody } from '../service';
|
|
7
|
+
import RCLocalMediaStream from './RCLocalMediaStream';
|
|
8
|
+
import { RCResolution } from '../enums/RCResolution';
|
|
9
|
+
import { RCFrameRate } from '../enums/RCFrameRate';
|
|
10
|
+
import { RCLivingType } from '../enums/RCLivingType';
|
|
11
|
+
import RCRTCPeerConnection from '../webrtc/RCRTCPeerConnection';
|
|
12
|
+
export interface IAudienceRoomEventListener extends IRCRTCTrackEventListener {
|
|
13
|
+
/**
|
|
14
|
+
* 主播加入
|
|
15
|
+
* @param userIds 加入主播的 id 列表
|
|
16
|
+
*/
|
|
17
|
+
onAnchorJoin?(userId: string[]): void;
|
|
18
|
+
/**
|
|
19
|
+
* 主播退出
|
|
20
|
+
* @param userIds 退出主播的 id 列表
|
|
21
|
+
*/
|
|
22
|
+
onAnchorLeave?(userId: string[]): void;
|
|
23
|
+
/**
|
|
24
|
+
* 房间内合流发布资源
|
|
25
|
+
* @param tracks 新发布的合流音轨与视轨数据列表,包含新发布的 RCRemoteAudioTrack 与 RCRemoteVideoTrack 实例
|
|
26
|
+
* @description
|
|
27
|
+
* 当房间内某个主播第一次发布资源时触发
|
|
28
|
+
*/
|
|
29
|
+
onTrackPublish?(tracks: RCRemoteTrack[]): void;
|
|
30
|
+
/**
|
|
31
|
+
* 房间内取消合流发布资源
|
|
32
|
+
* @param tracks 被取消发布的合流音轨与视轨数据列表
|
|
33
|
+
* @description
|
|
34
|
+
* 当房间内全部主播退出房间时,SDK 内部会取消对资源的订阅,业务层仅需处理 UI 业务
|
|
35
|
+
*/
|
|
36
|
+
onTrackUnpublish?(tracks: RCRemoteTrack[]): void;
|
|
37
|
+
/**
|
|
38
|
+
* 房间内主播发布资源
|
|
39
|
+
* @param tracks 主播新发布的音轨与视轨数据列表,包含新发布的 RCRemoteAudioTrack 与 RCRemoteVideoTrack 实例
|
|
40
|
+
*/
|
|
41
|
+
onAnchorTrackPublish?(tracks: RCRemoteTrack[]): void;
|
|
42
|
+
/**
|
|
43
|
+
* 房间内主播取消发布资源
|
|
44
|
+
* @param tracks 被主播取消发布的音轨与视轨数据列表
|
|
45
|
+
* @description 当资源被取消发布时,SDK 内部会取消对相关资源的订阅,业务层仅需处理 UI 业务
|
|
46
|
+
*/
|
|
47
|
+
onAnchorTrackUnpublish?(tracks: RCRemoteTrack[]): void;
|
|
48
|
+
/**
|
|
49
|
+
* 房间主播禁用/启用音频
|
|
50
|
+
* @param audioTrack RCRemoteAudioTrack 类实例
|
|
51
|
+
*/
|
|
52
|
+
onAudioMuteChange?(audioTrack: RCRemoteAudioTrack): void;
|
|
53
|
+
/**
|
|
54
|
+
* 房间主播禁用/启用视频
|
|
55
|
+
* @param videoTrack RCRemoteVideoTrack 类实例对象
|
|
56
|
+
*/
|
|
57
|
+
onVideoMuteChange?(videoTrack: RCRemoteVideoTrack): void;
|
|
58
|
+
/**
|
|
59
|
+
* 房间内主播把发布的资源推至 CDN
|
|
60
|
+
*/
|
|
61
|
+
onCDNInfoEnable?(CDNInfo: {
|
|
62
|
+
resolution: RCResolution;
|
|
63
|
+
fps: RCFrameRate;
|
|
64
|
+
}): void;
|
|
65
|
+
/**
|
|
66
|
+
* 主播停止推 CDN
|
|
67
|
+
*/
|
|
68
|
+
onCDNInfoDisable?(): void;
|
|
69
|
+
/**
|
|
70
|
+
* 主播改变推 CDN 的分辨率或帧率
|
|
71
|
+
*/
|
|
72
|
+
onCDNInfoChange?(CDNInfo: {
|
|
73
|
+
resolution: RCResolution;
|
|
74
|
+
fps: RCFrameRate;
|
|
75
|
+
}): void;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 观众直播房间类
|
|
79
|
+
* 处理:
|
|
80
|
+
* 1、通知观众房间内 人员变更、资源变更
|
|
81
|
+
* 2、观众订阅、取消订阅资源
|
|
82
|
+
*/
|
|
83
|
+
export default class RCAudienceLivingRoom {
|
|
84
|
+
private readonly _context;
|
|
85
|
+
private readonly _runtime;
|
|
86
|
+
private readonly _initOptions;
|
|
87
|
+
readonly _roomId: string;
|
|
88
|
+
private readonly _joinResData;
|
|
89
|
+
readonly _livingType: RCLivingType;
|
|
90
|
+
private readonly _service;
|
|
91
|
+
/**
|
|
92
|
+
* 主播列表
|
|
93
|
+
*/
|
|
94
|
+
private _roomAnchorList;
|
|
95
|
+
/**
|
|
96
|
+
* 合流、分流资源
|
|
97
|
+
*/
|
|
98
|
+
private _roomRes;
|
|
99
|
+
/**
|
|
100
|
+
* 主播分流资源
|
|
101
|
+
*/
|
|
102
|
+
private _roomAnchorRes;
|
|
103
|
+
/**
|
|
104
|
+
* 合流、分流 remoteTracks
|
|
105
|
+
*/
|
|
106
|
+
private _remoteTracks;
|
|
107
|
+
private _appListener;
|
|
108
|
+
private _pc;
|
|
109
|
+
private _subscribedList;
|
|
110
|
+
private _sessionId;
|
|
111
|
+
private _destroyed;
|
|
112
|
+
/**
|
|
113
|
+
* 北极星上报实例
|
|
114
|
+
*/
|
|
115
|
+
protected _polarisReport: PolarisReporter | null;
|
|
116
|
+
/**
|
|
117
|
+
* 音量上报实例
|
|
118
|
+
*/
|
|
119
|
+
private _audioLevelReport;
|
|
120
|
+
/**
|
|
121
|
+
* cdn_uris 资源
|
|
122
|
+
*/
|
|
123
|
+
private _CDNUris;
|
|
124
|
+
constructor(_context: RTCPluginContext, _runtime: IRuntime, _initOptions: IRCRTCInitOptions, _roomId: string, _joinResData: {
|
|
125
|
+
token: string;
|
|
126
|
+
kvEntries: IServerRTCRoomEntry[];
|
|
127
|
+
}, _livingType: RCLivingType);
|
|
128
|
+
/**
|
|
129
|
+
* 解析服务端返回的 KV 数据,赋值 room 内数据
|
|
130
|
+
*/
|
|
131
|
+
private _setInitData;
|
|
132
|
+
protected _assertRoomDestroyed(): RCRTCCode | undefined;
|
|
133
|
+
/**
|
|
134
|
+
* @description 信令数据处理
|
|
135
|
+
* @param roomId 数据对应的房间 Id
|
|
136
|
+
* @param singalData 拉取到的数据
|
|
137
|
+
* * key RC_ANCHOR_LIST value: 为主播 ID 集合
|
|
138
|
+
* * key RC_RES_`userId` value: 为主播发布的资源
|
|
139
|
+
* * key RC_RTC_SESSIONID value: sessionId
|
|
140
|
+
* * key RC_CDN value: CDN 资源数据
|
|
141
|
+
*/
|
|
142
|
+
private singalDataChange;
|
|
143
|
+
/**
|
|
144
|
+
* 计算加入离开的主播 ID 列表
|
|
145
|
+
*/
|
|
146
|
+
private _diffAnchorList;
|
|
147
|
+
private _handleNewJoinedAnchor;
|
|
148
|
+
private _handleLeftedAnchor;
|
|
149
|
+
/**
|
|
150
|
+
* 计算新发布和取消发布的合流资源
|
|
151
|
+
*/
|
|
152
|
+
private _diffRoomResource;
|
|
153
|
+
/**
|
|
154
|
+
* 计算主播发布和取消发布的资源,以及资源的状态变更
|
|
155
|
+
*/
|
|
156
|
+
private _diffAnchorResource;
|
|
157
|
+
private _onUserUnpublish;
|
|
158
|
+
private _callAppListener;
|
|
159
|
+
/**
|
|
160
|
+
* ice 断线后,尝试重新走 exchange
|
|
161
|
+
*/
|
|
162
|
+
private _reTryExchange;
|
|
163
|
+
/**
|
|
164
|
+
* 获取 subscribe 接口的请求体数据
|
|
165
|
+
* @param subscribeList 订阅清单
|
|
166
|
+
* @param publishedStreams 已发布流
|
|
167
|
+
* @param iceRestart
|
|
168
|
+
*/
|
|
169
|
+
protected _createSubscribeParams(subscribeList: ISubscribeAttr[], publishedStreams: {
|
|
170
|
+
[msid: string]: RCLocalMediaStream;
|
|
171
|
+
}, iceRestart: boolean): Promise<{
|
|
172
|
+
reqBody: IBroadcastSubReqBody;
|
|
173
|
+
offer: RTCSessionDescriptionInit;
|
|
174
|
+
dynamicBitrate: {
|
|
175
|
+
min: number;
|
|
176
|
+
max: number;
|
|
177
|
+
};
|
|
178
|
+
}>;
|
|
179
|
+
private _subscribeHandle;
|
|
180
|
+
private _getReqHeaders;
|
|
181
|
+
private _exchangeHandle;
|
|
182
|
+
private _updateSubListHandle;
|
|
183
|
+
/**
|
|
184
|
+
* 对比 cdn_uris 资源
|
|
185
|
+
* @param newCDNUris 新的 cdn_uris 数据
|
|
186
|
+
*/
|
|
187
|
+
private _diffCDNUris;
|
|
188
|
+
/**
|
|
189
|
+
* 获取 CDN 资源对应的拉流地址
|
|
190
|
+
* _CDNUris 无 url 时,说明未开启 CDN 推送
|
|
191
|
+
* @returns CDNPlayUrl
|
|
192
|
+
*/
|
|
193
|
+
private _getCDNPlayUrl;
|
|
194
|
+
/**
|
|
195
|
+
* 获取 CDN 资源对应的拉流地址
|
|
196
|
+
* @returns CDNPlayUrl
|
|
197
|
+
*/
|
|
198
|
+
getCDNPlayUrl(resolution?: RCResolution, fps?: RCFrameRate): Promise<{
|
|
199
|
+
code: RCRTCCode;
|
|
200
|
+
CDNPlayUrl?: string;
|
|
201
|
+
}>;
|
|
202
|
+
/**
|
|
203
|
+
* 订阅资源
|
|
204
|
+
* @param tracks
|
|
205
|
+
*/
|
|
206
|
+
subscribe(tracks: (RCRemoteTrack | ISubscribeAttr)[]): Promise<{
|
|
207
|
+
code: RCRTCCode;
|
|
208
|
+
failedList?: ISubscribeAttr[];
|
|
209
|
+
}>;
|
|
210
|
+
private __unsubscribe;
|
|
211
|
+
/**
|
|
212
|
+
* 取消订阅资源
|
|
213
|
+
* @param tracks
|
|
214
|
+
*/
|
|
215
|
+
unsubscribe(tracks: RCRemoteTrack[]): Promise<{
|
|
216
|
+
code: RCRTCCode;
|
|
217
|
+
failedList?: ISubscribeAttr[];
|
|
218
|
+
}>;
|
|
219
|
+
/**
|
|
220
|
+
* 退出房间并销毁当前房间实例,退出后该房间的所有方法将不可用
|
|
221
|
+
*/
|
|
222
|
+
__destroy(quitRoom: boolean): Promise<void>;
|
|
223
|
+
/**
|
|
224
|
+
* 根据 trackId 获取房间内的远端资源
|
|
225
|
+
* @param trackId
|
|
226
|
+
*/
|
|
227
|
+
getRemoteTrack(trackId: string): RCRemoteTrack;
|
|
228
|
+
/**
|
|
229
|
+
* 获取 _pc 实例
|
|
230
|
+
*/
|
|
231
|
+
__getPC(): RCRTCPeerConnection;
|
|
232
|
+
/**
|
|
233
|
+
* TODO 待优化
|
|
234
|
+
* @param trackId
|
|
235
|
+
*/
|
|
236
|
+
getLocalTrack(trackId: string): RCRemoteTrack;
|
|
237
|
+
/**
|
|
238
|
+
* 断线重连后处理逻辑, SDK 内部处理调用
|
|
239
|
+
*/
|
|
240
|
+
__onReconnected(): Promise<void>;
|
|
241
|
+
/**
|
|
242
|
+
* 观众房间事件注册
|
|
243
|
+
* @param tag 参数描述
|
|
244
|
+
*/
|
|
245
|
+
registerRoomEventListener(listener: IAudienceRoomEventListener | null): void;
|
|
246
|
+
/**
|
|
247
|
+
* 音量上报
|
|
248
|
+
* @param handler 业务端传入的音量上报事件
|
|
249
|
+
* @param gap 上报时间间隔
|
|
250
|
+
*/
|
|
251
|
+
onAudioLevelChange(handler: IAudioLevelChangeHandler | null, gap?: number): void;
|
|
252
|
+
/**
|
|
253
|
+
* 注册房间数据监控
|
|
254
|
+
* @param listener
|
|
255
|
+
*/
|
|
256
|
+
registerReportListener(listener: IRCRTCReportListener | null): void;
|
|
257
|
+
/**
|
|
258
|
+
* 获取房间 Id
|
|
259
|
+
*/
|
|
260
|
+
getRoomId(): string;
|
|
261
|
+
/**
|
|
262
|
+
* 获取当前 userId
|
|
263
|
+
*/
|
|
264
|
+
getCrtUserId(): string;
|
|
265
|
+
/**
|
|
266
|
+
* 获取房间当前会话 Id,当房间内已无成员时房间会回收,重新加入时 sessionId 将更新
|
|
267
|
+
*/
|
|
268
|
+
getSessionId(): string;
|
|
269
|
+
/**
|
|
270
|
+
* 获取远程主播用户列表
|
|
271
|
+
*/
|
|
272
|
+
getRemoteUserIds(): string[];
|
|
273
|
+
/**
|
|
274
|
+
* 获取远端用户的资源列表
|
|
275
|
+
* @param userId
|
|
276
|
+
* @returns
|
|
277
|
+
*/
|
|
278
|
+
getRemoteTracksByUserId(userId: string): RCRemoteTrack[];
|
|
279
|
+
/**
|
|
280
|
+
* 获取房间内所有已发布的远端资源列表, 包含合流资源
|
|
281
|
+
* @returns
|
|
282
|
+
*/
|
|
283
|
+
getRemoteTracks(): RCRemoteTrack[];
|
|
284
|
+
/**
|
|
285
|
+
* 获取远端 RTC tracks
|
|
286
|
+
*/
|
|
287
|
+
getRemoteRTCTracks(): RCRemoteTrack[];
|
|
288
|
+
/**
|
|
289
|
+
* 获取远端 MCU tracks
|
|
290
|
+
*/
|
|
291
|
+
getRemoteMCUTracks(): RCRemoteTrack[];
|
|
292
|
+
/**
|
|
293
|
+
* 获取房间内 CDN 信息
|
|
294
|
+
*/
|
|
295
|
+
getCDNInfo(): {
|
|
296
|
+
resolution: RCResolution;
|
|
297
|
+
fps: RCFrameRate;
|
|
298
|
+
CDNEnable: boolean | undefined;
|
|
299
|
+
} | {
|
|
300
|
+
CDNEnable: boolean;
|
|
301
|
+
resolution?: undefined;
|
|
302
|
+
fps?: undefined;
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
//# sourceMappingURL=RCAudienceLivingRoom.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IAudioLevelChangeHandler } from '../interfaces';
|
|
2
|
+
import RCAbstractRoom from './RCAbstractRoom';
|
|
3
|
+
import RCAudienceLivingRoom from './RCAudienceLivingRoom';
|
|
4
|
+
export default class RCAudioLevelReport {
|
|
5
|
+
private readonly _room;
|
|
6
|
+
private _pc;
|
|
7
|
+
private _audioLevelChangeHandler;
|
|
8
|
+
private _timer;
|
|
9
|
+
constructor(_room: RCAbstractRoom | RCAudienceLivingRoom);
|
|
10
|
+
/**
|
|
11
|
+
* 通知业务端音量 > 0 的数据,数组每一项包含 track、audioLevel
|
|
12
|
+
*/
|
|
13
|
+
private _audioLevelReport;
|
|
14
|
+
onAudioLevelChange(handler: IAudioLevelChangeHandler | null, gap: number): void;
|
|
15
|
+
clearAudioLevelReportTimer(): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=RCAudioLevelReport.d.ts.map
|