@rongcloud/plugin-call 5.0.7 → 5.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -12,4 +12,4 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
12
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
13
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
14
  PERFORMANCE OF THIS SOFTWARE.
15
- ***************************************************************************** */function s(e,o,t,i){return new(t||(t=Promise))((function(s,r){function n(e){try{a(i.next(e))}catch(e){r(e)}}function l(e){try{a(i.throw(e))}catch(e){r(e)}}function a(e){var o;e.done?s(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(n,l)}a((i=i.apply(e,o||[])).next())}))}var r;!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(r||(r={}));var n=new class{constructor(){this.list={}}on(e,o){return(this.list[e]||(this.list[e]=[])).push(o),this}once(e,o){const t=i=>{this.off(e,t),o.call(this,i)};t.fun=o,this.on(e,t)}off(e,o){const t=this.list[e];if(!t)return!1;if(o){let e;for(let i=0,s=t.length;i<s;i++)if(e=t[i],e===o||e.fun===o){t.splice(i,1);break}}else t&&(t.length=0)}emit(e,o){const t=[...this.list[e]];if(!t||0===t.length)return!1;t.forEach((e=>{e.call(this,o)}))}};const l=t=>{if(!t)return{result:!1,msg:"Initialization missing parameter -> options"};if("object"!=typeof t)return{result:!1,msg:"Initialization options must be an object"};const i=Object.keys(t),s=[];return["rtcClient","onSession","onSessionClose"].forEach((e=>{i.includes(e)||s.push(e)})),s.length?{result:!1,msg:`Initialization missing parameter -> "${s.join(",")}"`}:"object"!=typeof t.rtcClient?{result:!1,msg:"Initialization 'rtcClient' parameter must be of type 'object'"}:"function"!=typeof t.onSession?{result:!1,msg:"Initialization 'onSession' parameter must be of type 'function'"}:"function"!=typeof t.onSessionClose?{result:!1,msg:"Initialization 'onSessionClose' parameter must be of type 'function'"}:void 0!==t.isAllowSubscribeRetry&&"boolean"!=typeof t.isAllowSubscribeRetry?{result:!1,msg:"Initialization 'isAllowSubscribeRetry' parameter must be of type 'boolean'"}:void 0!==t.isAllowPublishRetry&&"boolean"!=typeof t.isAllowPublishRetry?{result:!1,msg:"Initialization 'isAllowPublishRetry' parameter must be of type 'boolean'"}:void 0!==t.isOffCameraWhenVideoDisable&&"boolean"!=typeof t.isOffCameraWhenVideoDisable?{result:!1,msg:"Initialization 'isOffCameraWhenVideoDisable' parameter must be of type 'boolean'"}:void 0===t.joinType||(r=t.joinType,Object.values(o.RTCJoinType).includes(r))?void 0!==t.isAllowDemotionGetStream&&"boolean"!=typeof t.isAllowDemotionGetStream?{result:!1,msg:"Initialization 'isAllowDemotionGetStream' parameter must be of type 'boolean'"}:void 0===t.lang||function(o){return Object.values(e.RCCallLanguage).includes(o)}(t.lang)?void 0===t.logLevel||function(e){return Object.values(o.LogLevel).includes(e)}(t.logLevel)?void 0!==t.logStdout&&"function"!=typeof t.logStdout?{result:!1,msg:"Initialization 'logStdout' parameter must be of type 'function'"}:{result:!0}:{result:!1,msg:"Initialization 'logLevel' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'lang' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'joinType' parameter must be of type correct type"};var r},a=e=>{if(!e)return{result:!1,msg:"missing parameter -> listener"};if("object"!=typeof e)return{result:!1,msg:"listener must be an object"};const o=Object.keys(e),t=[];return["onRinging","onAccept","onHungup","onTrackReady"].forEach((e=>{o.includes(e)||t.push(e)})),t.length?{result:!1,msg:`missing parameter -> "${t.join(",")}"`}:"function"!=typeof e.onRinging?{result:!1,msg:"'onRinging' parameter must be of type 'function'"}:"function"!=typeof e.onAccept?{result:!1,msg:"'onAccept' parameter must be of type 'function'"}:"function"!=typeof e.onHungup?{result:!1,msg:"'onHungup' parameter must be of type 'function'"}:"function"!=typeof e.onTrackReady?{result:!1,msg:"'onTrackReady' parameter must be of type 'function'"}:{result:!0}},c=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},C=o=>o===e.RCCallMediaType.AUDIO||o===e.RCCallMediaType.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},d=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},u=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},R=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushContent' parameter must be of type 'string'"},h=e=>Array.isArray(e)&&e.length?e.every((e=>"string"==typeof e&&e.length>0))?{result:!0}:{result:!1,msg:"'userIds' parameter is required"}:{result:!1,msg:"'userIds' parameter is required, must be of type 'string[]'"};class _{constructor(o,t,r={}){this._stateMachine=o,this._rtcClient=t,this._options=r,this._listener=null,this._RETRYCOUNT=2,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:o})=>{i.info(`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${o}`)},onStateChange:o=>s(this,void 0,void 0,(function*(){const{state:t,reason:s}=o;if(i.info(`[RCCallSession onStateChange] : state->${t} reason->${s}`),t===e.RCCallSessionState.KEEPING){const o=this._stateMachine.getCallId();i.info(`[RCCallSession onStateChange] roomId: ${o}`);try{yield this._joinRoom(o)}catch(t){this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR),i.error(`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${o}`),console.error(t)}}else if(t===e.RCCallSessionState.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void n.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),i.info("[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{i.info(`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){i.error("[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{i.info(`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){i.error("[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,o)=>{i.info(`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${o}`);try{this._listener.onHungup(e,o,this)}catch(e){i.error("[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:o})=>{i.info(`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,o,this)}catch(e){i.error("[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:o,mediaType:t})=>{i.info(`[RCCallSession onMediaModify]sender: sender.userId -> ${o.userId} mediaType: ${t}`),t===e.RCCallMediaType.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(o,t,this)}catch(e){i.error("[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}}})}_joinRoom(o){return s(this,void 0,void 0,(function*(){try{const{code:s,room:r}=yield this._rtcClient.joinRTCRoom(o,this._options.joinType);if(s!==t.RCRTCCode.SUCCESS)return s===t.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(e.RCCallEndReason.SERVICE_NOT_OPENED),s===t.RCRTCCode.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(e.RCCallEndReason.OTHER_CLIENT_IN_CALL):this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR),i.info(`[RCCallClient _joinRoom] join room failed: roomId -> ${o} RCRTCCode -> ${s}`),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR};this._room=r}catch(t){return this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR),i.error(`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${o}`),console.error(t),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(t){return this._exceptionClose(e.RCCallEndReason.SUBSCRIBE_ERROR),i.error(`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${o}`),console.error(t),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(t){return this._exceptionClose(e.RCCallEndReason.PUBLISH_ERROR),i.error(`[RCCallSession _joinRoom] _publish Exception roomId -> ${o}`),console.error(t),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR}}return{code:e.RCCallErrorCode.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return s(this,void 0,void 0,(function*(){const o=this._room.getRemoteTracks();if(o.length){const{code:s}=yield this._subscribeRetry(o,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);s!==t.RCRTCCode.SUCCESS&&(this._exceptionClose(e.RCCallEndReason.SUBSCRIBE_ERROR),i.error(`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${s}`))}}))}_subscribeRetry(e,o=!1,r=0){return s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.subscribe(e);if(s!==t.RCRTCCode.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(s,this)}catch(e){i.error("[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!o)return{code:s};if(r>0)return r--,this._subscribeRetry(e,o,r)}return{code:s}}))}_publish(){return s(this,void 0,void 0,(function*(){const o=this._options.localTracks,{code:s}=yield this._publishRetry(o,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(s!==t.RCRTCCode.SUCCESS)return this._exceptionClose(e.RCCallEndReason.PUBLISH_ERROR),void i.info(`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${s}`);this._options.produceType===r.CALLEE&&this._notifyTrackReady(o)}))}_publishRetry(e,o=!1,r=0){return s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.publish(e);if(s!==t.RCRTCCode.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(s,this)}catch(e){i.error("[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!o)return{code:s};if(r>0)return r--,this._publishRetry(e,o,r)}return{code:s}}))}_leaveRoom(){return s(this,void 0,void 0,(function*(){try{const{code:e}=yield this._rtcClient.leaveRoom(this._room);i.info("[RCCallSession _leaveRoom] Successfully exited the room")}catch(e){i.error("[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();n.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const o=a(e);if(!o.result)throw new Error(`[RCCallSession registerSessionListener] ${o.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(o,r){return s(this,void 0,void 0,(function*(){if(o===e.RCCallMediaType.AUDIO){const{code:o,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",r&&r.audio&&Object.assign({},r.audio));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(i.info("[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:o,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",r&&Object.assign({},r));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(i.info("[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(o,t){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&o===e.RCCallMediaType.AUDIO_VIDEO){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO_VIDEO,t);if(o!==e.RCCallErrorCode.SUCCESS){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO,t);return o!==e.RCCallErrorCode.SUCCESS?(this._exceptionClose(e.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:o}):{code:o,tracks:i}}return{code:o,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(o,t);return i!==e.RCCallErrorCode.SUCCESS?(this._exceptionClose(e.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:i}):{code:i,tracks:s}}}))}changeAudioDevice(o){return s(this,void 0,void 0,(function*(){const s=[],r=[],{code:n,track:l}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o);if(n!==t.RCRTCCode.SUCCESS)return i.error(`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${n}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||r.push(e)})),s.push(l),r.push(l),this._options.localTracks=r,this._notifyTrackReady(s),this._room){const{code:o}=yield this._room.publish(s);if(o!==t.RCRTCCode.SUCCESS)return{code:e.RCCallErrorCode.AUDIO_PUBLISH_ERROR}}return{code:e.RCCallErrorCode.SUCCESS}}))}invite(e,o={}){return s(this,void 0,void 0,(function*(){const{extra:t="",pushTitle:i="",pushContent:s=""}=o,r=[h(e),d(t),u(i),R(s)],n=[];if(!r.every((e=>(!e.result&&n.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${n.join("\n")}`);const{code:l}=yield this._stateMachine.invite(e,{extra:t,pushTitle:i,pushContent:s});return{code:l}}))}accept(o){return s(this,void 0,void 0,(function*(){const t=(e=>{return e&&e.audio&&void 0!==e.audio.micphoneId&&"string"!=typeof e.audio.micphoneId?{result:!1,msg:"'constraints.audio.micphoneId' must be of type 'string'"}:e&&e.audio&&void 0!==e.audio.sampleRate&&"number"!=typeof e.audio.sampleRate?{result:!1,msg:"'constraints.audio.sampleRate' must be of type 'number'"}:e&&e.video&&void 0!==e.video.cameraId&&"string"!=typeof e.video.cameraId?{result:!1,msg:"'constraints.video.cameraId' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&"string"!=typeof e.video.frameRate?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&(o=e.video.frameRate,!["FPS_10","FPS_15","FPS_24","FPS_30"].includes(o))?{result:!1,msg:"'frameRate' value is out of range"}:e&&e.video&&void 0!==e.video.resolution&&"string"!=typeof e.video.resolution?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.resolution&&!function(e){return["W176_H132","W176_H144","W256_H144","W320_H180","W240_H240","W320_H240","W480_H360","W640_H360","W480_H480","W640_H480","W720_H480","W1280_H720","W1920_H1080"].includes(e)}(e.video.resolution)?{result:!1,msg:"'resolution' value is out of range"}:!e||!e.video||e.video.frameRate&&e.video.resolution?{result:!0}:{result:!1,msg:"'resolution' and 'resolution' is required"};var o})(o);if(!t.result)throw new Error(`[RCCallSession accept] ${t.msg}`);n.emit("hungupOtherSession",{session:this});const s=this._stateMachine.getMediaType(),{code:r,tracks:l}=yield this._getLocalTrack(s,o);if(r!==e.RCCallErrorCode.SUCCESS)return{code:r};this._options.localTracks=l;const{code:a}=yield this._stateMachine.accept();return a!==e.RCCallErrorCode.SUCCESS?(i.error(`[RCCallSession accept]Send accept message failed -> code: ${a}`),{code:a}):{code:a}}))}hungup(){return s(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(o){return s(this,void 0,void 0,(function*(){const{code:t}=yield this._stateMachine.changeMediaType(o);return t!==e.RCCallErrorCode.SUCCESS&&i.error(`[RCCallSession _changeMediaType] change media type fail code-> ${t}`),{code:t}}))}_getLocalVideoTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isVideoTrack()))),e):e}_getLocalAudioTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isAudioTrack()))),e):e}_setMediaTypeToAudioAndVideo(){return s(this,void 0,void 0,(function*(){const{code:o,track:s}=yield this._rtcClient.createCameraVideoTrack();if(o!==t.RCRTCCode.SUCCESS)return{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:r}=yield this._room.publish([s]);r===t.RCRTCCode.SUCCESS?(this._notifyTrackReady([s]),this._changeMediaType(e.RCCallMediaType.AUDIO_VIDEO)):i.error(`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${o}`)}))}_setMediaTypeToAudio(){return s(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(e.length){e.forEach((e=>{e.mute()}));const{code:o}=yield this._room.unpublish(e);o!==t.RCRTCCode.SUCCESS&&i.error(`[RCCallSession disableVideo] unpublish failed -> ${o}`),this._destroyTracks(e)}}))}descendAbility(){return s(this,void 0,void 0,(function*(){const{code:o}=yield this._changeMediaType(e.RCCallMediaType.AUDIO);return o===e.RCCallErrorCode.SUCCESS&&this._setMediaTypeToAudio(),{code:o}}))}disableVideoTrack(){return s(this,void 0,void 0,(function*(){const o=this._getLocalVideoTracks();if(!o.length)return i.error(`[RCCallSession disableVideoTrack] Room missing video track -> ${e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};if(o.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:e.RCCallErrorCode.SUCCESS};const{code:s}=yield this._room.unpublish(o);return s!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession disableVideo] unpublish failed -> ${s}`),{code:e.RCCallErrorCode.UNPUBLISH_VIDEO_ERROR}):(o.forEach((e=>{e.destroy()})),{code:e.RCCallErrorCode.SUCCESS})}))}enableVideoTrack(){return s(this,void 0,void 0,(function*(){if(!this._options.isOffCameraWhenVideoDisable){const o=this._getLocalVideoTracks();return o.length?(o.forEach((e=>{e.unmute()})),{code:e.RCCallErrorCode.SUCCESS}):(i.error(`[RCCallSession EnableVideoTrack] Room missing video track -> ${e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR})}const{code:o,track:s}=yield this._rtcClient.createCameraVideoTrack();if(o!==t.RCRTCCode.SUCCESS)return i.error(`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_VIDEO_TRACK_ERROR};const r=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():r.push(e)})),r.push(s),this._options.localTracks=r,s.mute();const{code:n}=yield this._room.publish([s]);return n!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${o}`),{code:e.RCCallErrorCode.VIDEO_PUBLISH_ERROR}):(s.unmute(),this._notifyTrackReady([s]),{code:e.RCCallErrorCode.SUCCESS})}))}disableAudioTrack(){return s(this,void 0,void 0,(function*(){this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return s(this,void 0,void 0,(function*(){this._getLocalAudioTracks().forEach((e=>{e.unmute()}))}))}_destroyTracks(e){e.forEach((e=>{e.destroy()}))}_notifyTrackReady(e){e.forEach((e=>{try{this._listener.onTrackReady(e,this)}catch(e){i.error("[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(o,i)=>{const s=this._rtcClient.getCurrentId();this._stateMachine.userLeave([s]),o?(i===t.RCKickReason.SERVER_KICK&&this._exceptionClose(e.RCCallEndReason.KICKED_BY_SERVER),i===t.RCKickReason.OTHER_KICK&&this._exceptionClose(e.RCCallEndReason.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR)},onMessageReceive(e,o,t,i){},onRoomAttributeChange(e,o){},onAudioMuteChange:e=>{i.info(`[RCCallSession onAudioMuteChange] userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"audio",trackId:e.getTrackId()};try{this._listener.onAudioMuteChange(o,this)}catch(e){i.error("[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{i.info(`[RCCallSession onVideoMuteChange]userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"video",trackId:e.getTrackId()};try{this._listener.onVideoMuteChange(o,this)}catch(e){i.error("[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>s(this,void 0,void 0,(function*(){if(this._room){const{code:o}=yield this._room.subscribe(e);o!==t.RCRTCCode.SUCCESS&&i.error(`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${o}`)}})),onTrackUnpublish:e=>{},onTrackReady:o=>{this._stateMachine.getMediaType()===e.RCCallMediaType.AUDIO&&o.isVideoTrack()||this._notifyTrackReady([o])},onUserJoin:e=>{this._stateMachine.userJoin(e)},onUserLeave:e=>{i.info(`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{i.info(`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){i.error("[RCCallSession onPing] listening onPing exception"),console.error(e)}}})}_registerReportListener(){this._room.registerReportListener({onStateReport:e=>{try{this._listener.onRTCStateReport&&this._listener.onRTCStateReport(e,this)}catch(e){i.error("[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){i.error("[RCCallSession onICEConnectionStateChange] onICEConnectionStateChange exception"),console.error(e)}}})}getSessionId(){return this._stateMachine.getCallId()}getRTCSessionId(){return this._room?this._room.getSessionId():null}getTargetId(){return this._stateMachine.getTargetId()}getConversationType(){return this._stateMachine.getConversationType()}getChannelId(){return this._stateMachine.getChannelId()}getRemoteUsers(){return this._stateMachine.getRemoteUsers()}getUserState(e){if(!e||"string"!=typeof e)throw new Error("userId is required, must be of type 'string'");return this._stateMachine.getUserState(e)}getState(){return this._stateMachine.getState()}getCallerId(){return this._stateMachine.getCallerId()}getMediaType(){return this._stateMachine.getMediaType()}}o.VersionManage.add("plugin-call","5.0.7"),o.VersionManage.validEngine(">=4.5.2")||i.error(`The current engine version '${o.VersionManage.getInfo().engine}' error,plugin-call required engine version at least '>=4.5.2'.`);class p{constructor(t,s,r){this._context=t,this._runtime=s,this._sessionList=[],this._rtcClient=r.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:o.RTCJoinType.COEXIST,isAllowDemotionGetStream:!1,lang:e.RCCallLanguage.ZH},r),this._callEngine=new e.RCCallEngine(this._context,s,i,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||e.RCCallLanguage.ZH}),n.on("sessionClose",(({session:e,summaryInfo:o})=>{this._removeSession(e);try{this._options.onSessionClose(e,o)}catch(e){i.error("[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),n.on("hungupOtherSession",(({session:e})=>{const o=e.getSessionId();i.info(`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${o}`),i.info(`[RCCallClient hungupOtherSession] sessionList ->${this._sessionList.map((e=>e.getSessionId())).join(",")}`);let t=0;for(;this._sessionList.length>1;)this._sessionList[t].getSessionId()!==o?(this._sessionList[t].hungup(),this._sessionList.splice(t,1)):t++;i.info(`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e,o){i.info("[RCCallClient _onInvite] Received invite message");const t=new _(e,this._rtcClient,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:r.CALLEE});i.info("[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(t);try{this._options.onSession(t,o)}catch(e){i.error("[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!t._listener)throw i.error("[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=a(t._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){i.error("[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),i.info("[RCCallClient registerUserInfo] successfully register user info data")}call({targetId:o,mediaType:t=e.RCCallMediaType.AUDIO,listener:n,constraints:l,channelId:h="",extra:p="",pushTitle:g="",pushContent:f=""}){return s(this,void 0,void 0,(function*(){i.info(`[RCCallClient call] extra->${p} pushTitle->${g} pushContent->${f}`);const s=[c(o),C(t),a(n),d(p),u(g),R(f)],S=[];if(!s.every((e=>(!e.result&&S.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${S.join("\n")}`);let m=[];const{code:y,tracks:E}=yield this._getLocalTrack(t,l);if(y!==e.RCCallErrorCode.SUCCESS)return{code:y};m=E,m.forEach((e=>{n.onTrackReady(e)}));const{code:T,stateMachine:I}=yield this._callEngine.call(h,o,t,p,g,f);if(T===e.RCCallErrorCode.SUCCESS&&I){i.info("[RCCallClient call] successfully created state machine");const e=new _(I,this._rtcClient,{localTracks:m,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:r.CALLER});return e.registerSessionListener(n),this._sessionList.push(e),i.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:T,session:e}}return i.error(`[RCCallClient call] call failed code ->: ${T}`),m.forEach((e=>{e.mute(),e.destroy()})),{code:T}}))}callInGroup({targetId:o,userIds:t,mediaType:n=e.RCCallMediaType.AUDIO,listener:l,constraints:p,channelId:g="",extra:f="",pushTitle:S="",pushContent:m=""}){return s(this,void 0,void 0,(function*(){const s=[c(o),h(t),C(n),a(l),d(f),u(S),R(m)],y=[];if(!s.every((e=>(!e.result&&y.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${y.join("\n")}`);let E=[];const{code:T,tracks:I}=yield this._getLocalTrack(n,p);if(T!==e.RCCallErrorCode.SUCCESS)return{code:T};E=I,E.forEach((e=>{l.onTrackReady(e)}));const{code:b,stateMachine:v}=yield this._callEngine.callInGroup(g,o,n,t,f,S,m);if(b===e.RCCallErrorCode.SUCCESS&&v){i.info("[RCCallClient callInGroup] successfully created state machine");const e=new _(v,this._rtcClient,{localTracks:E,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:r.CALLER});return e.registerSessionListener(l),this._sessionList.push(e),i.info(`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:b,session:e}}return i.info(`[RCCallClient callInGroup] callInGroup failed code -> ${b}`),E.forEach((e=>{e.mute(),e.destroy()})),{code:b}}))}_getLocalTrackCore(o,r){return s(this,void 0,void 0,(function*(){if(o===e.RCCallMediaType.AUDIO){const{code:o,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",r&&r.audio&&Object.assign({},r.audio));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(i.info("[RCCallClient _getTrack] successfully get Audio local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:o,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",r&&Object.assign({},r));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(i.info("[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(o,t){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&o===e.RCCallMediaType.AUDIO_VIDEO){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO_VIDEO,t);if(o!==e.RCCallErrorCode.SUCCESS){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO,t);return o!==e.RCCallErrorCode.SUCCESS?{code:o}:{code:o,tracks:i}}return{code:o,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(o,t);return i!==e.RCCallErrorCode.SUCCESS?{code:i}:{code:i,tracks:s}}}))}_removeSession(e){const o=e.getSessionId();this._sessionList=this._sessionList.filter((e=>e.getSessionId()!==o))}getJoinedRoomInfo(){return s(this,void 0,void 0,(function*(){const{code:t,data:s}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return t!==o.ErrorCode.SUCCESS?(i.error("getJoinedUserInfo error",t),{code:e.RCCallErrorCode.QUERY_JOINED_USER_INFO_ERROR}):{code:e.RCCallErrorCode.SUCCESS,data:s}}))}}const g={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,o,t){const s=l(t);if(!s.result)throw new Error(`[RCCallLib installer steup]${s.msg}`);return i.setLogLevel(t.logLevel),i.setLogStdout(t.logStdout),i.warn("RCCall Version: 5.0.7, Commit: 3dcd9a3cf924b311e2169155be169d960765c55e"),new p(e,o,t)}};Object.defineProperty(exports,"RCCallEndReason",{enumerable:!0,get:function(){return e.RCCallEndReason}}),Object.defineProperty(exports,"RCCallErrorCode",{enumerable:!0,get:function(){return e.RCCallErrorCode}}),Object.defineProperty(exports,"RCCallLanguage",{enumerable:!0,get:function(){return e.RCCallLanguage}}),Object.defineProperty(exports,"RCCallMediaType",{enumerable:!0,get:function(){return e.RCCallMediaType}}),Object.defineProperty(exports,"RCCallSessionState",{enumerable:!0,get:function(){return e.RCCallSessionState}}),Object.defineProperty(exports,"RCCallUserState",{enumerable:!0,get:function(){return e.RCCallUserState}}),exports.RCCallClient=p,exports.RCCallSession=_,exports.installer=g;
15
+ ***************************************************************************** */function s(e,o,t,i){return new(t||(t=Promise))((function(s,r){function n(e){try{a(i.next(e))}catch(e){r(e)}}function l(e){try{a(i.throw(e))}catch(e){r(e)}}function a(e){var o;e.done?s(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(n,l)}a((i=i.apply(e,o||[])).next())}))}var r;!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(r||(r={}));var n=new class{constructor(){this.list={}}on(e,o){return(this.list[e]||(this.list[e]=[])).push(o),this}once(e,o){const t=i=>{this.off(e,t),o.call(this,i)};t.fun=o,this.on(e,t)}off(e,o){const t=this.list[e];if(!t)return!1;if(o){let e;for(let i=0,s=t.length;i<s;i++)if(e=t[i],e===o||e.fun===o){t.splice(i,1);break}}else t&&(t.length=0)}emit(e,o){const t=[...this.list[e]];if(!t||0===t.length)return!1;t.forEach((e=>{e.call(this,o)}))}};const l=t=>{if(!t)return{result:!1,msg:"Initialization missing parameter -> options"};if("object"!=typeof t)return{result:!1,msg:"Initialization options must be an object"};const i=Object.keys(t),s=[];return["rtcClient","onSession","onSessionClose"].forEach((e=>{i.includes(e)||s.push(e)})),s.length?{result:!1,msg:`Initialization missing parameter -> "${s.join(",")}"`}:"object"!=typeof t.rtcClient?{result:!1,msg:"Initialization 'rtcClient' parameter must be of type 'object'"}:"function"!=typeof t.onSession?{result:!1,msg:"Initialization 'onSession' parameter must be of type 'function'"}:"function"!=typeof t.onSessionClose?{result:!1,msg:"Initialization 'onSessionClose' parameter must be of type 'function'"}:void 0!==t.isAllowSubscribeRetry&&"boolean"!=typeof t.isAllowSubscribeRetry?{result:!1,msg:"Initialization 'isAllowSubscribeRetry' parameter must be of type 'boolean'"}:void 0!==t.isAllowPublishRetry&&"boolean"!=typeof t.isAllowPublishRetry?{result:!1,msg:"Initialization 'isAllowPublishRetry' parameter must be of type 'boolean'"}:void 0!==t.isOffCameraWhenVideoDisable&&"boolean"!=typeof t.isOffCameraWhenVideoDisable?{result:!1,msg:"Initialization 'isOffCameraWhenVideoDisable' parameter must be of type 'boolean'"}:void 0===t.joinType||(r=t.joinType,Object.values(o.RTCJoinType).includes(r))?void 0!==t.isAllowDemotionGetStream&&"boolean"!=typeof t.isAllowDemotionGetStream?{result:!1,msg:"Initialization 'isAllowDemotionGetStream' parameter must be of type 'boolean'"}:void 0===t.lang||function(o){return Object.values(e.RCCallLanguage).includes(o)}(t.lang)?void 0===t.logLevel||function(e){return Object.values(o.LogLevel).includes(e)}(t.logLevel)?void 0!==t.logStdout&&"function"!=typeof t.logStdout?{result:!1,msg:"Initialization 'logStdout' parameter must be of type 'function'"}:{result:!0}:{result:!1,msg:"Initialization 'logLevel' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'lang' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'joinType' parameter must be of type correct type"};var r},a=e=>{if(!e)return{result:!1,msg:"missing parameter -> listener"};if("object"!=typeof e)return{result:!1,msg:"listener must be an object"};const o=Object.keys(e),t=[];return["onRinging","onAccept","onHungup","onTrackReady"].forEach((e=>{o.includes(e)||t.push(e)})),t.length?{result:!1,msg:`missing parameter -> "${t.join(",")}"`}:"function"!=typeof e.onRinging?{result:!1,msg:"'onRinging' parameter must be of type 'function'"}:"function"!=typeof e.onAccept?{result:!1,msg:"'onAccept' parameter must be of type 'function'"}:"function"!=typeof e.onHungup?{result:!1,msg:"'onHungup' parameter must be of type 'function'"}:"function"!=typeof e.onTrackReady?{result:!1,msg:"'onTrackReady' parameter must be of type 'function'"}:{result:!0}},c=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},C=o=>o===e.RCCallMediaType.AUDIO||o===e.RCCallMediaType.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},d=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},u=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},R=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushContent' parameter must be of type 'string'"},h=e=>Array.isArray(e)&&e.length?e.every((e=>"string"==typeof e&&e.length>0))?{result:!0}:{result:!1,msg:"'userIds' parameter is required"}:{result:!1,msg:"'userIds' parameter is required, must be of type 'string[]'"};class _{constructor(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(o,t,r={}){this._stateMachine=o,this._rtcClient=t,this._options=r,this._listener=null,this._RETRYCOUNT=2,this.joinRoomTimer=null,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:o})=>{i.info(`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${o}`)},onStateChange:o=>s(this,void 0,void 0,(function*(){const{state:t,reason:s}=o;if(i.info(`[RCCallSession onStateChange] : state->${t} reason->${s}`),t===e.RCCallSessionState.KEEPING){const o=this._stateMachine.getCallId();i.info(`[RCCallSession onStateChange] roomId: ${o}`);try{yield this._joinRoom(o)}catch(t){this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR),i.error(`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${o}`),console.error(t)}}else if(t===e.RCCallSessionState.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void n.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),i.info("[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{i.info(`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){i.error("[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{i.info(`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){i.error("[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,o)=>{i.info(`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${o}`);try{this._listener.onHungup(e,o,this)}catch(e){i.error("[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:o})=>{i.info(`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,o,this)}catch(e){i.error("[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:o,mediaType:t})=>{i.info(`[RCCallSession onMediaModify]sender: sender.userId -> ${o.userId} mediaType: ${t}`),t===e.RCCallMediaType.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(o,t,this)}catch(e){i.error("[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}}})}_joinRoom(o){return s(this,void 0,void 0,(function*(){try{const{code:s,userIds:r,room:n}=yield this._rtcClient.joinRTCRoom(o,this._options.joinType);if(s!==t.RCRTCCode.SUCCESS)return s===t.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(e.RCCallEndReason.SERVICE_NOT_OPENED),s===t.RCRTCCode.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(e.RCCallEndReason.OTHER_CLIENT_IN_CALL):this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR),i.info(`[RCCallClient _joinRoom] join room failed: roomId -> ${o} RCRTCCode -> ${s}`),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR};r.length<1&&(this.joinRoomTimer=new _((()=>{this._exceptionClose(e.RCCallEndReason.REMOTE_NETWORK_ERROR)}),6e4)),this._room=n}catch(t){return this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR),i.error(`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${o}`),console.error(t),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(t){return this._exceptionClose(e.RCCallEndReason.SUBSCRIBE_ERROR),i.error(`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${o}`),console.error(t),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(t){return this._exceptionClose(e.RCCallEndReason.PUBLISH_ERROR),i.error(`[RCCallSession _joinRoom] _publish Exception roomId -> ${o}`),console.error(t),{code:e.RCCallErrorCode.JOIN_ROOM_ERROR}}return{code:e.RCCallErrorCode.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return s(this,void 0,void 0,(function*(){const o=this._room.getRemoteTracks();if(o.length){const{code:s}=yield this._subscribeRetry(o,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);s!==t.RCRTCCode.SUCCESS&&(this._exceptionClose(e.RCCallEndReason.SUBSCRIBE_ERROR),i.error(`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${s}`))}}))}_subscribeRetry(e,o=!1,r=0){return s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.subscribe(e);if(s!==t.RCRTCCode.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(s,this)}catch(e){i.error("[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!o)return{code:s};if(r>0)return r--,this._subscribeRetry(e,o,r)}return{code:s}}))}_publish(){return s(this,void 0,void 0,(function*(){const o=this._options.localTracks,{code:s}=yield this._publishRetry(o,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(s!==t.RCRTCCode.SUCCESS)return this._exceptionClose(e.RCCallEndReason.PUBLISH_ERROR),void i.info(`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${s}`);this._options.produceType===r.CALLEE&&this._notifyTrackReady(o)}))}_publishRetry(e,o=!1,r=0){return s(this,void 0,void 0,(function*(){const{code:s}=yield this._room.publish(e);if(s!==t.RCRTCCode.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(s,this)}catch(e){i.error("[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!o)return{code:s};if(r>0)return r--,this._publishRetry(e,o,r)}return{code:s}}))}_leaveRoom(){return s(this,void 0,void 0,(function*(){try{const{code:e}=yield this._rtcClient.leaveRoom(this._room);i.info("[RCCallSession _leaveRoom] Successfully exited the room")}catch(e){i.error("[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();n.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const o=a(e);if(!o.result)throw new Error(`[RCCallSession registerSessionListener] ${o.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(o,r){return s(this,void 0,void 0,(function*(){if(o===e.RCCallMediaType.AUDIO){const{code:o,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",r&&r.audio&&Object.assign({},r.audio));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(i.info("[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:o,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",r&&Object.assign({},r));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(i.info("[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(o,t){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&o===e.RCCallMediaType.AUDIO_VIDEO){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO_VIDEO,t);if(o!==e.RCCallErrorCode.SUCCESS){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO,t);return o!==e.RCCallErrorCode.SUCCESS?(this._exceptionClose(e.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:o}):{code:o,tracks:i}}return{code:o,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(o,t);return i!==e.RCCallErrorCode.SUCCESS?(this._exceptionClose(e.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:i}):{code:i,tracks:s}}}))}changeAudioDevice(o){return s(this,void 0,void 0,(function*(){const s=[],r=[],{code:n,track:l}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",o);if(n!==t.RCRTCCode.SUCCESS)return i.error(`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${n}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||r.push(e)})),s.push(l),r.push(l),this._options.localTracks=r,this._notifyTrackReady(s),this._room){const{code:o}=yield this._room.publish(s);if(o!==t.RCRTCCode.SUCCESS)return{code:e.RCCallErrorCode.AUDIO_PUBLISH_ERROR}}return{code:e.RCCallErrorCode.SUCCESS}}))}invite(e,o={}){return s(this,void 0,void 0,(function*(){const{extra:t="",pushTitle:i="",pushContent:s=""}=o,r=[h(e),d(t),u(i),R(s)],n=[];if(!r.every((e=>(!e.result&&n.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${n.join("\n")}`);const{code:l}=yield this._stateMachine.invite(e,{extra:t,pushTitle:i,pushContent:s});return{code:l}}))}accept(o){return s(this,void 0,void 0,(function*(){const t=(e=>{return e&&e.audio&&void 0!==e.audio.micphoneId&&"string"!=typeof e.audio.micphoneId?{result:!1,msg:"'constraints.audio.micphoneId' must be of type 'string'"}:e&&e.audio&&void 0!==e.audio.sampleRate&&"number"!=typeof e.audio.sampleRate?{result:!1,msg:"'constraints.audio.sampleRate' must be of type 'number'"}:e&&e.video&&void 0!==e.video.cameraId&&"string"!=typeof e.video.cameraId?{result:!1,msg:"'constraints.video.cameraId' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&"string"!=typeof e.video.frameRate?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&(o=e.video.frameRate,!["FPS_10","FPS_15","FPS_24","FPS_30"].includes(o))?{result:!1,msg:"'frameRate' value is out of range"}:e&&e.video&&void 0!==e.video.resolution&&"string"!=typeof e.video.resolution?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.resolution&&!function(e){return["W176_H132","W176_H144","W256_H144","W320_H180","W240_H240","W320_H240","W480_H360","W640_H360","W480_H480","W640_H480","W720_H480","W1280_H720","W1920_H1080"].includes(e)}(e.video.resolution)?{result:!1,msg:"'resolution' value is out of range"}:!e||!e.video||e.video.frameRate&&e.video.resolution?{result:!0}:{result:!1,msg:"'resolution' and 'resolution' is required"};var o})(o);if(!t.result)throw new Error(`[RCCallSession accept] ${t.msg}`);n.emit("hungupOtherSession",{session:this});const s=this._stateMachine.getMediaType(),{code:r,tracks:l}=yield this._getLocalTrack(s,o);if(r!==e.RCCallErrorCode.SUCCESS)return{code:r};this._options.localTracks=l;const{code:a}=yield this._stateMachine.accept();return a!==e.RCCallErrorCode.SUCCESS?(i.error(`[RCCallSession accept]Send accept message failed -> code: ${a}`),{code:a}):{code:a}}))}hungup(){return s(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(o){return s(this,void 0,void 0,(function*(){const{code:t}=yield this._stateMachine.changeMediaType(o);return t!==e.RCCallErrorCode.SUCCESS&&i.error(`[RCCallSession _changeMediaType] change media type fail code-> ${t}`),{code:t}}))}_getLocalVideoTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isVideoTrack()))),e):e}_getLocalAudioTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isAudioTrack()))),e):e}_setMediaTypeToAudioAndVideo(){return s(this,void 0,void 0,(function*(){const{code:o,track:s}=yield this._rtcClient.createCameraVideoTrack();if(o!==t.RCRTCCode.SUCCESS)return{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:r}=yield this._room.publish([s]);r===t.RCRTCCode.SUCCESS?(this._notifyTrackReady([s]),this._changeMediaType(e.RCCallMediaType.AUDIO_VIDEO)):i.error(`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${o}`)}))}_setMediaTypeToAudio(){return s(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(e.length){e.forEach((e=>{e.mute()}));const{code:o}=yield this._room.unpublish(e);o!==t.RCRTCCode.SUCCESS&&i.error(`[RCCallSession disableVideo] unpublish failed -> ${o}`),this._destroyTracks(e)}}))}descendAbility(){return s(this,void 0,void 0,(function*(){const{code:o}=yield this._changeMediaType(e.RCCallMediaType.AUDIO);return o===e.RCCallErrorCode.SUCCESS&&this._setMediaTypeToAudio(),{code:o}}))}disableVideoTrack(){return s(this,void 0,void 0,(function*(){const o=this._getLocalVideoTracks();if(!o.length)return i.error(`[RCCallSession disableVideoTrack] Room missing video track -> ${e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};if(o.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:e.RCCallErrorCode.SUCCESS};const{code:s}=yield this._room.unpublish(o);return s!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession disableVideo] unpublish failed -> ${s}`),{code:e.RCCallErrorCode.UNPUBLISH_VIDEO_ERROR}):(o.forEach((e=>{e.destroy()})),{code:e.RCCallErrorCode.SUCCESS})}))}enableVideoTrack(){return s(this,void 0,void 0,(function*(){if(!this._options.isOffCameraWhenVideoDisable){const o=this._getLocalVideoTracks();return o.length?(o.forEach((e=>{e.unmute()})),{code:e.RCCallErrorCode.SUCCESS}):(i.error(`[RCCallSession EnableVideoTrack] Room missing video track -> ${e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:e.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR})}const{code:o,track:s}=yield this._rtcClient.createCameraVideoTrack();if(o!==t.RCRTCCode.SUCCESS)return i.error(`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_VIDEO_TRACK_ERROR};const r=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():r.push(e)})),r.push(s),this._options.localTracks=r,s.mute();const{code:n}=yield this._room.publish([s]);return n!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${o}`),{code:e.RCCallErrorCode.VIDEO_PUBLISH_ERROR}):(s.unmute(),this._notifyTrackReady([s]),{code:e.RCCallErrorCode.SUCCESS})}))}disableAudioTrack(){return s(this,void 0,void 0,(function*(){this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return s(this,void 0,void 0,(function*(){this._getLocalAudioTracks().forEach((e=>{e.unmute()}))}))}_destroyTracks(e){e.forEach((e=>{e.destroy()}))}_notifyTrackReady(e){e.forEach((e=>{try{this._listener.onTrackReady(e,this)}catch(e){i.error("[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(o,i)=>{const s=this._rtcClient.getCurrentId();this._stateMachine.userLeave([s]),o?(i===t.RCKickReason.SERVER_KICK&&this._exceptionClose(e.RCCallEndReason.KICKED_BY_SERVER),i===t.RCKickReason.OTHER_KICK&&this._exceptionClose(e.RCCallEndReason.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(e.RCCallEndReason.NETWORK_ERROR)},onMessageReceive(e,o,t,i){},onRoomAttributeChange(e,o){},onAudioMuteChange:e=>{i.info(`[RCCallSession onAudioMuteChange] userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"audio",trackId:e.getTrackId()};try{this._listener.onAudioMuteChange(o,this)}catch(e){i.error("[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{i.info(`[RCCallSession onVideoMuteChange]userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"video",trackId:e.getTrackId()};try{this._listener.onVideoMuteChange(o,this)}catch(e){i.error("[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>s(this,void 0,void 0,(function*(){if(this._room){const{code:o}=yield this._room.subscribe(e);o!==t.RCRTCCode.SUCCESS&&i.error(`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${o}`)}})),onTrackUnpublish:e=>{},onTrackReady:o=>{this._stateMachine.getMediaType()===e.RCCallMediaType.AUDIO&&o.isVideoTrack()||this._notifyTrackReady([o])},onUserJoin:e=>{this.joinRoomTimer&&this.joinRoomTimer.stop(),this._stateMachine.userJoin(e)},onUserLeave:e=>{i.info(`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{i.info(`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){i.error("[RCCallSession onPing] listening onPing exception"),console.error(e)}}})}_registerReportListener(){this._room.registerReportListener({onStateReport:e=>{try{this._listener.onRTCStateReport&&this._listener.onRTCStateReport(e,this)}catch(e){i.error("[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){i.error("[RCCallSession onICEConnectionStateChange] onICEConnectionStateChange exception"),console.error(e)}}})}getSessionId(){return this._stateMachine.getCallId()}getRTCSessionId(){return this._room?this._room.getSessionId():null}getTargetId(){return this._stateMachine.getTargetId()}getConversationType(){return this._stateMachine.getConversationType()}getChannelId(){return this._stateMachine.getChannelId()}getRemoteUsers(){return this._stateMachine.getRemoteUsers()}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()}}o.VersionManage.add("plugin-call","5.0.10"),o.VersionManage.validEngine("^4.5.5-enterprise.1")||i.error(`The current engine version '${o.VersionManage.getInfo().engine}' error,plugin-call required engine version at least '^4.5.5-enterprise.1'.`);class g{constructor(t,s,r){this._context=t,this._runtime=s,this._sessionList=[],this._rtcClient=r.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:o.RTCJoinType.COEXIST,isAllowDemotionGetStream:!1,lang:e.RCCallLanguage.ZH},r),this._callEngine=new e.RCCallEngine(this._context,s,i,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||e.RCCallLanguage.ZH}),n.on("sessionClose",(({session:e,summaryInfo:o})=>{this._removeSession(e);try{this._options.onSessionClose(e,o)}catch(e){i.error("[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),n.on("hungupOtherSession",(({session:e})=>{const o=e.getSessionId();i.info(`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${o}`),i.info(`[RCCallClient hungupOtherSession] sessionList ->${this._sessionList.map((e=>e.getSessionId())).join(",")}`);let t=0;for(;this._sessionList.length>1;)this._sessionList[t].getSessionId()!==o?(this._sessionList[t].hungup(),this._sessionList.splice(t,1)):t++;i.info(`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e,o){i.info("[RCCallClient _onInvite] Received invite message");const t=new p(e,this._rtcClient,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:r.CALLEE});i.info("[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(t);try{this._options.onSession(t,o)}catch(e){i.error("[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!t._listener)throw i.error("[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=a(t._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){i.error("[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),i.info("[RCCallClient registerUserInfo] successfully register user info data")}call({targetId:o,mediaType:t=e.RCCallMediaType.AUDIO,listener:n,constraints:l,channelId:h="",extra:_="",pushTitle:g="",pushContent:f="",bitrate:S}){return s(this,void 0,void 0,(function*(){i.info(`[RCCallClient call] extra->${_} pushTitle->${g} pushContent->${f}`);const s=[c(o),C(t),a(n),d(_),u(g),R(f)],m=[];if(!s.every((e=>(!e.result&&m.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${m.join("\n")}`);let y=[];const{code:T,tracks:E}=yield this._getLocalTrack(t,l);if(T!==e.RCCallErrorCode.SUCCESS)return{code:T};y=E,y.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:v,stateMachine:I}=yield this._callEngine.call(h,o,t,_,g,f);if(v===e.RCCallErrorCode.SUCCESS&&I){i.info("[RCCallClient call] successfully created state machine");const e=new p(I,this._rtcClient,{localTracks:y,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:r.CALLER});return e.registerSessionListener(n),this._sessionList.push(e),i.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:v,session:e}}return i.error(`[RCCallClient call] call failed code ->: ${v}`),y.forEach((e=>{e.mute(),e.destroy()})),{code:v}}))}callInGroup({targetId:o,userIds:t,mediaType:n=e.RCCallMediaType.AUDIO,listener:l,constraints:_,channelId:g="",extra:f="",pushTitle:S="",pushContent:m="",bitrate:y}){return s(this,void 0,void 0,(function*(){const s=[c(o),h(t),C(n),a(l),d(f),u(S),R(m)],T=[];if(!s.every((e=>(!e.result&&T.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${T.join("\n")}`);let E=[];const{code:v,tracks:I}=yield this._getLocalTrack(n,_);if(v!==e.RCCallErrorCode.SUCCESS)return{code:v};E=I,E.forEach((e=>{var o,t,i;e.isAudioTrack()&&(null==y?void 0:y.audio)&&e.setBitrate(null==y?void 0:y.audio),e.isVideoTrack()&&(null==y?void 0:y.video)&&e.setBitrate(null===(o=null==y?void 0:y.video)||void 0===o?void 0:o.max,null===(t=null==y?void 0:y.video)||void 0===t?void 0:t.min,null===(i=null==y?void 0:y.video)||void 0===i?void 0:i.start),l.onTrackReady(e)}));const{code:b,stateMachine:O}=yield this._callEngine.callInGroup(g,o,n,t,f,S,m);if(b===e.RCCallErrorCode.SUCCESS&&O){i.info("[RCCallClient callInGroup] successfully created state machine");const e=new p(O,this._rtcClient,{localTracks:E,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:r.CALLER});return e.registerSessionListener(l),this._sessionList.push(e),i.info(`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:b,session:e}}return i.info(`[RCCallClient callInGroup] callInGroup failed code -> ${b}`),E.forEach((e=>{e.mute(),e.destroy()})),{code:b}}))}_getLocalTrackCore(o,r){return s(this,void 0,void 0,(function*(){if(o===e.RCCallMediaType.AUDIO){const{code:o,track:s}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",r&&r.audio&&Object.assign({},r.audio));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(i.info("[RCCallClient _getTrack] successfully get Audio local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:[s]})}{const{code:o,tracks:s}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",r&&Object.assign({},r));return o!==t.RCRTCCode.SUCCESS?(i.error(`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${o}`),{code:e.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(i.info("[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:e.RCCallErrorCode.SUCCESS,tracks:s})}}))}_getLocalTrack(o,t){return s(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&o===e.RCCallMediaType.AUDIO_VIDEO){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO_VIDEO,t);if(o!==e.RCCallErrorCode.SUCCESS){const{code:o,tracks:i}=yield this._getLocalTrackCore(e.RCCallMediaType.AUDIO,t);return o!==e.RCCallErrorCode.SUCCESS?{code:o}:{code:o,tracks:i}}return{code:o,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(o,t);return i!==e.RCCallErrorCode.SUCCESS?{code:i}:{code:i,tracks:s}}}))}_removeSession(e){const o=e.getSessionId();this._sessionList=this._sessionList.filter((e=>e.getSessionId()!==o))}getJoinedRoomInfo(){return s(this,void 0,void 0,(function*(){const{code:t,data:s}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return t!==o.ErrorCode.SUCCESS?(i.error("getJoinedUserInfo error",t),{code:e.RCCallErrorCode.QUERY_JOINED_USER_INFO_ERROR}):{code:e.RCCallErrorCode.SUCCESS,data:s}}))}destroyStateMachine(){return s(this,void 0,void 0,(function*(){return this._callEngine.destroy()}))}}const f={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,o,t){const s=l(t);if(!s.result)throw new Error(`[RCCallLib installer steup]${s.msg}`);return i.setLogLevel(t.logLevel),i.setLogStdout(t.logStdout),i.warn("RCCall Version: 5.0.10, Commit: 010761df892b669845b52207e7c1c3829782d100"),new g(e,o,t)}};Object.defineProperty(exports,"RCCallEndReason",{enumerable:!0,get:function(){return e.RCCallEndReason}}),Object.defineProperty(exports,"RCCallErrorCode",{enumerable:!0,get:function(){return e.RCCallErrorCode}}),Object.defineProperty(exports,"RCCallLanguage",{enumerable:!0,get:function(){return e.RCCallLanguage}}),Object.defineProperty(exports,"RCCallMediaType",{enumerable:!0,get:function(){return e.RCCallMediaType}}),Object.defineProperty(exports,"RCCallSessionState",{enumerable:!0,get:function(){return e.RCCallSessionState}}),Object.defineProperty(exports,"RCCallUserState",{enumerable:!0,get:function(){return e.RCCallUserState}}),exports.RCCallClient=g,exports.RCCallSession=p,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 r(e,o,t,i){return new(t||(t=Promise))((function(s,r){function n(e){try{a(i.next(e))}catch(e){r(e)}}function l(e){try{a(i.throw(e))}catch(e){r(e)}}function a(e){var o;e.done?s(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(n,l)}a((i=i.apply(e,o||[])).next())}))}var n;!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(n||(n={}));var l=new class{constructor(){this.list={}}on(e,o){return(this.list[e]||(this.list[e]=[])).push(o),this}once(e,o){const t=i=>{this.off(e,t),o.call(this,i)};t.fun=o,this.on(e,t)}off(e,o){const t=this.list[e];if(!t)return!1;if(o){let e;for(let i=0,s=t.length;i<s;i++)if(e=t[i],e===o||e.fun===o){t.splice(i,1);break}}else t&&(t.length=0)}emit(e,o){const t=[...this.list[e]];if(!t||0===t.length)return!1;t.forEach((e=>{e.call(this,o)}))}};const a=e=>{if(!e)return{result:!1,msg:"Initialization missing parameter -> options"};if("object"!=typeof e)return{result:!1,msg:"Initialization options must be an object"};const i=Object.keys(e),s=[];return["rtcClient","onSession","onSessionClose"].forEach((e=>{i.includes(e)||s.push(e)})),s.length?{result:!1,msg:`Initialization missing parameter -> "${s.join(",")}"`}:"object"!=typeof e.rtcClient?{result:!1,msg:"Initialization 'rtcClient' parameter must be of type 'object'"}:"function"!=typeof e.onSession?{result:!1,msg:"Initialization 'onSession' parameter must be of type 'function'"}:"function"!=typeof e.onSessionClose?{result:!1,msg:"Initialization 'onSessionClose' parameter must be of type 'function'"}:void 0!==e.isAllowSubscribeRetry&&"boolean"!=typeof e.isAllowSubscribeRetry?{result:!1,msg:"Initialization 'isAllowSubscribeRetry' parameter must be of type 'boolean'"}:void 0!==e.isAllowPublishRetry&&"boolean"!=typeof e.isAllowPublishRetry?{result:!1,msg:"Initialization 'isAllowPublishRetry' parameter must be of type 'boolean'"}:void 0!==e.isOffCameraWhenVideoDisable&&"boolean"!=typeof e.isOffCameraWhenVideoDisable?{result:!1,msg:"Initialization 'isOffCameraWhenVideoDisable' parameter must be of type 'boolean'"}:void 0===e.joinType||(r=e.joinType,Object.values(t.RTCJoinType).includes(r))?void 0!==e.isAllowDemotionGetStream&&"boolean"!=typeof e.isAllowDemotionGetStream?{result:!1,msg:"Initialization 'isAllowDemotionGetStream' parameter must be of type 'boolean'"}:void 0===e.lang||function(e){return Object.values(o.RCCallLanguage).includes(e)}(e.lang)?void 0===e.logLevel||function(e){return Object.values(t.LogLevel).includes(e)}(e.logLevel)?void 0!==e.logStdout&&"function"!=typeof e.logStdout?{result:!1,msg:"Initialization 'logStdout' parameter must be of type 'function'"}:{result:!0}:{result:!1,msg:"Initialization 'logLevel' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'lang' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'joinType' parameter must be of type correct type"};var r},c=e=>{if(!e)return{result:!1,msg:"missing parameter -> listener"};if("object"!=typeof e)return{result:!1,msg:"listener must be an object"};const o=Object.keys(e),t=[];return["onRinging","onAccept","onHungup","onTrackReady"].forEach((e=>{o.includes(e)||t.push(e)})),t.length?{result:!1,msg:`missing parameter -> "${t.join(",")}"`}:"function"!=typeof e.onRinging?{result:!1,msg:"'onRinging' parameter must be of type 'function'"}:"function"!=typeof e.onAccept?{result:!1,msg:"'onAccept' parameter must be of type 'function'"}:"function"!=typeof e.onHungup?{result:!1,msg:"'onHungup' parameter must be of type 'function'"}:"function"!=typeof e.onTrackReady?{result:!1,msg:"'onTrackReady' parameter must be of type 'function'"}:{result:!0}},C=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},d=e=>e===o.RCCallMediaType.AUDIO||e===o.RCCallMediaType.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},u=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},R=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},h=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushContent' parameter must be of type 'string'"},_=e=>Array.isArray(e)&&e.length?e.every((e=>"string"==typeof e&&e.length>0))?{result:!0}:{result:!1,msg:"'userIds' parameter is required"}:{result:!1,msg:"'userIds' parameter is required, must be of type 'string[]'"};class p{constructor(e,t,i={}){this._stateMachine=e,this._rtcClient=t,this._options=i,this._listener=null,this._RETRYCOUNT=2,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:o})=>{s.info(`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${o}`)},onStateChange:e=>r(this,void 0,void 0,(function*(){const{state:t,reason:i}=e;if(s.info(`[RCCallSession onStateChange] : state->${t} reason->${i}`),t===o.RCCallSessionState.KEEPING){const e=this._stateMachine.getCallId();s.info(`[RCCallSession onStateChange] roomId: ${e}`);try{yield this._joinRoom(e)}catch(t){this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR),s.error(`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${e}`),console.error(t)}}else if(t===o.RCCallSessionState.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void l.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),s.info("[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{s.info(`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){s.error("[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{s.info(`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){s.error("[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,o)=>{s.info(`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${o}`);try{this._listener.onHungup(e,o,this)}catch(e){s.error("[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:o})=>{s.info(`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,o,this)}catch(e){s.error("[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:e,mediaType:t})=>{s.info(`[RCCallSession onMediaModify]sender: sender.userId -> ${e.userId} mediaType: ${t}`),t===o.RCCallMediaType.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(e,t,this)}catch(e){s.error("[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}}})}_joinRoom(e){return r(this,void 0,void 0,(function*(){try{const{code:t,room:r}=yield this._rtcClient.joinRTCRoom(e,this._options.joinType);if(t!==i.RCRTCCode.SUCCESS)return t===i.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(o.RCCallEndReason.SERVICE_NOT_OPENED),t===i.RCRTCCode.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(o.RCCallEndReason.OTHER_CLIENT_IN_CALL):this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR),s.info(`[RCCallClient _joinRoom] join room failed: roomId -> ${e} RCRTCCode -> ${t}`),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR};this._room=r}catch(t){return this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR),s.error(`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${e}`),console.error(t),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(t){return this._exceptionClose(o.RCCallEndReason.SUBSCRIBE_ERROR),s.error(`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${e}`),console.error(t),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(t){return this._exceptionClose(o.RCCallEndReason.PUBLISH_ERROR),s.error(`[RCCallSession _joinRoom] _publish Exception roomId -> ${e}`),console.error(t),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR}}return{code:o.RCCallErrorCode.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return r(this,void 0,void 0,(function*(){const e=this._room.getRemoteTracks();if(e.length){const{code:t}=yield this._subscribeRetry(e,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);t!==i.RCRTCCode.SUCCESS&&(this._exceptionClose(o.RCCallEndReason.SUBSCRIBE_ERROR),s.error(`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${t}`))}}))}_subscribeRetry(e,o=!1,t=0){return r(this,void 0,void 0,(function*(){const{code:r}=yield this._room.subscribe(e);if(r!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(r,this)}catch(e){s.error("[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!o)return{code:r};if(t>0)return t--,this._subscribeRetry(e,o,t)}return{code:r}}))}_publish(){return r(this,void 0,void 0,(function*(){const e=this._options.localTracks,{code:t}=yield this._publishRetry(e,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(t!==i.RCRTCCode.SUCCESS)return this._exceptionClose(o.RCCallEndReason.PUBLISH_ERROR),void s.info(`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${t}`);this._options.produceType===n.CALLEE&&this._notifyTrackReady(e)}))}_publishRetry(e,o=!1,t=0){return r(this,void 0,void 0,(function*(){const{code:r}=yield this._room.publish(e);if(r!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(r,this)}catch(e){s.error("[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!o)return{code:r};if(t>0)return t--,this._publishRetry(e,o,t)}return{code:r}}))}_leaveRoom(){return r(this,void 0,void 0,(function*(){try{const{code:e}=yield this._rtcClient.leaveRoom(this._room);s.info("[RCCallSession _leaveRoom] Successfully exited the room")}catch(e){s.error("[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();l.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const o=c(e);if(!o.result)throw new Error(`[RCCallSession registerSessionListener] ${o.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(e,t){return r(this,void 0,void 0,(function*(){if(e===o.RCCallMediaType.AUDIO){const{code:e,track:r}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",t&&t.audio&&Object.assign({},t.audio));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(s.info("[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:[r]})}{const{code:e,tracks:r}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",t&&Object.assign({},t));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(s.info("[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:r})}}))}_getLocalTrack(e,t){return r(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===o.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO_VIDEO,t);if(e!==o.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO,t);return e!==o.RCCallErrorCode.SUCCESS?(this._exceptionClose(o.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:e}):{code:e,tracks:i}}return{code:e,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(e,t);return i!==o.RCCallErrorCode.SUCCESS?(this._exceptionClose(o.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:i}):{code:i,tracks:s}}}))}changeAudioDevice(e){return r(this,void 0,void 0,(function*(){const t=[],r=[],{code:n,track:l}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",e);if(n!==i.RCRTCCode.SUCCESS)return s.error(`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${n}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||r.push(e)})),t.push(l),r.push(l),this._options.localTracks=r,this._notifyTrackReady(t),this._room){const{code:e}=yield this._room.publish(t);if(e!==i.RCRTCCode.SUCCESS)return{code:o.RCCallErrorCode.AUDIO_PUBLISH_ERROR}}return{code:o.RCCallErrorCode.SUCCESS}}))}invite(e,o={}){return r(this,void 0,void 0,(function*(){const{extra:t="",pushTitle:i="",pushContent:s=""}=o,r=[_(e),u(t),R(i),h(s)],n=[];if(!r.every((e=>(!e.result&&n.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${n.join("\n")}`);const{code:l}=yield this._stateMachine.invite(e,{extra:t,pushTitle:i,pushContent:s});return{code:l}}))}accept(e){return r(this,void 0,void 0,(function*(){const t=(e=>{return e&&e.audio&&void 0!==e.audio.micphoneId&&"string"!=typeof e.audio.micphoneId?{result:!1,msg:"'constraints.audio.micphoneId' must be of type 'string'"}:e&&e.audio&&void 0!==e.audio.sampleRate&&"number"!=typeof e.audio.sampleRate?{result:!1,msg:"'constraints.audio.sampleRate' must be of type 'number'"}:e&&e.video&&void 0!==e.video.cameraId&&"string"!=typeof e.video.cameraId?{result:!1,msg:"'constraints.video.cameraId' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&"string"!=typeof e.video.frameRate?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&(o=e.video.frameRate,!["FPS_10","FPS_15","FPS_24","FPS_30"].includes(o))?{result:!1,msg:"'frameRate' value is out of range"}:e&&e.video&&void 0!==e.video.resolution&&"string"!=typeof e.video.resolution?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.resolution&&!function(e){return["W176_H132","W176_H144","W256_H144","W320_H180","W240_H240","W320_H240","W480_H360","W640_H360","W480_H480","W640_H480","W720_H480","W1280_H720","W1920_H1080"].includes(e)}(e.video.resolution)?{result:!1,msg:"'resolution' value is out of range"}:!e||!e.video||e.video.frameRate&&e.video.resolution?{result:!0}:{result:!1,msg:"'resolution' and 'resolution' is required"};var o})(e);if(!t.result)throw new Error(`[RCCallSession accept] ${t.msg}`);l.emit("hungupOtherSession",{session:this});const i=this._stateMachine.getMediaType(),{code:r,tracks:n}=yield this._getLocalTrack(i,e);if(r!==o.RCCallErrorCode.SUCCESS)return{code:r};this._options.localTracks=n;const{code:a}=yield this._stateMachine.accept();return a!==o.RCCallErrorCode.SUCCESS?(s.error(`[RCCallSession accept]Send accept message failed -> code: ${a}`),{code:a}):{code:a}}))}hungup(){return r(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(e){return r(this,void 0,void 0,(function*(){const{code:t}=yield this._stateMachine.changeMediaType(e);return t!==o.RCCallErrorCode.SUCCESS&&s.error(`[RCCallSession _changeMediaType] change media type fail code-> ${t}`),{code:t}}))}_getLocalVideoTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isVideoTrack()))),e):e}_getLocalAudioTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isAudioTrack()))),e):e}_setMediaTypeToAudioAndVideo(){return r(this,void 0,void 0,(function*(){const{code:e,track:t}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:r}=yield this._room.publish([t]);r===i.RCRTCCode.SUCCESS?(this._notifyTrackReady([t]),this._changeMediaType(o.RCCallMediaType.AUDIO_VIDEO)):s.error(`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${e}`)}))}_setMediaTypeToAudio(){return r(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(e.length){e.forEach((e=>{e.mute()}));const{code:o}=yield this._room.unpublish(e);o!==i.RCRTCCode.SUCCESS&&s.error(`[RCCallSession disableVideo] unpublish failed -> ${o}`),this._destroyTracks(e)}}))}descendAbility(){return r(this,void 0,void 0,(function*(){const{code:e}=yield this._changeMediaType(o.RCCallMediaType.AUDIO);return e===o.RCCallErrorCode.SUCCESS&&this._setMediaTypeToAudio(),{code:e}}))}disableVideoTrack(){return r(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(!e.length)return s.error(`[RCCallSession disableVideoTrack] Room missing video track -> ${o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};if(e.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:o.RCCallErrorCode.SUCCESS};const{code:t}=yield this._room.unpublish(e);return t!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession disableVideo] unpublish failed -> ${t}`),{code:o.RCCallErrorCode.UNPUBLISH_VIDEO_ERROR}):(e.forEach((e=>{e.destroy()})),{code:o.RCCallErrorCode.SUCCESS})}))}enableVideoTrack(){return r(this,void 0,void 0,(function*(){if(!this._options.isOffCameraWhenVideoDisable){const e=this._getLocalVideoTracks();return e.length?(e.forEach((e=>{e.unmute()})),{code:o.RCCallErrorCode.SUCCESS}):(s.error(`[RCCallSession EnableVideoTrack] Room missing video track -> ${o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR})}const{code:e,track:t}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return s.error(`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_VIDEO_TRACK_ERROR};const r=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():r.push(e)})),r.push(t),this._options.localTracks=r,t.mute();const{code:n}=yield this._room.publish([t]);return n!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${e}`),{code:o.RCCallErrorCode.VIDEO_PUBLISH_ERROR}):(t.unmute(),this._notifyTrackReady([t]),{code:o.RCCallErrorCode.SUCCESS})}))}disableAudioTrack(){return r(this,void 0,void 0,(function*(){this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return r(this,void 0,void 0,(function*(){this._getLocalAudioTracks().forEach((e=>{e.unmute()}))}))}_destroyTracks(e){e.forEach((e=>{e.destroy()}))}_notifyTrackReady(e){e.forEach((e=>{try{this._listener.onTrackReady(e,this)}catch(e){s.error("[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(e,t)=>{const s=this._rtcClient.getCurrentId();this._stateMachine.userLeave([s]),e?(t===i.RCKickReason.SERVER_KICK&&this._exceptionClose(o.RCCallEndReason.KICKED_BY_SERVER),t===i.RCKickReason.OTHER_KICK&&this._exceptionClose(o.RCCallEndReason.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR)},onMessageReceive(e,o,t,i){},onRoomAttributeChange(e,o){},onAudioMuteChange:e=>{s.info(`[RCCallSession onAudioMuteChange] userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"audio",trackId:e.getTrackId()};try{this._listener.onAudioMuteChange(o,this)}catch(e){s.error("[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{s.info(`[RCCallSession onVideoMuteChange]userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"video",trackId:e.getTrackId()};try{this._listener.onVideoMuteChange(o,this)}catch(e){s.error("[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>r(this,void 0,void 0,(function*(){if(this._room){const{code:o}=yield this._room.subscribe(e);o!==i.RCRTCCode.SUCCESS&&s.error(`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${o}`)}})),onTrackUnpublish:e=>{},onTrackReady:e=>{this._stateMachine.getMediaType()===o.RCCallMediaType.AUDIO&&e.isVideoTrack()||this._notifyTrackReady([e])},onUserJoin:e=>{this._stateMachine.userJoin(e)},onUserLeave:e=>{s.info(`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{s.info(`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){s.error("[RCCallSession onPing] listening onPing exception"),console.error(e)}}})}_registerReportListener(){this._room.registerReportListener({onStateReport:e=>{try{this._listener.onRTCStateReport&&this._listener.onRTCStateReport(e,this)}catch(e){s.error("[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){s.error("[RCCallSession onICEConnectionStateChange] onICEConnectionStateChange exception"),console.error(e)}}})}getSessionId(){return this._stateMachine.getCallId()}getRTCSessionId(){return this._room?this._room.getSessionId():null}getTargetId(){return this._stateMachine.getTargetId()}getConversationType(){return this._stateMachine.getConversationType()}getChannelId(){return this._stateMachine.getChannelId()}getRemoteUsers(){return this._stateMachine.getRemoteUsers()}getUserState(e){if(!e||"string"!=typeof e)throw new Error("userId is required, must be of type 'string'");return this._stateMachine.getUserState(e)}getState(){return this._stateMachine.getState()}getCallerId(){return this._stateMachine.getCallerId()}getMediaType(){return this._stateMachine.getMediaType()}}t.VersionManage.add("plugin-call","5.0.7"),t.VersionManage.validEngine(">=4.5.2")||s.error(`The current engine version '${t.VersionManage.getInfo().engine}' error,plugin-call required engine version at least '>=4.5.2'.`);class g{constructor(e,i,r){this._context=e,this._runtime=i,this._sessionList=[],this._rtcClient=r.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:t.RTCJoinType.COEXIST,isAllowDemotionGetStream:!1,lang:o.RCCallLanguage.ZH},r),this._callEngine=new o.RCCallEngine(this._context,i,s,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||o.RCCallLanguage.ZH}),l.on("sessionClose",(({session:e,summaryInfo:o})=>{this._removeSession(e);try{this._options.onSessionClose(e,o)}catch(e){s.error("[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),l.on("hungupOtherSession",(({session:e})=>{const o=e.getSessionId();s.info(`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${o}`),s.info(`[RCCallClient hungupOtherSession] sessionList ->${this._sessionList.map((e=>e.getSessionId())).join(",")}`);let t=0;for(;this._sessionList.length>1;)this._sessionList[t].getSessionId()!==o?(this._sessionList[t].hungup(),this._sessionList.splice(t,1)):t++;s.info(`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e,o){s.info("[RCCallClient _onInvite] Received invite message");const t=new p(e,this._rtcClient,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:n.CALLEE});s.info("[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(t);try{this._options.onSession(t,o)}catch(e){s.error("[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!t._listener)throw s.error("[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=c(t._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){s.error("[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),s.info("[RCCallClient registerUserInfo] successfully register user info data")}call({targetId:e,mediaType:t=o.RCCallMediaType.AUDIO,listener:i,constraints:l,channelId:a="",extra:_="",pushTitle:g="",pushContent:f=""}){return r(this,void 0,void 0,(function*(){s.info(`[RCCallClient call] extra->${_} pushTitle->${g} pushContent->${f}`);const r=[C(e),d(t),c(i),u(_),R(g),h(f)],S=[];if(!r.every((e=>(!e.result&&S.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${S.join("\n")}`);let m=[];const{code:y,tracks:E}=yield this._getLocalTrack(t,l);if(y!==o.RCCallErrorCode.SUCCESS)return{code:y};m=E,m.forEach((e=>{i.onTrackReady(e)}));const{code:T,stateMachine:b}=yield this._callEngine.call(a,e,t,_,g,f);if(T===o.RCCallErrorCode.SUCCESS&&b){s.info("[RCCallClient call] successfully created state machine");const e=new p(b,this._rtcClient,{localTracks:m,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:n.CALLER});return e.registerSessionListener(i),this._sessionList.push(e),s.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:T,session:e}}return s.error(`[RCCallClient call] call failed code ->: ${T}`),m.forEach((e=>{e.mute(),e.destroy()})),{code:T}}))}callInGroup({targetId:e,userIds:t,mediaType:i=o.RCCallMediaType.AUDIO,listener:l,constraints:a,channelId:g="",extra:f="",pushTitle:S="",pushContent:m=""}){return r(this,void 0,void 0,(function*(){const r=[C(e),_(t),d(i),c(l),u(f),R(S),h(m)],y=[];if(!r.every((e=>(!e.result&&y.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${y.join("\n")}`);let E=[];const{code:T,tracks:b}=yield this._getLocalTrack(i,a);if(T!==o.RCCallErrorCode.SUCCESS)return{code:T};E=b,E.forEach((e=>{l.onTrackReady(e)}));const{code:I,stateMachine:v}=yield this._callEngine.callInGroup(g,e,i,t,f,S,m);if(I===o.RCCallErrorCode.SUCCESS&&v){s.info("[RCCallClient callInGroup] successfully created state machine");const e=new p(v,this._rtcClient,{localTracks:E,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:n.CALLER});return e.registerSessionListener(l),this._sessionList.push(e),s.info(`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:I,session:e}}return s.info(`[RCCallClient callInGroup] callInGroup failed code -> ${I}`),E.forEach((e=>{e.mute(),e.destroy()})),{code:I}}))}_getLocalTrackCore(e,t){return r(this,void 0,void 0,(function*(){if(e===o.RCCallMediaType.AUDIO){const{code:e,track:r}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",t&&t.audio&&Object.assign({},t.audio));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(s.info("[RCCallClient _getTrack] successfully get Audio local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:[r]})}{const{code:e,tracks:r}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",t&&Object.assign({},t));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(s.info("[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:r})}}))}_getLocalTrack(e,t){return r(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===o.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO_VIDEO,t);if(e!==o.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO,t);return e!==o.RCCallErrorCode.SUCCESS?{code:e}:{code:e,tracks:i}}return{code:e,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(e,t);return i!==o.RCCallErrorCode.SUCCESS?{code:i}:{code:i,tracks:s}}}))}_removeSession(e){const o=e.getSessionId();this._sessionList=this._sessionList.filter((e=>e.getSessionId()!==o))}getJoinedRoomInfo(){return r(this,void 0,void 0,(function*(){const{code:e,data:i}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return e!==t.ErrorCode.SUCCESS?(s.error("getJoinedUserInfo error",e),{code:o.RCCallErrorCode.QUERY_JOINED_USER_INFO_ERROR}):{code:o.RCCallErrorCode.SUCCESS,data:i}}))}}const f={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,o,t){const i=a(t);if(!i.result)throw new Error(`[RCCallLib installer steup]${i.msg}`);return s.setLogLevel(t.logLevel),s.setLogStdout(t.logStdout),s.warn("RCCall Version: 5.0.7, Commit: 3dcd9a3cf924b311e2169155be169d960765c55e"),new g(e,o,t)}};Object.defineProperty(e,"RCCallEndReason",{enumerable:!0,get:function(){return o.RCCallEndReason}}),Object.defineProperty(e,"RCCallErrorCode",{enumerable:!0,get:function(){return o.RCCallErrorCode}}),Object.defineProperty(e,"RCCallLanguage",{enumerable:!0,get:function(){return o.RCCallLanguage}}),Object.defineProperty(e,"RCCallMediaType",{enumerable:!0,get:function(){return o.RCCallMediaType}}),Object.defineProperty(e,"RCCallSessionState",{enumerable:!0,get:function(){return o.RCCallSessionState}}),Object.defineProperty(e,"RCCallUserState",{enumerable:!0,get:function(){return o.RCCallUserState}}),e.RCCallClient=g,e.RCCallSession=p,e.installer=f,Object.defineProperty(e,"__esModule",{value:!0})}));
15
+ ***************************************************************************** */function r(e,o,t,i){return new(t||(t=Promise))((function(s,r){function n(e){try{a(i.next(e))}catch(e){r(e)}}function l(e){try{a(i.throw(e))}catch(e){r(e)}}function a(e){var o;e.done?s(e.value):(o=e.value,o instanceof t?o:new t((function(e){e(o)}))).then(n,l)}a((i=i.apply(e,o||[])).next())}))}var n;!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(n||(n={}));var l=new class{constructor(){this.list={}}on(e,o){return(this.list[e]||(this.list[e]=[])).push(o),this}once(e,o){const t=i=>{this.off(e,t),o.call(this,i)};t.fun=o,this.on(e,t)}off(e,o){const t=this.list[e];if(!t)return!1;if(o){let e;for(let i=0,s=t.length;i<s;i++)if(e=t[i],e===o||e.fun===o){t.splice(i,1);break}}else t&&(t.length=0)}emit(e,o){const t=[...this.list[e]];if(!t||0===t.length)return!1;t.forEach((e=>{e.call(this,o)}))}};const a=e=>{if(!e)return{result:!1,msg:"Initialization missing parameter -> options"};if("object"!=typeof e)return{result:!1,msg:"Initialization options must be an object"};const i=Object.keys(e),s=[];return["rtcClient","onSession","onSessionClose"].forEach((e=>{i.includes(e)||s.push(e)})),s.length?{result:!1,msg:`Initialization missing parameter -> "${s.join(",")}"`}:"object"!=typeof e.rtcClient?{result:!1,msg:"Initialization 'rtcClient' parameter must be of type 'object'"}:"function"!=typeof e.onSession?{result:!1,msg:"Initialization 'onSession' parameter must be of type 'function'"}:"function"!=typeof e.onSessionClose?{result:!1,msg:"Initialization 'onSessionClose' parameter must be of type 'function'"}:void 0!==e.isAllowSubscribeRetry&&"boolean"!=typeof e.isAllowSubscribeRetry?{result:!1,msg:"Initialization 'isAllowSubscribeRetry' parameter must be of type 'boolean'"}:void 0!==e.isAllowPublishRetry&&"boolean"!=typeof e.isAllowPublishRetry?{result:!1,msg:"Initialization 'isAllowPublishRetry' parameter must be of type 'boolean'"}:void 0!==e.isOffCameraWhenVideoDisable&&"boolean"!=typeof e.isOffCameraWhenVideoDisable?{result:!1,msg:"Initialization 'isOffCameraWhenVideoDisable' parameter must be of type 'boolean'"}:void 0===e.joinType||(r=e.joinType,Object.values(t.RTCJoinType).includes(r))?void 0!==e.isAllowDemotionGetStream&&"boolean"!=typeof e.isAllowDemotionGetStream?{result:!1,msg:"Initialization 'isAllowDemotionGetStream' parameter must be of type 'boolean'"}:void 0===e.lang||function(e){return Object.values(o.RCCallLanguage).includes(e)}(e.lang)?void 0===e.logLevel||function(e){return Object.values(t.LogLevel).includes(e)}(e.logLevel)?void 0!==e.logStdout&&"function"!=typeof e.logStdout?{result:!1,msg:"Initialization 'logStdout' parameter must be of type 'function'"}:{result:!0}:{result:!1,msg:"Initialization 'logLevel' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'lang' parameter must be of type correct type"}:{result:!1,msg:"Initialization 'joinType' parameter must be of type correct type"};var r},c=e=>{if(!e)return{result:!1,msg:"missing parameter -> listener"};if("object"!=typeof e)return{result:!1,msg:"listener must be an object"};const o=Object.keys(e),t=[];return["onRinging","onAccept","onHungup","onTrackReady"].forEach((e=>{o.includes(e)||t.push(e)})),t.length?{result:!1,msg:`missing parameter -> "${t.join(",")}"`}:"function"!=typeof e.onRinging?{result:!1,msg:"'onRinging' parameter must be of type 'function'"}:"function"!=typeof e.onAccept?{result:!1,msg:"'onAccept' parameter must be of type 'function'"}:"function"!=typeof e.onHungup?{result:!1,msg:"'onHungup' parameter must be of type 'function'"}:"function"!=typeof e.onTrackReady?{result:!1,msg:"'onTrackReady' parameter must be of type 'function'"}:{result:!0}},C=e=>e&&"string"==typeof e?{result:!0}:{result:!1,msg:"'targetId' parameter is required, must be of type 'string'"},d=e=>e===o.RCCallMediaType.AUDIO||e===o.RCCallMediaType.AUDIO_VIDEO?{result:!0}:{result:!1,msg:"'mediaType' parameter is required, must be of type 'RCCallMediaType'"},u=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'extra' parameter must be of type 'string'"},R=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushTitle' parameter must be of type 'string'"},h=e=>"string"==typeof e?{result:!0}:{result:!1,msg:"'pushContent' parameter must be of type 'string'"},_=e=>Array.isArray(e)&&e.length?e.every((e=>"string"==typeof e&&e.length>0))?{result:!0}:{result:!1,msg:"'userIds' parameter is required"}:{result:!1,msg:"'userIds' parameter is required, must be of type 'string[]'"};class p{constructor(e,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,t,i={}){this._stateMachine=e,this._rtcClient=t,this._options=i,this._listener=null,this._RETRYCOUNT=2,this.joinRoomTimer=null,this._stateMachine.registerEventListener({onUserStateChange:({user:e,reason:o})=>{s.info(`[RCCallSession onUserStateChange] userId->${null==e?void 0:e.userId} state->${null==e?void 0:e.state} reason->${o}`)},onStateChange:e=>r(this,void 0,void 0,(function*(){const{state:t,reason:i}=e;if(s.info(`[RCCallSession onStateChange] : state->${t} reason->${i}`),t===o.RCCallSessionState.KEEPING){const e=this._stateMachine.getCallId();s.info(`[RCCallSession onStateChange] roomId: ${e}`);try{yield this._joinRoom(e)}catch(t){this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR),s.error(`[RCCallSession onStateChange] joinRoom throw exception roomId -> ${e}`),console.error(t)}}else if(t===o.RCCallSessionState.END){if(!this._room){this._options.localTracks&&this._destroyTracks(this._options.localTracks);const e=this._stateMachine.getSummary();return void l.emit("sessionClose",{session:this,summaryInfo:e})}this._options.localTracks&&this._destroyTracks(this._options.localTracks),s.info("[RCCallSession onStateChange] localTracks destroyed"),this._leaveRoom(),this._room=null}})),onRinging:e=>{s.info(`[RCCallSession onRinging]sender: sender.userId -> ${e.userId}`);try{this._listener.onRinging(e,this)}catch(e){s.error("[RCCallSession onRinging] method exception -> onRinging"),console.error(e)}},onAccept:e=>{s.info(`[RCCallSession onAccept]sender: sender.userId -> ${e.userId}`);try{this._listener.onAccept(e,this)}catch(e){s.error("[RCCallSession onAccept] method exception -> onAccept"),console.error(e)}},onHungup:(e,o)=>{s.info(`[RCCallSession onHungup]sender: sender.userId -> ${e.userId} reason->${o}`);try{this._listener.onHungup(e,o,this)}catch(e){s.error("[RCCallSession onHungup] method exception -> onHungup"),console.error(e)}},onMemberModify:({sender:e,invitedUsers:o})=>{s.info(`[RCCallSession onMemberModify] sender.userId -> ${e.userId}`);try{this._listener.onMemberModify(e,o,this)}catch(e){s.error("[RCCallSession onMemberModify] method exception -> onMemberModify"),console.error(e)}},onMediaModify:({sender:e,mediaType:t})=>{s.info(`[RCCallSession onMediaModify]sender: sender.userId -> ${e.userId} mediaType: ${t}`),t===o.RCCallMediaType.AUDIO&&this._setMediaTypeToAudio();try{this._listener.onMediaModify(e,t,this)}catch(e){s.error("[RCCallSession onMediaModify] method exception -> onMediaModify"),console.error(e)}}})}_joinRoom(e){return r(this,void 0,void 0,(function*(){try{const{code:t,userIds:r,room:n}=yield this._rtcClient.joinRTCRoom(e,this._options.joinType);if(t!==i.RCRTCCode.SUCCESS)return t===i.RCRTCCode.NOT_OPEN_VIDEO_AUDIO_SERVER&&this._exceptionClose(o.RCCallEndReason.SERVICE_NOT_OPENED),t===i.RCRTCCode.SIGNAL_JOIN_RTC_ROOM_REFUSED?this._exceptionClose(o.RCCallEndReason.OTHER_CLIENT_IN_CALL):this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR),s.info(`[RCCallClient _joinRoom] join room failed: roomId -> ${e} RCRTCCode -> ${t}`),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR};r.length<1&&(this.joinRoomTimer=new p((()=>{this._exceptionClose(o.RCCallEndReason.REMOTE_NETWORK_ERROR)}),6e4)),this._room=n}catch(t){return this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR),s.error(`[RCCallSession _joinRoom] _rtcClient.joinRTCRoom throw exception roomId -> ${e}`),console.error(t),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR}}this._registerRoomEventListener(),this._registerReportListener();try{yield this._subscribeInRoomRemoteTrack()}catch(t){return this._exceptionClose(o.RCCallEndReason.SUBSCRIBE_ERROR),s.error(`[RCCallSession _joinRoom] _subscribeInRoomRemoteTrack Exception roomId -> ${e}`),console.error(t),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR}}try{yield this._publish()}catch(t){return this._exceptionClose(o.RCCallEndReason.PUBLISH_ERROR),s.error(`[RCCallSession _joinRoom] _publish Exception roomId -> ${e}`),console.error(t),{code:o.RCCallErrorCode.JOIN_ROOM_ERROR}}return{code:o.RCCallErrorCode.SUCCESS}}))}_subscribeInRoomRemoteTrack(){return r(this,void 0,void 0,(function*(){const e=this._room.getRemoteTracks();if(e.length){const{code:t}=yield this._subscribeRetry(e,this._options.isAllowSubscribeRetry,this._RETRYCOUNT);t!==i.RCRTCCode.SUCCESS&&(this._exceptionClose(o.RCCallEndReason.SUBSCRIBE_ERROR),s.error(`[RCCallSession _subscribeInRoomRemoteTrack] Resource subscription failed roomId -> ${this._stateMachine.getCallId()} RTC code -> ${t}`))}}))}_subscribeRetry(e,o=!1,t=0){return r(this,void 0,void 0,(function*(){const{code:r}=yield this._room.subscribe(e);if(r!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackSubscribeFail&&this._listener.onTrackSubscribeFail(r,this)}catch(e){s.error("[RCCallSession] _listener.onTrackSubscribeFail exception"),console.error(e)}if(!o)return{code:r};if(t>0)return t--,this._subscribeRetry(e,o,t)}return{code:r}}))}_publish(){return r(this,void 0,void 0,(function*(){const e=this._options.localTracks,{code:t}=yield this._publishRetry(e,this._options.isAllowPublishRetry,this._RETRYCOUNT);if(t!==i.RCRTCCode.SUCCESS)return this._exceptionClose(o.RCCallEndReason.PUBLISH_ERROR),void s.info(`[RCCallSession _publist] Resource publishing failed: roomId -> ${this._stateMachine.getCallId()} RCRTCCode -> ${t}`);this._options.produceType===n.CALLEE&&this._notifyTrackReady(e)}))}_publishRetry(e,o=!1,t=0){return r(this,void 0,void 0,(function*(){const{code:r}=yield this._room.publish(e);if(r!==i.RCRTCCode.SUCCESS){try{this._listener.onTrackPublishFail&&this._listener.onTrackPublishFail(r,this)}catch(e){s.error("[RCCallSession] _listener.onTrackPublishFail exception"),console.error(e)}if(!o)return{code:r};if(t>0)return t--,this._publishRetry(e,o,t)}return{code:r}}))}_leaveRoom(){return r(this,void 0,void 0,(function*(){try{const{code:e}=yield this._rtcClient.leaveRoom(this._room);s.info("[RCCallSession _leaveRoom] Successfully exited the room")}catch(e){s.error("[RCCallSession _leaveRoom] leaveRoom throw exception"),console.error(e)}finally{const e=this._stateMachine.getSummary();l.emit("sessionClose",{session:this,summaryInfo:e})}}))}_exceptionClose(e){this._options.localTracks&&this._destroyTracks(this._options.localTracks),this._stateMachine.close(e)}registerSessionListener(e){const o=c(e);if(!o.result)throw new Error(`[RCCallSession registerSessionListener] ${o.msg}`);this._listener=Object.assign({},e)}_getLocalTrackCore(e,t){return r(this,void 0,void 0,(function*(){if(e===o.RCCallMediaType.AUDIO){const{code:e,track:r}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",t&&t.audio&&Object.assign({},t.audio));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession _getLocalTrackCore] get Audio local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(s.info("[RCCallSession _getLocalTrackCore] successfully get Audio local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:[r]})}{const{code:e,tracks:r}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",t&&Object.assign({},t));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession _getLocalTrackCore] get Audio and Video local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(s.info("[RCCallSession _getLocalTrackCore] successfully get audio and video local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:r})}}))}_getLocalTrack(e,t){return r(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===o.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO_VIDEO,t);if(e!==o.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO,t);return e!==o.RCCallErrorCode.SUCCESS?(this._exceptionClose(o.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:e}):{code:e,tracks:i}}return{code:e,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(e,t);return i!==o.RCCallErrorCode.SUCCESS?(this._exceptionClose(o.RCCallEndReason.GET_MEDIA_RESOURCES_ERROR),{code:i}):{code:i,tracks:s}}}))}changeAudioDevice(e){return r(this,void 0,void 0,(function*(){const t=[],r=[],{code:n,track:l}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",e);if(n!==i.RCRTCCode.SUCCESS)return s.error(`[RCCallSession changeDevice] get local Audio tracks failed RCTLib code -> ${n}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR};if(this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isAudioTrack()||r.push(e)})),t.push(l),r.push(l),this._options.localTracks=r,this._notifyTrackReady(t),this._room){const{code:e}=yield this._room.publish(t);if(e!==i.RCRTCCode.SUCCESS)return{code:o.RCCallErrorCode.AUDIO_PUBLISH_ERROR}}return{code:o.RCCallErrorCode.SUCCESS}}))}invite(e,o={}){return r(this,void 0,void 0,(function*(){const{extra:t="",pushTitle:i="",pushContent:s=""}=o,r=[_(e),u(t),R(i),h(s)],n=[];if(!r.every((e=>(!e.result&&n.push(e.msg),e.result))))throw new Error(`[RCCallClient invite] ${n.join("\n")}`);const{code:l}=yield this._stateMachine.invite(e,{extra:t,pushTitle:i,pushContent:s});return{code:l}}))}accept(e){return r(this,void 0,void 0,(function*(){const t=(e=>{return e&&e.audio&&void 0!==e.audio.micphoneId&&"string"!=typeof e.audio.micphoneId?{result:!1,msg:"'constraints.audio.micphoneId' must be of type 'string'"}:e&&e.audio&&void 0!==e.audio.sampleRate&&"number"!=typeof e.audio.sampleRate?{result:!1,msg:"'constraints.audio.sampleRate' must be of type 'number'"}:e&&e.video&&void 0!==e.video.cameraId&&"string"!=typeof e.video.cameraId?{result:!1,msg:"'constraints.video.cameraId' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&"string"!=typeof e.video.frameRate?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.frameRate&&(o=e.video.frameRate,!["FPS_10","FPS_15","FPS_24","FPS_30"].includes(o))?{result:!1,msg:"'frameRate' value is out of range"}:e&&e.video&&void 0!==e.video.resolution&&"string"!=typeof e.video.resolution?{result:!1,msg:"'constraints.video.frameRate' must be of type 'string'"}:e&&e.video&&void 0!==e.video.resolution&&!function(e){return["W176_H132","W176_H144","W256_H144","W320_H180","W240_H240","W320_H240","W480_H360","W640_H360","W480_H480","W640_H480","W720_H480","W1280_H720","W1920_H1080"].includes(e)}(e.video.resolution)?{result:!1,msg:"'resolution' value is out of range"}:!e||!e.video||e.video.frameRate&&e.video.resolution?{result:!0}:{result:!1,msg:"'resolution' and 'resolution' is required"};var o})(e);if(!t.result)throw new Error(`[RCCallSession accept] ${t.msg}`);l.emit("hungupOtherSession",{session:this});const i=this._stateMachine.getMediaType(),{code:r,tracks:n}=yield this._getLocalTrack(i,e);if(r!==o.RCCallErrorCode.SUCCESS)return{code:r};this._options.localTracks=n;const{code:a}=yield this._stateMachine.accept();return a!==o.RCCallErrorCode.SUCCESS?(s.error(`[RCCallSession accept]Send accept message failed -> code: ${a}`),{code:a}):{code:a}}))}hungup(){return r(this,void 0,void 0,(function*(){return this._stateMachine.hungup()}))}_changeMediaType(e){return r(this,void 0,void 0,(function*(){const{code:t}=yield this._stateMachine.changeMediaType(e);return t!==o.RCCallErrorCode.SUCCESS&&s.error(`[RCCallSession _changeMediaType] change media type fail code-> ${t}`),{code:t}}))}_getLocalVideoTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isVideoTrack()))),e):e}_getLocalAudioTracks(){let e=[];return this._room?(this._options.localTracks&&(e=this._options.localTracks.filter((e=>e.isAudioTrack()))),e):e}_setMediaTypeToAudioAndVideo(){return r(this,void 0,void 0,(function*(){const{code:e,track:t}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR};const{code:r}=yield this._room.publish([t]);r===i.RCRTCCode.SUCCESS?(this._notifyTrackReady([t]),this._changeMediaType(o.RCCallMediaType.AUDIO_VIDEO)):s.error(`[RCCallSession _enableVideo] Resource publishing failed: RCRTCCode -> ${e}`)}))}_setMediaTypeToAudio(){return r(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(e.length){e.forEach((e=>{e.mute()}));const{code:o}=yield this._room.unpublish(e);o!==i.RCRTCCode.SUCCESS&&s.error(`[RCCallSession disableVideo] unpublish failed -> ${o}`),this._destroyTracks(e)}}))}descendAbility(){return r(this,void 0,void 0,(function*(){const{code:e}=yield this._changeMediaType(o.RCCallMediaType.AUDIO);return e===o.RCCallErrorCode.SUCCESS&&this._setMediaTypeToAudio(),{code:e}}))}disableVideoTrack(){return r(this,void 0,void 0,(function*(){const e=this._getLocalVideoTracks();if(!e.length)return s.error(`[RCCallSession disableVideoTrack] Room missing video track -> ${o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR};if(e.forEach((e=>{e.mute()})),!this._options.isOffCameraWhenVideoDisable)return{code:o.RCCallErrorCode.SUCCESS};const{code:t}=yield this._room.unpublish(e);return t!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession disableVideo] unpublish failed -> ${t}`),{code:o.RCCallErrorCode.UNPUBLISH_VIDEO_ERROR}):(e.forEach((e=>{e.destroy()})),{code:o.RCCallErrorCode.SUCCESS})}))}enableVideoTrack(){return r(this,void 0,void 0,(function*(){if(!this._options.isOffCameraWhenVideoDisable){const e=this._getLocalVideoTracks();return e.length?(e.forEach((e=>{e.unmute()})),{code:o.RCCallErrorCode.SUCCESS}):(s.error(`[RCCallSession EnableVideoTrack] Room missing video track -> ${o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR}`),{code:o.RCCallErrorCode.MISSING_VIDEO_TRACK_ERROR})}const{code:e,track:t}=yield this._rtcClient.createCameraVideoTrack();if(e!==i.RCRTCCode.SUCCESS)return s.error(`[RCCallSession EnableVideoTrack] Get Resource failed: RCRTCCode -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_VIDEO_TRACK_ERROR};const r=[];this._options.localTracks&&this._options.localTracks.forEach((e=>{e.isVideoTrack()?e.destroy():r.push(e)})),r.push(t),this._options.localTracks=r,t.mute();const{code:n}=yield this._room.publish([t]);return n!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallSession EnableVideoTrack] Resource publishing failed: RCRTCCode -> ${e}`),{code:o.RCCallErrorCode.VIDEO_PUBLISH_ERROR}):(t.unmute(),this._notifyTrackReady([t]),{code:o.RCCallErrorCode.SUCCESS})}))}disableAudioTrack(){return r(this,void 0,void 0,(function*(){this._getLocalAudioTracks().forEach((e=>{e.mute()}))}))}enableAudioTrack(){return r(this,void 0,void 0,(function*(){this._getLocalAudioTracks().forEach((e=>{e.unmute()}))}))}_destroyTracks(e){e.forEach((e=>{e.destroy()}))}_notifyTrackReady(e){e.forEach((e=>{try{this._listener.onTrackReady(e,this)}catch(e){s.error("[RCCallSession _notifyTrackReady] _listener onTrackReady exception"),console.error(e)}}))}_registerRoomEventListener(){this._room.registerRoomEventListener({onKickOff:(e,t)=>{const s=this._rtcClient.getCurrentId();this._stateMachine.userLeave([s]),e?(t===i.RCKickReason.SERVER_KICK&&this._exceptionClose(o.RCCallEndReason.KICKED_BY_SERVER),t===i.RCKickReason.OTHER_KICK&&this._exceptionClose(o.RCCallEndReason.OTHER_CLIENT_JOINED_CALL)):this._exceptionClose(o.RCCallEndReason.NETWORK_ERROR)},onMessageReceive(e,o,t,i){},onRoomAttributeChange(e,o){},onAudioMuteChange:e=>{s.info(`[RCCallSession onAudioMuteChange] userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"audio",trackId:e.getTrackId()};try{this._listener.onAudioMuteChange(o,this)}catch(e){s.error("[RCCallSession onAudioMuteChange] Missing listening method -> onTrackMuteChange"),console.error(e)}},onVideoMuteChange:e=>{s.info(`[RCCallSession onVideoMuteChange]userId->${e.getUserId()} muted -> ${e.isOwnerMuted()}`);const o={userId:e.getUserId(),muted:e.isOwnerMuted(),kind:"video",trackId:e.getTrackId()};try{this._listener.onVideoMuteChange(o,this)}catch(e){s.error("[RCCallSession onVideoMuteChange] Missing listening method -> onVideoMuteChange"),console.error(e)}},onTrackPublish:e=>r(this,void 0,void 0,(function*(){if(this._room){const{code:o}=yield this._room.subscribe(e);o!==i.RCRTCCode.SUCCESS&&s.error(`[RCCallSession onTrackPublish] subscribe failed RTCCode ->${o}`)}})),onTrackUnpublish:e=>{},onTrackReady:e=>{this._stateMachine.getMediaType()===o.RCCallMediaType.AUDIO&&e.isVideoTrack()||this._notifyTrackReady([e])},onUserJoin:e=>{this.joinRoomTimer&&this.joinRoomTimer.stop(),this._stateMachine.userJoin(e)},onUserLeave:e=>{s.info(`[RCCallSession onUserLeave] listening onUserLeave userIds -> ${null==e?void 0:e.join(",")}`),this._stateMachine.userLeave(e)},onPing:e=>{s.info(`[RCCallSession onPing]${e}`);try{this._listener.onPing&&this._listener.onPing(e,this)}catch(e){s.error("[RCCallSession onPing] listening onPing exception"),console.error(e)}}})}_registerReportListener(){this._room.registerReportListener({onStateReport:e=>{try{this._listener.onRTCStateReport&&this._listener.onRTCStateReport(e,this)}catch(e){s.error("[RCCallSession onStateReport] listener onStateReport exception"),console.error(e)}},onICEConnectionStateChange:e=>{try{this._listener.onICEConnectionStateChange&&this._listener.onICEConnectionStateChange(e,this)}catch(e){s.error("[RCCallSession onICEConnectionStateChange] onICEConnectionStateChange exception"),console.error(e)}}})}getSessionId(){return this._stateMachine.getCallId()}getRTCSessionId(){return this._room?this._room.getSessionId():null}getTargetId(){return this._stateMachine.getTargetId()}getConversationType(){return this._stateMachine.getConversationType()}getChannelId(){return this._stateMachine.getChannelId()}getRemoteUsers(){return this._stateMachine.getRemoteUsers()}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()}}t.VersionManage.add("plugin-call","5.0.10"),t.VersionManage.validEngine("^4.5.5-enterprise.1")||s.error(`The current engine version '${t.VersionManage.getInfo().engine}' error,plugin-call required engine version at least '^4.5.5-enterprise.1'.`);class f{constructor(e,i,r){this._context=e,this._runtime=i,this._sessionList=[],this._rtcClient=r.rtcClient,this._options=Object.assign({isAllowPublishRetry:!1,isAllowSubscribeRetry:!1,isOffCameraWhenVideoDisable:!0,joinType:t.RTCJoinType.COEXIST,isAllowDemotionGetStream:!1,lang:o.RCCallLanguage.ZH},r),this._callEngine=new o.RCCallEngine(this._context,i,s,{onInvite:this._onInvite.bind(this),onOfflineRecord:this._onOfflineRecord.bind(this)},{lang:this._options.lang||o.RCCallLanguage.ZH}),l.on("sessionClose",(({session:e,summaryInfo:o})=>{this._removeSession(e);try{this._options.onSessionClose(e,o)}catch(e){s.error("[RCCCallClient] options.onSessionClose exception"),console.log(e)}})),l.on("hungupOtherSession",(({session:e})=>{const o=e.getSessionId();s.info(`[RCCallClient hungupOtherSession] sessionId ready to accept -> ${o}`),s.info(`[RCCallClient hungupOtherSession] sessionList ->${this._sessionList.map((e=>e.getSessionId())).join(",")}`);let t=0;for(;this._sessionList.length>1;)this._sessionList[t].getSessionId()!==o?(this._sessionList[t].hungup(),this._sessionList.splice(t,1)):t++;s.info(`[RCCallClient hungupOtherSession] current sessionList length ->${this._sessionList.length}`)}))}_onInvite(e,o){s.info("[RCCallClient _onInvite] Received invite message");const t=new g(e,this._rtcClient,{isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:n.CALLEE});s.info("[RCCallClient _onInvite] Received invite message, successfully created session"),this._sessionList.push(t);try{this._options.onSession(t,o)}catch(e){s.error("[RCCallClient _options.onSession] onSession exception"),console.log(e)}if(!t._listener)throw s.error("[RCCallClient _options.onSession] session Must Have Listener"),new Error("[RCCallSession _options.onSession] session Must Have Listener");{const e=c(t._listener);if(!e.result)throw new Error(e.msg)}}_onOfflineRecord(e){try{this._options.onOfflineRecord&&this._options.onOfflineRecord(e)}catch(e){s.error("[RCCallClient _options.onOfflineRecord] onOfflineRecord exception"),console.log(e)}}registerUserInfo(e={}){this._callEngine.registerUserInfo(e),s.info("[RCCallClient registerUserInfo] successfully register user info data")}call({targetId:e,mediaType:t=o.RCCallMediaType.AUDIO,listener:i,constraints:l,channelId:a="",extra:_="",pushTitle:p="",pushContent:f="",bitrate:m}){return r(this,void 0,void 0,(function*(){s.info(`[RCCallClient call] extra->${_} pushTitle->${p} pushContent->${f}`);const r=[C(e),d(t),c(i),u(_),R(p),h(f)],S=[];if(!r.every((e=>(!e.result&&S.push(e.msg),e.result))))throw new Error(`[RCCallClient call] ${S.join("\n")}`);let y=[];const{code:T,tracks:E}=yield this._getLocalTrack(t,l);if(T!==o.RCCallErrorCode.SUCCESS)return{code:T};y=E,y.forEach((e=>{var o,t,s;e.isAudioTrack()&&(null==m?void 0:m.audio)&&e.setBitrate(null==m?void 0:m.audio),e.isVideoTrack()&&(null==m?void 0:m.video)&&e.setBitrate(null===(o=null==m?void 0:m.video)||void 0===o?void 0:o.max,null===(t=null==m?void 0:m.video)||void 0===t?void 0:t.min,null===(s=null==m?void 0:m.video)||void 0===s?void 0:s.start),i.onTrackReady(e)}));const{code:v,stateMachine:b}=yield this._callEngine.call(a,e,t,_,p,f);if(v===o.RCCallErrorCode.SUCCESS&&b){s.info("[RCCallClient call] successfully created state machine");const e=new g(b,this._rtcClient,{localTracks:y,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:n.CALLER});return e.registerSessionListener(i),this._sessionList.push(e),s.info(`[RCCallClient call] successfully created session object, sessionId: ${e.getSessionId()}`),{code:v,session:e}}return s.error(`[RCCallClient call] call failed code ->: ${v}`),y.forEach((e=>{e.mute(),e.destroy()})),{code:v}}))}callInGroup({targetId:e,userIds:t,mediaType:i=o.RCCallMediaType.AUDIO,listener:l,constraints:a,channelId:p="",extra:f="",pushTitle:m="",pushContent:S="",bitrate:y}){return r(this,void 0,void 0,(function*(){const r=[C(e),_(t),d(i),c(l),u(f),R(m),h(S)],T=[];if(!r.every((e=>(!e.result&&T.push(e.msg),e.result))))throw new Error(`[RCCallClient callInGroup] ${T.join("\n")}`);let E=[];const{code:v,tracks:b}=yield this._getLocalTrack(i,a);if(v!==o.RCCallErrorCode.SUCCESS)return{code:v};E=b,E.forEach((e=>{var o,t,i;e.isAudioTrack()&&(null==y?void 0:y.audio)&&e.setBitrate(null==y?void 0:y.audio),e.isVideoTrack()&&(null==y?void 0:y.video)&&e.setBitrate(null===(o=null==y?void 0:y.video)||void 0===o?void 0:o.max,null===(t=null==y?void 0:y.video)||void 0===t?void 0:t.min,null===(i=null==y?void 0:y.video)||void 0===i?void 0:i.start),l.onTrackReady(e)}));const{code:I,stateMachine:O}=yield this._callEngine.callInGroup(p,e,i,t,f,m,S);if(I===o.RCCallErrorCode.SUCCESS&&O){s.info("[RCCallClient callInGroup] successfully created state machine");const e=new g(O,this._rtcClient,{localTracks:E,isAllowSubscribeRetry:this._options.isAllowSubscribeRetry,isAllowPublishRetry:this._options.isAllowPublishRetry,isOffCameraWhenVideoDisable:this._options.isOffCameraWhenVideoDisable,joinType:this._options.joinType,isAllowDemotionGetStream:this._options.isAllowDemotionGetStream,produceType:n.CALLER});return e.registerSessionListener(l),this._sessionList.push(e),s.info(`[RCCallClient callInGroup] successfully created session object, sessionId: ${e.getSessionId()}`),{code:I,session:e}}return s.info(`[RCCallClient callInGroup] callInGroup failed code -> ${I}`),E.forEach((e=>{e.mute(),e.destroy()})),{code:I}}))}_getLocalTrackCore(e,t){return r(this,void 0,void 0,(function*(){if(e===o.RCCallMediaType.AUDIO){const{code:e,track:r}=yield this._rtcClient.createMicrophoneAudioTrack("RongCloudRTC",t&&t.audio&&Object.assign({},t.audio));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallClient _getTrack] get Audio local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_TRACK_ERROR}):(s.info("[RCCallClient _getTrack] successfully get Audio local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:[r]})}{const{code:e,tracks:r}=yield this._rtcClient.createMicrophoneAndCameraTracks("RongCloudRTC",t&&Object.assign({},t));return e!==i.RCRTCCode.SUCCESS?(s.error(`[RCCallClient _getTrack] get Audio and Video local tracks failed RCT code -> ${e}`),{code:o.RCCallErrorCode.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR}):(s.info("[RCCallClient _getTrack] successfully get audio and video local tracks"),{code:o.RCCallErrorCode.SUCCESS,tracks:r})}}))}_getLocalTrack(e,t){return r(this,void 0,void 0,(function*(){if(this._options.isAllowDemotionGetStream&&e===o.RCCallMediaType.AUDIO_VIDEO){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO_VIDEO,t);if(e!==o.RCCallErrorCode.SUCCESS){const{code:e,tracks:i}=yield this._getLocalTrackCore(o.RCCallMediaType.AUDIO,t);return e!==o.RCCallErrorCode.SUCCESS?{code:e}:{code:e,tracks:i}}return{code:e,tracks:i}}{const{code:i,tracks:s}=yield this._getLocalTrackCore(e,t);return i!==o.RCCallErrorCode.SUCCESS?{code:i}:{code:i,tracks:s}}}))}_removeSession(e){const o=e.getSessionId();this._sessionList=this._sessionList.filter((e=>e.getSessionId()!==o))}getJoinedRoomInfo(){return r(this,void 0,void 0,(function*(){const{code:e,data:i}=yield this._context.getRTCJoinedUserInfo(this._context.getCurrentId());return e!==t.ErrorCode.SUCCESS?(s.error("getJoinedUserInfo error",e),{code:o.RCCallErrorCode.QUERY_JOINED_USER_INFO_ERROR}):{code:o.RCCallErrorCode.SUCCESS,data:i}}))}destroyStateMachine(){return r(this,void 0,void 0,(function*(){return this._callEngine.destroy()}))}}const m={tag:"RCCall",verify:e=>"browser"===e.tag,setup(e,o,t){const i=a(t);if(!i.result)throw new Error(`[RCCallLib installer steup]${i.msg}`);return s.setLogLevel(t.logLevel),s.setLogStdout(t.logStdout),s.warn("RCCall Version: 5.0.10, Commit: 010761df892b669845b52207e7c1c3829782d100"),new f(e,o,t)}};Object.defineProperty(e,"RCCallEndReason",{enumerable:!0,get:function(){return o.RCCallEndReason}}),Object.defineProperty(e,"RCCallErrorCode",{enumerable:!0,get:function(){return o.RCCallErrorCode}}),Object.defineProperty(e,"RCCallLanguage",{enumerable:!0,get:function(){return o.RCCallLanguage}}),Object.defineProperty(e,"RCCallMediaType",{enumerable:!0,get:function(){return o.RCCallMediaType}}),Object.defineProperty(e,"RCCallSessionState",{enumerable:!0,get:function(){return o.RCCallSessionState}}),Object.defineProperty(e,"RCCallUserState",{enumerable:!0,get:function(){return o.RCCallUserState}}),e.RCCallClient=f,e.RCCallSession=g,e.installer=m,Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -0,0 +1,294 @@
1
+ import { LogLevel, RTCJoinType } from '@rongcloud/engine';
2
+ import { RCRTCClient, RCTrack, RCLocalTrack, RCRTCCode, ICameraVideoProfile, IMicphoneAudioProfile, IRCRTCStateReport, RCRTCPingResult } from '@rongcloud/plugin-rtc';
3
+ import { ProduceTypes } from './enums';
4
+ import { RCCallSession } from './RCCallSession';
5
+ import { RCCallMediaType, RCCallEndReason, RCCallLanguage, IEndSummary, IInvitedUsers, IOfflineRecord } from '@rongcloud/plugin-call-engine';
6
+ export interface ISender {
7
+ userId: string;
8
+ /**
9
+ * 用户名
10
+ */
11
+ name?: string;
12
+ /**
13
+ * 用户头像地址
14
+ */
15
+ portraitUri?: string;
16
+ /**
17
+ * user info 中附加信息
18
+ */
19
+ extra?: string;
20
+ }
21
+ export interface IMuteUser extends ISender {
22
+ /**
23
+ * 是否禁用
24
+ */
25
+ muted: boolean;
26
+ /**
27
+ * track类型
28
+ */
29
+ kind: string;
30
+ /**
31
+ * trackId
32
+ */
33
+ trackId: string;
34
+ }
35
+ /**
36
+ * CallLib 初始化参数
37
+ */
38
+ export interface IRCCallInitOptions {
39
+ /**
40
+ * RTC实例
41
+ */
42
+ rtcClient: RCRTCClient;
43
+ /**
44
+ * 收到邀请后,产生新的session
45
+ */
46
+ onSession: (session: RCCallSession, extra?: string) => void;
47
+ /**
48
+ * session已关闭
49
+ */
50
+ onSessionClose: (session: RCCallSession, summary?: IEndSummary) => void;
51
+ onOfflineRecord?: (record: IOfflineRecord) => void;
52
+ /**
53
+ * 是否允许接听新呼叫,当前正在通话,如果收到新的邀请,是直接挂断,还是允许选择, 默认值false,直接挂断新的session
54
+ *
55
+ * 暂不对外暴露
56
+ */
57
+ /**
58
+ * 是否允许订阅重试, 默认为false
59
+ */
60
+ isAllowSubscribeRetry?: boolean;
61
+ /**
62
+ * 是否允许发布重试, 默认为false
63
+ */
64
+ isAllowPublishRetry?: boolean;
65
+ /**
66
+ * 禁用视频时关摄像头, 默认false
67
+ */
68
+ isOffCameraWhenVideoDisable?: boolean;
69
+ /**
70
+ * RTC 房间加入类型
71
+ */
72
+ joinType?: RTCJoinType;
73
+ /**
74
+ * 允许降级获得流,获得音视频不成功 ,降级获得音频
75
+ */
76
+ isAllowDemotionGetStream?: boolean;
77
+ /**
78
+ * 日志等级
79
+ */
80
+ logLevel?: LogLevel;
81
+ logStdout?: (logLevel: LogLevel, content: string) => void;
82
+ /**
83
+ * 语言设置 (推送), 不传默认为中文
84
+ */
85
+ lang?: RCCallLanguage;
86
+ }
87
+ /**
88
+ * session上的监听
89
+ */
90
+ export interface ISessionListener {
91
+ /**
92
+ * 当对方已响铃
93
+ */
94
+ onRinging: (sender: ISender, session: RCCallSession) => void;
95
+ /**
96
+ * 当对方已同意
97
+ */
98
+ onAccept: (sender: ISender, session: RCCallSession) => void;
99
+ /**
100
+ * 当对方已挂断
101
+ */
102
+ onHungup: (sender: ISender, reason: RCCallEndReason, session: RCCallSession) => void;
103
+ /**
104
+ * 群组通话,人员改变
105
+ */
106
+ onMemberModify: (sender: ISender, invitedUsers: IInvitedUsers[], session: RCCallSession) => void;
107
+ /**
108
+ * 通话降级
109
+ */
110
+ onMediaModify: (sender: ISender, mediaType: RCCallMediaType, session: RCCallSession) => void;
111
+ /**
112
+ * 当接到流
113
+ */
114
+ onTrackReady: (track: RCTrack, session?: RCCallSession) => void;
115
+ /**
116
+ * 关闭 或 开启 音频
117
+ */
118
+ onAudioMuteChange: (muteUser: IMuteUser, session: RCCallSession) => void;
119
+ /**
120
+ * 关闭 或 开启 视频
121
+ */
122
+ onVideoMuteChange: (muteUser: IMuteUser, session: RCCallSession) => void;
123
+ /**
124
+ * 资源订阅失败
125
+ */
126
+ onTrackSubscribeFail?: (code: RCRTCCode, session: RCCallSession) => void;
127
+ /**
128
+ * 资源发布失败
129
+ */
130
+ onTrackPublishFail?: (code: RCRTCCode, session: RCCallSession) => void;
131
+ /**
132
+ * 用于接收RTC状态数据报告
133
+ */
134
+ onRTCStateReport?: (report: IRCRTCStateReport, session: RCCallSession) => void;
135
+ /**
136
+ * RTC 每次 Ping 结果
137
+ */
138
+ onPing?: (result: RCRTCPingResult, session: RCCallSession) => void;
139
+ /**
140
+ * ~ICE 连接状态变更通知~
141
+ * @since version 5.1.5
142
+ */
143
+ onICEConnectionStateChange?: (state: RTCIceConnectionState, session: RCCallSession) => void;
144
+ }
145
+ /**
146
+ * 创建session的options
147
+ */
148
+ export interface IRCCallSessionOptions {
149
+ /**
150
+ * 本地资源,用户主动发起会话的时候,会先获得本地资源
151
+ */
152
+ localTracks?: RCLocalTrack[];
153
+ /**
154
+ * 是否允许订阅重试, 默认为false
155
+ */
156
+ isAllowSubscribeRetry?: boolean;
157
+ /**
158
+ * 是否允许发布重试, 默认为false
159
+ */
160
+ isAllowPublishRetry?: boolean;
161
+ /**
162
+ * 禁用视频时关摄像头, 默认false
163
+ */
164
+ isOffCameraWhenVideoDisable?: boolean;
165
+ /**
166
+ * RTC 房间加入类型
167
+ */
168
+ joinType?: RTCJoinType;
169
+ /**
170
+ * 允许降级获得流,获得音视频不成功 ,降级获得音频
171
+ */
172
+ isAllowDemotionGetStream?: boolean;
173
+ /**
174
+ * 产生session的场景,是主叫产生 或 被叫产生
175
+ */
176
+ produceType?: ProduceTypes;
177
+ }
178
+ export interface IRCTrackBitrate {
179
+ /**
180
+ * 最大码率
181
+ */
182
+ max: number;
183
+ /**
184
+ * 最小码率
185
+ */
186
+ min: number;
187
+ /**
188
+ * 上行起始码率
189
+ */
190
+ start?: number;
191
+ }
192
+ /**
193
+ * RCCallClient call方法的传参
194
+ */
195
+ export interface IRCCallParams {
196
+ targetId: string;
197
+ /**
198
+ * 音频 or 音视频, 默认音频
199
+ */
200
+ mediaType: RCCallMediaType;
201
+ /**
202
+ * session上要注册的监听事件
203
+ */
204
+ listener: ISessionListener;
205
+ /**
206
+ * 组织 Id,可选
207
+ */
208
+ channelId?: string;
209
+ /**
210
+ * 用于获取己方媒体资源的参数
211
+ */
212
+ constraints?: {
213
+ video?: ICameraVideoProfile;
214
+ audio: IMicphoneAudioProfile;
215
+ };
216
+ /**
217
+ * 消息的扩展信息
218
+ */
219
+ extra?: string;
220
+ /**
221
+ * 对方显示通知的标题
222
+ */
223
+ pushTitle?: string;
224
+ /**
225
+ * 对方显示的通知内容
226
+ */
227
+ pushContent?: string;
228
+ /**
229
+ * 设置码率
230
+ */
231
+ bitrate?: {
232
+ video?: IRCTrackBitrate;
233
+ audio?: number;
234
+ };
235
+ }
236
+ export interface IMediaStreamConstraints {
237
+ video?: ICameraVideoProfile;
238
+ audio?: IMicphoneAudioProfile;
239
+ }
240
+ export interface IMediaStreamDevice {
241
+ video?: ICameraVideoProfile;
242
+ audio?: IMicphoneAudioProfile;
243
+ }
244
+ /**
245
+ * RCCallClient callInGroup方法的传参
246
+ */
247
+ export interface IRCCallInGroupParams {
248
+ targetId: string;
249
+ userIds: string[];
250
+ mediaType: RCCallMediaType;
251
+ /**
252
+ * session上要注册的监听事件
253
+ */
254
+ listener: ISessionListener;
255
+ /**
256
+ * 组织 Id,可选
257
+ */
258
+ channelId?: string;
259
+ /**
260
+ * 用于获取己方媒体资源的参数
261
+ */
262
+ constraints?: IMediaStreamConstraints;
263
+ /**
264
+ * 消息的扩展信息
265
+ */
266
+ extra?: string;
267
+ /**
268
+ * 对方显示通知的标题
269
+ */
270
+ pushTitle?: string;
271
+ /**
272
+ * 对方显示的通知内容
273
+ */
274
+ pushContent?: string;
275
+ /**
276
+ * 设置码率
277
+ */
278
+ bitrate?: {
279
+ video?: IRCTrackBitrate;
280
+ audio?: number;
281
+ };
282
+ }
283
+ export interface IDevice {
284
+ deviceId: string;
285
+ }
286
+ export interface IDeviceChangeParams {
287
+ audio?: IMicphoneAudioProfile;
288
+ video?: ICameraVideoProfile;
289
+ }
290
+ export interface IValidationResult {
291
+ result: boolean;
292
+ msg?: string;
293
+ }
294
+ //# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1,4 @@
1
+ import { Logger } from '@rongcloud/engine';
2
+ declare const logger: Logger;
3
+ export default logger;
4
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1,12 @@
1
+ export declare class Timer {
2
+ private _timerId;
3
+ private _startTime;
4
+ constructor(callback: Function, timeout: number);
5
+ stop(): {
6
+ startTime: number;
7
+ endTime: number;
8
+ duration: number;
9
+ };
10
+ reset(): void;
11
+ }
12
+ //# sourceMappingURL=timer.d.ts.map
@@ -0,0 +1,9 @@
1
+ declare class EventEmitter {
2
+ private list;
3
+ on(event: string, fun: (data?: any) => void): this;
4
+ once(event: string, fun: (data?: any) => void): void;
5
+ off(event: string, fun?: (data?: any) => void): false | undefined;
6
+ emit(event: string, data?: any): false | undefined;
7
+ }
8
+ export { EventEmitter };
9
+ //# sourceMappingURL=utils.d.ts.map