@rongcloud/plugin-call 5.0.5 → 5.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +49 -10
- package/dist/index.esm.js +2 -2
- package/dist/index.js +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +4 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* RCCall - v5.0.
|
|
3
|
-
* CommitId -
|
|
4
|
-
* Thu
|
|
2
|
+
* RCCall - v5.0.7
|
|
3
|
+
* CommitId - 3dcd9a3cf924b311e2169155be169d960765c55e
|
|
4
|
+
* Thu Jan 13 2022 15:41:47 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
|
-
import { RCCallStateMachine, RCCallErrorCode, RCCallMediaType, IUserData, RCCallUserState, RCCallSessionState, IEndSummary, IOfflineRecord, RCCallLanguage, RCCallEndReason, IInvitedUsers } from '@rongcloud/plugin-call-engine';
|
|
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
11
|
|
|
@@ -115,8 +115,11 @@ declare class RCCallSession {
|
|
|
115
115
|
/**
|
|
116
116
|
* 群呼叫中继续邀请
|
|
117
117
|
* @param userIds 被邀请用户 ID 列表
|
|
118
|
+
* @param options.extra 消息的扩展信息
|
|
119
|
+
* @param options.pushTitle 通知的标题
|
|
120
|
+
* @param options.pushContent 通知内容
|
|
118
121
|
*/
|
|
119
|
-
invite(userIds: string[]): Promise<{
|
|
122
|
+
invite(userIds: string[], options?: IInviteOptions): Promise<{
|
|
120
123
|
code: RCCallErrorCode;
|
|
121
124
|
}>;
|
|
122
125
|
/**
|
|
@@ -205,7 +208,7 @@ declare class RCCallSession {
|
|
|
205
208
|
/**
|
|
206
209
|
* 获取房间当前会话 Id,当房间内已无成员时房间会回收,重新加入时 sessionId 将更新,(用户录制资源用的)
|
|
207
210
|
*/
|
|
208
|
-
getRTCSessionId(): string;
|
|
211
|
+
getRTCSessionId(): string | null;
|
|
209
212
|
/**
|
|
210
213
|
* 目标 ID,单呼对方人员 Id, 群呼群组 Id
|
|
211
214
|
*/
|
|
@@ -280,7 +283,7 @@ interface IRCCallInitOptions {
|
|
|
280
283
|
/**
|
|
281
284
|
* 收到邀请后,产生新的session
|
|
282
285
|
*/
|
|
283
|
-
onSession: (session: RCCallSession) => void;
|
|
286
|
+
onSession: (session: RCCallSession, extra?: string) => void;
|
|
284
287
|
/**
|
|
285
288
|
* session已关闭
|
|
286
289
|
*/
|
|
@@ -436,6 +439,18 @@ interface IRCCallParams {
|
|
|
436
439
|
video?: ICameraVideoProfile;
|
|
437
440
|
audio: IMicphoneAudioProfile;
|
|
438
441
|
};
|
|
442
|
+
/**
|
|
443
|
+
* 消息的扩展信息
|
|
444
|
+
*/
|
|
445
|
+
extra?: string;
|
|
446
|
+
/**
|
|
447
|
+
* 对方显示通知的标题
|
|
448
|
+
*/
|
|
449
|
+
pushTitle?: string;
|
|
450
|
+
/**
|
|
451
|
+
* 对方显示的通知内容
|
|
452
|
+
*/
|
|
453
|
+
pushContent?: string;
|
|
439
454
|
}
|
|
440
455
|
interface IMediaStreamConstraints {
|
|
441
456
|
video?: ICameraVideoProfile;
|
|
@@ -452,8 +467,26 @@ interface IRCCallInGroupParams {
|
|
|
452
467
|
* session上要注册的监听事件
|
|
453
468
|
*/
|
|
454
469
|
listener: ISessionListener;
|
|
470
|
+
/**
|
|
471
|
+
* 组织 Id,可选
|
|
472
|
+
*/
|
|
455
473
|
channelId?: string;
|
|
474
|
+
/**
|
|
475
|
+
* 用于获取己方媒体资源的参数
|
|
476
|
+
*/
|
|
456
477
|
constraints?: IMediaStreamConstraints;
|
|
478
|
+
/**
|
|
479
|
+
* 消息的扩展信息
|
|
480
|
+
*/
|
|
481
|
+
extra?: string;
|
|
482
|
+
/**
|
|
483
|
+
* 对方显示通知的标题
|
|
484
|
+
*/
|
|
485
|
+
pushTitle?: string;
|
|
486
|
+
/**
|
|
487
|
+
* 对方显示的通知内容
|
|
488
|
+
*/
|
|
489
|
+
pushContent?: string;
|
|
457
490
|
}
|
|
458
491
|
interface IDeviceChangeParams {
|
|
459
492
|
audio?: IMicphoneAudioProfile;
|
|
@@ -507,8 +540,11 @@ declare class RCCallClient {
|
|
|
507
540
|
* @param params.listener (session上的监听) 必填
|
|
508
541
|
* @param params.constraints 获取音频或音视频资源时的参数 可选
|
|
509
542
|
* @param params.channelId 组织 Id 可选
|
|
543
|
+
* @param params.extra 消息扩展信息
|
|
544
|
+
* @param params.pushTitle 通知的标题
|
|
545
|
+
* @param params.pushContent 通知的内容
|
|
510
546
|
*/
|
|
511
|
-
call({ targetId, mediaType, listener, constraints, channelId }: IRCCallParams): Promise<{
|
|
547
|
+
call({ targetId, mediaType, listener, constraints, channelId, extra, pushTitle, pushContent }: IRCCallParams): Promise<{
|
|
512
548
|
code: RCCallErrorCode;
|
|
513
549
|
session?: RCCallSession;
|
|
514
550
|
}>;
|
|
@@ -518,10 +554,13 @@ declare class RCCallClient {
|
|
|
518
554
|
* @param params.userIds 被呼叫的群内成员 Id 必填
|
|
519
555
|
* @param params.mediaType 音频呼叫 or 音视频呼叫 必填
|
|
520
556
|
* @param params.listener (session上的监听) 必填
|
|
521
|
-
* @param params.channelId 组织 Id 可选
|
|
522
557
|
* @param params.constraints 获取音频或音视频资源时的参数 可选
|
|
558
|
+
* @param params.channelId 组织 Id 可选
|
|
559
|
+
* @param params.extra 消息扩展信息 可选
|
|
560
|
+
* @param params.pushTitle 通知的标题
|
|
561
|
+
* @param params.pushContent 通知的内容
|
|
523
562
|
*/
|
|
524
|
-
callInGroup({ targetId, userIds, mediaType, listener, constraints, channelId }: IRCCallInGroupParams): Promise<{
|
|
563
|
+
callInGroup({ targetId, userIds, mediaType, listener, constraints, channelId, extra, pushTitle, pushContent }: IRCCallInGroupParams): Promise<{
|
|
525
564
|
code: RCCallErrorCode;
|
|
526
565
|
session?: RCCallSession;
|
|
527
566
|
}>;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{RCCallMediaType as e,RCCallLanguage as
|
|
1
|
+
import{RCCallMediaType as e,RCCallLanguage as t,RCCallSessionState as o,RCCallEndReason as i,RCCallErrorCode as s,RCCallEngine as n}from"@rongcloud/plugin-call-engine";export{RCCallEndReason,RCCallErrorCode,RCCallLanguage,RCCallMediaType,RCCallSessionState,RCCallUserState}from"@rongcloud/plugin-call-engine";import{Logger as r,RTCJoinType as l,LogLevel as a,VersionManage as c,ErrorCode as d}from"@rongcloud/engine";import{RCRTCCode as u,RCKickReason as h}from"@rongcloud/plugin-rtc";const C=new r("RCCall");
|
|
2
2
|
/*! *****************************************************************************
|
|
3
3
|
Copyright (c) Microsoft Corporation.
|
|
4
4
|
|
|
@@ -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,o,t,i){return new(t||(t=Promise))((function(s,n){function r(e){try{l(i.next(e))}catch(e){n(e)}}function a(e){try{l(i.throw(e))}catch(e){n(e)}}function l(e){var o;e.done?s(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(r,a)}l((i=i.apply(e,o||[])).next())}))}var R;!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(R||(R={}));var f=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 g=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 t=Object.keys(e),i=[];return["rtcClient","onSession","onSessionClose"].forEach((e=>{t.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(a).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(o).includes(e)}(e.lang)?void 0===e.logLevel||function(e){return Object.values(l).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},S=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}},p=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},m=o=>o===e.AUDIO||o===e.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},y=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 T{constructor(o,s,n={}){this._stateMachine=o,this._rtcClient=s,this._options=n,this._listener=null,this._RETRYCOUNT=2,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:o})=>{h.info(`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${o}`)},onStateChange:e=>_(this,void 0,void 0,(function*(){const{state:o,reason:s}=e;if(h.info(`[RCCallSession onStateChange] : state->${o} reason->${s}`),o===t.KEEPING){const e=this._stateMachine.getCallId();h.info(`[RCCallSession onStateChange] roomId: ${e}`);try{yield this._joinRoom(e)}catch(o){this._exceptionClose(i.NETWORK_ERROR),h.error(`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${e}`),console.error(o)}}else if(o===t.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void f.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),h.info("[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{h.info(`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){h.error("[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{h.info(`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){h.error("[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,o)=>{h.info(`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${o}`);try{this._listener.onHungup(e,o,this)}catch(e){h.error("[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:o})=>{h.info(`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,o,this)}catch(e){h.error("[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:o,mediaType:t})=>{h.info(`[RCCallSession onMediaModify]sender: sender.userId -> ${o.userId} mediaType: ${t}`),t===e.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(o,t,this)}catch(e){h.error("[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}}})}_joinRoom(e){return _(this,void 0,void 0,(function*(){try{const{code:o,room:t}=yield this._rtcClient.joinRTCRoom(e,this._options.joinType);if(o!==u.SUCCESS)return o===u.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(i.SERVICE_NOT_OPENED),o===u.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(i.OTHER_CLIENT_IN_CALL):this._exceptionClose(i.NETWORK_ERROR),h.info(`[RCCallClient _joinRoom] join room failed: roomId -> ${e} RCRTCCode -> ${o}`),{code:s.JOIN_ROOM_ERROR};this._room=t}catch(o){return this._exceptionClose(i.NETWORK_ERROR),h.error(`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${e}`),console.error(o),{code:s.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(o){return this._exceptionClose(i.SUBSCRIBE_ERROR),h.error(`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${e}`),console.error(o),{code:s.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(o){return this._exceptionClose(i.PUBLISH_ERROR),h.error(`[RCCallSession _joinRoom] _publish Exception roomId -> ${e}`),console.error(o),{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:o}=yield this._subscribeRetry(e,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);o!==u.SUCCESS&&(this._exceptionClose(i.SUBSCRIBE_ERROR),h.error(`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${o}`))}}))}_subscribeRetry(e,o=!1,t=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){h.error("[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!o)return{code:i};if(t>0)return t--,this._subscribeRetry(e,o,t)}return{code:i}}))}_publish(){return _(this,void 0,void 0,(function*(){const e=this._options.localTracks,{code:o}=yield this._publishRetry(e,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(o!==u.SUCCESS)return this._exceptionClose(i.PUBLISH_ERROR),void h.info(`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${o}`);this._options.produceType===R.CALLEE&&this._notifyTrackReady(e)}))}_publishRetry(e,o=!1,t=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){h.error("[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!o)return{code:i};if(t>0)return t--,this._publishRetry(e,o,t)}return{code:i}}))}_leaveRoom(){return _(this,void 0,void 0,(function*(){try{const{code:e}=yield this._rtcClient.leaveRoom(this._room);h.info("[RCCallSession _leaveRoom] Successfully exited the room")}catch(e){h.error("[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();f.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const o=S(e);if(!o.result)throw new Error(`[RCCallSession registerSessionListener] ${o.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(o,t){return _(this,void 0,void 0,(function*(){if(o===e.AUDIO){const{code:e,track:o}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",t&&t.audio&&Object.assign({},t.audio));return e!==u.SUCCESS?(h.error(`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_TRACK_ERROR}):(h.info("[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:s.SUCCESS,tracks:[o]})}{const{code:e,tracks:o}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",t&&Object.assign({},t));return e!==u.SUCCESS?(h.error(`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(h.info("[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:s.SUCCESS,tracks:o})}}))}_getLocalTrack(o,t){return _(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&o===e.AUDIO_VIDEO){const{code:o,tracks:n}=yield this._getLocalTrackCore(e.AUDIO_VIDEO,t);if(o!==s.SUCCESS){const{code:o,tracks:n}=yield this._getLocalTrackCore(e.AUDIO,t);return o!==s.SUCCESS?(this._exceptionClose(i.GET_MEDIA_RESOURCES_ERROR),{code:o}):{code:o,tracks:n}}return{code:o,tracks:n}}{const{code:e,tracks:n}=yield this._getLocalTrackCore(o,t);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 o=[],t=[],{code:i,track:n}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",e);if(i!==u.SUCCESS)return h.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()||t.push(e)})),o.push(n),t.push(n),this._options.localTracks=t,this._notifyTrackReady(o),this._room){const{code:e}=yield this._room.publish(o);if(e!==u.SUCCESS)return{code:s.AUDIO_PUBLISH_ERROR}}return{code:s.SUCCESS}}))}invite(e){return _(this,void 0,void 0,(function*(){const o=y(e);if(!o.result)throw new Error(`[RCCallSession invite] ${o.msg}`);const{code:t}=yield this._stateMachine.invite(e);return{code:t}}))}accept(e){return _(this,void 0,void 0,(function*(){const o=(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&&!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 o})(e);if(!o.result)throw new Error(`[RCCallSession accept] ${o.msg}`);f.emit("hungupOtherSession",{session:this});const t=this._stateMachine.getMediaType(),{code:i,tracks:n}=yield this._getLocalTrack(t,e);if(i!==s.SUCCESS)return{code:i};this._options.localTracks=n;const{code:r}=yield this._stateMachine.accept();return r!==s.SUCCESS?(h.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:o}=yield this._stateMachine.changeMediaType(e);return o!==s.SUCCESS&&h.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 _(this,void 0,void 0,(function*(){const{code:o,track:t}=yield this._rtcClient.createCameraVideoTrack();if(o!==u.SUCCESS)return{code:s.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:i}=yield this._room.publish([t]);i===u.SUCCESS?(this._notifyTrackReady([t]),this._changeMediaType(e.AUDIO_VIDEO)):h.error(`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${o}`)}))}_setMediaTypeToAudio(){return _(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!==u.SUCCESS&&h.error(`[RCCallSession disableVideo] unpublish failed -> ${o}`),this._destroyTracks(e)}}))}descendAbility(){return _(this,void 0,void 0,(function*(){const{code:o}=yield this._changeMediaType(e.AUDIO);return o===s.SUCCESS&&this._setMediaTypeToAudio(),{code:o}}))}disableVideoTrack(){return _(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(!e.length)return h.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:o}=yield this._room.unpublish(e);return o!==u.SUCCESS?(h.error(`[RCCallSession disableVideo] unpublish failed -> ${o}`),{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}):(h.error(`[RCCallSession EnableVideoTrack] Room missing video track -> ${s.MISSING_VIDEO_TRACK_ERROR}`),{code:s.MISSING_VIDEO_TRACK_ERROR})}const{code:e,track:o}=yield this._rtcClient.createCameraVideoTrack();if(e!==u.SUCCESS)return h.error(`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${e}`),{code:s.GET_LOCAL_VIDEO_TRACK_ERROR};const t=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():t.push(e)})),t.push(o),this._options.localTracks=t,o.mute();const{code:i}=yield this._room.publish([o]);return i!==u.SUCCESS?(h.error(`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${e}`),{code:s.VIDEO_PUBLISH_ERROR}):(o.unmute(),this._notifyTrackReady([o]),{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){h.error("[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(e,o)=>{const t=this._rtcClient.getCurrentId();this._stateMachine.userLeave([t]),e?(o===C.SERVER_KICK&&this._exceptionClose(i.KICKED_BY_SERVER),o===C.OTHER_KICK&&this._exceptionClose(i.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(i.NETWORK_ERROR)},onMessageReceive(e,o,t,i){},onRoomAttributeChange(e,o){},onAudioMuteChange:e=>{h.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){h.error("[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{h.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){h.error("[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>_(this,void 0,void 0,(function*(){if(this._room){const{code:o}=yield this._room.subscribe(e);o!==u.SUCCESS&&h.error(`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${o}`)}})),onTrackUnpublish:e=>{},onTrackReady:o=>{this._stateMachine.getMediaType()===e.AUDIO&&o.isVideoTrack()||this._notifyTrackReady([o])},onUserJoin:e=>{this._stateMachine.userJoin(e)},onUserLeave:e=>{h.info(`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{h.info(`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){h.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){h.error("[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){h.error("[RCCallSession onICEConnectionStateChange] onICEConnectionStateChange exception"),console.error(e)}}})}getSessionId(){return this._stateMachine.getCallId()}getRTCSessionId(){return this._room.getSessionId()}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.5"),c.validEngine(">=4.5.2")||h.error(`The current engine version '${c.getInfo().engine}' error,plugin-call required engine version at least '>=4.5.2'.`);class E{constructor(e,t,i){this._context=e,this._runtime=t,this._sessionList=[],this._rtcClient=i.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:a.COEXIST,isAllowDemotionGetStream:!1,lang:o.ZH},i),this._callEngine=new n(this._context,t,h,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||o.ZH}),f.on("sessionClose",(({session:e,summaryInfo:o})=>{this._removeSession(e);try{this._options.onSessionClose(e,o)}catch(e){h.error("[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),f.on("hungupOtherSession",(({session:e})=>{const o=e.getSessionId();h.info(`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${o}`),h.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++;h.info(`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e){h.info("[RCCallClient _onInvite] Received invite message");const o=new T(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});h.info("[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(o);try{this._options.onSession(o)}catch(e){h.error("[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!o._listener)throw h.error("[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=S(o._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){h.error("[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),h.info("[RCCallClient registerUserInfo] successfully register user info data")}call({targetId:o,mediaType:t=e.AUDIO,listener:i,constraints:n,channelId:r=""}){return _(this,void 0,void 0,(function*(){const e=[p(o),m(t),S(i)],a=[];if(!e.every((e=>(!e.result&&a.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${a.join("\n")}`);let l=[];const{code:c,tracks:d}=yield this._getLocalTrack(t,n);if(c!==s.SUCCESS)return{code:c};l=d,l.forEach((e=>{i.onTrackReady(e)}));const{code:u,stateMachine:C}=yield this._callEngine.call(r,o,t);if(u===s.SUCCESS&&C){h.info("[RCCallClient call] successfully created state machine");const e=new T(C,this._rtcClient,{localTracks:l,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),h.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:u,session:e}}return h.error(`[RCCallClient call] call failed code ->: ${u}`),l.forEach((e=>{e.mute(),e.destroy()})),{code:u}}))}callInGroup({targetId:o,userIds:t,mediaType:i=e.AUDIO,listener:n,constraints:r,channelId:a=""}){return _(this,void 0,void 0,(function*(){const e=[p(o),y(t),m(i),S(n)],l=[];if(!e.every((e=>(!e.result&&l.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${l.join("\n")}`);let c=[];const{code:d,tracks:u}=yield this._getLocalTrack(i,r);if(d!==s.SUCCESS)return{code:d};c=u,c.forEach((e=>{n.onTrackReady(e)}));const{code:C,stateMachine:_}=yield this._callEngine.callInGroup(a,o,i,t);if(C===s.SUCCESS&&_){h.info("[RCCallClient callInGroup] successfully created state machine");const e=new T(_,this._rtcClient,{localTracks:c,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),h.info(`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:C,session:e}}return h.info(`[RCCallClient callInGroup] callInGroup failed code -> ${C}`),c.forEach((e=>{e.mute(),e.destroy()})),{code:C}}))}_getLocalTrackCore(o,t){return _(this,void 0,void 0,(function*(){if(o===e.AUDIO){const{code:e,track:o}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",t&&t.audio&&Object.assign({},t.audio));return e!==u.SUCCESS?(h.error(`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_TRACK_ERROR}):(h.info("[RCCallClient _getTrack] successfully get Audio local tracks"),{code:s.SUCCESS,tracks:[o]})}{const{code:e,tracks:o}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",t&&Object.assign({},t));return e!==u.SUCCESS?(h.error(`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(h.info("[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:s.SUCCESS,tracks:o})}}))}_getLocalTrack(o,t){return _(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&o===e.AUDIO_VIDEO){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.AUDIO_VIDEO,t);if(o!==s.SUCCESS){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.AUDIO,t);return o!==s.SUCCESS?{code:o}:{code:o,tracks:i}}return{code:o,tracks:i}}{const{code:e,tracks:i}=yield this._getLocalTrackCore(o,t);return e!==s.SUCCESS?{code:e}:{code:e,tracks:i}}}))}_removeSession(e){const o=e.getSessionId();this._sessionList=this._sessionList.filter((e=>e.getSessionId()!==o))}getJoinedRoomInfo(){return _(this,void 0,void 0,(function*(){const{code:e,data:o}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return e!==d.SUCCESS?(h.error("getJoinedUserInfo error",e),{code:s.QUERY_JOINED_USER_INFO_ERROR}):{code:s.SUCCESS,data:o}}))}}const I={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,o,t){const i=g(t);if(!i.result)throw new Error(`[RCCallLib installer steup]${i.msg}`);return h.setLogLevel(t.logLevel),h.setLogStdout(t.logStdout),h.warn("RCCall Version: 5.0.5, Commit: 87afc0755fbba331ed398046c2aa4f5c245a4e42"),new E(e,o,t)}};export{E as RCCallClient,T as RCCallSession,I 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}},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};
|
package/dist/index.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 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())}))}var r;!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(r||(r={}));var n=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 l=t=>{if(!t)return{result:!1,msg:"Initialization missing parameter -> options"};if("object"!=typeof t)return{result:!1,msg:"Initialization options must be an object"};const i=Object.keys(t),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 t.rtcClient?{result:!1,msg:"Initialization 'rtcClient' parameter must be of type 'object'"}:"function"!=typeof t.onSession?{result:!1,msg:"Initialization 'onSession' parameter must be of type 'function'"}:"function"!=typeof t.onSessionClose?{result:!1,msg:"Initialization 'onSessionClose' parameter must be of type 'function'"}:void 0!==t.isAllowSubscribeRetry&&"boolean"!=typeof t.isAllowSubscribeRetry?{result:!1,msg:"Initialization 'isAllowSubscribeRetry' parameter must be of type 'boolean'"}:void 0!==t.isAllowPublishRetry&&"boolean"!=typeof t.isAllowPublishRetry?{result:!1,msg:"Initialization 'isAllowPublishRetry' parameter must be of type 'boolean'"}:void 0!==t.isOffCameraWhenVideoDisable&&"boolean"!=typeof t.isOffCameraWhenVideoDisable?{result:!1,msg:"Initialization 'isOffCameraWhenVideoDisable' parameter must be of type 'boolean'"}:void 0===t.joinType||(r=t.joinType,Object.values(o.RTCJoinType).includes(r))?void 0!==t.isAllowDemotionGetStream&&"boolean"!=typeof t.isAllowDemotionGetStream?{result:!1,msg:"Initialization 'isAllowDemotionGetStream' parameter must be of type 'boolean'"}:void 0===t.lang||function(o){return Object.values(e.RCCallLanguage).includes(o)}(t.lang)?void 0===t.logLevel||function(e){return Object.values(o.LogLevel).includes(e)}(t.logLevel)?void 0!==t.logStdout&&"function"!=typeof t.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},a=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}},c=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},C=o=>o===e.RCCallMediaType.AUDIO||o===e.RCCallMediaType.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},d=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 u{constructor(o,t,r={}){this._stateMachine=o,this._rtcClient=t,this._options=r,this._listener=null,this._RETRYCOUNT=2,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:o})=>{i.info(`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${o}`)},onStateChange:o=>s(this,void 0,void 0,(function*(){const{state:t,reason:s}=o;if(i.info(`[RCCallSession onStateChange] : state->${t} reason->${s}`),t===e.RCCallSessionState.KEEPING){const o=this._stateMachine.getCallId();i.info(`[RCCallSession onStateChange] roomId: ${o}`);try{yield this._joinRoom(o)}catch(t){this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR),i.error(`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${o}`),console.error(t)}}else if(t===e.RCCallSessionState.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void n.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),i.info("[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{i.info(`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){i.error("[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{i.info(`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){i.error("[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,o)=>{i.info(`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${o}`);try{this._listener.onHungup(e,o,this)}catch(e){i.error("[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:o})=>{i.info(`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,o,this)}catch(e){i.error("[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:o,mediaType:t})=>{i.info(`[RCCallSession onMediaModify]sender: sender.userId -> ${o.userId} mediaType: ${t}`),t===e.RCCallMediaType.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(o,t,this)}catch(e){i.error("[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}}})}_joinRoom(o){return s(this,void 0,void 0,(function*(){try{const{code:s,room:r}=yield this._rtcClient.joinRTCRoom(o,this._options.joinType);if(s!==t.RCRTCCode.SUCCESS)return s===t.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(e.RCCallEndReason.SERVICE_NOT_OPENED),s===t.RCRTCCode.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(e.RCCallEndReason.OTHER_CLIENT_IN_CALL):this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR),i.info(`[RCCallClient _joinRoom] join room failed: roomId -> ${o} RCRTCCode -> ${s}`),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR};this._room=r}catch(t){return this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR),i.error(`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${o}`),console.error(t),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(t){return this._exceptionClose(e.RCCallEndReason.SUBSCRIBE_ERROR),i.error(`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${o}`),console.error(t),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(t){return this._exceptionClose(e.RCCallEndReason.PUBLISH_ERROR),i.error(`[RCCallSession _joinRoom] _publish Exception roomId -> ${o}`),console.error(t),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR}}return{code:e.RCCallErrorCode.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return s(this,void 0,void 0,(function*(){const o=this._room.getRemoteTracks();if(o.length){const{code:s}=yield this._subscribeRetry(o,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);s!==t.RCRTCCode.SUCCESS&&(this._exceptionClose(e.RCCallEndReason.SUBSCRIBE_ERROR),i.error(`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${s}`))}}))}_subscribeRetry(e,o=!1,r=0){return s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.subscribe(e);if(s!==t.RCRTCCode.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(s,this)}catch(e){i.error("[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!o)return{code:s};if(r>0)return r--,this._subscribeRetry(e,o,r)}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!==t.RCRTCCode.SUCCESS)return this._exceptionClose(e.RCCallEndReason.PUBLISH_ERROR),void i.info(`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${s}`);this._options.produceType===r.CALLEE&&this._notifyTrackReady(o)}))}_publishRetry(e,o=!1,r=0){return s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.publish(e);if(s!==t.RCRTCCode.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(s,this)}catch(e){i.error("[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!o)return{code:s};if(r>0)return r--,this._publishRetry(e,o,r)}return{code:s}}))}_leaveRoom(){return s(this,void 0,void 0,(function*(){try{const{code:e}=yield this._rtcClient.leaveRoom(this._room);i.info("[RCCallSession _leaveRoom] Successfully exited the room")}catch(e){i.error("[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();n.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const o=a(e);if(!o.result)throw new Error(`[RCCallSession registerSessionListener] ${o.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(o,r){return s(this,void 0,void 0,(function*(){if(o===e.RCCallMediaType.AUDIO){const{code:o,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",r&&r.audio&&Object.assign({},r.audio));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(i.info("[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:o,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",r&&Object.assign({},r));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(i.info("[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(o,t){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&o===e.RCCallMediaType.AUDIO_VIDEO){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO_VIDEO,t);if(o!==e.RCCallErrorCode.SUCCESS){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO,t);return o!==e.RCCallErrorCode.SUCCESS?(this._exceptionClose(e.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:o}):{code:o,tracks:i}}return{code:o,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(o,t);return i!==e.RCCallErrorCode.SUCCESS?(this._exceptionClose(e.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:i}):{code:i,tracks:s}}}))}changeAudioDevice(o){return s(this,void 0,void 0,(function*(){const s=[],r=[],{code:n,track:l}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o);if(n!==t.RCRTCCode.SUCCESS)return i.error(`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${n}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||r.push(e)})),s.push(l),r.push(l),this._options.localTracks=r,this._notifyTrackReady(s),this._room){const{code:o}=yield this._room.publish(s);if(o!==t.RCRTCCode.SUCCESS)return{code:e.RCCallErrorCode.AUDIO_PUBLISH_ERROR}}return{code:e.RCCallErrorCode.SUCCESS}}))}invite(e){return s(this,void 0,void 0,(function*(){const o=d(e);if(!o.result)throw new Error(`[RCCallSession invite] ${o.msg}`);const{code:t}=yield this._stateMachine.invite(e);return{code:t}}))}accept(o){return s(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&&(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&&!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 o})(o);if(!t.result)throw new Error(`[RCCallSession accept] ${t.msg}`);n.emit("hungupOtherSession",{session:this});const s=this._stateMachine.getMediaType(),{code:r,tracks:l}=yield this._getLocalTrack(s,o);if(r!==e.RCCallErrorCode.SUCCESS)return{code:r};this._options.localTracks=l;const{code:a}=yield this._stateMachine.accept();return a!==e.RCCallErrorCode.SUCCESS?(i.error(`[RCCallSession accept]Send accept message failed -> code: ${a}`),{code:a}):{code:a}}))}hungup(){return s(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(o){return s(this,void 0,void 0,(function*(){const{code:t}=yield this._stateMachine.changeMediaType(o);return t!==e.RCCallErrorCode.SUCCESS&&i.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 s(this,void 0,void 0,(function*(){const{code:o,track:s}=yield this._rtcClient.createCameraVideoTrack();if(o!==t.RCRTCCode.SUCCESS)return{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:r}=yield this._room.publish([s]);r===t.RCRTCCode.SUCCESS?(this._notifyTrackReady([s]),this._changeMediaType(e.RCCallMediaType.AUDIO_VIDEO)):i.error(`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${o}`)}))}_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!==t.RCRTCCode.SUCCESS&&i.error(`[RCCallSession disableVideo] unpublish failed -> ${o}`),this._destroyTracks(e)}}))}descendAbility(){return s(this,void 0,void 0,(function*(){const{code:o}=yield this._changeMediaType(e.RCCallMediaType.AUDIO);return o===e.RCCallErrorCode.SUCCESS&&this._setMediaTypeToAudio(),{code:o}}))}disableVideoTrack(){return s(this,void 0,void 0,(function*(){const o=this._getLocalVideoTracks();if(!o.length)return i.error(`[RCCallSession disableVideoTrack] Room missing video track -> ${e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};if(o.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:e.RCCallErrorCode.SUCCESS};const{code:s}=yield this._room.unpublish(o);return s!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession disableVideo] unpublish failed -> ${s}`),{code:e.RCCallErrorCode.UNPUBLISH_VIDEO_ERROR}):(o.forEach((e=>{e.destroy()})),{code:e.RCCallErrorCode.SUCCESS})}))}enableVideoTrack(){return s(this,void 0,void 0,(function*(){if(!this._options.isOffCameraWhenVideoDisable){const o=this._getLocalVideoTracks();return o.length?(o.forEach((e=>{e.unmute()})),{code:e.RCCallErrorCode.SUCCESS}):(i.error(`[RCCallSession EnableVideoTrack] Room missing video track -> ${e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR})}const{code:o,track:s}=yield this._rtcClient.createCameraVideoTrack();if(o!==t.RCRTCCode.SUCCESS)return i.error(`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_VIDEO_TRACK_ERROR};const r=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():r.push(e)})),r.push(s),this._options.localTracks=r,s.mute();const{code:n}=yield this._room.publish([s]);return n!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${o}`),{code:e.RCCallErrorCode.VIDEO_PUBLISH_ERROR}):(s.unmute(),this._notifyTrackReady([s]),{code:e.RCCallErrorCode.SUCCESS})}))}disableAudioTrack(){return s(this,void 0,void 0,(function*(){this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return s(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){i.error("[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(o,i)=>{const s=this._rtcClient.getCurrentId();this._stateMachine.userLeave([s]),o?(i===t.RCKickReason.SERVER_KICK&&this._exceptionClose(e.RCCallEndReason.KICKED_BY_SERVER),i===t.RCKickReason.OTHER_KICK&&this._exceptionClose(e.RCCallEndReason.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR)},onMessageReceive(e,o,t,i){},onRoomAttributeChange(e,o){},onAudioMuteChange:e=>{i.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){i.error("[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{i.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){i.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!==t.RCRTCCode.SUCCESS&&i.error(`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${o}`)}})),onTrackUnpublish:e=>{},onTrackReady:o=>{this._stateMachine.getMediaType()===e.RCCallMediaType.AUDIO&&o.isVideoTrack()||this._notifyTrackReady([o])},onUserJoin:e=>{this._stateMachine.userJoin(e)},onUserLeave:e=>{i.info(`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{i.info(`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){i.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){i.error("[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){i.error("[RCCallSession onICEConnectionStateChange] onICEConnectionStateChange exception"),console.error(e)}}})}getSessionId(){return this._stateMachine.getCallId()}getRTCSessionId(){return this._room.getSessionId()}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()}}o.VersionManage.add("plugin-call","5.0.5"),o.VersionManage.validEngine(">=4.5.2")||i.error(`The current engine version '${o.VersionManage.getInfo().engine}' error,plugin-call required engine version at least '>=4.5.2'.`);class R{constructor(t,s,r){this._context=t,this._runtime=s,this._sessionList=[],this._rtcClient=r.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:o.RTCJoinType.COEXIST,isAllowDemotionGetStream:!1,lang:e.RCCallLanguage.ZH},r),this._callEngine=new e.RCCallEngine(this._context,s,i,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||e.RCCallLanguage.ZH}),n.on("sessionClose",(({session:e,summaryInfo:o})=>{this._removeSession(e);try{this._options.onSessionClose(e,o)}catch(e){i.error("[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),n.on("hungupOtherSession",(({session:e})=>{const o=e.getSessionId();i.info(`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${o}`),i.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++;i.info(`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e){i.info("[RCCallClient _onInvite] Received invite message");const o=new u(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});i.info("[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(o);try{this._options.onSession(o)}catch(e){i.error("[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!o._listener)throw i.error("[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=a(o._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){i.error("[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),i.info("[RCCallClient registerUserInfo] successfully register user info data")}call({targetId:o,mediaType:t=e.RCCallMediaType.AUDIO,listener:n,constraints:l,channelId:d=""}){return s(this,void 0,void 0,(function*(){const s=[c(o),C(t),a(n)],R=[];if(!s.every((e=>(!e.result&&R.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${R.join("\n")}`);let h=[];const{code:_,tracks:p}=yield this._getLocalTrack(t,l);if(_!==e.RCCallErrorCode.SUCCESS)return{code:_};h=p,h.forEach((e=>{n.onTrackReady(e)}));const{code:g,stateMachine:f}=yield this._callEngine.call(d,o,t);if(g===e.RCCallErrorCode.SUCCESS&&f){i.info("[RCCallClient call] successfully created state machine");const e=new u(f,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),i.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:g,session:e}}return i.error(`[RCCallClient call] call failed code ->: ${g}`),h.forEach((e=>{e.mute(),e.destroy()})),{code:g}}))}callInGroup({targetId:o,userIds:t,mediaType:n=e.RCCallMediaType.AUDIO,listener:l,constraints:R,channelId:h=""}){return s(this,void 0,void 0,(function*(){const s=[c(o),d(t),C(n),a(l)],_=[];if(!s.every((e=>(!e.result&&_.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${_.join("\n")}`);let p=[];const{code:g,tracks:f}=yield this._getLocalTrack(n,R);if(g!==e.RCCallErrorCode.SUCCESS)return{code:g};p=f,p.forEach((e=>{l.onTrackReady(e)}));const{code:S,stateMachine:m}=yield this._callEngine.callInGroup(h,o,n,t);if(S===e.RCCallErrorCode.SUCCESS&&m){i.info("[RCCallClient callInGroup] successfully created state machine");const e=new u(m,this._rtcClient,{localTracks:p,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(l),this._sessionList.push(e),i.info(`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:S,session:e}}return i.info(`[RCCallClient callInGroup] callInGroup failed code -> ${S}`),p.forEach((e=>{e.mute(),e.destroy()})),{code:S}}))}_getLocalTrackCore(o,r){return s(this,void 0,void 0,(function*(){if(o===e.RCCallMediaType.AUDIO){const{code:o,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",r&&r.audio&&Object.assign({},r.audio));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(i.info("[RCCallClient _getTrack] successfully get Audio local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:o,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",r&&Object.assign({},r));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(i.info("[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(o,t){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&o===e.RCCallMediaType.AUDIO_VIDEO){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO_VIDEO,t);if(o!==e.RCCallErrorCode.SUCCESS){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO,t);return o!==e.RCCallErrorCode.SUCCESS?{code:o}:{code:o,tracks:i}}return{code:o,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(o,t);return i!==e.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:t,data:s}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return t!==o.ErrorCode.SUCCESS?(i.error("getJoinedUserInfo error",t),{code:e.RCCallErrorCode.QUERY_JOINED_USER_INFO_ERROR}):{code:e.RCCallErrorCode.SUCCESS,data:s}}))}}const h={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,o,t){const s=l(t);if(!s.result)throw new Error(`[RCCallLib installer steup]${s.msg}`);return i.setLogLevel(t.logLevel),i.setLogStdout(t.logStdout),i.warn("RCCall Version: 5.0.5, Commit: 87afc0755fbba331ed398046c2aa4f5c245a4e42"),new R(e,o,t)}};Object.defineProperty(exports,"RCCallEndReason",{enumerable:!0,get:function(){return e.RCCallEndReason}}),Object.defineProperty(exports,"RCCallErrorCode",{enumerable:!0,get:function(){return e.RCCallErrorCode}}),Object.defineProperty(exports,"RCCallLanguage",{enumerable:!0,get:function(){return e.RCCallLanguage}}),Object.defineProperty(exports,"RCCallMediaType",{enumerable:!0,get:function(){return e.RCCallMediaType}}),Object.defineProperty(exports,"RCCallSessionState",{enumerable:!0,get:function(){return e.RCCallSessionState}}),Object.defineProperty(exports,"RCCallUserState",{enumerable:!0,get:function(){return e.RCCallUserState}}),exports.RCCallClient=R,exports.RCCallSession=u,exports.installer=h;
|
|
15
|
+
***************************************************************************** */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())}))}var r;!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(r||(r={}));var n=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 l=t=>{if(!t)return{result:!1,msg:"Initialization missing parameter -> options"};if("object"!=typeof t)return{result:!1,msg:"Initialization options must be an object"};const i=Object.keys(t),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 t.rtcClient?{result:!1,msg:"Initialization 'rtcClient' parameter must be of type 'object'"}:"function"!=typeof t.onSession?{result:!1,msg:"Initialization 'onSession' parameter must be of type 'function'"}:"function"!=typeof t.onSessionClose?{result:!1,msg:"Initialization 'onSessionClose' parameter must be of type 'function'"}:void 0!==t.isAllowSubscribeRetry&&"boolean"!=typeof t.isAllowSubscribeRetry?{result:!1,msg:"Initialization 'isAllowSubscribeRetry' parameter must be of type 'boolean'"}:void 0!==t.isAllowPublishRetry&&"boolean"!=typeof t.isAllowPublishRetry?{result:!1,msg:"Initialization 'isAllowPublishRetry' parameter must be of type 'boolean'"}:void 0!==t.isOffCameraWhenVideoDisable&&"boolean"!=typeof t.isOffCameraWhenVideoDisable?{result:!1,msg:"Initialization 'isOffCameraWhenVideoDisable' parameter must be of type 'boolean'"}:void 0===t.joinType||(r=t.joinType,Object.values(o.RTCJoinType).includes(r))?void 0!==t.isAllowDemotionGetStream&&"boolean"!=typeof t.isAllowDemotionGetStream?{result:!1,msg:"Initialization 'isAllowDemotionGetStream' parameter must be of type 'boolean'"}:void 0===t.lang||function(o){return Object.values(e.RCCallLanguage).includes(o)}(t.lang)?void 0===t.logLevel||function(e){return Object.values(o.LogLevel).includes(e)}(t.logLevel)?void 0!==t.logStdout&&"function"!=typeof t.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},a=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}},c=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},C=o=>o===e.RCCallMediaType.AUDIO||o===e.RCCallMediaType.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},d=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},u=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},R=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[]'"};class _{constructor(o,t,r={}){this._stateMachine=o,this._rtcClient=t,this._options=r,this._listener=null,this._RETRYCOUNT=2,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:o})=>{i.info(`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${o}`)},onStateChange:o=>s(this,void 0,void 0,(function*(){const{state:t,reason:s}=o;if(i.info(`[RCCallSession onStateChange] : state->${t} reason->${s}`),t===e.RCCallSessionState.KEEPING){const o=this._stateMachine.getCallId();i.info(`[RCCallSession onStateChange] roomId: ${o}`);try{yield this._joinRoom(o)}catch(t){this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR),i.error(`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${o}`),console.error(t)}}else if(t===e.RCCallSessionState.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void n.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),i.info("[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{i.info(`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){i.error("[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{i.info(`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){i.error("[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,o)=>{i.info(`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${o}`);try{this._listener.onHungup(e,o,this)}catch(e){i.error("[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:o})=>{i.info(`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,o,this)}catch(e){i.error("[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:o,mediaType:t})=>{i.info(`[RCCallSession onMediaModify]sender: sender.userId -> ${o.userId} mediaType: ${t}`),t===e.RCCallMediaType.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(o,t,this)}catch(e){i.error("[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}}})}_joinRoom(o){return s(this,void 0,void 0,(function*(){try{const{code:s,room:r}=yield this._rtcClient.joinRTCRoom(o,this._options.joinType);if(s!==t.RCRTCCode.SUCCESS)return s===t.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(e.RCCallEndReason.SERVICE_NOT_OPENED),s===t.RCRTCCode.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(e.RCCallEndReason.OTHER_CLIENT_IN_CALL):this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR),i.info(`[RCCallClient _joinRoom] join room failed: roomId -> ${o} RCRTCCode -> ${s}`),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR};this._room=r}catch(t){return this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR),i.error(`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${o}`),console.error(t),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(t){return this._exceptionClose(e.RCCallEndReason.SUBSCRIBE_ERROR),i.error(`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${o}`),console.error(t),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(t){return this._exceptionClose(e.RCCallEndReason.PUBLISH_ERROR),i.error(`[RCCallSession _joinRoom] _publish Exception roomId -> ${o}`),console.error(t),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR}}return{code:e.RCCallErrorCode.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return s(this,void 0,void 0,(function*(){const o=this._room.getRemoteTracks();if(o.length){const{code:s}=yield this._subscribeRetry(o,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);s!==t.RCRTCCode.SUCCESS&&(this._exceptionClose(e.RCCallEndReason.SUBSCRIBE_ERROR),i.error(`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${s}`))}}))}_subscribeRetry(e,o=!1,r=0){return s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.subscribe(e);if(s!==t.RCRTCCode.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(s,this)}catch(e){i.error("[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!o)return{code:s};if(r>0)return r--,this._subscribeRetry(e,o,r)}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!==t.RCRTCCode.SUCCESS)return this._exceptionClose(e.RCCallEndReason.PUBLISH_ERROR),void i.info(`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${s}`);this._options.produceType===r.CALLEE&&this._notifyTrackReady(o)}))}_publishRetry(e,o=!1,r=0){return s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.publish(e);if(s!==t.RCRTCCode.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(s,this)}catch(e){i.error("[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!o)return{code:s};if(r>0)return r--,this._publishRetry(e,o,r)}return{code:s}}))}_leaveRoom(){return s(this,void 0,void 0,(function*(){try{const{code:e}=yield this._rtcClient.leaveRoom(this._room);i.info("[RCCallSession _leaveRoom] Successfully exited the room")}catch(e){i.error("[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();n.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const o=a(e);if(!o.result)throw new Error(`[RCCallSession registerSessionListener] ${o.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(o,r){return s(this,void 0,void 0,(function*(){if(o===e.RCCallMediaType.AUDIO){const{code:o,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",r&&r.audio&&Object.assign({},r.audio));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(i.info("[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:o,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",r&&Object.assign({},r));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(i.info("[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(o,t){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&o===e.RCCallMediaType.AUDIO_VIDEO){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO_VIDEO,t);if(o!==e.RCCallErrorCode.SUCCESS){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO,t);return o!==e.RCCallErrorCode.SUCCESS?(this._exceptionClose(e.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:o}):{code:o,tracks:i}}return{code:o,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(o,t);return i!==e.RCCallErrorCode.SUCCESS?(this._exceptionClose(e.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:i}):{code:i,tracks:s}}}))}changeAudioDevice(o){return s(this,void 0,void 0,(function*(){const s=[],r=[],{code:n,track:l}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o);if(n!==t.RCRTCCode.SUCCESS)return i.error(`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${n}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||r.push(e)})),s.push(l),r.push(l),this._options.localTracks=r,this._notifyTrackReady(s),this._room){const{code:o}=yield this._room.publish(s);if(o!==t.RCRTCCode.SUCCESS)return{code:e.RCCallErrorCode.AUDIO_PUBLISH_ERROR}}return{code:e.RCCallErrorCode.SUCCESS}}))}invite(e,o={}){return s(this,void 0,void 0,(function*(){const{extra:t="",pushTitle:i="",pushContent:s=""}=o,r=[h(e),d(t),u(i),R(s)],n=[];if(!r.every((e=>(!e.result&&n.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${n.join("\n")}`);const{code:l}=yield this._stateMachine.invite(e,{extra:t,pushTitle:i,pushContent:s});return{code:l}}))}accept(o){return s(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&&(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&&!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 o})(o);if(!t.result)throw new Error(`[RCCallSession accept] ${t.msg}`);n.emit("hungupOtherSession",{session:this});const s=this._stateMachine.getMediaType(),{code:r,tracks:l}=yield this._getLocalTrack(s,o);if(r!==e.RCCallErrorCode.SUCCESS)return{code:r};this._options.localTracks=l;const{code:a}=yield this._stateMachine.accept();return a!==e.RCCallErrorCode.SUCCESS?(i.error(`[RCCallSession accept]Send accept message failed -> code: ${a}`),{code:a}):{code:a}}))}hungup(){return s(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(o){return s(this,void 0,void 0,(function*(){const{code:t}=yield this._stateMachine.changeMediaType(o);return t!==e.RCCallErrorCode.SUCCESS&&i.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 s(this,void 0,void 0,(function*(){const{code:o,track:s}=yield this._rtcClient.createCameraVideoTrack();if(o!==t.RCRTCCode.SUCCESS)return{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:r}=yield this._room.publish([s]);r===t.RCRTCCode.SUCCESS?(this._notifyTrackReady([s]),this._changeMediaType(e.RCCallMediaType.AUDIO_VIDEO)):i.error(`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${o}`)}))}_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!==t.RCRTCCode.SUCCESS&&i.error(`[RCCallSession disableVideo] unpublish failed -> ${o}`),this._destroyTracks(e)}}))}descendAbility(){return s(this,void 0,void 0,(function*(){const{code:o}=yield this._changeMediaType(e.RCCallMediaType.AUDIO);return o===e.RCCallErrorCode.SUCCESS&&this._setMediaTypeToAudio(),{code:o}}))}disableVideoTrack(){return s(this,void 0,void 0,(function*(){const o=this._getLocalVideoTracks();if(!o.length)return i.error(`[RCCallSession disableVideoTrack] Room missing video track -> ${e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};if(o.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:e.RCCallErrorCode.SUCCESS};const{code:s}=yield this._room.unpublish(o);return s!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession disableVideo] unpublish failed -> ${s}`),{code:e.RCCallErrorCode.UNPUBLISH_VIDEO_ERROR}):(o.forEach((e=>{e.destroy()})),{code:e.RCCallErrorCode.SUCCESS})}))}enableVideoTrack(){return s(this,void 0,void 0,(function*(){if(!this._options.isOffCameraWhenVideoDisable){const o=this._getLocalVideoTracks();return o.length?(o.forEach((e=>{e.unmute()})),{code:e.RCCallErrorCode.SUCCESS}):(i.error(`[RCCallSession EnableVideoTrack] Room missing video track -> ${e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR})}const{code:o,track:s}=yield this._rtcClient.createCameraVideoTrack();if(o!==t.RCRTCCode.SUCCESS)return i.error(`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_VIDEO_TRACK_ERROR};const r=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():r.push(e)})),r.push(s),this._options.localTracks=r,s.mute();const{code:n}=yield this._room.publish([s]);return n!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${o}`),{code:e.RCCallErrorCode.VIDEO_PUBLISH_ERROR}):(s.unmute(),this._notifyTrackReady([s]),{code:e.RCCallErrorCode.SUCCESS})}))}disableAudioTrack(){return s(this,void 0,void 0,(function*(){this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return s(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){i.error("[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(o,i)=>{const s=this._rtcClient.getCurrentId();this._stateMachine.userLeave([s]),o?(i===t.RCKickReason.SERVER_KICK&&this._exceptionClose(e.RCCallEndReason.KICKED_BY_SERVER),i===t.RCKickReason.OTHER_KICK&&this._exceptionClose(e.RCCallEndReason.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR)},onMessageReceive(e,o,t,i){},onRoomAttributeChange(e,o){},onAudioMuteChange:e=>{i.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){i.error("[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{i.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){i.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!==t.RCRTCCode.SUCCESS&&i.error(`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${o}`)}})),onTrackUnpublish:e=>{},onTrackReady:o=>{this._stateMachine.getMediaType()===e.RCCallMediaType.AUDIO&&o.isVideoTrack()||this._notifyTrackReady([o])},onUserJoin:e=>{this._stateMachine.userJoin(e)},onUserLeave:e=>{i.info(`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{i.info(`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){i.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){i.error("[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){i.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()}}o.VersionManage.add("plugin-call","5.0.7"),o.VersionManage.validEngine(">=4.5.2")||i.error(`The current engine version '${o.VersionManage.getInfo().engine}' error,plugin-call required engine version at least '>=4.5.2'.`);class p{constructor(t,s,r){this._context=t,this._runtime=s,this._sessionList=[],this._rtcClient=r.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:o.RTCJoinType.COEXIST,isAllowDemotionGetStream:!1,lang:e.RCCallLanguage.ZH},r),this._callEngine=new e.RCCallEngine(this._context,s,i,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||e.RCCallLanguage.ZH}),n.on("sessionClose",(({session:e,summaryInfo:o})=>{this._removeSession(e);try{this._options.onSessionClose(e,o)}catch(e){i.error("[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),n.on("hungupOtherSession",(({session:e})=>{const o=e.getSessionId();i.info(`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${o}`),i.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++;i.info(`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e,o){i.info("[RCCallClient _onInvite] Received invite message");const t=new _(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});i.info("[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(t);try{this._options.onSession(t,o)}catch(e){i.error("[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!t._listener)throw i.error("[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=a(t._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){i.error("[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),i.info("[RCCallClient registerUserInfo] successfully register user info data")}call({targetId:o,mediaType:t=e.RCCallMediaType.AUDIO,listener:n,constraints:l,channelId:h="",extra:p="",pushTitle:g="",pushContent:f=""}){return s(this,void 0,void 0,(function*(){i.info(`[RCCallClient call] extra->${p} pushTitle->${g} pushContent->${f}`);const s=[c(o),C(t),a(n),d(p),u(g),R(f)],S=[];if(!s.every((e=>(!e.result&&S.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${S.join("\n")}`);let m=[];const{code:y,tracks:E}=yield this._getLocalTrack(t,l);if(y!==e.RCCallErrorCode.SUCCESS)return{code:y};m=E,m.forEach((e=>{n.onTrackReady(e)}));const{code:T,stateMachine:I}=yield this._callEngine.call(h,o,t,p,g,f);if(T===e.RCCallErrorCode.SUCCESS&&I){i.info("[RCCallClient call] successfully created state machine");const e=new _(I,this._rtcClient,{localTracks:m,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),i.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:T,session:e}}return i.error(`[RCCallClient call] call failed code ->: ${T}`),m.forEach((e=>{e.mute(),e.destroy()})),{code:T}}))}callInGroup({targetId:o,userIds:t,mediaType:n=e.RCCallMediaType.AUDIO,listener:l,constraints:p,channelId:g="",extra:f="",pushTitle:S="",pushContent:m=""}){return s(this,void 0,void 0,(function*(){const s=[c(o),h(t),C(n),a(l),d(f),u(S),R(m)],y=[];if(!s.every((e=>(!e.result&&y.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${y.join("\n")}`);let E=[];const{code:T,tracks:I}=yield this._getLocalTrack(n,p);if(T!==e.RCCallErrorCode.SUCCESS)return{code:T};E=I,E.forEach((e=>{l.onTrackReady(e)}));const{code:b,stateMachine:v}=yield this._callEngine.callInGroup(g,o,n,t,f,S,m);if(b===e.RCCallErrorCode.SUCCESS&&v){i.info("[RCCallClient callInGroup] successfully created state machine");const e=new _(v,this._rtcClient,{localTracks:E,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(l),this._sessionList.push(e),i.info(`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:b,session:e}}return i.info(`[RCCallClient callInGroup] callInGroup failed code -> ${b}`),E.forEach((e=>{e.mute(),e.destroy()})),{code:b}}))}_getLocalTrackCore(o,r){return s(this,void 0,void 0,(function*(){if(o===e.RCCallMediaType.AUDIO){const{code:o,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",r&&r.audio&&Object.assign({},r.audio));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(i.info("[RCCallClient _getTrack] successfully get Audio local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:o,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",r&&Object.assign({},r));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(i.info("[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(o,t){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&o===e.RCCallMediaType.AUDIO_VIDEO){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO_VIDEO,t);if(o!==e.RCCallErrorCode.SUCCESS){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO,t);return o!==e.RCCallErrorCode.SUCCESS?{code:o}:{code:o,tracks:i}}return{code:o,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(o,t);return i!==e.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:t,data:s}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return t!==o.ErrorCode.SUCCESS?(i.error("getJoinedUserInfo error",t),{code:e.RCCallErrorCode.QUERY_JOINED_USER_INFO_ERROR}):{code:e.RCCallErrorCode.SUCCESS,data:s}}))}}const g={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,o,t){const s=l(t);if(!s.result)throw new Error(`[RCCallLib installer steup]${s.msg}`);return i.setLogLevel(t.logLevel),i.setLogStdout(t.logStdout),i.warn("RCCall Version: 5.0.7, Commit: 3dcd9a3cf924b311e2169155be169d960765c55e"),new p(e,o,t)}};Object.defineProperty(exports,"RCCallEndReason",{enumerable:!0,get:function(){return e.RCCallEndReason}}),Object.defineProperty(exports,"RCCallErrorCode",{enumerable:!0,get:function(){return e.RCCallErrorCode}}),Object.defineProperty(exports,"RCCallLanguage",{enumerable:!0,get:function(){return e.RCCallLanguage}}),Object.defineProperty(exports,"RCCallMediaType",{enumerable:!0,get:function(){return e.RCCallMediaType}}),Object.defineProperty(exports,"RCCallSessionState",{enumerable:!0,get:function(){return e.RCCallSessionState}}),Object.defineProperty(exports,"RCCallUserState",{enumerable:!0,get:function(){return e.RCCallUserState}}),exports.RCCallClient=p,exports.RCCallSession=_,exports.installer=g;
|
package/dist/index.umd.js
CHANGED
|
@@ -12,4 +12,4 @@
|
|
|
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 r(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())}))}var n;!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(n||(n={}));var l=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 a=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(t.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(o.RCCallLanguage).includes(e)}(e.lang)?void 0===e.logLevel||function(e){return Object.values(t.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},c=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}},C=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},d=e=>e===o.RCCallMediaType.AUDIO||e===o.RCCallMediaType.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},u=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 R{constructor(e,t,i={}){this._stateMachine=e,this._rtcClient=t,this._options=i,this._listener=null,this._RETRYCOUNT=2,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:o})=>{s.info(`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${o}`)},onStateChange:e=>r(this,void 0,void 0,(function*(){const{state:t,reason:i}=e;if(s.info(`[RCCallSession onStateChange] : state->${t} reason->${i}`),t===o.RCCallSessionState.KEEPING){const e=this._stateMachine.getCallId();s.info(`[RCCallSession onStateChange] roomId: ${e}`);try{yield this._joinRoom(e)}catch(t){this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR),s.error(`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${e}`),console.error(t)}}else if(t===o.RCCallSessionState.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void l.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),s.info("[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{s.info(`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){s.error("[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{s.info(`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){s.error("[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,o)=>{s.info(`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${o}`);try{this._listener.onHungup(e,o,this)}catch(e){s.error("[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:o})=>{s.info(`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,o,this)}catch(e){s.error("[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:e,mediaType:t})=>{s.info(`[RCCallSession onMediaModify]sender: sender.userId -> ${e.userId} mediaType: ${t}`),t===o.RCCallMediaType.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(e,t,this)}catch(e){s.error("[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}}})}_joinRoom(e){return r(this,void 0,void 0,(function*(){try{const{code:t,room:r}=yield this._rtcClient.joinRTCRoom(e,this._options.joinType);if(t!==i.RCRTCCode.SUCCESS)return t===i.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(o.RCCallEndReason.SERVICE_NOT_OPENED),t===i.RCRTCCode.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(o.RCCallEndReason.OTHER_CLIENT_IN_CALL):this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR),s.info(`[RCCallClient _joinRoom] join room failed: roomId -> ${e} RCRTCCode -> ${t}`),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR};this._room=r}catch(t){return this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR),s.error(`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${e}`),console.error(t),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(t){return this._exceptionClose(o.RCCallEndReason.SUBSCRIBE_ERROR),s.error(`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${e}`),console.error(t),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(t){return this._exceptionClose(o.RCCallEndReason.PUBLISH_ERROR),s.error(`[RCCallSession _joinRoom] _publish Exception roomId -> ${e}`),console.error(t),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR}}return{code:o.RCCallErrorCode.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return r(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!==i.RCRTCCode.SUCCESS&&(this._exceptionClose(o.RCCallEndReason.SUBSCRIBE_ERROR),s.error(`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${t}`))}}))}_subscribeRetry(e,o=!1,t=0){return r(this,void 0,void 0,(function*(){const{code:r}=yield this._room.subscribe(e);if(r!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(r,this)}catch(e){s.error("[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!o)return{code:r};if(t>0)return t--,this._subscribeRetry(e,o,t)}return{code:r}}))}_publish(){return r(this,void 0,void 0,(function*(){const e=this._options.localTracks,{code:t}=yield this._publishRetry(e,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(t!==i.RCRTCCode.SUCCESS)return this._exceptionClose(o.RCCallEndReason.PUBLISH_ERROR),void s.info(`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${t}`);this._options.produceType===n.CALLEE&&this._notifyTrackReady(e)}))}_publishRetry(e,o=!1,t=0){return r(this,void 0,void 0,(function*(){const{code:r}=yield this._room.publish(e);if(r!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(r,this)}catch(e){s.error("[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!o)return{code:r};if(t>0)return t--,this._publishRetry(e,o,t)}return{code:r}}))}_leaveRoom(){return r(this,void 0,void 0,(function*(){try{const{code:e}=yield this._rtcClient.leaveRoom(this._room);s.info("[RCCallSession _leaveRoom] Successfully exited the room")}catch(e){s.error("[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();l.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const o=c(e);if(!o.result)throw new Error(`[RCCallSession registerSessionListener] ${o.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(e,t){return r(this,void 0,void 0,(function*(){if(e===o.RCCallMediaType.AUDIO){const{code:e,track:r}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",t&&t.audio&&Object.assign({},t.audio));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(s.info("[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:[r]})}{const{code:e,tracks:r}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",t&&Object.assign({},t));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(s.info("[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:r})}}))}_getLocalTrack(e,t){return r(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===o.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO_VIDEO,t);if(e!==o.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO,t);return e!==o.RCCallErrorCode.SUCCESS?(this._exceptionClose(o.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,t);return i!==o.RCCallErrorCode.SUCCESS?(this._exceptionClose(o.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:i}):{code:i,tracks:s}}}))}changeAudioDevice(e){return r(this,void 0,void 0,(function*(){const t=[],r=[],{code:n,track:l}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",e);if(n!==i.RCRTCCode.SUCCESS)return s.error(`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${n}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||r.push(e)})),t.push(l),r.push(l),this._options.localTracks=r,this._notifyTrackReady(t),this._room){const{code:e}=yield this._room.publish(t);if(e!==i.RCRTCCode.SUCCESS)return{code:o.RCCallErrorCode.AUDIO_PUBLISH_ERROR}}return{code:o.RCCallErrorCode.SUCCESS}}))}invite(e){return r(this,void 0,void 0,(function*(){const o=u(e);if(!o.result)throw new Error(`[RCCallSession invite] ${o.msg}`);const{code:t}=yield this._stateMachine.invite(e);return{code:t}}))}accept(e){return r(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&&(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&&!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 o})(e);if(!t.result)throw new Error(`[RCCallSession accept] ${t.msg}`);l.emit("hungupOtherSession",{session:this});const i=this._stateMachine.getMediaType(),{code:r,tracks:n}=yield this._getLocalTrack(i,e);if(r!==o.RCCallErrorCode.SUCCESS)return{code:r};this._options.localTracks=n;const{code:a}=yield this._stateMachine.accept();return a!==o.RCCallErrorCode.SUCCESS?(s.error(`[RCCallSession accept]Send accept message failed -> code: ${a}`),{code:a}):{code:a}}))}hungup(){return r(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(e){return r(this,void 0,void 0,(function*(){const{code:t}=yield this._stateMachine.changeMediaType(e);return t!==o.RCCallErrorCode.SUCCESS&&s.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 r(this,void 0,void 0,(function*(){const{code:e,track:t}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:r}=yield this._room.publish([t]);r===i.RCRTCCode.SUCCESS?(this._notifyTrackReady([t]),this._changeMediaType(o.RCCallMediaType.AUDIO_VIDEO)):s.error(`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${e}`)}))}_setMediaTypeToAudio(){return r(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&&s.error(`[RCCallSession disableVideo] unpublish failed -> ${o}`),this._destroyTracks(e)}}))}descendAbility(){return r(this,void 0,void 0,(function*(){const{code:e}=yield this._changeMediaType(o.RCCallMediaType.AUDIO);return e===o.RCCallErrorCode.SUCCESS&&this._setMediaTypeToAudio(),{code:e}}))}disableVideoTrack(){return r(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(!e.length)return s.error(`[RCCallSession disableVideoTrack] Room missing video track -> ${o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};if(e.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:o.RCCallErrorCode.SUCCESS};const{code:t}=yield this._room.unpublish(e);return t!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession disableVideo] unpublish failed -> ${t}`),{code:o.RCCallErrorCode.UNPUBLISH_VIDEO_ERROR}):(e.forEach((e=>{e.destroy()})),{code:o.RCCallErrorCode.SUCCESS})}))}enableVideoTrack(){return r(this,void 0,void 0,(function*(){if(!this._options.isOffCameraWhenVideoDisable){const e=this._getLocalVideoTracks();return e.length?(e.forEach((e=>{e.unmute()})),{code:o.RCCallErrorCode.SUCCESS}):(s.error(`[RCCallSession EnableVideoTrack] Room missing video track -> ${o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR})}const{code:e,track:t}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return s.error(`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_VIDEO_TRACK_ERROR};const r=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():r.push(e)})),r.push(t),this._options.localTracks=r,t.mute();const{code:n}=yield this._room.publish([t]);return n!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${e}`),{code:o.RCCallErrorCode.VIDEO_PUBLISH_ERROR}):(t.unmute(),this._notifyTrackReady([t]),{code:o.RCCallErrorCode.SUCCESS})}))}disableAudioTrack(){return r(this,void 0,void 0,(function*(){this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return r(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){s.error("[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(e,t)=>{const s=this._rtcClient.getCurrentId();this._stateMachine.userLeave([s]),e?(t===i.RCKickReason.SERVER_KICK&&this._exceptionClose(o.RCCallEndReason.KICKED_BY_SERVER),t===i.RCKickReason.OTHER_KICK&&this._exceptionClose(o.RCCallEndReason.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR)},onMessageReceive(e,o,t,i){},onRoomAttributeChange(e,o){},onAudioMuteChange:e=>{s.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){s.error("[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{s.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){s.error("[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>r(this,void 0,void 0,(function*(){if(this._room){const{code:o}=yield this._room.subscribe(e);o!==i.RCRTCCode.SUCCESS&&s.error(`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${o}`)}})),onTrackUnpublish:e=>{},onTrackReady:e=>{this._stateMachine.getMediaType()===o.RCCallMediaType.AUDIO&&e.isVideoTrack()||this._notifyTrackReady([e])},onUserJoin:e=>{this._stateMachine.userJoin(e)},onUserLeave:e=>{s.info(`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{s.info(`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){s.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){s.error("[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){s.error("[RCCallSession onICEConnectionStateChange] onICEConnectionStateChange exception"),console.error(e)}}})}getSessionId(){return this._stateMachine.getCallId()}getRTCSessionId(){return this._room.getSessionId()}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()}}t.VersionManage.add("plugin-call","5.0.5"),t.VersionManage.validEngine(">=4.5.2")||s.error(`The current engine version '${t.VersionManage.getInfo().engine}' error,plugin-call required engine version at least '>=4.5.2'.`);class h{constructor(e,i,r){this._context=e,this._runtime=i,this._sessionList=[],this._rtcClient=r.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:t.RTCJoinType.COEXIST,isAllowDemotionGetStream:!1,lang:o.RCCallLanguage.ZH},r),this._callEngine=new o.RCCallEngine(this._context,i,s,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||o.RCCallLanguage.ZH}),l.on("sessionClose",(({session:e,summaryInfo:o})=>{this._removeSession(e);try{this._options.onSessionClose(e,o)}catch(e){s.error("[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),l.on("hungupOtherSession",(({session:e})=>{const o=e.getSessionId();s.info(`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${o}`),s.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++;s.info(`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e){s.info("[RCCallClient _onInvite] Received invite message");const o=new R(e,this._rtcClient,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:n.CALLEE});s.info("[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(o);try{this._options.onSession(o)}catch(e){s.error("[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!o._listener)throw s.error("[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=c(o._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){s.error("[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),s.info("[RCCallClient registerUserInfo] successfully register user info data")}call({targetId:e,mediaType:t=o.RCCallMediaType.AUDIO,listener:i,constraints:l,channelId:a=""}){return r(this,void 0,void 0,(function*(){const r=[C(e),d(t),c(i)],u=[];if(!r.every((e=>(!e.result&&u.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${u.join("\n")}`);let h=[];const{code:_,tracks:f}=yield this._getLocalTrack(t,l);if(_!==o.RCCallErrorCode.SUCCESS)return{code:_};h=f,h.forEach((e=>{i.onTrackReady(e)}));const{code:g,stateMachine:p}=yield this._callEngine.call(a,e,t);if(g===o.RCCallErrorCode.SUCCESS&&p){s.info("[RCCallClient call] successfully created state machine");const e=new R(p,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:n.CALLER});return e.registerSessionListener(i),this._sessionList.push(e),s.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:g,session:e}}return s.error(`[RCCallClient call] call failed code ->: ${g}`),h.forEach((e=>{e.mute(),e.destroy()})),{code:g}}))}callInGroup({targetId:e,userIds:t,mediaType:i=o.RCCallMediaType.AUDIO,listener:l,constraints:a,channelId:h=""}){return r(this,void 0,void 0,(function*(){const r=[C(e),u(t),d(i),c(l)],_=[];if(!r.every((e=>(!e.result&&_.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${_.join("\n")}`);let f=[];const{code:g,tracks:p}=yield this._getLocalTrack(i,a);if(g!==o.RCCallErrorCode.SUCCESS)return{code:g};f=p,f.forEach((e=>{l.onTrackReady(e)}));const{code:S,stateMachine:m}=yield this._callEngine.callInGroup(h,e,i,t);if(S===o.RCCallErrorCode.SUCCESS&&m){s.info("[RCCallClient callInGroup] successfully created state machine");const e=new R(m,this._rtcClient,{localTracks:f,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:n.CALLER});return e.registerSessionListener(l),this._sessionList.push(e),s.info(`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:S,session:e}}return s.info(`[RCCallClient callInGroup] callInGroup failed code -> ${S}`),f.forEach((e=>{e.mute(),e.destroy()})),{code:S}}))}_getLocalTrackCore(e,t){return r(this,void 0,void 0,(function*(){if(e===o.RCCallMediaType.AUDIO){const{code:e,track:r}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",t&&t.audio&&Object.assign({},t.audio));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(s.info("[RCCallClient _getTrack] successfully get Audio local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:[r]})}{const{code:e,tracks:r}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",t&&Object.assign({},t));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(s.info("[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:r})}}))}_getLocalTrack(e,t){return r(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===o.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO_VIDEO,t);if(e!==o.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO,t);return e!==o.RCCallErrorCode.SUCCESS?{code:e}:{code:e,tracks:i}}return{code:e,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(e,t);return i!==o.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 r(this,void 0,void 0,(function*(){const{code:e,data:i}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return e!==t.ErrorCode.SUCCESS?(s.error("getJoinedUserInfo error",e),{code:o.RCCallErrorCode.QUERY_JOINED_USER_INFO_ERROR}):{code:o.RCCallErrorCode.SUCCESS,data:i}}))}}const _={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,o,t){const i=a(t);if(!i.result)throw new Error(`[RCCallLib installer steup]${i.msg}`);return s.setLogLevel(t.logLevel),s.setLogStdout(t.logStdout),s.warn("RCCall Version: 5.0.5, Commit: 87afc0755fbba331ed398046c2aa4f5c245a4e42"),new h(e,o,t)}};Object.defineProperty(e,"RCCallEndReason",{enumerable:!0,get:function(){return o.RCCallEndReason}}),Object.defineProperty(e,"RCCallErrorCode",{enumerable:!0,get:function(){return o.RCCallErrorCode}}),Object.defineProperty(e,"RCCallLanguage",{enumerable:!0,get:function(){return o.RCCallLanguage}}),Object.defineProperty(e,"RCCallMediaType",{enumerable:!0,get:function(){return o.RCCallMediaType}}),Object.defineProperty(e,"RCCallSessionState",{enumerable:!0,get:function(){return o.RCCallSessionState}}),Object.defineProperty(e,"RCCallUserState",{enumerable:!0,get:function(){return o.RCCallUserState}}),e.RCCallClient=h,e.RCCallSession=R,e.installer=_,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
15
|
+
***************************************************************************** */function r(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())}))}var n;!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(n||(n={}));var l=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 a=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(t.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(o.RCCallLanguage).includes(e)}(e.lang)?void 0===e.logLevel||function(e){return Object.values(t.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},c=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}},C=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},d=e=>e===o.RCCallMediaType.AUDIO||e===o.RCCallMediaType.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},u=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},R=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},h=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushContent' parameter must be of type 'string'"},_=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 p{constructor(e,t,i={}){this._stateMachine=e,this._rtcClient=t,this._options=i,this._listener=null,this._RETRYCOUNT=2,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:o})=>{s.info(`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${o}`)},onStateChange:e=>r(this,void 0,void 0,(function*(){const{state:t,reason:i}=e;if(s.info(`[RCCallSession onStateChange] : state->${t} reason->${i}`),t===o.RCCallSessionState.KEEPING){const e=this._stateMachine.getCallId();s.info(`[RCCallSession onStateChange] roomId: ${e}`);try{yield this._joinRoom(e)}catch(t){this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR),s.error(`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${e}`),console.error(t)}}else if(t===o.RCCallSessionState.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void l.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),s.info("[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{s.info(`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){s.error("[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{s.info(`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){s.error("[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,o)=>{s.info(`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${o}`);try{this._listener.onHungup(e,o,this)}catch(e){s.error("[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:o})=>{s.info(`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,o,this)}catch(e){s.error("[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:e,mediaType:t})=>{s.info(`[RCCallSession onMediaModify]sender: sender.userId -> ${e.userId} mediaType: ${t}`),t===o.RCCallMediaType.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(e,t,this)}catch(e){s.error("[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}}})}_joinRoom(e){return r(this,void 0,void 0,(function*(){try{const{code:t,room:r}=yield this._rtcClient.joinRTCRoom(e,this._options.joinType);if(t!==i.RCRTCCode.SUCCESS)return t===i.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(o.RCCallEndReason.SERVICE_NOT_OPENED),t===i.RCRTCCode.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(o.RCCallEndReason.OTHER_CLIENT_IN_CALL):this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR),s.info(`[RCCallClient _joinRoom] join room failed: roomId -> ${e} RCRTCCode -> ${t}`),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR};this._room=r}catch(t){return this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR),s.error(`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${e}`),console.error(t),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(t){return this._exceptionClose(o.RCCallEndReason.SUBSCRIBE_ERROR),s.error(`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${e}`),console.error(t),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(t){return this._exceptionClose(o.RCCallEndReason.PUBLISH_ERROR),s.error(`[RCCallSession _joinRoom] _publish Exception roomId -> ${e}`),console.error(t),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR}}return{code:o.RCCallErrorCode.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return r(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!==i.RCRTCCode.SUCCESS&&(this._exceptionClose(o.RCCallEndReason.SUBSCRIBE_ERROR),s.error(`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${t}`))}}))}_subscribeRetry(e,o=!1,t=0){return r(this,void 0,void 0,(function*(){const{code:r}=yield this._room.subscribe(e);if(r!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(r,this)}catch(e){s.error("[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!o)return{code:r};if(t>0)return t--,this._subscribeRetry(e,o,t)}return{code:r}}))}_publish(){return r(this,void 0,void 0,(function*(){const e=this._options.localTracks,{code:t}=yield this._publishRetry(e,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(t!==i.RCRTCCode.SUCCESS)return this._exceptionClose(o.RCCallEndReason.PUBLISH_ERROR),void s.info(`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${t}`);this._options.produceType===n.CALLEE&&this._notifyTrackReady(e)}))}_publishRetry(e,o=!1,t=0){return r(this,void 0,void 0,(function*(){const{code:r}=yield this._room.publish(e);if(r!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(r,this)}catch(e){s.error("[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!o)return{code:r};if(t>0)return t--,this._publishRetry(e,o,t)}return{code:r}}))}_leaveRoom(){return r(this,void 0,void 0,(function*(){try{const{code:e}=yield this._rtcClient.leaveRoom(this._room);s.info("[RCCallSession _leaveRoom] Successfully exited the room")}catch(e){s.error("[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();l.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const o=c(e);if(!o.result)throw new Error(`[RCCallSession registerSessionListener] ${o.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(e,t){return r(this,void 0,void 0,(function*(){if(e===o.RCCallMediaType.AUDIO){const{code:e,track:r}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",t&&t.audio&&Object.assign({},t.audio));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(s.info("[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:[r]})}{const{code:e,tracks:r}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",t&&Object.assign({},t));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(s.info("[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:r})}}))}_getLocalTrack(e,t){return r(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===o.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO_VIDEO,t);if(e!==o.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO,t);return e!==o.RCCallErrorCode.SUCCESS?(this._exceptionClose(o.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,t);return i!==o.RCCallErrorCode.SUCCESS?(this._exceptionClose(o.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:i}):{code:i,tracks:s}}}))}changeAudioDevice(e){return r(this,void 0,void 0,(function*(){const t=[],r=[],{code:n,track:l}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",e);if(n!==i.RCRTCCode.SUCCESS)return s.error(`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${n}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||r.push(e)})),t.push(l),r.push(l),this._options.localTracks=r,this._notifyTrackReady(t),this._room){const{code:e}=yield this._room.publish(t);if(e!==i.RCRTCCode.SUCCESS)return{code:o.RCCallErrorCode.AUDIO_PUBLISH_ERROR}}return{code:o.RCCallErrorCode.SUCCESS}}))}invite(e,o={}){return r(this,void 0,void 0,(function*(){const{extra:t="",pushTitle:i="",pushContent:s=""}=o,r=[_(e),u(t),R(i),h(s)],n=[];if(!r.every((e=>(!e.result&&n.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${n.join("\n")}`);const{code:l}=yield this._stateMachine.invite(e,{extra:t,pushTitle:i,pushContent:s});return{code:l}}))}accept(e){return r(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&&(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&&!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 o})(e);if(!t.result)throw new Error(`[RCCallSession accept] ${t.msg}`);l.emit("hungupOtherSession",{session:this});const i=this._stateMachine.getMediaType(),{code:r,tracks:n}=yield this._getLocalTrack(i,e);if(r!==o.RCCallErrorCode.SUCCESS)return{code:r};this._options.localTracks=n;const{code:a}=yield this._stateMachine.accept();return a!==o.RCCallErrorCode.SUCCESS?(s.error(`[RCCallSession accept]Send accept message failed -> code: ${a}`),{code:a}):{code:a}}))}hungup(){return r(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(e){return r(this,void 0,void 0,(function*(){const{code:t}=yield this._stateMachine.changeMediaType(e);return t!==o.RCCallErrorCode.SUCCESS&&s.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 r(this,void 0,void 0,(function*(){const{code:e,track:t}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:r}=yield this._room.publish([t]);r===i.RCRTCCode.SUCCESS?(this._notifyTrackReady([t]),this._changeMediaType(o.RCCallMediaType.AUDIO_VIDEO)):s.error(`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${e}`)}))}_setMediaTypeToAudio(){return r(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&&s.error(`[RCCallSession disableVideo] unpublish failed -> ${o}`),this._destroyTracks(e)}}))}descendAbility(){return r(this,void 0,void 0,(function*(){const{code:e}=yield this._changeMediaType(o.RCCallMediaType.AUDIO);return e===o.RCCallErrorCode.SUCCESS&&this._setMediaTypeToAudio(),{code:e}}))}disableVideoTrack(){return r(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(!e.length)return s.error(`[RCCallSession disableVideoTrack] Room missing video track -> ${o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};if(e.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:o.RCCallErrorCode.SUCCESS};const{code:t}=yield this._room.unpublish(e);return t!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession disableVideo] unpublish failed -> ${t}`),{code:o.RCCallErrorCode.UNPUBLISH_VIDEO_ERROR}):(e.forEach((e=>{e.destroy()})),{code:o.RCCallErrorCode.SUCCESS})}))}enableVideoTrack(){return r(this,void 0,void 0,(function*(){if(!this._options.isOffCameraWhenVideoDisable){const e=this._getLocalVideoTracks();return e.length?(e.forEach((e=>{e.unmute()})),{code:o.RCCallErrorCode.SUCCESS}):(s.error(`[RCCallSession EnableVideoTrack] Room missing video track -> ${o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR})}const{code:e,track:t}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return s.error(`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_VIDEO_TRACK_ERROR};const r=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():r.push(e)})),r.push(t),this._options.localTracks=r,t.mute();const{code:n}=yield this._room.publish([t]);return n!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${e}`),{code:o.RCCallErrorCode.VIDEO_PUBLISH_ERROR}):(t.unmute(),this._notifyTrackReady([t]),{code:o.RCCallErrorCode.SUCCESS})}))}disableAudioTrack(){return r(this,void 0,void 0,(function*(){this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return r(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){s.error("[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(e,t)=>{const s=this._rtcClient.getCurrentId();this._stateMachine.userLeave([s]),e?(t===i.RCKickReason.SERVER_KICK&&this._exceptionClose(o.RCCallEndReason.KICKED_BY_SERVER),t===i.RCKickReason.OTHER_KICK&&this._exceptionClose(o.RCCallEndReason.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR)},onMessageReceive(e,o,t,i){},onRoomAttributeChange(e,o){},onAudioMuteChange:e=>{s.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){s.error("[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{s.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){s.error("[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>r(this,void 0,void 0,(function*(){if(this._room){const{code:o}=yield this._room.subscribe(e);o!==i.RCRTCCode.SUCCESS&&s.error(`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${o}`)}})),onTrackUnpublish:e=>{},onTrackReady:e=>{this._stateMachine.getMediaType()===o.RCCallMediaType.AUDIO&&e.isVideoTrack()||this._notifyTrackReady([e])},onUserJoin:e=>{this._stateMachine.userJoin(e)},onUserLeave:e=>{s.info(`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{s.info(`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){s.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){s.error("[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){s.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()}}t.VersionManage.add("plugin-call","5.0.7"),t.VersionManage.validEngine(">=4.5.2")||s.error(`The current engine version '${t.VersionManage.getInfo().engine}' error,plugin-call required engine version at least '>=4.5.2'.`);class g{constructor(e,i,r){this._context=e,this._runtime=i,this._sessionList=[],this._rtcClient=r.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:t.RTCJoinType.COEXIST,isAllowDemotionGetStream:!1,lang:o.RCCallLanguage.ZH},r),this._callEngine=new o.RCCallEngine(this._context,i,s,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||o.RCCallLanguage.ZH}),l.on("sessionClose",(({session:e,summaryInfo:o})=>{this._removeSession(e);try{this._options.onSessionClose(e,o)}catch(e){s.error("[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),l.on("hungupOtherSession",(({session:e})=>{const o=e.getSessionId();s.info(`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${o}`),s.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++;s.info(`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e,o){s.info("[RCCallClient _onInvite] Received invite message");const t=new p(e,this._rtcClient,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:n.CALLEE});s.info("[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(t);try{this._options.onSession(t,o)}catch(e){s.error("[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!t._listener)throw s.error("[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=c(t._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){s.error("[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),s.info("[RCCallClient registerUserInfo] successfully register user info data")}call({targetId:e,mediaType:t=o.RCCallMediaType.AUDIO,listener:i,constraints:l,channelId:a="",extra:_="",pushTitle:g="",pushContent:f=""}){return r(this,void 0,void 0,(function*(){s.info(`[RCCallClient call] extra->${_} pushTitle->${g} pushContent->${f}`);const r=[C(e),d(t),c(i),u(_),R(g),h(f)],S=[];if(!r.every((e=>(!e.result&&S.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${S.join("\n")}`);let m=[];const{code:y,tracks:E}=yield this._getLocalTrack(t,l);if(y!==o.RCCallErrorCode.SUCCESS)return{code:y};m=E,m.forEach((e=>{i.onTrackReady(e)}));const{code:T,stateMachine:b}=yield this._callEngine.call(a,e,t,_,g,f);if(T===o.RCCallErrorCode.SUCCESS&&b){s.info("[RCCallClient call] successfully created state machine");const e=new p(b,this._rtcClient,{localTracks:m,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:n.CALLER});return e.registerSessionListener(i),this._sessionList.push(e),s.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:T,session:e}}return s.error(`[RCCallClient call] call failed code ->: ${T}`),m.forEach((e=>{e.mute(),e.destroy()})),{code:T}}))}callInGroup({targetId:e,userIds:t,mediaType:i=o.RCCallMediaType.AUDIO,listener:l,constraints:a,channelId:g="",extra:f="",pushTitle:S="",pushContent:m=""}){return r(this,void 0,void 0,(function*(){const r=[C(e),_(t),d(i),c(l),u(f),R(S),h(m)],y=[];if(!r.every((e=>(!e.result&&y.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${y.join("\n")}`);let E=[];const{code:T,tracks:b}=yield this._getLocalTrack(i,a);if(T!==o.RCCallErrorCode.SUCCESS)return{code:T};E=b,E.forEach((e=>{l.onTrackReady(e)}));const{code:I,stateMachine:v}=yield this._callEngine.callInGroup(g,e,i,t,f,S,m);if(I===o.RCCallErrorCode.SUCCESS&&v){s.info("[RCCallClient callInGroup] successfully created state machine");const e=new p(v,this._rtcClient,{localTracks:E,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:n.CALLER});return e.registerSessionListener(l),this._sessionList.push(e),s.info(`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:I,session:e}}return s.info(`[RCCallClient callInGroup] callInGroup failed code -> ${I}`),E.forEach((e=>{e.mute(),e.destroy()})),{code:I}}))}_getLocalTrackCore(e,t){return r(this,void 0,void 0,(function*(){if(e===o.RCCallMediaType.AUDIO){const{code:e,track:r}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",t&&t.audio&&Object.assign({},t.audio));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(s.info("[RCCallClient _getTrack] successfully get Audio local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:[r]})}{const{code:e,tracks:r}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",t&&Object.assign({},t));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(s.info("[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:r})}}))}_getLocalTrack(e,t){return r(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===o.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO_VIDEO,t);if(e!==o.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO,t);return e!==o.RCCallErrorCode.SUCCESS?{code:e}:{code:e,tracks:i}}return{code:e,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(e,t);return i!==o.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 r(this,void 0,void 0,(function*(){const{code:e,data:i}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return e!==t.ErrorCode.SUCCESS?(s.error("getJoinedUserInfo error",e),{code:o.RCCallErrorCode.QUERY_JOINED_USER_INFO_ERROR}):{code:o.RCCallErrorCode.SUCCESS,data:i}}))}}const f={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,o,t){const i=a(t);if(!i.result)throw new Error(`[RCCallLib installer steup]${i.msg}`);return s.setLogLevel(t.logLevel),s.setLogStdout(t.logStdout),s.warn("RCCall Version: 5.0.7, Commit: 3dcd9a3cf924b311e2169155be169d960765c55e"),new g(e,o,t)}};Object.defineProperty(e,"RCCallEndReason",{enumerable:!0,get:function(){return o.RCCallEndReason}}),Object.defineProperty(e,"RCCallErrorCode",{enumerable:!0,get:function(){return o.RCCallErrorCode}}),Object.defineProperty(e,"RCCallLanguage",{enumerable:!0,get:function(){return o.RCCallLanguage}}),Object.defineProperty(e,"RCCallMediaType",{enumerable:!0,get:function(){return o.RCCallMediaType}}),Object.defineProperty(e,"RCCallSessionState",{enumerable:!0,get:function(){return o.RCCallSessionState}}),Object.defineProperty(e,"RCCallUserState",{enumerable:!0,get:function(){return o.RCCallUserState}}),e.RCCallClient=g,e.RCCallSession=p,e.installer=f,Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rongcloud/plugin-call",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.7",
|
|
4
4
|
"description": "@rongcloud/plugin-call",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"__attrs__": {
|
|
@@ -33,12 +33,10 @@
|
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"@rongcloud/engine": ">=4.5.2",
|
|
36
|
-
"@rongcloud/plugin-rtc": "
|
|
36
|
+
"@rongcloud/plugin-rtc": "^5.2.2"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@rongcloud/plugin-call-engine": "
|
|
40
|
-
"@rongcloud/engine": ">=4.5.2",
|
|
41
|
-
"@rongcloud/plugin-rtc": "~5.2.2"
|
|
39
|
+
"@rongcloud/plugin-call-engine": "^5.0.6"
|
|
42
40
|
},
|
|
43
|
-
"__commit__": "
|
|
41
|
+
"__commit__": "3dcd9a3cf924b311e2169155be169d960765c55e"
|
|
44
42
|
}
|