@rongcloud/plugin-call 5.1.2 → 5.1.3

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.1.2
3
- * CommitId - 89ba2ed5a9c788362ba96f084fdc3c18106a64c4
4
- * Thu Mar 16 2023 10:30:56 GMT+0800 (China Standard Time)
2
+ * RCCall - v5.1.3
3
+ * CommitId - c1ec87082611a289263c27c340ee414ee9e60ba8
4
+ * Fri Apr 21 2023 12:01:49 GMT+0800 (China Standard Time)
5
5
  * ©2020 RongCloud, Inc. All rights reserved.
6
6
  */
7
7
  import { ILogger, ConversationType, RTCJoinType, LogLevel, RTCPluginContext, IRuntime, BasicLogger, IRTCJoinedInfo, IPluginGenerator } from '@rongcloud/engine';
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import{RTCJoinType as e,LogLevel as t,ErrorCode as o,VersionManage as i}from"@rongcloud/engine";import{RCCallMediaType as s,RCCallLanguage as n,RCCallSessionState as r,RCCallEndReason as l,RCCallErrorCode as a,RCCallEngine as c}from"@rongcloud/plugin-call-engine";export{RCCallEndReason,RCCallErrorCode,RCCallLanguage,RCCallMediaType,RCCallSessionState,RCCallUserState}from"@rongcloud/plugin-call-engine";import{RCRTCCode as h,RCKickReason as u}from"@rongcloud/plugin-rtc";
1
+ import{RTCJoinType as e,LogLevel as t,ErrorCode as o,VersionManage as i}from"@rongcloud/engine";import{RCCallMediaType as s,RCCallLanguage as n,RCCallSessionState as r,RCCallEndReason as l,RCCallErrorCode as a,RCCallEngine as c}from"@rongcloud/plugin-call-engine";export{RCCallEndReason,RCCallErrorCode,RCCallLanguage,RCCallMediaType,RCCallSessionState,RCCallUserState}from"@rongcloud/plugin-call-engine";import{RCResolution as h,RCRTCCode as u,RCKickReason as d}from"@rongcloud/plugin-rtc";
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 d(e,t,o,i){return new(o||(o=Promise))((function(s,n){function r(e){try{a(i.next(e))}catch(e){n(e)}}function l(e){try{a(i.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?s(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(r,l)}a((i=i.apply(e,t||[])).next())}))}var _;!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(_||(_={}));var C=new class{constructor(){this.list={}}on(e,t){return(this.list[e]||(this.list[e]=[])).push(t),this}once(e,t){const o=i=>{this.off(e,o),t.call(this,i)};o.fun=t,this.on(e,o)}off(e,t){const o=this.list[e];if(!o)return!1;if(t){let e;for(let i=0,s=o.length;i<s;i++)if(e=o[i],e===t||e.fun===t){o.splice(i,1);break}}else o&&(o.length=0)}emit(e,t){const o=[...this.list[e]];if(!o||0===o.length)return!1;o.forEach((e=>{e.call(this,t)}))}};const g=o=>{if(!o)return{result:!1,msg:"Initialization missing parameter -> options"};if("object"!=typeof o)return{result:!1,msg:"Initialization options must be an object"};const i=Object.keys(o),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 o.rtcClient?{result:!1,msg:"Initialization 'rtcClient' parameter must be of type 'object'"}:"function"!=typeof o.onSession?{result:!1,msg:"Initialization 'onSession' parameter must be of type 'function'"}:"function"!=typeof o.onSessionClose?{result:!1,msg:"Initialization 'onSessionClose' parameter must be of type 'function'"}:void 0!==o.isAllowSubscribeRetry&&"boolean"!=typeof o.isAllowSubscribeRetry?{result:!1,msg:"Initialization 'isAllowSubscribeRetry' parameter must be of type 'boolean'"}:void 0!==o.isAllowPublishRetry&&"boolean"!=typeof o.isAllowPublishRetry?{result:!1,msg:"Initialization 'isAllowPublishRetry' parameter must be of type 'boolean'"}:void 0!==o.isOffCameraWhenVideoDisable&&"boolean"!=typeof o.isOffCameraWhenVideoDisable?{result:!1,msg:"Initialization 'isOffCameraWhenVideoDisable' parameter must be of type 'boolean'"}:void 0===o.joinType||(r=o.joinType,Object.values(e).includes(r))?void 0!==o.isAllowDemotionGetStream&&"boolean"!=typeof o.isAllowDemotionGetStream?{result:!1,msg:"Initialization 'isAllowDemotionGetStream' parameter must be of type 'boolean'"}:void 0===o.lang||function(e){return Object.values(n).includes(e)}(o.lang)?void 0===o.logLevel||function(e){return Object.values(t).includes(e)}(o.logLevel)?void 0!==o.logStdout&&"function"!=typeof o.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},R=e=>{if(!e)return{result:!1,msg:"missing parameter -> listener"};if("object"!=typeof e)return{result:!1,msg:"listener must be an object"};const t=Object.keys(e),o=[];return["onRinging","onAccept","onHungup","onTrackReady"].forEach((e=>{t.includes(e)||o.push(e)})),o.length?{result:!1,msg:`missing parameter -> "${o.join(",")}"`}:"function"!=typeof e.onRinging?{result:!1,msg:"'onRinging' parameter must be of type 'function'"}:"function"!=typeof e.onAccept?{result:!1,msg:"'onAccept' parameter must be of type 'function'"}:"function"!=typeof e.onHungup?{result:!1,msg:"'onHungup' parameter must be of type 'function'"}:"function"!=typeof e.onTrackReady?{result:!1,msg:"'onTrackReady' parameter must be of type 'function'"}:{result:!0}},p=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},f=e=>e===s.AUDIO||e===s.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},m=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},S=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},T=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushContent' parameter must be of type 'string'"},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 I{constructor(e,t){this._timerId=0,this._startTime=0,e&&(this._timerId=((e,t)=>setTimeout(e,t))((()=>{e()}),t)),this._startTime=Date.now()}stop(){clearTimeout(this._timerId);const e=Date.now();let t=e-this._startTime;return 0===this._startTime&&(t=0),{startTime:this._startTime,endTime:e,duration:t}}reset(){this._startTime=0}}class E{constructor(e,t,o,i={}){this._stateMachine=e,this._rtcClient=t,this._logger=o,this._options=i,this._listener=null,this._RETRYCOUNT=2,this.joinRoomTimer=null,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:t})=>{this._logger.info("_",`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${t}`)},onStateChange:e=>d(this,void 0,void 0,(function*(){const{state:t,reason:o}=e;if(this._logger.info("_",`[RCCallSession onStateChange] : state->${t} reason->${o}`),t===r.KEEPING){const e=this._stateMachine.getCallId();this._logger.info("_",`[RCCallSession onStateChange] roomId: ${e}`);try{yield this._joinRoom(e)}catch(t){this._exceptionClose(l.NETWORK_ERROR),this._logger.error("_",`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${e}`),console.error(t)}}else if(t===r.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void C.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._logger.info("_","[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{this._logger.info("_",`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){this._logger.error("_","[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{this._logger.info("_",`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){this._logger.error("_","[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,t)=>{this._logger.info("_",`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${t}`);try{this._listener.onHungup(e,t,this)}catch(e){this._logger.error("_","[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:t})=>{this._logger.info("_",`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,t,this)}catch(e){this._logger.error("_","[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:e,mediaType:t})=>{this._logger.info("_",`[RCCallSession onMediaModify]sender: sender.userId -> ${e.userId} mediaType: ${t}`),t===s.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(e,t,this)}catch(e){this._logger.error("_","[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}},crossAppkey:e=>{this._logger.info("_",`[RCCallSession crossAppkey] 是否跨 appkey: ${e}`),this._options.isCrossAppkey=e}});const{pushTitle:n,pushContent:a}=this._options.hungupPushConfig;this._stateMachine.setHungupPushConfig(n,a)}_joinRoom(e){return d(this,void 0,void 0,(function*(){let t;try{t=this._options.isCrossAppkey?yield this._rtcClient.joinCrossRTCRoom(e,this._options.joinType):yield this._rtcClient.joinRTCRoom(e,this._options.joinType);const{code:o,userIds:i,room:s}=t;if(o!==h.SUCCESS)return o===h.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(l.SERVICE_NOT_OPENED),o===h.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(l.OTHER_CLIENT_IN_CALL):this._exceptionClose(l.NETWORK_ERROR),this._logger.info("_",`[RCCallClient _joinRoom] join room failed: roomId -> ${e} RCRTCCode -> ${o}`),{code:a.JOIN_ROOM_ERROR};if(this._stateMachine.getState()===r.END)return yield this._rtcClient.leaveRoom(s),this._room=null,{code:a.SUCCESS};i.length<1&&(this.joinRoomTimer=new I((()=>{this._exceptionClose(l.REMOTE_NETWORK_ERROR)}),6e4)),this._room=s}catch(t){return this._exceptionClose(l.NETWORK_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${e}`),console.error(t),{code:a.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(t){return this._exceptionClose(l.SUBSCRIBE_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${e}`),console.error(t),{code:a.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(t){return this._exceptionClose(l.PUBLISH_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _publish Exception roomId -> ${e}`),console.error(t),{code:a.JOIN_ROOM_ERROR}}return{code:a.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return d(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!==h.SUCCESS&&(this._exceptionClose(l.SUBSCRIBE_ERROR),this._logger.error("_",`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${t}`))}}))}_subscribeRetry(e,t=!1,o=0){return d(this,void 0,void 0,(function*(){const{code:i}=yield this._room.subscribe(e);if(i!==h.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(i,this)}catch(e){this._logger.error("_","[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!t)return{code:i};if(o>0)return o--,this._subscribeRetry(e,t,o)}return{code:i}}))}_publish(){return d(this,void 0,void 0,(function*(){const e=this._options.localTracks,{code:t}=yield this._publishRetry(e,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(t!==h.SUCCESS)return this._exceptionClose(l.PUBLISH_ERROR),void this._logger.info("_",`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${t}`);this._options.produceType===_.CALLEE&&this._notifyTrackReady(e)}))}_publishRetry(e,t=!1,o=0){return d(this,void 0,void 0,(function*(){const{code:i}=yield this._room.publish(e);if(i!==h.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(i,this)}catch(e){this._logger.error("_","[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!t)return{code:i};if(o>0)return o--,this._publishRetry(e,t,o)}return{code:i}}))}_leaveRoom(){return d(this,void 0,void 0,(function*(){try{const e=yield this._rtcClient.leaveRoom(this._room);this._logger.info("_",`[RCCallSession _leaveRoom] Successfully exited the room code: ${e.code}`)}catch(e){this._logger.error("_","[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();C.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const t=R(e);if(!t.result)throw new Error(`[RCCallSession registerSessionListener] ${t.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(e,t){return d(this,void 0,void 0,(function*(){if(e===s.AUDIO){const{code:e,track:o}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",t&&t.audio&&Object.assign({},t.audio));return e!==h.SUCCESS?(this._logger.error("_",`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${e}`),{code:a.GET_LOCAL_AUDIO_TRACK_ERROR}):(this._logger.info("_","[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:a.SUCCESS,tracks:[o]})}{const{code:e,tracks:o}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",t&&Object.assign({},t));return e!==h.SUCCESS?(this._logger.error("_",`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${e}`),{code:a.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(this._logger.info("_","[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:a.SUCCESS,tracks:o})}}))}_getLocalTrack(e,t){return d(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===s.AUDIO_VIDEO){const{code:e,tracks:o}=yield this._getLocalTrackCore(s.AUDIO_VIDEO,t);if(e!==a.SUCCESS){const{code:e,tracks:o}=yield this._getLocalTrackCore(s.AUDIO,t);return e!==a.SUCCESS?(this._exceptionClose(l.GET_MEDIA_RESOURCES_ERROR),{code:e}):{code:e,tracks:o}}return{code:e,tracks:o}}{const{code:o,tracks:i}=yield this._getLocalTrackCore(e,t);return o!==a.SUCCESS?(this._exceptionClose(l.GET_MEDIA_RESOURCES_ERROR),{code:o}):{code:o,tracks:i}}}))}changeAudioDevice(e){return d(this,void 0,void 0,(function*(){const t=[],o=[],{code:i,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",e);if(i!==h.SUCCESS)return this._logger.error("_",`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${i}`),{code:a.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||o.push(e)})),t.push(s),o.push(s),this._options.localTracks=o,this._notifyTrackReady(t),this._room){const{code:e}=yield this._room.publish(t);if(e!==h.SUCCESS)return{code:a.AUDIO_PUBLISH_ERROR}}return{code:a.SUCCESS}}))}invite(e,t={}){var o,i;return d(this,void 0,void 0,(function*(){const{extra:s=""}=t,{pushTitle:n="",pushContent:r=""}=(null===(o=this._options.callPushConfig)||void 0===o?void 0:o.pushTitle)||(null===(i=this._options.callPushConfig)||void 0===i?void 0:i.pushContent)?this._options.callPushConfig:t,l=[y(e),m(s),S(n),T(r)],a=[];if(!l.every((e=>(!e.result&&a.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${a.join("\n")}`);const{code:c}=yield this._stateMachine.invite(e,{extra:s,pushTitle:n,pushContent:r});return{code:c}}))}accept(e){return d(this,void 0,void 0,(function*(){const t=(e=>{return e&&e.audio&&void 0!==e.audio.micphoneId&&"string"!=typeof e.audio.micphoneId?{result:!1,msg:"'constraints.audio.micphoneId' must be of type 'string'"}:e&&e.audio&&void 0!==e.audio.sampleRate&&"number"!=typeof e.audio.sampleRate?{result:!1,msg:"'constraints.audio.sampleRate' must be of type 'number'"}:e&&e.video&&void 0!==e.video.cameraId&&"string"!=typeof e.video.cameraId?{result:!1,msg:"'constraints.video.cameraId' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&"string"!=typeof e.video.frameRate?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&(t=e.video.frameRate,!["FPS_10","FPS_15","FPS_24","FPS_30"].includes(t))?{result:!1,msg:"'frameRate' value is out of range"}:e&&e.video&&void 0!==e.video.resolution&&"string"!=typeof e.video.resolution?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.resolution&&!function(e){return["W176_H132","W176_H144","W256_H144","W320_H180","W240_H240","W320_H240","W480_H360","W640_H360","W480_H480","W640_H480","W720_H480","W1280_H720","W1920_H1080"].includes(e)}(e.video.resolution)?{result:!1,msg:"'resolution' value is out of range"}:!e||!e.video||e.video.frameRate&&e.video.resolution?{result:!0}:{result:!1,msg:"'resolution' and 'resolution' is required"};var t})(e);if(!t.result)throw new Error(`[RCCallSession accept] ${t.msg}`);C.emit("hungupOtherSession",{session:this});const o=this._stateMachine.getMediaType(),{code:i,tracks:s}=yield this._getLocalTrack(o,e);if(i!==a.SUCCESS)return{code:i};this._options.localTracks=s;const{code:n}=yield this._stateMachine.accept();return n!==a.SUCCESS?(this._logger.error("_",`[RCCallSession accept]Send accept message failed -> code: ${n}`),{code:n}):{code:n}}))}hungup(){return d(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(e){return d(this,void 0,void 0,(function*(){const{code:t}=yield this._stateMachine.changeMediaType(e);return t!==a.SUCCESS&&this._logger.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 d(this,void 0,void 0,(function*(){const{code:e,track:t}=yield this._rtcClient.createCameraVideoTrack();if(e!==h.SUCCESS)return{code:a.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:o}=yield this._room.publish([t]);o===h.SUCCESS?(this._notifyTrackReady([t]),this._changeMediaType(s.AUDIO_VIDEO)):this._logger.error("_",`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${e}`)}))}_setMediaTypeToAudio(){return d(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(e.length){e.forEach((e=>{e.mute()}));const{code:t}=yield this._room.unpublish(e);t!==h.SUCCESS&&this._logger.error("_",`[RCCallSession disableVideo] unpublish failed -> ${t}`),this._destroyTracks(e)}}))}descendAbility(){return d(this,void 0,void 0,(function*(){const{code:e}=yield this._changeMediaType(s.AUDIO);return e===a.SUCCESS&&this._setMediaTypeToAudio(),{code:e}}))}disableVideoTrack(){return d(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${a.NOT_IN_ROOM_ERROR}`),{code:a.NOT_IN_ROOM_ERROR};const e=this._getLocalVideoTracks();if(!e.length)return this._logger.error("_",`[RCCallSession disableVideoTrack] Room missing video track -> ${a.MISSING_VIDEO_TRACK_ERROR}`),{code:a.MISSING_VIDEO_TRACK_ERROR};if(e.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:a.SUCCESS};const{code:t}=yield this._room.unpublish(e);return t!==h.SUCCESS?(this._logger.error("_",`[RCCallSession disableVideo] unpublish failed -> ${t}`),{code:a.UNPUBLISH_VIDEO_ERROR}):(e.forEach((e=>{e.destroy()})),{code:a.SUCCESS})}))}enableVideoTrack(){return d(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${a.NOT_IN_ROOM_ERROR}`),{code:a.NOT_IN_ROOM_ERROR};if(!this._options.isOffCameraWhenVideoDisable){const e=this._getLocalVideoTracks();return e.length?(e.forEach((e=>{e.unmute()})),{code:a.SUCCESS}):(this._logger.error("_",`[RCCallSession EnableVideoTrack] Room missing video track -> ${a.MISSING_VIDEO_TRACK_ERROR}`),{code:a.MISSING_VIDEO_TRACK_ERROR})}const{code:e,track:t}=yield this._rtcClient.createCameraVideoTrack();if(e!==h.SUCCESS)return this._logger.error("_",`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${e}`),{code:a.GET_LOCAL_VIDEO_TRACK_ERROR};const o=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():o.push(e)})),o.push(t),this._options.localTracks=o,t.mute();const{code:i}=yield this._room.publish([t]);return i!==h.SUCCESS?(this._logger.error("_",`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${e}`),{code:a.VIDEO_PUBLISH_ERROR}):(t.unmute(),this._notifyTrackReady([t]),{code:a.SUCCESS})}))}disableAudioTrack(){return d(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${a.NOT_IN_ROOM_ERROR}`),{code:a.NOT_IN_ROOM_ERROR};this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return d(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${a.NOT_IN_ROOM_ERROR}`),{code:a.NOT_IN_ROOM_ERROR};const e=this._getLocalAudioTracks();if(!e.length)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${a.MISSING_VIDEO_TRACK_ERROR}`),{code:a.MISSING_VIDEO_TRACK_ERROR};e.forEach((e=>{e.unmute()}))}))}_destroyTracks(e){e.forEach((e=>{e.destroy()}))}_notifyTrackReady(e){e.forEach((e=>{try{this._listener.onTrackReady(e,this)}catch(e){this._logger.error("_","[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(e,t)=>{const o=this._rtcClient.getCurrentId();this._stateMachine.userLeave([o]),e?(t===u.SERVER_KICK&&this._exceptionClose(l.KICKED_BY_SERVER),t===u.OTHER_KICK&&this._exceptionClose(l.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(l.NETWORK_ERROR)},onMessageReceive(e,t,o,i){},onRoomAttributeChange(e,t){},onAudioMuteChange:e=>{this._logger.info("_",`[RCCallSession onAudioMuteChange] userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const t={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"audio",trackId:e.getTrackId()};try{this._listener.onAudioMuteChange(t,this)}catch(e){this._logger.error("_","[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{this._logger.info("_",`[RCCallSession onVideoMuteChange]userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const t={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"video",trackId:e.getTrackId()};try{this._listener.onVideoMuteChange(t,this)}catch(e){this._logger.error("_","[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>d(this,void 0,void 0,(function*(){if(this._room){const{code:t}=yield this._room.subscribe(e);t!==h.SUCCESS&&this._logger.error("_",`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${t}`)}})),onTrackUnpublish:e=>{},onTrackReady:e=>{this._stateMachine.getMediaType()===s.AUDIO&&e.isVideoTrack()||this._notifyTrackReady([e])},onUserJoin:e=>{this.joinRoomTimer&&this.joinRoomTimer.stop(),this._stateMachine.userJoin(e)},onUserLeave:e=>{this._logger.info("_",`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{this._logger.info("_",`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){this._logger.error("_","[RCCallSession onPing] listening onPing exception"),console.error(e)}}})}_registerReportListener(){this._room.registerReportListener({onStateReport:e=>{try{this._listener.onRTCStateReport&&this._listener.onRTCStateReport(e,this)}catch(e){this._logger.error("_","[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){this._logger.error("_","[RCCallSession onICEConnectionStateChange] onICEConnectionStateChange exception"),console.error(e)}}})}getSessionId(){return this._stateMachine.getCallId()}getRTCSessionId(){return this._room?this._room.getSessionId():null}getTargetId(){return this._stateMachine.getTargetId()}getConversationType(){return this._stateMachine.getConversationType()}getChannelId(){return this._stateMachine.getChannelId()}getRemoteUsers(){return this._stateMachine.getRemoteUsers()}getUsers(){return this._stateMachine.getRemoteUsers()}getUserState(e){if(!e||"string"!=typeof e)throw new Error("userId is required, must be of type 'string'");return this._stateMachine.getUserState(e)}getState(){return this._stateMachine.getState()}getCallerId(){return this._stateMachine.getCallerId()}getMediaType(){return this._stateMachine.getMediaType()}}class v{constructor(t,o,i,s){this._context=t,this._runtime=o,this._logger=i,this._sessionList=[],this._callPushConfig={},this._hungupPushConfig={},this._rtcClient=s.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:e.COEXIST,isAllowDemotionGetStream:!1,lang:n.ZH},s),this._callEngine=new c(this._context,o,this._logger,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||n.ZH}),C.on("sessionClose",(({session:e,summaryInfo:t})=>{this._removeSession(e);try{this._options.onSessionClose(e,t)}catch(e){this._logger.error("_","[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),C.on("hungupOtherSession",(({session:e})=>{const t=e.getSessionId();this._logger.info("_",`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${t}`),this._logger.info("_",`[RCCallClient hungupOtherSession] sessionList ->${this._sessionList.map((e=>e.getSessionId())).join(",")}`);let o=0;for(;this._sessionList.length>1;)this._sessionList[o].getSessionId()!==t?(this._sessionList[o].hungup(),this._sessionList.splice(o,1)):o++;this._logger.info("_",`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e,t){this._logger.info("_","[RCCallClient _onInvite] Received invite message");const o=new E(e,this._rtcClient,this._logger,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:_.CALLEE,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});this._logger.info("_","[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(o);try{this._options.onSession(o,t)}catch(e){this._logger.error("_","[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!o._listener)throw this._logger.error("_","[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=R(o._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){this._logger.error("_","[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),this._logger.info("_","[RCCallClient registerUserInfo] successfully register user info data")}startCrossCall({targetId:e,mediaType:t=s.AUDIO,listener:o,constraints:i,channelId:n="",extra:r="",pushTitle:l="",pushContent:a="",bitrate:c}){return d(this,void 0,void 0,(function*(){return this.__call({targetId:e,mediaType:t,listener:o,constraints:i,channelId:n,extra:r,pushTitle:l,pushContent:a,bitrate:c,isCrossAppkey:!0})}))}call({targetId:e,mediaType:t=s.AUDIO,listener:o,constraints:i,channelId:n="",extra:r="",pushTitle:l="",pushContent:a="",bitrate:c}){return d(this,void 0,void 0,(function*(){return this.__call({targetId:e,mediaType:t,listener:o,constraints:i,channelId:n,extra:r,pushTitle:l,pushContent:a,bitrate:c})}))}__call({targetId:e,mediaType:t=s.AUDIO,listener:o,constraints:i,channelId:n="",extra:r="",pushTitle:l="",pushContent:c="",bitrate:h,isCrossAppkey:u=!1}){return d(this,void 0,void 0,(function*(){const{pushTitle:s="",pushContent:d=""}=this._callPushConfig.pushTitle||this._callPushConfig.pushContent?this._callPushConfig:{pushTitle:l,pushContent:c};this._logger.info("_",`[RCCallClient call] extra->${r} pushTitle->${s} pushContent->${d}`);const C=[p(e),f(t),R(o),m(r),S(s),T(d)],g=[];if(!C.every((e=>(!e.result&&g.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${g.join("\n")}`);let y=[];const{code:I,tracks:v}=yield this._getLocalTrack(t,i);if(I!==a.SUCCESS)return{code:I};y=v,y.forEach((e=>{var t,i,s;e.isAudioTrack()&&(null==h?void 0:h.audio)&&e.setBitrate(null==h?void 0:h.audio),e.isVideoTrack()&&(null==h?void 0:h.video)&&e.setBitrate(null===(t=null==h?void 0:h.video)||void 0===t?void 0:t.max,null===(i=null==h?void 0:h.video)||void 0===i?void 0:i.min,null===(s=null==h?void 0:h.video)||void 0===s?void 0:s.start),o.onTrackReady(e)}));const{code:O,stateMachine:b}=yield this._callEngine.call(n,e,t,r,s,d,u);if(O===a.SUCCESS&&b){this._logger.info("_","[RCCallClient call] successfully created state machine");const e=new E(b,this._rtcClient,this._logger,{localTracks:y,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:_.CALLER,isCrossAppkey:u,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});return e.registerSessionListener(o),this._sessionList.push(e),this._logger.info("_",`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:O,session:e}}return this._logger.error("_",`[RCCallClient call] call failed code ->: ${O}`),y.forEach((e=>{e.mute(),e.destroy()})),{code:O}}))}callInGroup({targetId:e,userIds:t,mediaType:o=s.AUDIO,listener:i,constraints:n,channelId:r="",extra:l="",pushTitle:c="",pushContent:h="",bitrate:u}){return d(this,void 0,void 0,(function*(){const{pushTitle:s="",pushContent:d=""}=this._callPushConfig.pushTitle||this._callPushConfig.pushContent?this._callPushConfig:{pushTitle:c,pushContent:h},C=[p(e),y(t),f(o),R(i),m(l),S(s),T(d)],g=[];if(!C.every((e=>(!e.result&&g.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${g.join("\n")}`);let I=[];const{code:v,tracks:O}=yield this._getLocalTrack(o,n);if(v!==a.SUCCESS)return{code:v};I=O,I.forEach((e=>{var t,o,s;e.isAudioTrack()&&(null==u?void 0:u.audio)&&e.setBitrate(null==u?void 0:u.audio),e.isVideoTrack()&&(null==u?void 0:u.video)&&e.setBitrate(null===(t=null==u?void 0:u.video)||void 0===t?void 0:t.max,null===(o=null==u?void 0:u.video)||void 0===o?void 0:o.min,null===(s=null==u?void 0:u.video)||void 0===s?void 0:s.start),i.onTrackReady(e)}));const{code:b,stateMachine:k}=yield this._callEngine.callInGroup(r,e,o,t,l,s,d);if(b===a.SUCCESS&&k){this._logger.info("_","[RCCallClient callInGroup] successfully created state machine");const e=new E(k,this._rtcClient,this._logger,{localTracks:I,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:_.CALLER,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});return e.registerSessionListener(i),this._sessionList.push(e),this._logger.info("_",`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:b,session:e}}return this._logger.info("_",`[RCCallClient callInGroup] callInGroup failed code -> ${b}`),I.forEach((e=>{e.mute(),e.destroy()})),{code:b}}))}_getLocalTrackCore(e,t){return d(this,void 0,void 0,(function*(){if(e===s.AUDIO){const{code:e,track:o}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",t&&t.audio&&Object.assign({},t.audio));return e!==h.SUCCESS?(this._logger.error("_",`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${e}`),{code:a.GET_LOCAL_AUDIO_TRACK_ERROR}):(this._logger.info("_","[RCCallClient _getTrack] successfully get Audio local tracks"),{code:a.SUCCESS,tracks:[o]})}{const{code:e,tracks:o}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",t&&Object.assign({},t));return e!==h.SUCCESS?(this._logger.error("_",`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${e}`),{code:a.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(this._logger.info("_","[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:a.SUCCESS,tracks:o})}}))}_getLocalTrack(e,t){return d(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===s.AUDIO_VIDEO){const{code:e,tracks:o}=yield this._getLocalTrackCore(s.AUDIO_VIDEO,t);if(e!==a.SUCCESS){const{code:e,tracks:o}=yield this._getLocalTrackCore(s.AUDIO,t);return e!==a.SUCCESS?{code:e}:{code:e,tracks:o}}return{code:e,tracks:o}}{const{code:o,tracks:i}=yield this._getLocalTrackCore(e,t);return o!==a.SUCCESS?{code:o}:{code:o,tracks:i}}}))}_removeSession(e){const t=e.getSessionId();this._sessionList=this._sessionList.filter((e=>e.getSessionId()!==t))}getJoinedRoomInfo(){return d(this,void 0,void 0,(function*(){const{code:e,data:t}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return e!==o.SUCCESS?(this._logger.error("_",`getJoinedUserInfo error code: ${e}`),{code:a.QUERY_JOINED_USER_INFO_ERROR}):{code:a.SUCCESS,data:t}}))}setPushConfig(e={},t={}){const o=[e,t].map((e=>(e=>{const{pushTitle:t="",pushContent:o=""}=e,i=[];return i.push(S(t)),i.push(T(o)),i})(e)))[0],i=[];if(!o.every((e=>(!e.result&&i.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup callPushConfig or hungupPushConfig] ${i.join("\n")}`);this._callPushConfig=e,this._hungupPushConfig=t}}i.add("plugin-call","5.1.2");const O={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,t,o){const s=g(o);if(!s.result)throw new Error(`[RCCallLib installer steup]${s.msg}`);if(!i.validEngine("^5.7.3"))throw new Error(`The current engine version '${i.getInfo().engine}' error, plugin-call required engine version at least '^5.7.3'.`);const n=e.createLogger("RCCall","RTC");return n.warn("_","RCCall Version: 5.1.2, Commit: 89ba2ed5a9c788362ba96f084fdc3c18106a64c4"),new v(e,t,n,o)}};export{v as RCCallClient,E as RCCallSession,O as installer};
15
+ ***************************************************************************** */function _(e,t,o,i){return new(o||(o=Promise))((function(s,n){function r(e){try{a(i.next(e))}catch(e){n(e)}}function l(e){try{a(i.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?s(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(r,l)}a((i=i.apply(e,t||[])).next())}))}var C;!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(C||(C={}));var g=new class{constructor(){this.list={}}on(e,t){return(this.list[e]||(this.list[e]=[])).push(t),this}once(e,t){const o=i=>{this.off(e,o),t.call(this,i)};o.fun=t,this.on(e,o)}off(e,t){const o=this.list[e];if(!o)return!1;if(t){let e;for(let i=0,s=o.length;i<s;i++)if(e=o[i],e===t||e.fun===t){o.splice(i,1);break}}else o&&(o.length=0)}emit(e,t){const o=[...this.list[e]];if(!o||0===o.length)return!1;o.forEach((e=>{e.call(this,t)}))}};const R=o=>{if(!o)return{result:!1,msg:"Initialization missing parameter -> options"};if("object"!=typeof o)return{result:!1,msg:"Initialization options must be an object"};const i=Object.keys(o),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 o.rtcClient?{result:!1,msg:"Initialization 'rtcClient' parameter must be of type 'object'"}:"function"!=typeof o.onSession?{result:!1,msg:"Initialization 'onSession' parameter must be of type 'function'"}:"function"!=typeof o.onSessionClose?{result:!1,msg:"Initialization 'onSessionClose' parameter must be of type 'function'"}:void 0!==o.isAllowSubscribeRetry&&"boolean"!=typeof o.isAllowSubscribeRetry?{result:!1,msg:"Initialization 'isAllowSubscribeRetry' parameter must be of type 'boolean'"}:void 0!==o.isAllowPublishRetry&&"boolean"!=typeof o.isAllowPublishRetry?{result:!1,msg:"Initialization 'isAllowPublishRetry' parameter must be of type 'boolean'"}:void 0!==o.isOffCameraWhenVideoDisable&&"boolean"!=typeof o.isOffCameraWhenVideoDisable?{result:!1,msg:"Initialization 'isOffCameraWhenVideoDisable' parameter must be of type 'boolean'"}:void 0===o.joinType||(r=o.joinType,Object.values(e).includes(r))?void 0!==o.isAllowDemotionGetStream&&"boolean"!=typeof o.isAllowDemotionGetStream?{result:!1,msg:"Initialization 'isAllowDemotionGetStream' parameter must be of type 'boolean'"}:void 0===o.lang||function(e){return Object.values(n).includes(e)}(o.lang)?void 0===o.logLevel||function(e){return Object.values(t).includes(e)}(o.logLevel)?void 0!==o.logStdout&&"function"!=typeof o.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},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 t=Object.keys(e),o=[];return["onRinging","onAccept","onHungup","onTrackReady"].forEach((e=>{t.includes(e)||o.push(e)})),o.length?{result:!1,msg:`missing parameter -> "${o.join(",")}"`}:"function"!=typeof e.onRinging?{result:!1,msg:"'onRinging' parameter must be of type 'function'"}:"function"!=typeof e.onAccept?{result:!1,msg:"'onAccept' parameter must be of type 'function'"}:"function"!=typeof e.onHungup?{result:!1,msg:"'onHungup' parameter must be of type 'function'"}:"function"!=typeof e.onTrackReady?{result:!1,msg:"'onTrackReady' parameter must be of type 'function'"}:{result:!0}},f=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},m=e=>e===s.AUDIO||e===s.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},S=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},T=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},y=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushContent' parameter must be of type 'string'"},I=e=>Array.isArray(e)&&e.length?e.every((e=>"string"==typeof e&&e.length>0))?{result:!0}:{result:!1,msg:"'userIds' parameter is required"}:{result:!1,msg:"'userIds' parameter is required, must be of type 'string[]'"};const E=e=>{return e&&e.audio&&void 0!==e.audio.micphoneId&&"string"!=typeof e.audio.micphoneId?{result:!1,msg:"'constraints.audio.micphoneId' must be of type 'string'"}:e&&e.audio&&void 0!==e.audio.sampleRate&&"number"!=typeof e.audio.sampleRate?{result:!1,msg:"'constraints.audio.sampleRate' must be of type 'number'"}:e&&e.video&&void 0!==e.video.cameraId&&"string"!=typeof e.video.cameraId?{result:!1,msg:"'constraints.video.cameraId' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&"string"!=typeof e.video.frameRate?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&(t=e.video.frameRate,!["FPS_10","FPS_15","FPS_24","FPS_30"].includes(t))?{result:!1,msg:"'frameRate' value is out of range"}:e&&e.video&&void 0!==e.video.resolution&&"string"!=typeof e.video.resolution?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.resolution&&(o=e.video.resolution,!h[o])?{result:!1,msg:"'resolution' value is out of range"}:!e||!e.video||e.video.frameRate&&e.video.resolution?{result:!0}:{result:!1,msg:"'resolution' and 'resolution' is required"};var t,o};class v{constructor(e,t){this._timerId=0,this._startTime=0,e&&(this._timerId=((e,t)=>setTimeout(e,t))((()=>{e()}),t)),this._startTime=Date.now()}stop(){clearTimeout(this._timerId);const e=Date.now();let t=e-this._startTime;return 0===this._startTime&&(t=0),{startTime:this._startTime,endTime:e,duration:t}}reset(){this._startTime=0}}class O{constructor(e,t,o,i={}){this._stateMachine=e,this._rtcClient=t,this._logger=o,this._options=i,this._listener=null,this._RETRYCOUNT=2,this.joinRoomTimer=null,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:t})=>{this._logger.info("_",`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${t}`)},onStateChange:e=>_(this,void 0,void 0,(function*(){const{state:t,reason:o}=e;if(this._logger.info("_",`[RCCallSession onStateChange] : state->${t} reason->${o}`),t===r.KEEPING){const e=this._stateMachine.getCallId();this._logger.info("_",`[RCCallSession onStateChange] roomId: ${e}`);try{yield this._joinRoom(e)}catch(t){this._exceptionClose(l.NETWORK_ERROR),this._logger.error("_",`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${e}`),console.error(t)}}else if(t===r.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),this._logger.info("_","[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{this._logger.info("_",`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){this._logger.error("_","[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{this._logger.info("_",`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){this._logger.error("_","[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,t)=>{this._logger.info("_",`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${t}`);try{this._listener.onHungup(e,t,this)}catch(e){this._logger.error("_","[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:t})=>{this._logger.info("_",`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,t,this)}catch(e){this._logger.error("_","[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:e,mediaType:t})=>{this._logger.info("_",`[RCCallSession onMediaModify]sender: sender.userId -> ${e.userId} mediaType: ${t}`),t===s.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(e,t,this)}catch(e){this._logger.error("_","[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}},crossAppkey:e=>{this._logger.info("_",`[RCCallSession crossAppkey] 是否跨 appkey: ${e}`),this._options.isCrossAppkey=e}});const{pushTitle:n,pushContent:a}=this._options.hungupPushConfig;this._stateMachine.setHungupPushConfig(n,a)}_joinRoom(e){return _(this,void 0,void 0,(function*(){let t;try{t=this._options.isCrossAppkey?yield this._rtcClient.joinCrossRTCRoom(e,this._options.joinType):yield this._rtcClient.joinRTCRoom(e,this._options.joinType);const{code:o,userIds:i,room:s}=t;if(o!==u.SUCCESS)return o===u.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(l.SERVICE_NOT_OPENED),o===u.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(l.OTHER_CLIENT_IN_CALL):this._exceptionClose(l.NETWORK_ERROR),this._logger.info("_",`[RCCallClient _joinRoom] join room failed: roomId -> ${e} RCRTCCode -> ${o}`),{code:a.JOIN_ROOM_ERROR};if(this._stateMachine.getState()===r.END)return yield this._rtcClient.leaveRoom(s),this._room=null,{code:a.SUCCESS};i.length<1&&(this.joinRoomTimer=new v((()=>{this._exceptionClose(l.REMOTE_NETWORK_ERROR)}),6e4)),this._room=s}catch(t){return this._exceptionClose(l.NETWORK_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${e}`),console.error(t),{code:a.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(t){return this._exceptionClose(l.SUBSCRIBE_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${e}`),console.error(t),{code:a.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(t){return this._exceptionClose(l.PUBLISH_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _publish Exception roomId -> ${e}`),console.error(t),{code:a.JOIN_ROOM_ERROR}}return{code:a.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return _(this,void 0,void 0,(function*(){const e=this._room.getRemoteTracks();if(e.length){const{code:t}=yield this._subscribeRetry(e,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);t!==u.SUCCESS&&(this._exceptionClose(l.SUBSCRIBE_ERROR),this._logger.error("_",`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${t}`))}}))}_subscribeRetry(e,t=!1,o=0){return _(this,void 0,void 0,(function*(){const{code:i}=yield this._room.subscribe(e);if(i!==u.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(i,this)}catch(e){this._logger.error("_","[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!t)return{code:i};if(o>0)return o--,this._subscribeRetry(e,t,o)}return{code:i}}))}_publish(){return _(this,void 0,void 0,(function*(){const e=this._options.localTracks,{code:t}=yield this._publishRetry(e,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(t!==u.SUCCESS)return this._exceptionClose(l.PUBLISH_ERROR),void this._logger.info("_",`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${t}`);this._options.produceType===C.CALLEE&&this._notifyTrackReady(e)}))}_publishRetry(e,t=!1,o=0){return _(this,void 0,void 0,(function*(){const{code:i}=yield this._room.publish(e);if(i!==u.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(i,this)}catch(e){this._logger.error("_","[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!t)return{code:i};if(o>0)return o--,this._publishRetry(e,t,o)}return{code:i}}))}_leaveRoom(){return _(this,void 0,void 0,(function*(){try{const e=yield this._rtcClient.leaveRoom(this._room);this._logger.info("_",`[RCCallSession _leaveRoom] Successfully exited the room code: ${e.code}`)}catch(e){this._logger.error("_","[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();g.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const t=p(e);if(!t.result)throw new Error(`[RCCallSession registerSessionListener] ${t.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(e,t){return _(this,void 0,void 0,(function*(){if(e===s.AUDIO){const{code:e,track:o}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",t&&t.audio&&Object.assign({},t.audio));return e!==u.SUCCESS?(this._logger.error("_",`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${e}`),{code:a.GET_LOCAL_AUDIO_TRACK_ERROR}):(this._logger.info("_","[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:a.SUCCESS,tracks:[o]})}{const{code:e,tracks:o}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",t&&Object.assign({},t));return e!==u.SUCCESS?(this._logger.error("_",`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${e}`),{code:a.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(this._logger.info("_","[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:a.SUCCESS,tracks:o})}}))}_getLocalTrack(e,t){return _(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===s.AUDIO_VIDEO){const{code:e,tracks:o}=yield this._getLocalTrackCore(s.AUDIO_VIDEO,t);if(e!==a.SUCCESS){const{code:e,tracks:o}=yield this._getLocalTrackCore(s.AUDIO,t);return e!==a.SUCCESS?(this._exceptionClose(l.GET_MEDIA_RESOURCES_ERROR),{code:e}):{code:e,tracks:o}}return{code:e,tracks:o}}{const{code:o,tracks:i}=yield this._getLocalTrackCore(e,t);return o!==a.SUCCESS?(this._exceptionClose(l.GET_MEDIA_RESOURCES_ERROR),{code:o}):{code:o,tracks:i}}}))}changeAudioDevice(e){return _(this,void 0,void 0,(function*(){const t=[],o=[],{code:i,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",e);if(i!==u.SUCCESS)return this._logger.error("_",`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${i}`),{code:a.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||o.push(e)})),t.push(s),o.push(s),this._options.localTracks=o,this._notifyTrackReady(t),this._room){const{code:e}=yield this._room.publish(t);if(e!==u.SUCCESS)return{code:a.AUDIO_PUBLISH_ERROR}}return{code:a.SUCCESS}}))}invite(e,t={}){var o,i;return _(this,void 0,void 0,(function*(){const{extra:s=""}=t,{pushTitle:n="",pushContent:r=""}=(null===(o=this._options.callPushConfig)||void 0===o?void 0:o.pushTitle)||(null===(i=this._options.callPushConfig)||void 0===i?void 0:i.pushContent)?this._options.callPushConfig:t,l=[I(e),S(s),T(n),y(r)],a=[];if(!l.every((e=>(!e.result&&a.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${a.join("\n")}`);const{code:c}=yield this._stateMachine.invite(e,{extra:s,pushTitle:n,pushContent:r});return{code:c}}))}accept(e){return _(this,void 0,void 0,(function*(){const t=E(e);if(!t.result)throw new Error(`[RCCallSession accept] ${t.msg}`);g.emit("hungupOtherSession",{session:this});const o=this._stateMachine.getMediaType(),{code:i,tracks:s}=yield this._getLocalTrack(o,e);if(i!==a.SUCCESS)return{code:i};this._options.localTracks=s;const{code:n}=yield this._stateMachine.accept();return n!==a.SUCCESS?(this._logger.error("_",`[RCCallSession accept]Send accept message failed -> code: ${n}`),{code:n}):{code:n}}))}hungup(){return _(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(e){return _(this,void 0,void 0,(function*(){const{code:t}=yield this._stateMachine.changeMediaType(e);return t!==a.SUCCESS&&this._logger.error("_",`[RCCallSession _changeMediaType] change media type fail code-> ${t}`),{code:t}}))}_getLocalVideoTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isVideoTrack()))),e):e}_getLocalAudioTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isAudioTrack()))),e):e}_setMediaTypeToAudioAndVideo(){return _(this,void 0,void 0,(function*(){const{code:e,track:t}=yield this._rtcClient.createCameraVideoTrack();if(e!==u.SUCCESS)return{code:a.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:o}=yield this._room.publish([t]);o===u.SUCCESS?(this._notifyTrackReady([t]),this._changeMediaType(s.AUDIO_VIDEO)):this._logger.error("_",`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${e}`)}))}_setMediaTypeToAudio(){return _(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(e.length){e.forEach((e=>{e.mute()}));const{code:t}=yield this._room.unpublish(e);t!==u.SUCCESS&&this._logger.error("_",`[RCCallSession disableVideo] unpublish failed -> ${t}`),this._destroyTracks(e)}}))}descendAbility(){return _(this,void 0,void 0,(function*(){const{code:e}=yield this._changeMediaType(s.AUDIO);return e===a.SUCCESS&&this._setMediaTypeToAudio(),{code:e}}))}disableVideoTrack(){return _(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${a.NOT_IN_ROOM_ERROR}`),{code:a.NOT_IN_ROOM_ERROR};const e=this._getLocalVideoTracks();if(!e.length)return this._logger.error("_",`[RCCallSession disableVideoTrack] Room missing video track -> ${a.MISSING_VIDEO_TRACK_ERROR}`),{code:a.MISSING_VIDEO_TRACK_ERROR};if(e.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:a.SUCCESS};const{code:t}=yield this._room.unpublish(e);return t!==u.SUCCESS?(this._logger.error("_",`[RCCallSession disableVideo] unpublish failed -> ${t}`),{code:a.UNPUBLISH_VIDEO_ERROR}):(e.forEach((e=>{e.destroy()})),{code:a.SUCCESS})}))}enableVideoTrack(){return _(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${a.NOT_IN_ROOM_ERROR}`),{code:a.NOT_IN_ROOM_ERROR};if(!this._options.isOffCameraWhenVideoDisable){const e=this._getLocalVideoTracks();return e.length?(e.forEach((e=>{e.unmute()})),{code:a.SUCCESS}):(this._logger.error("_",`[RCCallSession EnableVideoTrack] Room missing video track -> ${a.MISSING_VIDEO_TRACK_ERROR}`),{code:a.MISSING_VIDEO_TRACK_ERROR})}const{code:e,track:t}=yield this._rtcClient.createCameraVideoTrack();if(e!==u.SUCCESS)return this._logger.error("_",`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${e}`),{code:a.GET_LOCAL_VIDEO_TRACK_ERROR};const o=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():o.push(e)})),o.push(t),this._options.localTracks=o,t.mute();const{code:i}=yield this._room.publish([t]);return i!==u.SUCCESS?(this._logger.error("_",`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${e}`),{code:a.VIDEO_PUBLISH_ERROR}):(t.unmute(),this._notifyTrackReady([t]),{code:a.SUCCESS})}))}disableAudioTrack(){return _(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${a.NOT_IN_ROOM_ERROR}`),{code:a.NOT_IN_ROOM_ERROR};this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return _(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${a.NOT_IN_ROOM_ERROR}`),{code:a.NOT_IN_ROOM_ERROR};const e=this._getLocalAudioTracks();if(!e.length)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${a.MISSING_VIDEO_TRACK_ERROR}`),{code:a.MISSING_VIDEO_TRACK_ERROR};e.forEach((e=>{e.unmute()}))}))}_destroyTracks(e){e.forEach((e=>{e.destroy()}))}_notifyTrackReady(e){e.forEach((e=>{try{this._listener.onTrackReady(e,this)}catch(e){this._logger.error("_","[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(e,t)=>{const o=this._rtcClient.getCurrentId();this._stateMachine.userLeave([o]),e?(t===d.SERVER_KICK&&this._exceptionClose(l.KICKED_BY_SERVER),t===d.OTHER_KICK&&this._exceptionClose(l.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(l.NETWORK_ERROR)},onMessageReceive(e,t,o,i){},onRoomAttributeChange(e,t){},onAudioMuteChange:e=>{this._logger.info("_",`[RCCallSession onAudioMuteChange] userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const t={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"audio",trackId:e.getTrackId()};try{this._listener.onAudioMuteChange(t,this)}catch(e){this._logger.error("_","[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{this._logger.info("_",`[RCCallSession onVideoMuteChange]userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const t={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"video",trackId:e.getTrackId()};try{this._listener.onVideoMuteChange(t,this)}catch(e){this._logger.error("_","[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>_(this,void 0,void 0,(function*(){if(this._room){const{code:t}=yield this._room.subscribe(e);t!==u.SUCCESS&&this._logger.error("_",`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${t}`)}})),onTrackUnpublish:e=>{},onTrackReady:e=>{this._stateMachine.getMediaType()===s.AUDIO&&e.isVideoTrack()||this._notifyTrackReady([e])},onUserJoin:e=>{this.joinRoomTimer&&this.joinRoomTimer.stop(),this._stateMachine.userJoin(e)},onUserLeave:e=>{this._logger.info("_",`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{this._logger.info("_",`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){this._logger.error("_","[RCCallSession onPing] listening onPing exception"),console.error(e)}}})}_registerReportListener(){this._room.registerReportListener({onStateReport:e=>{try{this._listener.onRTCStateReport&&this._listener.onRTCStateReport(e,this)}catch(e){this._logger.error("_","[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){this._logger.error("_","[RCCallSession onICEConnectionStateChange] onICEConnectionStateChange exception"),console.error(e)}}})}getSessionId(){return this._stateMachine.getCallId()}getRTCSessionId(){return this._room?this._room.getSessionId():null}getTargetId(){return this._stateMachine.getTargetId()}getConversationType(){return this._stateMachine.getConversationType()}getChannelId(){return this._stateMachine.getChannelId()}getRemoteUsers(){return this._stateMachine.getRemoteUsers()}getUsers(){return this._stateMachine.getRemoteUsers()}getUserState(e){if(!e||"string"!=typeof e)throw new Error("userId is required, must be of type 'string'");return this._stateMachine.getUserState(e)}getState(){return this._stateMachine.getState()}getCallerId(){return this._stateMachine.getCallerId()}getMediaType(){return this._stateMachine.getMediaType()}}class b{constructor(t,o,i,s){this._context=t,this._runtime=o,this._logger=i,this._sessionList=[],this._callPushConfig={},this._hungupPushConfig={},this._rtcClient=s.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:e.COEXIST,isAllowDemotionGetStream:!1,lang:n.ZH},s),this._callEngine=new c(this._context,o,this._logger,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||n.ZH}),g.on("sessionClose",(({session:e,summaryInfo:t})=>{this._removeSession(e);try{this._options.onSessionClose(e,t)}catch(e){this._logger.error("_","[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),g.on("hungupOtherSession",(({session:e})=>{const t=e.getSessionId();this._logger.info("_",`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${t}`),this._logger.info("_",`[RCCallClient hungupOtherSession] sessionList ->${this._sessionList.map((e=>e.getSessionId())).join(",")}`);let o=0;for(;this._sessionList.length>1;)this._sessionList[o].getSessionId()!==t?(this._sessionList[o].hungup(),this._sessionList.splice(o,1)):o++;this._logger.info("_",`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e,t){this._logger.info("_","[RCCallClient _onInvite] Received invite message");const o=new O(e,this._rtcClient,this._logger,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:C.CALLEE,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});this._logger.info("_","[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(o);try{this._options.onSession(o,t)}catch(e){this._logger.error("_","[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!o._listener)throw this._logger.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){this._logger.error("_","[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),this._logger.info("_","[RCCallClient registerUserInfo] successfully register user info data")}startCrossCall({targetId:e,mediaType:t=s.AUDIO,listener:o,constraints:i,channelId:n="",extra:r="",pushTitle:l="",pushContent:a="",bitrate:c}){return _(this,void 0,void 0,(function*(){return this.__call({targetId:e,mediaType:t,listener:o,constraints:i,channelId:n,extra:r,pushTitle:l,pushContent:a,bitrate:c,isCrossAppkey:!0})}))}call({targetId:e,mediaType:t=s.AUDIO,listener:o,constraints:i,channelId:n="",extra:r="",pushTitle:l="",pushContent:a="",bitrate:c}){return _(this,void 0,void 0,(function*(){return this.__call({targetId:e,mediaType:t,listener:o,constraints:i,channelId:n,extra:r,pushTitle:l,pushContent:a,bitrate:c})}))}__call({targetId:e,mediaType:t=s.AUDIO,listener:o,constraints:i,channelId:n="",extra:r="",pushTitle:l="",pushContent:c="",bitrate:h,isCrossAppkey:u=!1}){return _(this,void 0,void 0,(function*(){const{pushTitle:s="",pushContent:d=""}=this._callPushConfig.pushTitle||this._callPushConfig.pushContent?this._callPushConfig:{pushTitle:l,pushContent:c};this._logger.info("_",`[RCCallClient call] extra->${r} pushTitle->${s} pushContent->${d}`);const _=[f(e),m(t),p(o),S(r),T(s),y(d)],g=[];if(!_.every((e=>(!e.result&&g.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${g.join("\n")}`);let R=[];const{code:I,tracks:E}=yield this._getLocalTrack(t,i);if(I!==a.SUCCESS)return{code:I};R=E,R.forEach((e=>{var t,i,s;e.isAudioTrack()&&(null==h?void 0:h.audio)&&e.setBitrate(null==h?void 0:h.audio),e.isVideoTrack()&&(null==h?void 0:h.video)&&e.setBitrate(null===(t=null==h?void 0:h.video)||void 0===t?void 0:t.max,null===(i=null==h?void 0:h.video)||void 0===i?void 0:i.min,null===(s=null==h?void 0:h.video)||void 0===s?void 0:s.start),o.onTrackReady(e)}));const{code:v,stateMachine:b}=yield this._callEngine.call(n,e,t,r,s,d,u);if(v===a.SUCCESS&&b){this._logger.info("_","[RCCallClient call] successfully created state machine");const e=new O(b,this._rtcClient,this._logger,{localTracks:R,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:C.CALLER,isCrossAppkey:u,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});return e.registerSessionListener(o),this._sessionList.push(e),this._logger.info("_",`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:v,session:e}}return this._logger.error("_",`[RCCallClient call] call failed code ->: ${v}`),R.forEach((e=>{e.mute(),e.destroy()})),{code:v}}))}callInGroup({targetId:e,userIds:t,mediaType:o=s.AUDIO,listener:i,constraints:n,channelId:r="",extra:l="",pushTitle:c="",pushContent:h="",bitrate:u}){return _(this,void 0,void 0,(function*(){const{pushTitle:s="",pushContent:d=""}=this._callPushConfig.pushTitle||this._callPushConfig.pushContent?this._callPushConfig:{pushTitle:c,pushContent:h},_=[f(e),I(t),m(o),p(i),S(l),T(s),y(d)],g=[];if(!_.every((e=>(!e.result&&g.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${g.join("\n")}`);let R=[];const{code:E,tracks:v}=yield this._getLocalTrack(o,n);if(E!==a.SUCCESS)return{code:E};R=v,R.forEach((e=>{var t,o,s;e.isAudioTrack()&&(null==u?void 0:u.audio)&&e.setBitrate(null==u?void 0:u.audio),e.isVideoTrack()&&(null==u?void 0:u.video)&&e.setBitrate(null===(t=null==u?void 0:u.video)||void 0===t?void 0:t.max,null===(o=null==u?void 0:u.video)||void 0===o?void 0:o.min,null===(s=null==u?void 0:u.video)||void 0===s?void 0:s.start),i.onTrackReady(e)}));const{code:b,stateMachine:k}=yield this._callEngine.callInGroup(r,e,o,t,l,s,d);if(b===a.SUCCESS&&k){this._logger.info("_","[RCCallClient callInGroup] successfully created state machine");const e=new O(k,this._rtcClient,this._logger,{localTracks:R,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:C.CALLER,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});return e.registerSessionListener(i),this._sessionList.push(e),this._logger.info("_",`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:b,session:e}}return this._logger.info("_",`[RCCallClient callInGroup] callInGroup failed code -> ${b}`),R.forEach((e=>{e.mute(),e.destroy()})),{code:b}}))}_getLocalTrackCore(e,t){return _(this,void 0,void 0,(function*(){if(e===s.AUDIO){const{code:e,track:o}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",t&&t.audio&&Object.assign({},t.audio));return e!==u.SUCCESS?(this._logger.error("_",`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${e}`),{code:a.GET_LOCAL_AUDIO_TRACK_ERROR}):(this._logger.info("_","[RCCallClient _getTrack] successfully get Audio local tracks"),{code:a.SUCCESS,tracks:[o]})}{const{code:e,tracks:o}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",t&&Object.assign({},t));return e!==u.SUCCESS?(this._logger.error("_",`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${e}`),{code:a.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(this._logger.info("_","[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:a.SUCCESS,tracks:o})}}))}_getLocalTrack(e,t){return _(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===s.AUDIO_VIDEO){const{code:e,tracks:o}=yield this._getLocalTrackCore(s.AUDIO_VIDEO,t);if(e!==a.SUCCESS){const{code:e,tracks:o}=yield this._getLocalTrackCore(s.AUDIO,t);return e!==a.SUCCESS?{code:e}:{code:e,tracks:o}}return{code:e,tracks:o}}{const{code:o,tracks:i}=yield this._getLocalTrackCore(e,t);return o!==a.SUCCESS?{code:o}:{code:o,tracks:i}}}))}_removeSession(e){const t=e.getSessionId();this._sessionList=this._sessionList.filter((e=>e.getSessionId()!==t))}getJoinedRoomInfo(){return _(this,void 0,void 0,(function*(){const{code:e,data:t}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return e!==o.SUCCESS?(this._logger.error("_",`getJoinedUserInfo error code: ${e}`),{code:a.QUERY_JOINED_USER_INFO_ERROR}):{code:a.SUCCESS,data:t}}))}setPushConfig(e={},t={}){const o=[e,t].map((e=>(e=>{const{pushTitle:t="",pushContent:o=""}=e,i=[];return i.push(T(t)),i.push(y(o)),i})(e)))[0],i=[];if(!o.every((e=>(!e.result&&i.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup callPushConfig or hungupPushConfig] ${i.join("\n")}`);this._callPushConfig=e,this._hungupPushConfig=t}}i.add("plugin-call","5.1.3");const k={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,t,o){const s=R(o);if(!s.result)throw new Error(`[RCCallLib installer steup]${s.msg}`);if(!i.validEngine("^5.7.6"))throw new Error(`The current engine version '${i.getInfo().engine}' error, plugin-call required engine version at least '^5.7.6'.`);const n=e.createLogger("RCCall","RTC");return n.warn("_","RCCall Version: 5.1.3, Commit: c1ec87082611a289263c27c340ee414ee9e60ba8"),new b(e,t,n,o)}};export{b as RCCallClient,O as RCCallSession,k as installer};
package/dist/index.js CHANGED
@@ -13,4 +13,4 @@ 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
15
  ***************************************************************************** */
16
- function s(e,o,t,i){return new(t||(t=Promise))((function(s,r){function n(e){try{a(i.next(e))}catch(e){r(e)}}function l(e){try{a(i.throw(e))}catch(e){r(e)}}function a(e){var o;e.done?s(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(n,l)}a((i=i.apply(e,o||[])).next())}))}!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(e||(e={}));var r=new class{constructor(){this.list={}}on(e,o){return(this.list[e]||(this.list[e]=[])).push(o),this}once(e,o){const t=i=>{this.off(e,t),o.call(this,i)};t.fun=o,this.on(e,t)}off(e,o){const t=this.list[e];if(!t)return!1;if(o){let e;for(let i=0,s=t.length;i<s;i++)if(e=t[i],e===o||e.fun===o){t.splice(i,1);break}}else t&&(t.length=0)}emit(e,o){const t=[...this.list[e]];if(!t||0===t.length)return!1;t.forEach((e=>{e.call(this,o)}))}};const n=e=>{if(!e)return{result:!1,msg:"Initialization missing parameter -> options"};if("object"!=typeof e)return{result:!1,msg:"Initialization options must be an object"};const i=Object.keys(e),s=[];return["rtcClient","onSession","onSessionClose"].forEach((e=>{i.includes(e)||s.push(e)})),s.length?{result:!1,msg:`Initialization missing parameter -> "${s.join(",")}"`}:"object"!=typeof e.rtcClient?{result:!1,msg:"Initialization 'rtcClient' parameter must be of type 'object'"}:"function"!=typeof e.onSession?{result:!1,msg:"Initialization 'onSession' parameter must be of type 'function'"}:"function"!=typeof e.onSessionClose?{result:!1,msg:"Initialization 'onSessionClose' parameter must be of type 'function'"}:void 0!==e.isAllowSubscribeRetry&&"boolean"!=typeof e.isAllowSubscribeRetry?{result:!1,msg:"Initialization 'isAllowSubscribeRetry' parameter must be of type 'boolean'"}:void 0!==e.isAllowPublishRetry&&"boolean"!=typeof e.isAllowPublishRetry?{result:!1,msg:"Initialization 'isAllowPublishRetry' parameter must be of type 'boolean'"}:void 0!==e.isOffCameraWhenVideoDisable&&"boolean"!=typeof e.isOffCameraWhenVideoDisable?{result:!1,msg:"Initialization 'isOffCameraWhenVideoDisable' parameter must be of type 'boolean'"}:void 0===e.joinType||(r=e.joinType,Object.values(o.RTCJoinType).includes(r))?void 0!==e.isAllowDemotionGetStream&&"boolean"!=typeof e.isAllowDemotionGetStream?{result:!1,msg:"Initialization 'isAllowDemotionGetStream' parameter must be of type 'boolean'"}:void 0===e.lang||function(e){return Object.values(t.RCCallLanguage).includes(e)}(e.lang)?void 0===e.logLevel||function(e){return Object.values(o.LogLevel).includes(e)}(e.logLevel)?void 0!==e.logStdout&&"function"!=typeof e.logStdout?{result:!1,msg:"Initialization 'logStdout' parameter must be of type 'function'"}:{result:!0}:{result:!1,msg:"Initialization 'logLevel' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'lang' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'joinType' parameter must be of type correct type"};var r},l=e=>{if(!e)return{result:!1,msg:"missing parameter -> listener"};if("object"!=typeof e)return{result:!1,msg:"listener must be an object"};const o=Object.keys(e),t=[];return["onRinging","onAccept","onHungup","onTrackReady"].forEach((e=>{o.includes(e)||t.push(e)})),t.length?{result:!1,msg:`missing parameter -> "${t.join(",")}"`}:"function"!=typeof e.onRinging?{result:!1,msg:"'onRinging' parameter must be of type 'function'"}:"function"!=typeof e.onAccept?{result:!1,msg:"'onAccept' parameter must be of type 'function'"}:"function"!=typeof e.onHungup?{result:!1,msg:"'onHungup' parameter must be of type 'function'"}:"function"!=typeof e.onTrackReady?{result:!1,msg:"'onTrackReady' parameter must be of type 'function'"}:{result:!0}},a=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},c=e=>e===t.RCCallMediaType.AUDIO||e===t.RCCallMediaType.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},C=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},d=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},u=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushContent' parameter must be of type 'string'"},h=e=>Array.isArray(e)&&e.length?e.every((e=>"string"==typeof e&&e.length>0))?{result:!0}:{result:!1,msg:"'userIds' parameter is required"}:{result:!1,msg:"'userIds' parameter is required, must be of type 'string[]'"};class _{constructor(e,o){this._timerId=0,this._startTime=0,e&&(this._timerId=((e,o)=>setTimeout(e,o))((()=>{e()}),o)),this._startTime=Date.now()}stop(){clearTimeout(this._timerId);const e=Date.now();let o=e-this._startTime;return 0===this._startTime&&(o=0),{startTime:this._startTime,endTime:e,duration:o}}reset(){this._startTime=0}}class R{constructor(e,o,i,n={}){this._stateMachine=e,this._rtcClient=o,this._logger=i,this._options=n,this._listener=null,this._RETRYCOUNT=2,this.joinRoomTimer=null,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:o})=>{this._logger.info("_",`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${o}`)},onStateChange:e=>s(this,void 0,void 0,(function*(){const{state:o,reason:i}=e;if(this._logger.info("_",`[RCCallSession onStateChange] : state->${o} reason->${i}`),o===t.RCCallSessionState.KEEPING){const e=this._stateMachine.getCallId();this._logger.info("_",`[RCCallSession onStateChange] roomId: ${e}`);try{yield this._joinRoom(e)}catch(o){this._exceptionClose(t.RCCallEndReason.NETWORK_ERROR),this._logger.error("_",`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${e}`),console.error(o)}}else if(o===t.RCCallSessionState.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void r.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._logger.info("_","[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{this._logger.info("_",`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){this._logger.error("_","[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{this._logger.info("_",`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){this._logger.error("_","[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,o)=>{this._logger.info("_",`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${o}`);try{this._listener.onHungup(e,o,this)}catch(e){this._logger.error("_","[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:o})=>{this._logger.info("_",`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,o,this)}catch(e){this._logger.error("_","[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:e,mediaType:o})=>{this._logger.info("_",`[RCCallSession onMediaModify]sender: sender.userId -> ${e.userId} mediaType: ${o}`),o===t.RCCallMediaType.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(e,o,this)}catch(e){this._logger.error("_","[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}},crossAppkey:e=>{this._logger.info("_",`[RCCallSession crossAppkey] 是否跨 appkey: ${e}`),this._options.isCrossAppkey=e}});const{pushTitle:l,pushContent:a}=this._options.hungupPushConfig;this._stateMachine.setHungupPushConfig(l,a)}_joinRoom(e){return s(this,void 0,void 0,(function*(){let o;try{o=this._options.isCrossAppkey?yield this._rtcClient.joinCrossRTCRoom(e,this._options.joinType):yield this._rtcClient.joinRTCRoom(e,this._options.joinType);const{code:s,userIds:r,room:n}=o;if(s!==i.RCRTCCode.SUCCESS)return s===i.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(t.RCCallEndReason.SERVICE_NOT_OPENED),s===i.RCRTCCode.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(t.RCCallEndReason.OTHER_CLIENT_IN_CALL):this._exceptionClose(t.RCCallEndReason.NETWORK_ERROR),this._logger.info("_",`[RCCallClient _joinRoom] join room failed: roomId -> ${e} RCRTCCode -> ${s}`),{code:t.RCCallErrorCode.JOIN_ROOM_ERROR};if(this._stateMachine.getState()===t.RCCallSessionState.END)return yield this._rtcClient.leaveRoom(n),this._room=null,{code:t.RCCallErrorCode.SUCCESS};r.length<1&&(this.joinRoomTimer=new _((()=>{this._exceptionClose(t.RCCallEndReason.REMOTE_NETWORK_ERROR)}),6e4)),this._room=n}catch(o){return this._exceptionClose(t.RCCallEndReason.NETWORK_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${e}`),console.error(o),{code:t.RCCallErrorCode.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(o){return this._exceptionClose(t.RCCallEndReason.SUBSCRIBE_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${e}`),console.error(o),{code:t.RCCallErrorCode.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(o){return this._exceptionClose(t.RCCallEndReason.PUBLISH_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _publish Exception roomId -> ${e}`),console.error(o),{code:t.RCCallErrorCode.JOIN_ROOM_ERROR}}return{code:t.RCCallErrorCode.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return s(this,void 0,void 0,(function*(){const e=this._room.getRemoteTracks();if(e.length){const{code:o}=yield this._subscribeRetry(e,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);o!==i.RCRTCCode.SUCCESS&&(this._exceptionClose(t.RCCallEndReason.SUBSCRIBE_ERROR),this._logger.error("_",`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${o}`))}}))}_subscribeRetry(e,o=!1,t=0){return s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.subscribe(e);if(s!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(s,this)}catch(e){this._logger.error("_","[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!o)return{code:s};if(t>0)return t--,this._subscribeRetry(e,o,t)}return{code:s}}))}_publish(){return s(this,void 0,void 0,(function*(){const o=this._options.localTracks,{code:s}=yield this._publishRetry(o,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(s!==i.RCRTCCode.SUCCESS)return this._exceptionClose(t.RCCallEndReason.PUBLISH_ERROR),void this._logger.info("_",`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${s}`);this._options.produceType===e.CALLEE&&this._notifyTrackReady(o)}))}_publishRetry(e,o=!1,t=0){return s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.publish(e);if(s!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(s,this)}catch(e){this._logger.error("_","[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!o)return{code:s};if(t>0)return t--,this._publishRetry(e,o,t)}return{code:s}}))}_leaveRoom(){return s(this,void 0,void 0,(function*(){try{const e=yield this._rtcClient.leaveRoom(this._room);this._logger.info("_",`[RCCallSession _leaveRoom] Successfully exited the room code: ${e.code}`)}catch(e){this._logger.error("_","[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();r.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const o=l(e);if(!o.result)throw new Error(`[RCCallSession registerSessionListener] ${o.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(e,o){return s(this,void 0,void 0,(function*(){if(e===t.RCCallMediaType.AUDIO){const{code:e,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o&&o.audio&&Object.assign({},o.audio));return e!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(this._logger.info("_","[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:t.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:e,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",o&&Object.assign({},o));return e!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(this._logger.info("_","[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:t.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(e,o){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===t.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(t.RCCallMediaType.AUDIO_VIDEO,o);if(e!==t.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(t.RCCallMediaType.AUDIO,o);return e!==t.RCCallErrorCode.SUCCESS?(this._exceptionClose(t.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:e}):{code:e,tracks:i}}return{code:e,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(e,o);return i!==t.RCCallErrorCode.SUCCESS?(this._exceptionClose(t.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:i}):{code:i,tracks:s}}}))}changeAudioDevice(e){return s(this,void 0,void 0,(function*(){const o=[],s=[],{code:r,track:n}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",e);if(r!==i.RCRTCCode.SUCCESS)return this._logger.error("_",`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${r}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||s.push(e)})),o.push(n),s.push(n),this._options.localTracks=s,this._notifyTrackReady(o),this._room){const{code:e}=yield this._room.publish(o);if(e!==i.RCRTCCode.SUCCESS)return{code:t.RCCallErrorCode.AUDIO_PUBLISH_ERROR}}return{code:t.RCCallErrorCode.SUCCESS}}))}invite(e,o={}){var t,i;return s(this,void 0,void 0,(function*(){const{extra:s=""}=o,{pushTitle:r="",pushContent:n=""}=(null===(t=this._options.callPushConfig)||void 0===t?void 0:t.pushTitle)||(null===(i=this._options.callPushConfig)||void 0===i?void 0:i.pushContent)?this._options.callPushConfig:o,l=[h(e),C(s),d(r),u(n)],a=[];if(!l.every((e=>(!e.result&&a.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${a.join("\n")}`);const{code:c}=yield this._stateMachine.invite(e,{extra:s,pushTitle:r,pushContent:n});return{code:c}}))}accept(e){return s(this,void 0,void 0,(function*(){const o=(e=>{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}`);r.emit("hungupOtherSession",{session:this});const i=this._stateMachine.getMediaType(),{code:s,tracks:n}=yield this._getLocalTrack(i,e);if(s!==t.RCCallErrorCode.SUCCESS)return{code:s};this._options.localTracks=n;const{code:l}=yield this._stateMachine.accept();return l!==t.RCCallErrorCode.SUCCESS?(this._logger.error("_",`[RCCallSession accept]Send accept message failed -> code: ${l}`),{code:l}):{code:l}}))}hungup(){return s(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(e){return s(this,void 0,void 0,(function*(){const{code:o}=yield this._stateMachine.changeMediaType(e);return o!==t.RCCallErrorCode.SUCCESS&&this._logger.error("_",`[RCCallSession _changeMediaType] change media type fail code-> ${o}`),{code:o}}))}_getLocalVideoTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isVideoTrack()))),e):e}_getLocalAudioTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isAudioTrack()))),e):e}_setMediaTypeToAudioAndVideo(){return s(this,void 0,void 0,(function*(){const{code:e,track:o}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:s}=yield this._room.publish([o]);s===i.RCRTCCode.SUCCESS?(this._notifyTrackReady([o]),this._changeMediaType(t.RCCallMediaType.AUDIO_VIDEO)):this._logger.error("_",`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${e}`)}))}_setMediaTypeToAudio(){return s(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(e.length){e.forEach((e=>{e.mute()}));const{code:o}=yield this._room.unpublish(e);o!==i.RCRTCCode.SUCCESS&&this._logger.error("_",`[RCCallSession disableVideo] unpublish failed -> ${o}`),this._destroyTracks(e)}}))}descendAbility(){return s(this,void 0,void 0,(function*(){const{code:e}=yield this._changeMediaType(t.RCCallMediaType.AUDIO);return e===t.RCCallErrorCode.SUCCESS&&this._setMediaTypeToAudio(),{code:e}}))}disableVideoTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:t.RCCallErrorCode.NOT_IN_ROOM_ERROR};const e=this._getLocalVideoTracks();if(!e.length)return this._logger.error("_",`[RCCallSession disableVideoTrack] Room missing video track -> ${t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};if(e.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:t.RCCallErrorCode.SUCCESS};const{code:o}=yield this._room.unpublish(e);return o!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallSession disableVideo] unpublish failed -> ${o}`),{code:t.RCCallErrorCode.UNPUBLISH_VIDEO_ERROR}):(e.forEach((e=>{e.destroy()})),{code:t.RCCallErrorCode.SUCCESS})}))}enableVideoTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:t.RCCallErrorCode.NOT_IN_ROOM_ERROR};if(!this._options.isOffCameraWhenVideoDisable){const e=this._getLocalVideoTracks();return e.length?(e.forEach((e=>{e.unmute()})),{code:t.RCCallErrorCode.SUCCESS}):(this._logger.error("_",`[RCCallSession EnableVideoTrack] Room missing video track -> ${t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR})}const{code:e,track:o}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return this._logger.error("_",`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_VIDEO_TRACK_ERROR};const s=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():s.push(e)})),s.push(o),this._options.localTracks=s,o.mute();const{code:r}=yield this._room.publish([o]);return r!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${e}`),{code:t.RCCallErrorCode.VIDEO_PUBLISH_ERROR}):(o.unmute(),this._notifyTrackReady([o]),{code:t.RCCallErrorCode.SUCCESS})}))}disableAudioTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:t.RCCallErrorCode.NOT_IN_ROOM_ERROR};this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:t.RCCallErrorCode.NOT_IN_ROOM_ERROR};const e=this._getLocalAudioTracks();if(!e.length)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};e.forEach((e=>{e.unmute()}))}))}_destroyTracks(e){e.forEach((e=>{e.destroy()}))}_notifyTrackReady(e){e.forEach((e=>{try{this._listener.onTrackReady(e,this)}catch(e){this._logger.error("_","[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(e,o)=>{const s=this._rtcClient.getCurrentId();this._stateMachine.userLeave([s]),e?(o===i.RCKickReason.SERVER_KICK&&this._exceptionClose(t.RCCallEndReason.KICKED_BY_SERVER),o===i.RCKickReason.OTHER_KICK&&this._exceptionClose(t.RCCallEndReason.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(t.RCCallEndReason.NETWORK_ERROR)},onMessageReceive(e,o,t,i){},onRoomAttributeChange(e,o){},onAudioMuteChange:e=>{this._logger.info("_",`[RCCallSession onAudioMuteChange] userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"audio",trackId:e.getTrackId()};try{this._listener.onAudioMuteChange(o,this)}catch(e){this._logger.error("_","[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{this._logger.info("_",`[RCCallSession onVideoMuteChange]userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"video",trackId:e.getTrackId()};try{this._listener.onVideoMuteChange(o,this)}catch(e){this._logger.error("_","[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>s(this,void 0,void 0,(function*(){if(this._room){const{code:o}=yield this._room.subscribe(e);o!==i.RCRTCCode.SUCCESS&&this._logger.error("_",`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${o}`)}})),onTrackUnpublish:e=>{},onTrackReady:e=>{this._stateMachine.getMediaType()===t.RCCallMediaType.AUDIO&&e.isVideoTrack()||this._notifyTrackReady([e])},onUserJoin:e=>{this.joinRoomTimer&&this.joinRoomTimer.stop(),this._stateMachine.userJoin(e)},onUserLeave:e=>{this._logger.info("_",`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{this._logger.info("_",`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){this._logger.error("_","[RCCallSession onPing] listening onPing exception"),console.error(e)}}})}_registerReportListener(){this._room.registerReportListener({onStateReport:e=>{try{this._listener.onRTCStateReport&&this._listener.onRTCStateReport(e,this)}catch(e){this._logger.error("_","[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){this._logger.error("_","[RCCallSession onICEConnectionStateChange] onICEConnectionStateChange exception"),console.error(e)}}})}getSessionId(){return this._stateMachine.getCallId()}getRTCSessionId(){return this._room?this._room.getSessionId():null}getTargetId(){return this._stateMachine.getTargetId()}getConversationType(){return this._stateMachine.getConversationType()}getChannelId(){return this._stateMachine.getChannelId()}getRemoteUsers(){return this._stateMachine.getRemoteUsers()}getUsers(){return this._stateMachine.getRemoteUsers()}getUserState(e){if(!e||"string"!=typeof e)throw new Error("userId is required, must be of type 'string'");return this._stateMachine.getUserState(e)}getState(){return this._stateMachine.getState()}getCallerId(){return this._stateMachine.getCallerId()}getMediaType(){return this._stateMachine.getMediaType()}}class g{constructor(e,i,s,n){this._context=e,this._runtime=i,this._logger=s,this._sessionList=[],this._callPushConfig={},this._hungupPushConfig={},this._rtcClient=n.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:o.RTCJoinType.COEXIST,isAllowDemotionGetStream:!1,lang:t.RCCallLanguage.ZH},n),this._callEngine=new t.RCCallEngine(this._context,i,this._logger,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||t.RCCallLanguage.ZH}),r.on("sessionClose",(({session:e,summaryInfo:o})=>{this._removeSession(e);try{this._options.onSessionClose(e,o)}catch(e){this._logger.error("_","[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),r.on("hungupOtherSession",(({session:e})=>{const o=e.getSessionId();this._logger.info("_",`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${o}`),this._logger.info("_",`[RCCallClient hungupOtherSession] sessionList ->${this._sessionList.map((e=>e.getSessionId())).join(",")}`);let t=0;for(;this._sessionList.length>1;)this._sessionList[t].getSessionId()!==o?(this._sessionList[t].hungup(),this._sessionList.splice(t,1)):t++;this._logger.info("_",`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(o,t){this._logger.info("_","[RCCallClient _onInvite] Received invite message");const i=new R(o,this._rtcClient,this._logger,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:e.CALLEE,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});this._logger.info("_","[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(i);try{this._options.onSession(i,t)}catch(e){this._logger.error("_","[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!i._listener)throw this._logger.error("_","[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=l(i._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){this._logger.error("_","[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),this._logger.info("_","[RCCallClient registerUserInfo] successfully register user info data")}startCrossCall({targetId:e,mediaType:o=t.RCCallMediaType.AUDIO,listener:i,constraints:r,channelId:n="",extra:l="",pushTitle:a="",pushContent:c="",bitrate:C}){return s(this,void 0,void 0,(function*(){return this.__call({targetId:e,mediaType:o,listener:i,constraints:r,channelId:n,extra:l,pushTitle:a,pushContent:c,bitrate:C,isCrossAppkey:!0})}))}call({targetId:e,mediaType:o=t.RCCallMediaType.AUDIO,listener:i,constraints:r,channelId:n="",extra:l="",pushTitle:a="",pushContent:c="",bitrate:C}){return s(this,void 0,void 0,(function*(){return this.__call({targetId:e,mediaType:o,listener:i,constraints:r,channelId:n,extra:l,pushTitle:a,pushContent:c,bitrate:C})}))}__call({targetId:o,mediaType:i=t.RCCallMediaType.AUDIO,listener:r,constraints:n,channelId:h="",extra:_="",pushTitle:g="",pushContent:p="",bitrate:f,isCrossAppkey:m=!1}){return s(this,void 0,void 0,(function*(){const{pushTitle:s="",pushContent:S=""}=this._callPushConfig.pushTitle||this._callPushConfig.pushContent?this._callPushConfig:{pushTitle:g,pushContent:p};this._logger.info("_",`[RCCallClient call] extra->${_} pushTitle->${s} pushContent->${S}`);const T=[a(o),c(i),l(r),C(_),d(s),u(S)],y=[];if(!T.every((e=>(!e.result&&y.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${y.join("\n")}`);let E=[];const{code:I,tracks:v}=yield this._getLocalTrack(i,n);if(I!==t.RCCallErrorCode.SUCCESS)return{code:I};E=v,E.forEach((e=>{var o,t,i;e.isAudioTrack()&&(null==f?void 0:f.audio)&&e.setBitrate(null==f?void 0:f.audio),e.isVideoTrack()&&(null==f?void 0:f.video)&&e.setBitrate(null===(o=null==f?void 0:f.video)||void 0===o?void 0:o.max,null===(t=null==f?void 0:f.video)||void 0===t?void 0:t.min,null===(i=null==f?void 0:f.video)||void 0===i?void 0:i.start),r.onTrackReady(e)}));const{code:b,stateMachine:O}=yield this._callEngine.call(h,o,i,_,s,S,m);if(b===t.RCCallErrorCode.SUCCESS&&O){this._logger.info("_","[RCCallClient call] successfully created state machine");const o=new R(O,this._rtcClient,this._logger,{localTracks:E,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:e.CALLER,isCrossAppkey:m,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});return o.registerSessionListener(r),this._sessionList.push(o),this._logger.info("_",`[RCCallClient call] successfully created session object, sessionId: ${o.getSessionId()}`),{code:b,session:o}}return this._logger.error("_",`[RCCallClient call] call failed code ->: ${b}`),E.forEach((e=>{e.mute(),e.destroy()})),{code:b}}))}callInGroup({targetId:o,userIds:i,mediaType:r=t.RCCallMediaType.AUDIO,listener:n,constraints:_,channelId:g="",extra:p="",pushTitle:f="",pushContent:m="",bitrate:S}){return s(this,void 0,void 0,(function*(){const{pushTitle:s="",pushContent:T=""}=this._callPushConfig.pushTitle||this._callPushConfig.pushContent?this._callPushConfig:{pushTitle:f,pushContent:m},y=[a(o),h(i),c(r),l(n),C(p),d(s),u(T)],E=[];if(!y.every((e=>(!e.result&&E.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${E.join("\n")}`);let I=[];const{code:v,tracks:b}=yield this._getLocalTrack(r,_);if(v!==t.RCCallErrorCode.SUCCESS)return{code:v};I=b,I.forEach((e=>{var o,t,i;e.isAudioTrack()&&(null==S?void 0:S.audio)&&e.setBitrate(null==S?void 0:S.audio),e.isVideoTrack()&&(null==S?void 0:S.video)&&e.setBitrate(null===(o=null==S?void 0:S.video)||void 0===o?void 0:o.max,null===(t=null==S?void 0:S.video)||void 0===t?void 0:t.min,null===(i=null==S?void 0:S.video)||void 0===i?void 0:i.start),n.onTrackReady(e)}));const{code:O,stateMachine:k}=yield this._callEngine.callInGroup(g,o,r,i,p,s,T);if(O===t.RCCallErrorCode.SUCCESS&&k){this._logger.info("_","[RCCallClient callInGroup] successfully created state machine");const o=new R(k,this._rtcClient,this._logger,{localTracks:I,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:e.CALLER,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});return o.registerSessionListener(n),this._sessionList.push(o),this._logger.info("_",`[RCCallClient callInGroup] successfully created session object, sessionId: ${o.getSessionId()}`),{code:O,session:o}}return this._logger.info("_",`[RCCallClient callInGroup] callInGroup failed code -> ${O}`),I.forEach((e=>{e.mute(),e.destroy()})),{code:O}}))}_getLocalTrackCore(e,o){return s(this,void 0,void 0,(function*(){if(e===t.RCCallMediaType.AUDIO){const{code:e,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o&&o.audio&&Object.assign({},o.audio));return e!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(this._logger.info("_","[RCCallClient _getTrack] successfully get Audio local tracks"),{code:t.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:e,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",o&&Object.assign({},o));return e!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(this._logger.info("_","[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:t.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(e,o){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===t.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(t.RCCallMediaType.AUDIO_VIDEO,o);if(e!==t.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(t.RCCallMediaType.AUDIO,o);return e!==t.RCCallErrorCode.SUCCESS?{code:e}:{code:e,tracks:i}}return{code:e,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(e,o);return i!==t.RCCallErrorCode.SUCCESS?{code:i}:{code:i,tracks:s}}}))}_removeSession(e){const o=e.getSessionId();this._sessionList=this._sessionList.filter((e=>e.getSessionId()!==o))}getJoinedRoomInfo(){return s(this,void 0,void 0,(function*(){const{code:e,data:i}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return e!==o.ErrorCode.SUCCESS?(this._logger.error("_",`getJoinedUserInfo error code: ${e}`),{code:t.RCCallErrorCode.QUERY_JOINED_USER_INFO_ERROR}):{code:t.RCCallErrorCode.SUCCESS,data:i}}))}setPushConfig(e={},o={}){const t=[e,o].map((e=>(e=>{const{pushTitle:o="",pushContent:t=""}=e,i=[];return i.push(d(o)),i.push(u(t)),i})(e)))[0],i=[];if(!t.every((e=>(!e.result&&i.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup callPushConfig or hungupPushConfig] ${i.join("\n")}`);this._callPushConfig=e,this._hungupPushConfig=o}}o.VersionManage.add("plugin-call","5.1.2");const p={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,t,i){const s=n(i);if(!s.result)throw new Error(`[RCCallLib installer steup]${s.msg}`);if(!o.VersionManage.validEngine("^5.7.3"))throw new Error(`The current engine version '${o.VersionManage.getInfo().engine}' error, plugin-call required engine version at least '^5.7.3'.`);const r=e.createLogger("RCCall","RTC");return r.warn("_","RCCall Version: 5.1.2, Commit: 89ba2ed5a9c788362ba96f084fdc3c18106a64c4"),new g(e,t,r,i)}};Object.defineProperty(exports,"RCCallEndReason",{enumerable:!0,get:function(){return t.RCCallEndReason}}),Object.defineProperty(exports,"RCCallErrorCode",{enumerable:!0,get:function(){return t.RCCallErrorCode}}),Object.defineProperty(exports,"RCCallLanguage",{enumerable:!0,get:function(){return t.RCCallLanguage}}),Object.defineProperty(exports,"RCCallMediaType",{enumerable:!0,get:function(){return t.RCCallMediaType}}),Object.defineProperty(exports,"RCCallSessionState",{enumerable:!0,get:function(){return t.RCCallSessionState}}),Object.defineProperty(exports,"RCCallUserState",{enumerable:!0,get:function(){return t.RCCallUserState}}),exports.RCCallClient=g,exports.RCCallSession=R,exports.installer=p;
16
+ function s(e,o,t,i){return new(t||(t=Promise))((function(s,r){function n(e){try{a(i.next(e))}catch(e){r(e)}}function l(e){try{a(i.throw(e))}catch(e){r(e)}}function a(e){var o;e.done?s(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(n,l)}a((i=i.apply(e,o||[])).next())}))}!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(e||(e={}));var r=new class{constructor(){this.list={}}on(e,o){return(this.list[e]||(this.list[e]=[])).push(o),this}once(e,o){const t=i=>{this.off(e,t),o.call(this,i)};t.fun=o,this.on(e,t)}off(e,o){const t=this.list[e];if(!t)return!1;if(o){let e;for(let i=0,s=t.length;i<s;i++)if(e=t[i],e===o||e.fun===o){t.splice(i,1);break}}else t&&(t.length=0)}emit(e,o){const t=[...this.list[e]];if(!t||0===t.length)return!1;t.forEach((e=>{e.call(this,o)}))}};const n=e=>{if(!e)return{result:!1,msg:"Initialization missing parameter -> options"};if("object"!=typeof e)return{result:!1,msg:"Initialization options must be an object"};const i=Object.keys(e),s=[];return["rtcClient","onSession","onSessionClose"].forEach((e=>{i.includes(e)||s.push(e)})),s.length?{result:!1,msg:`Initialization missing parameter -> "${s.join(",")}"`}:"object"!=typeof e.rtcClient?{result:!1,msg:"Initialization 'rtcClient' parameter must be of type 'object'"}:"function"!=typeof e.onSession?{result:!1,msg:"Initialization 'onSession' parameter must be of type 'function'"}:"function"!=typeof e.onSessionClose?{result:!1,msg:"Initialization 'onSessionClose' parameter must be of type 'function'"}:void 0!==e.isAllowSubscribeRetry&&"boolean"!=typeof e.isAllowSubscribeRetry?{result:!1,msg:"Initialization 'isAllowSubscribeRetry' parameter must be of type 'boolean'"}:void 0!==e.isAllowPublishRetry&&"boolean"!=typeof e.isAllowPublishRetry?{result:!1,msg:"Initialization 'isAllowPublishRetry' parameter must be of type 'boolean'"}:void 0!==e.isOffCameraWhenVideoDisable&&"boolean"!=typeof e.isOffCameraWhenVideoDisable?{result:!1,msg:"Initialization 'isOffCameraWhenVideoDisable' parameter must be of type 'boolean'"}:void 0===e.joinType||(r=e.joinType,Object.values(o.RTCJoinType).includes(r))?void 0!==e.isAllowDemotionGetStream&&"boolean"!=typeof e.isAllowDemotionGetStream?{result:!1,msg:"Initialization 'isAllowDemotionGetStream' parameter must be of type 'boolean'"}:void 0===e.lang||function(e){return Object.values(t.RCCallLanguage).includes(e)}(e.lang)?void 0===e.logLevel||function(e){return Object.values(o.LogLevel).includes(e)}(e.logLevel)?void 0!==e.logStdout&&"function"!=typeof e.logStdout?{result:!1,msg:"Initialization 'logStdout' parameter must be of type 'function'"}:{result:!0}:{result:!1,msg:"Initialization 'logLevel' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'lang' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'joinType' parameter must be of type correct type"};var r},l=e=>{if(!e)return{result:!1,msg:"missing parameter -> listener"};if("object"!=typeof e)return{result:!1,msg:"listener must be an object"};const o=Object.keys(e),t=[];return["onRinging","onAccept","onHungup","onTrackReady"].forEach((e=>{o.includes(e)||t.push(e)})),t.length?{result:!1,msg:`missing parameter -> "${t.join(",")}"`}:"function"!=typeof e.onRinging?{result:!1,msg:"'onRinging' parameter must be of type 'function'"}:"function"!=typeof e.onAccept?{result:!1,msg:"'onAccept' parameter must be of type 'function'"}:"function"!=typeof e.onHungup?{result:!1,msg:"'onHungup' parameter must be of type 'function'"}:"function"!=typeof e.onTrackReady?{result:!1,msg:"'onTrackReady' parameter must be of type 'function'"}:{result:!0}},a=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},C=e=>e===t.RCCallMediaType.AUDIO||e===t.RCCallMediaType.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},c=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},d=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},u=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushContent' parameter must be of type 'string'"},h=e=>Array.isArray(e)&&e.length?e.every((e=>"string"==typeof e&&e.length>0))?{result:!0}:{result:!1,msg:"'userIds' parameter is required"}:{result:!1,msg:"'userIds' parameter is required, must be of type 'string[]'"};const _=e=>{return e&&e.audio&&void 0!==e.audio.micphoneId&&"string"!=typeof e.audio.micphoneId?{result:!1,msg:"'constraints.audio.micphoneId' must be of type 'string'"}:e&&e.audio&&void 0!==e.audio.sampleRate&&"number"!=typeof e.audio.sampleRate?{result:!1,msg:"'constraints.audio.sampleRate' must be of type 'number'"}:e&&e.video&&void 0!==e.video.cameraId&&"string"!=typeof e.video.cameraId?{result:!1,msg:"'constraints.video.cameraId' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&"string"!=typeof e.video.frameRate?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&(o=e.video.frameRate,!["FPS_10","FPS_15","FPS_24","FPS_30"].includes(o))?{result:!1,msg:"'frameRate' value is out of range"}:e&&e.video&&void 0!==e.video.resolution&&"string"!=typeof e.video.resolution?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.resolution&&(t=e.video.resolution,!i.RCResolution[t])?{result:!1,msg:"'resolution' value is out of range"}:!e||!e.video||e.video.frameRate&&e.video.resolution?{result:!0}:{result:!1,msg:"'resolution' and 'resolution' is required"};var o,t};class R{constructor(e,o){this._timerId=0,this._startTime=0,e&&(this._timerId=((e,o)=>setTimeout(e,o))((()=>{e()}),o)),this._startTime=Date.now()}stop(){clearTimeout(this._timerId);const e=Date.now();let o=e-this._startTime;return 0===this._startTime&&(o=0),{startTime:this._startTime,endTime:e,duration:o}}reset(){this._startTime=0}}class g{constructor(e,o,i,n={}){this._stateMachine=e,this._rtcClient=o,this._logger=i,this._options=n,this._listener=null,this._RETRYCOUNT=2,this.joinRoomTimer=null,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:o})=>{this._logger.info("_",`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${o}`)},onStateChange:e=>s(this,void 0,void 0,(function*(){const{state:o,reason:i}=e;if(this._logger.info("_",`[RCCallSession onStateChange] : state->${o} reason->${i}`),o===t.RCCallSessionState.KEEPING){const e=this._stateMachine.getCallId();this._logger.info("_",`[RCCallSession onStateChange] roomId: ${e}`);try{yield this._joinRoom(e)}catch(o){this._exceptionClose(t.RCCallEndReason.NETWORK_ERROR),this._logger.error("_",`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${e}`),console.error(o)}}else if(o===t.RCCallSessionState.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void r.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._logger.info("_","[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{this._logger.info("_",`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){this._logger.error("_","[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{this._logger.info("_",`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){this._logger.error("_","[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,o)=>{this._logger.info("_",`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${o}`);try{this._listener.onHungup(e,o,this)}catch(e){this._logger.error("_","[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:o})=>{this._logger.info("_",`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,o,this)}catch(e){this._logger.error("_","[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:e,mediaType:o})=>{this._logger.info("_",`[RCCallSession onMediaModify]sender: sender.userId -> ${e.userId} mediaType: ${o}`),o===t.RCCallMediaType.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(e,o,this)}catch(e){this._logger.error("_","[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}},crossAppkey:e=>{this._logger.info("_",`[RCCallSession crossAppkey] 是否跨 appkey: ${e}`),this._options.isCrossAppkey=e}});const{pushTitle:l,pushContent:a}=this._options.hungupPushConfig;this._stateMachine.setHungupPushConfig(l,a)}_joinRoom(e){return s(this,void 0,void 0,(function*(){let o;try{o=this._options.isCrossAppkey?yield this._rtcClient.joinCrossRTCRoom(e,this._options.joinType):yield this._rtcClient.joinRTCRoom(e,this._options.joinType);const{code:s,userIds:r,room:n}=o;if(s!==i.RCRTCCode.SUCCESS)return s===i.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(t.RCCallEndReason.SERVICE_NOT_OPENED),s===i.RCRTCCode.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(t.RCCallEndReason.OTHER_CLIENT_IN_CALL):this._exceptionClose(t.RCCallEndReason.NETWORK_ERROR),this._logger.info("_",`[RCCallClient _joinRoom] join room failed: roomId -> ${e} RCRTCCode -> ${s}`),{code:t.RCCallErrorCode.JOIN_ROOM_ERROR};if(this._stateMachine.getState()===t.RCCallSessionState.END)return yield this._rtcClient.leaveRoom(n),this._room=null,{code:t.RCCallErrorCode.SUCCESS};r.length<1&&(this.joinRoomTimer=new R((()=>{this._exceptionClose(t.RCCallEndReason.REMOTE_NETWORK_ERROR)}),6e4)),this._room=n}catch(o){return this._exceptionClose(t.RCCallEndReason.NETWORK_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${e}`),console.error(o),{code:t.RCCallErrorCode.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(o){return this._exceptionClose(t.RCCallEndReason.SUBSCRIBE_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${e}`),console.error(o),{code:t.RCCallErrorCode.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(o){return this._exceptionClose(t.RCCallEndReason.PUBLISH_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _publish Exception roomId -> ${e}`),console.error(o),{code:t.RCCallErrorCode.JOIN_ROOM_ERROR}}return{code:t.RCCallErrorCode.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return s(this,void 0,void 0,(function*(){const e=this._room.getRemoteTracks();if(e.length){const{code:o}=yield this._subscribeRetry(e,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);o!==i.RCRTCCode.SUCCESS&&(this._exceptionClose(t.RCCallEndReason.SUBSCRIBE_ERROR),this._logger.error("_",`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${o}`))}}))}_subscribeRetry(e,o=!1,t=0){return s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.subscribe(e);if(s!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(s,this)}catch(e){this._logger.error("_","[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!o)return{code:s};if(t>0)return t--,this._subscribeRetry(e,o,t)}return{code:s}}))}_publish(){return s(this,void 0,void 0,(function*(){const o=this._options.localTracks,{code:s}=yield this._publishRetry(o,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(s!==i.RCRTCCode.SUCCESS)return this._exceptionClose(t.RCCallEndReason.PUBLISH_ERROR),void this._logger.info("_",`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${s}`);this._options.produceType===e.CALLEE&&this._notifyTrackReady(o)}))}_publishRetry(e,o=!1,t=0){return s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.publish(e);if(s!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(s,this)}catch(e){this._logger.error("_","[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!o)return{code:s};if(t>0)return t--,this._publishRetry(e,o,t)}return{code:s}}))}_leaveRoom(){return s(this,void 0,void 0,(function*(){try{const e=yield this._rtcClient.leaveRoom(this._room);this._logger.info("_",`[RCCallSession _leaveRoom] Successfully exited the room code: ${e.code}`)}catch(e){this._logger.error("_","[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();r.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const o=l(e);if(!o.result)throw new Error(`[RCCallSession registerSessionListener] ${o.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(e,o){return s(this,void 0,void 0,(function*(){if(e===t.RCCallMediaType.AUDIO){const{code:e,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o&&o.audio&&Object.assign({},o.audio));return e!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(this._logger.info("_","[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:t.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:e,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",o&&Object.assign({},o));return e!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(this._logger.info("_","[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:t.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(e,o){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===t.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(t.RCCallMediaType.AUDIO_VIDEO,o);if(e!==t.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(t.RCCallMediaType.AUDIO,o);return e!==t.RCCallErrorCode.SUCCESS?(this._exceptionClose(t.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:e}):{code:e,tracks:i}}return{code:e,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(e,o);return i!==t.RCCallErrorCode.SUCCESS?(this._exceptionClose(t.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:i}):{code:i,tracks:s}}}))}changeAudioDevice(e){return s(this,void 0,void 0,(function*(){const o=[],s=[],{code:r,track:n}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",e);if(r!==i.RCRTCCode.SUCCESS)return this._logger.error("_",`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${r}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||s.push(e)})),o.push(n),s.push(n),this._options.localTracks=s,this._notifyTrackReady(o),this._room){const{code:e}=yield this._room.publish(o);if(e!==i.RCRTCCode.SUCCESS)return{code:t.RCCallErrorCode.AUDIO_PUBLISH_ERROR}}return{code:t.RCCallErrorCode.SUCCESS}}))}invite(e,o={}){var t,i;return s(this,void 0,void 0,(function*(){const{extra:s=""}=o,{pushTitle:r="",pushContent:n=""}=(null===(t=this._options.callPushConfig)||void 0===t?void 0:t.pushTitle)||(null===(i=this._options.callPushConfig)||void 0===i?void 0:i.pushContent)?this._options.callPushConfig:o,l=[h(e),c(s),d(r),u(n)],a=[];if(!l.every((e=>(!e.result&&a.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${a.join("\n")}`);const{code:C}=yield this._stateMachine.invite(e,{extra:s,pushTitle:r,pushContent:n});return{code:C}}))}accept(e){return s(this,void 0,void 0,(function*(){const o=_(e);if(!o.result)throw new Error(`[RCCallSession accept] ${o.msg}`);r.emit("hungupOtherSession",{session:this});const i=this._stateMachine.getMediaType(),{code:s,tracks:n}=yield this._getLocalTrack(i,e);if(s!==t.RCCallErrorCode.SUCCESS)return{code:s};this._options.localTracks=n;const{code:l}=yield this._stateMachine.accept();return l!==t.RCCallErrorCode.SUCCESS?(this._logger.error("_",`[RCCallSession accept]Send accept message failed -> code: ${l}`),{code:l}):{code:l}}))}hungup(){return s(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(e){return s(this,void 0,void 0,(function*(){const{code:o}=yield this._stateMachine.changeMediaType(e);return o!==t.RCCallErrorCode.SUCCESS&&this._logger.error("_",`[RCCallSession _changeMediaType] change media type fail code-> ${o}`),{code:o}}))}_getLocalVideoTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isVideoTrack()))),e):e}_getLocalAudioTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isAudioTrack()))),e):e}_setMediaTypeToAudioAndVideo(){return s(this,void 0,void 0,(function*(){const{code:e,track:o}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:s}=yield this._room.publish([o]);s===i.RCRTCCode.SUCCESS?(this._notifyTrackReady([o]),this._changeMediaType(t.RCCallMediaType.AUDIO_VIDEO)):this._logger.error("_",`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${e}`)}))}_setMediaTypeToAudio(){return s(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(e.length){e.forEach((e=>{e.mute()}));const{code:o}=yield this._room.unpublish(e);o!==i.RCRTCCode.SUCCESS&&this._logger.error("_",`[RCCallSession disableVideo] unpublish failed -> ${o}`),this._destroyTracks(e)}}))}descendAbility(){return s(this,void 0,void 0,(function*(){const{code:e}=yield this._changeMediaType(t.RCCallMediaType.AUDIO);return e===t.RCCallErrorCode.SUCCESS&&this._setMediaTypeToAudio(),{code:e}}))}disableVideoTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:t.RCCallErrorCode.NOT_IN_ROOM_ERROR};const e=this._getLocalVideoTracks();if(!e.length)return this._logger.error("_",`[RCCallSession disableVideoTrack] Room missing video track -> ${t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};if(e.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:t.RCCallErrorCode.SUCCESS};const{code:o}=yield this._room.unpublish(e);return o!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallSession disableVideo] unpublish failed -> ${o}`),{code:t.RCCallErrorCode.UNPUBLISH_VIDEO_ERROR}):(e.forEach((e=>{e.destroy()})),{code:t.RCCallErrorCode.SUCCESS})}))}enableVideoTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:t.RCCallErrorCode.NOT_IN_ROOM_ERROR};if(!this._options.isOffCameraWhenVideoDisable){const e=this._getLocalVideoTracks();return e.length?(e.forEach((e=>{e.unmute()})),{code:t.RCCallErrorCode.SUCCESS}):(this._logger.error("_",`[RCCallSession EnableVideoTrack] Room missing video track -> ${t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR})}const{code:e,track:o}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return this._logger.error("_",`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_VIDEO_TRACK_ERROR};const s=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():s.push(e)})),s.push(o),this._options.localTracks=s,o.mute();const{code:r}=yield this._room.publish([o]);return r!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${e}`),{code:t.RCCallErrorCode.VIDEO_PUBLISH_ERROR}):(o.unmute(),this._notifyTrackReady([o]),{code:t.RCCallErrorCode.SUCCESS})}))}disableAudioTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:t.RCCallErrorCode.NOT_IN_ROOM_ERROR};this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:t.RCCallErrorCode.NOT_IN_ROOM_ERROR};const e=this._getLocalAudioTracks();if(!e.length)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};e.forEach((e=>{e.unmute()}))}))}_destroyTracks(e){e.forEach((e=>{e.destroy()}))}_notifyTrackReady(e){e.forEach((e=>{try{this._listener.onTrackReady(e,this)}catch(e){this._logger.error("_","[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(e,o)=>{const s=this._rtcClient.getCurrentId();this._stateMachine.userLeave([s]),e?(o===i.RCKickReason.SERVER_KICK&&this._exceptionClose(t.RCCallEndReason.KICKED_BY_SERVER),o===i.RCKickReason.OTHER_KICK&&this._exceptionClose(t.RCCallEndReason.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(t.RCCallEndReason.NETWORK_ERROR)},onMessageReceive(e,o,t,i){},onRoomAttributeChange(e,o){},onAudioMuteChange:e=>{this._logger.info("_",`[RCCallSession onAudioMuteChange] userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"audio",trackId:e.getTrackId()};try{this._listener.onAudioMuteChange(o,this)}catch(e){this._logger.error("_","[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{this._logger.info("_",`[RCCallSession onVideoMuteChange]userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"video",trackId:e.getTrackId()};try{this._listener.onVideoMuteChange(o,this)}catch(e){this._logger.error("_","[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>s(this,void 0,void 0,(function*(){if(this._room){const{code:o}=yield this._room.subscribe(e);o!==i.RCRTCCode.SUCCESS&&this._logger.error("_",`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${o}`)}})),onTrackUnpublish:e=>{},onTrackReady:e=>{this._stateMachine.getMediaType()===t.RCCallMediaType.AUDIO&&e.isVideoTrack()||this._notifyTrackReady([e])},onUserJoin:e=>{this.joinRoomTimer&&this.joinRoomTimer.stop(),this._stateMachine.userJoin(e)},onUserLeave:e=>{this._logger.info("_",`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{this._logger.info("_",`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){this._logger.error("_","[RCCallSession onPing] listening onPing exception"),console.error(e)}}})}_registerReportListener(){this._room.registerReportListener({onStateReport:e=>{try{this._listener.onRTCStateReport&&this._listener.onRTCStateReport(e,this)}catch(e){this._logger.error("_","[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){this._logger.error("_","[RCCallSession onICEConnectionStateChange] onICEConnectionStateChange exception"),console.error(e)}}})}getSessionId(){return this._stateMachine.getCallId()}getRTCSessionId(){return this._room?this._room.getSessionId():null}getTargetId(){return this._stateMachine.getTargetId()}getConversationType(){return this._stateMachine.getConversationType()}getChannelId(){return this._stateMachine.getChannelId()}getRemoteUsers(){return this._stateMachine.getRemoteUsers()}getUsers(){return this._stateMachine.getRemoteUsers()}getUserState(e){if(!e||"string"!=typeof e)throw new Error("userId is required, must be of type 'string'");return this._stateMachine.getUserState(e)}getState(){return this._stateMachine.getState()}getCallerId(){return this._stateMachine.getCallerId()}getMediaType(){return this._stateMachine.getMediaType()}}class p{constructor(e,i,s,n){this._context=e,this._runtime=i,this._logger=s,this._sessionList=[],this._callPushConfig={},this._hungupPushConfig={},this._rtcClient=n.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:o.RTCJoinType.COEXIST,isAllowDemotionGetStream:!1,lang:t.RCCallLanguage.ZH},n),this._callEngine=new t.RCCallEngine(this._context,i,this._logger,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||t.RCCallLanguage.ZH}),r.on("sessionClose",(({session:e,summaryInfo:o})=>{this._removeSession(e);try{this._options.onSessionClose(e,o)}catch(e){this._logger.error("_","[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),r.on("hungupOtherSession",(({session:e})=>{const o=e.getSessionId();this._logger.info("_",`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${o}`),this._logger.info("_",`[RCCallClient hungupOtherSession] sessionList ->${this._sessionList.map((e=>e.getSessionId())).join(",")}`);let t=0;for(;this._sessionList.length>1;)this._sessionList[t].getSessionId()!==o?(this._sessionList[t].hungup(),this._sessionList.splice(t,1)):t++;this._logger.info("_",`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(o,t){this._logger.info("_","[RCCallClient _onInvite] Received invite message");const i=new g(o,this._rtcClient,this._logger,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:e.CALLEE,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});this._logger.info("_","[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(i);try{this._options.onSession(i,t)}catch(e){this._logger.error("_","[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!i._listener)throw this._logger.error("_","[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=l(i._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){this._logger.error("_","[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),this._logger.info("_","[RCCallClient registerUserInfo] successfully register user info data")}startCrossCall({targetId:e,mediaType:o=t.RCCallMediaType.AUDIO,listener:i,constraints:r,channelId:n="",extra:l="",pushTitle:a="",pushContent:C="",bitrate:c}){return s(this,void 0,void 0,(function*(){return this.__call({targetId:e,mediaType:o,listener:i,constraints:r,channelId:n,extra:l,pushTitle:a,pushContent:C,bitrate:c,isCrossAppkey:!0})}))}call({targetId:e,mediaType:o=t.RCCallMediaType.AUDIO,listener:i,constraints:r,channelId:n="",extra:l="",pushTitle:a="",pushContent:C="",bitrate:c}){return s(this,void 0,void 0,(function*(){return this.__call({targetId:e,mediaType:o,listener:i,constraints:r,channelId:n,extra:l,pushTitle:a,pushContent:C,bitrate:c})}))}__call({targetId:o,mediaType:i=t.RCCallMediaType.AUDIO,listener:r,constraints:n,channelId:h="",extra:_="",pushTitle:R="",pushContent:p="",bitrate:f,isCrossAppkey:m=!1}){return s(this,void 0,void 0,(function*(){const{pushTitle:s="",pushContent:S=""}=this._callPushConfig.pushTitle||this._callPushConfig.pushContent?this._callPushConfig:{pushTitle:R,pushContent:p};this._logger.info("_",`[RCCallClient call] extra->${_} pushTitle->${s} pushContent->${S}`);const T=[a(o),C(i),l(r),c(_),d(s),u(S)],y=[];if(!T.every((e=>(!e.result&&y.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${y.join("\n")}`);let E=[];const{code:I,tracks:v}=yield this._getLocalTrack(i,n);if(I!==t.RCCallErrorCode.SUCCESS)return{code:I};E=v,E.forEach((e=>{var o,t,i;e.isAudioTrack()&&(null==f?void 0:f.audio)&&e.setBitrate(null==f?void 0:f.audio),e.isVideoTrack()&&(null==f?void 0:f.video)&&e.setBitrate(null===(o=null==f?void 0:f.video)||void 0===o?void 0:o.max,null===(t=null==f?void 0:f.video)||void 0===t?void 0:t.min,null===(i=null==f?void 0:f.video)||void 0===i?void 0:i.start),r.onTrackReady(e)}));const{code:b,stateMachine:O}=yield this._callEngine.call(h,o,i,_,s,S,m);if(b===t.RCCallErrorCode.SUCCESS&&O){this._logger.info("_","[RCCallClient call] successfully created state machine");const o=new g(O,this._rtcClient,this._logger,{localTracks:E,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:e.CALLER,isCrossAppkey:m,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});return o.registerSessionListener(r),this._sessionList.push(o),this._logger.info("_",`[RCCallClient call] successfully created session object, sessionId: ${o.getSessionId()}`),{code:b,session:o}}return this._logger.error("_",`[RCCallClient call] call failed code ->: ${b}`),E.forEach((e=>{e.mute(),e.destroy()})),{code:b}}))}callInGroup({targetId:o,userIds:i,mediaType:r=t.RCCallMediaType.AUDIO,listener:n,constraints:_,channelId:R="",extra:p="",pushTitle:f="",pushContent:m="",bitrate:S}){return s(this,void 0,void 0,(function*(){const{pushTitle:s="",pushContent:T=""}=this._callPushConfig.pushTitle||this._callPushConfig.pushContent?this._callPushConfig:{pushTitle:f,pushContent:m},y=[a(o),h(i),C(r),l(n),c(p),d(s),u(T)],E=[];if(!y.every((e=>(!e.result&&E.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${E.join("\n")}`);let I=[];const{code:v,tracks:b}=yield this._getLocalTrack(r,_);if(v!==t.RCCallErrorCode.SUCCESS)return{code:v};I=b,I.forEach((e=>{var o,t,i;e.isAudioTrack()&&(null==S?void 0:S.audio)&&e.setBitrate(null==S?void 0:S.audio),e.isVideoTrack()&&(null==S?void 0:S.video)&&e.setBitrate(null===(o=null==S?void 0:S.video)||void 0===o?void 0:o.max,null===(t=null==S?void 0:S.video)||void 0===t?void 0:t.min,null===(i=null==S?void 0:S.video)||void 0===i?void 0:i.start),n.onTrackReady(e)}));const{code:O,stateMachine:k}=yield this._callEngine.callInGroup(R,o,r,i,p,s,T);if(O===t.RCCallErrorCode.SUCCESS&&k){this._logger.info("_","[RCCallClient callInGroup] successfully created state machine");const o=new g(k,this._rtcClient,this._logger,{localTracks:I,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:e.CALLER,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});return o.registerSessionListener(n),this._sessionList.push(o),this._logger.info("_",`[RCCallClient callInGroup] successfully created session object, sessionId: ${o.getSessionId()}`),{code:O,session:o}}return this._logger.info("_",`[RCCallClient callInGroup] callInGroup failed code -> ${O}`),I.forEach((e=>{e.mute(),e.destroy()})),{code:O}}))}_getLocalTrackCore(e,o){return s(this,void 0,void 0,(function*(){if(e===t.RCCallMediaType.AUDIO){const{code:e,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o&&o.audio&&Object.assign({},o.audio));return e!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(this._logger.info("_","[RCCallClient _getTrack] successfully get Audio local tracks"),{code:t.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:e,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",o&&Object.assign({},o));return e!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(this._logger.info("_","[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:t.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(e,o){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===t.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(t.RCCallMediaType.AUDIO_VIDEO,o);if(e!==t.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(t.RCCallMediaType.AUDIO,o);return e!==t.RCCallErrorCode.SUCCESS?{code:e}:{code:e,tracks:i}}return{code:e,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(e,o);return i!==t.RCCallErrorCode.SUCCESS?{code:i}:{code:i,tracks:s}}}))}_removeSession(e){const o=e.getSessionId();this._sessionList=this._sessionList.filter((e=>e.getSessionId()!==o))}getJoinedRoomInfo(){return s(this,void 0,void 0,(function*(){const{code:e,data:i}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return e!==o.ErrorCode.SUCCESS?(this._logger.error("_",`getJoinedUserInfo error code: ${e}`),{code:t.RCCallErrorCode.QUERY_JOINED_USER_INFO_ERROR}):{code:t.RCCallErrorCode.SUCCESS,data:i}}))}setPushConfig(e={},o={}){const t=[e,o].map((e=>(e=>{const{pushTitle:o="",pushContent:t=""}=e,i=[];return i.push(d(o)),i.push(u(t)),i})(e)))[0],i=[];if(!t.every((e=>(!e.result&&i.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup callPushConfig or hungupPushConfig] ${i.join("\n")}`);this._callPushConfig=e,this._hungupPushConfig=o}}o.VersionManage.add("plugin-call","5.1.3");const f={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,t,i){const s=n(i);if(!s.result)throw new Error(`[RCCallLib installer steup]${s.msg}`);if(!o.VersionManage.validEngine("^5.7.6"))throw new Error(`The current engine version '${o.VersionManage.getInfo().engine}' error, plugin-call required engine version at least '^5.7.6'.`);const r=e.createLogger("RCCall","RTC");return r.warn("_","RCCall Version: 5.1.3, Commit: c1ec87082611a289263c27c340ee414ee9e60ba8"),new p(e,t,r,i)}};Object.defineProperty(exports,"RCCallEndReason",{enumerable:!0,get:function(){return t.RCCallEndReason}}),Object.defineProperty(exports,"RCCallErrorCode",{enumerable:!0,get:function(){return t.RCCallErrorCode}}),Object.defineProperty(exports,"RCCallLanguage",{enumerable:!0,get:function(){return t.RCCallLanguage}}),Object.defineProperty(exports,"RCCallMediaType",{enumerable:!0,get:function(){return t.RCCallMediaType}}),Object.defineProperty(exports,"RCCallSessionState",{enumerable:!0,get:function(){return t.RCCallSessionState}}),Object.defineProperty(exports,"RCCallUserState",{enumerable:!0,get:function(){return t.RCCallUserState}}),exports.RCCallClient=p,exports.RCCallSession=g,exports.installer=f;
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 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=e=>{if(!e)return{result:!1,msg:"Initialization missing parameter -> options"};if("object"!=typeof e)return{result:!1,msg:"Initialization options must be an object"};const i=Object.keys(e),s=[];return["rtcClient","onSession","onSessionClose"].forEach((e=>{i.includes(e)||s.push(e)})),s.length?{result:!1,msg:`Initialization missing parameter -> "${s.join(",")}"`}:"object"!=typeof e.rtcClient?{result:!1,msg:"Initialization 'rtcClient' parameter must be of type 'object'"}:"function"!=typeof e.onSession?{result:!1,msg:"Initialization 'onSession' parameter must be of type 'function'"}:"function"!=typeof e.onSessionClose?{result:!1,msg:"Initialization 'onSessionClose' parameter must be of type 'function'"}:void 0!==e.isAllowSubscribeRetry&&"boolean"!=typeof e.isAllowSubscribeRetry?{result:!1,msg:"Initialization 'isAllowSubscribeRetry' parameter must be of type 'boolean'"}:void 0!==e.isAllowPublishRetry&&"boolean"!=typeof e.isAllowPublishRetry?{result:!1,msg:"Initialization 'isAllowPublishRetry' parameter must be of type 'boolean'"}:void 0!==e.isOffCameraWhenVideoDisable&&"boolean"!=typeof e.isOffCameraWhenVideoDisable?{result:!1,msg:"Initialization 'isOffCameraWhenVideoDisable' parameter must be of type 'boolean'"}:void 0===e.joinType||(r=e.joinType,Object.values(o.RTCJoinType).includes(r))?void 0!==e.isAllowDemotionGetStream&&"boolean"!=typeof e.isAllowDemotionGetStream?{result:!1,msg:"Initialization 'isAllowDemotionGetStream' parameter must be of type 'boolean'"}:void 0===e.lang||function(e){return Object.values(t.RCCallLanguage).includes(e)}(e.lang)?void 0===e.logLevel||function(e){return Object.values(o.LogLevel).includes(e)}(e.logLevel)?void 0!==e.logStdout&&"function"!=typeof e.logStdout?{result:!1,msg:"Initialization 'logStdout' parameter must be of type 'function'"}:{result:!0}:{result:!1,msg:"Initialization 'logLevel' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'lang' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'joinType' parameter must be of type correct type"};var r},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=e=>e===t.RCCallMediaType.AUDIO||e===t.RCCallMediaType.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},d=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},u=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},h=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushContent' parameter must be of type 'string'"},_=e=>Array.isArray(e)&&e.length?e.every((e=>"string"==typeof e&&e.length>0))?{result:!0}:{result:!1,msg:"'userIds' parameter is required"}:{result:!1,msg:"'userIds' parameter is required, must be of type 'string[]'"};class R{constructor(e,o){this._timerId=0,this._startTime=0,e&&(this._timerId=((e,o)=>setTimeout(e,o))((()=>{e()}),o)),this._startTime=Date.now()}stop(){clearTimeout(this._timerId);const e=Date.now();let o=e-this._startTime;return 0===this._startTime&&(o=0),{startTime:this._startTime,endTime:e,duration:o}}reset(){this._startTime=0}}class g{constructor(e,o,i,r={}){this._stateMachine=e,this._rtcClient=o,this._logger=i,this._options=r,this._listener=null,this._RETRYCOUNT=2,this.joinRoomTimer=null,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:o})=>{this._logger.info("_",`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${o}`)},onStateChange:e=>s(this,void 0,void 0,(function*(){const{state:o,reason:i}=e;if(this._logger.info("_",`[RCCallSession onStateChange] : state->${o} reason->${i}`),o===t.RCCallSessionState.KEEPING){const e=this._stateMachine.getCallId();this._logger.info("_",`[RCCallSession onStateChange] roomId: ${e}`);try{yield this._joinRoom(e)}catch(o){this._exceptionClose(t.RCCallEndReason.NETWORK_ERROR),this._logger.error("_",`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${e}`),console.error(o)}}else if(o===t.RCCallSessionState.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void n.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._logger.info("_","[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{this._logger.info("_",`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){this._logger.error("_","[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{this._logger.info("_",`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){this._logger.error("_","[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,o)=>{this._logger.info("_",`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${o}`);try{this._listener.onHungup(e,o,this)}catch(e){this._logger.error("_","[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:o})=>{this._logger.info("_",`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,o,this)}catch(e){this._logger.error("_","[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:e,mediaType:o})=>{this._logger.info("_",`[RCCallSession onMediaModify]sender: sender.userId -> ${e.userId} mediaType: ${o}`),o===t.RCCallMediaType.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(e,o,this)}catch(e){this._logger.error("_","[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}},crossAppkey:e=>{this._logger.info("_",`[RCCallSession crossAppkey] 是否跨 appkey: ${e}`),this._options.isCrossAppkey=e}});const{pushTitle:l,pushContent:a}=this._options.hungupPushConfig;this._stateMachine.setHungupPushConfig(l,a)}_joinRoom(e){return s(this,void 0,void 0,(function*(){let o;try{o=this._options.isCrossAppkey?yield this._rtcClient.joinCrossRTCRoom(e,this._options.joinType):yield this._rtcClient.joinRTCRoom(e,this._options.joinType);const{code:s,userIds:r,room:n}=o;if(s!==i.RCRTCCode.SUCCESS)return s===i.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(t.RCCallEndReason.SERVICE_NOT_OPENED),s===i.RCRTCCode.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(t.RCCallEndReason.OTHER_CLIENT_IN_CALL):this._exceptionClose(t.RCCallEndReason.NETWORK_ERROR),this._logger.info("_",`[RCCallClient _joinRoom] join room failed: roomId -> ${e} RCRTCCode -> ${s}`),{code:t.RCCallErrorCode.JOIN_ROOM_ERROR};if(this._stateMachine.getState()===t.RCCallSessionState.END)return yield this._rtcClient.leaveRoom(n),this._room=null,{code:t.RCCallErrorCode.SUCCESS};r.length<1&&(this.joinRoomTimer=new R((()=>{this._exceptionClose(t.RCCallEndReason.REMOTE_NETWORK_ERROR)}),6e4)),this._room=n}catch(o){return this._exceptionClose(t.RCCallEndReason.NETWORK_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${e}`),console.error(o),{code:t.RCCallErrorCode.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(o){return this._exceptionClose(t.RCCallEndReason.SUBSCRIBE_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${e}`),console.error(o),{code:t.RCCallErrorCode.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(o){return this._exceptionClose(t.RCCallEndReason.PUBLISH_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _publish Exception roomId -> ${e}`),console.error(o),{code:t.RCCallErrorCode.JOIN_ROOM_ERROR}}return{code:t.RCCallErrorCode.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return s(this,void 0,void 0,(function*(){const e=this._room.getRemoteTracks();if(e.length){const{code:o}=yield this._subscribeRetry(e,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);o!==i.RCRTCCode.SUCCESS&&(this._exceptionClose(t.RCCallEndReason.SUBSCRIBE_ERROR),this._logger.error("_",`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${o}`))}}))}_subscribeRetry(e,o=!1,t=0){return s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.subscribe(e);if(s!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(s,this)}catch(e){this._logger.error("_","[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!o)return{code:s};if(t>0)return t--,this._subscribeRetry(e,o,t)}return{code:s}}))}_publish(){return s(this,void 0,void 0,(function*(){const e=this._options.localTracks,{code:o}=yield this._publishRetry(e,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(o!==i.RCRTCCode.SUCCESS)return this._exceptionClose(t.RCCallEndReason.PUBLISH_ERROR),void this._logger.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 s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.publish(e);if(s!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(s,this)}catch(e){this._logger.error("_","[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!o)return{code:s};if(t>0)return t--,this._publishRetry(e,o,t)}return{code:s}}))}_leaveRoom(){return s(this,void 0,void 0,(function*(){try{const e=yield this._rtcClient.leaveRoom(this._room);this._logger.info("_",`[RCCallSession _leaveRoom] Successfully exited the room code: ${e.code}`)}catch(e){this._logger.error("_","[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();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(e,o){return s(this,void 0,void 0,(function*(){if(e===t.RCCallMediaType.AUDIO){const{code:e,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o&&o.audio&&Object.assign({},o.audio));return e!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(this._logger.info("_","[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:t.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:e,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",o&&Object.assign({},o));return e!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(this._logger.info("_","[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:t.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(e,o){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===t.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(t.RCCallMediaType.AUDIO_VIDEO,o);if(e!==t.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(t.RCCallMediaType.AUDIO,o);return e!==t.RCCallErrorCode.SUCCESS?(this._exceptionClose(t.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:e}):{code:e,tracks:i}}return{code:e,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(e,o);return i!==t.RCCallErrorCode.SUCCESS?(this._exceptionClose(t.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:i}):{code:i,tracks:s}}}))}changeAudioDevice(e){return s(this,void 0,void 0,(function*(){const o=[],s=[],{code:r,track:n}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",e);if(r!==i.RCRTCCode.SUCCESS)return this._logger.error("_",`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${r}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||s.push(e)})),o.push(n),s.push(n),this._options.localTracks=s,this._notifyTrackReady(o),this._room){const{code:e}=yield this._room.publish(o);if(e!==i.RCRTCCode.SUCCESS)return{code:t.RCCallErrorCode.AUDIO_PUBLISH_ERROR}}return{code:t.RCCallErrorCode.SUCCESS}}))}invite(e,o={}){var t,i;return s(this,void 0,void 0,(function*(){const{extra:s=""}=o,{pushTitle:r="",pushContent:n=""}=(null===(t=this._options.callPushConfig)||void 0===t?void 0:t.pushTitle)||(null===(i=this._options.callPushConfig)||void 0===i?void 0:i.pushContent)?this._options.callPushConfig:o,l=[_(e),d(s),u(r),h(n)],a=[];if(!l.every((e=>(!e.result&&a.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${a.join("\n")}`);const{code:c}=yield this._stateMachine.invite(e,{extra:s,pushTitle:r,pushContent:n});return{code:c}}))}accept(e){return s(this,void 0,void 0,(function*(){const o=(e=>{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}`);n.emit("hungupOtherSession",{session:this});const i=this._stateMachine.getMediaType(),{code:s,tracks:r}=yield this._getLocalTrack(i,e);if(s!==t.RCCallErrorCode.SUCCESS)return{code:s};this._options.localTracks=r;const{code:l}=yield this._stateMachine.accept();return l!==t.RCCallErrorCode.SUCCESS?(this._logger.error("_",`[RCCallSession accept]Send accept message failed -> code: ${l}`),{code:l}):{code:l}}))}hungup(){return s(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(e){return s(this,void 0,void 0,(function*(){const{code:o}=yield this._stateMachine.changeMediaType(e);return o!==t.RCCallErrorCode.SUCCESS&&this._logger.error("_",`[RCCallSession _changeMediaType] change media type fail code-> ${o}`),{code:o}}))}_getLocalVideoTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isVideoTrack()))),e):e}_getLocalAudioTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isAudioTrack()))),e):e}_setMediaTypeToAudioAndVideo(){return s(this,void 0,void 0,(function*(){const{code:e,track:o}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:s}=yield this._room.publish([o]);s===i.RCRTCCode.SUCCESS?(this._notifyTrackReady([o]),this._changeMediaType(t.RCCallMediaType.AUDIO_VIDEO)):this._logger.error("_",`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${e}`)}))}_setMediaTypeToAudio(){return s(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(e.length){e.forEach((e=>{e.mute()}));const{code:o}=yield this._room.unpublish(e);o!==i.RCRTCCode.SUCCESS&&this._logger.error("_",`[RCCallSession disableVideo] unpublish failed -> ${o}`),this._destroyTracks(e)}}))}descendAbility(){return s(this,void 0,void 0,(function*(){const{code:e}=yield this._changeMediaType(t.RCCallMediaType.AUDIO);return e===t.RCCallErrorCode.SUCCESS&&this._setMediaTypeToAudio(),{code:e}}))}disableVideoTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:t.RCCallErrorCode.NOT_IN_ROOM_ERROR};const e=this._getLocalVideoTracks();if(!e.length)return this._logger.error("_",`[RCCallSession disableVideoTrack] Room missing video track -> ${t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};if(e.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:t.RCCallErrorCode.SUCCESS};const{code:o}=yield this._room.unpublish(e);return o!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallSession disableVideo] unpublish failed -> ${o}`),{code:t.RCCallErrorCode.UNPUBLISH_VIDEO_ERROR}):(e.forEach((e=>{e.destroy()})),{code:t.RCCallErrorCode.SUCCESS})}))}enableVideoTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:t.RCCallErrorCode.NOT_IN_ROOM_ERROR};if(!this._options.isOffCameraWhenVideoDisable){const e=this._getLocalVideoTracks();return e.length?(e.forEach((e=>{e.unmute()})),{code:t.RCCallErrorCode.SUCCESS}):(this._logger.error("_",`[RCCallSession EnableVideoTrack] Room missing video track -> ${t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR})}const{code:e,track:o}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return this._logger.error("_",`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_VIDEO_TRACK_ERROR};const s=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():s.push(e)})),s.push(o),this._options.localTracks=s,o.mute();const{code:r}=yield this._room.publish([o]);return r!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${e}`),{code:t.RCCallErrorCode.VIDEO_PUBLISH_ERROR}):(o.unmute(),this._notifyTrackReady([o]),{code:t.RCCallErrorCode.SUCCESS})}))}disableAudioTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:t.RCCallErrorCode.NOT_IN_ROOM_ERROR};this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:t.RCCallErrorCode.NOT_IN_ROOM_ERROR};const e=this._getLocalAudioTracks();if(!e.length)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};e.forEach((e=>{e.unmute()}))}))}_destroyTracks(e){e.forEach((e=>{e.destroy()}))}_notifyTrackReady(e){e.forEach((e=>{try{this._listener.onTrackReady(e,this)}catch(e){this._logger.error("_","[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(e,o)=>{const s=this._rtcClient.getCurrentId();this._stateMachine.userLeave([s]),e?(o===i.RCKickReason.SERVER_KICK&&this._exceptionClose(t.RCCallEndReason.KICKED_BY_SERVER),o===i.RCKickReason.OTHER_KICK&&this._exceptionClose(t.RCCallEndReason.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(t.RCCallEndReason.NETWORK_ERROR)},onMessageReceive(e,o,t,i){},onRoomAttributeChange(e,o){},onAudioMuteChange:e=>{this._logger.info("_",`[RCCallSession onAudioMuteChange] userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"audio",trackId:e.getTrackId()};try{this._listener.onAudioMuteChange(o,this)}catch(e){this._logger.error("_","[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{this._logger.info("_",`[RCCallSession onVideoMuteChange]userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"video",trackId:e.getTrackId()};try{this._listener.onVideoMuteChange(o,this)}catch(e){this._logger.error("_","[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>s(this,void 0,void 0,(function*(){if(this._room){const{code:o}=yield this._room.subscribe(e);o!==i.RCRTCCode.SUCCESS&&this._logger.error("_",`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${o}`)}})),onTrackUnpublish:e=>{},onTrackReady:e=>{this._stateMachine.getMediaType()===t.RCCallMediaType.AUDIO&&e.isVideoTrack()||this._notifyTrackReady([e])},onUserJoin:e=>{this.joinRoomTimer&&this.joinRoomTimer.stop(),this._stateMachine.userJoin(e)},onUserLeave:e=>{this._logger.info("_",`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{this._logger.info("_",`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){this._logger.error("_","[RCCallSession onPing] listening onPing exception"),console.error(e)}}})}_registerReportListener(){this._room.registerReportListener({onStateReport:e=>{try{this._listener.onRTCStateReport&&this._listener.onRTCStateReport(e,this)}catch(e){this._logger.error("_","[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){this._logger.error("_","[RCCallSession onICEConnectionStateChange] onICEConnectionStateChange exception"),console.error(e)}}})}getSessionId(){return this._stateMachine.getCallId()}getRTCSessionId(){return this._room?this._room.getSessionId():null}getTargetId(){return this._stateMachine.getTargetId()}getConversationType(){return this._stateMachine.getConversationType()}getChannelId(){return this._stateMachine.getChannelId()}getRemoteUsers(){return this._stateMachine.getRemoteUsers()}getUsers(){return this._stateMachine.getRemoteUsers()}getUserState(e){if(!e||"string"!=typeof e)throw new Error("userId is required, must be of type 'string'");return this._stateMachine.getUserState(e)}getState(){return this._stateMachine.getState()}getCallerId(){return this._stateMachine.getCallerId()}getMediaType(){return this._stateMachine.getMediaType()}}class p{constructor(e,i,s,r){this._context=e,this._runtime=i,this._logger=s,this._sessionList=[],this._callPushConfig={},this._hungupPushConfig={},this._rtcClient=r.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:o.RTCJoinType.COEXIST,isAllowDemotionGetStream:!1,lang:t.RCCallLanguage.ZH},r),this._callEngine=new t.RCCallEngine(this._context,i,this._logger,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||t.RCCallLanguage.ZH}),n.on("sessionClose",(({session:e,summaryInfo:o})=>{this._removeSession(e);try{this._options.onSessionClose(e,o)}catch(e){this._logger.error("_","[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),n.on("hungupOtherSession",(({session:e})=>{const o=e.getSessionId();this._logger.info("_",`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${o}`),this._logger.info("_",`[RCCallClient hungupOtherSession] sessionList ->${this._sessionList.map((e=>e.getSessionId())).join(",")}`);let t=0;for(;this._sessionList.length>1;)this._sessionList[t].getSessionId()!==o?(this._sessionList[t].hungup(),this._sessionList.splice(t,1)):t++;this._logger.info("_",`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e,o){this._logger.info("_","[RCCallClient _onInvite] Received invite message");const t=new g(e,this._rtcClient,this._logger,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:r.CALLEE,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});this._logger.info("_","[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(t);try{this._options.onSession(t,o)}catch(e){this._logger.error("_","[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!t._listener)throw this._logger.error("_","[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=a(t._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){this._logger.error("_","[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),this._logger.info("_","[RCCallClient registerUserInfo] successfully register user info data")}startCrossCall({targetId:e,mediaType:o=t.RCCallMediaType.AUDIO,listener:i,constraints:r,channelId:n="",extra:l="",pushTitle:a="",pushContent:c="",bitrate:C}){return s(this,void 0,void 0,(function*(){return this.__call({targetId:e,mediaType:o,listener:i,constraints:r,channelId:n,extra:l,pushTitle:a,pushContent:c,bitrate:C,isCrossAppkey:!0})}))}call({targetId:e,mediaType:o=t.RCCallMediaType.AUDIO,listener:i,constraints:r,channelId:n="",extra:l="",pushTitle:a="",pushContent:c="",bitrate:C}){return s(this,void 0,void 0,(function*(){return this.__call({targetId:e,mediaType:o,listener:i,constraints:r,channelId:n,extra:l,pushTitle:a,pushContent:c,bitrate:C})}))}__call({targetId:e,mediaType:o=t.RCCallMediaType.AUDIO,listener:i,constraints:n,channelId:l="",extra:_="",pushTitle:R="",pushContent:p="",bitrate:f,isCrossAppkey:m=!1}){return s(this,void 0,void 0,(function*(){const{pushTitle:s="",pushContent:S=""}=this._callPushConfig.pushTitle||this._callPushConfig.pushContent?this._callPushConfig:{pushTitle:R,pushContent:p};this._logger.info("_",`[RCCallClient call] extra->${_} pushTitle->${s} pushContent->${S}`);const T=[c(e),C(o),a(i),d(_),u(s),h(S)],y=[];if(!T.every((e=>(!e.result&&y.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${y.join("\n")}`);let E=[];const{code:I,tracks:b}=yield this._getLocalTrack(o,n);if(I!==t.RCCallErrorCode.SUCCESS)return{code:I};E=b,E.forEach((e=>{var o,t,s;e.isAudioTrack()&&(null==f?void 0:f.audio)&&e.setBitrate(null==f?void 0:f.audio),e.isVideoTrack()&&(null==f?void 0:f.video)&&e.setBitrate(null===(o=null==f?void 0:f.video)||void 0===o?void 0:o.max,null===(t=null==f?void 0:f.video)||void 0===t?void 0:t.min,null===(s=null==f?void 0:f.video)||void 0===s?void 0:s.start),i.onTrackReady(e)}));const{code:v,stateMachine:O}=yield this._callEngine.call(l,e,o,_,s,S,m);if(v===t.RCCallErrorCode.SUCCESS&&O){this._logger.info("_","[RCCallClient call] successfully created state machine");const e=new g(O,this._rtcClient,this._logger,{localTracks:E,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:r.CALLER,isCrossAppkey:m,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});return e.registerSessionListener(i),this._sessionList.push(e),this._logger.info("_",`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:v,session:e}}return this._logger.error("_",`[RCCallClient call] call failed code ->: ${v}`),E.forEach((e=>{e.mute(),e.destroy()})),{code:v}}))}callInGroup({targetId:e,userIds:o,mediaType:i=t.RCCallMediaType.AUDIO,listener:n,constraints:l,channelId:R="",extra:p="",pushTitle:f="",pushContent:m="",bitrate:S}){return s(this,void 0,void 0,(function*(){const{pushTitle:s="",pushContent:T=""}=this._callPushConfig.pushTitle||this._callPushConfig.pushContent?this._callPushConfig:{pushTitle:f,pushContent:m},y=[c(e),_(o),C(i),a(n),d(p),u(s),h(T)],E=[];if(!y.every((e=>(!e.result&&E.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${E.join("\n")}`);let I=[];const{code:b,tracks:v}=yield this._getLocalTrack(i,l);if(b!==t.RCCallErrorCode.SUCCESS)return{code:b};I=v,I.forEach((e=>{var o,t,i;e.isAudioTrack()&&(null==S?void 0:S.audio)&&e.setBitrate(null==S?void 0:S.audio),e.isVideoTrack()&&(null==S?void 0:S.video)&&e.setBitrate(null===(o=null==S?void 0:S.video)||void 0===o?void 0:o.max,null===(t=null==S?void 0:S.video)||void 0===t?void 0:t.min,null===(i=null==S?void 0:S.video)||void 0===i?void 0:i.start),n.onTrackReady(e)}));const{code:O,stateMachine:k}=yield this._callEngine.callInGroup(R,e,i,o,p,s,T);if(O===t.RCCallErrorCode.SUCCESS&&k){this._logger.info("_","[RCCallClient callInGroup] successfully created state machine");const e=new g(k,this._rtcClient,this._logger,{localTracks:I,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:r.CALLER,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});return e.registerSessionListener(n),this._sessionList.push(e),this._logger.info("_",`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:O,session:e}}return this._logger.info("_",`[RCCallClient callInGroup] callInGroup failed code -> ${O}`),I.forEach((e=>{e.mute(),e.destroy()})),{code:O}}))}_getLocalTrackCore(e,o){return s(this,void 0,void 0,(function*(){if(e===t.RCCallMediaType.AUDIO){const{code:e,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o&&o.audio&&Object.assign({},o.audio));return e!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(this._logger.info("_","[RCCallClient _getTrack] successfully get Audio local tracks"),{code:t.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:e,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",o&&Object.assign({},o));return e!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(this._logger.info("_","[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:t.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(e,o){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===t.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(t.RCCallMediaType.AUDIO_VIDEO,o);if(e!==t.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(t.RCCallMediaType.AUDIO,o);return e!==t.RCCallErrorCode.SUCCESS?{code:e}:{code:e,tracks:i}}return{code:e,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(e,o);return i!==t.RCCallErrorCode.SUCCESS?{code:i}:{code:i,tracks:s}}}))}_removeSession(e){const o=e.getSessionId();this._sessionList=this._sessionList.filter((e=>e.getSessionId()!==o))}getJoinedRoomInfo(){return s(this,void 0,void 0,(function*(){const{code:e,data:i}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return e!==o.ErrorCode.SUCCESS?(this._logger.error("_",`getJoinedUserInfo error code: ${e}`),{code:t.RCCallErrorCode.QUERY_JOINED_USER_INFO_ERROR}):{code:t.RCCallErrorCode.SUCCESS,data:i}}))}setPushConfig(e={},o={}){const t=[e,o].map((e=>(e=>{const{pushTitle:o="",pushContent:t=""}=e,i=[];return i.push(u(o)),i.push(h(t)),i})(e)))[0],i=[];if(!t.every((e=>(!e.result&&i.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup callPushConfig or hungupPushConfig] ${i.join("\n")}`);this._callPushConfig=e,this._hungupPushConfig=o}}o.VersionManage.add("plugin-call","5.1.2");const f={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,t,i){const s=l(i);if(!s.result)throw new Error(`[RCCallLib installer steup]${s.msg}`);if(!o.VersionManage.validEngine("^5.7.3"))throw new Error(`The current engine version '${o.VersionManage.getInfo().engine}' error, plugin-call required engine version at least '^5.7.3'.`);const r=e.createLogger("RCCall","RTC");return r.warn("_","RCCall Version: 5.1.2, Commit: 89ba2ed5a9c788362ba96f084fdc3c18106a64c4"),new p(e,t,r,i)}};Object.defineProperty(e,"RCCallEndReason",{enumerable:!0,get:function(){return t.RCCallEndReason}}),Object.defineProperty(e,"RCCallErrorCode",{enumerable:!0,get:function(){return t.RCCallErrorCode}}),Object.defineProperty(e,"RCCallLanguage",{enumerable:!0,get:function(){return t.RCCallLanguage}}),Object.defineProperty(e,"RCCallMediaType",{enumerable:!0,get:function(){return t.RCCallMediaType}}),Object.defineProperty(e,"RCCallSessionState",{enumerable:!0,get:function(){return t.RCCallSessionState}}),Object.defineProperty(e,"RCCallUserState",{enumerable:!0,get:function(){return t.RCCallUserState}}),e.RCCallClient=p,e.RCCallSession=g,e.installer=f,Object.defineProperty(e,"__esModule",{value:!0})}));
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=e=>{if(!e)return{result:!1,msg:"Initialization missing parameter -> options"};if("object"!=typeof e)return{result:!1,msg:"Initialization options must be an object"};const i=Object.keys(e),s=[];return["rtcClient","onSession","onSessionClose"].forEach((e=>{i.includes(e)||s.push(e)})),s.length?{result:!1,msg:`Initialization missing parameter -> "${s.join(",")}"`}:"object"!=typeof e.rtcClient?{result:!1,msg:"Initialization 'rtcClient' parameter must be of type 'object'"}:"function"!=typeof e.onSession?{result:!1,msg:"Initialization 'onSession' parameter must be of type 'function'"}:"function"!=typeof e.onSessionClose?{result:!1,msg:"Initialization 'onSessionClose' parameter must be of type 'function'"}:void 0!==e.isAllowSubscribeRetry&&"boolean"!=typeof e.isAllowSubscribeRetry?{result:!1,msg:"Initialization 'isAllowSubscribeRetry' parameter must be of type 'boolean'"}:void 0!==e.isAllowPublishRetry&&"boolean"!=typeof e.isAllowPublishRetry?{result:!1,msg:"Initialization 'isAllowPublishRetry' parameter must be of type 'boolean'"}:void 0!==e.isOffCameraWhenVideoDisable&&"boolean"!=typeof e.isOffCameraWhenVideoDisable?{result:!1,msg:"Initialization 'isOffCameraWhenVideoDisable' parameter must be of type 'boolean'"}:void 0===e.joinType||(r=e.joinType,Object.values(o.RTCJoinType).includes(r))?void 0!==e.isAllowDemotionGetStream&&"boolean"!=typeof e.isAllowDemotionGetStream?{result:!1,msg:"Initialization 'isAllowDemotionGetStream' parameter must be of type 'boolean'"}:void 0===e.lang||function(e){return Object.values(t.RCCallLanguage).includes(e)}(e.lang)?void 0===e.logLevel||function(e){return Object.values(o.LogLevel).includes(e)}(e.logLevel)?void 0!==e.logStdout&&"function"!=typeof e.logStdout?{result:!1,msg:"Initialization 'logStdout' parameter must be of type 'function'"}:{result:!0}:{result:!1,msg:"Initialization 'logLevel' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'lang' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'joinType' parameter must be of type correct type"};var r},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=e=>e===t.RCCallMediaType.AUDIO||e===t.RCCallMediaType.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},d=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},u=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},h=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushContent' parameter must be of type 'string'"},_=e=>Array.isArray(e)&&e.length?e.every((e=>"string"==typeof e&&e.length>0))?{result:!0}:{result:!1,msg:"'userIds' parameter is required"}:{result:!1,msg:"'userIds' parameter is required, must be of type 'string[]'"};const R=e=>{return e&&e.audio&&void 0!==e.audio.micphoneId&&"string"!=typeof e.audio.micphoneId?{result:!1,msg:"'constraints.audio.micphoneId' must be of type 'string'"}:e&&e.audio&&void 0!==e.audio.sampleRate&&"number"!=typeof e.audio.sampleRate?{result:!1,msg:"'constraints.audio.sampleRate' must be of type 'number'"}:e&&e.video&&void 0!==e.video.cameraId&&"string"!=typeof e.video.cameraId?{result:!1,msg:"'constraints.video.cameraId' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&"string"!=typeof e.video.frameRate?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&(o=e.video.frameRate,!["FPS_10","FPS_15","FPS_24","FPS_30"].includes(o))?{result:!1,msg:"'frameRate' value is out of range"}:e&&e.video&&void 0!==e.video.resolution&&"string"!=typeof e.video.resolution?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.resolution&&(t=e.video.resolution,!i.RCResolution[t])?{result:!1,msg:"'resolution' value is out of range"}:!e||!e.video||e.video.frameRate&&e.video.resolution?{result:!0}:{result:!1,msg:"'resolution' and 'resolution' is required"};var o,t};class g{constructor(e,o){this._timerId=0,this._startTime=0,e&&(this._timerId=((e,o)=>setTimeout(e,o))((()=>{e()}),o)),this._startTime=Date.now()}stop(){clearTimeout(this._timerId);const e=Date.now();let o=e-this._startTime;return 0===this._startTime&&(o=0),{startTime:this._startTime,endTime:e,duration:o}}reset(){this._startTime=0}}class p{constructor(e,o,i,r={}){this._stateMachine=e,this._rtcClient=o,this._logger=i,this._options=r,this._listener=null,this._RETRYCOUNT=2,this.joinRoomTimer=null,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:o})=>{this._logger.info("_",`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${o}`)},onStateChange:e=>s(this,void 0,void 0,(function*(){const{state:o,reason:i}=e;if(this._logger.info("_",`[RCCallSession onStateChange] : state->${o} reason->${i}`),o===t.RCCallSessionState.KEEPING){const e=this._stateMachine.getCallId();this._logger.info("_",`[RCCallSession onStateChange] roomId: ${e}`);try{yield this._joinRoom(e)}catch(o){this._exceptionClose(t.RCCallEndReason.NETWORK_ERROR),this._logger.error("_",`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${e}`),console.error(o)}}else if(o===t.RCCallSessionState.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void n.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._logger.info("_","[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{this._logger.info("_",`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){this._logger.error("_","[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{this._logger.info("_",`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){this._logger.error("_","[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,o)=>{this._logger.info("_",`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${o}`);try{this._listener.onHungup(e,o,this)}catch(e){this._logger.error("_","[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:o})=>{this._logger.info("_",`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,o,this)}catch(e){this._logger.error("_","[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:e,mediaType:o})=>{this._logger.info("_",`[RCCallSession onMediaModify]sender: sender.userId -> ${e.userId} mediaType: ${o}`),o===t.RCCallMediaType.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(e,o,this)}catch(e){this._logger.error("_","[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}},crossAppkey:e=>{this._logger.info("_",`[RCCallSession crossAppkey] 是否跨 appkey: ${e}`),this._options.isCrossAppkey=e}});const{pushTitle:l,pushContent:a}=this._options.hungupPushConfig;this._stateMachine.setHungupPushConfig(l,a)}_joinRoom(e){return s(this,void 0,void 0,(function*(){let o;try{o=this._options.isCrossAppkey?yield this._rtcClient.joinCrossRTCRoom(e,this._options.joinType):yield this._rtcClient.joinRTCRoom(e,this._options.joinType);const{code:s,userIds:r,room:n}=o;if(s!==i.RCRTCCode.SUCCESS)return s===i.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(t.RCCallEndReason.SERVICE_NOT_OPENED),s===i.RCRTCCode.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(t.RCCallEndReason.OTHER_CLIENT_IN_CALL):this._exceptionClose(t.RCCallEndReason.NETWORK_ERROR),this._logger.info("_",`[RCCallClient _joinRoom] join room failed: roomId -> ${e} RCRTCCode -> ${s}`),{code:t.RCCallErrorCode.JOIN_ROOM_ERROR};if(this._stateMachine.getState()===t.RCCallSessionState.END)return yield this._rtcClient.leaveRoom(n),this._room=null,{code:t.RCCallErrorCode.SUCCESS};r.length<1&&(this.joinRoomTimer=new g((()=>{this._exceptionClose(t.RCCallEndReason.REMOTE_NETWORK_ERROR)}),6e4)),this._room=n}catch(o){return this._exceptionClose(t.RCCallEndReason.NETWORK_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${e}`),console.error(o),{code:t.RCCallErrorCode.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(o){return this._exceptionClose(t.RCCallEndReason.SUBSCRIBE_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${e}`),console.error(o),{code:t.RCCallErrorCode.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(o){return this._exceptionClose(t.RCCallEndReason.PUBLISH_ERROR),this._logger.error("_",`[RCCallSession _joinRoom] _publish Exception roomId -> ${e}`),console.error(o),{code:t.RCCallErrorCode.JOIN_ROOM_ERROR}}return{code:t.RCCallErrorCode.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return s(this,void 0,void 0,(function*(){const e=this._room.getRemoteTracks();if(e.length){const{code:o}=yield this._subscribeRetry(e,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);o!==i.RCRTCCode.SUCCESS&&(this._exceptionClose(t.RCCallEndReason.SUBSCRIBE_ERROR),this._logger.error("_",`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${o}`))}}))}_subscribeRetry(e,o=!1,t=0){return s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.subscribe(e);if(s!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(s,this)}catch(e){this._logger.error("_","[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!o)return{code:s};if(t>0)return t--,this._subscribeRetry(e,o,t)}return{code:s}}))}_publish(){return s(this,void 0,void 0,(function*(){const e=this._options.localTracks,{code:o}=yield this._publishRetry(e,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(o!==i.RCRTCCode.SUCCESS)return this._exceptionClose(t.RCCallEndReason.PUBLISH_ERROR),void this._logger.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 s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.publish(e);if(s!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(s,this)}catch(e){this._logger.error("_","[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!o)return{code:s};if(t>0)return t--,this._publishRetry(e,o,t)}return{code:s}}))}_leaveRoom(){return s(this,void 0,void 0,(function*(){try{const e=yield this._rtcClient.leaveRoom(this._room);this._logger.info("_",`[RCCallSession _leaveRoom] Successfully exited the room code: ${e.code}`)}catch(e){this._logger.error("_","[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();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(e,o){return s(this,void 0,void 0,(function*(){if(e===t.RCCallMediaType.AUDIO){const{code:e,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o&&o.audio&&Object.assign({},o.audio));return e!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(this._logger.info("_","[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:t.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:e,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",o&&Object.assign({},o));return e!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(this._logger.info("_","[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:t.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(e,o){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===t.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(t.RCCallMediaType.AUDIO_VIDEO,o);if(e!==t.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(t.RCCallMediaType.AUDIO,o);return e!==t.RCCallErrorCode.SUCCESS?(this._exceptionClose(t.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:e}):{code:e,tracks:i}}return{code:e,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(e,o);return i!==t.RCCallErrorCode.SUCCESS?(this._exceptionClose(t.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:i}):{code:i,tracks:s}}}))}changeAudioDevice(e){return s(this,void 0,void 0,(function*(){const o=[],s=[],{code:r,track:n}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",e);if(r!==i.RCRTCCode.SUCCESS)return this._logger.error("_",`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${r}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||s.push(e)})),o.push(n),s.push(n),this._options.localTracks=s,this._notifyTrackReady(o),this._room){const{code:e}=yield this._room.publish(o);if(e!==i.RCRTCCode.SUCCESS)return{code:t.RCCallErrorCode.AUDIO_PUBLISH_ERROR}}return{code:t.RCCallErrorCode.SUCCESS}}))}invite(e,o={}){var t,i;return s(this,void 0,void 0,(function*(){const{extra:s=""}=o,{pushTitle:r="",pushContent:n=""}=(null===(t=this._options.callPushConfig)||void 0===t?void 0:t.pushTitle)||(null===(i=this._options.callPushConfig)||void 0===i?void 0:i.pushContent)?this._options.callPushConfig:o,l=[_(e),d(s),u(r),h(n)],a=[];if(!l.every((e=>(!e.result&&a.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${a.join("\n")}`);const{code:c}=yield this._stateMachine.invite(e,{extra:s,pushTitle:r,pushContent:n});return{code:c}}))}accept(e){return s(this,void 0,void 0,(function*(){const o=R(e);if(!o.result)throw new Error(`[RCCallSession accept] ${o.msg}`);n.emit("hungupOtherSession",{session:this});const i=this._stateMachine.getMediaType(),{code:s,tracks:r}=yield this._getLocalTrack(i,e);if(s!==t.RCCallErrorCode.SUCCESS)return{code:s};this._options.localTracks=r;const{code:l}=yield this._stateMachine.accept();return l!==t.RCCallErrorCode.SUCCESS?(this._logger.error("_",`[RCCallSession accept]Send accept message failed -> code: ${l}`),{code:l}):{code:l}}))}hungup(){return s(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(e){return s(this,void 0,void 0,(function*(){const{code:o}=yield this._stateMachine.changeMediaType(e);return o!==t.RCCallErrorCode.SUCCESS&&this._logger.error("_",`[RCCallSession _changeMediaType] change media type fail code-> ${o}`),{code:o}}))}_getLocalVideoTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isVideoTrack()))),e):e}_getLocalAudioTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isAudioTrack()))),e):e}_setMediaTypeToAudioAndVideo(){return s(this,void 0,void 0,(function*(){const{code:e,track:o}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:s}=yield this._room.publish([o]);s===i.RCRTCCode.SUCCESS?(this._notifyTrackReady([o]),this._changeMediaType(t.RCCallMediaType.AUDIO_VIDEO)):this._logger.error("_",`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${e}`)}))}_setMediaTypeToAudio(){return s(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(e.length){e.forEach((e=>{e.mute()}));const{code:o}=yield this._room.unpublish(e);o!==i.RCRTCCode.SUCCESS&&this._logger.error("_",`[RCCallSession disableVideo] unpublish failed -> ${o}`),this._destroyTracks(e)}}))}descendAbility(){return s(this,void 0,void 0,(function*(){const{code:e}=yield this._changeMediaType(t.RCCallMediaType.AUDIO);return e===t.RCCallErrorCode.SUCCESS&&this._setMediaTypeToAudio(),{code:e}}))}disableVideoTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:t.RCCallErrorCode.NOT_IN_ROOM_ERROR};const e=this._getLocalVideoTracks();if(!e.length)return this._logger.error("_",`[RCCallSession disableVideoTrack] Room missing video track -> ${t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};if(e.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:t.RCCallErrorCode.SUCCESS};const{code:o}=yield this._room.unpublish(e);return o!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallSession disableVideo] unpublish failed -> ${o}`),{code:t.RCCallErrorCode.UNPUBLISH_VIDEO_ERROR}):(e.forEach((e=>{e.destroy()})),{code:t.RCCallErrorCode.SUCCESS})}))}enableVideoTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:t.RCCallErrorCode.NOT_IN_ROOM_ERROR};if(!this._options.isOffCameraWhenVideoDisable){const e=this._getLocalVideoTracks();return e.length?(e.forEach((e=>{e.unmute()})),{code:t.RCCallErrorCode.SUCCESS}):(this._logger.error("_",`[RCCallSession EnableVideoTrack] Room missing video track -> ${t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR})}const{code:e,track:o}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return this._logger.error("_",`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_VIDEO_TRACK_ERROR};const s=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():s.push(e)})),s.push(o),this._options.localTracks=s,o.mute();const{code:r}=yield this._room.publish([o]);return r!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${e}`),{code:t.RCCallErrorCode.VIDEO_PUBLISH_ERROR}):(o.unmute(),this._notifyTrackReady([o]),{code:t.RCCallErrorCode.SUCCESS})}))}disableAudioTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:t.RCCallErrorCode.NOT_IN_ROOM_ERROR};this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return s(this,void 0,void 0,(function*(){if(!this._room)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.NOT_IN_ROOM_ERROR}`),{code:t.RCCallErrorCode.NOT_IN_ROOM_ERROR};const e=this._getLocalAudioTracks();if(!e.length)return this._logger.error("_",`[RCCallSession disableAudioTrack] Room missing audio track -> ${t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:t.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};e.forEach((e=>{e.unmute()}))}))}_destroyTracks(e){e.forEach((e=>{e.destroy()}))}_notifyTrackReady(e){e.forEach((e=>{try{this._listener.onTrackReady(e,this)}catch(e){this._logger.error("_","[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(e,o)=>{const s=this._rtcClient.getCurrentId();this._stateMachine.userLeave([s]),e?(o===i.RCKickReason.SERVER_KICK&&this._exceptionClose(t.RCCallEndReason.KICKED_BY_SERVER),o===i.RCKickReason.OTHER_KICK&&this._exceptionClose(t.RCCallEndReason.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(t.RCCallEndReason.NETWORK_ERROR)},onMessageReceive(e,o,t,i){},onRoomAttributeChange(e,o){},onAudioMuteChange:e=>{this._logger.info("_",`[RCCallSession onAudioMuteChange] userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"audio",trackId:e.getTrackId()};try{this._listener.onAudioMuteChange(o,this)}catch(e){this._logger.error("_","[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{this._logger.info("_",`[RCCallSession onVideoMuteChange]userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"video",trackId:e.getTrackId()};try{this._listener.onVideoMuteChange(o,this)}catch(e){this._logger.error("_","[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>s(this,void 0,void 0,(function*(){if(this._room){const{code:o}=yield this._room.subscribe(e);o!==i.RCRTCCode.SUCCESS&&this._logger.error("_",`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${o}`)}})),onTrackUnpublish:e=>{},onTrackReady:e=>{this._stateMachine.getMediaType()===t.RCCallMediaType.AUDIO&&e.isVideoTrack()||this._notifyTrackReady([e])},onUserJoin:e=>{this.joinRoomTimer&&this.joinRoomTimer.stop(),this._stateMachine.userJoin(e)},onUserLeave:e=>{this._logger.info("_",`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{this._logger.info("_",`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){this._logger.error("_","[RCCallSession onPing] listening onPing exception"),console.error(e)}}})}_registerReportListener(){this._room.registerReportListener({onStateReport:e=>{try{this._listener.onRTCStateReport&&this._listener.onRTCStateReport(e,this)}catch(e){this._logger.error("_","[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){this._logger.error("_","[RCCallSession onICEConnectionStateChange] onICEConnectionStateChange exception"),console.error(e)}}})}getSessionId(){return this._stateMachine.getCallId()}getRTCSessionId(){return this._room?this._room.getSessionId():null}getTargetId(){return this._stateMachine.getTargetId()}getConversationType(){return this._stateMachine.getConversationType()}getChannelId(){return this._stateMachine.getChannelId()}getRemoteUsers(){return this._stateMachine.getRemoteUsers()}getUsers(){return this._stateMachine.getRemoteUsers()}getUserState(e){if(!e||"string"!=typeof e)throw new Error("userId is required, must be of type 'string'");return this._stateMachine.getUserState(e)}getState(){return this._stateMachine.getState()}getCallerId(){return this._stateMachine.getCallerId()}getMediaType(){return this._stateMachine.getMediaType()}}class f{constructor(e,i,s,r){this._context=e,this._runtime=i,this._logger=s,this._sessionList=[],this._callPushConfig={},this._hungupPushConfig={},this._rtcClient=r.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:o.RTCJoinType.COEXIST,isAllowDemotionGetStream:!1,lang:t.RCCallLanguage.ZH},r),this._callEngine=new t.RCCallEngine(this._context,i,this._logger,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||t.RCCallLanguage.ZH}),n.on("sessionClose",(({session:e,summaryInfo:o})=>{this._removeSession(e);try{this._options.onSessionClose(e,o)}catch(e){this._logger.error("_","[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),n.on("hungupOtherSession",(({session:e})=>{const o=e.getSessionId();this._logger.info("_",`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${o}`),this._logger.info("_",`[RCCallClient hungupOtherSession] sessionList ->${this._sessionList.map((e=>e.getSessionId())).join(",")}`);let t=0;for(;this._sessionList.length>1;)this._sessionList[t].getSessionId()!==o?(this._sessionList[t].hungup(),this._sessionList.splice(t,1)):t++;this._logger.info("_",`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e,o){this._logger.info("_","[RCCallClient _onInvite] Received invite message");const t=new p(e,this._rtcClient,this._logger,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:r.CALLEE,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});this._logger.info("_","[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(t);try{this._options.onSession(t,o)}catch(e){this._logger.error("_","[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!t._listener)throw this._logger.error("_","[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=a(t._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){this._logger.error("_","[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),this._logger.info("_","[RCCallClient registerUserInfo] successfully register user info data")}startCrossCall({targetId:e,mediaType:o=t.RCCallMediaType.AUDIO,listener:i,constraints:r,channelId:n="",extra:l="",pushTitle:a="",pushContent:c="",bitrate:C}){return s(this,void 0,void 0,(function*(){return this.__call({targetId:e,mediaType:o,listener:i,constraints:r,channelId:n,extra:l,pushTitle:a,pushContent:c,bitrate:C,isCrossAppkey:!0})}))}call({targetId:e,mediaType:o=t.RCCallMediaType.AUDIO,listener:i,constraints:r,channelId:n="",extra:l="",pushTitle:a="",pushContent:c="",bitrate:C}){return s(this,void 0,void 0,(function*(){return this.__call({targetId:e,mediaType:o,listener:i,constraints:r,channelId:n,extra:l,pushTitle:a,pushContent:c,bitrate:C})}))}__call({targetId:e,mediaType:o=t.RCCallMediaType.AUDIO,listener:i,constraints:n,channelId:l="",extra:_="",pushTitle:R="",pushContent:g="",bitrate:f,isCrossAppkey:m=!1}){return s(this,void 0,void 0,(function*(){const{pushTitle:s="",pushContent:S=""}=this._callPushConfig.pushTitle||this._callPushConfig.pushContent?this._callPushConfig:{pushTitle:R,pushContent:g};this._logger.info("_",`[RCCallClient call] extra->${_} pushTitle->${s} pushContent->${S}`);const T=[c(e),C(o),a(i),d(_),u(s),h(S)],y=[];if(!T.every((e=>(!e.result&&y.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${y.join("\n")}`);let E=[];const{code:I,tracks:v}=yield this._getLocalTrack(o,n);if(I!==t.RCCallErrorCode.SUCCESS)return{code:I};E=v,E.forEach((e=>{var o,t,s;e.isAudioTrack()&&(null==f?void 0:f.audio)&&e.setBitrate(null==f?void 0:f.audio),e.isVideoTrack()&&(null==f?void 0:f.video)&&e.setBitrate(null===(o=null==f?void 0:f.video)||void 0===o?void 0:o.max,null===(t=null==f?void 0:f.video)||void 0===t?void 0:t.min,null===(s=null==f?void 0:f.video)||void 0===s?void 0:s.start),i.onTrackReady(e)}));const{code:b,stateMachine:O}=yield this._callEngine.call(l,e,o,_,s,S,m);if(b===t.RCCallErrorCode.SUCCESS&&O){this._logger.info("_","[RCCallClient call] successfully created state machine");const e=new p(O,this._rtcClient,this._logger,{localTracks:E,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:r.CALLER,isCrossAppkey:m,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});return e.registerSessionListener(i),this._sessionList.push(e),this._logger.info("_",`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:b,session:e}}return this._logger.error("_",`[RCCallClient call] call failed code ->: ${b}`),E.forEach((e=>{e.mute(),e.destroy()})),{code:b}}))}callInGroup({targetId:e,userIds:o,mediaType:i=t.RCCallMediaType.AUDIO,listener:n,constraints:l,channelId:R="",extra:g="",pushTitle:f="",pushContent:m="",bitrate:S}){return s(this,void 0,void 0,(function*(){const{pushTitle:s="",pushContent:T=""}=this._callPushConfig.pushTitle||this._callPushConfig.pushContent?this._callPushConfig:{pushTitle:f,pushContent:m},y=[c(e),_(o),C(i),a(n),d(g),u(s),h(T)],E=[];if(!y.every((e=>(!e.result&&E.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${E.join("\n")}`);let I=[];const{code:v,tracks:b}=yield this._getLocalTrack(i,l);if(v!==t.RCCallErrorCode.SUCCESS)return{code:v};I=b,I.forEach((e=>{var o,t,i;e.isAudioTrack()&&(null==S?void 0:S.audio)&&e.setBitrate(null==S?void 0:S.audio),e.isVideoTrack()&&(null==S?void 0:S.video)&&e.setBitrate(null===(o=null==S?void 0:S.video)||void 0===o?void 0:o.max,null===(t=null==S?void 0:S.video)||void 0===t?void 0:t.min,null===(i=null==S?void 0:S.video)||void 0===i?void 0:i.start),n.onTrackReady(e)}));const{code:O,stateMachine:k}=yield this._callEngine.callInGroup(R,e,i,o,g,s,T);if(O===t.RCCallErrorCode.SUCCESS&&k){this._logger.info("_","[RCCallClient callInGroup] successfully created state machine");const e=new p(k,this._rtcClient,this._logger,{localTracks:I,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:r.CALLER,callPushConfig:this._callPushConfig,hungupPushConfig:this._hungupPushConfig});return e.registerSessionListener(n),this._sessionList.push(e),this._logger.info("_",`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:O,session:e}}return this._logger.info("_",`[RCCallClient callInGroup] callInGroup failed code -> ${O}`),I.forEach((e=>{e.mute(),e.destroy()})),{code:O}}))}_getLocalTrackCore(e,o){return s(this,void 0,void 0,(function*(){if(e===t.RCCallMediaType.AUDIO){const{code:e,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o&&o.audio&&Object.assign({},o.audio));return e!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(this._logger.info("_","[RCCallClient _getTrack] successfully get Audio local tracks"),{code:t.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:e,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",o&&Object.assign({},o));return e!==i.RCRTCCode.SUCCESS?(this._logger.error("_",`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${e}`),{code:t.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(this._logger.info("_","[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:t.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(e,o){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===t.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(t.RCCallMediaType.AUDIO_VIDEO,o);if(e!==t.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(t.RCCallMediaType.AUDIO,o);return e!==t.RCCallErrorCode.SUCCESS?{code:e}:{code:e,tracks:i}}return{code:e,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(e,o);return i!==t.RCCallErrorCode.SUCCESS?{code:i}:{code:i,tracks:s}}}))}_removeSession(e){const o=e.getSessionId();this._sessionList=this._sessionList.filter((e=>e.getSessionId()!==o))}getJoinedRoomInfo(){return s(this,void 0,void 0,(function*(){const{code:e,data:i}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return e!==o.ErrorCode.SUCCESS?(this._logger.error("_",`getJoinedUserInfo error code: ${e}`),{code:t.RCCallErrorCode.QUERY_JOINED_USER_INFO_ERROR}):{code:t.RCCallErrorCode.SUCCESS,data:i}}))}setPushConfig(e={},o={}){const t=[e,o].map((e=>(e=>{const{pushTitle:o="",pushContent:t=""}=e,i=[];return i.push(u(o)),i.push(h(t)),i})(e)))[0],i=[];if(!t.every((e=>(!e.result&&i.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup callPushConfig or hungupPushConfig] ${i.join("\n")}`);this._callPushConfig=e,this._hungupPushConfig=o}}o.VersionManage.add("plugin-call","5.1.3");const m={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,t,i){const s=l(i);if(!s.result)throw new Error(`[RCCallLib installer steup]${s.msg}`);if(!o.VersionManage.validEngine("^5.7.6"))throw new Error(`The current engine version '${o.VersionManage.getInfo().engine}' error, plugin-call required engine version at least '^5.7.6'.`);const r=e.createLogger("RCCall","RTC");return r.warn("_","RCCall Version: 5.1.3, Commit: c1ec87082611a289263c27c340ee414ee9e60ba8"),new f(e,t,r,i)}};Object.defineProperty(e,"RCCallEndReason",{enumerable:!0,get:function(){return t.RCCallEndReason}}),Object.defineProperty(e,"RCCallErrorCode",{enumerable:!0,get:function(){return t.RCCallErrorCode}}),Object.defineProperty(e,"RCCallLanguage",{enumerable:!0,get:function(){return t.RCCallLanguage}}),Object.defineProperty(e,"RCCallMediaType",{enumerable:!0,get:function(){return t.RCCallMediaType}}),Object.defineProperty(e,"RCCallSessionState",{enumerable:!0,get:function(){return t.RCCallSessionState}}),Object.defineProperty(e,"RCCallUserState",{enumerable:!0,get:function(){return t.RCCallUserState}}),e.RCCallClient=f,e.RCCallSession=p,e.installer=m,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.1.2",
3
+ "version": "5.1.3",
4
4
  "description": "@rongcloud/plugin-call",
5
5
  "main": "./dist/index.js",
6
6
  "__attrs__": {
@@ -32,11 +32,11 @@
32
32
  "node": ">=10.0.0"
33
33
  },
34
34
  "peerDependencies": {
35
- "@rongcloud/engine": "^5.7.3",
35
+ "@rongcloud/engine": "^5.7.6",
36
36
  "@rongcloud/plugin-rtc": "^5.5.1"
37
37
  },
38
38
  "dependencies": {
39
- "@rongcloud/plugin-call-engine": "^5.1.2"
39
+ "@rongcloud/plugin-call-engine": "^5.1.3"
40
40
  },
41
- "__commit__": "89ba2ed5a9c788362ba96f084fdc3c18106a64c4"
41
+ "__commit__": "c1ec87082611a289263c27c340ee414ee9e60ba8"
42
42
  }
package/dist/logger.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import { Logger } from '@rongcloud/engine';
2
- declare const logger: Logger;
3
- export default logger;
4
- //# sourceMappingURL=logger.d.ts.map