@rongcloud/plugin-call 5.0.7 → 5.0.10

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.
@@ -0,0 +1,100 @@
1
+ import { PluginContext, IRuntime, IRTCJoinedInfo } from '@rongcloud/engine';
2
+ import { RCCallErrorCode, IOfflineRecord } from '@rongcloud/plugin-call-engine';
3
+ import { IRCCallInGroupParams, IRCCallInitOptions, IRCCallParams } from './interface';
4
+ import { RCCallSession } from './RCCallSession';
5
+ export default class RCCallClient {
6
+ private _context;
7
+ private readonly _runtime;
8
+ /**
9
+ * rtc实例
10
+ */
11
+ private readonly _rtcClient;
12
+ /**
13
+ * callEngine层实例
14
+ */
15
+ private readonly _callEngine;
16
+ /**
17
+ * 其它参数
18
+ */
19
+ private _options;
20
+ /**
21
+ * session列表
22
+ */
23
+ private _sessionList;
24
+ constructor(_context: PluginContext, _runtime: IRuntime, _options: IRCCallInitOptions);
25
+ /**
26
+ * 监听onInvite
27
+ */
28
+ private _onInvite;
29
+ /**
30
+ * 监听离线消息报告
31
+ * @param record
32
+ */
33
+ _onOfflineRecord(record: IOfflineRecord): void;
34
+ /**
35
+ * 注册用户信息。注册后,在发起邀请或挂断等操作时,会将该信息一并发送给对端
36
+ * @param info.name 用户名称
37
+ * @param info.portraitUri 用户头像信息
38
+ * @param info.extra 预留拓展字段
39
+ */
40
+ registerUserInfo(info?: {
41
+ name?: string;
42
+ portraitUri?: string;
43
+ extra?: string;
44
+ }): void;
45
+ /**
46
+ * 单呼,发送invite消息,回调回来接收stateMachine, 建session
47
+ * @param params.targetId 被呼叫一方的用户 id 必填
48
+ * @param params.mediaType 音频呼叫 or 音视频呼叫 必填
49
+ * @param params.listener (session上的监听) 必填
50
+ * @param params.constraints 获取音频或音视频资源时的参数 可选
51
+ * @param params.channelId 组织 Id 可选
52
+ * @param params.extra 消息扩展信息
53
+ * @param params.pushTitle 通知的标题
54
+ * @param params.pushContent 通知的内容
55
+ * @param params.bitrate 需要设置的码率参数
56
+ *
57
+ */
58
+ call({ targetId, mediaType, listener, constraints, channelId, extra, pushTitle, pushContent, bitrate }: IRCCallParams): Promise<{
59
+ code: RCCallErrorCode;
60
+ session?: RCCallSession;
61
+ }>;
62
+ /**
63
+ * 发起群组呼叫
64
+ * @param params.targetId 群组 Id 必填
65
+ * @param params.userIds 被呼叫的群内成员 Id 必填
66
+ * @param params.mediaType 音频呼叫 or 音视频呼叫 必填
67
+ * @param params.listener (session上的监听) 必填
68
+ * @param params.constraints 获取音频或音视频资源时的参数 可选
69
+ * @param params.channelId 组织 Id 可选
70
+ * @param params.extra 消息扩展信息 可选
71
+ * @param params.pushTitle 通知的标题
72
+ * @param params.pushContent 通知的内容
73
+ * @param params.bitrate 需要设置的码率参数
74
+ */
75
+ callInGroup({ targetId, userIds, mediaType, listener, constraints, channelId, extra, pushTitle, pushContent, bitrate }: IRCCallInGroupParams): Promise<{
76
+ code: RCCallErrorCode;
77
+ session?: RCCallSession;
78
+ }>;
79
+ /**
80
+ * 调RTC API 获得本地流
81
+ */
82
+ private _getLocalTrackCore;
83
+ private _getLocalTrack;
84
+ /**
85
+ * 从sessionList删除某个session
86
+ */
87
+ private _removeSession;
88
+ /**
89
+ * 获取己方其他端加入通话(已加入 RTC 房间)的用户信息
90
+ */
91
+ getJoinedRoomInfo(): Promise<{
92
+ code: RCCallErrorCode;
93
+ data?: IRTCJoinedInfo[];
94
+ }>;
95
+ /**
96
+ * 销毁本地状态机(应对本地状态机异常无法重新建立通话)
97
+ */
98
+ destroyStateMachine(): Promise<void>;
99
+ }
100
+ //# sourceMappingURL=RCCallClient.d.ts.map
@@ -0,0 +1,232 @@
1
+ import { ConversationType } 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
+ /**
15
+ * session的其它选项
16
+ */
17
+ private _options;
18
+ /**
19
+ * RTC房间实例
20
+ */
21
+ private _room;
22
+ /**
23
+ * 用户传进来的 对session的监听 (要在RCCallClient的_onInvite里判断,要求执行完onSession必须注册session的监听,所以这里是public)
24
+ */
25
+ _listener: ISessionListener | null;
26
+ /**
27
+ * RTC订阅、发布重试的次数
28
+ */
29
+ private readonly _RETRYCOUNT;
30
+ /**
31
+ * 加入房间定时器
32
+ */
33
+ private joinRoomTimer;
34
+ constructor(
35
+ /**
36
+ * 状态机实例
37
+ */
38
+ _stateMachine: RCCallStateMachine,
39
+ /**
40
+ * rtc实例
41
+ */
42
+ _rtcClient: RCRTCClient,
43
+ /**
44
+ * session的其它选项
45
+ */
46
+ _options?: IRCCallSessionOptions);
47
+ /**
48
+ * 加入房间
49
+ */
50
+ private _joinRoom;
51
+ /**
52
+ * (初始化房间的时候) 订阅远程的流,把远程的流抛给用户
53
+ */
54
+ private _subscribeInRoomRemoteTrack;
55
+ /**
56
+ * 可以重试的订阅
57
+ * @param params.tracks tracks
58
+ * @param params.isAllowSubscribeRetry 是否允许重试
59
+ * @param params.count 允许重试的次数
60
+ */
61
+ private _subscribeRetry;
62
+ /**
63
+ * 发布本地资源的逻辑
64
+ *
65
+ */
66
+ private _publish;
67
+ /**
68
+ * 可以重试的发布
69
+ * @param params.tracks tracks
70
+ * @param params.isAllowPublishRetry 是否允许重试
71
+ * @param params.count 允许重试的次数
72
+ */
73
+ private _publishRetry;
74
+ /**
75
+ * 退出房间
76
+ */
77
+ private _leaveRoom;
78
+ /**
79
+ * 出现异常后要处理的逻辑,
80
+ * @param endReason 原因
81
+ */
82
+ private _exceptionClose;
83
+ /**
84
+ * 用户调用的,注册session上的监听
85
+ */
86
+ registerSessionListener(listener: ISessionListener): void;
87
+ /**
88
+ * 调RTC API 获得本地流
89
+ */
90
+ private _getLocalTrackCore;
91
+ private _getLocalTrack;
92
+ /**
93
+ * 通话中更换音频设备
94
+ */
95
+ changeAudioDevice(audioConstraints?: IMicphoneAudioProfile): Promise<{
96
+ code: RCCallErrorCode;
97
+ }>;
98
+ /**
99
+ * 群呼叫中继续邀请
100
+ * @param userIds 被邀请用户 ID 列表
101
+ * @param options.extra 消息的扩展信息
102
+ * @param options.pushTitle 通知的标题
103
+ * @param options.pushContent 通知内容
104
+ */
105
+ invite(userIds: string[], options?: IInviteOptions): Promise<{
106
+ code: RCCallErrorCode;
107
+ }>;
108
+ /**
109
+ * 同意接听
110
+ */
111
+ accept(constraints?: IMediaStreamConstraints): Promise<{
112
+ code: RCCallErrorCode;
113
+ }>;
114
+ /**
115
+ * 挂断
116
+ */
117
+ hungup(): Promise<{
118
+ code: RCCallErrorCode;
119
+ }>;
120
+ /**
121
+ * 通话媒体变更
122
+ * @param mediaType RCCallMediaType.AUDIO 改为音频通话 | RCCallMediaType.AUDIO_VIDEO 改为音视频通话
123
+ */
124
+ _changeMediaType(mediaType: RCCallMediaType): Promise<{
125
+ code: RCCallErrorCode;
126
+ }>;
127
+ /**
128
+ * 获得本地视频
129
+ */
130
+ private _getLocalVideoTracks;
131
+ /**
132
+ * 获得本地音频
133
+ */
134
+ private _getLocalAudioTracks;
135
+ /**
136
+ * 把通话的MediaType升级到音视频
137
+ */
138
+ private _setMediaTypeToAudioAndVideo;
139
+ /**
140
+ * 把通话的MediaType降级到音频
141
+ * @param isSendMesssage 是否需要发消息, 默认发消息
142
+ */
143
+ private _setMediaTypeToAudio;
144
+ /**
145
+ * 通话降级,目前需求只做通话降级,音视频可以降级为音频,音频不能升到音视频, 发消息成功才算降级成功
146
+ *
147
+ */
148
+ descendAbility(): Promise<{
149
+ code: RCCallErrorCode;
150
+ }>;
151
+ /**
152
+ * 禁用视频track
153
+ */
154
+ disableVideoTrack(): Promise<{
155
+ code: RCCallErrorCode;
156
+ }>;
157
+ /**
158
+ * 启用视频track
159
+ */
160
+ enableVideoTrack(): Promise<{
161
+ code: RCCallErrorCode;
162
+ }>;
163
+ /**
164
+ * 禁用音频track
165
+ */
166
+ disableAudioTrack(): Promise<void>;
167
+ /**
168
+ * 启用音频track
169
+ */
170
+ enableAudioTrack(): Promise<void>;
171
+ /**
172
+ * 销毁本地流
173
+ */
174
+ private _destroyTracks;
175
+ /**
176
+ * 向外抛出本地流
177
+ */
178
+ private _notifyTrackReady;
179
+ /**
180
+ * 房间上注册事件
181
+ */
182
+ private _registerRoomEventListener;
183
+ /**
184
+ * 注册房间质量数据监听器
185
+ */
186
+ private _registerReportListener;
187
+ /**
188
+ * 通话唯一标识
189
+ */
190
+ getSessionId(): string;
191
+ /**
192
+ * 获取房间当前会话 Id,当房间内已无成员时房间会回收,重新加入时 sessionId 将更新,(用户录制资源用的)
193
+ */
194
+ getRTCSessionId(): string | null;
195
+ /**
196
+ * 目标 ID,单呼对方人员 Id, 群呼群组 Id
197
+ */
198
+ getTargetId(): string;
199
+ /**
200
+ * 获取会话类型
201
+ */
202
+ getConversationType(): ConversationType;
203
+ /**
204
+ * 组织 ID
205
+ */
206
+ getChannelId(): string;
207
+ /**
208
+ * 房间人员列表,不包含本端信息
209
+ */
210
+ getRemoteUsers(): IUserData[];
211
+ /**
212
+ * 房间人员列表,不包含本端信息
213
+ */
214
+ getUsers(): IUserData[];
215
+ /**
216
+ * 获取人员状态
217
+ */
218
+ getUserState(userId: string): RCCallUserState;
219
+ /**
220
+ * 获取session状态
221
+ */
222
+ getState(): RCCallSessionState;
223
+ /**
224
+ * 获得会话发起者id
225
+ */
226
+ getCallerId(): string;
227
+ /**
228
+ * 获得mediaType
229
+ */
230
+ getMediaType(): RCCallMediaType;
231
+ }
232
+ //# sourceMappingURL=RCCallSession.d.ts.map
@@ -0,0 +1,14 @@
1
+ /**
2
+ * 产生session的场景
3
+ */
4
+ export declare enum ProduceTypes {
5
+ /**
6
+ * 主叫
7
+ */
8
+ CALLER = 1,
9
+ /**
10
+ * 被叫
11
+ */
12
+ CALLEE = 2
13
+ }
14
+ //# sourceMappingURL=enums.d.ts.map
@@ -0,0 +1,4 @@
1
+ import { EventEmitter } from './utils';
2
+ declare const _default: EventEmitter;
3
+ export default _default;
4
+ //# sourceMappingURL=eventEmitter.d.ts.map
@@ -0,0 +1,2 @@
1
+ export declare const timerSetTimeout: (func: Function, timeout: number) => number;
2
+ //# sourceMappingURL=helper.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  /*
2
- * RCCall - v5.0.7
3
- * CommitId - 3dcd9a3cf924b311e2169155be169d960765c55e
4
- * Thu Jan 13 2022 15:41:47 GMT+0800 (China Standard Time)
2
+ * RCCall - v5.0.10
3
+ * CommitId - 010761df892b669845b52207e7c1c3829782d100
4
+ * Mon Aug 08 2022 16:11:54 GMT+0800 (China Standard Time)
5
5
  * ©2020 RongCloud, Inc. All rights reserved.
6
6
  */
7
7
  import { ConversationType, RTCJoinType, LogLevel, PluginContext, IRuntime, IRTCJoinedInfo, IPluginGenerator } from '@rongcloud/engine';
8
8
  import { RCCallStateMachine, RCCallErrorCode, IInviteOptions, RCCallMediaType, IUserData, RCCallUserState, RCCallSessionState, IEndSummary, IOfflineRecord, RCCallLanguage, RCCallEndReason, IInvitedUsers } from '@rongcloud/plugin-call-engine';
9
9
  export { IEndSummary, IInvitedUsers, IOfflineRecord, ISenderInfo, RCCallEndReason, RCCallErrorCode, RCCallLanguage, RCCallMediaType, RCCallSessionState, RCCallUserState } from '@rongcloud/plugin-call-engine';
10
10
  import { RCRTCClient, IMicphoneAudioProfile, RCTrack, RCRTCCode, IRCRTCStateReport, RCRTCPingResult, RCLocalTrack, ICameraVideoProfile } from '@rongcloud/plugin-rtc';
11
+ export { IRCRTCStateReport } from '@rongcloud/plugin-rtc';
11
12
 
12
13
  /**
13
14
  * 产生session的场景
@@ -48,6 +49,10 @@ declare class RCCallSession {
48
49
  * RTC订阅、发布重试的次数
49
50
  */
50
51
  private readonly _RETRYCOUNT;
52
+ /**
53
+ * 加入房间定时器
54
+ */
55
+ private joinRoomTimer;
51
56
  constructor(
52
57
  /**
53
58
  * 状态机实例
@@ -225,6 +230,10 @@ declare class RCCallSession {
225
230
  * 房间人员列表,不包含本端信息
226
231
  */
227
232
  getRemoteUsers(): IUserData[];
233
+ /**
234
+ * 房间人员列表,不包含本端信息
235
+ */
236
+ getUsers(): IUserData[];
228
237
  /**
229
238
  * 获取人员状态
230
239
  */
@@ -415,6 +424,20 @@ interface IRCCallSessionOptions {
415
424
  */
416
425
  produceType?: ProduceTypes;
417
426
  }
427
+ interface IRCTrackBitrate {
428
+ /**
429
+ * 最大码率
430
+ */
431
+ max: number;
432
+ /**
433
+ * 最小码率
434
+ */
435
+ min: number;
436
+ /**
437
+ * 上行起始码率
438
+ */
439
+ start?: number;
440
+ }
418
441
  /**
419
442
  * RCCallClient call方法的传参
420
443
  */
@@ -451,6 +474,13 @@ interface IRCCallParams {
451
474
  * 对方显示的通知内容
452
475
  */
453
476
  pushContent?: string;
477
+ /**
478
+ * 设置码率
479
+ */
480
+ bitrate?: {
481
+ video?: IRCTrackBitrate;
482
+ audio?: number;
483
+ };
454
484
  }
455
485
  interface IMediaStreamConstraints {
456
486
  video?: ICameraVideoProfile;
@@ -487,6 +517,13 @@ interface IRCCallInGroupParams {
487
517
  * 对方显示的通知内容
488
518
  */
489
519
  pushContent?: string;
520
+ /**
521
+ * 设置码率
522
+ */
523
+ bitrate?: {
524
+ video?: IRCTrackBitrate;
525
+ audio?: number;
526
+ };
490
527
  }
491
528
  interface IDeviceChangeParams {
492
529
  audio?: IMicphoneAudioProfile;
@@ -543,8 +580,10 @@ declare class RCCallClient {
543
580
  * @param params.extra 消息扩展信息
544
581
  * @param params.pushTitle 通知的标题
545
582
  * @param params.pushContent 通知的内容
583
+ * @param params.bitrate 需要设置的码率参数
584
+ *
546
585
  */
547
- call({ targetId, mediaType, listener, constraints, channelId, extra, pushTitle, pushContent }: IRCCallParams): Promise<{
586
+ call({ targetId, mediaType, listener, constraints, channelId, extra, pushTitle, pushContent, bitrate }: IRCCallParams): Promise<{
548
587
  code: RCCallErrorCode;
549
588
  session?: RCCallSession;
550
589
  }>;
@@ -559,8 +598,9 @@ declare class RCCallClient {
559
598
  * @param params.extra 消息扩展信息 可选
560
599
  * @param params.pushTitle 通知的标题
561
600
  * @param params.pushContent 通知的内容
601
+ * @param params.bitrate 需要设置的码率参数
562
602
  */
563
- callInGroup({ targetId, userIds, mediaType, listener, constraints, channelId, extra, pushTitle, pushContent }: IRCCallInGroupParams): Promise<{
603
+ callInGroup({ targetId, userIds, mediaType, listener, constraints, channelId, extra, pushTitle, pushContent, bitrate }: IRCCallInGroupParams): Promise<{
564
604
  code: RCCallErrorCode;
565
605
  session?: RCCallSession;
566
606
  }>;
@@ -580,6 +620,10 @@ declare class RCCallClient {
580
620
  code: RCCallErrorCode;
581
621
  data?: IRTCJoinedInfo[];
582
622
  }>;
623
+ /**
624
+ * 销毁本地状态机(应对本地状态机异常无法重新建立通话)
625
+ */
626
+ destroyStateMachine(): Promise<void>;
583
627
  }
584
628
 
585
629
  declare const installer: IPluginGenerator<RCCallClient, IRCCallInitOptions>;
package/dist/index.esm.js CHANGED
@@ -12,4 +12,4 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
12
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
13
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
14
  PERFORMANCE OF THIS SOFTWARE.
15
- ***************************************************************************** */function _(e,t,o,i){return new(o||(o=Promise))((function(s,n){function r(e){try{a(i.next(e))}catch(e){n(e)}}function l(e){try{a(i.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?s(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(r,l)}a((i=i.apply(e,t||[])).next())}))}var R;!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(R||(R={}));var p=new class{constructor(){this.list={}}on(e,t){return(this.list[e]||(this.list[e]=[])).push(t),this}once(e,t){const o=i=>{this.off(e,o),t.call(this,i)};o.fun=t,this.on(e,o)}off(e,t){const o=this.list[e];if(!o)return!1;if(t){let e;for(let i=0,s=o.length;i<s;i++)if(e=o[i],e===t||e.fun===t){o.splice(i,1);break}}else o&&(o.length=0)}emit(e,t){const o=[...this.list[e]];if(!o||0===o.length)return!1;o.forEach((e=>{e.call(this,t)}))}};const f=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 o=Object.keys(e),i=[];return["rtcClient","onSession","onSessionClose"].forEach((e=>{o.includes(e)||i.push(e)})),i.length?{result:!1,msg:`Initialization missing parameter -> "${i.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||(s=e.joinType,Object.values(l).includes(s))?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).includes(e)}(e.lang)?void 0===e.logLevel||function(e){return Object.values(a).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 s},g=e=>{if(!e)return{result:!1,msg:"missing parameter -> listener"};if("object"!=typeof e)return{result:!1,msg:"listener must be an object"};const t=Object.keys(e),o=[];return["onRinging","onAccept","onHungup","onTrackReady"].forEach((e=>{t.includes(e)||o.push(e)})),o.length?{result:!1,msg:`missing parameter -> "${o.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}},S=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},m=t=>t===e.AUDIO||t===e.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},y=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},T=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},E=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushContent' parameter must be of type 'string'"},I=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[]'"};class b{constructor(t,s,n={}){this._stateMachine=t,this._rtcClient=s,this._options=n,this._listener=null,this._RETRYCOUNT=2,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:t})=>{C.info(`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${t}`)},onStateChange:e=>_(this,void 0,void 0,(function*(){const{state:t,reason:s}=e;if(C.info(`[RCCallSession onStateChange] : state->${t} reason->${s}`),t===o.KEEPING){const e=this._stateMachine.getCallId();C.info(`[RCCallSession onStateChange] roomId: ${e}`);try{yield this._joinRoom(e)}catch(t){this._exceptionClose(i.NETWORK_ERROR),C.error(`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${e}`),console.error(t)}}else if(t===o.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void p.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),C.info("[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{C.info(`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){C.error("[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{C.info(`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){C.error("[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,t)=>{C.info(`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${t}`);try{this._listener.onHungup(e,t,this)}catch(e){C.error("[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:t})=>{C.info(`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,t,this)}catch(e){C.error("[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:t,mediaType:o})=>{C.info(`[RCCallSession onMediaModify]sender: sender.userId -> ${t.userId} mediaType: ${o}`),o===e.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(t,o,this)}catch(e){C.error("[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}}})}_joinRoom(e){return _(this,void 0,void 0,(function*(){try{const{code:t,room:o}=yield this._rtcClient.joinRTCRoom(e,this._options.joinType);if(t!==u.SUCCESS)return t===u.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(i.SERVICE_NOT_OPENED),t===u.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(i.OTHER_CLIENT_IN_CALL):this._exceptionClose(i.NETWORK_ERROR),C.info(`[RCCallClient _joinRoom] join room failed: roomId -> ${e} RCRTCCode -> ${t}`),{code:s.JOIN_ROOM_ERROR};this._room=o}catch(t){return this._exceptionClose(i.NETWORK_ERROR),C.error(`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${e}`),console.error(t),{code:s.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(t){return this._exceptionClose(i.SUBSCRIBE_ERROR),C.error(`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${e}`),console.error(t),{code:s.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(t){return this._exceptionClose(i.PUBLISH_ERROR),C.error(`[RCCallSession _joinRoom] _publish Exception roomId -> ${e}`),console.error(t),{code:s.JOIN_ROOM_ERROR}}return{code:s.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return _(this,void 0,void 0,(function*(){const e=this._room.getRemoteTracks();if(e.length){const{code:t}=yield this._subscribeRetry(e,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);t!==u.SUCCESS&&(this._exceptionClose(i.SUBSCRIBE_ERROR),C.error(`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${t}`))}}))}_subscribeRetry(e,t=!1,o=0){return _(this,void 0,void 0,(function*(){const{code:i}=yield this._room.subscribe(e);if(i!==u.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(i,this)}catch(e){C.error("[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!t)return{code:i};if(o>0)return o--,this._subscribeRetry(e,t,o)}return{code:i}}))}_publish(){return _(this,void 0,void 0,(function*(){const e=this._options.localTracks,{code:t}=yield this._publishRetry(e,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(t!==u.SUCCESS)return this._exceptionClose(i.PUBLISH_ERROR),void C.info(`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${t}`);this._options.produceType===R.CALLEE&&this._notifyTrackReady(e)}))}_publishRetry(e,t=!1,o=0){return _(this,void 0,void 0,(function*(){const{code:i}=yield this._room.publish(e);if(i!==u.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(i,this)}catch(e){C.error("[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!t)return{code:i};if(o>0)return o--,this._publishRetry(e,t,o)}return{code:i}}))}_leaveRoom(){return _(this,void 0,void 0,(function*(){try{const{code:e}=yield this._rtcClient.leaveRoom(this._room);C.info("[RCCallSession _leaveRoom] Successfully exited the room")}catch(e){C.error("[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();p.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const t=g(e);if(!t.result)throw new Error(`[RCCallSession registerSessionListener] ${t.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(t,o){return _(this,void 0,void 0,(function*(){if(t===e.AUDIO){const{code:e,track:t}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o&&o.audio&&Object.assign({},o.audio));return e!==u.SUCCESS?(C.error(`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_TRACK_ERROR}):(C.info("[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:s.SUCCESS,tracks:[t]})}{const{code:e,tracks:t}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",o&&Object.assign({},o));return e!==u.SUCCESS?(C.error(`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(C.info("[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:s.SUCCESS,tracks:t})}}))}_getLocalTrack(t,o){return _(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&t===e.AUDIO_VIDEO){const{code:t,tracks:n}=yield this._getLocalTrackCore(e.AUDIO_VIDEO,o);if(t!==s.SUCCESS){const{code:t,tracks:n}=yield this._getLocalTrackCore(e.AUDIO,o);return t!==s.SUCCESS?(this._exceptionClose(i.GET_MEDIA_RESOURCES_ERROR),{code:t}):{code:t,tracks:n}}return{code:t,tracks:n}}{const{code:e,tracks:n}=yield this._getLocalTrackCore(t,o);return e!==s.SUCCESS?(this._exceptionClose(i.GET_MEDIA_RESOURCES_ERROR),{code:e}):{code:e,tracks:n}}}))}changeAudioDevice(e){return _(this,void 0,void 0,(function*(){const t=[],o=[],{code:i,track:n}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",e);if(i!==u.SUCCESS)return C.error(`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${i}`),{code:s.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||o.push(e)})),t.push(n),o.push(n),this._options.localTracks=o,this._notifyTrackReady(t),this._room){const{code:e}=yield this._room.publish(t);if(e!==u.SUCCESS)return{code:s.AUDIO_PUBLISH_ERROR}}return{code:s.SUCCESS}}))}invite(e,t={}){return _(this,void 0,void 0,(function*(){const{extra:o="",pushTitle:i="",pushContent:s=""}=t,n=[I(e),y(o),T(i),E(s)],r=[];if(!n.every((e=>(!e.result&&r.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${r.join("\n")}`);const{code:l}=yield this._stateMachine.invite(e,{extra:o,pushTitle:i,pushContent:s});return{code:l}}))}accept(e){return _(this,void 0,void 0,(function*(){const t=(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&&(t=e.video.frameRate,!["FPS_10","FPS_15","FPS_24","FPS_30"].includes(t))?{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&&!function(e){return["W176_H132","W176_H144","W256_H144","W320_H180","W240_H240","W320_H240","W480_H360","W640_H360","W480_H480","W640_H480","W720_H480","W1280_H720","W1920_H1080"].includes(e)}(e.video.resolution)?{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 t})(e);if(!t.result)throw new Error(`[RCCallSession accept] ${t.msg}`);p.emit("hungupOtherSession",{session:this});const o=this._stateMachine.getMediaType(),{code:i,tracks:n}=yield this._getLocalTrack(o,e);if(i!==s.SUCCESS)return{code:i};this._options.localTracks=n;const{code:r}=yield this._stateMachine.accept();return r!==s.SUCCESS?(C.error(`[RCCallSession accept]Send accept message failed -> code: ${r}`),{code:r}):{code:r}}))}hungup(){return _(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(e){return _(this,void 0,void 0,(function*(){const{code:t}=yield this._stateMachine.changeMediaType(e);return t!==s.SUCCESS&&C.error(`[RCCallSession _changeMediaType] change media type fail code-> ${t}`),{code:t}}))}_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 _(this,void 0,void 0,(function*(){const{code:t,track:o}=yield this._rtcClient.createCameraVideoTrack();if(t!==u.SUCCESS)return{code:s.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:i}=yield this._room.publish([o]);i===u.SUCCESS?(this._notifyTrackReady([o]),this._changeMediaType(e.AUDIO_VIDEO)):C.error(`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${t}`)}))}_setMediaTypeToAudio(){return _(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(e.length){e.forEach((e=>{e.mute()}));const{code:t}=yield this._room.unpublish(e);t!==u.SUCCESS&&C.error(`[RCCallSession disableVideo] unpublish failed -> ${t}`),this._destroyTracks(e)}}))}descendAbility(){return _(this,void 0,void 0,(function*(){const{code:t}=yield this._changeMediaType(e.AUDIO);return t===s.SUCCESS&&this._setMediaTypeToAudio(),{code:t}}))}disableVideoTrack(){return _(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(!e.length)return C.error(`[RCCallSession disableVideoTrack] Room missing video track -> ${s.MISSING_VIDEO_TRACK_ERROR}`),{code:s.MISSING_VIDEO_TRACK_ERROR};if(e.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:s.SUCCESS};const{code:t}=yield this._room.unpublish(e);return t!==u.SUCCESS?(C.error(`[RCCallSession disableVideo] unpublish failed -> ${t}`),{code:s.UNPUBLISH_VIDEO_ERROR}):(e.forEach((e=>{e.destroy()})),{code:s.SUCCESS})}))}enableVideoTrack(){return _(this,void 0,void 0,(function*(){if(!this._options.isOffCameraWhenVideoDisable){const e=this._getLocalVideoTracks();return e.length?(e.forEach((e=>{e.unmute()})),{code:s.SUCCESS}):(C.error(`[RCCallSession EnableVideoTrack] Room missing video track -> ${s.MISSING_VIDEO_TRACK_ERROR}`),{code:s.MISSING_VIDEO_TRACK_ERROR})}const{code:e,track:t}=yield this._rtcClient.createCameraVideoTrack();if(e!==u.SUCCESS)return C.error(`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${e}`),{code:s.GET_LOCAL_VIDEO_TRACK_ERROR};const o=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():o.push(e)})),o.push(t),this._options.localTracks=o,t.mute();const{code:i}=yield this._room.publish([t]);return i!==u.SUCCESS?(C.error(`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${e}`),{code:s.VIDEO_PUBLISH_ERROR}):(t.unmute(),this._notifyTrackReady([t]),{code:s.SUCCESS})}))}disableAudioTrack(){return _(this,void 0,void 0,(function*(){this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return _(this,void 0,void 0,(function*(){this._getLocalAudioTracks().forEach((e=>{e.unmute()}))}))}_destroyTracks(e){e.forEach((e=>{e.destroy()}))}_notifyTrackReady(e){e.forEach((e=>{try{this._listener.onTrackReady(e,this)}catch(e){C.error("[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(e,t)=>{const o=this._rtcClient.getCurrentId();this._stateMachine.userLeave([o]),e?(t===h.SERVER_KICK&&this._exceptionClose(i.KICKED_BY_SERVER),t===h.OTHER_KICK&&this._exceptionClose(i.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(i.NETWORK_ERROR)},onMessageReceive(e,t,o,i){},onRoomAttributeChange(e,t){},onAudioMuteChange:e=>{C.info(`[RCCallSession onAudioMuteChange] userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const t={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"audio",trackId:e.getTrackId()};try{this._listener.onAudioMuteChange(t,this)}catch(e){C.error("[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{C.info(`[RCCallSession onVideoMuteChange]userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const t={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"video",trackId:e.getTrackId()};try{this._listener.onVideoMuteChange(t,this)}catch(e){C.error("[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>_(this,void 0,void 0,(function*(){if(this._room){const{code:t}=yield this._room.subscribe(e);t!==u.SUCCESS&&C.error(`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${t}`)}})),onTrackUnpublish:e=>{},onTrackReady:t=>{this._stateMachine.getMediaType()===e.AUDIO&&t.isVideoTrack()||this._notifyTrackReady([t])},onUserJoin:e=>{this._stateMachine.userJoin(e)},onUserLeave:e=>{C.info(`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{C.info(`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){C.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){C.error("[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){C.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()}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()}}c.add("plugin-call","5.0.7"),c.validEngine(">=4.5.2")||C.error(`The current engine version '${c.getInfo().engine}' error,plugin-call required engine version at least '>=4.5.2'.`);class v{constructor(e,o,i){this._context=e,this._runtime=o,this._sessionList=[],this._rtcClient=i.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:l.COEXIST,isAllowDemotionGetStream:!1,lang:t.ZH},i),this._callEngine=new n(this._context,o,C,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||t.ZH}),p.on("sessionClose",(({session:e,summaryInfo:t})=>{this._removeSession(e);try{this._options.onSessionClose(e,t)}catch(e){C.error("[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),p.on("hungupOtherSession",(({session:e})=>{const t=e.getSessionId();C.info(`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${t}`),C.info(`[RCCallClient hungupOtherSession] sessionList ->${this._sessionList.map((e=>e.getSessionId())).join(",")}`);let o=0;for(;this._sessionList.length>1;)this._sessionList[o].getSessionId()!==t?(this._sessionList[o].hungup(),this._sessionList.splice(o,1)):o++;C.info(`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e,t){C.info("[RCCallClient _onInvite] Received invite message");const o=new b(e,this._rtcClient,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:R.CALLEE});C.info("[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(o);try{this._options.onSession(o,t)}catch(e){C.error("[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!o._listener)throw C.error("[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=g(o._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){C.error("[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),C.info("[RCCallClient registerUserInfo] successfully register user info data")}call({targetId:t,mediaType:o=e.AUDIO,listener:i,constraints:n,channelId:r="",extra:l="",pushTitle:a="",pushContent:c=""}){return _(this,void 0,void 0,(function*(){C.info(`[RCCallClient call] extra->${l} pushTitle->${a} pushContent->${c}`);const e=[S(t),m(o),g(i),y(l),T(a),E(c)],d=[];if(!e.every((e=>(!e.result&&d.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${d.join("\n")}`);let u=[];const{code:h,tracks:_}=yield this._getLocalTrack(o,n);if(h!==s.SUCCESS)return{code:h};u=_,u.forEach((e=>{i.onTrackReady(e)}));const{code:p,stateMachine:f}=yield this._callEngine.call(r,t,o,l,a,c);if(p===s.SUCCESS&&f){C.info("[RCCallClient call] successfully created state machine");const e=new b(f,this._rtcClient,{localTracks:u,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:R.CALLER});return e.registerSessionListener(i),this._sessionList.push(e),C.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:p,session:e}}return C.error(`[RCCallClient call] call failed code ->: ${p}`),u.forEach((e=>{e.mute(),e.destroy()})),{code:p}}))}callInGroup({targetId:t,userIds:o,mediaType:i=e.AUDIO,listener:n,constraints:r,channelId:l="",extra:a="",pushTitle:c="",pushContent:d=""}){return _(this,void 0,void 0,(function*(){const e=[S(t),I(o),m(i),g(n),y(a),T(c),E(d)],u=[];if(!e.every((e=>(!e.result&&u.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${u.join("\n")}`);let h=[];const{code:_,tracks:p}=yield this._getLocalTrack(i,r);if(_!==s.SUCCESS)return{code:_};h=p,h.forEach((e=>{n.onTrackReady(e)}));const{code:f,stateMachine:v}=yield this._callEngine.callInGroup(l,t,i,o,a,c,d);if(f===s.SUCCESS&&v){C.info("[RCCallClient callInGroup] successfully created state machine");const e=new b(v,this._rtcClient,{localTracks:h,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:R.CALLER});return e.registerSessionListener(n),this._sessionList.push(e),C.info(`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:f,session:e}}return C.info(`[RCCallClient callInGroup] callInGroup failed code -> ${f}`),h.forEach((e=>{e.mute(),e.destroy()})),{code:f}}))}_getLocalTrackCore(t,o){return _(this,void 0,void 0,(function*(){if(t===e.AUDIO){const{code:e,track:t}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o&&o.audio&&Object.assign({},o.audio));return e!==u.SUCCESS?(C.error(`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_TRACK_ERROR}):(C.info("[RCCallClient _getTrack] successfully get Audio local tracks"),{code:s.SUCCESS,tracks:[t]})}{const{code:e,tracks:t}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",o&&Object.assign({},o));return e!==u.SUCCESS?(C.error(`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(C.info("[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:s.SUCCESS,tracks:t})}}))}_getLocalTrack(t,o){return _(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&t===e.AUDIO_VIDEO){const{code:t,tracks:i}=yield this._getLocalTrackCore(e.AUDIO_VIDEO,o);if(t!==s.SUCCESS){const{code:t,tracks:i}=yield this._getLocalTrackCore(e.AUDIO,o);return t!==s.SUCCESS?{code:t}:{code:t,tracks:i}}return{code:t,tracks:i}}{const{code:e,tracks:i}=yield this._getLocalTrackCore(t,o);return e!==s.SUCCESS?{code:e}:{code:e,tracks:i}}}))}_removeSession(e){const t=e.getSessionId();this._sessionList=this._sessionList.filter((e=>e.getSessionId()!==t))}getJoinedRoomInfo(){return _(this,void 0,void 0,(function*(){const{code:e,data:t}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return e!==d.SUCCESS?(C.error("getJoinedUserInfo error",e),{code:s.QUERY_JOINED_USER_INFO_ERROR}):{code:s.SUCCESS,data:t}}))}}const O={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,t,o){const i=f(o);if(!i.result)throw new Error(`[RCCallLib installer steup]${i.msg}`);return C.setLogLevel(o.logLevel),C.setLogStdout(o.logStdout),C.warn("RCCall Version: 5.0.7, Commit: 3dcd9a3cf924b311e2169155be169d960765c55e"),new v(e,t,o)}};export{v as RCCallClient,b as RCCallSession,O as installer};
15
+ ***************************************************************************** */function _(e,t,o,i){return new(o||(o=Promise))((function(s,n){function r(e){try{a(i.next(e))}catch(e){n(e)}}function l(e){try{a(i.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?s(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(r,l)}a((i=i.apply(e,t||[])).next())}))}var R;!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(R||(R={}));var p=new class{constructor(){this.list={}}on(e,t){return(this.list[e]||(this.list[e]=[])).push(t),this}once(e,t){const o=i=>{this.off(e,o),t.call(this,i)};o.fun=t,this.on(e,o)}off(e,t){const o=this.list[e];if(!o)return!1;if(t){let e;for(let i=0,s=o.length;i<s;i++)if(e=o[i],e===t||e.fun===t){o.splice(i,1);break}}else o&&(o.length=0)}emit(e,t){const o=[...this.list[e]];if(!o||0===o.length)return!1;o.forEach((e=>{e.call(this,t)}))}};const f=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 o=Object.keys(e),i=[];return["rtcClient","onSession","onSessionClose"].forEach((e=>{o.includes(e)||i.push(e)})),i.length?{result:!1,msg:`Initialization missing parameter -> "${i.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||(s=e.joinType,Object.values(l).includes(s))?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).includes(e)}(e.lang)?void 0===e.logLevel||function(e){return Object.values(a).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 s},g=e=>{if(!e)return{result:!1,msg:"missing parameter -> listener"};if("object"!=typeof e)return{result:!1,msg:"listener must be an object"};const t=Object.keys(e),o=[];return["onRinging","onAccept","onHungup","onTrackReady"].forEach((e=>{t.includes(e)||o.push(e)})),o.length?{result:!1,msg:`missing parameter -> "${o.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}},m=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},S=t=>t===e.AUDIO||t===e.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},y=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},T=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},E=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushContent' parameter must be of type 'string'"},v=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[]'"};class I{constructor(e,t){this._timerId=0,this._startTime=0,e&&(this._timerId=((e,t)=>setTimeout(e,t))((()=>{e()}),t)),this._startTime=Date.now()}stop(){clearTimeout(this._timerId);const e=Date.now();let t=e-this._startTime;return 0===this._startTime&&(t=0),{startTime:this._startTime,endTime:e,duration:t}}reset(){this._startTime=0}}class b{constructor(t,s,n={}){this._stateMachine=t,this._rtcClient=s,this._options=n,this._listener=null,this._RETRYCOUNT=2,this.joinRoomTimer=null,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:t})=>{C.info(`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${t}`)},onStateChange:e=>_(this,void 0,void 0,(function*(){const{state:t,reason:s}=e;if(C.info(`[RCCallSession onStateChange] : state->${t} reason->${s}`),t===o.KEEPING){const e=this._stateMachine.getCallId();C.info(`[RCCallSession onStateChange] roomId: ${e}`);try{yield this._joinRoom(e)}catch(t){this._exceptionClose(i.NETWORK_ERROR),C.error(`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${e}`),console.error(t)}}else if(t===o.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void p.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),C.info("[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{C.info(`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){C.error("[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{C.info(`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){C.error("[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,t)=>{C.info(`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${t}`);try{this._listener.onHungup(e,t,this)}catch(e){C.error("[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:t})=>{C.info(`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,t,this)}catch(e){C.error("[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:t,mediaType:o})=>{C.info(`[RCCallSession onMediaModify]sender: sender.userId -> ${t.userId} mediaType: ${o}`),o===e.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(t,o,this)}catch(e){C.error("[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}}})}_joinRoom(e){return _(this,void 0,void 0,(function*(){try{const{code:t,userIds:o,room:n}=yield this._rtcClient.joinRTCRoom(e,this._options.joinType);if(t!==u.SUCCESS)return t===u.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(i.SERVICE_NOT_OPENED),t===u.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(i.OTHER_CLIENT_IN_CALL):this._exceptionClose(i.NETWORK_ERROR),C.info(`[RCCallClient _joinRoom] join room failed: roomId -> ${e} RCRTCCode -> ${t}`),{code:s.JOIN_ROOM_ERROR};o.length<1&&(this.joinRoomTimer=new I((()=>{this._exceptionClose(i.REMOTE_NETWORK_ERROR)}),6e4)),this._room=n}catch(t){return this._exceptionClose(i.NETWORK_ERROR),C.error(`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${e}`),console.error(t),{code:s.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(t){return this._exceptionClose(i.SUBSCRIBE_ERROR),C.error(`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${e}`),console.error(t),{code:s.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(t){return this._exceptionClose(i.PUBLISH_ERROR),C.error(`[RCCallSession _joinRoom] _publish Exception roomId -> ${e}`),console.error(t),{code:s.JOIN_ROOM_ERROR}}return{code:s.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return _(this,void 0,void 0,(function*(){const e=this._room.getRemoteTracks();if(e.length){const{code:t}=yield this._subscribeRetry(e,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);t!==u.SUCCESS&&(this._exceptionClose(i.SUBSCRIBE_ERROR),C.error(`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${t}`))}}))}_subscribeRetry(e,t=!1,o=0){return _(this,void 0,void 0,(function*(){const{code:i}=yield this._room.subscribe(e);if(i!==u.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(i,this)}catch(e){C.error("[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!t)return{code:i};if(o>0)return o--,this._subscribeRetry(e,t,o)}return{code:i}}))}_publish(){return _(this,void 0,void 0,(function*(){const e=this._options.localTracks,{code:t}=yield this._publishRetry(e,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(t!==u.SUCCESS)return this._exceptionClose(i.PUBLISH_ERROR),void C.info(`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${t}`);this._options.produceType===R.CALLEE&&this._notifyTrackReady(e)}))}_publishRetry(e,t=!1,o=0){return _(this,void 0,void 0,(function*(){const{code:i}=yield this._room.publish(e);if(i!==u.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(i,this)}catch(e){C.error("[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!t)return{code:i};if(o>0)return o--,this._publishRetry(e,t,o)}return{code:i}}))}_leaveRoom(){return _(this,void 0,void 0,(function*(){try{const{code:e}=yield this._rtcClient.leaveRoom(this._room);C.info("[RCCallSession _leaveRoom] Successfully exited the room")}catch(e){C.error("[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();p.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const t=g(e);if(!t.result)throw new Error(`[RCCallSession registerSessionListener] ${t.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(t,o){return _(this,void 0,void 0,(function*(){if(t===e.AUDIO){const{code:e,track:t}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o&&o.audio&&Object.assign({},o.audio));return e!==u.SUCCESS?(C.error(`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_TRACK_ERROR}):(C.info("[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:s.SUCCESS,tracks:[t]})}{const{code:e,tracks:t}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",o&&Object.assign({},o));return e!==u.SUCCESS?(C.error(`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(C.info("[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:s.SUCCESS,tracks:t})}}))}_getLocalTrack(t,o){return _(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&t===e.AUDIO_VIDEO){const{code:t,tracks:n}=yield this._getLocalTrackCore(e.AUDIO_VIDEO,o);if(t!==s.SUCCESS){const{code:t,tracks:n}=yield this._getLocalTrackCore(e.AUDIO,o);return t!==s.SUCCESS?(this._exceptionClose(i.GET_MEDIA_RESOURCES_ERROR),{code:t}):{code:t,tracks:n}}return{code:t,tracks:n}}{const{code:e,tracks:n}=yield this._getLocalTrackCore(t,o);return e!==s.SUCCESS?(this._exceptionClose(i.GET_MEDIA_RESOURCES_ERROR),{code:e}):{code:e,tracks:n}}}))}changeAudioDevice(e){return _(this,void 0,void 0,(function*(){const t=[],o=[],{code:i,track:n}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",e);if(i!==u.SUCCESS)return C.error(`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${i}`),{code:s.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||o.push(e)})),t.push(n),o.push(n),this._options.localTracks=o,this._notifyTrackReady(t),this._room){const{code:e}=yield this._room.publish(t);if(e!==u.SUCCESS)return{code:s.AUDIO_PUBLISH_ERROR}}return{code:s.SUCCESS}}))}invite(e,t={}){return _(this,void 0,void 0,(function*(){const{extra:o="",pushTitle:i="",pushContent:s=""}=t,n=[v(e),y(o),T(i),E(s)],r=[];if(!n.every((e=>(!e.result&&r.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${r.join("\n")}`);const{code:l}=yield this._stateMachine.invite(e,{extra:o,pushTitle:i,pushContent:s});return{code:l}}))}accept(e){return _(this,void 0,void 0,(function*(){const t=(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&&(t=e.video.frameRate,!["FPS_10","FPS_15","FPS_24","FPS_30"].includes(t))?{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&&!function(e){return["W176_H132","W176_H144","W256_H144","W320_H180","W240_H240","W320_H240","W480_H360","W640_H360","W480_H480","W640_H480","W720_H480","W1280_H720","W1920_H1080"].includes(e)}(e.video.resolution)?{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 t})(e);if(!t.result)throw new Error(`[RCCallSession accept] ${t.msg}`);p.emit("hungupOtherSession",{session:this});const o=this._stateMachine.getMediaType(),{code:i,tracks:n}=yield this._getLocalTrack(o,e);if(i!==s.SUCCESS)return{code:i};this._options.localTracks=n;const{code:r}=yield this._stateMachine.accept();return r!==s.SUCCESS?(C.error(`[RCCallSession accept]Send accept message failed -> code: ${r}`),{code:r}):{code:r}}))}hungup(){return _(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(e){return _(this,void 0,void 0,(function*(){const{code:t}=yield this._stateMachine.changeMediaType(e);return t!==s.SUCCESS&&C.error(`[RCCallSession _changeMediaType] change media type fail code-> ${t}`),{code:t}}))}_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 _(this,void 0,void 0,(function*(){const{code:t,track:o}=yield this._rtcClient.createCameraVideoTrack();if(t!==u.SUCCESS)return{code:s.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:i}=yield this._room.publish([o]);i===u.SUCCESS?(this._notifyTrackReady([o]),this._changeMediaType(e.AUDIO_VIDEO)):C.error(`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${t}`)}))}_setMediaTypeToAudio(){return _(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(e.length){e.forEach((e=>{e.mute()}));const{code:t}=yield this._room.unpublish(e);t!==u.SUCCESS&&C.error(`[RCCallSession disableVideo] unpublish failed -> ${t}`),this._destroyTracks(e)}}))}descendAbility(){return _(this,void 0,void 0,(function*(){const{code:t}=yield this._changeMediaType(e.AUDIO);return t===s.SUCCESS&&this._setMediaTypeToAudio(),{code:t}}))}disableVideoTrack(){return _(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(!e.length)return C.error(`[RCCallSession disableVideoTrack] Room missing video track -> ${s.MISSING_VIDEO_TRACK_ERROR}`),{code:s.MISSING_VIDEO_TRACK_ERROR};if(e.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:s.SUCCESS};const{code:t}=yield this._room.unpublish(e);return t!==u.SUCCESS?(C.error(`[RCCallSession disableVideo] unpublish failed -> ${t}`),{code:s.UNPUBLISH_VIDEO_ERROR}):(e.forEach((e=>{e.destroy()})),{code:s.SUCCESS})}))}enableVideoTrack(){return _(this,void 0,void 0,(function*(){if(!this._options.isOffCameraWhenVideoDisable){const e=this._getLocalVideoTracks();return e.length?(e.forEach((e=>{e.unmute()})),{code:s.SUCCESS}):(C.error(`[RCCallSession EnableVideoTrack] Room missing video track -> ${s.MISSING_VIDEO_TRACK_ERROR}`),{code:s.MISSING_VIDEO_TRACK_ERROR})}const{code:e,track:t}=yield this._rtcClient.createCameraVideoTrack();if(e!==u.SUCCESS)return C.error(`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${e}`),{code:s.GET_LOCAL_VIDEO_TRACK_ERROR};const o=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():o.push(e)})),o.push(t),this._options.localTracks=o,t.mute();const{code:i}=yield this._room.publish([t]);return i!==u.SUCCESS?(C.error(`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${e}`),{code:s.VIDEO_PUBLISH_ERROR}):(t.unmute(),this._notifyTrackReady([t]),{code:s.SUCCESS})}))}disableAudioTrack(){return _(this,void 0,void 0,(function*(){this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return _(this,void 0,void 0,(function*(){this._getLocalAudioTracks().forEach((e=>{e.unmute()}))}))}_destroyTracks(e){e.forEach((e=>{e.destroy()}))}_notifyTrackReady(e){e.forEach((e=>{try{this._listener.onTrackReady(e,this)}catch(e){C.error("[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(e,t)=>{const o=this._rtcClient.getCurrentId();this._stateMachine.userLeave([o]),e?(t===h.SERVER_KICK&&this._exceptionClose(i.KICKED_BY_SERVER),t===h.OTHER_KICK&&this._exceptionClose(i.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(i.NETWORK_ERROR)},onMessageReceive(e,t,o,i){},onRoomAttributeChange(e,t){},onAudioMuteChange:e=>{C.info(`[RCCallSession onAudioMuteChange] userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const t={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"audio",trackId:e.getTrackId()};try{this._listener.onAudioMuteChange(t,this)}catch(e){C.error("[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{C.info(`[RCCallSession onVideoMuteChange]userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const t={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"video",trackId:e.getTrackId()};try{this._listener.onVideoMuteChange(t,this)}catch(e){C.error("[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>_(this,void 0,void 0,(function*(){if(this._room){const{code:t}=yield this._room.subscribe(e);t!==u.SUCCESS&&C.error(`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${t}`)}})),onTrackUnpublish:e=>{},onTrackReady:t=>{this._stateMachine.getMediaType()===e.AUDIO&&t.isVideoTrack()||this._notifyTrackReady([t])},onUserJoin:e=>{this.joinRoomTimer&&this.joinRoomTimer.stop(),this._stateMachine.userJoin(e)},onUserLeave:e=>{C.info(`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{C.info(`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){C.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){C.error("[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){C.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()}}c.add("plugin-call","5.0.10"),c.validEngine("^4.5.5-enterprise.1")||C.error(`The current engine version '${c.getInfo().engine}' error,plugin-call required engine version at least '^4.5.5-enterprise.1'.`);class k{constructor(e,o,i){this._context=e,this._runtime=o,this._sessionList=[],this._rtcClient=i.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:l.COEXIST,isAllowDemotionGetStream:!1,lang:t.ZH},i),this._callEngine=new n(this._context,o,C,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||t.ZH}),p.on("sessionClose",(({session:e,summaryInfo:t})=>{this._removeSession(e);try{this._options.onSessionClose(e,t)}catch(e){C.error("[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),p.on("hungupOtherSession",(({session:e})=>{const t=e.getSessionId();C.info(`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${t}`),C.info(`[RCCallClient hungupOtherSession] sessionList ->${this._sessionList.map((e=>e.getSessionId())).join(",")}`);let o=0;for(;this._sessionList.length>1;)this._sessionList[o].getSessionId()!==t?(this._sessionList[o].hungup(),this._sessionList.splice(o,1)):o++;C.info(`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e,t){C.info("[RCCallClient _onInvite] Received invite message");const o=new b(e,this._rtcClient,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:R.CALLEE});C.info("[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(o);try{this._options.onSession(o,t)}catch(e){C.error("[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!o._listener)throw C.error("[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=g(o._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){C.error("[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),C.info("[RCCallClient registerUserInfo] successfully register user info data")}call({targetId:t,mediaType:o=e.AUDIO,listener:i,constraints:n,channelId:r="",extra:l="",pushTitle:a="",pushContent:c="",bitrate:d}){return _(this,void 0,void 0,(function*(){C.info(`[RCCallClient call] extra->${l} pushTitle->${a} pushContent->${c}`);const e=[m(t),S(o),g(i),y(l),T(a),E(c)],u=[];if(!e.every((e=>(!e.result&&u.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${u.join("\n")}`);let h=[];const{code:_,tracks:p}=yield this._getLocalTrack(o,n);if(_!==s.SUCCESS)return{code:_};h=p,h.forEach((e=>{var t,o,s;e.isAudioTrack()&&(null==d?void 0:d.audio)&&e.setBitrate(null==d?void 0:d.audio),e.isVideoTrack()&&(null==d?void 0:d.video)&&e.setBitrate(null===(t=null==d?void 0:d.video)||void 0===t?void 0:t.max,null===(o=null==d?void 0:d.video)||void 0===o?void 0:o.min,null===(s=null==d?void 0:d.video)||void 0===s?void 0:s.start),i.onTrackReady(e)}));const{code:f,stateMachine:v}=yield this._callEngine.call(r,t,o,l,a,c);if(f===s.SUCCESS&&v){C.info("[RCCallClient call] successfully created state machine");const e=new b(v,this._rtcClient,{localTracks:h,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:R.CALLER});return e.registerSessionListener(i),this._sessionList.push(e),C.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:f,session:e}}return C.error(`[RCCallClient call] call failed code ->: ${f}`),h.forEach((e=>{e.mute(),e.destroy()})),{code:f}}))}callInGroup({targetId:t,userIds:o,mediaType:i=e.AUDIO,listener:n,constraints:r,channelId:l="",extra:a="",pushTitle:c="",pushContent:d="",bitrate:u}){return _(this,void 0,void 0,(function*(){const e=[m(t),v(o),S(i),g(n),y(a),T(c),E(d)],h=[];if(!e.every((e=>(!e.result&&h.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${h.join("\n")}`);let _=[];const{code:p,tracks:f}=yield this._getLocalTrack(i,r);if(p!==s.SUCCESS)return{code:p};_=f,_.forEach((e=>{var t,o,i;e.isAudioTrack()&&(null==u?void 0:u.audio)&&e.setBitrate(null==u?void 0:u.audio),e.isVideoTrack()&&(null==u?void 0:u.video)&&e.setBitrate(null===(t=null==u?void 0:u.video)||void 0===t?void 0:t.max,null===(o=null==u?void 0:u.video)||void 0===o?void 0:o.min,null===(i=null==u?void 0:u.video)||void 0===i?void 0:i.start),n.onTrackReady(e)}));const{code:I,stateMachine:k}=yield this._callEngine.callInGroup(l,t,i,o,a,c,d);if(I===s.SUCCESS&&k){C.info("[RCCallClient callInGroup] successfully created state machine");const e=new b(k,this._rtcClient,{localTracks:_,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:R.CALLER});return e.registerSessionListener(n),this._sessionList.push(e),C.info(`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:I,session:e}}return C.info(`[RCCallClient callInGroup] callInGroup failed code -> ${I}`),_.forEach((e=>{e.mute(),e.destroy()})),{code:I}}))}_getLocalTrackCore(t,o){return _(this,void 0,void 0,(function*(){if(t===e.AUDIO){const{code:e,track:t}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o&&o.audio&&Object.assign({},o.audio));return e!==u.SUCCESS?(C.error(`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_TRACK_ERROR}):(C.info("[RCCallClient _getTrack] successfully get Audio local tracks"),{code:s.SUCCESS,tracks:[t]})}{const{code:e,tracks:t}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",o&&Object.assign({},o));return e!==u.SUCCESS?(C.error(`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(C.info("[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:s.SUCCESS,tracks:t})}}))}_getLocalTrack(t,o){return _(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&t===e.AUDIO_VIDEO){const{code:t,tracks:i}=yield this._getLocalTrackCore(e.AUDIO_VIDEO,o);if(t!==s.SUCCESS){const{code:t,tracks:i}=yield this._getLocalTrackCore(e.AUDIO,o);return t!==s.SUCCESS?{code:t}:{code:t,tracks:i}}return{code:t,tracks:i}}{const{code:e,tracks:i}=yield this._getLocalTrackCore(t,o);return e!==s.SUCCESS?{code:e}:{code:e,tracks:i}}}))}_removeSession(e){const t=e.getSessionId();this._sessionList=this._sessionList.filter((e=>e.getSessionId()!==t))}getJoinedRoomInfo(){return _(this,void 0,void 0,(function*(){const{code:e,data:t}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return e!==d.SUCCESS?(C.error("getJoinedUserInfo error",e),{code:s.QUERY_JOINED_USER_INFO_ERROR}):{code:s.SUCCESS,data:t}}))}destroyStateMachine(){return _(this,void 0,void 0,(function*(){return this._callEngine.destroy()}))}}const O={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,t,o){const i=f(o);if(!i.result)throw new Error(`[RCCallLib installer steup]${i.msg}`);return C.setLogLevel(o.logLevel),C.setLogStdout(o.logStdout),C.warn("RCCall Version: 5.0.10, Commit: 010761df892b669845b52207e7c1c3829782d100"),new k(e,t,o)}};export{k as RCCallClient,b as RCCallSession,O as installer};