@rongcloud/plugin-call 5.1.3 → 5.2.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/README.md +11 -249
- package/dist/index.d.ts +961 -13
- package/dist/index.esm.js +2589 -15
- package/dist/index.umd.js +6 -15
- package/package.json +13 -21
- package/dist/RCCallClient.d.ts +0 -127
- package/dist/RCCallSession.d.ts +0 -237
- package/dist/enums.d.ts +0 -14
- package/dist/eventEmitter.d.ts +0 -4
- package/dist/helper.d.ts +0 -2
- package/dist/index.js +0 -16
- package/dist/interface.d.ts +0 -320
- package/dist/timer.d.ts +0 -12
- package/dist/utils.d.ts +0 -9
- package/dist/validation.d.ts +0 -15
package/package.json
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rongcloud/plugin-call",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"__attrs__": {
|
|
7
|
-
"globals": "RCCall"
|
|
8
|
-
},
|
|
3
|
+
"type": "module",
|
|
4
|
+
"main": "./dist/index.umd.js",
|
|
9
5
|
"types": "./dist/index.d.ts",
|
|
10
6
|
"module": "./dist/index.esm.js",
|
|
11
|
-
"
|
|
7
|
+
"exports": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.esm.js",
|
|
10
|
+
"require": "./dist/index.umd.js"
|
|
11
|
+
},
|
|
12
12
|
"keywords": [
|
|
13
13
|
"RongCloud",
|
|
14
14
|
"JSSDK",
|
|
15
15
|
"WebRTC",
|
|
16
|
-
"RTCLib",
|
|
17
16
|
"CallLib"
|
|
18
17
|
],
|
|
19
18
|
"contributors": [
|
|
20
|
-
"
|
|
21
|
-
"lizhipeng@rongcloud.cn",
|
|
22
|
-
"lishunan1@rongcloud.cn"
|
|
19
|
+
"support@rongcloud.cn"
|
|
23
20
|
],
|
|
24
21
|
"files": [
|
|
25
22
|
"README.md",
|
|
@@ -27,16 +24,11 @@
|
|
|
27
24
|
"dist"
|
|
28
25
|
],
|
|
29
26
|
"license": "LGPL 2.1",
|
|
27
|
+
"description": "@rongcloud/plugin-call",
|
|
30
28
|
"homepage": "https://www.rongcloud.cn",
|
|
31
|
-
"
|
|
32
|
-
"node": ">=10.0.0"
|
|
33
|
-
},
|
|
29
|
+
"version": "5.2.0",
|
|
34
30
|
"peerDependencies": {
|
|
35
|
-
"@rongcloud/engine": "^5.7.
|
|
31
|
+
"@rongcloud/engine": "^5.7.7",
|
|
36
32
|
"@rongcloud/plugin-rtc": "^5.5.1"
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
"@rongcloud/plugin-call-engine": "^5.1.3"
|
|
40
|
-
},
|
|
41
|
-
"__commit__": "c1ec87082611a289263c27c340ee414ee9e60ba8"
|
|
42
|
-
}
|
|
33
|
+
}
|
|
34
|
+
}
|
package/dist/RCCallClient.d.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { RTCPluginContext, IRuntime, IRTCJoinedInfo, BasicLogger } from '@rongcloud/engine';
|
|
2
|
-
import { RCCallErrorCode, IOfflineRecord } from '@rongcloud/plugin-call-engine';
|
|
3
|
-
import { IRCCallInGroupParams, IRCCallInitOptions, IRCCallParams, IPushConfig } from './interface';
|
|
4
|
-
import { RCCallSession } from './RCCallSession';
|
|
5
|
-
export default class RCCallClient {
|
|
6
|
-
private _context;
|
|
7
|
-
private readonly _runtime;
|
|
8
|
-
private readonly _logger;
|
|
9
|
-
/**
|
|
10
|
-
* rtc实例
|
|
11
|
-
*/
|
|
12
|
-
private readonly _rtcClient;
|
|
13
|
-
/**
|
|
14
|
-
* callEngine层实例
|
|
15
|
-
*/
|
|
16
|
-
private readonly _callEngine;
|
|
17
|
-
/**
|
|
18
|
-
* 其它参数
|
|
19
|
-
*/
|
|
20
|
-
private _options;
|
|
21
|
-
/**
|
|
22
|
-
* session列表
|
|
23
|
-
*/
|
|
24
|
-
private _sessionList;
|
|
25
|
-
private _callPushConfig;
|
|
26
|
-
private _hungupPushConfig;
|
|
27
|
-
constructor(_context: RTCPluginContext, _runtime: IRuntime, _logger: BasicLogger, _options: IRCCallInitOptions);
|
|
28
|
-
/**
|
|
29
|
-
* 监听onInvite
|
|
30
|
-
*/
|
|
31
|
-
private _onInvite;
|
|
32
|
-
/**
|
|
33
|
-
* 监听离线消息报告
|
|
34
|
-
* @param record
|
|
35
|
-
*/
|
|
36
|
-
_onOfflineRecord(record: IOfflineRecord): void;
|
|
37
|
-
/**
|
|
38
|
-
* 注册用户信息。注册后,在发起邀请或挂断等操作时,会将该信息一并发送给对端
|
|
39
|
-
* @param info.name 用户名称
|
|
40
|
-
* @param info.portraitUri 用户头像信息
|
|
41
|
-
* @param info.extra 预留拓展字段
|
|
42
|
-
*/
|
|
43
|
-
registerUserInfo(info?: {
|
|
44
|
-
name?: string;
|
|
45
|
-
portraitUri?: string;
|
|
46
|
-
extra?: string;
|
|
47
|
-
}): void;
|
|
48
|
-
/**
|
|
49
|
-
* 跨App单呼,发送invite消息,回调回来接收stateMachine, 建session
|
|
50
|
-
* @param params.targetId 被呼叫一方的用户 id 必填
|
|
51
|
-
* @param params.mediaType 音频呼叫 or 音视频呼叫 必填
|
|
52
|
-
* @param params.listener (session上的监听) 必填
|
|
53
|
-
* @param params.constraints 获取音频或音视频资源时的参数 可选
|
|
54
|
-
* @param params.channelId 组织 Id 可选
|
|
55
|
-
* @param params.extra 消息扩展信息
|
|
56
|
-
* @deprecated 5.1.2 版本废弃 params.pushTitle 通知的标题
|
|
57
|
-
* @deprecated 5.1.2 版本废弃 params.pushContent 通知的内容
|
|
58
|
-
* @param params.bitrate 需要设置的码率参数
|
|
59
|
-
*
|
|
60
|
-
*/
|
|
61
|
-
startCrossCall({ targetId, mediaType, listener, constraints, channelId, extra, pushTitle, pushContent, bitrate }: IRCCallParams): Promise<{
|
|
62
|
-
code: RCCallErrorCode;
|
|
63
|
-
session?: RCCallSession;
|
|
64
|
-
}>;
|
|
65
|
-
/**
|
|
66
|
-
* 单呼,发送invite消息,回调回来接收stateMachine, 建session
|
|
67
|
-
* @param params.targetId 被呼叫一方的用户 id 必填
|
|
68
|
-
* @param params.mediaType 音频呼叫 or 音视频呼叫 必填
|
|
69
|
-
* @param params.listener (session上的监听) 必填
|
|
70
|
-
* @param params.constraints 获取音频或音视频资源时的参数 可选
|
|
71
|
-
* @param params.channelId 组织 Id 可选
|
|
72
|
-
* @param params.extra 消息扩展信息
|
|
73
|
-
* @deprecated 5.1.2 版本废弃 params.pushTitle 通知的标题
|
|
74
|
-
* @deprecated 5.1.2 版本废弃 params.pushContent 通知的内容
|
|
75
|
-
* @param params.bitrate 需要设置的码率参数
|
|
76
|
-
*
|
|
77
|
-
*/
|
|
78
|
-
call({ targetId, mediaType, listener, constraints, channelId, extra, pushTitle, pushContent, bitrate }: IRCCallParams): Promise<{
|
|
79
|
-
code: RCCallErrorCode;
|
|
80
|
-
session?: RCCallSession;
|
|
81
|
-
}>;
|
|
82
|
-
private __call;
|
|
83
|
-
/**
|
|
84
|
-
* 发起群组呼叫
|
|
85
|
-
* @param params.targetId 群组 Id 必填
|
|
86
|
-
* @param params.userIds 被呼叫的群内成员 Id 必填
|
|
87
|
-
* @param params.mediaType 音频呼叫 or 音视频呼叫 必填
|
|
88
|
-
* @param params.listener (session上的监听) 必填
|
|
89
|
-
* @param params.constraints 获取音频或音视频资源时的参数 可选
|
|
90
|
-
* @param params.channelId 组织 Id 可选
|
|
91
|
-
* @param params.extra 消息扩展信息 可选
|
|
92
|
-
* @deprecated 5.1.2 版本废弃 params.pushTitle 通知的标题
|
|
93
|
-
* @deprecated 5.1.2 版本废弃 params.pushContent 通知的内容
|
|
94
|
-
* @param params.bitrate 需要设置的码率参数
|
|
95
|
-
*/
|
|
96
|
-
callInGroup({ targetId, userIds, mediaType, listener, constraints, channelId, extra, pushTitle, pushContent, bitrate }: IRCCallInGroupParams): Promise<{
|
|
97
|
-
code: RCCallErrorCode;
|
|
98
|
-
session?: RCCallSession;
|
|
99
|
-
}>;
|
|
100
|
-
/**
|
|
101
|
-
* 调RTC API 获得本地流
|
|
102
|
-
*/
|
|
103
|
-
private _getLocalTrackCore;
|
|
104
|
-
private _getLocalTrack;
|
|
105
|
-
/**
|
|
106
|
-
* 从sessionList删除某个session
|
|
107
|
-
*/
|
|
108
|
-
private _removeSession;
|
|
109
|
-
/**
|
|
110
|
-
* 获取己方其他端加入通话(已加入 RTC 房间)的用户信息
|
|
111
|
-
*/
|
|
112
|
-
getJoinedRoomInfo(): Promise<{
|
|
113
|
-
code: RCCallErrorCode;
|
|
114
|
-
data?: IRTCJoinedInfo[];
|
|
115
|
-
}>;
|
|
116
|
-
/**
|
|
117
|
-
* 设置呼叫、挂断推送数据
|
|
118
|
-
* @param callPushConfig 呼叫推送配置
|
|
119
|
-
* @param callPushConfig.pushTitle 呼叫推送标题
|
|
120
|
-
* @param callPushConfig.pushContent 呼叫推送内容
|
|
121
|
-
* @param hungupPushConfig 挂断推送配置
|
|
122
|
-
* @param hungupPushConfig.pushTitle 挂断推送标题
|
|
123
|
-
* @param hungupPushConfig.pushContent 挂断推送内容
|
|
124
|
-
*/
|
|
125
|
-
setPushConfig(callPushConfig?: IPushConfig, hungupPushConfig?: IPushConfig): void;
|
|
126
|
-
}
|
|
127
|
-
//# sourceMappingURL=RCCallClient.d.ts.map
|
package/dist/RCCallSession.d.ts
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import { ConversationType, ILogger } from '@rongcloud/engine';
|
|
2
|
-
import { IUserData, IInviteOptions, RCCallErrorCode, RCCallMediaType, RCCallSessionState, RCCallStateMachine, RCCallUserState } from '@rongcloud/plugin-call-engine';
|
|
3
|
-
import { RCRTCClient, IMicphoneAudioProfile } from '@rongcloud/plugin-rtc';
|
|
4
|
-
import { IMediaStreamConstraints, IRCCallSessionOptions, ISessionListener } from './interface';
|
|
5
|
-
export declare class RCCallSession {
|
|
6
|
-
/**
|
|
7
|
-
* 状态机实例
|
|
8
|
-
*/
|
|
9
|
-
private _stateMachine;
|
|
10
|
-
/**
|
|
11
|
-
* rtc实例
|
|
12
|
-
*/
|
|
13
|
-
private readonly _rtcClient;
|
|
14
|
-
private readonly _logger;
|
|
15
|
-
/**
|
|
16
|
-
* session的其它选项
|
|
17
|
-
*/
|
|
18
|
-
private _options;
|
|
19
|
-
/**
|
|
20
|
-
* RTC房间实例
|
|
21
|
-
*/
|
|
22
|
-
private _room;
|
|
23
|
-
/**
|
|
24
|
-
* 用户传进来的 对session的监听 (要在RCCallClient的_onInvite里判断,要求执行完onSession必须注册session的监听,所以这里是public)
|
|
25
|
-
*/
|
|
26
|
-
_listener: ISessionListener | null;
|
|
27
|
-
/**
|
|
28
|
-
* RTC订阅、发布重试的次数
|
|
29
|
-
*/
|
|
30
|
-
private readonly _RETRYCOUNT;
|
|
31
|
-
/**
|
|
32
|
-
* 加入房间定时器
|
|
33
|
-
*/
|
|
34
|
-
private joinRoomTimer;
|
|
35
|
-
constructor(
|
|
36
|
-
/**
|
|
37
|
-
* 状态机实例
|
|
38
|
-
*/
|
|
39
|
-
_stateMachine: RCCallStateMachine,
|
|
40
|
-
/**
|
|
41
|
-
* rtc实例
|
|
42
|
-
*/
|
|
43
|
-
_rtcClient: RCRTCClient, _logger: ILogger,
|
|
44
|
-
/**
|
|
45
|
-
* session的其它选项
|
|
46
|
-
*/
|
|
47
|
-
_options?: IRCCallSessionOptions);
|
|
48
|
-
/**
|
|
49
|
-
* 加入房间
|
|
50
|
-
*/
|
|
51
|
-
private _joinRoom;
|
|
52
|
-
/**
|
|
53
|
-
* (初始化房间的时候) 订阅远程的流,把远程的流抛给用户
|
|
54
|
-
*/
|
|
55
|
-
private _subscribeInRoomRemoteTrack;
|
|
56
|
-
/**
|
|
57
|
-
* 可以重试的订阅
|
|
58
|
-
* @param params.tracks tracks
|
|
59
|
-
* @param params.isAllowSubscribeRetry 是否允许重试
|
|
60
|
-
* @param params.count 允许重试的次数
|
|
61
|
-
*/
|
|
62
|
-
private _subscribeRetry;
|
|
63
|
-
/**
|
|
64
|
-
* 发布本地资源的逻辑
|
|
65
|
-
*
|
|
66
|
-
*/
|
|
67
|
-
private _publish;
|
|
68
|
-
/**
|
|
69
|
-
* 可以重试的发布
|
|
70
|
-
* @param params.tracks tracks
|
|
71
|
-
* @param params.isAllowPublishRetry 是否允许重试
|
|
72
|
-
* @param params.count 允许重试的次数
|
|
73
|
-
*/
|
|
74
|
-
private _publishRetry;
|
|
75
|
-
/**
|
|
76
|
-
* 退出房间
|
|
77
|
-
*/
|
|
78
|
-
private _leaveRoom;
|
|
79
|
-
/**
|
|
80
|
-
* 出现异常后要处理的逻辑,
|
|
81
|
-
* @param endReason 原因
|
|
82
|
-
*/
|
|
83
|
-
private _exceptionClose;
|
|
84
|
-
/**
|
|
85
|
-
* 用户调用的,注册session上的监听
|
|
86
|
-
*/
|
|
87
|
-
registerSessionListener(listener: ISessionListener): void;
|
|
88
|
-
/**
|
|
89
|
-
* 调RTC API 获得本地流
|
|
90
|
-
*/
|
|
91
|
-
private _getLocalTrackCore;
|
|
92
|
-
private _getLocalTrack;
|
|
93
|
-
/**
|
|
94
|
-
* 通话中更换音频设备
|
|
95
|
-
*/
|
|
96
|
-
changeAudioDevice(audioConstraints?: IMicphoneAudioProfile): Promise<{
|
|
97
|
-
code: RCCallErrorCode;
|
|
98
|
-
}>;
|
|
99
|
-
/**
|
|
100
|
-
* 群呼叫中继续邀请
|
|
101
|
-
* @param userIds 被邀请用户 ID 列表
|
|
102
|
-
* @param options.extra 消息的扩展信息
|
|
103
|
-
* @deprecated 5.1.2 废弃 options.pushTitle 通知的标题
|
|
104
|
-
* @deprecated 5.1.2 废弃 options.pushContent 通知内容
|
|
105
|
-
*/
|
|
106
|
-
invite(userIds: string[], options?: IInviteOptions): Promise<{
|
|
107
|
-
code: RCCallErrorCode;
|
|
108
|
-
}>;
|
|
109
|
-
/**
|
|
110
|
-
* 同意接听
|
|
111
|
-
*/
|
|
112
|
-
accept(constraints?: IMediaStreamConstraints): Promise<{
|
|
113
|
-
code: RCCallErrorCode;
|
|
114
|
-
}>;
|
|
115
|
-
/**
|
|
116
|
-
* 挂断
|
|
117
|
-
*/
|
|
118
|
-
hungup(): Promise<{
|
|
119
|
-
code: RCCallErrorCode;
|
|
120
|
-
}>;
|
|
121
|
-
/**
|
|
122
|
-
* 通话媒体变更
|
|
123
|
-
* @param mediaType RCCallMediaType.AUDIO 改为音频通话 | RCCallMediaType.AUDIO_VIDEO 改为音视频通话
|
|
124
|
-
*/
|
|
125
|
-
_changeMediaType(mediaType: RCCallMediaType): Promise<{
|
|
126
|
-
code: RCCallErrorCode;
|
|
127
|
-
}>;
|
|
128
|
-
/**
|
|
129
|
-
* 获得本地视频
|
|
130
|
-
*/
|
|
131
|
-
private _getLocalVideoTracks;
|
|
132
|
-
/**
|
|
133
|
-
* 获得本地音频
|
|
134
|
-
*/
|
|
135
|
-
private _getLocalAudioTracks;
|
|
136
|
-
/**
|
|
137
|
-
* 把通话的MediaType升级到音视频
|
|
138
|
-
*/
|
|
139
|
-
private _setMediaTypeToAudioAndVideo;
|
|
140
|
-
/**
|
|
141
|
-
* 把通话的MediaType降级到音频
|
|
142
|
-
* @param isSendMesssage 是否需要发消息, 默认发消息
|
|
143
|
-
*/
|
|
144
|
-
private _setMediaTypeToAudio;
|
|
145
|
-
/**
|
|
146
|
-
* 通话降级,目前需求只做通话降级,音视频可以降级为音频,音频不能升到音视频, 发消息成功才算降级成功
|
|
147
|
-
*
|
|
148
|
-
*/
|
|
149
|
-
descendAbility(): Promise<{
|
|
150
|
-
code: RCCallErrorCode;
|
|
151
|
-
}>;
|
|
152
|
-
/**
|
|
153
|
-
* 禁用视频track
|
|
154
|
-
*/
|
|
155
|
-
disableVideoTrack(): Promise<{
|
|
156
|
-
code: RCCallErrorCode;
|
|
157
|
-
}>;
|
|
158
|
-
/**
|
|
159
|
-
* 启用视频track
|
|
160
|
-
*/
|
|
161
|
-
enableVideoTrack(): Promise<{
|
|
162
|
-
code: RCCallErrorCode;
|
|
163
|
-
}>;
|
|
164
|
-
/**
|
|
165
|
-
* 禁用音频track
|
|
166
|
-
*/
|
|
167
|
-
disableAudioTrack(): Promise<{
|
|
168
|
-
code: RCCallErrorCode;
|
|
169
|
-
} | undefined>;
|
|
170
|
-
/**
|
|
171
|
-
* 启用音频track
|
|
172
|
-
*/
|
|
173
|
-
enableAudioTrack(): Promise<{
|
|
174
|
-
code: RCCallErrorCode;
|
|
175
|
-
} | undefined>;
|
|
176
|
-
/**
|
|
177
|
-
* 销毁本地流
|
|
178
|
-
*/
|
|
179
|
-
private _destroyTracks;
|
|
180
|
-
/**
|
|
181
|
-
* 向外抛出本地流
|
|
182
|
-
*/
|
|
183
|
-
private _notifyTrackReady;
|
|
184
|
-
/**
|
|
185
|
-
* 房间上注册事件
|
|
186
|
-
*/
|
|
187
|
-
private _registerRoomEventListener;
|
|
188
|
-
/**
|
|
189
|
-
* 注册房间质量数据监听器
|
|
190
|
-
*/
|
|
191
|
-
private _registerReportListener;
|
|
192
|
-
/**
|
|
193
|
-
* 通话唯一标识
|
|
194
|
-
*/
|
|
195
|
-
getSessionId(): string;
|
|
196
|
-
/**
|
|
197
|
-
* 获取房间当前会话 Id,当房间内已无成员时房间会回收,重新加入时 sessionId 将更新,(用户录制资源用的)
|
|
198
|
-
*/
|
|
199
|
-
getRTCSessionId(): string | null;
|
|
200
|
-
/**
|
|
201
|
-
* 目标 ID,单呼对方人员 Id, 群呼群组 Id
|
|
202
|
-
*/
|
|
203
|
-
getTargetId(): string;
|
|
204
|
-
/**
|
|
205
|
-
* 获取会话类型
|
|
206
|
-
*/
|
|
207
|
-
getConversationType(): ConversationType;
|
|
208
|
-
/**
|
|
209
|
-
* 组织 ID
|
|
210
|
-
*/
|
|
211
|
-
getChannelId(): string;
|
|
212
|
-
/**
|
|
213
|
-
* 房间人员列表,不包含本端信息
|
|
214
|
-
*/
|
|
215
|
-
getRemoteUsers(): IUserData[];
|
|
216
|
-
/**
|
|
217
|
-
* 房间人员列表,不包含本端信息
|
|
218
|
-
*/
|
|
219
|
-
getUsers(): IUserData[];
|
|
220
|
-
/**
|
|
221
|
-
* 获取人员状态
|
|
222
|
-
*/
|
|
223
|
-
getUserState(userId: string): RCCallUserState;
|
|
224
|
-
/**
|
|
225
|
-
* 获取session状态
|
|
226
|
-
*/
|
|
227
|
-
getState(): RCCallSessionState;
|
|
228
|
-
/**
|
|
229
|
-
* 获得会话发起者id
|
|
230
|
-
*/
|
|
231
|
-
getCallerId(): string;
|
|
232
|
-
/**
|
|
233
|
-
* 获得mediaType
|
|
234
|
-
*/
|
|
235
|
-
getMediaType(): RCCallMediaType;
|
|
236
|
-
}
|
|
237
|
-
//# sourceMappingURL=RCCallSession.d.ts.map
|
package/dist/enums.d.ts
DELETED
package/dist/eventEmitter.d.ts
DELETED
package/dist/helper.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,o=require("@rongcloud/engine"),t=require("@rongcloud/plugin-call-engine"),i=require("@rongcloud/plugin-rtc");
|
|
2
|
-
/*! *****************************************************************************
|
|
3
|
-
Copyright (c) Microsoft Corporation.
|
|
4
|
-
|
|
5
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
-
purpose with or without fee is hereby granted.
|
|
7
|
-
|
|
8
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
9
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
10
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
11
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
12
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */
|
|
16
|
-
function s(e,o,t,i){return new(t||(t=Promise))((function(s,r){function n(e){try{a(i.next(e))}catch(e){r(e)}}function l(e){try{a(i.throw(e))}catch(e){r(e)}}function a(e){var o;e.done?s(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(n,l)}a((i=i.apply(e,o||[])).next())}))}!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(e||(e={}));var r=new class{constructor(){this.list={}}on(e,o){return(this.list[e]||(this.list[e]=[])).push(o),this}once(e,o){const t=i=>{this.off(e,t),o.call(this,i)};t.fun=o,this.on(e,t)}off(e,o){const t=this.list[e];if(!t)return!1;if(o){let e;for(let i=0,s=t.length;i<s;i++)if(e=t[i],e===o||e.fun===o){t.splice(i,1);break}}else t&&(t.length=0)}emit(e,o){const t=[...this.list[e]];if(!t||0===t.length)return!1;t.forEach((e=>{e.call(this,o)}))}};const n=e=>{if(!e)return{result:!1,msg:"Initialization missing parameter -> options"};if("object"!=typeof e)return{result:!1,msg:"Initialization options must be an object"};const i=Object.keys(e),s=[];return["rtcClient","onSession","onSessionClose"].forEach((e=>{i.includes(e)||s.push(e)})),s.length?{result:!1,msg:`Initialization missing parameter -> "${s.join(",")}"`}:"object"!=typeof e.rtcClient?{result:!1,msg:"Initialization 'rtcClient' parameter must be of type 'object'"}:"function"!=typeof e.onSession?{result:!1,msg:"Initialization 'onSession' parameter must be of type 'function'"}:"function"!=typeof e.onSessionClose?{result:!1,msg:"Initialization 'onSessionClose' parameter must be of type 'function'"}:void 0!==e.isAllowSubscribeRetry&&"boolean"!=typeof e.isAllowSubscribeRetry?{result:!1,msg:"Initialization 'isAllowSubscribeRetry' parameter must be of type 'boolean'"}:void 0!==e.isAllowPublishRetry&&"boolean"!=typeof e.isAllowPublishRetry?{result:!1,msg:"Initialization 'isAllowPublishRetry' parameter must be of type 'boolean'"}:void 0!==e.isOffCameraWhenVideoDisable&&"boolean"!=typeof e.isOffCameraWhenVideoDisable?{result:!1,msg:"Initialization 'isOffCameraWhenVideoDisable' parameter must be of type 'boolean'"}:void 0===e.joinType||(r=e.joinType,Object.values(o.RTCJoinType).includes(r))?void 0!==e.isAllowDemotionGetStream&&"boolean"!=typeof e.isAllowDemotionGetStream?{result:!1,msg:"Initialization 'isAllowDemotionGetStream' parameter must be of type 'boolean'"}:void 0===e.lang||function(e){return Object.values(t.RCCallLanguage).includes(e)}(e.lang)?void 0===e.logLevel||function(e){return Object.values(o.LogLevel).includes(e)}(e.logLevel)?void 0!==e.logStdout&&"function"!=typeof e.logStdout?{result:!1,msg:"Initialization 'logStdout' parameter must be of type 'function'"}:{result:!0}:{result:!1,msg:"Initialization 'logLevel' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'lang' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'joinType' parameter must be of type correct type"};var r},l=e=>{if(!e)return{result:!1,msg:"missing parameter -> listener"};if("object"!=typeof e)return{result:!1,msg:"listener must be an object"};const o=Object.keys(e),t=[];return["onRinging","onAccept","onHungup","onTrackReady"].forEach((e=>{o.includes(e)||t.push(e)})),t.length?{result:!1,msg:`missing parameter -> "${t.join(",")}"`}:"function"!=typeof e.onRinging?{result:!1,msg:"'onRinging' parameter must be of type 'function'"}:"function"!=typeof e.onAccept?{result:!1,msg:"'onAccept' parameter must be of type 'function'"}:"function"!=typeof e.onHungup?{result:!1,msg:"'onHungup' parameter must be of type 'function'"}:"function"!=typeof e.onTrackReady?{result:!1,msg:"'onTrackReady' parameter must be of type 'function'"}:{result:!0}},a=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},C=e=>e===t.RCCallMediaType.AUDIO||e===t.RCCallMediaType.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},c=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},d=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},u=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushContent' parameter must be of type 'string'"},h=e=>Array.isArray(e)&&e.length?e.every((e=>"string"==typeof e&&e.length>0))?{result:!0}:{result:!1,msg:"'userIds' parameter is required"}:{result:!1,msg:"'userIds' parameter is required, must be of type 'string[]'"};const _=e=>{return e&&e.audio&&void 0!==e.audio.micphoneId&&"string"!=typeof e.audio.micphoneId?{result:!1,msg:"'constraints.audio.micphoneId' must be of type 'string'"}:e&&e.audio&&void 0!==e.audio.sampleRate&&"number"!=typeof e.audio.sampleRate?{result:!1,msg:"'constraints.audio.sampleRate' must be of type 'number'"}:e&&e.video&&void 0!==e.video.cameraId&&"string"!=typeof e.video.cameraId?{result:!1,msg:"'constraints.video.cameraId' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&"string"!=typeof e.video.frameRate?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&(o=e.video.frameRate,!["FPS_10","FPS_15","FPS_24","FPS_30"].includes(o))?{result:!1,msg:"'frameRate' value is out of range"}:e&&e.video&&void 0!==e.video.resolution&&"string"!=typeof e.video.resolution?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.resolution&&(t=e.video.resolution,!i.RCResolution[t])?{result:!1,msg:"'resolution' value is out of range"}:!e||!e.video||e.video.frameRate&&e.video.resolution?{result:!0}:{result:!1,msg:"'resolution' and 'resolution' is required"};var o,t};class R{constructor(e,o){this._timerId=0,this._startTime=0,e&&(this._timerId=((e,o)=>setTimeout(e,o))((()=>{e()}),o)),this._startTime=Date.now()}stop(){clearTimeout(this._timerId);const e=Date.now();let o=e-this._startTime;return 0===this._startTime&&(o=0),{startTime:this._startTime,endTime:e,duration:o}}reset(){this._startTime=0}}class g{constructor(e,o,i,n={}){this._stateMachine=e,this._rtcClient=o,this._logger=i,this._options=n,this._listener=null,this._RETRYCOUNT=2,this.joinRoomTimer=null,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:o})=>{this._logger.info("_",`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${o}`)},onStateChange:e=>s(this,void 0,void 0,(function*(){const{state:o,reason:i}=e;if(this._logger.info("_",`[RCCallSession onStateChange] : state->${o} reason->${i}`),o===t.RCCallSessionState.KEEPING){const e=this._stateMachine.getCallId();this._logger.info("_",`[RCCallSession onStateChange] roomId: ${e}`);try{yield this._joinRoom(e)}catch(o){this._exceptionClose(t.RCCallEndReason.NETWORK_ERROR),this._logger.error("_",`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${e}`),console.error(o)}}else if(o===t.RCCallSessionState.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void r.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._logger.info("_","[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{this._logger.info("_",`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){this._logger.error("_","[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{this._logger.info("_",`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){this._logger.error("_","[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,o)=>{this._logger.info("_",`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${o}`);try{this._listener.onHungup(e,o,this)}catch(e){this._logger.error("_","[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:o})=>{this._logger.info("_",`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,o,this)}catch(e){this._logger.error("_","[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:e,mediaType:o})=>{this._logger.info("_",`[RCCallSession onMediaModify]sender: sender.userId -> ${e.userId} mediaType: ${o}`),o===t.RCCallMediaType.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(e,o,this)}catch(e){this._logger.error("_","[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}},crossAppkey:e=>{this._logger.info("_",`[RCCallSession crossAppkey] 是否跨 appkey: ${e}`),this._options.isCrossAppkey=e}});const{pushTitle:l,pushContent:a}=this._options.hungupPushConfig;this._stateMachine.setHungupPushConfig(l,a)}_joinRoom(e){return s(this,void 0,void 0,(function*(){let o;try{o=this._options.isCrossAppkey?yield this._rtcClient.joinCrossRTCRoom(e,this._options.joinType):yield this._rtcClient.joinRTCRoom(e,this._options.joinType);const{code:s,userIds:r,room:n}=o;if(s!==i.RCRTCCode.SUCCESS)return s===i.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(t.RCCallEndReason.SERVICE_NOT_OPENED),s===i.RCRTCCode.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(t.RCCallEndReason.OTHER_CLIENT_IN_CALL):this._exceptionClose(t.RCCallEndReason.NETWORK_ERROR),this._logger.info("_",`[RCCallClient _joinRoom] join room failed: roomId -> ${e} RCRTCCode -> ${s}`),{code:t.RCCallErrorCode.JOIN_ROOM_ERROR};if(this._stateMachine.getState()===t.RCCallSessionState.END)return yield this._rtcClient.leaveRoom(n),this._room=null,{code:t.RCCallErrorCode.SUCCESS};r.length<1&&(this.joinRoomTimer=new R((()=>{this._exceptionClose(t.RCCallEndReason.REMOTE_NETWORK_ERROR)}),6e4)),this._room=n}catch(o){return this._exceptionClose(t.RCCallEndReason.NETWORK_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${e}`),console.error(o),{code:t.RCCallErrorCode.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(o){return this._exceptionClose(t.RCCallEndReason.SUBSCRIBE_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${e}`),console.error(o),{code:t.RCCallErrorCode.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(o){return this._exceptionClose(t.RCCallEndReason.PUBLISH_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _publish Exception roomId -> ${e}`),console.error(o),{code:t.RCCallErrorCode.JOIN_ROOM_ERROR}}return{code:t.RCCallErrorCode.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return s(this,void 0,void 0,(function*(){const e=this._room.getRemoteTracks();if(e.length){const{code:o}=yield this._subscribeRetry(e,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);o!==i.RCRTCCode.SUCCESS&&(this._exceptionClose(t.RCCallEndReason.SUBSCRIBE_ERROR),this._logger.error("_",`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${o}`))}}))}_subscribeRetry(e,o=!1,t=0){return s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.subscribe(e);if(s!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(s,this)}catch(e){this._logger.error("_","[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!o)return{code:s};if(t>0)return t--,this._subscribeRetry(e,o,t)}return{code:s}}))}_publish(){return s(this,void 0,void 0,(function*(){const o=this._options.localTracks,{code:s}=yield this._publishRetry(o,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(s!==i.RCRTCCode.SUCCESS)return this._exceptionClose(t.RCCallEndReason.PUBLISH_ERROR),void this._logger.info("_",`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${s}`);this._options.produceType===e.CALLEE&&this._notifyTrackReady(o)}))}_publishRetry(e,o=!1,t=0){return s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.publish(e);if(s!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(s,this)}catch(e){this._logger.error("_","[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!o)return{code:s};if(t>0)return t--,this._publishRetry(e,o,t)}return{code:s}}))}_leaveRoom(){return s(this,void 0,void 0,(function*(){try{const e=yield this._rtcClient.leaveRoom(this._room);this._logger.info("_",`[RCCallSession _leaveRoom] Successfully exited the room code: ${e.code}`)}catch(e){this._logger.error("_","[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();r.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const o=l(e);if(!o.result)throw new Error(`[RCCallSession registerSessionListener] ${o.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(e,o){return s(this,void 0,void 0,(function*(){if(e===t.RCCallMediaType.AUDIO){const{code:e,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o&&o.audio&&Object.assign({},o.audio));return e!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(this._logger.info("_","[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:t.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:e,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",o&&Object.assign({},o));return e!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(this._logger.info("_","[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:t.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(e,o){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===t.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(t.RCCallMediaType.AUDIO_VIDEO,o);if(e!==t.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(t.RCCallMediaType.AUDIO,o);return e!==t.RCCallErrorCode.SUCCESS?(this._exceptionClose(t.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:e}):{code:e,tracks:i}}return{code:e,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(e,o);return i!==t.RCCallErrorCode.SUCCESS?(this._exceptionClose(t.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:i}):{code:i,tracks:s}}}))}changeAudioDevice(e){return s(this,void 0,void 0,(function*(){const o=[],s=[],{code:r,track:n}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",e);if(r!==i.RCRTCCode.SUCCESS)return this._logger.error("_",`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${r}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||s.push(e)})),o.push(n),s.push(n),this._options.localTracks=s,this._notifyTrackReady(o),this._room){const{code:e}=yield this._room.publish(o);if(e!==i.RCRTCCode.SUCCESS)return{code:t.RCCallErrorCode.AUDIO_PUBLISH_ERROR}}return{code:t.RCCallErrorCode.SUCCESS}}))}invite(e,o={}){var t,i;return s(this,void 0,void 0,(function*(){const{extra:s=""}=o,{pushTitle:r="",pushContent:n=""}=(null===(t=this._options.callPushConfig)||void 0===t?void 0:t.pushTitle)||(null===(i=this._options.callPushConfig)||void 0===i?void 0:i.pushContent)?this._options.callPushConfig:o,l=[h(e),c(s),d(r),u(n)],a=[];if(!l.every((e=>(!e.result&&a.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${a.join("\n")}`);const{code:C}=yield this._stateMachine.invite(e,{extra:s,pushTitle:r,pushContent:n});return{code:C}}))}accept(e){return s(this,void 0,void 0,(function*(){const o=_(e);if(!o.result)throw new Error(`[RCCallSession accept] ${o.msg}`);r.emit("hungupOtherSession",{session:this});const i=this._stateMachine.getMediaType(),{code:s,tracks:n}=yield this._getLocalTrack(i,e);if(s!==t.RCCallErrorCode.SUCCESS)return{code:s};this._options.localTracks=n;const{code:l}=yield this._stateMachine.accept();return l!==t.RCCallErrorCode.SUCCESS?(this._logger.error("_",`[RCCallSession accept]Send accept message failed -> code: ${l}`),{code:l}):{code:l}}))}hungup(){return s(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(e){return s(this,void 0,void 0,(function*(){const{code:o}=yield this._stateMachine.changeMediaType(e);return o!==t.RCCallErrorCode.SUCCESS&&this._logger.error("_",`[RCCallSession _changeMediaType] change media type fail code-> ${o}`),{code:o}}))}_getLocalVideoTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isVideoTrack()))),e):e}_getLocalAudioTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isAudioTrack()))),e):e}_setMediaTypeToAudioAndVideo(){return s(this,void 0,void 0,(function*(){const{code:e,track:o}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:s}=yield this._room.publish([o]);s===i.RCRTCCode.SUCCESS?(this._notifyTrackReady([o]),this._changeMediaType(t.RCCallMediaType.AUDIO_VIDEO)):this._logger.error("_",`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${e}`)}))}_setMediaTypeToAudio(){return s(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(e.length){e.forEach((e=>{e.mute()}));const{code:o}=yield this._room.unpublish(e);o!==i.RCRTCCode.SUCCESS&&this._logger.error("_",`[RCCallSession disableVideo] unpublish failed -> ${o}`),this._destroyTracks(e)}}))}descendAbility(){return s(this,void 0,void 0,(function*(){const{code:e}=yield this._changeMediaType(t.RCCallMediaType.AUDIO);return e===t.RCCallErrorCode.SUCCESS&&this._setMediaTypeToAudio(),{code:e}}))}disableVideoTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:t.RCCallErrorCode.NOT_IN_ROOM_ERROR};const e=this._getLocalVideoTracks();if(!e.length)return this._logger.error("_",`[RCCallSession disableVideoTrack] Room missing video track -> ${t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};if(e.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:t.RCCallErrorCode.SUCCESS};const{code:o}=yield this._room.unpublish(e);return o!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallSession disableVideo] unpublish failed -> ${o}`),{code:t.RCCallErrorCode.UNPUBLISH_VIDEO_ERROR}):(e.forEach((e=>{e.destroy()})),{code:t.RCCallErrorCode.SUCCESS})}))}enableVideoTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:t.RCCallErrorCode.NOT_IN_ROOM_ERROR};if(!this._options.isOffCameraWhenVideoDisable){const e=this._getLocalVideoTracks();return e.length?(e.forEach((e=>{e.unmute()})),{code:t.RCCallErrorCode.SUCCESS}):(this._logger.error("_",`[RCCallSession EnableVideoTrack] Room missing video track -> ${t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR})}const{code:e,track:o}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return this._logger.error("_",`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_VIDEO_TRACK_ERROR};const s=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():s.push(e)})),s.push(o),this._options.localTracks=s,o.mute();const{code:r}=yield this._room.publish([o]);return r!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${e}`),{code:t.RCCallErrorCode.VIDEO_PUBLISH_ERROR}):(o.unmute(),this._notifyTrackReady([o]),{code:t.RCCallErrorCode.SUCCESS})}))}disableAudioTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:t.RCCallErrorCode.NOT_IN_ROOM_ERROR};this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:t.RCCallErrorCode.NOT_IN_ROOM_ERROR};const e=this._getLocalAudioTracks();if(!e.length)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};e.forEach((e=>{e.unmute()}))}))}_destroyTracks(e){e.forEach((e=>{e.destroy()}))}_notifyTrackReady(e){e.forEach((e=>{try{this._listener.onTrackReady(e,this)}catch(e){this._logger.error("_","[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(e,o)=>{const s=this._rtcClient.getCurrentId();this._stateMachine.userLeave([s]),e?(o===i.RCKickReason.SERVER_KICK&&this._exceptionClose(t.RCCallEndReason.KICKED_BY_SERVER),o===i.RCKickReason.OTHER_KICK&&this._exceptionClose(t.RCCallEndReason.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(t.RCCallEndReason.NETWORK_ERROR)},onMessageReceive(e,o,t,i){},onRoomAttributeChange(e,o){},onAudioMuteChange:e=>{this._logger.info("_",`[RCCallSession onAudioMuteChange] userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"audio",trackId:e.getTrackId()};try{this._listener.onAudioMuteChange(o,this)}catch(e){this._logger.error("_","[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{this._logger.info("_",`[RCCallSession onVideoMuteChange]userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"video",trackId:e.getTrackId()};try{this._listener.onVideoMuteChange(o,this)}catch(e){this._logger.error("_","[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>s(this,void 0,void 0,(function*(){if(this._room){const{code:o}=yield this._room.subscribe(e);o!==i.RCRTCCode.SUCCESS&&this._logger.error("_",`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${o}`)}})),onTrackUnpublish:e=>{},onTrackReady:e=>{this._stateMachine.getMediaType()===t.RCCallMediaType.AUDIO&&e.isVideoTrack()||this._notifyTrackReady([e])},onUserJoin:e=>{this.joinRoomTimer&&this.joinRoomTimer.stop(),this._stateMachine.userJoin(e)},onUserLeave:e=>{this._logger.info("_",`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{this._logger.info("_",`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){this._logger.error("_","[RCCallSession onPing] listening onPing exception"),console.error(e)}}})}_registerReportListener(){this._room.registerReportListener({onStateReport:e=>{try{this._listener.onRTCStateReport&&this._listener.onRTCStateReport(e,this)}catch(e){this._logger.error("_","[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){this._logger.error("_","[RCCallSession onICEConnectionStateChange] onICEConnectionStateChange exception"),console.error(e)}}})}getSessionId(){return this._stateMachine.getCallId()}getRTCSessionId(){return this._room?this._room.getSessionId():null}getTargetId(){return this._stateMachine.getTargetId()}getConversationType(){return this._stateMachine.getConversationType()}getChannelId(){return this._stateMachine.getChannelId()}getRemoteUsers(){return this._stateMachine.getRemoteUsers()}getUsers(){return this._stateMachine.getRemoteUsers()}getUserState(e){if(!e||"string"!=typeof e)throw new Error("userId is required, must be of type 'string'");return this._stateMachine.getUserState(e)}getState(){return this._stateMachine.getState()}getCallerId(){return this._stateMachine.getCallerId()}getMediaType(){return this._stateMachine.getMediaType()}}class p{constructor(e,i,s,n){this._context=e,this._runtime=i,this._logger=s,this._sessionList=[],this._callPushConfig={},this._hungupPushConfig={},this._rtcClient=n.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:o.RTCJoinType.COEXIST,isAllowDemotionGetStream:!1,lang:t.RCCallLanguage.ZH},n),this._callEngine=new t.RCCallEngine(this._context,i,this._logger,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||t.RCCallLanguage.ZH}),r.on("sessionClose",(({session:e,summaryInfo:o})=>{this._removeSession(e);try{this._options.onSessionClose(e,o)}catch(e){this._logger.error("_","[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),r.on("hungupOtherSession",(({session:e})=>{const o=e.getSessionId();this._logger.info("_",`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${o}`),this._logger.info("_",`[RCCallClient hungupOtherSession] sessionList ->${this._sessionList.map((e=>e.getSessionId())).join(",")}`);let t=0;for(;this._sessionList.length>1;)this._sessionList[t].getSessionId()!==o?(this._sessionList[t].hungup(),this._sessionList.splice(t,1)):t++;this._logger.info("_",`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(o,t){this._logger.info("_","[RCCallClient _onInvite] Received invite message");const i=new g(o,this._rtcClient,this._logger,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:e.CALLEE,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});this._logger.info("_","[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(i);try{this._options.onSession(i,t)}catch(e){this._logger.error("_","[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!i._listener)throw this._logger.error("_","[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=l(i._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){this._logger.error("_","[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),this._logger.info("_","[RCCallClient registerUserInfo] successfully register user info data")}startCrossCall({targetId:e,mediaType:o=t.RCCallMediaType.AUDIO,listener:i,constraints:r,channelId:n="",extra:l="",pushTitle:a="",pushContent:C="",bitrate:c}){return s(this,void 0,void 0,(function*(){return this.__call({targetId:e,mediaType:o,listener:i,constraints:r,channelId:n,extra:l,pushTitle:a,pushContent:C,bitrate:c,isCrossAppkey:!0})}))}call({targetId:e,mediaType:o=t.RCCallMediaType.AUDIO,listener:i,constraints:r,channelId:n="",extra:l="",pushTitle:a="",pushContent:C="",bitrate:c}){return s(this,void 0,void 0,(function*(){return this.__call({targetId:e,mediaType:o,listener:i,constraints:r,channelId:n,extra:l,pushTitle:a,pushContent:C,bitrate:c})}))}__call({targetId:o,mediaType:i=t.RCCallMediaType.AUDIO,listener:r,constraints:n,channelId:h="",extra:_="",pushTitle:R="",pushContent:p="",bitrate:f,isCrossAppkey:m=!1}){return s(this,void 0,void 0,(function*(){const{pushTitle:s="",pushContent:S=""}=this._callPushConfig.pushTitle||this._callPushConfig.pushContent?this._callPushConfig:{pushTitle:R,pushContent:p};this._logger.info("_",`[RCCallClient call] extra->${_} pushTitle->${s} pushContent->${S}`);const T=[a(o),C(i),l(r),c(_),d(s),u(S)],y=[];if(!T.every((e=>(!e.result&&y.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${y.join("\n")}`);let E=[];const{code:I,tracks:v}=yield this._getLocalTrack(i,n);if(I!==t.RCCallErrorCode.SUCCESS)return{code:I};E=v,E.forEach((e=>{var o,t,i;e.isAudioTrack()&&(null==f?void 0:f.audio)&&e.setBitrate(null==f?void 0:f.audio),e.isVideoTrack()&&(null==f?void 0:f.video)&&e.setBitrate(null===(o=null==f?void 0:f.video)||void 0===o?void 0:o.max,null===(t=null==f?void 0:f.video)||void 0===t?void 0:t.min,null===(i=null==f?void 0:f.video)||void 0===i?void 0:i.start),r.onTrackReady(e)}));const{code:b,stateMachine:O}=yield this._callEngine.call(h,o,i,_,s,S,m);if(b===t.RCCallErrorCode.SUCCESS&&O){this._logger.info("_","[RCCallClient call] successfully created state machine");const o=new g(O,this._rtcClient,this._logger,{localTracks:E,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:e.CALLER,isCrossAppkey:m,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});return o.registerSessionListener(r),this._sessionList.push(o),this._logger.info("_",`[RCCallClient call] successfully created session object, sessionId: ${o.getSessionId()}`),{code:b,session:o}}return this._logger.error("_",`[RCCallClient call] call failed code ->: ${b}`),E.forEach((e=>{e.mute(),e.destroy()})),{code:b}}))}callInGroup({targetId:o,userIds:i,mediaType:r=t.RCCallMediaType.AUDIO,listener:n,constraints:_,channelId:R="",extra:p="",pushTitle:f="",pushContent:m="",bitrate:S}){return s(this,void 0,void 0,(function*(){const{pushTitle:s="",pushContent:T=""}=this._callPushConfig.pushTitle||this._callPushConfig.pushContent?this._callPushConfig:{pushTitle:f,pushContent:m},y=[a(o),h(i),C(r),l(n),c(p),d(s),u(T)],E=[];if(!y.every((e=>(!e.result&&E.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${E.join("\n")}`);let I=[];const{code:v,tracks:b}=yield this._getLocalTrack(r,_);if(v!==t.RCCallErrorCode.SUCCESS)return{code:v};I=b,I.forEach((e=>{var o,t,i;e.isAudioTrack()&&(null==S?void 0:S.audio)&&e.setBitrate(null==S?void 0:S.audio),e.isVideoTrack()&&(null==S?void 0:S.video)&&e.setBitrate(null===(o=null==S?void 0:S.video)||void 0===o?void 0:o.max,null===(t=null==S?void 0:S.video)||void 0===t?void 0:t.min,null===(i=null==S?void 0:S.video)||void 0===i?void 0:i.start),n.onTrackReady(e)}));const{code:O,stateMachine:k}=yield this._callEngine.callInGroup(R,o,r,i,p,s,T);if(O===t.RCCallErrorCode.SUCCESS&&k){this._logger.info("_","[RCCallClient callInGroup] successfully created state machine");const o=new g(k,this._rtcClient,this._logger,{localTracks:I,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:e.CALLER,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});return o.registerSessionListener(n),this._sessionList.push(o),this._logger.info("_",`[RCCallClient callInGroup] successfully created session object, sessionId: ${o.getSessionId()}`),{code:O,session:o}}return this._logger.info("_",`[RCCallClient callInGroup] callInGroup failed code -> ${O}`),I.forEach((e=>{e.mute(),e.destroy()})),{code:O}}))}_getLocalTrackCore(e,o){return s(this,void 0,void 0,(function*(){if(e===t.RCCallMediaType.AUDIO){const{code:e,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o&&o.audio&&Object.assign({},o.audio));return e!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(this._logger.info("_","[RCCallClient _getTrack] successfully get Audio local tracks"),{code:t.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:e,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",o&&Object.assign({},o));return e!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(this._logger.info("_","[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:t.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(e,o){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===t.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(t.RCCallMediaType.AUDIO_VIDEO,o);if(e!==t.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(t.RCCallMediaType.AUDIO,o);return e!==t.RCCallErrorCode.SUCCESS?{code:e}:{code:e,tracks:i}}return{code:e,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(e,o);return i!==t.RCCallErrorCode.SUCCESS?{code:i}:{code:i,tracks:s}}}))}_removeSession(e){const o=e.getSessionId();this._sessionList=this._sessionList.filter((e=>e.getSessionId()!==o))}getJoinedRoomInfo(){return s(this,void 0,void 0,(function*(){const{code:e,data:i}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return e!==o.ErrorCode.SUCCESS?(this._logger.error("_",`getJoinedUserInfo error code: ${e}`),{code:t.RCCallErrorCode.QUERY_JOINED_USER_INFO_ERROR}):{code:t.RCCallErrorCode.SUCCESS,data:i}}))}setPushConfig(e={},o={}){const t=[e,o].map((e=>(e=>{const{pushTitle:o="",pushContent:t=""}=e,i=[];return i.push(d(o)),i.push(u(t)),i})(e)))[0],i=[];if(!t.every((e=>(!e.result&&i.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup callPushConfig or hungupPushConfig] ${i.join("\n")}`);this._callPushConfig=e,this._hungupPushConfig=o}}o.VersionManage.add("plugin-call","5.1.3");const f={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,t,i){const s=n(i);if(!s.result)throw new Error(`[RCCallLib installer steup]${s.msg}`);if(!o.VersionManage.validEngine("^5.7.6"))throw new Error(`The current engine version '${o.VersionManage.getInfo().engine}' error, plugin-call required engine version at least '^5.7.6'.`);const r=e.createLogger("RCCall","RTC");return r.warn("_","RCCall Version: 5.1.3, Commit: c1ec87082611a289263c27c340ee414ee9e60ba8"),new p(e,t,r,i)}};Object.defineProperty(exports,"RCCallEndReason",{enumerable:!0,get:function(){return t.RCCallEndReason}}),Object.defineProperty(exports,"RCCallErrorCode",{enumerable:!0,get:function(){return t.RCCallErrorCode}}),Object.defineProperty(exports,"RCCallLanguage",{enumerable:!0,get:function(){return t.RCCallLanguage}}),Object.defineProperty(exports,"RCCallMediaType",{enumerable:!0,get:function(){return t.RCCallMediaType}}),Object.defineProperty(exports,"RCCallSessionState",{enumerable:!0,get:function(){return t.RCCallSessionState}}),Object.defineProperty(exports,"RCCallUserState",{enumerable:!0,get:function(){return t.RCCallUserState}}),exports.RCCallClient=p,exports.RCCallSession=g,exports.installer=f;
|