ue-softphone-sdk 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,7 @@
1
- import e from"socket.io-client";import{UeWebrtc as n}from"ue-webrtc";import{Base64 as s}from"js-base64";import o from"js-md5";import{JSEncrypt as t}from"jsencrypt";var i=function(){return i=Object.assign||function(e){for(var n,s=1,o=arguments.length;s<o;s++)for(var t in n=arguments[s])Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t]);return e},i.apply(this,arguments)};function c(e,n,s,o){return new(s||(s=Promise))((function(t,i){function c(e){try{r(o.next(e))}catch(e){i(e)}}function a(e){try{r(o.throw(e))}catch(e){i(e)}}function r(e){var n;e.done?t(e.value):(n=e.value,n instanceof s?n:new s((function(e){e(n)}))).then(c,a)}r((o=o.apply(e,n||[])).next())}))}function a(e,n){var s,o,t,i,c={label:0,sent:function(){if(1&t[0])throw t[1];return t[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(r){return function(a){if(s)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(c=0)),c;)try{if(s=1,o&&(t=2&a[0]?o.return:a[0]?o.throw||((t=o.return)&&t.call(o),0):o.next)&&!(t=t.call(o,a[1])).done)return t;switch(o=0,t&&(a=[2&a[0],t.value]),a[0]){case 0:case 1:t=a;break;case 4:return c.label++,{value:a[1],done:!1};case 5:c.label++,o=a[1],a=[0];continue;case 7:a=c.ops.pop(),c.trys.pop();continue;default:if(!(t=c.trys,(t=t.length>0&&t[t.length-1])||6!==a[0]&&2!==a[0])){c=0;continue}if(3===a[0]&&(!t||a[1]>t[0]&&a[1]<t[3])){c.label=a[1];break}if(6===a[0]&&c.label<t[1]){c.label=t[1],t=a;break}if(t&&c.label<t[2]){c.label=t[2],c.ops.push(a);break}t[2]&&c.ops.pop(),c.trys.pop();continue}a=n.call(e,c)}catch(e){a=[6,e],o=0}finally{s=t=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,r])}}}"function"==typeof SuppressedError&&SuppressedError;var r={notOpenAudioMsg:"麦克风没有开启",notOpenAudioCode:403,notOpenAudioMsgEn:"Permission dismissed"},l={forbiddenAudioMsg:"请先检查您的麦克风是否开启",forbiddenAudioCode:0,forbiddenAudioMsgEn:"Permission denied"},u=function(){function e(e){var n=this;void 0===e&&(e={}),this.getWebrtcInfo=function(e,n){u.request(e+"/call/api/sip/webrtc/config/query",{verb:"GET",loginToken:u.loginToken,sessionId:u.agentInfo._id,success:function(e){e.success&&e.data?(u.agentextras=e.data,u.initWebrtcEvent(e.data)):n.error(i({},e))},error:function(e){n.error({error:e})}})},this.initAttachEvent=function(e,s,o,t,i){n.attachEventCallbacks&&u.request(e+"/platform/action/refreshWsToken",{verb:"GET",loginToken:u.loginToken,sessionId:u.agentInfo._id,success:function(e){if(e&&e.data){var c="";o.forEach((function(e){"KF"===e.id&&(c=e.url)})),n.attachEventCallbacks.serve=c,n.attachEventCallbacks.SocketOptions={query:{accountId:t.accountId,agentNumber:t.agentNumber,agentId:t._id,token:e.data.wsToken,wsExtra:JSON.stringify({loginType:s,channelType:"SDK",ability:["call"]}),timestamp:e.data.timestamp,clientType:1},reconnectionDelay:3e3,"force new connection":!0,transports:["websocket"],timeout:5e3},n.attachEventCallbacks.suc=i,u.createEventHandle(n.attachEventCallbacks)}},error:function(e){o.error({error:e})}})},this.openMediaAudio=function(e,n){var s=navigator,o=s.mediaDevices,t=s.getUserMedia,i=s.webkitGetUserMedia,c=s.mozGetUserMedia,a=s.msGetUserMedia,u=(t||i||c||a).bind(navigator);return o?navigator.mediaDevices.getUserMedia({audio:!0}).catch((function(s){var o=s.message.includes("denied");return n?(o&&alert(l.forbiddenAudioMsg),e&&!o&&alert(e),o?l:r):o?l:r})):new Promise((function(s,o){u?u({audio:!0},(function(e){s(!0)}),(function(s){n&&e&&alert(e),o(r)})):o(r)}))},this.listenCallEvent=function(e){n.attachEventCallbacks=e},this._callApi=function(){var e,s,o=n;return{callout:function(n){return c(this,void 0,void 0,(function(){var t,c,r,l,f,d;return a(this,(function(a){switch(a.label){case 0:if(n.success=n&&"function"==typeof n.success?n.success:u.noop,n.fail=n&&"function"==typeof n.fail?n.fail:u.noop,null===u.loginToken||void 0===u.loginToken)return n.fail({success:!1,message:"initialization not complete!"}),[2];if(null===u.agentInfo||void 0===u.agentInfo)return n.fail({success:!1,message:"initialization not complete!"}),[2];if(null===n.customerNumber||void 0===n.customerNumber)return n.fail({success:!1,message:"Parameter customerNumber is required!"}),[2];if(t=u.initOptions.server||u.callApiUrl,c={customerNumber:n.customerNumber,agentNumber:u.agentInfo.agentNumber,accountId:u.agentInfo.accountId,agentId:u.agentInfo._id,loginType:n.loginType||u.agentInfo.loginType||u.initOptions.loginType},n.agentTimeout&&(c.agentTimeout=n.agentTimeout),n.customerTimeout&&(c.customerTimeout=n.customerTimeout),n.agentDisNumber&&(c.agentDisNumber=n.agentDisNumber),n.customerDisNumber&&(c.customerDisNumber=n.customerDisNumber),n.extras&&(c.extras=n.extras),r=u.initOptions,l=!0,"WEBRTC"!==r.loginType)return[3,4];a.label=1;case 1:return a.trys.push([1,3,,4]),[4,o.openMediaAudio("请打开麦克风权限!",l)];case 2:return f=a.sent()||{},[3,4];case 3:return d=a.sent(),console.log(d),[3,4];case 4:return u.request(t+"/call/api/call/call/out",{verb:"POST",body:c,loginToken:u.loginToken,sessionId:u.agentInfo._id,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?n.success(i({success:!0,message:"callout success"},f)):n.fail(i({success:!1,message:e.message,code:e.code},f))}}),[2]}}))}))},hangup:function(n){if(n.success=n&&"function"==typeof n.success?n.success:u.noop,n.fail=n&&"function"==typeof n.fail?n.fail:u.noop,null!==u.loginToken&&void 0!==u.loginToken)if(null!==u.agentInfo&&void 0!==u.agentInfo){var o=u.initOptions.server||u.callApiUrl;u.request(o+"/call/api/call/hangup",{verb:"POST",body:{},loginToken:u.loginToken,sessionId:u.agentInfo._id,accountId:u.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?n.success({success:!0,message:"hangup success",data:e.data.response.data}):n.fail({success:!1,message:e.message,code:e.code})}})}else n.fail({success:!1,message:"initialization not complete!"});else n.fail({success:!1,message:"initialization not complete!"})},holdOrUnHold:function(n){if(n.success=n&&"function"==typeof n.success?n.success:u.noop,n.fail=n&&"function"==typeof n.fail?n.fail:u.noop,null!==u.loginToken&&void 0!==u.loginToken)if(null!==u.agentInfo&&void 0!==u.agentInfo)if(null!==n.type&&void 0!==n.type){var o=u.initOptions.server||u.callApiUrl,t={type:n.type};u.request(o+"/call/api/call/hold",{verb:"POST",body:t,loginToken:u.loginToken,sessionId:u.agentInfo._id,accountId:u.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?n.success({success:!0,message:"holdOrUnHold success"}):n.fail({success:!1,message:e.message,code:e.code})}})}else n.fail({success:!1,message:"Parameter type is required!"});else n.fail({success:!1,message:"initialization not complete!"});else n.fail({success:!1,message:"initialization not complete!"})},muteOrUnMute:function(n){if(n.success=n&&"function"==typeof n.success?n.success:u.noop,n.fail=n&&"function"==typeof n.fail?n.fail:u.noop,null!==u.loginToken&&void 0!==u.loginToken)if(null!==u.agentInfo&&void 0!==u.agentInfo)if(null!==n.type&&void 0!==n.type){var o=u.initOptions.server||u.callApiUrl,t={type:n.type,direction:n.direction||"all"};u.request(o+"/call/api/call/mute",{verb:"POST",body:t,loginToken:u.loginToken,sessionId:u.agentInfo._id,accountId:u.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?n.success({success:!0,message:"muteOrUnMute success"}):n.fail({success:!1,message:e.message,code:e.code})}})}else n.fail({success:!1,message:"Parameter type is required!"});else n.fail({success:!1,message:"initialization not complete!"});else n.fail({success:!1,message:"initialization not complete!"})},transfer:function(n){if(n.success=n&&"function"==typeof n.success?n.success:u.noop,n.fail=n&&"function"==typeof n.fail?n.fail:u.noop,null!==u.loginToken&&void 0!==u.loginToken)if(null!==u.agentInfo&&void 0!==u.agentInfo)if(null!==n.type&&void 0!==n.type)if(null!==n.number&&void 0!==n.number){var o=u.initOptions.server||u.callApiUrl;u.request(o+"/call/api/call/transfer",{verb:"POST",body:n,loginToken:u.loginToken,sessionId:u.agentInfo._id,accountId:u.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?n.success({success:!0,message:"transfer success",data:e.data.response.data}):n.fail({success:!1,message:e.message,code:e.code})}})}else n.fail({success:!1,message:"Parameter number is required!"});else n.fail({success:!1,message:"Parameter type is required!"});else n.fail({success:!1,message:"initialization not complete!"});else n.fail({success:!1,message:"initialization not complete!"})},consult:function(n){if(n.success=n&&"function"==typeof n.success?n.success:u.noop,n.fail=n&&"function"==typeof n.fail?n.fail:u.noop,null!==u.loginToken&&void 0!==u.loginToken)if(null!==u.agentInfo&&void 0!==u.agentInfo)if(null!==n.mode&&void 0!==n.mode)if(null!==n.number&&void 0!==n.number)if(null!==n.agentNumber&&void 0!==n.agentNumber){var o=u.initOptions.server||u.callApiUrl;u.request(o+"/call/api/call/consult",{verb:"POST",body:n,loginToken:u.loginToken,sessionId:u.agentInfo._id,accountId:u.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?n.success({success:!0,message:"consult success",data:e.data.response.data}):n.fail({success:!1,message:e.message,code:e.code})}})}else n.fail({success:!1,message:"Parameter agentNumber is required!"});else n.fail({success:!1,message:"Parameter number is required!"});else n.fail({success:!1,message:"Parameter mode is required!"});else n.fail({success:!1,message:"initialization not complete!"});else n.fail({success:!1,message:"initialization not complete!"})},cancelconsult:function(n){if(n.success=n&&"function"==typeof n.success?n.success:u.noop,n.fail=n&&"function"==typeof n.fail?n.fail:u.noop,null!==u.loginToken&&void 0!==u.loginToken)if(null!==u.agentInfo&&void 0!==u.agentInfo){var o=u.initOptions.server||u.callApiUrl;u.request(o+"/call/api/call/consult/cancel",{verb:"POST",body:n,loginToken:u.loginToken,sessionId:u.agentInfo._id,accountId:u.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?n.success({success:!0,message:"cancelconsult success",data:e.data.response.data}):n.fail({success:!1,message:e.message,code:e.code})}})}else n.fail({success:!1,message:"initialization not complete!"});else n.fail({success:!1,message:"initialization not complete!"})},endConsult:function(n){if(n.success=n&&"function"==typeof n.success?n.success:u.noop,n.fail=n&&"function"==typeof n.fail?n.fail:u.noop,null!==u.loginToken&&void 0!==u.loginToken)if(null!==u.agentInfo&&void 0!==u.agentInfo){var o=u.initOptions.server||u.callApiUrl;u.request(o+"/call/api/call/consult/stop",{verb:"POST",body:n,loginToken:u.loginToken,sessionId:u.agentInfo._id,accountId:u.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?n.success({success:!0,message:"endConsult success",data:e.data.response.data}):n.fail({success:!1,message:e.message,code:e.code})}})}else n.fail({success:!1,message:"initialization not complete!"});else n.fail({success:!1,message:"initialization not complete!"})},callbackConsult:function(n){if(n.success=n&&"function"==typeof n.success?n.success:u.noop,n.fail=n&&"function"==typeof n.fail?n.fail:u.noop,null!==u.loginToken&&void 0!==u.loginToken)if(null!==u.agentInfo&&void 0!==u.agentInfo){var o=u.initOptions.server||u.callApiUrl;u.request(o+"/call/api/call/consult/resume",{verb:"POST",body:n,loginToken:u.loginToken,sessionId:u.agentInfo._id,accountId:u.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?n.success({success:!0,message:"resumeConsult success",data:e.data.response.data}):n.fail({success:!1,message:e.message,code:e.code})}})}else n.fail({success:!1,message:"initialization not complete!"});else n.fail({success:!1,message:"initialization not complete!"})},consultTransfer:function(n){if(n.success=n&&"function"==typeof n.success?n.success:u.noop,n.fail=n&&"function"==typeof n.fail?n.fail:u.noop,null!==u.loginToken&&void 0!==u.loginToken)if(null!==u.agentInfo&&void 0!==u.agentInfo){var o=u.initOptions.server||u.callApiUrl;u.request(o+"/call/api/call/consult/transfer",{verb:"POST",body:n,loginToken:u.loginToken,sessionId:u.agentInfo._id,accountId:u.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?n.success({success:!0,message:"consultTransfer success",data:e.data.response.data}):n.fail({success:!1,message:e.message,code:e.code})}})}else n.fail({success:!1,message:"initialization not complete!"});else n.fail({success:!1,message:"initialization not complete!"})},threeWayCall:function(n){if(n.success=n&&"function"==typeof n.success?n.success:u.noop,n.fail=n&&"function"==typeof n.fail?n.fail:u.noop,null!==u.loginToken&&void 0!==u.loginToken)if(null!==u.agentInfo&&void 0!==u.agentInfo){var o=u.initOptions.server||u.callApiUrl;u.request(o+"/call/api/call/threeway",{verb:"POST",body:n,loginToken:u.loginToken,sessionId:u.agentInfo._id,accountId:u.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?n.success({success:!0,message:"threeWayCall success",data:e.data.response.data}):n.fail({success:!1,message:e.message,code:e.code})}})}else n.fail({success:!1,message:"initialization not complete!"});else n.fail({success:!1,message:"initialization not complete!"})},evaluate:function(n){if(n.success=n&&"function"==typeof n.success?n.success:u.noop,n.fail=n&&"function"==typeof n.fail?n.fail:u.noop,null!==u.loginToken&&void 0!==u.loginToken)if(null!==u.agentInfo&&void 0!==u.agentInfo)if(null!==n.type&&void 0!==n.type){var o=u.initOptions.server||u.callApiUrl;u.request(o+"/call/api/call/evaluate",{verb:"POST",body:n,loginToken:u.loginToken,sessionId:u.agentInfo._id,accountId:u.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?n.success({success:!0,message:"evaluate success",data:e.data.response.data}):n.fail({success:!1,message:e.message,code:e.code})}})}else n.fail({success:!1,message:"Parameter type is required!"});else n.fail({success:!1,message:"initialization not complete!"});else n.fail({success:!1,message:"initialization not complete!"})},meeting:function(n){if(n.success=n&&"function"==typeof n.success?n.success:u.noop,n.fail=n&&"function"==typeof n.fail?n.fail:u.noop,null!==u.loginToken&&void 0!==u.loginToken)if(null!==u.agentInfo&&void 0!==u.agentInfo)if(null!==n.number&&void 0!==n.number){var o=u.initOptions.server||u.callApiUrl;u.request(o+"/call/api/call/meeting",{verb:"POST",body:{meetingType:"phone",number:n.number},loginToken:u.loginToken,sessionId:u.agentInfo._id,accountId:u.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?n.success({success:!0,message:"meeting success",data:e.data.response.data}):n.fail({success:!1,message:e.message,code:e.code})}})}else n.fail({success:!1,message:"Parameter number is required!"});else n.fail({success:!1,message:"initialization not complete!"});else n.fail({success:!1,message:"initialization not complete!"})}}},this._agentApi=function(){var e=n;return{switchLoginType:function(n){return c(this,void 0,void 0,(function(){var s,o,t,r,l,f,d=this;return a(this,(function(g){switch(g.label){case 0:if(s=null,n.success=n&&"function"==typeof n.success?n.success:u.noop,n.fail=n&&"function"==typeof n.fail?n.fail:u.noop,null===n.loginType||void 0===n.loginType)return n.fail({success:!1,message:"Parameter loginType is required!"}),[2];if(null===u.agentInfo||void 0===u.agentInfo)return n.fail({success:!1,message:"initialization not complete!"}),[2];if(null!==n.loginNumber&&void 0!==n.loginNumber&&(s=n.loginNumber),"PSTN"===n.loginType&&!(s=s||u.agentInfo.mobile))return alert("请给座席绑定手机号,或者传入号码参数!"),n.fail({success:!1,message:"Please bind your mobile number"}),[2];if("SIP"===n.loginType&&(s=s||u.agentInfo.sipNumber),"WEBRTC"===n.loginType&&(s=u.agentInfo.webrtcSipNumber),o=u.initOptions.server||u.callApiUrl,t={loginType:n.loginType,loginNumber:s},u.initOptions,l=!0,"WEBRTC"!==n.loginType)return[3,4];g.label=1;case 1:return g.trys.push([1,3,,4]),[4,e.openMediaAudio("请打开麦克风权限!",l)];case 2:return r=g.sent()||{},[3,4];case 3:return f=g.sent(),console.log(f),[3,4];case 4:return u.request(o+"/call/api/agent/v1/login-type/change",{verb:"POST",body:t,loginToken:u.loginToken,sessionId:u.agentInfo._id,accountId:u.agentInfo.accountId,success:function(s){return c(d,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return s.success?(n.success(i({success:!0,message:"updateLoginType success"},r)),u.agentInfo.loginType=n.loginType,"WEBRTC"!==n.loginType?[3,1]:(e._webPhoneApi().connect(),[3,4])):[3,5];case 1:return"PSTN"!==n.loginType?[3,3]:[4,u.request(o+"/platform/action/updateCallConfig",{verb:"POST",body:{agentCallConfig:{},mobile:n.loginNumber},loginToken:u.loginToken,sessionId:u.agentInfo._id,accountId:u.agentInfo.accountId})];case 2:return t.sent(),e._webPhoneApi().disconnect(),[3,4];case 3:e._webPhoneApi().disconnect(),t.label=4;case 4:return[3,6];case 5:n.fail(i({success:!1,message:s.message,code:s.code},r)),t.label=6;case 6:return[2]}}))}))}}),[2]}}))}))},findPhoneBarList:function(e){if(e.success=e&&"function"==typeof e.success?e.success:u.noop,e.fail=e&&"function"==typeof e.fail?e.fail:u.noop,null!==u.agentInfo&&void 0!==u.agentInfo){var n=u.initOptions.server||u.callApiUrl;u.request(n+"/call/api/phone/bar/all",{verb:"GET",loginToken:u.loginToken,sessionId:u.agentInfo._id,accountId:u.agentInfo.accountId,success:function(n){if(n.success){var s=[];n.data.forEach((function(e){var n={name:e.name,number:e.number};s.push(n)})),e.success({success:!0,data:s})}else e.fail({success:!1,message:n.message,code:n.code})}})}else e.fail({success:!1,message:"initialization not complete!"})},switchPhoneBar:function(e){if(e.success=e&&"function"==typeof e.success?e.success:u.noop,e.fail=e&&"function"==typeof e.fail?e.fail:u.noop,null!==e.stateNumber&&void 0!==e.stateNumber)if(null!==u.agentInfo&&void 0!==u.agentInfo){var n=u.initOptions.server||u.callApiUrl,s={stateNumber:e.stateNumber,accountId:u.agentInfo.accountId,agentNumber:u.agentInfo.agentNumber};u.request(n+"/call/api/agent/status/switch",{verb:"POST",body:s,loginToken:u.loginToken,sessionId:u.agentInfo._id,success:function(n){n.success?e.success({success:!0}):e.fail({success:!1,message:n.message,code:n.code})}})}else e.fail({success:!1,message:"initialization not complete!"});else e.fail({success:!1,message:"Parameter stateNumber is required!"})},logout:function(e){if(e.success=e&&"function"==typeof e.success?e.success:u.noop,e.fail=e&&"function"==typeof e.fail?e.fail:u.noop,null!==u.agentInfo&&void 0!==u.agentInfo){null!==e.toAnswerOffline&&void 0!==e.toAnswerOffline||(e.toAnswerOffline="1");var n=u.initOptions.server||u.callApiUrl,s={toAnswerOffline:e.toAnswerOffline};u.request(n+"/call/api/sdk/agent/logout",{verb:"POST",body:s,loginToken:u.loginToken,sessionId:u.agentInfo._id,accountId:u.agentInfo.accountId,success:function(n){n.success?e&&(u.Socketinstance.disconnect(),"WEBRTC"===u.agentInfo.loginType&&u.webPhone.disconnect(),e.success({success:!0})):e&&e.fail({success:!1,message:n.message,code:n.code})}})}else e.fail({success:!1,message:"initialization not complete!"})},findIdleAgentsForQueue:function(e){if(e.success=e&&"function"==typeof e.success?e.success:u.noop,e.fail=e&&"function"==typeof e.fail?e.fail:u.noop,null!==u.agentInfo&&void 0!==u.agentInfo){var n=u.initOptions.server||u.callApiUrl;u.request(n+"/call/api/queue/acountFreeAgent/find",{verb:"POST",body:{},loginToken:u.loginToken,sessionId:u.agentInfo._id,accountId:u.agentInfo.accountId,success:function(n){n.success?e&&e.success({success:!0,dataList:n.data||[]}):e&&e.fail({success:!1,message:n.message,code:n.code})}})}else e.fail({success:!1,message:"initialization not complete!"})},getAvailableSipNumberList:function(e){if(e.success=e&&"function"==typeof e.success?e.success:u.noop,e.fail=e&&"function"==typeof e.fail?e.fail:u.noop,null!==u.agentInfo&&void 0!==u.agentInfo){var n=u.initOptions.server||u.callApiUrl;u.request(n+"/call/api/sip/avaliable/query",{verb:"POST",body:{},loginToken:u.loginToken,sessionId:u.agentInfo._id,success:function(n){if(n.success&&n.data){var s=[];n.data.forEach((function(e){var n={number:e.id,numberName:e.number};s.push(n)})),e.success({success:!0,data:s})}else e.fail({success:!1,message:n.message,code:n.code})}})}else e.fail({success:!1,message:"initialization not complete!"})}}},this._webPhoneApi=function(){return{accept:function(){u.webPhone.accept()},connect:function(){u.webPhone&&this.isConnected()||u.initWebrtcEvent(u.agentextras)},disconnect:function(){u.webPhone&&this.isConnected()&&u.webPhone.disconnect()},isConnected:function(){return u.webPhone.isConnected()},sendDTMF:function(e){u.webPhone.sendDTMF(e)}}},e.error="function"==typeof e.error?e.error:u.noop,e.success="function"==typeof e.success?e.success:u.noop,null!==e.agentNumber&&void 0!==e.agentNumber?(null!==e.loginType&&void 0!==e.loginType||(e.loginType="PSTN"),this.init(e)):e.error({message:"Invalid agentNumber"})}var u;return e.noop=function(){},e.prototype.init=function(e){if(void 0===e&&(e={}),u.trace=u.noop,u.debug=u.noop,u.log=u.noop,u.warn=u.noop,u.error=u.noop,!0===e.debug||"all"===e.debug)u.trace=console.trace.bind(console),u.debug=console.debug.bind(console),u.log=console.log.bind(console),u.warn=console.warn.bind(console),u.error=console.error.bind(console);else if(Array.isArray(e.debug))for(var n in e.debug){var s=e.debug[n];switch(s){case"trace":u.trace=console.trace.bind(console);break;case"debug":u.debug=console.debug.bind(console);break;case"log":u.log=console.log.bind(console);break;case"warn":u.warn=console.warn.bind(console);break;case"error":u.error=console.error.bind(console);break;default:console.error("Unknown debugging option '"+s+"' (supported: 'trace', 'debug', 'log', warn', 'error')")}}u.log("Initializing library");var o=u.useDefaultDependencies({WebSocket:f});u.newWebSocket=o.newWebSocket,u.request=o.request,this.login(e)},e.prototype.login=function(e){return c(this,void 0,void 0,(function(){var n,c,r,l,f,d,g,p=this;return a(this,(function(a){switch(a.label){case 0:if(n=e.server||u.callApiUrl,c=e.agentNumber+"@"+e.accountId,r=e.loginType,l={loginName:c,loginType:r,loginChannel:"SDK",password:""},f=!0,"WEBRTC"!==r)return[3,4];a.label=1;case 1:return a.trys.push([1,3,,4]),[4,this.openMediaAudio("请打开麦克风权限!",f)];case 2:return d=a.sent()||{},[3,4];case 3:return g=a.sent(),console.log(g),[3,4];case 4:return e.password&&(l.password=e.password),u.request(n+"/platform/public/loginPre",{verb:"GET",success:function(c){if(c&&c.success&&c.data){var a=decodeURIComponent(s.decode(c.data.pk)),f=new t;f.setPublicKey(a);var g=o(l.password),m=f.encrypt(g);l.password=m,u.request(n+"/platform/public/login",{verb:"POST",body:l,success:function(s){s.success?u.request(n+"/platform/action/loginInfo",{verb:"GET",loginToken:s.data.loginToken,sessionId:s.data.sessionId,success:function(s){s.success?(s.data.agent&&(u.agentInfo=s.data.agent,u.loginToken=s.data.loginToken,u.initOptions=i(i({},e),{audioInfo:d})),p.initAttachEvent(n,r,s.data.pushServer,s.data.agent,e.success),"WEBRTC"===r&&p.getWebrtcInfo(n,e)):e.error(i(i({},s),d))},error:function(n){e.error(i({error:n},d))}}):e.error(i(i({},s),d))},error:function(n){e.error(i({error:n},d))}})}else e.error(i(i({},c),d))},error:function(n){e.error(i({error:n},d))}}),[2]}}))}))},e.createEventHandle=function(e){var n=this;void 0===e&&(e={}),e.success="function"==typeof e.success?e.success:u.noop,e.error="function"==typeof e.error?e.error:u.noop,e.message="function"==typeof e.message?e.message:u.noop,e.event="function"==typeof e.event?e.event:u.noop,e.server=null===e.serve||void 0===e.serve?"ws://152.136.72.209:3201/phoneBarGateway":e.serve,null!==e.SocketOptions&&void 0!==e.SocketOptions||(e.SocketOptions={},u.error({message:"login response error!"})),this.Socketinstance=u.newWebSocket(e.server,e.SocketOptions),this.Socketinstance.on("connect",(function(){e.success("connect event serve success!"),e.suc()})),this.Socketinstance.on("error",(function(n,s){e.error({type:"socketError",error:n}),s&&"function"==typeof s&&s("error")})),this.Socketinstance.on("message",(function(n,s){e.message({subtype:n.subType,data:n.data}),s&&"function"==typeof s&&s("success")})),this.Socketinstance.on("event",(function(s){if("KICK_OFF"===s.subType){n.Socketinstance.disconnect();try{u.webPhone.disconnect()}catch(e){}e.event({message:"坐席账户在其他地方登录"})}}))},e.useDefaultDependencies=function(e){var n=e&&e.fetch||fetch,s=e&&e.Promise||Promise,o=e&&e.WebSocket||WebSocket;return{newWebSocket:function(e,n){return new o(e,n)},request:function(e,o){var t={method:o.verb,cache:"no-cache",headers:{"Content-Type":"application/json",loginToken:o.loginToken||"",sessionId:o.sessionId||"",clienttype:0}};o.encryptionFields&&(t.headers["ue-encryption-algorithm"]=o.encryptionAlgorithm||"aes",t.headers["ue-encryption-fields"]=o.encryptionFields),void 0!==o.withCredentials&&(t.credentials=!0===o.withCredentials?"include":o.withCredentials?o.withCredentials:"omit"),void 0!==o.body&&(t.body=JSON.stringify(o.body));var i=n(e,t).catch((function(e){return s.reject({message:"Probably a network error, is the gateway down?",error:e})}));if(void 0!==o.timeout){var c=new s((function(e,n){var s=window.setTimeout((function(){return clearTimeout(s),o.error({message:"Request timed out",timeout:o.timeout}),n({message:"Request timed out",timeout:o.timeout})}),o.timeout)}));i=s.race([i,c])}return i.then((function(e){return e.ok?typeof o.success==typeof u.noop?e.json().then((function(e){o.success(e)})).catch((function(n){return o.error({message:"Failed to parse response body",error:n,response:e}),s.reject({message:"Failed to parse response body",error:n,response:e})})):void 0:(o.error({message:"API call failed",response:e}),s.reject({message:"API call failed",response:e}))})).catch((function(e){typeof o.error==typeof u.noop&&o.error(e.message||"<< internal error >>",e)})),i}}},Object.defineProperty(e.prototype,"agent",{get:function(){return this._agentApi()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"webrtc",{get:function(){return this._webPhoneApi()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"call",{get:function(){return this._callApi()},enumerable:!1,configurable:!0}),u=e,e.callApiUrl="https://app.useasy.cn/api",e.Socketinstance=null,e.initWebrtcEvent=function(e){return c(void 0,void 0,void 0,(function(){return a(u,(function(s){switch(s.label){case 0:return u.webPhone=new n({server:e.wssUrl,sip:e.sip,secret:e.password}),[4,this.webPhone.connect()];case 1:return s.sent(),this.webPhone.register(),[2]}}))}))},e}(),f=function(){function n(n,s){delete s.path,delete s.hostname,delete s.port,this.ws=e.connect("wss://".concat(n),s)}return n.prototype.on=function(e,n){"connect"===e&&this.ws.on(e,n),"error"===e&&(this.ws.on("connect_error",n),this.ws.on("error",n),this.ws.on("disconnect",n),this.ws.on("reconnect_failed",n)),"message"===e&&this.ws.on("call",n),"event"===e&&this.ws.on("event",n)},n.prototype.emit=function(e,n,s){this.ws.emit(e,n,s)},n.prototype.disconnect=function(){this.ws.disconnect()},n}();export{u as default};
1
+ import{UeWebrtc as e}from"ue-webrtc";import{Base64 as t}from"js-base64";import s from"js-md5";import{JSEncrypt as n}from"jsencrypt";var o=function(){return o=Object.assign||function(e){for(var t,s=1,n=arguments.length;s<n;s++)for(var o in t=arguments[s])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},o.apply(this,arguments)};function i(e,t,s,n){return new(s||(s=Promise))((function(o,i){function r(e){try{a(n.next(e))}catch(e){i(e)}}function c(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(r,c)}a((n=n.apply(e,t||[])).next())}))}function r(e,t){var s,n,o,i,r={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(s)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(r=0)),r;)try{if(s=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return r.label++,{value:c[1],done:!1};case 5:r.label++,n=c[1],c=[0];continue;case 7:c=r.ops.pop(),r.trys.pop();continue;default:if(!(o=r.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){r=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){r.label=c[1];break}if(6===c[0]&&r.label<o[1]){r.label=o[1],o=c;break}if(o&&r.label<o[2]){r.label=o[2],r.ops.push(c);break}o[2]&&r.ops.pop(),r.trys.pop();continue}c=t.call(e,r)}catch(e){c=[6,e],n=0}finally{s=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}"function"==typeof SuppressedError&&SuppressedError;
2
+ /*!
3
+ * Socket.IO v4.7.2
4
+ * (c) 2014-2023 Guillermo Rauch
5
+ * Released under the MIT License.
6
+ */
7
+ const c=Object.create(null);c.open="0",c.close="1",c.ping="2",c.pong="3",c.message="4",c.upgrade="5",c.noop="6";const a=Object.create(null);Object.keys(c).forEach((e=>{a[c[e]]=e}));const u={type:"error",data:"parser error"},l="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),h="function"==typeof ArrayBuffer,p=e=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,f=({type:e,data:t},s,n)=>l&&t instanceof Blob?s?n(t):d(t,n):h&&(t instanceof ArrayBuffer||p(t))?s?n(t):d(new Blob([t]),n):n(c[e]+(t||"")),d=(e,t)=>{const s=new FileReader;return s.onload=function(){const e=s.result.split(",")[1];t("b"+(e||""))},s.readAsDataURL(e)};function g(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}let m;const y="undefined"==typeof Uint8Array?[]:new Uint8Array(256);for(let e=0;e<64;e++)y["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(e)]=e;const b="function"==typeof ArrayBuffer,v=(e,t)=>{if("string"!=typeof e)return{type:"message",data:w(e,t)};const s=e.charAt(0);return"b"===s?{type:"message",data:k(e.substring(1),t)}:a[s]?e.length>1?{type:a[s],data:e.substring(1)}:{type:a[s]}:u},k=(e,t)=>{if(b){const s=(e=>{let t,s,n,o,i,r=.75*e.length,c=e.length,a=0;"="===e[e.length-1]&&(r--,"="===e[e.length-2]&&r--);const u=new ArrayBuffer(r),l=new Uint8Array(u);for(t=0;t<c;t+=4)s=y[e.charCodeAt(t)],n=y[e.charCodeAt(t+1)],o=y[e.charCodeAt(t+2)],i=y[e.charCodeAt(t+3)],l[a++]=s<<2|n>>4,l[a++]=(15&n)<<4|o>>2,l[a++]=(3&o)<<6|63&i;return u})(e);return w(s,t)}return{base64:!0,data:e}},w=(e,t)=>"blob"===t?e instanceof Blob?e:new Blob([e]):e instanceof ArrayBuffer?e:e.buffer,T=String.fromCharCode(30);function I(){return new TransformStream({transform(e,t){!function(e,t){l&&e.data instanceof Blob?e.data.arrayBuffer().then(g).then(t):h&&(e.data instanceof ArrayBuffer||p(e.data))?t(g(e.data)):f(e,!1,(e=>{m||(m=new TextEncoder),t(m.encode(e))}))}(e,(s=>{const n=s.length;let o;if(n<126)o=new Uint8Array(1),new DataView(o.buffer).setUint8(0,n);else if(n<65536){o=new Uint8Array(3);const e=new DataView(o.buffer);e.setUint8(0,126),e.setUint16(1,n)}else{o=new Uint8Array(9);const e=new DataView(o.buffer);e.setUint8(0,127),e.setBigUint64(1,BigInt(n))}e.data&&"string"!=typeof e.data&&(o[0]|=128),t.enqueue(o),t.enqueue(s)}))}})}let _;function A(e){return e.reduce(((e,t)=>e+t.length),0)}function O(e,t){if(e[0].length===t)return e.shift();const s=new Uint8Array(t);let n=0;for(let o=0;o<t;o++)s[o]=e[0][n++],n===e[0].length&&(e.shift(),n=0);return e.length&&n<e[0].length&&(e[0]=e[0].slice(n)),s}function E(e){if(e)return function(e){for(var t in E.prototype)e[t]=E.prototype[t];return e}(e)}E.prototype.on=E.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},E.prototype.once=function(e,t){function s(){this.off(e,s),t.apply(this,arguments)}return s.fn=t,this.on(e,s),this},E.prototype.off=E.prototype.removeListener=E.prototype.removeAllListeners=E.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var s,n=this._callbacks["$"+e];if(!n)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var o=0;o<n.length;o++)if((s=n[o])===t||s.fn===t){n.splice(o,1);break}return 0===n.length&&delete this._callbacks["$"+e],this},E.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),s=this._callbacks["$"+e],n=1;n<arguments.length;n++)t[n-1]=arguments[n];if(s){n=0;for(var o=(s=s.slice(0)).length;n<o;++n)s[n].apply(this,t)}return this},E.prototype.emitReserved=E.prototype.emit,E.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]},E.prototype.hasListeners=function(e){return!!this.listeners(e).length};const C="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function S(e,...t){return t.reduce(((t,s)=>(e.hasOwnProperty(s)&&(t[s]=e[s]),t)),{})}const N=C.setTimeout,P=C.clearTimeout;function R(e,t){t.useNativeTimers?(e.setTimeoutFn=N.bind(C),e.clearTimeoutFn=P.bind(C)):(e.setTimeoutFn=C.setTimeout.bind(C),e.clearTimeoutFn=C.clearTimeout.bind(C))}class q extends Error{constructor(e,t,s){super(e),this.description=t,this.context=s,this.type="TransportError"}}class B extends E{constructor(e){super(),this.writable=!1,R(this,e),this.opts=e,this.query=e.query,this.socket=e.socket}onError(e,t,s){return super.emitReserved("error",new q(e,t,s)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(e){"open"===this.readyState&&this.write(e)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(e){const t=v(e,this.socket.binaryType);this.onPacket(t)}onPacket(e){super.emitReserved("packet",e)}onClose(e){this.readyState="closed",super.emitReserved("close",e)}pause(e){}createUri(e,t={}){return e+"://"+this._hostname()+this._port()+this.opts.path+this._query(t)}_hostname(){const e=this.opts.hostname;return-1===e.indexOf(":")?e:"["+e+"]"}_port(){return this.opts.port&&(this.opts.secure&&Number(443!==this.opts.port)||!this.opts.secure&&80!==Number(this.opts.port))?":"+this.opts.port:""}_query(e){const t=function(e){let t="";for(let s in e)e.hasOwnProperty(s)&&(t.length&&(t+="&"),t+=encodeURIComponent(s)+"="+encodeURIComponent(e[s]));return t}(e);return t.length?"?"+t:""}}const x="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),L=64,U={};let j,F=0,D=0;function z(e){let t="";do{t=x[e%L]+t,e=Math.floor(e/L)}while(e>0);return t}function M(){const e=z(+new Date);return e!==j?(F=0,j=e):e+"."+z(F++)}for(;D<L;D++)U[x[D]]=D;let W=!1;try{W="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(c){}const V=W;function K(e){const t=e.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!t||V))return new XMLHttpRequest}catch(e){}if(!t)try{return new(C[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(e){}}function H(){}const Y=null!=new K({xdomain:!1}).responseType;class J extends E{constructor(e,t){super(),R(this,t),this.opts=t,this.method=t.method||"GET",this.uri=e,this.data=void 0!==t.data?t.data:null,this.create()}create(){var e;const t=S(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this.opts.xd;const s=this.xhr=new K(t);try{s.open(this.method,this.uri,!0);try{if(this.opts.extraHeaders){s.setDisableHeaderCheck&&s.setDisableHeaderCheck(!0);for(let e in this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(e)&&s.setRequestHeader(e,this.opts.extraHeaders[e])}}catch(e){}if("POST"===this.method)try{s.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(e){}try{s.setRequestHeader("Accept","*/*")}catch(e){}null===(e=this.opts.cookieJar)||void 0===e||e.addCookies(s),"withCredentials"in s&&(s.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(s.timeout=this.opts.requestTimeout),s.onreadystatechange=()=>{var e;3===s.readyState&&(null===(e=this.opts.cookieJar)||void 0===e||e.parseCookies(s)),4===s.readyState&&(200===s.status||1223===s.status?this.onLoad():this.setTimeoutFn((()=>{this.onError("number"==typeof s.status?s.status:0)}),0))},s.send(this.data)}catch(e){return void this.setTimeoutFn((()=>{this.onError(e)}),0)}"undefined"!=typeof document&&(this.index=J.requestsCount++,J.requests[this.index]=this)}onError(e){this.emitReserved("error",e,this.xhr),this.cleanup(!0)}cleanup(e){if(void 0!==this.xhr&&null!==this.xhr){if(this.xhr.onreadystatechange=H,e)try{this.xhr.abort()}catch(e){}"undefined"!=typeof document&&delete J.requests[this.index],this.xhr=null}}onLoad(){const e=this.xhr.responseText;null!==e&&(this.emitReserved("data",e),this.emitReserved("success"),this.cleanup())}abort(){this.cleanup()}}function G(){for(let e in J.requests)J.requests.hasOwnProperty(e)&&J.requests[e].abort()}J.requestsCount=0,J.requests={},"undefined"!=typeof document&&("function"==typeof attachEvent?attachEvent("onunload",G):"function"==typeof addEventListener&&addEventListener("onpagehide"in C?"pagehide":"unload",G,!1));const $="function"==typeof Promise&&"function"==typeof Promise.resolve?e=>Promise.resolve().then(e):(e,t)=>t(e,0),Q=C.WebSocket||C.MozWebSocket,X="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase(),Z={websocket:class extends B{constructor(e){super(e),this.supportsBinary=!e.forceBase64}get name(){return"websocket"}doOpen(){if(!this.check())return;const e=this.uri(),t=this.opts.protocols,s=X?{}:S(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(s.headers=this.opts.extraHeaders);try{this.ws=X?new Q(e,t,s):t?new Q(e,t):new Q(e)}catch(e){return this.emitReserved("error",e)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=e=>this.onClose({description:"websocket connection closed",context:e}),this.ws.onmessage=e=>this.onData(e.data),this.ws.onerror=e=>this.onError("websocket error",e)}write(e){this.writable=!1;for(let t=0;t<e.length;t++){const s=e[t],n=t===e.length-1;f(s,this.supportsBinary,(e=>{try{this.ws.send(e)}catch(e){}n&&$((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){void 0!==this.ws&&(this.ws.close(),this.ws=null)}uri(){const e=this.opts.secure?"wss":"ws",t=this.query||{};return this.opts.timestampRequests&&(t[this.opts.timestampParam]=M()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}check(){return!!Q}},webtransport:class extends B{get name(){return"webtransport"}doOpen(){"function"==typeof WebTransport&&(this.transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name]),this.transport.closed.then((()=>{this.onClose()})).catch((e=>{this.onError("webtransport error",e)})),this.transport.ready.then((()=>{this.transport.createBidirectionalStream().then((e=>{const t=function(e,t){_||(_=new TextDecoder);const s=[];let n=0,o=-1,i=!1;return new TransformStream({transform(r,c){for(s.push(r);;){if(0===n){if(A(s)<1)break;const e=O(s,1);i=128==(128&e[0]),o=127&e[0],n=o<126?3:126===o?1:2}else if(1===n){if(A(s)<2)break;const e=O(s,2);o=new DataView(e.buffer,e.byteOffset,e.length).getUint16(0),n=3}else if(2===n){if(A(s)<8)break;const e=O(s,8),t=new DataView(e.buffer,e.byteOffset,e.length),i=t.getUint32(0);if(i>Math.pow(2,21)-1){c.enqueue(u);break}o=i*Math.pow(2,32)+t.getUint32(4),n=3}else{if(A(s)<o)break;const e=O(s,o);c.enqueue(v(i?e:_.decode(e),t)),n=0}if(0===o||o>e){c.enqueue(u);break}}}})}(Number.MAX_SAFE_INTEGER,this.socket.binaryType),s=e.readable.pipeThrough(t).getReader(),n=I();n.readable.pipeTo(e.writable),this.writer=n.writable.getWriter();const o=()=>{s.read().then((({done:e,value:t})=>{e||(this.onPacket(t),o())})).catch((e=>{}))};o();const i={type:"open"};this.query.sid&&(i.data=`{"sid":"${this.query.sid}"}`),this.writer.write(i).then((()=>this.onOpen()))}))})))}write(e){this.writable=!1;for(let t=0;t<e.length;t++){const s=e[t],n=t===e.length-1;this.writer.write(s).then((()=>{n&&$((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){var e;null===(e=this.transport)||void 0===e||e.close()}},polling:class extends B{constructor(e){if(super(e),this.polling=!1,"undefined"!=typeof location){const t="https:"===location.protocol;let s=location.port;s||(s=t?"443":"80"),this.xd="undefined"!=typeof location&&e.hostname!==location.hostname||s!==e.port}const t=e&&e.forceBase64;this.supportsBinary=Y&&!t,this.opts.withCredentials&&(this.cookieJar=void 0)}get name(){return"polling"}doOpen(){this.poll()}pause(e){this.readyState="pausing";const t=()=>{this.readyState="paused",e()};if(this.polling||!this.writable){let e=0;this.polling&&(e++,this.once("pollComplete",(function(){--e||t()}))),this.writable||(e++,this.once("drain",(function(){--e||t()})))}else t()}poll(){this.polling=!0,this.doPoll(),this.emitReserved("poll")}onData(e){((e,t)=>{const s=e.split(T),n=[];for(let e=0;e<s.length;e++){const o=v(s[e],t);if(n.push(o),"error"===o.type)break}return n})(e,this.socket.binaryType).forEach((e=>{if("opening"===this.readyState&&"open"===e.type&&this.onOpen(),"close"===e.type)return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(e)})),"closed"!==this.readyState&&(this.polling=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this.poll())}doClose(){const e=()=>{this.write([{type:"close"}])};"open"===this.readyState?e():this.once("open",e)}write(e){this.writable=!1,((e,t)=>{const s=e.length,n=new Array(s);let o=0;e.forEach(((e,i)=>{f(e,!1,(e=>{n[i]=e,++o===s&&t(n.join(T))}))}))})(e,(e=>{this.doWrite(e,(()=>{this.writable=!0,this.emitReserved("drain")}))}))}uri(){const e=this.opts.secure?"https":"http",t=this.query||{};return!1!==this.opts.timestampRequests&&(t[this.opts.timestampParam]=M()),this.supportsBinary||t.sid||(t.b64=1),this.createUri(e,t)}request(e={}){return Object.assign(e,{xd:this.xd,cookieJar:this.cookieJar},this.opts),new J(this.uri(),e)}doWrite(e,t){const s=this.request({method:"POST",data:e});s.on("success",t),s.on("error",((e,t)=>{this.onError("xhr post error",e,t)}))}doPoll(){const e=this.request();e.on("data",this.onData.bind(this)),e.on("error",((e,t)=>{this.onError("xhr poll error",e,t)})),this.pollXhr=e}}},ee=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,te=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function se(e){const t=e,s=e.indexOf("["),n=e.indexOf("]");-1!=s&&-1!=n&&(e=e.substring(0,s)+e.substring(s,n).replace(/:/g,";")+e.substring(n,e.length));let o=ee.exec(e||""),i={},r=14;for(;r--;)i[te[r]]=o[r]||"";return-1!=s&&-1!=n&&(i.source=t,i.host=i.host.substring(1,i.host.length-1).replace(/;/g,":"),i.authority=i.authority.replace("[","").replace("]","").replace(/;/g,":"),i.ipv6uri=!0),i.pathNames=function(e,t){const s=t.replace(/\/{2,9}/g,"/").split("/");return"/"!=t.slice(0,1)&&0!==t.length||s.splice(0,1),"/"==t.slice(-1)&&s.splice(s.length-1,1),s}(0,i.path),i.queryKey=function(e,t){const s={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,(function(e,t,n){t&&(s[t]=n)})),s}(0,i.query),i}class ne extends E{constructor(e,t={}){super(),this.binaryType="arraybuffer",this.writeBuffer=[],e&&"object"==typeof e&&(t=e,e=null),e?(e=se(e),t.hostname=e.host,t.secure="https"===e.protocol||"wss"===e.protocol,t.port=e.port,e.query&&(t.query=e.query)):t.host&&(t.hostname=se(t.host).host),R(this,t),this.secure=null!=t.secure?t.secure:"undefined"!=typeof location&&"https:"===location.protocol,t.hostname&&!t.port&&(t.port=this.secure?"443":"80"),this.hostname=t.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=t.port||("undefined"!=typeof location&&location.port?location.port:this.secure?"443":"80"),this.transports=t.transports||["polling","websocket","webtransport"],this.writeBuffer=[],this.prevBufferLen=0,this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},t),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),"string"==typeof this.opts.query&&(this.opts.query=function(e){let t={},s=e.split("&");for(let e=0,n=s.length;e<n;e++){let n=s[e].split("=");t[decodeURIComponent(n[0])]=decodeURIComponent(n[1])}return t}(this.opts.query)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingTimeoutTimer=null,"function"==typeof addEventListener&&(this.opts.closeOnBeforeunload&&(this.beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.beforeunloadEventListener,!1)),"localhost"!==this.hostname&&(this.offlineEventListener=()=>{this.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",this.offlineEventListener,!1))),this.open()}createTransport(e){const t=Object.assign({},this.opts.query);t.EIO=4,t.transport=e,this.id&&(t.sid=this.id);const s=Object.assign({},this.opts,{query:t,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[e]);return new Z[e](s)}open(){let e;if(this.opts.rememberUpgrade&&ne.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket"))e="websocket";else{if(0===this.transports.length)return void this.setTimeoutFn((()=>{this.emitReserved("error","No transports available")}),0);e=this.transports[0]}this.readyState="opening";try{e=this.createTransport(e)}catch(e){return this.transports.shift(),void this.open()}e.open(),this.setTransport(e)}setTransport(e){this.transport&&this.transport.removeAllListeners(),this.transport=e,e.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",(e=>this.onClose("transport close",e)))}probe(e){let t=this.createTransport(e),s=!1;ne.priorWebsocketSuccess=!1;const n=()=>{s||(t.send([{type:"ping",data:"probe"}]),t.once("packet",(e=>{if(!s)if("pong"===e.type&&"probe"===e.data){if(this.upgrading=!0,this.emitReserved("upgrading",t),!t)return;ne.priorWebsocketSuccess="websocket"===t.name,this.transport.pause((()=>{s||"closed"!==this.readyState&&(u(),this.setTransport(t),t.send([{type:"upgrade"}]),this.emitReserved("upgrade",t),t=null,this.upgrading=!1,this.flush())}))}else{const e=new Error("probe error");e.transport=t.name,this.emitReserved("upgradeError",e)}})))};function o(){s||(s=!0,u(),t.close(),t=null)}const i=e=>{const s=new Error("probe error: "+e);s.transport=t.name,o(),this.emitReserved("upgradeError",s)};function r(){i("transport closed")}function c(){i("socket closed")}function a(e){t&&e.name!==t.name&&o()}const u=()=>{t.removeListener("open",n),t.removeListener("error",i),t.removeListener("close",r),this.off("close",c),this.off("upgrading",a)};t.once("open",n),t.once("error",i),t.once("close",r),this.once("close",c),this.once("upgrading",a),-1!==this.upgrades.indexOf("webtransport")&&"webtransport"!==e?this.setTimeoutFn((()=>{s||t.open()}),200):t.open()}onOpen(){if(this.readyState="open",ne.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush(),"open"===this.readyState&&this.opts.upgrade){let e=0;const t=this.upgrades.length;for(;e<t;e++)this.probe(this.upgrades[e])}}onPacket(e){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",e),this.emitReserved("heartbeat"),this.resetPingTimeout(),e.type){case"open":this.onHandshake(JSON.parse(e.data));break;case"ping":this.sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong");break;case"error":const t=new Error("server error");t.code=e.data,this.onError(t);break;case"message":this.emitReserved("data",e.data),this.emitReserved("message",e.data)}}onHandshake(e){this.emitReserved("handshake",e),this.id=e.sid,this.transport.query.sid=e.sid,this.upgrades=this.filterUpgrades(e.upgrades),this.pingInterval=e.pingInterval,this.pingTimeout=e.pingTimeout,this.maxPayload=e.maxPayload,this.onOpen(),"closed"!==this.readyState&&this.resetPingTimeout()}resetPingTimeout(){this.clearTimeoutFn(this.pingTimeoutTimer),this.pingTimeoutTimer=this.setTimeoutFn((()=>{this.onClose("ping timeout")}),this.pingInterval+this.pingTimeout),this.opts.autoUnref&&this.pingTimeoutTimer.unref()}onDrain(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}flush(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const e=this.getWritablePackets();this.transport.send(e),this.prevBufferLen=e.length,this.emitReserved("flush")}}getWritablePackets(){if(!(this.maxPayload&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;let e=1;for(let s=0;s<this.writeBuffer.length;s++){const n=this.writeBuffer[s].data;if(n&&(e+="string"==typeof(t=n)?function(e){let t=0,s=0;for(let n=0,o=e.length;n<o;n++)t=e.charCodeAt(n),t<128?s+=1:t<2048?s+=2:t<55296||t>=57344?s+=3:(n++,s+=4);return s}(t):Math.ceil(1.33*(t.byteLength||t.size))),s>0&&e>this.maxPayload)return this.writeBuffer.slice(0,s);e+=2}var t;return this.writeBuffer}write(e,t,s){return this.sendPacket("message",e,t,s),this}send(e,t,s){return this.sendPacket("message",e,t,s),this}sendPacket(e,t,s,n){if("function"==typeof t&&(n=t,t=void 0),"function"==typeof s&&(n=s,s=null),"closing"===this.readyState||"closed"===this.readyState)return;(s=s||{}).compress=!1!==s.compress;const o={type:e,data:t,options:s};this.emitReserved("packetCreate",o),this.writeBuffer.push(o),n&&this.once("flush",n),this.flush()}close(){const e=()=>{this.onClose("forced close"),this.transport.close()},t=()=>{this.off("upgrade",t),this.off("upgradeError",t),e()},s=()=>{this.once("upgrade",t),this.once("upgradeError",t)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",(()=>{this.upgrading?s():e()})):this.upgrading?s():e()),this}onError(e){ne.priorWebsocketSuccess=!1,this.emitReserved("error",e),this.onClose("transport error",e)}onClose(e,t){"opening"!==this.readyState&&"open"!==this.readyState&&"closing"!==this.readyState||(this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),"function"==typeof removeEventListener&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",e,t),this.writeBuffer=[],this.prevBufferLen=0)}filterUpgrades(e){const t=[];let s=0;const n=e.length;for(;s<n;s++)~this.transports.indexOf(e[s])&&t.push(e[s]);return t}}ne.protocol=4;const oe="function"==typeof ArrayBuffer,ie=e=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,re=Object.prototype.toString,ce="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===re.call(Blob),ae="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===re.call(File);function ue(e){return oe&&(e instanceof ArrayBuffer||ie(e))||ce&&e instanceof Blob||ae&&e instanceof File}function le(e,t){if(!e||"object"!=typeof e)return!1;if(Array.isArray(e)){for(let t=0,s=e.length;t<s;t++)if(le(e[t]))return!0;return!1}if(ue(e))return!0;if(e.toJSON&&"function"==typeof e.toJSON&&1===arguments.length)return le(e.toJSON(),!0);for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t)&&le(e[t]))return!0;return!1}function he(e){const t=[],s=e.data,n=e;return n.data=pe(s,t),n.attachments=t.length,{packet:n,buffers:t}}function pe(e,t){if(!e)return e;if(ue(e)){const s={_placeholder:!0,num:t.length};return t.push(e),s}if(Array.isArray(e)){const s=new Array(e.length);for(let n=0;n<e.length;n++)s[n]=pe(e[n],t);return s}if("object"==typeof e&&!(e instanceof Date)){const s={};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(s[n]=pe(e[n],t));return s}return e}function fe(e,t){return e.data=de(e.data,t),delete e.attachments,e}function de(e,t){if(!e)return e;if(e&&!0===e._placeholder){if("number"==typeof e.num&&e.num>=0&&e.num<t.length)return t[e.num];throw new Error("illegal attachments")}if(Array.isArray(e))for(let s=0;s<e.length;s++)e[s]=de(e[s],t);else if("object"==typeof e)for(const s in e)Object.prototype.hasOwnProperty.call(e,s)&&(e[s]=de(e[s],t));return e}const ge=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"];var me;function ye(e){return"[object Object]"===Object.prototype.toString.call(e)}!function(e){e[e.CONNECT=0]="CONNECT",e[e.DISCONNECT=1]="DISCONNECT",e[e.EVENT=2]="EVENT",e[e.ACK=3]="ACK",e[e.CONNECT_ERROR=4]="CONNECT_ERROR",e[e.BINARY_EVENT=5]="BINARY_EVENT",e[e.BINARY_ACK=6]="BINARY_ACK"}(me||(me={}));class be extends E{constructor(e){super(),this.reviver=e}add(e){let t;if("string"==typeof e){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");t=this.decodeString(e);const s=t.type===me.BINARY_EVENT;s||t.type===me.BINARY_ACK?(t.type=s?me.EVENT:me.ACK,this.reconstructor=new ve(t),0===t.attachments&&super.emitReserved("decoded",t)):super.emitReserved("decoded",t)}else{if(!ue(e)&&!e.base64)throw new Error("Unknown type: "+e);if(!this.reconstructor)throw new Error("got binary data when not reconstructing a packet");t=this.reconstructor.takeBinaryData(e),t&&(this.reconstructor=null,super.emitReserved("decoded",t))}}decodeString(e){let t=0;const s={type:Number(e.charAt(0))};if(void 0===me[s.type])throw new Error("unknown packet type "+s.type);if(s.type===me.BINARY_EVENT||s.type===me.BINARY_ACK){const n=t+1;for(;"-"!==e.charAt(++t)&&t!=e.length;);const o=e.substring(n,t);if(o!=Number(o)||"-"!==e.charAt(t))throw new Error("Illegal attachments");s.attachments=Number(o)}if("/"===e.charAt(t+1)){const n=t+1;for(;++t&&","!==e.charAt(t)&&t!==e.length;);s.nsp=e.substring(n,t)}else s.nsp="/";const n=e.charAt(t+1);if(""!==n&&Number(n)==n){const n=t+1;for(;++t;){const s=e.charAt(t);if(null==s||Number(s)!=s){--t;break}if(t===e.length)break}s.id=Number(e.substring(n,t+1))}if(e.charAt(++t)){const n=this.tryParse(e.substr(t));if(!be.isPayloadValid(s.type,n))throw new Error("invalid payload");s.data=n}return s}tryParse(e){try{return JSON.parse(e,this.reviver)}catch(e){return!1}}static isPayloadValid(e,t){switch(e){case me.CONNECT:return ye(t);case me.DISCONNECT:return void 0===t;case me.CONNECT_ERROR:return"string"==typeof t||ye(t);case me.EVENT:case me.BINARY_EVENT:return Array.isArray(t)&&("number"==typeof t[0]||"string"==typeof t[0]&&-1===ge.indexOf(t[0]));case me.ACK:case me.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class ve{constructor(e){this.packet=e,this.buffers=[],this.reconPack=e}takeBinaryData(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){const e=fe(this.reconPack,this.buffers);return this.finishedReconstruction(),e}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}var ke=Object.freeze({__proto__:null,protocol:5,get PacketType(){return me},Encoder:class{constructor(e){this.replacer=e}encode(e){return e.type!==me.EVENT&&e.type!==me.ACK||!le(e)?[this.encodeAsString(e)]:this.encodeAsBinary({type:e.type===me.EVENT?me.BINARY_EVENT:me.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id})}encodeAsString(e){let t=""+e.type;return e.type!==me.BINARY_EVENT&&e.type!==me.BINARY_ACK||(t+=e.attachments+"-"),e.nsp&&"/"!==e.nsp&&(t+=e.nsp+","),null!=e.id&&(t+=e.id),null!=e.data&&(t+=JSON.stringify(e.data,this.replacer)),t}encodeAsBinary(e){const t=he(e),s=this.encodeAsString(t.packet),n=t.buffers;return n.unshift(s),n}},Decoder:be});function we(e,t,s){return e.on(t,s),function(){e.off(t,s)}}const Te=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Ie extends E{constructor(e,t,s){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=e,this.nsp=t,s&&s.auth&&(this.auth=s.auth),this._opts=Object.assign({},s),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const e=this.io;this.subs=[we(e,"open",this.onopen.bind(this)),we(e,"packet",this.onpacket.bind(this)),we(e,"error",this.onerror.bind(this)),we(e,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected||(this.subEvents(),this.io._reconnecting||this.io.open(),"open"===this.io._readyState&&this.onopen()),this}open(){return this.connect()}send(...e){return e.unshift("message"),this.emit.apply(this,e),this}emit(e,...t){if(Te.hasOwnProperty(e))throw new Error('"'+e.toString()+'" is a reserved event name');if(t.unshift(e),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(t),this;const s={type:me.EVENT,data:t,options:{}};if(s.options.compress=!1!==this.flags.compress,"function"==typeof t[t.length-1]){const e=this.ids++,n=t.pop();this._registerAckCallback(e,n),s.id=e}const n=this.io.engine&&this.io.engine.transport&&this.io.engine.transport.writable;return this.flags.volatile&&(!n||!this.connected)||(this.connected?(this.notifyOutgoingListeners(s),this.packet(s)):this.sendBuffer.push(s)),this.flags={},this}_registerAckCallback(e,t){var s;const n=null!==(s=this.flags.timeout)&&void 0!==s?s:this._opts.ackTimeout;if(void 0===n)return void(this.acks[e]=t);const o=this.io.setTimeoutFn((()=>{delete this.acks[e];for(let t=0;t<this.sendBuffer.length;t++)this.sendBuffer[t].id===e&&this.sendBuffer.splice(t,1);t.call(this,new Error("operation has timed out"))}),n);this.acks[e]=(...e)=>{this.io.clearTimeoutFn(o),t.apply(this,[null,...e])}}emitWithAck(e,...t){const s=void 0!==this.flags.timeout||void 0!==this._opts.ackTimeout;return new Promise(((n,o)=>{t.push(((e,t)=>s?e?o(e):n(t):n(e))),this.emit(e,...t)}))}_addToQueue(e){let t;"function"==typeof e[e.length-1]&&(t=e.pop());const s={id:this._queueSeq++,tryCount:0,pending:!1,args:e,flags:Object.assign({fromQueue:!0},this.flags)};e.push(((e,...n)=>{if(s===this._queue[0])return null!==e?s.tryCount>this._opts.retries&&(this._queue.shift(),t&&t(e)):(this._queue.shift(),t&&t(null,...n)),s.pending=!1,this._drainQueue()})),this._queue.push(s),this._drainQueue()}_drainQueue(e=!1){if(!this.connected||0===this._queue.length)return;const t=this._queue[0];t.pending&&!e||(t.pending=!0,t.tryCount++,this.flags=t.flags,this.emit.apply(this,t.args))}packet(e){e.nsp=this.nsp,this.io._packet(e)}onopen(){"function"==typeof this.auth?this.auth((e=>{this._sendConnectPacket(e)})):this._sendConnectPacket(this.auth)}_sendConnectPacket(e){this.packet({type:me.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},e):e})}onerror(e){this.connected||this.emitReserved("connect_error",e)}onclose(e,t){this.connected=!1,delete this.id,this.emitReserved("disconnect",e,t)}onpacket(e){if(e.nsp===this.nsp)switch(e.type){case me.CONNECT:e.data&&e.data.sid?this.onconnect(e.data.sid,e.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case me.EVENT:case me.BINARY_EVENT:this.onevent(e);break;case me.ACK:case me.BINARY_ACK:this.onack(e);break;case me.DISCONNECT:this.ondisconnect();break;case me.CONNECT_ERROR:this.destroy();const t=new Error(e.data.message);t.data=e.data.data,this.emitReserved("connect_error",t)}}onevent(e){const t=e.data||[];null!=e.id&&t.push(this.ack(e.id)),this.connected?this.emitEvent(t):this.receiveBuffer.push(Object.freeze(t))}emitEvent(e){if(this._anyListeners&&this._anyListeners.length){const t=this._anyListeners.slice();for(const s of t)s.apply(this,e)}super.emit.apply(this,e),this._pid&&e.length&&"string"==typeof e[e.length-1]&&(this._lastOffset=e[e.length-1])}ack(e){const t=this;let s=!1;return function(...n){s||(s=!0,t.packet({type:me.ACK,id:e,data:n}))}}onack(e){const t=this.acks[e.id];"function"==typeof t&&(t.apply(this,e.data),delete this.acks[e.id])}onconnect(e,t){this.id=e,this.recovered=t&&this._pid===t,this._pid=t,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach((e=>this.emitEvent(e))),this.receiveBuffer=[],this.sendBuffer.forEach((e=>{this.notifyOutgoingListeners(e),this.packet(e)})),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach((e=>e())),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:me.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(e){return this.flags.compress=e,this}get volatile(){return this.flags.volatile=!0,this}timeout(e){return this.flags.timeout=e,this}onAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(e),this}prependAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(e),this}offAny(e){if(!this._anyListeners)return this;if(e){const t=this._anyListeners;for(let s=0;s<t.length;s++)if(e===t[s])return t.splice(s,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(e),this}prependAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(e),this}offAnyOutgoing(e){if(!this._anyOutgoingListeners)return this;if(e){const t=this._anyOutgoingListeners;for(let s=0;s<t.length;s++)if(e===t[s])return t.splice(s,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(e){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const t=this._anyOutgoingListeners.slice();for(const s of t)s.apply(this,e.data)}}}function _e(e){e=e||{},this.ms=e.min||100,this.max=e.max||1e4,this.factor=e.factor||2,this.jitter=e.jitter>0&&e.jitter<=1?e.jitter:0,this.attempts=0}_e.prototype.duration=function(){var e=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var t=Math.random(),s=Math.floor(t*this.jitter*e);e=0==(1&Math.floor(10*t))?e-s:e+s}return 0|Math.min(e,this.max)},_e.prototype.reset=function(){this.attempts=0},_e.prototype.setMin=function(e){this.ms=e},_e.prototype.setMax=function(e){this.max=e},_e.prototype.setJitter=function(e){this.jitter=e};class Ae extends E{constructor(e,t){var s;super(),this.nsps={},this.subs=[],e&&"object"==typeof e&&(t=e,e=void 0),(t=t||{}).path=t.path||"/socket.io",this.opts=t,R(this,t),this.reconnection(!1!==t.reconnection),this.reconnectionAttempts(t.reconnectionAttempts||1/0),this.reconnectionDelay(t.reconnectionDelay||1e3),this.reconnectionDelayMax(t.reconnectionDelayMax||5e3),this.randomizationFactor(null!==(s=t.randomizationFactor)&&void 0!==s?s:.5),this.backoff=new _e({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(null==t.timeout?2e4:t.timeout),this._readyState="closed",this.uri=e;const n=t.parser||ke;this.encoder=new n.Encoder,this.decoder=new n.Decoder,this._autoConnect=!1!==t.autoConnect,this._autoConnect&&this.open()}reconnection(e){return arguments.length?(this._reconnection=!!e,this):this._reconnection}reconnectionAttempts(e){return void 0===e?this._reconnectionAttempts:(this._reconnectionAttempts=e,this)}reconnectionDelay(e){var t;return void 0===e?this._reconnectionDelay:(this._reconnectionDelay=e,null===(t=this.backoff)||void 0===t||t.setMin(e),this)}randomizationFactor(e){var t;return void 0===e?this._randomizationFactor:(this._randomizationFactor=e,null===(t=this.backoff)||void 0===t||t.setJitter(e),this)}reconnectionDelayMax(e){var t;return void 0===e?this._reconnectionDelayMax:(this._reconnectionDelayMax=e,null===(t=this.backoff)||void 0===t||t.setMax(e),this)}timeout(e){return arguments.length?(this._timeout=e,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&0===this.backoff.attempts&&this.reconnect()}open(e){if(~this._readyState.indexOf("open"))return this;this.engine=new ne(this.uri,this.opts);const t=this.engine,s=this;this._readyState="opening",this.skipReconnect=!1;const n=we(t,"open",(function(){s.onopen(),e&&e()})),o=t=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",t),e?e(t):this.maybeReconnectOnOpen()},i=we(t,"error",o);if(!1!==this._timeout){const e=this._timeout,s=this.setTimeoutFn((()=>{n(),o(new Error("timeout")),t.close()}),e);this.opts.autoUnref&&s.unref(),this.subs.push((()=>{this.clearTimeoutFn(s)}))}return this.subs.push(n),this.subs.push(i),this}connect(e){return this.open(e)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const e=this.engine;this.subs.push(we(e,"ping",this.onping.bind(this)),we(e,"data",this.ondata.bind(this)),we(e,"error",this.onerror.bind(this)),we(e,"close",this.onclose.bind(this)),we(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(e){try{this.decoder.add(e)}catch(e){this.onclose("parse error",e)}}ondecoded(e){$((()=>{this.emitReserved("packet",e)}),this.setTimeoutFn)}onerror(e){this.emitReserved("error",e)}socket(e,t){let s=this.nsps[e];return s?this._autoConnect&&!s.active&&s.connect():(s=new Ie(this,e,t),this.nsps[e]=s),s}_destroy(e){const t=Object.keys(this.nsps);for(const e of t)if(this.nsps[e].active)return;this._close()}_packet(e){const t=this.encoder.encode(e);for(let s=0;s<t.length;s++)this.engine.write(t[s],e.options)}cleanup(){this.subs.forEach((e=>e())),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close"),this.engine&&this.engine.close()}disconnect(){return this._close()}onclose(e,t){this.cleanup(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",e,t),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const e=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const t=this.backoff.duration();this._reconnecting=!0;const s=this.setTimeoutFn((()=>{e.skipReconnect||(this.emitReserved("reconnect_attempt",e.backoff.attempts),e.skipReconnect||e.open((t=>{t?(e._reconnecting=!1,e.reconnect(),this.emitReserved("reconnect_error",t)):e.onreconnect()})))}),t);this.opts.autoUnref&&s.unref(),this.subs.push((()=>{this.clearTimeoutFn(s)}))}}onreconnect(){const e=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",e)}}const Oe={};function Ee(e,t){"object"==typeof e&&(t=e,e=void 0);const s=function(e,t="",s){let n=e;s=s||"undefined"!=typeof location&&location,null==e&&(e=s.protocol+"//"+s.host),"string"==typeof e&&("/"===e.charAt(0)&&(e="/"===e.charAt(1)?s.protocol+e:s.host+e),/^(https?|wss?):\/\//.test(e)||(e=void 0!==s?s.protocol+"//"+e:"https://"+e),n=se(e)),n.port||(/^(http|ws)$/.test(n.protocol)?n.port="80":/^(http|ws)s$/.test(n.protocol)&&(n.port="443")),n.path=n.path||"/";const o=-1!==n.host.indexOf(":")?"["+n.host+"]":n.host;return n.id=n.protocol+"://"+o+":"+n.port+t,n.href=n.protocol+"://"+o+(s&&s.port===n.port?"":":"+n.port),n}(e,(t=t||{}).path||"/socket.io"),n=s.source,o=s.id,i=s.path,r=Oe[o]&&i in Oe[o].nsps;let c;return t.forceNew||t["force new connection"]||!1===t.multiplex||r?c=new Ae(n,t):(Oe[o]||(Oe[o]=new Ae(n,t)),c=Oe[o]),s.query&&!t.query&&(t.query=s.queryKey),c.socket(s.path,t)}Object.assign(Ee,{Manager:Ae,Socket:Ie,io:Ee,connect:Ee});var Ce={notOpenAudioMsg:"麦克风没有开启",notOpenAudioCode:403,notOpenAudioMsgEn:"Permission dismissed"},Se={forbiddenAudioMsg:"请先检查您的麦克风是否开启",forbiddenAudioCode:0,forbiddenAudioMsgEn:"Permission denied"},Ne=function(){function c(e){var t=this;void 0===e&&(e={}),this.getWebrtcInfo=function(e,t){a.request(e+"/call/api/sip/webrtc/config/query",{verb:"GET",loginToken:a.loginToken,sessionId:a.agentInfo._id,success:function(e){e.success&&e.data?(a.agentextras=e.data,a.initWebrtcEvent(e.data)):t.error(o({},e))},error:function(e){t.error({error:e})}})},this.initAttachEvent=function(e,s,n,o,i){t.attachEventCallbacks&&a.request(e+"/platform/action/refreshWsToken",{verb:"GET",loginToken:a.loginToken,sessionId:a.agentInfo._id,success:function(e){if(e&&e.data){var r="";n.forEach((function(e){"KF"===e.id&&(r=e.url)})),t.attachEventCallbacks.serve=r,t.attachEventCallbacks.SocketOptions={query:{accountId:o.accountId,agentNumber:o.agentNumber,agentId:o._id,token:e.data.wsToken,wsExtra:JSON.stringify({loginType:s,channelType:"SDK",ability:["call"]}),timestamp:e.data.timestamp,clientType:1},reconnectionDelay:3e3,"force new connection":!0,transports:["websocket"],timeout:5e3},t.attachEventCallbacks.suc=i,a.createEventHandle(t.attachEventCallbacks)}},error:function(e){n.error({error:e})}})},this.openMediaAudio=function(e,t){var s=navigator,n=s.mediaDevices,o=s.getUserMedia,i=s.webkitGetUserMedia,r=s.mozGetUserMedia,c=s.msGetUserMedia,a=(o||i||r||c).bind(navigator);return n?navigator.mediaDevices.getUserMedia({audio:!0}).catch((function(s){var n=s.message.includes("denied");return t?(n&&alert(Se.forbiddenAudioMsg),e&&!n&&alert(e),n?Se:Ce):n?Se:Ce})):new Promise((function(s,n){a?a({audio:!0},(function(e){s(!0)}),(function(s){t&&e&&alert(e),n(Ce)})):n(Ce)}))},this.listenCallEvent=function(e){t.attachEventCallbacks=e},this._callApi=function(){var e,s,n=t;return{callout:function(t){return i(this,void 0,void 0,(function(){var i,c,u,l,h,p;return r(this,(function(r){switch(r.label){case 0:if(t.success=t&&"function"==typeof t.success?t.success:a.noop,t.fail=t&&"function"==typeof t.fail?t.fail:a.noop,null===a.loginToken||void 0===a.loginToken)return t.fail({success:!1,message:"initialization not complete!"}),[2];if(null===a.agentInfo||void 0===a.agentInfo)return t.fail({success:!1,message:"initialization not complete!"}),[2];if(null===t.customerNumber||void 0===t.customerNumber)return t.fail({success:!1,message:"Parameter customerNumber is required!"}),[2];if(i=a.initOptions.server||a.callApiUrl,c={customerNumber:t.customerNumber,agentNumber:a.agentInfo.agentNumber,accountId:a.agentInfo.accountId,agentId:a.agentInfo._id,loginType:t.loginType||a.agentInfo.loginType||a.initOptions.loginType},t.agentTimeout&&(c.agentTimeout=t.agentTimeout),t.customerTimeout&&(c.customerTimeout=t.customerTimeout),t.agentDisNumber&&(c.agentDisNumber=t.agentDisNumber),t.customerDisNumber&&(c.customerDisNumber=t.customerDisNumber),t.extras&&(c.extras=t.extras),u=a.initOptions,l=!0,"WEBRTC"!==u.loginType)return[3,4];r.label=1;case 1:return r.trys.push([1,3,,4]),[4,n.openMediaAudio("请打开麦克风权限!",l)];case 2:return h=r.sent()||{},[3,4];case 3:return p=r.sent(),console.log(p),[3,4];case 4:return a.request(i+"/call/api/call/call/out",{verb:"POST",body:c,loginToken:a.loginToken,sessionId:a.agentInfo._id,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?t.success(o({success:!0,message:"callout success"},h)):t.fail(o({success:!1,message:e.message,code:e.code},h))}}),[2]}}))}))},hangup:function(t){if(t.success=t&&"function"==typeof t.success?t.success:a.noop,t.fail=t&&"function"==typeof t.fail?t.fail:a.noop,null!==a.loginToken&&void 0!==a.loginToken)if(null!==a.agentInfo&&void 0!==a.agentInfo){var n=a.initOptions.server||a.callApiUrl;a.request(n+"/call/api/call/hangup",{verb:"POST",body:{},loginToken:a.loginToken,sessionId:a.agentInfo._id,accountId:a.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?t.success({success:!0,message:"hangup success",data:e.data.response.data}):t.fail({success:!1,message:e.message,code:e.code})}})}else t.fail({success:!1,message:"initialization not complete!"});else t.fail({success:!1,message:"initialization not complete!"})},holdOrUnHold:function(t){if(t.success=t&&"function"==typeof t.success?t.success:a.noop,t.fail=t&&"function"==typeof t.fail?t.fail:a.noop,null!==a.loginToken&&void 0!==a.loginToken)if(null!==a.agentInfo&&void 0!==a.agentInfo)if(null!==t.type&&void 0!==t.type){var n=a.initOptions.server||a.callApiUrl,o={type:t.type};a.request(n+"/call/api/call/hold",{verb:"POST",body:o,loginToken:a.loginToken,sessionId:a.agentInfo._id,accountId:a.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?t.success({success:!0,message:"holdOrUnHold success"}):t.fail({success:!1,message:e.message,code:e.code})}})}else t.fail({success:!1,message:"Parameter type is required!"});else t.fail({success:!1,message:"initialization not complete!"});else t.fail({success:!1,message:"initialization not complete!"})},muteOrUnMute:function(t){if(t.success=t&&"function"==typeof t.success?t.success:a.noop,t.fail=t&&"function"==typeof t.fail?t.fail:a.noop,null!==a.loginToken&&void 0!==a.loginToken)if(null!==a.agentInfo&&void 0!==a.agentInfo)if(null!==t.type&&void 0!==t.type){var n=a.initOptions.server||a.callApiUrl,o={type:t.type,direction:t.direction||"all"};a.request(n+"/call/api/call/mute",{verb:"POST",body:o,loginToken:a.loginToken,sessionId:a.agentInfo._id,accountId:a.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?t.success({success:!0,message:"muteOrUnMute success"}):t.fail({success:!1,message:e.message,code:e.code})}})}else t.fail({success:!1,message:"Parameter type is required!"});else t.fail({success:!1,message:"initialization not complete!"});else t.fail({success:!1,message:"initialization not complete!"})},transfer:function(t){if(t.success=t&&"function"==typeof t.success?t.success:a.noop,t.fail=t&&"function"==typeof t.fail?t.fail:a.noop,null!==a.loginToken&&void 0!==a.loginToken)if(null!==a.agentInfo&&void 0!==a.agentInfo)if(null!==t.type&&void 0!==t.type)if(null!==t.number&&void 0!==t.number){var n=a.initOptions.server||a.callApiUrl;a.request(n+"/call/api/call/transfer",{verb:"POST",body:t,loginToken:a.loginToken,sessionId:a.agentInfo._id,accountId:a.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?t.success({success:!0,message:"transfer success",data:e.data.response.data}):t.fail({success:!1,message:e.message,code:e.code})}})}else t.fail({success:!1,message:"Parameter number is required!"});else t.fail({success:!1,message:"Parameter type is required!"});else t.fail({success:!1,message:"initialization not complete!"});else t.fail({success:!1,message:"initialization not complete!"})},consult:function(t){if(t.success=t&&"function"==typeof t.success?t.success:a.noop,t.fail=t&&"function"==typeof t.fail?t.fail:a.noop,null!==a.loginToken&&void 0!==a.loginToken)if(null!==a.agentInfo&&void 0!==a.agentInfo)if(null!==t.mode&&void 0!==t.mode)if(null!==t.number&&void 0!==t.number)if(null!==t.agentNumber&&void 0!==t.agentNumber){var n=a.initOptions.server||a.callApiUrl;a.request(n+"/call/api/call/consult",{verb:"POST",body:t,loginToken:a.loginToken,sessionId:a.agentInfo._id,accountId:a.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?t.success({success:!0,message:"consult success",data:e.data.response.data}):t.fail({success:!1,message:e.message,code:e.code})}})}else t.fail({success:!1,message:"Parameter agentNumber is required!"});else t.fail({success:!1,message:"Parameter number is required!"});else t.fail({success:!1,message:"Parameter mode is required!"});else t.fail({success:!1,message:"initialization not complete!"});else t.fail({success:!1,message:"initialization not complete!"})},cancelconsult:function(t){if(t.success=t&&"function"==typeof t.success?t.success:a.noop,t.fail=t&&"function"==typeof t.fail?t.fail:a.noop,null!==a.loginToken&&void 0!==a.loginToken)if(null!==a.agentInfo&&void 0!==a.agentInfo){var n=a.initOptions.server||a.callApiUrl;a.request(n+"/call/api/call/consult/cancel",{verb:"POST",body:t,loginToken:a.loginToken,sessionId:a.agentInfo._id,accountId:a.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?t.success({success:!0,message:"cancelconsult success",data:e.data.response.data}):t.fail({success:!1,message:e.message,code:e.code})}})}else t.fail({success:!1,message:"initialization not complete!"});else t.fail({success:!1,message:"initialization not complete!"})},endConsult:function(t){if(t.success=t&&"function"==typeof t.success?t.success:a.noop,t.fail=t&&"function"==typeof t.fail?t.fail:a.noop,null!==a.loginToken&&void 0!==a.loginToken)if(null!==a.agentInfo&&void 0!==a.agentInfo){var n=a.initOptions.server||a.callApiUrl;a.request(n+"/call/api/call/consult/stop",{verb:"POST",body:t,loginToken:a.loginToken,sessionId:a.agentInfo._id,accountId:a.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?t.success({success:!0,message:"endConsult success",data:e.data.response.data}):t.fail({success:!1,message:e.message,code:e.code})}})}else t.fail({success:!1,message:"initialization not complete!"});else t.fail({success:!1,message:"initialization not complete!"})},callbackConsult:function(t){if(t.success=t&&"function"==typeof t.success?t.success:a.noop,t.fail=t&&"function"==typeof t.fail?t.fail:a.noop,null!==a.loginToken&&void 0!==a.loginToken)if(null!==a.agentInfo&&void 0!==a.agentInfo){var n=a.initOptions.server||a.callApiUrl;a.request(n+"/call/api/call/consult/resume",{verb:"POST",body:t,loginToken:a.loginToken,sessionId:a.agentInfo._id,accountId:a.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?t.success({success:!0,message:"resumeConsult success",data:e.data.response.data}):t.fail({success:!1,message:e.message,code:e.code})}})}else t.fail({success:!1,message:"initialization not complete!"});else t.fail({success:!1,message:"initialization not complete!"})},consultTransfer:function(t){if(t.success=t&&"function"==typeof t.success?t.success:a.noop,t.fail=t&&"function"==typeof t.fail?t.fail:a.noop,null!==a.loginToken&&void 0!==a.loginToken)if(null!==a.agentInfo&&void 0!==a.agentInfo){var n=a.initOptions.server||a.callApiUrl;a.request(n+"/call/api/call/consult/transfer",{verb:"POST",body:t,loginToken:a.loginToken,sessionId:a.agentInfo._id,accountId:a.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?t.success({success:!0,message:"consultTransfer success",data:e.data.response.data}):t.fail({success:!1,message:e.message,code:e.code})}})}else t.fail({success:!1,message:"initialization not complete!"});else t.fail({success:!1,message:"initialization not complete!"})},threeWayCall:function(t){if(t.success=t&&"function"==typeof t.success?t.success:a.noop,t.fail=t&&"function"==typeof t.fail?t.fail:a.noop,null!==a.loginToken&&void 0!==a.loginToken)if(null!==a.agentInfo&&void 0!==a.agentInfo){var n=a.initOptions.server||a.callApiUrl;a.request(n+"/call/api/call/threeway",{verb:"POST",body:t,loginToken:a.loginToken,sessionId:a.agentInfo._id,accountId:a.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?t.success({success:!0,message:"threeWayCall success",data:e.data.response.data}):t.fail({success:!1,message:e.message,code:e.code})}})}else t.fail({success:!1,message:"initialization not complete!"});else t.fail({success:!1,message:"initialization not complete!"})},evaluate:function(t){if(t.success=t&&"function"==typeof t.success?t.success:a.noop,t.fail=t&&"function"==typeof t.fail?t.fail:a.noop,null!==a.loginToken&&void 0!==a.loginToken)if(null!==a.agentInfo&&void 0!==a.agentInfo)if(null!==t.type&&void 0!==t.type){var n=a.initOptions.server||a.callApiUrl;a.request(n+"/call/api/call/evaluate",{verb:"POST",body:t,loginToken:a.loginToken,sessionId:a.agentInfo._id,accountId:a.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?t.success({success:!0,message:"evaluate success",data:e.data.response.data}):t.fail({success:!1,message:e.message,code:e.code})}})}else t.fail({success:!1,message:"Parameter type is required!"});else t.fail({success:!1,message:"initialization not complete!"});else t.fail({success:!1,message:"initialization not complete!"})},meeting:function(t){if(t.success=t&&"function"==typeof t.success?t.success:a.noop,t.fail=t&&"function"==typeof t.fail?t.fail:a.noop,null!==a.loginToken&&void 0!==a.loginToken)if(null!==a.agentInfo&&void 0!==a.agentInfo)if(null!==t.number&&void 0!==t.number){var n=a.initOptions.server||a.callApiUrl;a.request(n+"/call/api/call/meeting",{verb:"POST",body:{meetingType:"phone",number:t.number},loginToken:a.loginToken,sessionId:a.agentInfo._id,accountId:a.agentInfo.accountId,encryptionAlgorithm:e,encryptionFields:s,success:function(e){e.success?t.success({success:!0,message:"meeting success",data:e.data.response.data}):t.fail({success:!1,message:e.message,code:e.code})}})}else t.fail({success:!1,message:"Parameter number is required!"});else t.fail({success:!1,message:"initialization not complete!"});else t.fail({success:!1,message:"initialization not complete!"})}}},this._agentApi=function(){var e=t;return{switchLoginType:function(t){return i(this,void 0,void 0,(function(){var s,n,c,u,l,h,p=this;return r(this,(function(f){switch(f.label){case 0:if(s=null,t.success=t&&"function"==typeof t.success?t.success:a.noop,t.fail=t&&"function"==typeof t.fail?t.fail:a.noop,null===t.loginType||void 0===t.loginType)return t.fail({success:!1,message:"Parameter loginType is required!"}),[2];if(null===a.agentInfo||void 0===a.agentInfo)return t.fail({success:!1,message:"initialization not complete!"}),[2];if(null!==t.loginNumber&&void 0!==t.loginNumber&&(s=t.loginNumber),"PSTN"===t.loginType&&!(s=s||a.agentInfo.mobile))return alert("请给座席绑定手机号,或者传入号码参数!"),t.fail({success:!1,message:"Please bind your mobile number"}),[2];if("SIP"===t.loginType&&(s=s||a.agentInfo.sipNumber),"WEBRTC"===t.loginType&&(s=a.agentInfo.webrtcSipNumber),n=a.initOptions.server||a.callApiUrl,c={loginType:t.loginType,loginNumber:s},a.initOptions,l=!0,"WEBRTC"!==t.loginType)return[3,4];f.label=1;case 1:return f.trys.push([1,3,,4]),[4,e.openMediaAudio("请打开麦克风权限!",l)];case 2:return u=f.sent()||{},[3,4];case 3:return h=f.sent(),console.log(h),[3,4];case 4:return a.request(n+"/call/api/agent/v1/login-type/change",{verb:"POST",body:c,loginToken:a.loginToken,sessionId:a.agentInfo._id,accountId:a.agentInfo.accountId,success:function(s){return i(p,void 0,void 0,(function(){return r(this,(function(i){switch(i.label){case 0:return s.success?(t.success(o({success:!0,message:"updateLoginType success"},u)),a.agentInfo.loginType=t.loginType,"WEBRTC"!==t.loginType?[3,1]:(e._webPhoneApi().connect(),[3,4])):[3,5];case 1:return"PSTN"!==t.loginType?[3,3]:[4,a.request(n+"/platform/action/updateCallConfig",{verb:"POST",body:{agentCallConfig:{},mobile:t.loginNumber},loginToken:a.loginToken,sessionId:a.agentInfo._id,accountId:a.agentInfo.accountId})];case 2:return i.sent(),e._webPhoneApi().disconnect(),[3,4];case 3:e._webPhoneApi().disconnect(),i.label=4;case 4:return[3,6];case 5:t.fail(o({success:!1,message:s.message,code:s.code},u)),i.label=6;case 6:return[2]}}))}))}}),[2]}}))}))},findPhoneBarList:function(e){if(e.success=e&&"function"==typeof e.success?e.success:a.noop,e.fail=e&&"function"==typeof e.fail?e.fail:a.noop,null!==a.agentInfo&&void 0!==a.agentInfo){var t=a.initOptions.server||a.callApiUrl;a.request(t+"/call/api/phone/bar/all",{verb:"GET",loginToken:a.loginToken,sessionId:a.agentInfo._id,accountId:a.agentInfo.accountId,success:function(t){if(t.success){var s=[];t.data.forEach((function(e){var t={name:e.name,number:e.number};s.push(t)})),e.success({success:!0,data:s})}else e.fail({success:!1,message:t.message,code:t.code})}})}else e.fail({success:!1,message:"initialization not complete!"})},switchPhoneBar:function(e){if(e.success=e&&"function"==typeof e.success?e.success:a.noop,e.fail=e&&"function"==typeof e.fail?e.fail:a.noop,null!==e.stateNumber&&void 0!==e.stateNumber)if(null!==a.agentInfo&&void 0!==a.agentInfo){var t=a.initOptions.server||a.callApiUrl,s={stateNumber:e.stateNumber,accountId:a.agentInfo.accountId,agentNumber:a.agentInfo.agentNumber};a.request(t+"/call/api/agent/status/switch",{verb:"POST",body:s,loginToken:a.loginToken,sessionId:a.agentInfo._id,success:function(t){t.success?e.success({success:!0}):e.fail({success:!1,message:t.message,code:t.code})}})}else e.fail({success:!1,message:"initialization not complete!"});else e.fail({success:!1,message:"Parameter stateNumber is required!"})},logout:function(e){if(e.success=e&&"function"==typeof e.success?e.success:a.noop,e.fail=e&&"function"==typeof e.fail?e.fail:a.noop,null!==a.agentInfo&&void 0!==a.agentInfo){null!==e.toAnswerOffline&&void 0!==e.toAnswerOffline||(e.toAnswerOffline="1");var t=a.initOptions.server||a.callApiUrl,s={toAnswerOffline:e.toAnswerOffline};a.request(t+"/call/api/sdk/agent/logout",{verb:"POST",body:s,loginToken:a.loginToken,sessionId:a.agentInfo._id,accountId:a.agentInfo.accountId,success:function(t){t.success?e&&(a.Socketinstance.disconnect(),"WEBRTC"===a.agentInfo.loginType&&a.webPhone.disconnect(),e.success({success:!0})):e&&e.fail({success:!1,message:t.message,code:t.code})}})}else e.fail({success:!1,message:"initialization not complete!"})},findIdleAgentsForQueue:function(e){if(e.success=e&&"function"==typeof e.success?e.success:a.noop,e.fail=e&&"function"==typeof e.fail?e.fail:a.noop,null!==a.agentInfo&&void 0!==a.agentInfo){var t=a.initOptions.server||a.callApiUrl;a.request(t+"/call/api/queue/acountFreeAgent/find",{verb:"POST",body:{},loginToken:a.loginToken,sessionId:a.agentInfo._id,accountId:a.agentInfo.accountId,success:function(t){t.success?e&&e.success({success:!0,dataList:t.data||[]}):e&&e.fail({success:!1,message:t.message,code:t.code})}})}else e.fail({success:!1,message:"initialization not complete!"})},getAvailableSipNumberList:function(e){if(e.success=e&&"function"==typeof e.success?e.success:a.noop,e.fail=e&&"function"==typeof e.fail?e.fail:a.noop,null!==a.agentInfo&&void 0!==a.agentInfo){var t=a.initOptions.server||a.callApiUrl;a.request(t+"/call/api/sip/avaliable/query",{verb:"POST",body:{},loginToken:a.loginToken,sessionId:a.agentInfo._id,success:function(t){if(t.success&&t.data){var s=[];t.data.forEach((function(e){var t={number:e.id,numberName:e.number};s.push(t)})),e.success({success:!0,data:s})}else e.fail({success:!1,message:t.message,code:t.code})}})}else e.fail({success:!1,message:"initialization not complete!"})}}},this._webPhoneApi=function(){return{accept:function(){a.webPhone.accept()},connect:function(){a.webPhone&&this.isConnected()||a.initWebrtcEvent(a.agentextras)},disconnect:function(){a.webPhone&&this.isConnected()&&a.webPhone.disconnect()},isConnected:function(){return a.webPhone.isConnected()},sendDTMF:function(e){a.webPhone.sendDTMF(e)}}},e.error="function"==typeof e.error?e.error:a.noop,e.success="function"==typeof e.success?e.success:a.noop,null!==e.agentNumber&&void 0!==e.agentNumber?(null!==e.loginType&&void 0!==e.loginType||(e.loginType="PSTN"),this.init(e)):e.error({message:"Invalid agentNumber"})}var a;return c.noop=function(){},c.prototype.init=function(e){if(void 0===e&&(e={}),a.trace=a.noop,a.debug=a.noop,a.log=a.noop,a.warn=a.noop,a.error=a.noop,!0===e.debug||"all"===e.debug)a.trace=console.trace.bind(console),a.debug=console.debug.bind(console),a.log=console.log.bind(console),a.warn=console.warn.bind(console),a.error=console.error.bind(console);else if(Array.isArray(e.debug))for(var t in e.debug){var s=e.debug[t];switch(s){case"trace":a.trace=console.trace.bind(console);break;case"debug":a.debug=console.debug.bind(console);break;case"log":a.log=console.log.bind(console);break;case"warn":a.warn=console.warn.bind(console);break;case"error":a.error=console.error.bind(console);break;default:console.error("Unknown debugging option '"+s+"' (supported: 'trace', 'debug', 'log', warn', 'error')")}}a.log("Initializing library");var n=a.useDefaultDependencies({WebSocket:Pe});a.newWebSocket=n.newWebSocket,a.request=n.request,this.login(e)},c.prototype.login=function(e){return i(this,void 0,void 0,(function(){var i,c,u,l,h,p,f,d=this;return r(this,(function(r){switch(r.label){case 0:if(i=e.server||a.callApiUrl,c=e.agentNumber+"@"+e.accountId,u=e.loginType,l={loginName:c,loginType:u,loginChannel:"SDK",password:""},h=!0,"WEBRTC"!==u)return[3,4];r.label=1;case 1:return r.trys.push([1,3,,4]),[4,this.openMediaAudio("请打开麦克风权限!",h)];case 2:return p=r.sent()||{},[3,4];case 3:return f=r.sent(),console.log(f),[3,4];case 4:return e.password&&(l.password=e.password),a.request(i+"/platform/public/loginPre",{verb:"GET",success:function(r){if(r&&r.success&&r.data){var c=decodeURIComponent(t.decode(r.data.pk)),h=new n;h.setPublicKey(c);var f=s(l.password),g=h.encrypt(f);l.password=g,a.request(i+"/platform/public/login",{verb:"POST",body:l,success:function(t){t.success?a.request(i+"/platform/action/loginInfo",{verb:"GET",loginToken:t.data.loginToken,sessionId:t.data.sessionId,success:function(t){t.success?(t.data.agent&&(a.agentInfo=t.data.agent,a.loginToken=t.data.loginToken,a.initOptions=o(o({},e),{audioInfo:p})),d.initAttachEvent(i,u,t.data.pushServer,t.data.agent,e.success),"WEBRTC"===u&&d.getWebrtcInfo(i,e)):e.error(o(o({},t),p))},error:function(t){e.error(o({error:t},p))}}):e.error(o(o({},t),p))},error:function(t){e.error(o({error:t},p))}})}else e.error(o(o({},r),p))},error:function(t){e.error(o({error:t},p))}}),[2]}}))}))},c.createEventHandle=function(e){var t=this;void 0===e&&(e={}),e.success="function"==typeof e.success?e.success:a.noop,e.error="function"==typeof e.error?e.error:a.noop,e.message="function"==typeof e.message?e.message:a.noop,e.event="function"==typeof e.event?e.event:a.noop,e.server=null===e.serve||void 0===e.serve?"ws://152.136.72.209:3201/phoneBarGateway":e.serve,null!==e.SocketOptions&&void 0!==e.SocketOptions||(e.SocketOptions={},a.error({message:"login response error!"})),this.Socketinstance=a.newWebSocket(e.server,e.SocketOptions),this.Socketinstance.on("connect",(function(){e.success("connect event serve success!"),e.suc()})),this.Socketinstance.on("error",(function(t,s){e.error({type:"socketError",error:t}),s&&"function"==typeof s&&s("error")})),this.Socketinstance.on("message",(function(t,s){e.message({subtype:t.subType,data:t.data}),s&&"function"==typeof s&&s("success")})),this.Socketinstance.on("event",(function(s){if("KICK_OFF"===s.subType){t.Socketinstance.disconnect();try{a.webPhone.disconnect()}catch(e){}e.event({message:"坐席账户在其他地方登录"})}}))},c.useDefaultDependencies=function(e){var t=e&&e.fetch||fetch,s=e&&e.Promise||Promise,n=e&&e.WebSocket||WebSocket;return{newWebSocket:function(e,t){return new n(e,t)},request:function(e,n){var o={method:n.verb,cache:"no-cache",headers:{"Content-Type":"application/json",loginToken:n.loginToken||"",sessionId:n.sessionId||"",clienttype:0}};n.encryptionFields&&(o.headers["ue-encryption-algorithm"]=n.encryptionAlgorithm||"aes",o.headers["ue-encryption-fields"]=n.encryptionFields),void 0!==n.withCredentials&&(o.credentials=!0===n.withCredentials?"include":n.withCredentials?n.withCredentials:"omit"),void 0!==n.body&&(o.body=JSON.stringify(n.body));var i=t(e,o).catch((function(e){return s.reject({message:"Probably a network error, is the gateway down?",error:e})}));if(void 0!==n.timeout){var r=new s((function(e,t){var s=window.setTimeout((function(){return clearTimeout(s),n.error({message:"Request timed out",timeout:n.timeout}),t({message:"Request timed out",timeout:n.timeout})}),n.timeout)}));i=s.race([i,r])}return i.then((function(e){return e.ok?typeof n.success==typeof a.noop?e.json().then((function(e){n.success(e)})).catch((function(t){return n.error({message:"Failed to parse response body",error:t,response:e}),s.reject({message:"Failed to parse response body",error:t,response:e})})):void 0:(n.error({message:"API call failed",response:e}),s.reject({message:"API call failed",response:e}))})).catch((function(e){typeof n.error==typeof a.noop&&n.error(e.message||"<< internal error >>",e)})),i}}},Object.defineProperty(c.prototype,"agent",{get:function(){return this._agentApi()},enumerable:!1,configurable:!0}),Object.defineProperty(c.prototype,"webrtc",{get:function(){return this._webPhoneApi()},enumerable:!1,configurable:!0}),Object.defineProperty(c.prototype,"call",{get:function(){return this._callApi()},enumerable:!1,configurable:!0}),a=c,c.callApiUrl="https://app.useasy.cn/api",c.Socketinstance=null,c.initWebrtcEvent=function(t){return i(void 0,void 0,void 0,(function(){return r(a,(function(s){switch(s.label){case 0:return a.webPhone=new e({server:t.wssUrl,sip:t.sip,secret:t.password}),[4,this.webPhone.connect()];case 1:return s.sent(),this.webPhone.register(),[2]}}))}))},c}(),Pe=function(){function e(e,t){delete t.path,delete t.hostname,delete t.port,this.ws=Ee.connect("wss://".concat(e),t)}return e.prototype.on=function(e,t){"connect"===e&&this.ws.on(e,t),"error"===e&&(this.ws.on("connect_error",t),this.ws.on("error",t),this.ws.on("disconnect",t),this.ws.on("reconnect_failed",t)),"message"===e&&this.ws.on("call",t),"event"===e&&this.ws.on("event",t)},e.prototype.emit=function(e,t,s){this.ws.emit(e,t,s)},e.prototype.disconnect=function(){this.ws.disconnect()},e}();export{Ne as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ue-softphone-sdk",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "ue-softphone-sdk",
5
5
  "main": "dist/ue-softphone-sdk.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -16,7 +16,6 @@
16
16
  "js-base64": "^3.7.2",
17
17
  "js-md5": "^0.7.3",
18
18
  "jsencrypt": "^3.2.1",
19
- "socket.io-client": "^4.6.1",
20
19
  "ue-webrtc": "^1.0.2"
21
20
  },
22
21
  "devDependencies": {
package/src/index.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  /**package.json 版本号 */
11
11
  // @ts-ignore: Unreachable code error
12
12
  // import { Parameters } from './grammar/parameters.js'
13
- import io from "socket.io-client";
13
+ import io from "./lib/socket.io.esm.min.js";
14
14
  import { AUDIO_FORBIDDEN, DENIED, NOT_OPEN_AUDIO } from "./config";
15
15
  import { UeWebrtc } from "ue-webrtc";
16
16
 
@@ -0,0 +1,7 @@
1
+ /*!
2
+ * Socket.IO v4.7.2
3
+ * (c) 2014-2023 Guillermo Rauch
4
+ * Released under the MIT License.
5
+ */
6
+ const t=Object.create(null);t.open="0",t.close="1",t.ping="2",t.pong="3",t.message="4",t.upgrade="5",t.noop="6";const e=Object.create(null);Object.keys(t).forEach((s=>{e[t[s]]=s}));const s={type:"error",data:"parser error"},n="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),i="function"==typeof ArrayBuffer,r=t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t&&t.buffer instanceof ArrayBuffer,o=({type:e,data:s},o,h)=>n&&s instanceof Blob?o?h(s):a(s,h):i&&(s instanceof ArrayBuffer||r(s))?o?h(s):a(new Blob([s]),h):h(t[e]+(s||"")),a=(t,e)=>{const s=new FileReader;return s.onload=function(){const t=s.result.split(",")[1];e("b"+(t||""))},s.readAsDataURL(t)};function h(t){return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}let c;const u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",p="undefined"==typeof Uint8Array?[]:new Uint8Array(256);for(let t=0;t<64;t++)p[u.charCodeAt(t)]=t;const l="function"==typeof ArrayBuffer,d=(t,n)=>{if("string"!=typeof t)return{type:"message",data:y(t,n)};const i=t.charAt(0);if("b"===i)return{type:"message",data:f(t.substring(1),n)};return e[i]?t.length>1?{type:e[i],data:t.substring(1)}:{type:e[i]}:s},f=(t,e)=>{if(l){const s=(t=>{let e,s,n,i,r,o=.75*t.length,a=t.length,h=0;"="===t[t.length-1]&&(o--,"="===t[t.length-2]&&o--);const c=new ArrayBuffer(o),u=new Uint8Array(c);for(e=0;e<a;e+=4)s=p[t.charCodeAt(e)],n=p[t.charCodeAt(e+1)],i=p[t.charCodeAt(e+2)],r=p[t.charCodeAt(e+3)],u[h++]=s<<2|n>>4,u[h++]=(15&n)<<4|i>>2,u[h++]=(3&i)<<6|63&r;return c})(t);return y(s,e)}return{base64:!0,data:t}},y=(t,e)=>"blob"===e?t instanceof Blob?t:new Blob([t]):t instanceof ArrayBuffer?t:t.buffer,g=String.fromCharCode(30);function m(){return new TransformStream({transform(t,e){!function(t,e){n&&t.data instanceof Blob?t.data.arrayBuffer().then(h).then(e):i&&(t.data instanceof ArrayBuffer||r(t.data))?e(h(t.data)):o(t,!1,(t=>{c||(c=new TextEncoder),e(c.encode(t))}))}(t,(s=>{const n=s.length;let i;if(n<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,n);else if(n<65536){i=new Uint8Array(3);const t=new DataView(i.buffer);t.setUint8(0,126),t.setUint16(1,n)}else{i=new Uint8Array(9);const t=new DataView(i.buffer);t.setUint8(0,127),t.setBigUint64(1,BigInt(n))}t.data&&"string"!=typeof t.data&&(i[0]|=128),e.enqueue(i),e.enqueue(s)}))}})}let b;function v(t){return t.reduce(((t,e)=>t+e.length),0)}function w(t,e){if(t[0].length===e)return t.shift();const s=new Uint8Array(e);let n=0;for(let i=0;i<e;i++)s[i]=t[0][n++],n===t[0].length&&(t.shift(),n=0);return t.length&&n<t[0].length&&(t[0]=t[0].slice(n)),s}function k(t){if(t)return function(t){for(var e in k.prototype)t[e]=k.prototype[e];return t}(t)}k.prototype.on=k.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},k.prototype.once=function(t,e){function s(){this.off(t,s),e.apply(this,arguments)}return s.fn=e,this.on(t,s),this},k.prototype.off=k.prototype.removeListener=k.prototype.removeAllListeners=k.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var s,n=this._callbacks["$"+t];if(!n)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var i=0;i<n.length;i++)if((s=n[i])===e||s.fn===e){n.splice(i,1);break}return 0===n.length&&delete this._callbacks["$"+t],this},k.prototype.emit=function(t){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),s=this._callbacks["$"+t],n=1;n<arguments.length;n++)e[n-1]=arguments[n];if(s){n=0;for(var i=(s=s.slice(0)).length;n<i;++n)s[n].apply(this,e)}return this},k.prototype.emitReserved=k.prototype.emit,k.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},k.prototype.hasListeners=function(t){return!!this.listeners(t).length};const _="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function E(t,...e){return e.reduce(((e,s)=>(t.hasOwnProperty(s)&&(e[s]=t[s]),e)),{})}const A=_.setTimeout,O=_.clearTimeout;function T(t,e){e.useNativeTimers?(t.setTimeoutFn=A.bind(_),t.clearTimeoutFn=O.bind(_)):(t.setTimeoutFn=_.setTimeout.bind(_),t.clearTimeoutFn=_.clearTimeout.bind(_))}class R extends Error{constructor(t,e,s){super(t),this.description=e,this.context=s,this.type="TransportError"}}class C extends k{constructor(t){super(),this.writable=!1,T(this,t),this.opts=t,this.query=t.query,this.socket=t.socket}onError(t,e,s){return super.emitReserved("error",new R(t,e,s)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(t){"open"===this.readyState&&this.write(t)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(t){const e=d(t,this.socket.binaryType);this.onPacket(e)}onPacket(t){super.emitReserved("packet",t)}onClose(t){this.readyState="closed",super.emitReserved("close",t)}pause(t){}createUri(t,e={}){return t+"://"+this._hostname()+this._port()+this.opts.path+this._query(e)}_hostname(){const t=this.opts.hostname;return-1===t.indexOf(":")?t:"["+t+"]"}_port(){return this.opts.port&&(this.opts.secure&&Number(443!==this.opts.port)||!this.opts.secure&&80!==Number(this.opts.port))?":"+this.opts.port:""}_query(t){const e=function(t){let e="";for(let s in t)t.hasOwnProperty(s)&&(e.length&&(e+="&"),e+=encodeURIComponent(s)+"="+encodeURIComponent(t[s]));return e}(t);return e.length?"?"+e:""}}const B="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),N=64,S={};let x,L=0,q=0;function P(t){let e="";do{e=B[t%N]+e,t=Math.floor(t/N)}while(t>0);return e}function j(){const t=P(+new Date);return t!==x?(L=0,x=t):t+"."+P(L++)}for(;q<N;q++)S[B[q]]=q;let U=!1;try{U="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(t){}const D=U;function I(t){const e=t.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!e||D))return new XMLHttpRequest}catch(t){}if(!e)try{return new(_[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(t){}}function F(){}const M=null!=new I({xdomain:!1}).responseType;class V extends k{constructor(t,e){super(),T(this,e),this.opts=e,this.method=e.method||"GET",this.uri=t,this.data=void 0!==e.data?e.data:null,this.create()}create(){var t;const e=E(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");e.xdomain=!!this.opts.xd;const s=this.xhr=new I(e);try{s.open(this.method,this.uri,!0);try{if(this.opts.extraHeaders){s.setDisableHeaderCheck&&s.setDisableHeaderCheck(!0);for(let t in this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(t)&&s.setRequestHeader(t,this.opts.extraHeaders[t])}}catch(t){}if("POST"===this.method)try{s.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(t){}try{s.setRequestHeader("Accept","*/*")}catch(t){}null===(t=this.opts.cookieJar)||void 0===t||t.addCookies(s),"withCredentials"in s&&(s.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(s.timeout=this.opts.requestTimeout),s.onreadystatechange=()=>{var t;3===s.readyState&&(null===(t=this.opts.cookieJar)||void 0===t||t.parseCookies(s)),4===s.readyState&&(200===s.status||1223===s.status?this.onLoad():this.setTimeoutFn((()=>{this.onError("number"==typeof s.status?s.status:0)}),0))},s.send(this.data)}catch(t){return void this.setTimeoutFn((()=>{this.onError(t)}),0)}"undefined"!=typeof document&&(this.index=V.requestsCount++,V.requests[this.index]=this)}onError(t){this.emitReserved("error",t,this.xhr),this.cleanup(!0)}cleanup(t){if(void 0!==this.xhr&&null!==this.xhr){if(this.xhr.onreadystatechange=F,t)try{this.xhr.abort()}catch(t){}"undefined"!=typeof document&&delete V.requests[this.index],this.xhr=null}}onLoad(){const t=this.xhr.responseText;null!==t&&(this.emitReserved("data",t),this.emitReserved("success"),this.cleanup())}abort(){this.cleanup()}}if(V.requestsCount=0,V.requests={},"undefined"!=typeof document)if("function"==typeof attachEvent)attachEvent("onunload",H);else if("function"==typeof addEventListener){addEventListener("onpagehide"in _?"pagehide":"unload",H,!1)}function H(){for(let t in V.requests)V.requests.hasOwnProperty(t)&&V.requests[t].abort()}const K="function"==typeof Promise&&"function"==typeof Promise.resolve?t=>Promise.resolve().then(t):(t,e)=>e(t,0),Y=_.WebSocket||_.MozWebSocket,W="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase();const z={websocket:class extends C{constructor(t){super(t),this.supportsBinary=!t.forceBase64}get name(){return"websocket"}doOpen(){if(!this.check())return;const t=this.uri(),e=this.opts.protocols,s=W?{}:E(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(s.headers=this.opts.extraHeaders);try{this.ws=W?new Y(t,e,s):e?new Y(t,e):new Y(t)}catch(t){return this.emitReserved("error",t)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let e=0;e<t.length;e++){const s=t[e],n=e===t.length-1;o(s,this.supportsBinary,(t=>{try{this.ws.send(t)}catch(t){}n&&K((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){void 0!==this.ws&&(this.ws.close(),this.ws=null)}uri(){const t=this.opts.secure?"wss":"ws",e=this.query||{};return this.opts.timestampRequests&&(e[this.opts.timestampParam]=j()),this.supportsBinary||(e.b64=1),this.createUri(t,e)}check(){return!!Y}},webtransport:class extends C{get name(){return"webtransport"}doOpen(){"function"==typeof WebTransport&&(this.transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name]),this.transport.closed.then((()=>{this.onClose()})).catch((t=>{this.onError("webtransport error",t)})),this.transport.ready.then((()=>{this.transport.createBidirectionalStream().then((t=>{const e=function(t,e){b||(b=new TextDecoder);const n=[];let i=0,r=-1,o=!1;return new TransformStream({transform(a,h){for(n.push(a);;){if(0===i){if(v(n)<1)break;const t=w(n,1);o=128==(128&t[0]),r=127&t[0],i=r<126?3:126===r?1:2}else if(1===i){if(v(n)<2)break;const t=w(n,2);r=new DataView(t.buffer,t.byteOffset,t.length).getUint16(0),i=3}else if(2===i){if(v(n)<8)break;const t=w(n,8),e=new DataView(t.buffer,t.byteOffset,t.length),o=e.getUint32(0);if(o>Math.pow(2,21)-1){h.enqueue(s);break}r=o*Math.pow(2,32)+e.getUint32(4),i=3}else{if(v(n)<r)break;const t=w(n,r);h.enqueue(d(o?t:b.decode(t),e)),i=0}if(0===r||r>t){h.enqueue(s);break}}}})}(Number.MAX_SAFE_INTEGER,this.socket.binaryType),n=t.readable.pipeThrough(e).getReader(),i=m();i.readable.pipeTo(t.writable),this.writer=i.writable.getWriter();const r=()=>{n.read().then((({done:t,value:e})=>{t||(this.onPacket(e),r())})).catch((t=>{}))};r();const o={type:"open"};this.query.sid&&(o.data=`{"sid":"${this.query.sid}"}`),this.writer.write(o).then((()=>this.onOpen()))}))})))}write(t){this.writable=!1;for(let e=0;e<t.length;e++){const s=t[e],n=e===t.length-1;this.writer.write(s).then((()=>{n&&K((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){var t;null===(t=this.transport)||void 0===t||t.close()}},polling:class extends C{constructor(t){if(super(t),this.polling=!1,"undefined"!=typeof location){const e="https:"===location.protocol;let s=location.port;s||(s=e?"443":"80"),this.xd="undefined"!=typeof location&&t.hostname!==location.hostname||s!==t.port}const e=t&&t.forceBase64;this.supportsBinary=M&&!e,this.opts.withCredentials&&(this.cookieJar=void 0)}get name(){return"polling"}doOpen(){this.poll()}pause(t){this.readyState="pausing";const e=()=>{this.readyState="paused",t()};if(this.polling||!this.writable){let t=0;this.polling&&(t++,this.once("pollComplete",(function(){--t||e()}))),this.writable||(t++,this.once("drain",(function(){--t||e()})))}else e()}poll(){this.polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){((t,e)=>{const s=t.split(g),n=[];for(let t=0;t<s.length;t++){const i=d(s[t],e);if(n.push(i),"error"===i.type)break}return n})(t,this.socket.binaryType).forEach((t=>{if("opening"===this.readyState&&"open"===t.type&&this.onOpen(),"close"===t.type)return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(t)})),"closed"!==this.readyState&&(this.polling=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this.poll())}doClose(){const t=()=>{this.write([{type:"close"}])};"open"===this.readyState?t():this.once("open",t)}write(t){this.writable=!1,((t,e)=>{const s=t.length,n=new Array(s);let i=0;t.forEach(((t,r)=>{o(t,!1,(t=>{n[r]=t,++i===s&&e(n.join(g))}))}))})(t,(t=>{this.doWrite(t,(()=>{this.writable=!0,this.emitReserved("drain")}))}))}uri(){const t=this.opts.secure?"https":"http",e=this.query||{};return!1!==this.opts.timestampRequests&&(e[this.opts.timestampParam]=j()),this.supportsBinary||e.sid||(e.b64=1),this.createUri(t,e)}request(t={}){return Object.assign(t,{xd:this.xd,cookieJar:this.cookieJar},this.opts),new V(this.uri(),t)}doWrite(t,e){const s=this.request({method:"POST",data:t});s.on("success",e),s.on("error",((t,e)=>{this.onError("xhr post error",t,e)}))}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",((t,e)=>{this.onError("xhr poll error",t,e)})),this.pollXhr=t}}},J=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,$=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function Q(t){const e=t,s=t.indexOf("["),n=t.indexOf("]");-1!=s&&-1!=n&&(t=t.substring(0,s)+t.substring(s,n).replace(/:/g,";")+t.substring(n,t.length));let i=J.exec(t||""),r={},o=14;for(;o--;)r[$[o]]=i[o]||"";return-1!=s&&-1!=n&&(r.source=e,r.host=r.host.substring(1,r.host.length-1).replace(/;/g,":"),r.authority=r.authority.replace("[","").replace("]","").replace(/;/g,":"),r.ipv6uri=!0),r.pathNames=function(t,e){const s=/\/{2,9}/g,n=e.replace(s,"/").split("/");"/"!=e.slice(0,1)&&0!==e.length||n.splice(0,1);"/"==e.slice(-1)&&n.splice(n.length-1,1);return n}(0,r.path),r.queryKey=function(t,e){const s={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,(function(t,e,n){e&&(s[e]=n)})),s}(0,r.query),r}class X extends k{constructor(t,e={}){super(),this.binaryType="arraybuffer",this.writeBuffer=[],t&&"object"==typeof t&&(e=t,t=null),t?(t=Q(t),e.hostname=t.host,e.secure="https"===t.protocol||"wss"===t.protocol,e.port=t.port,t.query&&(e.query=t.query)):e.host&&(e.hostname=Q(e.host).host),T(this,e),this.secure=null!=e.secure?e.secure:"undefined"!=typeof location&&"https:"===location.protocol,e.hostname&&!e.port&&(e.port=this.secure?"443":"80"),this.hostname=e.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=e.port||("undefined"!=typeof location&&location.port?location.port:this.secure?"443":"80"),this.transports=e.transports||["polling","websocket","webtransport"],this.writeBuffer=[],this.prevBufferLen=0,this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},e),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),"string"==typeof this.opts.query&&(this.opts.query=function(t){let e={},s=t.split("&");for(let t=0,n=s.length;t<n;t++){let n=s[t].split("=");e[decodeURIComponent(n[0])]=decodeURIComponent(n[1])}return e}(this.opts.query)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingTimeoutTimer=null,"function"==typeof addEventListener&&(this.opts.closeOnBeforeunload&&(this.beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.beforeunloadEventListener,!1)),"localhost"!==this.hostname&&(this.offlineEventListener=()=>{this.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",this.offlineEventListener,!1))),this.open()}createTransport(t){const e=Object.assign({},this.opts.query);e.EIO=4,e.transport=t,this.id&&(e.sid=this.id);const s=Object.assign({},this.opts,{query:e,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new z[t](s)}open(){let t;if(this.opts.rememberUpgrade&&X.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket"))t="websocket";else{if(0===this.transports.length)return void this.setTimeoutFn((()=>{this.emitReserved("error","No transports available")}),0);t=this.transports[0]}this.readyState="opening";try{t=this.createTransport(t)}catch(t){return this.transports.shift(),void this.open()}t.open(),this.setTransport(t)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",(t=>this.onClose("transport close",t)))}probe(t){let e=this.createTransport(t),s=!1;X.priorWebsocketSuccess=!1;const n=()=>{s||(e.send([{type:"ping",data:"probe"}]),e.once("packet",(t=>{if(!s)if("pong"===t.type&&"probe"===t.data){if(this.upgrading=!0,this.emitReserved("upgrading",e),!e)return;X.priorWebsocketSuccess="websocket"===e.name,this.transport.pause((()=>{s||"closed"!==this.readyState&&(c(),this.setTransport(e),e.send([{type:"upgrade"}]),this.emitReserved("upgrade",e),e=null,this.upgrading=!1,this.flush())}))}else{const t=new Error("probe error");t.transport=e.name,this.emitReserved("upgradeError",t)}})))};function i(){s||(s=!0,c(),e.close(),e=null)}const r=t=>{const s=new Error("probe error: "+t);s.transport=e.name,i(),this.emitReserved("upgradeError",s)};function o(){r("transport closed")}function a(){r("socket closed")}function h(t){e&&t.name!==e.name&&i()}const c=()=>{e.removeListener("open",n),e.removeListener("error",r),e.removeListener("close",o),this.off("close",a),this.off("upgrading",h)};e.once("open",n),e.once("error",r),e.once("close",o),this.once("close",a),this.once("upgrading",h),-1!==this.upgrades.indexOf("webtransport")&&"webtransport"!==t?this.setTimeoutFn((()=>{s||e.open()}),200):e.open()}onOpen(){if(this.readyState="open",X.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush(),"open"===this.readyState&&this.opts.upgrade){let t=0;const e=this.upgrades.length;for(;t<e;t++)this.probe(this.upgrades[t])}}onPacket(t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),this.resetPingTimeout(),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this.sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong");break;case"error":const e=new Error("server error");e.code=t.data,this.onError(e);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data)}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this.upgrades=this.filterUpgrades(t.upgrades),this.pingInterval=t.pingInterval,this.pingTimeout=t.pingTimeout,this.maxPayload=t.maxPayload,this.onOpen(),"closed"!==this.readyState&&this.resetPingTimeout()}resetPingTimeout(){this.clearTimeoutFn(this.pingTimeoutTimer),this.pingTimeoutTimer=this.setTimeoutFn((()=>{this.onClose("ping timeout")}),this.pingInterval+this.pingTimeout),this.opts.autoUnref&&this.pingTimeoutTimer.unref()}onDrain(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}flush(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this.getWritablePackets();this.transport.send(t),this.prevBufferLen=t.length,this.emitReserved("flush")}}getWritablePackets(){if(!(this.maxPayload&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let s=0;s<this.writeBuffer.length;s++){const n=this.writeBuffer[s].data;if(n&&(t+="string"==typeof(e=n)?function(t){let e=0,s=0;for(let n=0,i=t.length;n<i;n++)e=t.charCodeAt(n),e<128?s+=1:e<2048?s+=2:e<55296||e>=57344?s+=3:(n++,s+=4);return s}(e):Math.ceil(1.33*(e.byteLength||e.size))),s>0&&t>this.maxPayload)return this.writeBuffer.slice(0,s);t+=2}var e;return this.writeBuffer}write(t,e,s){return this.sendPacket("message",t,e,s),this}send(t,e,s){return this.sendPacket("message",t,e,s),this}sendPacket(t,e,s,n){if("function"==typeof e&&(n=e,e=void 0),"function"==typeof s&&(n=s,s=null),"closing"===this.readyState||"closed"===this.readyState)return;(s=s||{}).compress=!1!==s.compress;const i={type:t,data:e,options:s};this.emitReserved("packetCreate",i),this.writeBuffer.push(i),n&&this.once("flush",n),this.flush()}close(){const t=()=>{this.onClose("forced close"),this.transport.close()},e=()=>{this.off("upgrade",e),this.off("upgradeError",e),t()},s=()=>{this.once("upgrade",e),this.once("upgradeError",e)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",(()=>{this.upgrading?s():t()})):this.upgrading?s():t()),this}onError(t){X.priorWebsocketSuccess=!1,this.emitReserved("error",t),this.onClose("transport error",t)}onClose(t,e){"opening"!==this.readyState&&"open"!==this.readyState&&"closing"!==this.readyState||(this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),"function"==typeof removeEventListener&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",t,e),this.writeBuffer=[],this.prevBufferLen=0)}filterUpgrades(t){const e=[];let s=0;const n=t.length;for(;s<n;s++)~this.transports.indexOf(t[s])&&e.push(t[s]);return e}}X.protocol=4;const G="function"==typeof ArrayBuffer,Z=t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t.buffer instanceof ArrayBuffer,tt=Object.prototype.toString,et="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===tt.call(Blob),st="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===tt.call(File);function nt(t){return G&&(t instanceof ArrayBuffer||Z(t))||et&&t instanceof Blob||st&&t instanceof File}function it(t,e){if(!t||"object"!=typeof t)return!1;if(Array.isArray(t)){for(let e=0,s=t.length;e<s;e++)if(it(t[e]))return!0;return!1}if(nt(t))return!0;if(t.toJSON&&"function"==typeof t.toJSON&&1===arguments.length)return it(t.toJSON(),!0);for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)&&it(t[e]))return!0;return!1}function rt(t){const e=[],s=t.data,n=t;return n.data=ot(s,e),n.attachments=e.length,{packet:n,buffers:e}}function ot(t,e){if(!t)return t;if(nt(t)){const s={_placeholder:!0,num:e.length};return e.push(t),s}if(Array.isArray(t)){const s=new Array(t.length);for(let n=0;n<t.length;n++)s[n]=ot(t[n],e);return s}if("object"==typeof t&&!(t instanceof Date)){const s={};for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(s[n]=ot(t[n],e));return s}return t}function at(t,e){return t.data=ht(t.data,e),delete t.attachments,t}function ht(t,e){if(!t)return t;if(t&&!0===t._placeholder){if("number"==typeof t.num&&t.num>=0&&t.num<e.length)return e[t.num];throw new Error("illegal attachments")}if(Array.isArray(t))for(let s=0;s<t.length;s++)t[s]=ht(t[s],e);else if("object"==typeof t)for(const s in t)Object.prototype.hasOwnProperty.call(t,s)&&(t[s]=ht(t[s],e));return t}const ct=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],ut=5;var pt;!function(t){t[t.CONNECT=0]="CONNECT",t[t.DISCONNECT=1]="DISCONNECT",t[t.EVENT=2]="EVENT",t[t.ACK=3]="ACK",t[t.CONNECT_ERROR=4]="CONNECT_ERROR",t[t.BINARY_EVENT=5]="BINARY_EVENT",t[t.BINARY_ACK=6]="BINARY_ACK"}(pt||(pt={}));function lt(t){return"[object Object]"===Object.prototype.toString.call(t)}class dt extends k{constructor(t){super(),this.reviver=t}add(t){let e;if("string"==typeof t){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");e=this.decodeString(t);const s=e.type===pt.BINARY_EVENT;s||e.type===pt.BINARY_ACK?(e.type=s?pt.EVENT:pt.ACK,this.reconstructor=new ft(e),0===e.attachments&&super.emitReserved("decoded",e)):super.emitReserved("decoded",e)}else{if(!nt(t)&&!t.base64)throw new Error("Unknown type: "+t);if(!this.reconstructor)throw new Error("got binary data when not reconstructing a packet");e=this.reconstructor.takeBinaryData(t),e&&(this.reconstructor=null,super.emitReserved("decoded",e))}}decodeString(t){let e=0;const s={type:Number(t.charAt(0))};if(void 0===pt[s.type])throw new Error("unknown packet type "+s.type);if(s.type===pt.BINARY_EVENT||s.type===pt.BINARY_ACK){const n=e+1;for(;"-"!==t.charAt(++e)&&e!=t.length;);const i=t.substring(n,e);if(i!=Number(i)||"-"!==t.charAt(e))throw new Error("Illegal attachments");s.attachments=Number(i)}if("/"===t.charAt(e+1)){const n=e+1;for(;++e;){if(","===t.charAt(e))break;if(e===t.length)break}s.nsp=t.substring(n,e)}else s.nsp="/";const n=t.charAt(e+1);if(""!==n&&Number(n)==n){const n=e+1;for(;++e;){const s=t.charAt(e);if(null==s||Number(s)!=s){--e;break}if(e===t.length)break}s.id=Number(t.substring(n,e+1))}if(t.charAt(++e)){const n=this.tryParse(t.substr(e));if(!dt.isPayloadValid(s.type,n))throw new Error("invalid payload");s.data=n}return s}tryParse(t){try{return JSON.parse(t,this.reviver)}catch(t){return!1}}static isPayloadValid(t,e){switch(t){case pt.CONNECT:return lt(e);case pt.DISCONNECT:return void 0===e;case pt.CONNECT_ERROR:return"string"==typeof e||lt(e);case pt.EVENT:case pt.BINARY_EVENT:return Array.isArray(e)&&("number"==typeof e[0]||"string"==typeof e[0]&&-1===ct.indexOf(e[0]));case pt.ACK:case pt.BINARY_ACK:return Array.isArray(e)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}}class ft{constructor(t){this.packet=t,this.buffers=[],this.reconPack=t}takeBinaryData(t){if(this.buffers.push(t),this.buffers.length===this.reconPack.attachments){const t=at(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}var yt=Object.freeze({__proto__:null,protocol:5,get PacketType(){return pt},Encoder:class{constructor(t){this.replacer=t}encode(t){return t.type!==pt.EVENT&&t.type!==pt.ACK||!it(t)?[this.encodeAsString(t)]:this.encodeAsBinary({type:t.type===pt.EVENT?pt.BINARY_EVENT:pt.BINARY_ACK,nsp:t.nsp,data:t.data,id:t.id})}encodeAsString(t){let e=""+t.type;return t.type!==pt.BINARY_EVENT&&t.type!==pt.BINARY_ACK||(e+=t.attachments+"-"),t.nsp&&"/"!==t.nsp&&(e+=t.nsp+","),null!=t.id&&(e+=t.id),null!=t.data&&(e+=JSON.stringify(t.data,this.replacer)),e}encodeAsBinary(t){const e=rt(t),s=this.encodeAsString(e.packet),n=e.buffers;return n.unshift(s),n}},Decoder:dt});function gt(t,e,s){return t.on(e,s),function(){t.off(e,s)}}const mt=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class bt extends k{constructor(t,e,s){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=t,this.nsp=e,s&&s.auth&&(this.auth=s.auth),this._opts=Object.assign({},s),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const t=this.io;this.subs=[gt(t,"open",this.onopen.bind(this)),gt(t,"packet",this.onpacket.bind(this)),gt(t,"error",this.onerror.bind(this)),gt(t,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected||(this.subEvents(),this.io._reconnecting||this.io.open(),"open"===this.io._readyState&&this.onopen()),this}open(){return this.connect()}send(...t){return t.unshift("message"),this.emit.apply(this,t),this}emit(t,...e){if(mt.hasOwnProperty(t))throw new Error('"'+t.toString()+'" is a reserved event name');if(e.unshift(t),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(e),this;const s={type:pt.EVENT,data:e,options:{}};if(s.options.compress=!1!==this.flags.compress,"function"==typeof e[e.length-1]){const t=this.ids++,n=e.pop();this._registerAckCallback(t,n),s.id=t}const n=this.io.engine&&this.io.engine.transport&&this.io.engine.transport.writable;return this.flags.volatile&&(!n||!this.connected)||(this.connected?(this.notifyOutgoingListeners(s),this.packet(s)):this.sendBuffer.push(s)),this.flags={},this}_registerAckCallback(t,e){var s;const n=null!==(s=this.flags.timeout)&&void 0!==s?s:this._opts.ackTimeout;if(void 0===n)return void(this.acks[t]=e);const i=this.io.setTimeoutFn((()=>{delete this.acks[t];for(let e=0;e<this.sendBuffer.length;e++)this.sendBuffer[e].id===t&&this.sendBuffer.splice(e,1);e.call(this,new Error("operation has timed out"))}),n);this.acks[t]=(...t)=>{this.io.clearTimeoutFn(i),e.apply(this,[null,...t])}}emitWithAck(t,...e){const s=void 0!==this.flags.timeout||void 0!==this._opts.ackTimeout;return new Promise(((n,i)=>{e.push(((t,e)=>s?t?i(t):n(e):n(t))),this.emit(t,...e)}))}_addToQueue(t){let e;"function"==typeof t[t.length-1]&&(e=t.pop());const s={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push(((t,...n)=>{if(s!==this._queue[0])return;return null!==t?s.tryCount>this._opts.retries&&(this._queue.shift(),e&&e(t)):(this._queue.shift(),e&&e(null,...n)),s.pending=!1,this._drainQueue()})),this._queue.push(s),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||0===this._queue.length)return;const e=this._queue[0];e.pending&&!t||(e.pending=!0,e.tryCount++,this.flags=e.flags,this.emit.apply(this,e.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){"function"==typeof this.auth?this.auth((t=>{this._sendConnectPacket(t)})):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:pt.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,e){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,e)}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case pt.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case pt.EVENT:case pt.BINARY_EVENT:this.onevent(t);break;case pt.ACK:case pt.BINARY_ACK:this.onack(t);break;case pt.DISCONNECT:this.ondisconnect();break;case pt.CONNECT_ERROR:this.destroy();const e=new Error(t.data.message);e.data=t.data.data,this.emitReserved("connect_error",e)}}onevent(t){const e=t.data||[];null!=t.id&&e.push(this.ack(t.id)),this.connected?this.emitEvent(e):this.receiveBuffer.push(Object.freeze(e))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){const e=this._anyListeners.slice();for(const s of e)s.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&"string"==typeof t[t.length-1]&&(this._lastOffset=t[t.length-1])}ack(t){const e=this;let s=!1;return function(...n){s||(s=!0,e.packet({type:pt.ACK,id:t,data:n}))}}onack(t){const e=this.acks[t.id];"function"==typeof e&&(e.apply(this,t.data),delete this.acks[t.id])}onconnect(t,e){this.id=t,this.recovered=e&&this._pid===e,this._pid=e,this.connected=!0,this.emitBuffered(),this.emitReserved("connect"),this._drainQueue(!0)}emitBuffered(){this.receiveBuffer.forEach((t=>this.emitEvent(t))),this.receiveBuffer=[],this.sendBuffer.forEach((t=>{this.notifyOutgoingListeners(t),this.packet(t)})),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach((t=>t())),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:pt.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){const e=this._anyListeners;for(let s=0;s<e.length;s++)if(t===e[s])return e.splice(s,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(t),this}prependAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(t),this}offAnyOutgoing(t){if(!this._anyOutgoingListeners)return this;if(t){const e=this._anyOutgoingListeners;for(let s=0;s<e.length;s++)if(t===e[s])return e.splice(s,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(t){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const e=this._anyOutgoingListeners.slice();for(const s of e)s.apply(this,t.data)}}}function vt(t){t=t||{},this.ms=t.min||100,this.max=t.max||1e4,this.factor=t.factor||2,this.jitter=t.jitter>0&&t.jitter<=1?t.jitter:0,this.attempts=0}vt.prototype.duration=function(){var t=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),s=Math.floor(e*this.jitter*t);t=0==(1&Math.floor(10*e))?t-s:t+s}return 0|Math.min(t,this.max)},vt.prototype.reset=function(){this.attempts=0},vt.prototype.setMin=function(t){this.ms=t},vt.prototype.setMax=function(t){this.max=t},vt.prototype.setJitter=function(t){this.jitter=t};class wt extends k{constructor(t,e){var s;super(),this.nsps={},this.subs=[],t&&"object"==typeof t&&(e=t,t=void 0),(e=e||{}).path=e.path||"/socket.io",this.opts=e,T(this,e),this.reconnection(!1!==e.reconnection),this.reconnectionAttempts(e.reconnectionAttempts||1/0),this.reconnectionDelay(e.reconnectionDelay||1e3),this.reconnectionDelayMax(e.reconnectionDelayMax||5e3),this.randomizationFactor(null!==(s=e.randomizationFactor)&&void 0!==s?s:.5),this.backoff=new vt({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(null==e.timeout?2e4:e.timeout),this._readyState="closed",this.uri=t;const n=e.parser||yt;this.encoder=new n.Encoder,this.decoder=new n.Decoder,this._autoConnect=!1!==e.autoConnect,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,this):this._reconnection}reconnectionAttempts(t){return void 0===t?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var e;return void 0===t?this._reconnectionDelay:(this._reconnectionDelay=t,null===(e=this.backoff)||void 0===e||e.setMin(t),this)}randomizationFactor(t){var e;return void 0===t?this._randomizationFactor:(this._randomizationFactor=t,null===(e=this.backoff)||void 0===e||e.setJitter(t),this)}reconnectionDelayMax(t){var e;return void 0===t?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,null===(e=this.backoff)||void 0===e||e.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&0===this.backoff.attempts&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new X(this.uri,this.opts);const e=this.engine,s=this;this._readyState="opening",this.skipReconnect=!1;const n=gt(e,"open",(function(){s.onopen(),t&&t()})),i=e=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",e),t?t(e):this.maybeReconnectOnOpen()},r=gt(e,"error",i);if(!1!==this._timeout){const t=this._timeout,s=this.setTimeoutFn((()=>{n(),i(new Error("timeout")),e.close()}),t);this.opts.autoUnref&&s.unref(),this.subs.push((()=>{this.clearTimeoutFn(s)}))}return this.subs.push(n),this.subs.push(r),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const t=this.engine;this.subs.push(gt(t,"ping",this.onping.bind(this)),gt(t,"data",this.ondata.bind(this)),gt(t,"error",this.onerror.bind(this)),gt(t,"close",this.onclose.bind(this)),gt(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(t){this.onclose("parse error",t)}}ondecoded(t){K((()=>{this.emitReserved("packet",t)}),this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,e){let s=this.nsps[t];return s?this._autoConnect&&!s.active&&s.connect():(s=new bt(this,t,e),this.nsps[t]=s),s}_destroy(t){const e=Object.keys(this.nsps);for(const t of e){if(this.nsps[t].active)return}this._close()}_packet(t){const e=this.encoder.encode(t);for(let s=0;s<e.length;s++)this.engine.write(e[s],t.options)}cleanup(){this.subs.forEach((t=>t())),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close"),this.engine&&this.engine.close()}disconnect(){return this._close()}onclose(t,e){this.cleanup(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,e),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const e=this.backoff.duration();this._reconnecting=!0;const s=this.setTimeoutFn((()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),t.skipReconnect||t.open((e=>{e?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",e)):t.onreconnect()})))}),e);this.opts.autoUnref&&s.unref(),this.subs.push((()=>{this.clearTimeoutFn(s)}))}}onreconnect(){const t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}}const kt={};function _t(t,e){"object"==typeof t&&(e=t,t=void 0);const s=function(t,e="",s){let n=t;s=s||"undefined"!=typeof location&&location,null==t&&(t=s.protocol+"//"+s.host),"string"==typeof t&&("/"===t.charAt(0)&&(t="/"===t.charAt(1)?s.protocol+t:s.host+t),/^(https?|wss?):\/\//.test(t)||(t=void 0!==s?s.protocol+"//"+t:"https://"+t),n=Q(t)),n.port||(/^(http|ws)$/.test(n.protocol)?n.port="80":/^(http|ws)s$/.test(n.protocol)&&(n.port="443")),n.path=n.path||"/";const i=-1!==n.host.indexOf(":")?"["+n.host+"]":n.host;return n.id=n.protocol+"://"+i+":"+n.port+e,n.href=n.protocol+"://"+i+(s&&s.port===n.port?"":":"+n.port),n}(t,(e=e||{}).path||"/socket.io"),n=s.source,i=s.id,r=s.path,o=kt[i]&&r in kt[i].nsps;let a;return e.forceNew||e["force new connection"]||!1===e.multiplex||o?a=new wt(n,e):(kt[i]||(kt[i]=new wt(n,e)),a=kt[i]),s.query&&!e.query&&(e.query=s.queryKey),a.socket(s.path,e)}Object.assign(_t,{Manager:wt,Socket:bt,io:_t,connect:_t});export{wt as Manager,bt as Socket,_t as connect,_t as default,_t as io,ut as protocol};
7
+ //# sourceMappingURL=socket.io.esm.min.js.map