UNPKG

@rongcloud/plugin-call

Version:

@rongcloud/plugin-call

9 lines 110 kB
import{EventEmitter as e,ConversationType as t,ErrorCode as n,isUndefined as i,isBoolean as r,isString as o,LogL as a,validate as s,notEmptyString as l,VersionManage as c}from"@rongcloud/engine";import{RTCJoinType as u,RCResolution as d,RCKickReason as _,RCRTCCode as h}from"@rongcloud/plugin-rtc";var f=function(e,t){return f=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])},f(e,t)};var g=function(){return g=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},g.apply(this,arguments)};function p(e,t,n,i){return new(n||(n=Promise))((function(r,o){function a(e){try{l(i.next(e))}catch(e){o(e)}}function s(e){try{l(i.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}l((i=i.apply(e,t||[])).next())}))}function C(e,t){var n,i,r,o,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[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,i&&(r=2&s[0]?i.return:s[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,s[1])).done)return r;switch(i=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,i=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]<r[3])){a.label=s[1];break}if(6===s[0]&&a.label<r[1]){a.label=r[1],r=s;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(s);break}r[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],i=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}function b(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var i,r,o=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(i=o.next()).done;)a.push(i.value)}catch(e){r={error:e}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return a}function R(e,t,n){if(n||2===arguments.length)for(var i,r=0,o=t.length;r<o;r++)!i&&r in t||(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return e.concat(i||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var m,v,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,i=+e,r=[];do{var o=i%n;i=(i-o)/n,r.unshift(t[o])}while(i);return r.join("")}(e=parseInt(e,16))).length>22&&(e=e.slice(0,22)),e},O=function(){var e=Math.floor(1e3*Math.random()),t=y();return[t=t.replace(/\//g,"0"),Date.now(),e].join("_")},S=new e,T=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"}(m||(m={})),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",e[e.SWITCH_VIDEO_DEVICE_ERROR=53316]="SWITCH_VIDEO_DEVICE_ERROR"}(v||(v={})),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 M,P,A,N,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"}(M||(M={})),function(e){e[e.WAITING=0]="WAITING",e[e.KEEPING=1]="KEEPING",e[e.END=2]="END"}(P||(P={})),function(e){e[e.NONE=0]="NONE",e[e.WAITING=1]="WAITING",e[e.KEEPING=2]="KEEPING"}(A||(A={})),function(e){ /*! 同App通话 */ e[e.RCCallRoomTypeNormalCall=0]="RCCallRoomTypeNormalCall", /*! 跨App通话 */ e[e.RCCallRoomTypeAcrossCall=7]="RCCallRoomTypeAcrossCall"}(N||(N={}));var U,L,k=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}();!function(e){e[e.CALLER=1]="CALLER",e[e.CALLEE=2]="CALLEE"}(U||(U={})),function(e){e[e.HANGUP=1]="HANGUP",e[e.IGNORE=2]="IGNORE"}(L||(L={}));var j,D,V,H=function(){function e(e,t,n,i,r,o,a,s,l,c){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:i}),Object.defineProperty(this,"_channelId",{enumerable:!0,configurable:!0,writable:!0,value:r}),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,"_options",{enumerable:!0,configurable:!0,writable:!0,value:c}),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===P.END&&(S.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,i=n.user,r=n.reason,o=e.messageType;for(var a in this._userInfo[t]={userId:t,state:A.NONE,isCaller:!1,isRemote:!1},this._userTimers)this._clearTimerById(a);var s=E.ACCEPT_BY_OTHER_CLIENT;o===M.VCHangup&&(s=r===E.BUSY_LINE?E.OTHER_CLIENT_IN_CALL:r===E.NO_RESPONSE?E.NO_RESPONSE:E.HANGUP_BY_OTHER_CLIENT),Object.assign(this._userInfo[t],i),this._notifyUserStateChange(this._userInfo[t],s),this._notifyStateChange(P.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===A.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,i=n.user,r=n.deviceId,o=this._isCrossAppkey?t.split("_")[1]:t;this._isRemoteInvalidMsg(o,r)?this._logger.debug("_","[RCCallStateMachine] onRinging -> not the remote device that is currently talking"):this._context.getCurrentId()!==o&&this._watchers.onRinging(g({userId:o},i))}}),Object.defineProperty(e.prototype,"_onAccept",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var n=this,i=e.senderUserId,r=e.content,o=r.user,a=r.deviceId;e.sentTime;var s=this._isCrossAppkey?i.split("_")[1]:i,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:A.KEEPING,isCaller:t,isRemote:t,deviceId:t?T(n._runtime):a},t||(n._beginTimestamp=Date.now(),Object.assign(n._userInfo[s],o)),n._notifyUserStateChange(n._userInfo[e])})),this.getCallerId()===l&&this._notifyStateChange(P.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,i=n.mediaType,r=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=i,this._watchers.onMediaModify({sender:g({userId:t},r),mediaType:i}))}}),Object.defineProperty(e.prototype,"_onHungup",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e.senderUserId,n=e.content,i=this._isCrossAppkey?t.split("_")[1]:t,r=n,o=r.reason,a=r.user,s=r.deviceId;if(this._options.busyCallPolicy!==L.IGNORE||o!==E.BUSY_LINE){var l=this._context.getCurrentId();if(this._isRemoteInvalidMsg(i,s))this._logger.debug("_","[RCCallStateMachine] _onHungup -> not the remote device that is currently talking");else if(l!==i)if(this._sessionState!==P.END){this._userInfo[i]&&(this._userInfo[i].state=A.NONE,this._endTimestamp=Date.now(),Object.assign(this._userInfo[i],a),this._notifyUserStateChange(this._userInfo[i],w[o]),delete this._userInfo[i]),w[o]===E.REMOTE_CANCEL?this.getRemoteUserIds().length<1&&this._clearTimerById(l):this.getInviterId()===l?this._clearTimerById(i):this.getRemoteUserIds().length<1&&this._clearTimerById(l);var c=Object.keys(this._userInfo).length<2,u=this._inviterId===i,d=Object.values(this._userInfo).every((function(e){return e.state!==A.KEEPING}));(c||u&&d)&&this._notifyStateChange(P.END,w[o]),this._watchers.onHungup(g({userId:i},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,i=this,r=e.senderUserId,o=e.content,a=e.sentTime,s=o,l=s.inviteUserIds,c=s.user,u=s.deviceId;s.roomType===N.RCCallRoomTypeAcrossCall?(t=b(r.split("_"),2),n=t[1],this._watchers.crossAppkey(!0),this._isCrossAppkey=!0):n=r;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 _=R([r],b(l),!1);this._callMsgHandler.sendRinging({conversationType:this._conversationType,targetId:this._targetId,channelId:this._channelId,callId:this._callId,userIds:_.filter((function(e){return i._isCrossAppkey?e.split("_")[1]!==d:e!==d}))});var h=this._isCrossAppkey?[l[0].split("_")[1]]:l;R([n],b(h),!1).forEach((function(e){i._userInfo[e]={userId:e,state:A.WAITING,isCaller:e===n,isRemote:e!==d},e===n&&Object.assign(i._userInfo[e],c,{deviceId:u}),i._notifyUserStateChange(i._userInfo[e]),e!==n&&(i._userTimers[e]=new k((function(){var t=e===d?E.NO_RESPONSE:E.REMOTE_NO_RESPONSE;e===d?i._hungupHandle(t,!1):(i._userInfo[e]&&(i._userInfo[e].state=A.NONE),i._notifyUserStateChange(i._userInfo[e]),i._watchers.onHungup(i._userInfo[e],t),delete i._userInfo[e]),i._clearTimerById(e)}),i._getTimeout(a)))})),this._notifyStateChange(P.WAITING)}}}),Object.defineProperty(e.prototype,"__onMemberModify",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this,n=e.senderUserId,i=e.content,r=e.sentTime,o=i,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:m.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(P.WAITING)}else this._watchers.onMemberModify({sender:g({userId:n},a),invitedUsers:u.map((function(e){return{userId:e}}))});s.forEach((function(e){var i=e.userId,o=e.callStatus;if(o!==m.IDLE&&(t._userInfo[i]={userId:i,state:o!==m.CONNECTED?A.WAITING:A.KEEPING,isCaller:n===i,isRemote:_!==i},i===n&&Object.assign(t._userInfo[i],a,{deviceId:c}),t._notifyUserStateChange(t._userInfo[i]),o!==m.CONNECTED&&!t._userTimers[i])){if(!u.includes(i))return;t._userTimers[i]=new k((function(){t._userInfo[i]&&(t._userInfo[i].state=A.NONE);var e=i===_?E.NO_RESPONSE:E.REMOTE_NO_RESPONSE;t._notifyUserStateChange(t._userInfo[i],e);try{t._watchers.onHungup(t._userInfo[i],e)}catch(e){t._logger.error("_","[RCCallStateMachine] call onhungup error -> ".concat(null==e?void 0:e.stack))}delete t._userInfo[i],(Object.keys(t._userInfo).length<2||i===_)&&t._notifyStateChange(P.END,e),t._clearTimerById(i)}),t._getTimeout(r))}}))}}}),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=A.NONE),this._notifyUserStateChange(this._userInfo[e]),this._clearTimerById(e);this._notifyStateChange(P.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,i){return void 0===t&&(t=""),void 0===i&&(i=!1),p(this,void 0,void 0,(function(){var r,o,a,s,l,c,u=this;return C(this,(function(d){switch(d.label){case 0:return this._logger.debug("_","[RCCallStateMachine] invite -> userIds: ".concat(JSON.stringify(e))),r=this._callerId=this._inviterId=this._context.getCurrentId(),[4,this._callMsgHandler.sendInvite({roomType:i?N.RCCallRoomTypeAcrossCall:N.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!==r}))})];case 1:return o=d.sent(),a=o.code,s=o.message,this._isCrossAppkey=i,a===v.SUCCESS?(l=s.sentTime,R([r],i?[e[0].split("_")[1]]:b(e),!1).forEach((function(e){var t=e===r;u._userInfo[e]={userId:e,state:A.WAITING,isCaller:t,isRemote:!t},u._notifyUserStateChange(u._userInfo[e]),t||(u._userTimers[e]=new k((function(){u._userInfo[e]&&(u._userInfo[e].state=A.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(P.END,E.REMOTE_NO_RESPONSE),0===u.getRemoteUserIds().length&&u._userInfo[r].state!==A.KEEPING&&u._hungupHandle(E.REMOTE_NO_RESPONSE)}),u._getTimeout(l)))})),this._notifyStateChange(P.WAITING)):(c=a===v.REJECTED_BY_BLACKLIST?E.ADDED_TO_BLACKLIST:E.NETWORK_ERROR,this._notifyStateChange(P.END,c)),[2,{code:a}]}}))}))}}),Object.defineProperty(e.prototype,"accept",{enumerable:!1,configurable:!0,writable:!0,value:function(){return p(this,void 0,void 0,(function(){var e,t,n,i,r;return C(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,i=t.message,this._clearTimerById(e),n===v.SUCCESS?(i.sentTime,this._userInfo[e]&&(this._userInfo[e].state=A.KEEPING),this._beginTimestamp=Date.now(),this._notifyUserStateChange(this._userInfo[e]),this._notifyStateChange(P.KEEPING)):(this._userInfo[e]&&(this._userInfo[e].state=A.NONE),this._notifyUserStateChange(this._userInfo[e]),r=n===v.REJECTED_BY_BLACKLIST?E.ADDED_TO_BLACKLIST:E.NETWORK_ERROR,this._notifyStateChange(P.END,r)),[2,{code:n}]}}))}))}}),Object.defineProperty(e.prototype,"invite",{enumerable:!1,configurable:!0,writable:!0,value:function(e,n){return void 0===n&&(n={}),p(this,void 0,void 0,(function(){var i,r,o,a,s,l,c,u,d,_,h,f=this;return C(this,(function(g){switch(g.label){case 0:return this._conversationType!==t.GROUP?[2,{code:v.CONVERSATION_NOT_GROUP_ERROR}]:(this._logger.info("_","[RCCallStateMachine] invite -> userIds: ".concat(JSON.stringify(e))),i=this._context.getCurrentId(),r=Object.keys(this._userInfo),0===(o=e.filter((function(e){return e!==i&&!r.includes(e)}))).length?(this._logger.warn("_","[RCCallStateMachine] invite -> all userId is in calling now!"),[2,{code:v.PARAM_ERROR}]):(a=r.map((function(e){var t=m.CONNECTED;return f._userInfo[e].state===A.WAITING&&(t=m.RINGING),{userId:e,mediaType:f._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:R(R([],b(r),!1),b(o),!1).filter((function(e){return e!==i}))})]));case 1:return u=g.sent(),d=u.code,_=u.message,d===v.SUCCESS?(h=_.sentTime,o.forEach((function(e){f._userInfo[e]={userId:e,state:A.WAITING,isCaller:!1,isRemote:!0},f._notifyUserStateChange(f._userInfo[e]),f._userTimers[e]=new k((function(){f._userInfo[e]&&(f._userInfo[e].state=A.NONE),f._notifyUserStateChange(f._userInfo[e],E.REMOTE_NO_RESPONSE),f._watchers.onHungup(f._userInfo[e],E.REMOTE_NO_RESPONSE),delete f._userInfo[e],Object.keys(f._userInfo).length<2&&f._notifyStateChange(P.END,E.REMOTE_NO_RESPONSE)}),f._getTimeout(h))}))):o.forEach((function(e){f._userInfo[e]={userId:e,state:A.NONE,isCaller:!1,isRemote:!0};var t=d===v.REJECTED_BY_BLACKLIST?E.ADDED_TO_BLACKLIST:E.NETWORK_ERROR;f._notifyUserStateChange(f._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),p(this,void 0,void 0,(function(){var n,i,r,o,a;return C(this,(function(s){switch(s.label){case 0:return n=this._context.getCurrentId(),i=v.SUCCESS,t?(r={channelId:this._channelId,conversationType:this._conversationType,targetId:this._targetId,callId:this._callId,reason:e,userIds:this.getRemoteUserIds(),pushConfig:g({},this._hungupPushConfig)},e!==E.OTHER_CLIENT_JOINED_CALL?[3,1]:(this._callMsgHandler.sendHungup(r),[3,3])):[3,3];case 1:return[4,this._callMsgHandler.sendHungup(r)];case 2:o=s.sent().code,i=o,s.label=3;case 3:for(a in this._endTimestamp=Date.now(),this._userInfo)this._userInfo[a].state=A.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(P.END,e),[2,{code:i}]}}))}))}}),Object.defineProperty(e.prototype,"hungup",{enumerable:!1,configurable:!0,writable:!0,value:function(){return p(this,void 0,void 0,(function(){var e,t,n;return C(this,(function(i){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===A.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 p(this,void 0,void 0,(function(){var t;return C(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)===v.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!==A.KEEPING&&(n.state=A.KEEPING,t._notifyUserStateChange(n)),t._sessionState!==P.KEEPING&&t._notifyStateChange(P.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!==A.NONE&&(n.state=A.NONE,t._notifyUserStateChange(n,E.REMOTE_HANGUP),t._watchers.onHungup(n,E.REMOTE_HANGUP),delete t._userInfo[e]),new k((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!==P.END&&(t._endTimestamp=Date.now(),t._notifyStateChange(P.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!==A.NONE&&(n.state=A.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!==P.END&&(t._endTimestamp=Date.now(),t._notifyStateChange(P.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?P.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 i={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(i))),i}}),e}();!function(e){e[e.AUDIO=1]="AUDIO",e[e.AUDIO_VIDEO=2]="AUDIO_VIDEO"}(j||(j={})),function(e){e[e.ADD=1]="ADD",e[e.REMOVE=2]="REMOVE"}(D||(D={})),function(e){e.WEB="Web",e.IOS="iOS",e.ANDROID="Android"}(V||(V={}));var G,x,B=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,i=e.targetId,r=e.senderUserId,o=e.content,a=o.callId,s=o.mediaType;this._channelId=t,this._conversationType=n,this._targetId=i,this._callId=a,this._mediaType=s;this._inviterId=r,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,i=e.senderUserId,r=t.reason,o=i===this._context.getCurrentId();this._endReason=o?r:w[r],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 M.VCInvite:this._doInvite(t);break;case M.VCRinging:this._doRinging(t);break;case M.VCAccept:this._doAccept(t);break;case M.VCModifyMem:this._doMemberModify(t);break;case M.VCModifyMedia:this._doMediaModify(t);break;case M.VCHangup:this._doHungup(t);break;default:this._logger.debug("_","[OfflineRecorder] onRecvOfflineMsgs -> unexpected message: ".concat(JSON.stringify(t)))}}while(this._messages.length>0)}}),e}(),K=["RC:VCAccept","RC:VCRinging","RC:VCSummary","RC:VCHangup","RC:VCInvite","RC:VCModifyMedia","RC:VCModifyMem"],J=((G={})[n.REJECTED_BY_BLACKLIST]=v.REJECTED_BY_BLACKLIST,G[n.NOT_IN_GROUP]=v.NOT_IN_GROUP,G),W=function(e){function i(t,n,i,r,o){void 0===r&&(r=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:i}),Object.defineProperty(a,"_offlineMsgItv",{enumerable:!0,configurable:!0,writable:!0,value:r}),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=T(n),a._context.onmessage=a._onMessage.bind(a),a._offlineRecorder=new B(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}f(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(i,e),Object.defineProperty(i.prototype,"_onMessage",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(K.includes(e.messageType)){this._logger.debug("_","[CallMessageHandler] _onMessage -> call message: ".concat(JSON.stringify(e)));try{var t=Date.now(),n=e.sentTime,i=0;this._msgBufferList.forEach((function(e,t){var r=e.msg.sentTime;n>=r&&(i=t+1)})),this._msgBufferList.splice(i,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(i.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 M.VCInvite:this._watchers.onInvite&&this._watchers.onInvite(t);break;case M.VCRinging:e.prototype.emit.call(this,"".concat(n,"onRinging"),t);break;case M.VCAccept:e.prototype.emit.call(this,"".concat(n,"onAccept"),t);break;case M.VCModifyMem:this._watchers.onInvite&&this._watchers.onInvite(t);break;case M.VCModifyMedia:e.prototype.emit.call(this,"".concat(n,"onMediaModify"),t);break;case M.VCHangup:e.prototype.emit.call(this,"".concat(n,"onHungup"),t);break;default:this._logger.warn("_","recv -> unexpected message: ".concat(t.messageType))}}}),Object.defineProperty(i.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(),i=e._msgBufferList.filter((function(e){return n-e.markTime>=200}));if(e._logger.debug("_","[CallMessageHandler] handleBufferMsgs -> lists over 200ms : ".concat(JSON.stringify(i.map((function(e){var t=e.msg;return{messageUId:t.messageUId,isOffLineMessage:t.isOffLineMessage,callId:t.content.callId}}))))),0===i.length)return e._hadHandleMsgTimer=!1,void e._handleBufferMsgs();if(i[0].msg.isOffLineMessage){var r=e._msgBufferList.filter((function(e){return e.msg.isOffLineMessage})),o=function(){var n=r[0].msg,i=n.conversationType,o=n.messageType,a=n.sentTime,s=n.senderUserId,l=n.content,c=l.callId,u=l.inviteUserIds,d=[M.VCInvite,M.VCModifyMem].includes(o),_=e._context.getServerTime()-a,h=_<e._offlineMsgItv;if(h||e._logger.warn("_","offline msg delayTime: ".concat(_,"ms")),d){for(var f=[],g=0;g<r.length;g++){var p=r[g].msg;if(c!==p.content.callId)break;f.push(p)}if(e._logger.warn("_","taskMsgList length: ".concat(f.length)),f.length>0){var C=e._msgBufferList.findIndex((function(e){return e.msg.messageUId===f[f.length-1].messageUId}));e._msgBufferList=e._msgBufferList.slice(C+1);var m=r.findIndex((function(e){return e.msg.messageUId===f[f.length-1].messageUId}));r=r.slice(m+1)}var v=function(){if(i!==t.PRIVATE)return!1;var e=1===f.length,n=f.every((function(e){return[M.VCInvite,M.VCModifyMedia,M.VCRinging].includes(e.messageType)}));return e||n}(),I=function(){if(i!==t.GROUP)return!1;for(var n=!1,r=!0,o=R([s],b(u),!1),a=!1,l=function(t){var n=f[t],i=n.senderUserId,l=n.messageType;if(l===M.VCHangup&&i===e._context.getCurrentId())return"break";l===M.VCHangup&&(a=s===i,o=o.filter((function(e){return i!==e}))),l===M.VCAccept&&(r=!1)},c=0;c<f.length;c++){if("break"===l(c))break}return r&&a||!(o.length>1)||(n=!0),n}();h&&(v||I)&&f.forEach(e._onRecvOnlineCallMsg,e),e._offlineRecorder.onRecvOfflineMsgs(f)}else h&&e._getStateMachine(c)?e._onRecvOnlineCallMsg(r[0].msg):e._logger.debug("_","[CallMessageHandler] unexcepted offline msg -> ".concat(JSON.stringify(r[0].msg))),r.shift(),e._msgBufferList.shift()};do{o()}while(r.length>0)}else{i.forEach((function(t){var n=t.msg;e._onRecvOnlineCallMsg(n)}));var a=i.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(i.prototype,"registerEventListener",{enumerable:!1,configurable:!0,writable:!0,value:function(e){Object.assign(this._watchers,e)}}),Object.defineProperty(i.prototype,"registerStateMachineEvent",{enumerable:!1,configurable:!0,writable:!0,value:function(t,n,i){var r=t+n;e.prototype.on.call(this,r,i)}}),Object.defineProperty(i.prototype,"unregisterStateMachineEvent",{enumerable:!1,configurable:!0,writable:!0,value:function(t){var n=this;["onRinging","onAccept","onHungup","onMediaModify"].forEach((function(i){var r=t+i;e.prototype.removeAll.call(n,r)}))}}),Object.defineProperty(i.prototype,"registerUserInfo",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._userInfo=e}}),Object.defineProperty(i.prototype,"_sendCallMessage",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return p(this,void 0,void 0,(function(){var t,i,r,o,a,s,l,c,u,d,_,h;return C(this,(function(f){switch(f.label){case 0:return this._logger.debug("_","CallMessageHandler] sendCallMesage -> message: ".concat(JSON.stringify(e))),t=e.channelId,i=e.conversationType,r=e.targetId,o=e.content,a=e.messageType,s=e.directionalUserIdList,l=e.pushConfig,c={channelId:t,messageType:a,content:o,directionalUserIdList:s},[M.VCInvite,M.VCModifyMem,M.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(i,r,c)];case 1:return d=f.sent(),_=d.code,h=d.data,_!==n.SUCCESS?(this._logger.error("_","CallMessageHandler] sendCallMesage error -> code: ".concat(_)),[2,{code:J[_]||v.SEND_MSG_ERROR}]):[2,{code:v.SUCCESS,message:h}]}}))}))}}),Object.defineProperty(i.prototype,"sendInvite",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return p(this,void 0,void 0,(function(){var n,i,r,o,a,s,l,c,u,d;return C(this,(function(_){return n=e.roomType,i=e.channelId,r=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:V.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:i,conversationType:r,targetId:o,content:d,messageType:M.VCInvite,directionalUserIdList:r===t.GROUP?l:void 0,pushConfig:u})]}))}))}}),Object.defineProperty(i.prototype,"sendMemeberModify",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return p(this,void 0,void 0,(function(){var t,n,i,r,o,a,s,l,c,u,d,_;return C(this,(function(h){return t=e.channelId,n=e.conversationType,i=e.targetId,r=e.callId,o=e.mediaType,a=e.inviteUserIds,s=e.callerId,l=e.existedUserPofiles,c=e.directionalUserIdList,u=e.extra,d=e.pushConfig,_={platform:V.WEB,deviceId:this._deviceId,callId:r,extra:u,engineType:4,channelInfo:{Id:r,Key:""},mediaType:o,inviteUserIds:a,observerUserIds:[],user:this._userInfo,caller:s,modifyMemType:D.ADD,existedUserPofiles:l},d&&(d.pushData=JSON.stringify({mediaType:o,userIdList:a,callId:r})),[2,this._sendCallMessage({channelId:t,conversationType:n,targetId:i,content:_,messageType:M.VCModifyMem,directionalUserIdList:c,pushConfig:d})]}))}))}}),Object.defineProperty(i.prototype,"sendRinging",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var n=e.channelId,i=e.conversationType,r=e.targetId,o=e.callId,a=e.userIds,s={platform:V.WEB,deviceId:this._deviceId,callId:o,user:this._userInfo};return this._sendCallMessage({channelId:n,conversationType:i,targetId:r,content:s,messageType:M.VCRinging,directionalUserIdList:i===t.GROUP?a:void 0})}}),Object.defineProperty(i.prototype,"sendAccept",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var n=e.channelId,i=e.conversationType,r=e.targetId,o=e.callId,a=e.mediaType,s=e.userIds,l={platform:V.WEB,deviceId:this._deviceId,callId:o,mediaType:a,user:this._userInfo};return this._sendCallMessage({channelId:n,conversationType:i,targetId:r,content:l,messageType:M.VCAccept,directionalUserIdList:i===t.GROUP?s:void 0})}}),Object.defineProperty(i.prototype,"sendHungup",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var n=e.channelId,i=e.conversationType,r=e.targetId,o=e.callId,a=e.reason,s=e.userIds,l=e.pushConfig,c={platform:V.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:i,targetId:r,content:c,messageType:M.VCHangup,pushConfig:l,directionalUserIdList:i===t.GROUP?s:void 0})}}),Object.defineProperty(i.prototype,"sendMediaModify",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var n=e.channelId,i=e.conversationType,r=e.targetId,o=e.callId,a=e.mediaType,s=e.userIds,l={platform:V.WEB,deviceId:this._deviceId,callId:o,mediaType:a,user:this._userInfo};return this._sendCallMessage({channelId:n,conversationType:i,targetId:r,content:l,messageType:M.VCModifyMedia,directionalUserIdList:i===t.GROUP?s:void 0})}}),i}(e);!function(e){e.ZH="zh",e.EN="en"}(x||(x={}));var Y={PushTitle:{AUDIO:"You have a voice call",VIDEO:"You have a video call"}},z={PushTitle:{AUDIO:"您有一条音频通话",VIDEO:"您有一条视频通话"}},F=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===x.EN?Y:z}}),Object.defineProperty(e,"_lang",{enumerable:!0,configurable:!0,writable:!0,value:x.ZH}),e}(),q=function(){function e(e,t,n,i,r){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:i}),Object.defineProperty(this,"_options",{enumerable:!0,configurable:!0,writable:!0,value:r}),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.36.0"," CommitId: ").concat("d8b9ac7b0c1524c64f9de2808bbaf27adbc54715")),T(t),this._callMsgHandler=new W(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}),S.on("onStateMachineClose",(function(e){delete o._stateMachine[e]})),F.set(r.lang)}return Object.defineProperty(e.prototype,"_onInvite",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e.channelId,n=e.conversationType,i=e.targetId,r=e.content,o=e.messageType,a=e.senderUserId;e.pushConfig;var s,l=r,c=l.mediaType,u=l.callId,d=l.extra;s=l.roomType!==N.RCCallRoomTypeAcrossCall?a:b(a.split("_"),2)[1];var _=this._context.getCurrentId();if(this._context.getCurrentId()!==s){if(o===M.VCModifyMem)if(r.existedUserPofiles.some((function(e){return e.userId===_}))&&!this._stateMachine[u])return;if(this._stateMachine[u])o===M.VCModifyMem&&this._stateMachine[u].__onMemberModify(e);else this._stateMachine[u]=new H(this._context,this._runtime,this._logger,this._callMsgHandler,t,n,i,c,u,{busyCallPolicy:this._options.busyCallPolicy}),this._logger.info("_","[RCCallEngine] RCCallStateMachine successfully created -> callId: ".concat(u)),o===M.VCInvite?this._stateMachine[u].__onInvite(e):o===M.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)