UNPKG

@rongcloud/plugin-call

Version:

@rongcloud/plugin-call

9 lines 99.6 kB
import{EventEmitter as e,ConversationType as t,ErrorCode as n,isUndefined as r,isBoolean as i,isString as o,LogL as a,VersionManage as s}from"@rongcloud/engine";import{RTCJoinType as l,RCResolution as c,RCKickReason as u,RCRTCCode as d}from"@rongcloud/plugin-rtc";var _=function(e,t){return _=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},_(e,t)};var f=function(){return f=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},f.apply(this,arguments)};function h(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{l(r.next(e))}catch(e){o(e)}}function s(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((r=r.apply(e,t||[])).next())}))}function g(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(l){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(n=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){a.label=s[1];break}if(6===s[0]&&a.label<i[1]){a.label=i[1],i=s;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(s);break}i[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],r=0}finally{n=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}function p(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)a.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return a}function b(e,t,n){if(n||2===arguments.length)for(var r,i=0,o=t.length;i<o;i++)!r&&i in t||(r||(r=Array.prototype.slice.call(t,0,i)),r[i]=t[i]);return e.concat(r||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var C,R,I,E,y=function(){var e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}));return e="".concat(e.replace(/-/g,""),"0"),(e=function(e){var t="0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ+/".split(""),n=t.length+1,r=+e,i=[];do{var o=r%n;r=(r-o)/n,i.unshift(t[o])}while(r);return i.join("")}(e=parseInt(e,16))).length>22&&(e=e.slice(0,22)),e},m=function(){var e=Math.floor(1e3*Math.random()),t=y();return[t=t.replace(/\//g,"0"),Date.now(),e].join("_")},v=new e,O=function(e){var t="RCCallDeviceId",n=e.sessionStorage.getItem(t);return n||(n=y(),e.sessionStorage.setItem(t,n)),n};!function(e){e[e.OUTGOING=1]="OUTGOING",e[e.INCOMING=2]="INCOMING",e[e.RINGING=3]="RINGING",e[e.CONNECTED=4]="CONNECTED",e[e.IDLE=5]="IDLE",e[e.ACCEPTED=6]="ACCEPTED"}(C||(C={})),function(e){e[e.SUCCESS=1e4]="SUCCESS",e[e.STATE_MACHINE_EXIT=53200]="STATE_MACHINE_EXIT",e[e.SEND_MSG_ERROR=53201]="SEND_MSG_ERROR",e[e.REJECTED_BY_BLACKLIST=53202]="REJECTED_BY_BLACKLIST",e[e.NOT_IN_GROUP=53203]="NOT_IN_GROUP",e[e.GET_LOCAL_AUDIO_TRACK_ERROR=53301]="GET_LOCAL_AUDIO_TRACK_ERROR",e[e.GET_LOCAL_VIDEO_TRACK_ERROR=53302]="GET_LOCAL_VIDEO_TRACK_ERROR",e[e.GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR=53303]="GET_LOCAL_AUDIO_AND_VIDEO_TRACK_ERROR",e[e.JOIN_ROOM_ERROR=53304]="JOIN_ROOM_ERROR",e[e.AUDIO_PUBLISH_ERROR=53305]="AUDIO_PUBLISH_ERROR",e[e.VIDEO_PUBLISH_ERROR=53306]="VIDEO_PUBLISH_ERROR",e[e.AUDIO_AND_VIDEO_PUBLISH_ERROR=53307]="AUDIO_AND_VIDEO_PUBLISH_ERROR",e[e.QUERY_JOINED_USER_INFO_ERROR=53308]="QUERY_JOINED_USER_INFO_ERROR",e[e.MISSING_VIDEO_TRACK_ERROR=53309]="MISSING_VIDEO_TRACK_ERROR",e[e.UNPUBLISH_VIDEO_ERROR=53310]="UNPUBLISH_VIDEO_ERROR",e[e.CONVERSATION_NOT_GROUP_ERROR=53311]="CONVERSATION_NOT_GROUP_ERROR",e[e.NOT_IN_ROOM_ERROR=53312]="NOT_IN_ROOM_ERROR",e[e.PARAM_ERROR=53313]="PARAM_ERROR",e[e.MISSING_AUDIO_TRACK_ERROR=53314]="MISSING_AUDIO_TRACK_ERROR",e[e.SESSION_ENDED=53315]="SESSION_ENDED"}(R||(R={})),function(e){e[e.CANCEL=1]="CANCEL",e[e.REJECT=2]="REJECT",e[e.HANGUP=3]="HANGUP",e[e.BUSY_LINE=4]="BUSY_LINE",e[e.NO_RESPONSE=5]="NO_RESPONSE",e[e.ENGINE_UNSUPPORTED=6]="ENGINE_UNSUPPORTED",e[e.NETWORK_ERROR=7]="NETWORK_ERROR",e[e.GET_MEDIA_RESOURCES_ERROR=8]="GET_MEDIA_RESOURCES_ERROR",e[e.PUBLISH_ERROR=9]="PUBLISH_ERROR",e[e.SUBSCRIBE_ERROR=10]="SUBSCRIBE_ERROR",e[e.REMOTE_CANCEL=11]="REMOTE_CANCEL",e[e.REMOTE_REJECT=12]="REMOTE_REJECT",e[e.REMOTE_HANGUP=13]="REMOTE_HANGUP",e[e.REMOTE_BUSY_LINE=14]="REMOTE_BUSY_LINE",e[e.REMOTE_NO_RESPONSE=15]="REMOTE_NO_RESPONSE",e[e.REMOTE_ENGINE_UNSUPPORTED=16]="REMOTE_ENGINE_UNSUPPORTED",e[e.REMOTE_NETWORK_ERROR=17]="REMOTE_NETWORK_ERROR",e[e.REMOTE_GET_MEDIA_RESOURCE_ERROR=18]="REMOTE_GET_MEDIA_RESOURCE_ERROR",e[e.REMOTE_PUBLISH_ERROR=19]="REMOTE_PUBLISH_ERROR",e[e.REMOTE_SUBSCRIBE_ERROR=20]="REMOTE_SUBSCRIBE_ERROR",e[e.OTHER_CLIENT_JOINED_CALL=21]="OTHER_CLIENT_JOINED_CALL",e[e.OTHER_CLIENT_IN_CALL=22]="OTHER_CLIENT_IN_CALL",e[e.KICKED_BY_SERVER=23]="KICKED_BY_SERVER",e[e.ACCEPT_SYSTEM_CALL=24]="ACCEPT_SYSTEM_CALL",e[e.REMOTE_OTHER_CLIENT_JOINED_CALL=31]="REMOTE_OTHER_CLIENT_JOINED_CALL",e[e.REMOTE_OTHER_CLIENT_IN_CALL=32]="REMOTE_OTHER_CLIENT_IN_CALL",e[e.REMOTE_KICKED_BY_SERVER=33]="REMOTE_KICKED_BY_SERVER",e[e.REMOTE_ACCEPT_SYSTEM_CALL=34]="REMOTE_ACCEPT_SYSTEM_CALL",e[e.ACCEPT_BY_OTHER_CLIENT=101]="ACCEPT_BY_OTHER_CLIENT",e[e.HANGUP_BY_OTHER_CLIENT=102]="HANGUP_BY_OTHER_CLIENT",e[e.ADDED_TO_BLACKLIST=103]="ADDED_TO_BLACKLIST",e[e.SERVICE_NOT_OPENED=104]="SERVICE_NOT_OPENED"}(E||(E={}));var T,S,M,P,w=((I={})[E.CANCEL]=E.REMOTE_CANCEL,I[E.REJECT]=E.REMOTE_REJECT,I[E.HANGUP]=E.REMOTE_HANGUP,I[E.BUSY_LINE]=E.REMOTE_BUSY_LINE,I[E.NO_RESPONSE]=E.REMOTE_NO_RESPONSE,I[E.ENGINE_UNSUPPORTED]=E.REMOTE_ENGINE_UNSUPPORTED,I[E.NETWORK_ERROR]=E.REMOTE_NETWORK_ERROR,I[E.GET_MEDIA_RESOURCES_ERROR]=E.REMOTE_GET_MEDIA_RESOURCE_ERROR,I[E.PUBLISH_ERROR]=E.REMOTE_PUBLISH_ERROR,I[E.SUBSCRIBE_ERROR]=E.REMOTE_SUBSCRIBE_ERROR,I[E.OTHER_CLIENT_JOINED_CALL]=E.REMOTE_OTHER_CLIENT_JOINED_CALL,I[E.OTHER_CLIENT_IN_CALL]=E.REMOTE_OTHER_CLIENT_IN_CALL,I[E.KICKED_BY_SERVER]=E.REMOTE_KICKED_BY_SERVER,I[E.REMOTE_NO_RESPONSE]=E.NO_RESPONSE,I[E.ACCEPT_SYSTEM_CALL]=E.REMOTE_ACCEPT_SYSTEM_CALL,I);!function(e){e.VCInvite="RC:VCInvite",e.VCRinging="RC:VCRinging",e.VCAccept="RC:VCAccept",e.VCHangup="RC:VCHangup",e.VCModifyMem="RC:VCModifyMem",e.VCModifyMedia="RC:VCModifyMedia"}(T||(T={})),function(e){e[e.WAITING=0]="WAITING",e[e.KEEPING=1]="KEEPING",e[e.END=2]="END"}(S||(S={})),function(e){e[e.NONE=0]="NONE",e[e.WAITING=1]="WAITING",e[e.KEEPING=2]="KEEPING"}(M||(M={})),function(e){ /*! 同App通话 */ e[e.RCCallRoomTypeNormalCall=0]="RCCallRoomTypeNormalCall", /*! 跨App通话 */ e[e.RCCallRoomTypeAcrossCall=7]="RCCallRoomTypeAcrossCall"}(P||(P={}));var N,A,U,L=function(){function e(e,t){Object.defineProperty(this,"_timerId",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_startTime",{enumerable:!0,configurable:!0,writable:!0,value:0}),e&&(this._timerId=function(e,t){return setTimeout(e,t)}((function(){e()}),t)),this._startTime=Date.now()}return Object.defineProperty(e.prototype,"stop",{enumerable:!1,configurable:!0,writable:!0,value:function(){clearTimeout(this._timerId);var e=Date.now(),t=e-this._startTime;return 0===this._startTime&&(t=0),{startTime:this._startTime,endTime:e,duration:t}}}),Object.defineProperty(e.prototype,"reset",{enumerable:!1,configurable:!0,writable:!0,value:function(){this._startTime=0}}),e}(),j=function(){function e(e,t,n,r,i,o,a,s,l){Object.defineProperty(this,"_context",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"_runtime",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"_logger",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"_callMsgHandler",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"_channelId",{enumerable:!0,configurable:!0,writable:!0,value:i}),Object.defineProperty(this,"_conversationType",{enumerable:!0,configurable:!0,writable:!0,value:o}),Object.defineProperty(this,"_targetId",{enumerable:!0,configurable:!0,writable:!0,value:a}),Object.defineProperty(this,"_mediaType",{enumerable:!0,configurable:!0,writable:!0,value:s}),Object.defineProperty(this,"_callId",{enumerable:!0,configurable:!0,writable:!0,value:l}),Object.defineProperty(this,"_sessionState",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_userInfo",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(this,"_userTimers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(this,"_watchers",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_callTimeout",{enumerable:!0,configurable:!0,writable:!0,value:6e4}),Object.defineProperty(this,"_beginTimestamp",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_endTimestamp",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_endReason",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_callerId",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_inviterId",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_isCrossAppkey",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_hungupPushConfig",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._callMsgHandler.registerStateMachineEvent(this._callId,"onRinging",this._onRinging.bind(this)),this._callMsgHandler.registerStateMachineEvent(this._callId,"onAccept",this._onAccept.bind(this)),this._callMsgHandler.registerStateMachineEvent(this._callId,"onMediaModify",this._onMediaModify.bind(this)),this._callMsgHandler.registerStateMachineEvent(this._callId,"onHungup",this._onHungup.bind(this))}return Object.defineProperty(e.prototype,"_getTimeout",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this._context.getServerTime()-e;t<0&&(t=500);var n=this._callTimeout-t;return this._logger.warn("_","_getTimeout -> timeout: ".concat(n)),n}}),Object.defineProperty(e.prototype,"_clearTimerById",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._logger.debug("_","[RCCallStateMachine] before _clearTimerById -> userId: ".concat(e," userTimers: ").concat(JSON.stringify(this._userTimers))),this._userTimers[e]&&(this._userTimers[e].stop(),delete this._userTimers[e]),this._logger.debug("_","[RCCallStateMachine] after _clearTimerById -> userTimers: ".concat(JSON.stringify(this._userTimers)))}}),Object.defineProperty(e.prototype,"_notifyStateChange",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n;this._logger.warn("_","[RCCallStateMachine] notifyStateChange -> info: ".concat(JSON.stringify({state:e,reason:t}))),this._endReason=t||null,this._sessionState!==e&&(this._sessionState=e,null===(n=this._watchers)||void 0===n||n.onStateChange({state:e,reason:t})),e===S.END&&(v.emit("onStateMachineClose",this._callId),this._callMsgHandler.unregisterStateMachineEvent(this._callId))}}),Object.defineProperty(e.prototype,"_notifyUserStateChange",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n;this._logger.warn("_","[RCCallStateMachine] notifyUserStateChange -> info: ".concat(JSON.stringify({user:e,reason:t}))),null===(n=this._watchers)||void 0===n||n.onUserStateChange({user:e,reason:t})}}),Object.defineProperty(e.prototype,"_otherClientHandle",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e.senderUserId,n=e.content,r=n.user,i=n.reason,o=e.messageType;for(var a in this._userInfo[t]={userId:t,state:M.NONE,isCaller:!1,isRemote:!1},this._userTimers)this._clearTimerById(a);var s=E.ACCEPT_BY_OTHER_CLIENT;o===T.VCHangup&&(s=i===E.BUSY_LINE?E.OTHER_CLIENT_IN_CALL:i===E.NO_RESPONSE?E.NO_RESPONSE:E.HANGUP_BY_OTHER_CLIENT),Object.assign(this._userInfo[t],r),this._notifyUserStateChange(this._userInfo[t],s),this._notifyStateChange(S.END,s)}}),Object.defineProperty(e.prototype,"_isRemoteInvalidMsg",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return!!this._userInfo[e]&&(!(!this._userInfo[e].deviceId||!t)&&(this._userInfo[e].state===M.KEEPING&&this._userInfo[e].deviceId!==t))}}),Object.defineProperty(e.prototype,"_onRinging",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e.senderUserId,n=e.content,r=n.user,i=n.deviceId,o=this._isCrossAppkey?t.split("_")[1]:t;this._isRemoteInvalidMsg(o,i)?this._logger.debug("_","[RCCallStateMachine] onRinging -> not the remote device that is currently talking"):this._context.getCurrentId()!==o&&this._watchers.onRinging(f({userId:o},r))}}),Object.defineProperty(e.prototype,"_onAccept",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var n=this,r=e.senderUserId,i=e.content,o=i.user,a=i.deviceId;e.sentTime;var s=this._isCrossAppkey?r.split("_")[1]:r,l=this._context.getCurrentId();this._isRemoteInvalidMsg(s,a)?this._logger.debug("_","[RCCallStateMachine] _onAccept -> not the remote device that is currently talking"):l!==s?(this._userTimers[s]&&this._clearTimerById(s),(this._conversationType===t.PRIVATE?[l,s]:[s]).forEach((function(e){var t=e===l;n._userInfo[e]={userId:e,state:M.KEEPING,isCaller:t,isRemote:t,deviceId:t?O(n._runtime):a},t||(n._beginTimestamp=Date.now(),Object.assign(n._userInfo[s],o)),n._notifyUserStateChange(n._userInfo[e])})),this.getCallerId()===l&&this._notifyStateChange(S.KEEPING),this._watchers.onAccept({userId:s})):this._otherClientHandle(e)}}),Object.defineProperty(e.prototype,"_onMediaModify",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e.senderUserId,n=e.content,r=n.mediaType,i=n.user,o=n.deviceId;this._isRemoteInvalidMsg(t,o)?this._logger.debug("_","[RCCallStateMachine] _onMediaModify -> not the remote device that is currently talking"):this._context.getCurrentId()!==t&&(this._mediaType=r,this._watchers.onMediaModify({sender:f({userId:t},i),mediaType:r}))}}),Object.defineProperty(e.prototype,"_onHungup",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e.senderUserId,n=e.content,r=this._isCrossAppkey?t.split("_")[1]:t,i=n,o=i.reason,a=i.user,s=i.deviceId,l=this._context.getCurrentId();if(this._isRemoteInvalidMsg(r,s))this._logger.debug("_","[RCCallStateMachine] _onHungup -> not the remote device that is currently talking");else if(l!==r)if(this._sessionState!==S.END){this._userInfo[r]&&(this._userInfo[r].state=M.NONE,this._endTimestamp=Date.now(),Object.assign(this._userInfo[r],a),this._notifyUserStateChange(this._userInfo[r],w[o]),delete this._userInfo[r]),w[o]===E.REMOTE_CANCEL?this.getRemoteUserIds().length<1&&this._clearTimerById(l):this.getInviterId()===l?this._clearTimerById(r):this.getRemoteUserIds().length<1&&this._clearTimerById(l);var c=Object.keys(this._userInfo).length<2,u=this._inviterId===r,d=Object.values(this._userInfo).every((function(e){return e.state!==M.KEEPING}));(c||u&&d)&&this._notifyStateChange(S.END,w[o]),this._watchers.onHungup(f({userId:r},a),w[o])}else this._logger.info("_","[RCCallStateMachine] Invalid hang up message, current room status has ended -> sessionState: ".concat(this._sessionState));else this._otherClientHandle(e)}}),Object.defineProperty(e.prototype,"registerEventListener",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._watchers=e}}),Object.defineProperty(e.prototype,"__onInvite",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t,n,r=this,i=e.senderUserId,o=e.content,a=e.sentTime,s=o,l=s.inviteUserIds,c=s.user,u=s.deviceId;s.roomType===P.RCCallRoomTypeAcrossCall?(t=p(i.split("_"),2),n=t[1],this._watchers.crossAppkey(!0),this._isCrossAppkey=!0):n=i;var d=this._context.getCurrentId();if(this._isRemoteInvalidMsg(n,u))this._logger.debug("_","[RCCallStateMachine] __onInvite -> not the remote device that is currently talking");else if(d!==n){this._callerId=this._inviterId=n;var _=b([i],p(l),!1);this._callMsgHandler.sendRinging({conversationType:this._conversationType,targetId:this._targetId,channelId:this._channelId,callId:this._callId,userIds:_.filter((function(e){return r._isCrossAppkey?e.split("_")[1]!==d:e!==d}))});var f=this._isCrossAppkey?[l[0].split("_")[1]]:l;b([n],p(f),!1).forEach((function(e){r._userInfo[e]={userId:e,state:M.WAITING,isCaller:e===n,isRemote:e!==d},e===n&&Object.assign(r._userInfo[e],c,{deviceId:u}),r._notifyUserStateChange(r._userInfo[e]),e!==n&&(r._userTimers[e]=new L((function(){var t=e===d?E.NO_RESPONSE:E.REMOTE_NO_RESPONSE;e===d?r._hungupHandle(t,!1):(r._userInfo[e]&&(r._userInfo[e].state=M.NONE),r._notifyUserStateChange(r._userInfo[e]),r._watchers.onHungup(r._userInfo[e],t),delete r._userInfo[e]),r._clearTimerById(e)}),r._getTimeout(a)))})),this._notifyStateChange(S.WAITING)}}}),Object.defineProperty(e.prototype,"__onMemberModify",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this,n=e.senderUserId,r=e.content,i=e.sentTime,o=r,a=o.user,s=o.existedUserPofiles,l=o.caller,c=o.deviceId,u=o.inviteUserIds,d=o.mediaType,_=this._context.getCurrentId();if(this._isRemoteInvalidMsg(n,c))this._logger.debug("_","[RCCallStateMachine] __onMemberModify -> not the remote device that is currently talking");else if(_!==n){if(this._callerId=l,this._inviterId=n,u.forEach((function(e){s.push({userId:e,mediaType:d,callStatus:C.INCOMING})})),u.includes(_)){var h=[];s.forEach((function(e){e.userId!==_&&h.push(e.userId)})),this._callMsgHandler.sendRinging({conversationType:this._conversationType,targetId:this._targetId,channelId:this._channelId,callId:this._callId,userIds:h}),this._notifyStateChange(S.WAITING)}else this._watchers.onMemberModify({sender:f({userId:n},a),invitedUsers:u.map((function(e){return{userId:e}}))});s.forEach((function(e){var r=e.userId,o=e.callStatus;if(o!==C.IDLE&&(t._userInfo[r]={userId:r,state:o!==C.CONNECTED?M.WAITING:M.KEEPING,isCaller:n===r,isRemote:_!==r},r===n&&Object.assign(t._userInfo[r],a,{deviceId:c}),t._notifyUserStateChange(t._userInfo[r]),o!==C.CONNECTED&&!t._userTimers[r])){if(!u.includes(r))return;t._userTimers[r]=new L((function(){t._userInfo[r]&&(t._userInfo[r].state=M.NONE);var e=r===_?E.NO_RESPONSE:E.REMOTE_NO_RESPONSE;t._notifyUserStateChange(t._userInfo[r],e);try{t._watchers.onHungup(t._userInfo[r],e)}catch(e){t._logger.error("_","[RCCallStateMachine] call onhungup error -> ".concat(null==e?void 0:e.stack))}delete t._userInfo[r],(Object.keys(t._userInfo).length<2||r===_)&&t._notifyStateChange(S.END,e),t._clearTimerById(r)}),t._getTimeout(i))}}))}}}),Object.defineProperty(e.prototype,"__handleInviteInSession",{enumerable:!1,configurable:!0,writable:!0,value:function(){for(var e in this._logger.info("_","StateMachine -> __handleInviteInSession"),this._userInfo)this._userInfo[e].state&&(this._userInfo[e].state=M.NONE),this._notifyUserStateChange(this._userInfo[e]),this._clearTimerById(e);this._notifyStateChange(S.END,E.BUSY_LINE),this._callMsgHandler.sendHungup({channelId:this._channelId,conversationType:this._conversationType,targetId:this._targetId,callId:this._callId,reason:E.BUSY_LINE,userIds:this.getRemoteUserIds()})}}),Object.defineProperty(e.prototype,"__call",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){return void 0===t&&(t=""),void 0===r&&(r=!1),h(this,void 0,void 0,(function(){var i,o,a,s,l,c,u=this;return g(this,(function(d){switch(d.label){case 0:return this._logger.debug("_","[RCCallStateMachine] invite -> userIds: ".concat(JSON.stringify(e))),i=this._callerId=this._inviterId=this._context.getCurrentId(),[4,this._callMsgHandler.sendInvite({roomType:r?P.RCCallRoomTypeAcrossCall:P.RCCallRoomTypeNormalCall,channelId:this._channelId,conversationType:this._conversationType,targetId:this._targetId,callId:this._callId,extra:t,pushConfig:n,mediaType:this._mediaType,inviteUserIds:e.filter((function(e){return e!==i}))})];case 1:return o=d.sent(),a=o.code,s=o.message,this._isCrossAppkey=r,a===R.SUCCESS?(l=s.sentTime,b([i],r?[e[0].split("_")[1]]:p(e),!1).forEach((function(e){var t=e===i;u._userInfo[e]={userId:e,state:M.WAITING,isCaller:t,isRemote:!t},u._notifyUserStateChange(u._userInfo[e]),t||(u._userTimers[e]=new L((function(){u._userInfo[e]&&(u._userInfo[e].state=M.NONE),u._notifyUserStateChange(u._userInfo[e],E.REMOTE_NO_RESPONSE),u._watchers.onHungup(u._userInfo[e],E.REMOTE_NO_RESPONSE),delete u._userInfo[e],Object.keys(u._userInfo).length<2&&u._notifyStateChange(S.END,E.REMOTE_NO_RESPONSE),0===u.getRemoteUserIds().length&&u._userInfo[i].state!==M.KEEPING&&u._hungupHandle(E.REMOTE_NO_RESPONSE)}),u._getTimeout(l)))})),this._notifyStateChange(S.WAITING)):(c=a===R.REJECTED_BY_BLACKLIST?E.ADDED_TO_BLACKLIST:E.NETWORK_ERROR,this._notifyStateChange(S.END,c)),[2,{code:a}]}}))}))}}),Object.defineProperty(e.prototype,"accept",{enumerable:!1,configurable:!0,writable:!0,value:function(){return h(this,void 0,void 0,(function(){var e,t,n,r,i;return g(this,(function(o){switch(o.label){case 0:return this._logger.debug("_","[RCCallStateMachine] accept"),e=this._context.getCurrentId(),[4,this._callMsgHandler.sendAccept({channelId:this._channelId,conversationType:this._conversationType,targetId:this._targetId,callId:this._callId,mediaType:this._mediaType,userIds:this.getRemoteUserIds()})];case 1:return t=o.sent(),n=t.code,r=t.message,this._clearTimerById(e),n===R.SUCCESS?(r.sentTime,this._userInfo[e]&&(this._userInfo[e].state=M.KEEPING),this._beginTimestamp=Date.now(),this._notifyUserStateChange(this._userInfo[e]),this._notifyStateChange(S.KEEPING)):(this._userInfo[e]&&(this._userInfo[e].state=M.NONE),this._notifyUserStateChange(this._userInfo[e]),i=n===R.REJECTED_BY_BLACKLIST?E.ADDED_TO_BLACKLIST:E.NETWORK_ERROR,this._notifyStateChange(S.END,i)),[2,{code:n}]}}))}))}}),Object.defineProperty(e.prototype,"invite",{enumerable:!1,configurable:!0,writable:!0,value:function(e,n){return void 0===n&&(n={}),h(this,void 0,void 0,(function(){var r,i,o,a,s,l,c,u,d,_,f,h=this;return g(this,(function(g){switch(g.label){case 0:return this._conversationType!==t.GROUP?[2,{code:R.CONVERSATION_NOT_GROUP_ERROR}]:(this._logger.info("_","[RCCallStateMachine] invite -> userIds: ".concat(JSON.stringify(e))),r=this._context.getCurrentId(),i=Object.keys(this._userInfo),0===(o=e.filter((function(e){return e!==r&&!i.includes(e)}))).length?(this._logger.warn("_","[RCCallStateMachine] invite -> all userId is in calling now!"),[2,{code:R.PARAM_ERROR}]):(a=i.map((function(e){var t=C.CONNECTED;return h._userInfo[e].state===M.WAITING&&(t=C.RINGING),{userId:e,mediaType:h._mediaType,callStatus:t,mediaId:e}})),s=n.extra,l=void 0===s?"":s,c=n.pushConfig,[4,this._callMsgHandler.sendMemeberModify({channelId:this._channelId,conversationType:this._conversationType,targetId:this._targetId,callId:this._callId,extra:l,pushConfig:c,mediaType:this._mediaType,inviteUserIds:o,callerId:this.getCallerId(),existedUserPofiles:a,directionalUserIdList:b(b([],p(i),!1),p(o),!1).filter((function(e){return e!==r}))})]));case 1:return u=g.sent(),d=u.code,_=u.message,d===R.SUCCESS?(f=_.sentTime,o.forEach((function(e){h._userInfo[e]={userId:e,state:M.WAITING,isCaller:!1,isRemote:!0},h._notifyUserStateChange(h._userInfo[e]),h._userTimers[e]=new L((function(){h._userInfo[e]&&(h._userInfo[e].state=M.NONE),h._notifyUserStateChange(h._userInfo[e],E.REMOTE_NO_RESPONSE),h._watchers.onHungup(h._userInfo[e],E.REMOTE_NO_RESPONSE),delete h._userInfo[e],Object.keys(h._userInfo).length<2&&h._notifyStateChange(S.END,E.REMOTE_NO_RESPONSE)}),h._getTimeout(f))}))):o.forEach((function(e){h._userInfo[e]={userId:e,state:M.NONE,isCaller:!1,isRemote:!0};var t=d===R.REJECTED_BY_BLACKLIST?E.ADDED_TO_BLACKLIST:E.NETWORK_ERROR;h._notifyUserStateChange(h._userInfo[e],t)})),[2,{code:d}]}}))}))}}),Object.defineProperty(e.prototype,"_hungupHandle",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return void 0===t&&(t=!0),h(this,void 0,void 0,(function(){var n,r,i,o,a;return g(this,(function(s){switch(s.label){case 0:return n=this._context.getCurrentId(),r=R.SUCCESS,t?(i={channelId:this._channelId,conversationType:this._conversationType,targetId:this._targetId,callId:this._callId,reason:e,userIds:this.getRemoteUserIds(),pushConfig:f({},this._hungupPushConfig)},e!==E.OTHER_CLIENT_JOINED_CALL?[3,1]:(this._callMsgHandler.sendHungup(i),[3,3])):[3,3];case 1:return[4,this._callMsgHandler.sendHungup(i)];case 2:o=s.sent().code,r=o,s.label=3;case 3:for(a in this._endTimestamp=Date.now(),this._userInfo)this._userInfo[a].state=M.NONE,a===n?this._notifyUserStateChange(this._userInfo[a],e):this._notifyUserStateChange(this._userInfo[a]),delete this._userInfo[a];return Object.keys(this._userInfo).length<2&&this._notifyStateChange(S.END,e),[2,{code:r}]}}))}))}}),Object.defineProperty(e.prototype,"hungup",{enumerable:!1,configurable:!0,writable:!0,value:function(){return h(this,void 0,void 0,(function(){var e,t,n;return g(this,(function(r){for(n in this._logger.debug("_","[RCCallStateMachine] hungup"),e=this._context.getCurrentId(),t=E.HANGUP,Object.keys(this._userTimers).length>0&&(this._userInfo[e].isCaller?t=E.CANCEL:this._userInfo[e].state===M.WAITING&&(t=E.REJECT)),this._userTimers)this._clearTimerById(n);return[2,this._hungupHandle(t)]}))}))}}),Object.defineProperty(e.prototype,"changeMediaType",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return h(this,void 0,void 0,(function(){var t;return g(this,(function(n){switch(n.label){case 0:return this._logger.debug("_","[RCCallStateMachine] changeMediaType -> mediaType: ".concat(e)),[4,this._callMsgHandler.sendMediaModify({channelId:this._channelId,conversationType:this._conversationType,targetId:this._targetId,callId:this._callId,mediaType:e,userIds:this.getRemoteUserIds()})];case 1:return(t=n.sent().code)===R.SUCCESS&&(this._mediaType=e),[2,{code:t}]}}))}))}}),Object.defineProperty(e.prototype,"userJoin",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;this._logger.debug("_","[RCCallStateMachine] userJoin -> userIds: ".concat(JSON.stringify(e))),setTimeout((function(){e.forEach((function(e){var n=t._userInfo[e];n&&n.state!==M.KEEPING&&(n.state=M.KEEPING,t._notifyUserStateChange(n)),t._sessionState!==S.KEEPING&&t._notifyStateChange(S.KEEPING),t._clearTimerById(e)}))}),300)}}),Object.defineProperty(e.prototype,"userLeave",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;this._logger.debug("_","[RCCallStateMachine] userLeave -> userIds: ".concat(JSON.stringify(e))),setTimeout((function(){e.forEach((function(e){var n=t._userInfo[e];n&&n.state!==M.NONE&&(n.state=M.NONE,t._notifyUserStateChange(n,E.REMOTE_HANGUP),t._watchers.onHungup(n,E.REMOTE_HANGUP),delete t._userInfo[e]),new L((function(){var e=t.getRemoteUsers();1===e.length&&1===e[0].state&&t._hungupHandle(E.REMOTE_NETWORK_ERROR)}),6e4),Object.keys(t._userInfo).length<2&&t._sessionState!==S.END&&(t._endTimestamp=Date.now(),t._notifyStateChange(S.END,E.REMOTE_HANGUP))}))}),300)}}),Object.defineProperty(e.prototype,"userOffline",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;this._logger.debug("_","[RCCallStateMachine] userOffline -> userIds: ".concat(JSON.stringify(e))),e.forEach((function(e){var n=t._userInfo[e];n&&n.state!==M.NONE&&(n.state=M.NONE,t._notifyUserStateChange(n,E.REMOTE_NETWORK_ERROR),t._watchers.onHungup(n,E.REMOTE_NETWORK_ERROR),delete t._userInfo[e]),Object.keys(t._userInfo).length<2&&t._sessionState!==S.END&&(t._endTimestamp=Date.now(),t._notifyStateChange(S.END,E.REMOTE_NETWORK_ERROR))}))}}),Object.defineProperty(e.prototype,"close",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._hungupHandle(e)}}),Object.defineProperty(e.prototype,"setHungupPushConfig",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._hungupPushConfig=e}}),Object.defineProperty(e.prototype,"getCallId",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._callId}}),Object.defineProperty(e.prototype,"getChannelId",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._channelId}}),Object.defineProperty(e.prototype,"getTargetId",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._targetId}}),Object.defineProperty(e.prototype,"getConversationType",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._conversationType}}),Object.defineProperty(e.prototype,"getRemoteUserIds",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;return Object.keys(this._userInfo).filter((function(t){return e._context.getCurrentId()!==t}))}}),Object.defineProperty(e.prototype,"getRemoteUsers",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=[],t=this._context.getCurrentId();for(var n in this._userInfo){this._userInfo[n].userId!==t&&e.push(this._userInfo[n])}return e}}),Object.defineProperty(e.prototype,"getState",{enumerable:!1,configurable:!0,writable:!0,value:function(){return null===this._sessionState?S.END:this._sessionState}}),Object.defineProperty(e.prototype,"getUserState",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t;return null===(t=this._userInfo[e])||void 0===t?void 0:t.state}}),Object.defineProperty(e.prototype,"getCallerId",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._callerId}}),Object.defineProperty(e.prototype,"getInviterId",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._inviterId}}),Object.defineProperty(e.prototype,"getMediaType",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._mediaType}}),Object.defineProperty(e.prototype,"getSummary",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this._beginTimestamp,t=this._endTimestamp,n=0;t>e&&0!==e&&(n=t-e);var r={conversationType:this._conversationType,channelId:this._channelId,targetId:this._targetId,mediaType:this._mediaType,beginTimestamp:e,endTimestamp:t,duration:n,endReason:this._endReason};return this._logger.debug("_","[RCCallStateMachine] getSummary -> summary: ".concat(JSON.stringify(r))),r}}),e}();!function(e){e[e.AUDIO=1]="AUDIO",e[e.AUDIO_VIDEO=2]="AUDIO_VIDEO"}(N||(N={})),function(e){e[e.ADD=1]="ADD",e[e.REMOVE=2]="REMOVE"}(A||(A={})),function(e){e.WEB="Web",e.IOS="iOS",e.ANDROID="Android"}(U||(U={}));var k,D,H=function(){function e(e,t,n){Object.defineProperty(this,"_context",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"_logger",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"_onRecord",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"_messages",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_channelId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_conversationType",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_targetId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_mediaType",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_callId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_callerId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_inviterId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_endReason",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_beginTimestamp",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_endTimestamp",{enumerable:!0,configurable:!0,writable:!0,value:0})}return Object.defineProperty(e.prototype,"_doInvite",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._context.getCurrentId();var t=e.channelId,n=e.conversationType,r=e.targetId,i=e.senderUserId,o=e.content,a=o.callId,s=o.mediaType;this._channelId=t,this._conversationType=n,this._targetId=r,this._callId=a,this._mediaType=s;this._inviterId=i,this._endReason=E.REMOTE_NO_RESPONSE,this._canGenRecord()}}),Object.defineProperty(e.prototype,"_doMemberModify",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._doInvite(e)}}),Object.defineProperty(e.prototype,"_doRinging",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._canGenRecord()}}),Object.defineProperty(e.prototype,"_doAccept",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._endReason=E.HANGUP,this._beginTimestamp=e.sentTime,this._canGenRecord()}}),Object.defineProperty(e.prototype,"_doHungup",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e.content,n=e.sentTime,r=e.senderUserId,i=t.reason,o=r===this._context.getCurrentId();this._endReason=o?i:w[i],this._endTimestamp=n,this._canGenRecord()}}),Object.defineProperty(e.prototype,"_doMediaModify",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e.content.mediaType;this._mediaType=t,this._canGenRecord()}}),Object.defineProperty(e.prototype,"_canGenRecord",{enumerable:!1,configurable:!0,writable:!0,value:function(){if(0===this._messages.length){var e=0;[E.HANGUP,E.REMOTE_HANGUP,E.OTHER_CLIENT_JOINED_CALL,E.REMOTE_OTHER_CLIENT_JOINED_CALL,E.KICKED_BY_SERVER,E.REMOTE_KICKED_BY_SERVER,E.ACCEPT_SYSTEM_CALL,E.REMOTE_ACCEPT_SYSTEM_CALL].includes(this._endReason)&&(e=this._endTimestamp-this._beginTimestamp),this._onRecord({channelId:this._channelId,conversationType:this._conversationType,targetId:this._targetId,callId:this._callId,inviterId:this._inviterId,mediaType:this._mediaType,endReason:this._endReason,beginTimestamp:this._beginTimestamp,endTimestamp:this._endTimestamp,duration:e})}}}),Object.defineProperty(e.prototype,"onRecvOfflineMsgs",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._messages=e;do{var t=this._messages.shift(),n=t.messageType;switch(t.content.callId,n){case T.VCInvite:this._doInvite(t);break;case T.VCRinging:this._doRinging(t);break;case T.VCAccept:this._doAccept(t);break;case T.VCModifyMem:this._doMemberModify(t);break;case T.VCModifyMedia:this._doMediaModify(t);break;case T.VCHangup:this._doHungup(t);break;default:this._logger.debug("_","[OfflineRecorder] onRecvOfflineMsgs -> unexpected message: ".concat(JSON.stringify(t)))}}while(this._messages.length>0)}}),e}(),V=["RC:VCAccept","RC:VCRinging","RC:VCSummary","RC:VCHangup","RC:VCInvite","RC:VCModifyMedia","RC:VCModifyMem"],G=((k={})[n.REJECTED_BY_BLACKLIST]=R.REJECTED_BY_BLACKLIST,k[n.NOT_IN_GROUP]=R.NOT_IN_GROUP,k),x=function(e){function r(t,n,r,i,o){void 0===i&&(i=6e4);var a=e.call(this)||this;return Object.defineProperty(a,"_context",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(a,"_runtime",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(a,"_logger",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(a,"_offlineMsgItv",{enumerable:!0,configurable:!0,writable:!0,value:i}),Object.defineProperty(a,"_getStateMachine",{enumerable:!0,configurable:!0,writable:!0,value:o}),Object.defineProperty(a,"_watchers",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(a,"_userInfo",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(a,"_msgBufferList",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(a,"_hadHandleMsgTimer",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(a,"_offlineRecorder",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(a,"_deviceId",{enumerable:!0,configurable:!0,writable:!0,value:""}),a._deviceId=O(n),a._context.onmessage=a._onMessage.bind(a),a._offlineRecorder=new H(a._context,a._logger,(function(e){a._logger.info("_","[CallMessageHandler] offlineRecorder -> ".concat(JSON.stringify(e))),a._watchers.onOfflineRecord&&a._watchers.onOfflineRecord(e)})),a}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}_(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(r,e),Object.defineProperty(r.prototype,"_onMessage",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(V.includes(e.messageType)){this._logger.debug("_","[CallMessageHandler] _onMessage -> call message: ".concat(JSON.stringify(e)));try{var t=Date.now(),n=e.sentTime,r=0;this._msgBufferList.forEach((function(e,t){var i=e.msg.sentTime;n>=i&&(r=t+1)})),this._msgBufferList.splice(r,0,{markTime:t,msg:e}),this._logger.warn("_","onMessage -> msgBufferList: ".concat(this._msgBufferList.length))}catch(e){this._logger.error("_","[CallMessageHandler] splice buffer msg error -> ".concat(e.message))}return this._handleBufferMsgs(),!0}return!1}}),Object.defineProperty(r.prototype,"_onRecvOnlineCallMsg",{enumerable:!1,configurable:!0,writable:!0,value:function(t){var n=t.content.callId;switch(this._logger.info("_","recv -> senderId: ".concat(t.senderUserId,", type: ").concat(t.messageType,", callId: ").concat(n)),t.messageType){case T.VCInvite:this._watchers.onInvite&&this._watchers.onInvite(t);break;case T.VCRinging:e.prototype.emit.call(this,"".concat(n,"onRinging"),t);break;case T.VCAccept:e.prototype.emit.call(this,"".concat(n,"onAccept"),t);break;case T.VCModifyMem:this._watchers.onInvite&&this._watchers.onInvite(t);break;case T.VCModifyMedia:e.prototype.emit.call(this,"".concat(n,"onMediaModify"),t);break;case T.VCHangup:e.prototype.emit.call(this,"".concat(n,"onHungup"),t);break;default:this._logger.warn("_","recv -> unexpected message: ".concat(t.messageType))}}}),Object.defineProperty(r.prototype,"_handleBufferMsgs",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;0===this._msgBufferList.length||this._hadHandleMsgTimer?this._logger.warn("_","_handleBufferMsgs return"):(this._hadHandleMsgTimer=!0,setTimeout((function(){var n=Date.now(),r=e._msgBufferList.filter((function(e){return n-e.markTime>=200}));if(e._logger.debug("_","[CallMessageHandler] handleBufferMsgs -> lists over 200ms : ".concat(JSON.stringify(r.map((function(e){var t=e.msg;return{messageUId:t.messageUId,isOffLineMessage:t.isOffLineMessage,callId:t.content.callId}}))))),0===r.length)return e._hadHandleMsgTimer=!1,void e._handleBufferMsgs();if(r[0].msg.isOffLineMessage){var i=e._msgBufferList.filter((function(e){return e.msg.isOffLineMessage})),o=function(){var n=i[0].msg,r=n.conversationType,o=n.messageType,a=n.sentTime,s=n.senderUserId,l=n.content,c=l.callId,u=l.inviteUserIds,d=[T.VCInvite,T.VCModifyMem].includes(o),_=e._context.getServerTime()-a,f=_<e._offlineMsgItv;if(f||e._logger.warn("_","offline msg delayTime: ".concat(_,"ms")),d){for(var h=[],g=0;g<i.length;g++){var C=i[g].msg;if(c!==C.content.callId)break;h.push(C)}if(e._logger.warn("_","taskMsgList length: ".concat(h.length)),h.length>0){var R=e._msgBufferList.findIndex((function(e){return e.msg.messageUId===h[h.length-1].messageUId}));e._msgBufferList=e._msgBufferList.slice(R+1);var I=i.findIndex((function(e){return e.msg.messageUId===h[h.length-1].messageUId}));i=i.slice(I+1)}var E=function(){if(r!==t.PRIVATE)return!1;var e=1===h.length,n=h.every((function(e){return[T.VCInvite,T.VCModifyMedia,T.VCRinging].includes(e.messageType)}));return e||n}(),y=function(){if(r!==t.GROUP)return!1;for(var n=!1,i=!0,o=b([s],p(u),!1),a=!1,l=function(t){var n=h[t],r=n.senderUserId,l=n.messageType;if(l===T.VCHangup&&r===e._context.getCurrentId())return"break";l===T.VCHangup&&(a=s===r,o=o.filter((function(e){return r!==e}))),l===T.VCAccept&&(i=!1)},c=0;c<h.length;c++){if("break"===l(c))break}return i&&a||!(o.length>1)||(n=!0),n}();f&&(E||y)&&h.forEach(e._onRecvOnlineCallMsg,e),e._offlineRecorder.onRecvOfflineMsgs(h)}else f&&e._getStateMachine(c)?e._onRecvOnlineCallMsg(i[0].msg):e._logger.debug("_","[CallMessageHandler] unexcepted offline msg -> ".concat(JSON.stringify(i[0].msg))),i.shift(),e._msgBufferList.shift()};do{o()}while(i.length>0)}else{r.forEach((function(t){var n=t.msg;e._onRecvOnlineCallMsg(n)}));var a=r.length;e._msgBufferList.splice(0,a),e._logger.debug("_","timer online msg handle -> delCount: ".concat(a," msgBufferList: ").concat(e._msgBufferList.length))}e._hadHandleMsgTimer=!1,e._handleBufferMsgs()}),20))}}),Object.defineProperty(r.prototype,"registerEventListener",{enumerable:!1,configurable:!0,writable:!0,value:function(e){Object.assign(this._watchers,e)}}),Object.defineProperty(r.prototype,"registerStateMachineEvent",{enumerable:!1,configurable:!0,writable:!0,value:function(t,n,r){var i=t+n;e.prototype.on.call(this,i,r)}}),Object.defineProperty(r.prototype,"unregisterStateMachineEvent",{enumerable:!1,configurable:!0,writable:!0,value:function(t){var n=this;["onRinging","onAccept","onHungup","onMediaModify"].forEach((function(r){var i=t+r;e.prototype.removeAll.call(n,i)}))}}),Object.defineProperty(r.prototype,"registerUserInfo",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._userInfo=e}}),Object.defineProperty(r.prototype,"_sendCallMessage",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return h(this,void 0,void 0,(function(){var t,r,i,o,a,s,l,c,u,d,_,f;return g(this,(function(h){switch(h.label){case 0:return this._logger.debug("_","CallMessageHandler] sendCallMesage -> message: ".concat(JSON.stringify(e))),t=e.channelId,r=e.conversationType,i=e.targetId,o=e.content,a=e.messageType,s=e.directionalUserIdList,l=e.pushConfig,c={channelId:t,messageType:a,content:o,directionalUserIdList:s},[T.VCInvite,T.VCModifyMem,T.VCHangup].includes(a)&&((u=l||{pushTitle:"",pushContent:"",pushData:""}).androidConfig=Object.assign((null==l?void 0:l.androidConfig)||{},{categoryHW:"VOIP",categoryVivo:"IM"}),u.iOSConfig=Object.assign(u.iOSConfig||{},{apnsCollapseId:o.callId}),u.disablePushTitle=!1,u.forceShowDetailContent=!1,c.pushConfig=u),[4,this._context.sendMessage(r,i,c)];case 1:return d=h.sent(),_=d.code,f=d.data,_!==n.SUCCESS?(this._logger.error("_","CallMessageHandler] sendCallMesage error -> code: ".concat(_)),[2,{code:G[_]||R.SEND_MSG_ERROR}]):[2,{code:R.SUCCESS,message:f}]}}))}))}}),Object.defineProperty(r.prototype,"sendInvite",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return h(this,void 0,void 0,(function(){var n,r,i,o,a,s,l,c,u,d;return g(this,(function(_){return n=e.roomType,r=e.channelId,i=e.conversationType,o=e.targetId,a=e.callId,s=e.mediaType,l=e.inviteUserIds,c=e.extra,u=e.pushConfig,this._logger.warn("_","CallMessageHandler] sendCallMesage sendInvite",JSON.stringify(e)),this._watchers.sendAccept&&this._watchers.sendAccept({callId:a}),d={platform:U.WEB,deviceId:this._deviceId,callId:a,roomType:n,extra:c,engineType:4,channelInfo:{Id:a,Key:""},mediaType:s,inviteUserIds:l,observerUserIds:[],user:this._userInfo},u&&(u.pushData=JSON.stringify({mediaType:s,userIdList:l,callId:a})),[2,this._sendCallMessage({channelId:r,conversationType:i,targetId:o,content:d,messageType:T.VCInvite,directionalUserIdList:i===t.GROUP?l:void 0,pushConfig:u})]}))}))}}),Object.defineProperty(r.prototype,"sendMemeberModify",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return h(this,void 0,void 0,(function(){var t,n,r,i,o,a,s,l,c,u,d,_;return g(this,(function(f){return t=e.channelId,n=e.conversationType,r=e.targetId,i=e.callId,o=e.mediaType,a=e.inviteUserIds,s=e.callerId,l=e.existedUserPofiles,c=e.directionalUserIdList,u=e.extra,d=e.pushConfig,_={platform:U.WEB,deviceId:this._deviceId,callId:i,extra:u,engineType:4,channelInfo:{Id:i,Key:""},mediaType:o,inviteUserIds:a,observerUserIds:[],user:this._userInfo,caller:s,modifyMemType:A.ADD,existedUserPofiles:l},d&&(d.pushData=JSON.stringify({mediaType:o,userIdList:a,callId:i})),[2,this._sendCallMessage({channelId:t,conversationType:n,targetId:r,content:_,messageType:T.VCModifyMem,directionalUserIdList:c,pushConfig:d})]}))}))}}),Object.defineProperty(r.prototype,"sendRinging",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var n=e.channelId,r=e.conversationType,i=e.targetId,o=e.callId,a=e.userIds,s={platform:U.WEB,deviceId:this._deviceId,callId:o,user:this._userInfo};return this._sendCallMessage({channelId:n,conversationType:r,targetId:i,content:s,messageType:T.VCRinging,directionalUserIdList:r===t.GROUP?a:void 0})}}),Object.defineProperty(r.prototype,"sendAccept",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var n=e.channelId,r=e.conversationType,i=e.targetId,o=e.callId,a=e.mediaType,s=e.userIds,l={platform:U.WEB,deviceId:this._deviceId,callId:o,mediaType:a,user:this._userInfo};return this._sendCallMessage({channelId:n,conversationType:r,targetId:i,content:l,messageType:T.VCAccept,directionalUserIdList:r===t.GROUP?s:void 0})}}),Object.defineProperty(r.prototype,"sendHungup",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var n=e.channelId,r=e.conversationType,i=e.targetId,o=e.callId,a=e.reason,s=e.userIds,l=e.pushConfig,c={platform:U.WEB,deviceId:this._deviceId,callId:o,reason:a,user:this._userInfo};return l&&(l.pushData=JSON.stringify({callId:o,reason:a})),this._sendCallMessage({channelId:n,conversationType:r,targetId:i,content:c,messageType:T.VCHangup,pushConfig:l,directionalUserIdList:r===t.GROUP?s:void 0})}}),Object.defineProperty(r.prototype,"sendMediaModify",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var n=e.channelId,r=e.conversationType,i=e.targetId,o=e.callId,a=e.mediaType,s=e.userIds,l={platform:U.WEB,deviceId:this._deviceId,callId:o,mediaType:a,user:this._userInfo};return this._sendCallMessage({channelId:n,conversationType:r,targetId:i,content:l,messageType:T.VCModifyMedia,directionalUserIdList:r===t.GROUP?s:void 0})}}),r}(e);!function(e){e.ZH="zh",e.EN="en"}(D||(D={}));var B,K={PushTitle:{AUDIO:"You have a voice call",VIDEO:"You have a video call"}},J={PushTitle:{AUDIO:"您有一条音频通话",VIDEO:"您有一条视频通话"}},W=function(){function e(){}return Object.defineProperty(e,"set",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._lang=e}}),Object.defineProperty(e,"get",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._lang===D.EN?K:J}}),Object.defineProperty(e,"_lang",{enumerable:!0,configurable:!0,writable:!0,value:D.ZH}),e}(),Y=function(){function e(e,t,n,r,i){var o=this;Object.defineProperty(this,"_context",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"_runtime",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"_logger",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"_watchers",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"_options",{enumerable:!0,configurable:!0,writable:!0,value:i}),Object.defineProperty(this,"_stateMachine",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(this,"_callMsgHandler",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._logger.warn("_","RCCallEngine Version: ".concat("5.28.0"," CommitId: ").concat("770da028649322229aae9a9e88c63120bf209b32")),O(t),this._callMsgHandler=new x(this._context,this._runtime,this._logger,this._options.offlineMsgItv,this._getStateMachine.bind(this)),this._callMsgHandler.registerEventListener({onInvite:this._onInvite.bind(this),sendAccept:this._handleSendAccept.bind(this),onOfflineRecord:this._watchers.onOfflineRecord}),v.on("onStateMachineClose",(function(e){delete o._stateMachine[e]})),W.set(i.lang)}return Object.defineProperty(e.prototype,"_onInvite",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e.channelId,n=e.conversationType,r=e.targetId,i=e.content,o=e.messageType,a=e.senderUserId;e.pushConfig;var s,l=i,c=l.mediaType,u=l.callId,d=l.extra;s=l.roomType!==P.RCCallRoomTypeAcrossCall?a:p(a.split("_"),2)[1];var _=this._context.getCurrentId();if(this._context.getCurrentId()!==s){if(o===T.VCModifyMem)if(i.existedUserPofiles.some((function(e){return e.userId===_}))&&!this._stateMachine[u])return;if(this._stateMachine[u])o===T.VCModifyMem&&this._stateMachine[u].__onMemberModify(e);else this._stateMachine[u]=new j(this._context,this._runtime,this._logger,this._callMsgHandler,t,n,r,c,u),this._logger.info("_","[RCCallEngine] RCCallStateMachine successfully created -> callId: ".concat(u)),o===T.VCInvite?this._stateMachine[u].__onInvite(e):o===T.VCModifyMem&&this._stateMachine[u].__onMemberModify(e),this._watchers.onInvite(this._stateMachine[u],d),Object.keys(this._stateMachine).filter((function(e){return u!==e})).length>0&&!this._options.isAllowAcceptNewCall&&this._stateMachine[u].__handleInviteInSession()}}}),Object.defineProperty(e.prototype,"_handleSendAccept",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(this._options.isAllowAcceptNewCall){var t=e.callId;for(var n in this._stateMachine)t!==n&&(this._stateMachine[n].hungup(),delete this._stateMachine[n])}}}),Object.defineProperty(e.prototype,"_getStateMachine",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._stateMachine[e]}}),Object.defineProperty(e.prototype,"registerUserInfo",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._logger.debug("_","[RCCallEngine] registerUserInfo -> userInfo: ".concat(JSON.stringify(e))),this._callMsgHandler.registerUserInfo(e)}}),Object.defineProperty(e.prototype,"call",{enumerable:!1,configurable:!0,writable:!0,value:function(e,n,r,i,o,a){return void 0===i&&(i=""),void 0===a&&(a=!1),h(thi