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