@rongcloud/plugin-call 5.0.2 → 5.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
- * RCCall - v5.0.2
3
- * CommitId - f0959f27d32f3dccbae8442b88461249a35bd893
4
- * Thu Oct 28 2021 17:26:36 GMT+0800 (China Standard Time)
2
+ * RCCall - v5.0.5
3
+ * CommitId - 87afc0755fbba331ed398046c2aa4f5c245a4e42
4
+ * Thu Dec 09 2021 18:19:17 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';
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import{RCCallMediaType as e,RCCallLanguage as o,RCCallSessionState as t,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 a,LogLevel as l,ConversationType as c,VersionManage as d,ErrorCode as u}from"@rongcloud/engine";import{RCRTCCode as C,RCKickReason as h}from"@rongcloud/plugin-rtc";const _=new r("RCCall");
1
+ import{RCCallMediaType as e,RCCallLanguage as o,RCCallSessionState as t,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 a,LogLevel as l,VersionManage as c,ErrorCode as d}from"@rongcloud/engine";import{RCRTCCode as u,RCKickReason as C}from"@rongcloud/plugin-rtc";const h=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 R(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 f;!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(f||(f={}));var g=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 S=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},p=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}},m=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},y=o=>o===e.AUDIO||o===e.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},T=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 E{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})=>{_.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:o,reason:s}=e;if(_.info(`[RCCallSession onStateChange] : state->${o} reason->${s}`),o===t.KEEPING){const e=this._stateMachine.getCallId();_.info(`[RCCallSession onStateChange] roomId: ${e}`);try{yield this._joinRoom(e)}catch(o){this._exceptionClose(i.NETWORK_ERROR),_.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 g.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),_.info("[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{_.info(`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){_.error("[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{_.info(`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){_.error("[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,o)=>{_.info(`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${o}`);try{this._listener.onHungup(e,o,this)}catch(e){_.error("[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:o})=>{_.info(`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,o,this)}catch(e){_.error("[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:o,mediaType:t})=>{_.info(`[RCCallSession onMediaModify]sender: sender.userId -> ${o.userId} mediaType: ${t}`),t===e.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(o,t,this)}catch(e){_.error("[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}}})}_joinRoom(e){return R(this,void 0,void 0,(function*(){try{const{code:o,room:t}=yield this._rtcClient.joinRTCRoom(e,this._options.joinType);if(o!==C.SUCCESS)return o===C.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(i.SERVICE_NOT_OPENED),o===C.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(i.OTHER_CLIENT_IN_CALL):this._exceptionClose(i.NETWORK_ERROR),_.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),_.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),_.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),_.error(`[RCCallSession _joinRoom] _publish Exception roomId -> ${e}`),console.error(o),{code:s.JOIN_ROOM_ERROR}}return{code:s.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return R(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!==C.SUCCESS&&(this._exceptionClose(i.SUBSCRIBE_ERROR),_.error(`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${o}`))}}))}_subscribeRetry(e,o=!1,t=0){return R(this,void 0,void 0,(function*(){const{code:i}=yield this._room.subscribe(e);if(i!==C.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(i,this)}catch(e){_.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 R(this,void 0,void 0,(function*(){const e=this._options.localTracks,{code:o}=yield this._publishRetry(e,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(o!==C.SUCCESS)return this._exceptionClose(i.PUBLISH_ERROR),void _.info(`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${o}`);this._options.produceType===f.CALLEE&&this._notifyTrackReady(e)}))}_publishRetry(e,o=!1,t=0){return R(this,void 0,void 0,(function*(){const{code:i}=yield this._room.publish(e);if(i!==C.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(i,this)}catch(e){_.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 R(this,void 0,void 0,(function*(){try{const{code:e}=yield this._rtcClient.leaveRoom(this._room);_.info("[RCCallSession _leaveRoom] Successfully exited the room")}catch(e){_.error("[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();g.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const o=p(e);if(!o.result)throw new Error(`[RCCallSession registerSessionListener] ${o.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(o,t){return R(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!==C.SUCCESS?(_.error(`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_TRACK_ERROR}):(_.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!==C.SUCCESS?(_.error(`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(_.info("[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:s.SUCCESS,tracks:o})}}))}_getLocalTrack(o,t){return R(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 R(this,void 0,void 0,(function*(){const o=[],t=[],{code:i,track:n}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",e);if(i!==C.SUCCESS)return _.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!==C.SUCCESS)return{code:s.AUDIO_PUBLISH_ERROR}}return{code:s.SUCCESS}}))}invite(e){return R(this,void 0,void 0,(function*(){if(this._stateMachine.getConversationType()!==c.GROUP)return{code:s.CONVERSATION_NOT_GROUP_ERROR};const o=T(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 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}`);g.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?(_.error(`[RCCallSession accept]Send accept message failed -> code: ${r}`),{code:r}):{code:r}}))}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:o}=yield this._stateMachine.changeMediaType(e);return o!==s.SUCCESS&&_.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 R(this,void 0,void 0,(function*(){const{code:o,track:t}=yield this._rtcClient.createCameraVideoTrack();if(o!==C.SUCCESS)return{code:s.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:i}=yield this._room.publish([t]);i===C.SUCCESS?(this._notifyTrackReady([t]),this._changeMediaType(e.AUDIO_VIDEO)):_.error(`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${o}`)}))}_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!==C.SUCCESS&&_.error(`[RCCallSession disableVideo] unpublish failed -> ${o}`),this._destroyTracks(e)}}))}descendAbility(){return R(this,void 0,void 0,(function*(){const{code:o}=yield this._changeMediaType(e.AUDIO);return o===s.SUCCESS&&this._setMediaTypeToAudio(),{code:o}}))}disableVideoTrack(){return R(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(!e.length)return _.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!==C.SUCCESS?(_.error(`[RCCallSession disableVideo] unpublish failed -> ${o}`),{code:s.UNPUBLISH_VIDEO_ERROR}):(e.forEach((e=>{e.destroy()})),{code:s.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:s.SUCCESS}):(_.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!==C.SUCCESS)return _.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!==C.SUCCESS?(_.error(`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${e}`),{code:s.VIDEO_PUBLISH_ERROR}):(o.unmute(),this._notifyTrackReady([o]),{code:s.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){_.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===h.SERVER_KICK&&this._exceptionClose(i.KICKED_BY_SERVER),o===h.OTHER_KICK&&this._exceptionClose(i.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(i.NETWORK_ERROR)},onMessageReceive(e,o,t,i){},onRoomAttributeChange(e,o){},onAudioMuteChange:e=>{_.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){_.error("[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{_.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){_.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!==C.SUCCESS&&_.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=>{_.info(`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{_.info(`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){_.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){_.error("[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){_.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()}}d.add("plugin-call","5.0.2"),d.validEngine("~4.5.0")||_.error(`The current engine version '${d.getInfo().engine}' error,plugin-call required engine version at least '~4.5.0'.`);class I{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,_,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||o.ZH}),g.on("sessionClose",(({session:e,summaryInfo:o})=>{this._removeSession(e);try{this._options.onSessionClose(e,o)}catch(e){_.error("[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),g.on("hungupOtherSession",(({session:e})=>{const o=e.getSessionId();_.info(`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${o}`),_.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++;_.info(`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e){_.info("[RCCallClient _onInvite] Received invite message");const o=new E(e,this._rtcClient,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:f.CALLEE});_.info("[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(o);try{this._options.onSession(o)}catch(e){_.error("[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!o._listener)throw _.error("[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=p(o._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){_.error("[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),_.info("[RCCallClient registerUserInfo] successfully register user info data")}call({targetId:o,mediaType:t=e.AUDIO,listener:i,constraints:n,channelId:r=""}){return R(this,void 0,void 0,(function*(){const e=[m(o),y(t),p(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){_.info("[RCCallClient call] successfully created state machine");const e=new E(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:f.CALLER});return e.registerSessionListener(i),this._sessionList.push(e),_.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:u,session:e}}return _.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 R(this,void 0,void 0,(function*(){const e=[m(o),T(t),y(i),p(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:h}=yield this._callEngine.callInGroup(a,o,i,t);if(C===s.SUCCESS&&h){_.info("[RCCallClient callInGroup] successfully created state machine");const e=new E(h,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:f.CALLER});return e.registerSessionListener(n),this._sessionList.push(e),_.info(`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:C,session:e}}return _.info(`[RCCallClient callInGroup] callInGroup failed code -> ${C}`),c.forEach((e=>{e.mute(),e.destroy()})),{code:C}}))}_getLocalTrackCore(o,t){return R(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!==C.SUCCESS?(_.error(`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_TRACK_ERROR}):(_.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!==C.SUCCESS?(_.error(`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${e}`),{code:s.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(_.info("[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:s.SUCCESS,tracks:o})}}))}_getLocalTrack(o,t){return R(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 R(this,void 0,void 0,(function*(){const{code:e,data:o}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return e!==u.SUCCESS?(_.error("getJoinedUserInfo error",e),{code:s.QUERY_JOINED_USER_INFO_ERROR}):{code:s.SUCCESS,data:o}}))}}const b={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,o,t){const i=S(t);if(!i.result)throw new Error(`[RCCallLib installer steup]${i.msg}`);return _.setLogLevel(t.logLevel),_.setLogStdout(t.logStdout),_.warn("RCCall Version: 5.0.2, Commit: f0959f27d32f3dccbae8442b88461249a35bd893"),new I(e,o,t)}};export{I as RCCallClient,E as RCCallSession,b as installer};
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};
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(t){return s(this,void 0,void 0,(function*(){if(this._stateMachine.getConversationType()!==o.ConversationType.GROUP)return{code:e.RCCallErrorCode.CONVERSATION_NOT_GROUP_ERROR};const i=d(t);if(!i.result)throw new Error(`[RCCallSession invite] ${i.msg}`);const{code:s}=yield this._stateMachine.invite(t);return{code:s}}))}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.2"),o.VersionManage.validEngine("~4.5.0")||i.error(`The current engine version '${o.VersionManage.getInfo().engine}' error,plugin-call required engine version at least '~4.5.0'.`);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.2, Commit: f0959f27d32f3dccbae8442b88461249a35bd893"),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=>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;
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*(){if(this._stateMachine.getConversationType()!==t.ConversationType.GROUP)return{code:o.RCCallErrorCode.CONVERSATION_NOT_GROUP_ERROR};const i=u(e);if(!i.result)throw new Error(`[RCCallSession invite] ${i.msg}`);const{code:s}=yield this._stateMachine.invite(e);return{code:s}}))}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.2"),t.VersionManage.validEngine("~4.5.0")||s.error(`The current engine version '${t.VersionManage.getInfo().engine}' error,plugin-call required engine version at least '~4.5.0'.`);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.2, Commit: f0959f27d32f3dccbae8442b88461249a35bd893"),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=>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})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rongcloud/plugin-call",
3
- "version": "5.0.2",
3
+ "version": "5.0.5",
4
4
  "description": "@rongcloud/plugin-call",
5
5
  "main": "./dist/index.js",
6
6
  "__attrs__": {
@@ -32,11 +32,13 @@
32
32
  "node": ">=10.0.0"
33
33
  },
34
34
  "peerDependencies": {
35
- "@rongcloud/engine": "~4.5.0",
36
- "@rongcloud/plugin-rtc": "~5.2.0"
35
+ "@rongcloud/engine": ">=4.5.2",
36
+ "@rongcloud/plugin-rtc": "~5.2.2"
37
37
  },
38
38
  "dependencies": {
39
- "@rongcloud/plugin-call-engine": "~5.0.2"
39
+ "@rongcloud/plugin-call-engine": "~5.0.5",
40
+ "@rongcloud/engine": ">=4.5.2",
41
+ "@rongcloud/plugin-rtc": "~5.2.2"
40
42
  },
41
- "__commit__": "f0959f27d32f3dccbae8442b88461249a35bd893"
43
+ "__commit__": "87afc0755fbba331ed398046c2aa4f5c245a4e42"
42
44
  }