ecentrix-voip
Version:
package ecentrix8 telephony agent, call center, telemarketing, omnichannel, collection system
2 lines • 509 kB
JavaScript
/*! For license information please see ecentrix-sdk.module.js.LICENSE.txt */
(()=>{var e={9695:(e,t,n)=>{var r=n(6752);e.exports=function(e,t,n){var i,o=t,s={autoplay:!0,mirror:!1,muted:!1,audio:!1,disableContextMenu:!1};if(n)for(i in n)s[i]=n[i];return o?"audio"===o.tagName.toLowerCase()&&(s.audio=!0):o=document.createElement(s.audio?"audio":"video"),s.disableContextMenu&&(o.oncontextmenu=function(e){e.preventDefault()}),s.autoplay&&(o.autoplay="autoplay"),o.muted=!!s.muted,s.audio||["","moz","webkit","o","ms"].forEach((function(e){var t=e?e+"Transform":"transform";o.style[t]=s.mirror?"scaleX(-1)":"scaleX(1)"})),"safari"===r.browserDetails.browser&&o.setAttribute("playsinline",!0),o.srcObject=e,o}},3091:(e,t,n)=>{var r=n(8953).b;e.exports=r},8953:(e,t,n)=>{"use strict";n.d(t,{b:()=>_t});var r={};n.r(r),n.d(r,{Decoder:()=>Ye,Encoder:()=>Ke,PacketType:()=>ze,protocol:()=>Ve});const i=require("react"),o=e=>{let t;const n=new Set,r=(e,r)=>{const i="function"==typeof e?e(t):e;if(!Object.is(i,t)){const e=t;t=(null!=r?r:"object"!=typeof i||null===i)?i:Object.assign({},t,i),n.forEach((n=>n(t,e)))}},i=()=>t,o={setState:r,getState:i,getInitialState:()=>s,subscribe:e=>(n.add(e),()=>n.delete(e))},s=t=e(r,i,o);return o},s=e=>e,a=e=>{const t=(e=>e?o(e):o)(e),n=e=>function(e,t=s){const n=i.useSyncExternalStore(e.subscribe,(()=>t(e.getState())),(()=>t(e.getInitialState())));return i.useDebugValue(n),n}(t,e);return Object.assign(n,t),n};var u,l=(u=function(e){return{count:0,setCount:function(t){return e({count:t})},increment:function(){return e((function(e){return{count:e.count+1}}))},decrement:function(){return e((function(e){return{count:e.count-1}}))},isLogin:!1,setLogin:function(t){return e({isLogin:t})},sessionID:null,setSessionID:function(t){return e({sessionID:t})},connectionID:null,setConnectionID:function(t){return e({connectionID:t})},dataLogin:null,setDataLogin:function(t){return e({dataLogin:t})},token:!1,setToken:function(t){return e({token:t})},chatDesign:null,setChatDesign:function(t){return e({chatDesign:t})},callSession:null,setCallSession:function(t){return e({callSession:t})},voipSession:null,setVoipSession:function(t){return e({voipSession:t})},responsePhone:"",setResponsePhone:function(t){return e({responsePhone:t})},holdCall:!1,setHoldCall:function(t){return e({holdCall:t})},muteCall:!1,setMuteCall:function(t){return e({muteCall:t})},showChat:!1,setShowChat:function(t){return e({showChat:t})},showAttachment:!1,setAttachment:function(t){return e({showAttachment:t})},showVideo:!1,setVideo:function(t){return e({showVideo:t})},showVoice:!1,setVoice:function(t){return e({showVoice:t})},getMessage:!1,setMessage:function(t){return e({getMessage:t})},connection:!1,setConnection:function(t){return e({connection:t})},sipRegister:!1,setSipRegister:function(t){return e({sipRegister:t})},isIdle:!1,setIsIdle:function(t){return e({isIdle:t})},ecxSocket:!1,setEcxSocket:function(t){return e({ecxSocket:t})},ecxAgentId:null,setEcxAgentId:function(t){return e({ecxAgentId:t})},hours:0,minutes:0,seconds:0,resetTimer:function(){return e({hours:0,minutes:0,seconds:0})},incrementTime:function(){return e((function(e){var t=e.hours,n=e.minutes,r=e.seconds;return 59===r?(r=0,59===n?(n=0,t+=1):n+=1):r+=1,{hours:t,minutes:n,seconds:r}}))}}},u?a(u):a),c=n(5053),d=n.n(c),h=n(4692),f=n.n(h);function p(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];try{var n=f()("#remoteVoice");n.trigger("pause"),n.prop("loop",t),n.attr("src",e),n.currentTime=0,setTimeout((function(){n.trigger("play")}),100)}catch(e){console.log("playVoice >>>",e)}}function m(e){try{var t=document.querySelector("select#audioSource"),n=document.querySelector("select#audioOutput"),r=[t,n],i=r.map((function(e){return e.value}));r.forEach((function(e){for(;e.firstChild;)e.removeChild(e.firstChild)}));for(var o=0;o!==e.length;++o){var s=e[o],a=document.createElement("option");a.value=s.deviceId,"audioinput"===s.kind?(a.text=s.label||"microphone ".concat(t.length+1),t.appendChild(a)):"audiooutput"===s.kind&&(a.text=s.label||"speaker ".concat(n.length+1),n.appendChild(a))}r.forEach((function(e,t){Array.prototype.slice.call(e.childNodes).some((function(e){return e.value===i[t]}))&&(e.value=i[t])}));try{var u=Array.from(t.options).map((function(e){return{value:e.value,label:e.text}}));"function"==typeof ecxAudioList&&window.ecxAudioList(u)}catch(e){}}catch(e){console.log(e)}}function v(e){console.log("navigator.MediaDevices.getUserMedia error: ",e.message,e.name)}function g(e){var t=document.querySelector("remoteVoice");return window.stream=e,t.srcObject=e,navigator.mediaDevices.enumerateDevices()}function _(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default";window.stream&&window.stream.getTracks().forEach((function(e){e.stop()}));var t={audio:{deviceId:e?{exact:e}:void 0}};navigator.mediaDevices.getUserMedia(t).then(g).then(m).catch(v)}var y=n(9695);function b(e){return b="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},b(e)}function T(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,S(r.key),r)}}function S(e){var t=function(e){if("object"!=b(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=b(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==b(t)?t:t+""}function C(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(C=function(){return!!e})()}function w(e){return w=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},w(e)}function E(e,t){return E=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},E(e,t)}var A=function(e){function t(e,n,r){var i;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),i=function(e,t,n){return t=w(t),function(e,t){if(t&&("object"==b(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,C()?Reflect.construct(t,n||[],w(e).constructor):t.apply(e,n))}(this,t,[e,n,r]),d().debug.disable("JsSIP:*"),i._localDetail,i._phone=null,i._session=null,i._uri="sip:"+e+"@"+r,i._ws="wss://"+r+":8189/asterisk/ws";var o=new(d().WebSocketInterface)(i._ws);return i._config={uri:i._uri+";transport=wss",contact_uri:i._uri+";transport=wss",password:n,ws_servers:i._ws,session_timers:!1,iceTransportPolicy:"all",rtcpMuxPolicy:"negotiate",rtcOfferConstraints:{offerToReceiveAudio:!0},mandatory:[{OfferToReceiveAudio:!0,OfferToReceiveVideo:!0},{DtlsSrtpKeyAgreement:!0}],realm:"ecentrix.net"},i._config.sockets=[o],i._phone=new(d().UA)(i._config),navigator.mediaDevices.enumerateDevices().then(m).catch(v),i.connect(),i.state={message:l.getState().responsePhone},i}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&E(e,t)}(t,e),n=t,r=[{key:"componentDidMount",value:function(){var e=this;this.unsubscribe=l.subscribe((function(t){e.setState({message:t.message})}))}},{key:"componentWillUnmount",value:function(){this.unsubscribe&&this.unsubscribe()}},{key:"connect",value:function(){var e=null;this._phone.on("connected",(function(){l.getState().setSipRegister(!0),"function"==typeof ecxSipState&&window.ecxSipState("connected");try{var e=new CustomEvent("ecxSipState",{detail:"connected"});window.dispatchEvent(e)}catch(e){}})),this._phone.on("disconnected",(function(){l.getState().setSipRegister(!1),"function"==typeof ecxSipState&&window.ecxSipState("disconnected");try{var e=new CustomEvent("ecxSipState",{detail:"disconnected"});window.dispatchEvent(e)}catch(e){}})),this._phone.on("registered",(function(){"function"==typeof ecxSipState&&window.ecxSipState("registered");try{var e=new CustomEvent("ecxSipState",{detail:"registered"});window.dispatchEvent(e)}catch(e){}})),this._phone.on("unregistered",(function(){"function"==typeof ecxSipState&&window.ecxSipState("unregistered");try{var e=new CustomEvent("ecxSipState",{detail:"unregistered"});window.dispatchEvent(e)}catch(e){}})),this._phone.on("registrationFailed",(function(e){"function"==typeof ecxSipState&&window.ecxSipState("registrationFailed",e);try{var t=new CustomEvent("ecxSipState",{detail:"registrationFailed"});window.dispatchEvent(t)}catch(e){}})),this._phone.on("transportError",(function(e){l.getState().setSipRegister(!1),"function"==typeof ecxSipState&&window.ecxSipState("transportError",e);try{var t=new CustomEvent("ecxSipState",{detail:"transportError"});window.dispatchEvent(t)}catch(e){}})),this._phone.on("newRTCSession",(function(t){var n=this;if(e=t.session,this._session&&this._session.terminate(),this._session=e,l.getState().setCallSession(this._session),this._session.isInProgress()&&"incoming"===this._session.direction){l.getState().setResponsePhone("ringing"),"function"==typeof ecxSipState&&window.ecxSipState("ringing");try{var r=new CustomEvent("ecxSipState",{detail:"ringing"});window.dispatchEvent(r)}catch(e){}}this._session.isEstablished(),this._session.on("connecting",(function(e){var t;"function"==typeof ecxSipState&&window.ecxSipState("connecting with call_id ".concat(null===(t=e.request)||void 0===t?void 0:t.call_id));try{var n,r=new CustomEvent("ecxSipState",{detail:"connecting with call_id ".concat(null===(n=r.request)||void 0===n?void 0:n.call_id)});window.dispatchEvent(r)}catch(e){}l.getState().setResponsePhone("connecting")})),this._session.on("sdp",(function(e){})),this._session.on("icecandidate",(function(e){})),this._session.on("getusermediafailed",(function(e){console.log("session @getusermediafailed [error: %o]",e)})),this._session.on("peerconnection:createofferfailed",(function(e){console.log("session @peerconnection:createofferfailed [error: %o]",e)})),this._session.on("peerconnection:createanswerfailed",(function(e){console.log("session @peerconnection:createanswerfailed [error: %o]",e)})),this._session.on("peerconnection:setlocaldescriptionfailed",(function(e){console.log("session @peerconnection:setlocaldescriptionfailed [error: %o]",e)})),this._session.on("peerconnection:setremotedescriptionfailed",(function(e){console.log("session @peerconnection:setremotedescriptionfailed [error: %o]",e)})),this._session.on("ended",(function(){"function"==typeof ecxSipState&&window.ecxSipState("ended");try{var e=new CustomEvent("ecxSipState",{detail:"ended"});window.dispatchEvent(e)}catch(e){}l.getState().setResponsePhone("ended"),setTimeout((function(){l.getState().setResponsePhone("ready"),"function"==typeof ecxSipState&&window.ecxSipState("ready");try{var e=new CustomEvent("ecxSipState",{detail:"ready"});window.dispatchEvent(e)}catch(e){}}),1e3),n._session=null,l.getState().setCallSession(null)})),this._session.on("failed",(function(){"function"==typeof ecxSipState&&window.ecxSipState("failed");try{var e=new CustomEvent("ecxSipState",{detail:"failed"});window.dispatchEvent(e)}catch(e){}l.getState().setResponsePhone("failed"),n._session=null,l.getState().setCallSession(null)})),this._session.on("accepted",(function(){"function"==typeof ecxSipState&&window.ecxSipState("accepted");try{var e=new CustomEvent("ecxSipState",{detail:"accepted"});window.dispatchEvent(e)}catch(e){}if(n._session.isInProgress()){l.getState().setResponsePhone("ringing"),"function"==typeof ecxSipState&&window.ecxSipState("ringing");try{var t=new CustomEvent("ecxSipState",{detail:"ringing"});window.dispatchEvent(t)}catch(e){}}if(n._session.isEstablished()){l.getState().setResponsePhone("establish"),"function"==typeof ecxSipState&&window.ecxSipState("establish");try{var r=new CustomEvent("ecxSipState",{detail:"establish"});window.dispatchEvent(r)}catch(e){}}if(n._session.isMuted().audio){l.getState().setResponsePhone("muted"),"function"==typeof ecxSipState&&window.ecxSipState("muted");try{var i=new CustomEvent("ecxSipState",{detail:"muted"});window.dispatchEvent(i)}catch(e){}}})),this._session.on("progress",(function(){"function"==typeof ecxSipState&&window.ecxSipState("progress");try{var t=new CustomEvent("ecxSipState",{detail:"progress"});window.dispatchEvent(t)}catch(e){}l.getState().setResponsePhone("progress"),p("./ecentrixSDK-v1.0/assets/ringtone.wav",!0),setTimeout((function(){e.answer()}),Math.floor(1001*Math.random())+1e3)})),this._session.on("peerconnection",(function(e){if("incoming"===n._session.direction){p("./ecentrixSDK-v1.0/assets/ringtone.wav",!0);try{n._session.connection.addEventListener("addstream",(function(e){var t=this._session.connection.getLocalStreams();(0,y.attachMediaStream)(t[0],document.getElementById("localVoice"),{autoplay:!1,audio:!0})}))}catch(e){}}})),this._session.on("confirmed",(function(){"function"==typeof ecxSipState&&window.ecxSipState("confirmed");try{var e=new CustomEvent("ecxSipState",{detail:"confirmed"});window.dispatchEvent(e)}catch(e){}var t;(t=f()("#songs")).trigger("pause"),t.currentTime=0,p("./ecentrixSDK-v1.0/assets/answered.mp3",!1);try{n._session.connection.getReceivers().map((function(e){return e.track&&"audio"===e.track.kind&&e.track})).filter(Boolean);var r=n._session.connection.getReceivers().map((function(e){return e.track&&"audio"===e.track.kind&&e.track})),i=new MediaStream(r),o=document.getElementById("remoteVoice");o&&(o.srcObject=i,o.play().catch((function(e){return console.warn("Audio play failed:",e)}))),n._session.connection.addEventListener("track",(function(e){}))}catch(e){console.log("248 >>>",e)}})),this._session.on("addstream",(function(e){try{var t=n._session.connection.getLocalStreams();(0,y.attachMediaStream)(t,document.getElementById("localVoice"),{autoplay:!1,audio:!0}),e.stream&&(0,y.attachMediaStream)(e.stream,document.getElementById("remoteVoice"),{autoplay:!1,audio:!0})}catch(e){console.error("261 >>> ",e)}}))})),this._phone.start(),l.getState().setVoipSession(this._phone)}}],r&&T(n.prototype,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r}(i.Component);function R(e){return R="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},R(e)}function x(){x=function(){return t};var e,t={},n=Object.prototype,r=n.hasOwnProperty,i=Object.defineProperty||function(e,t,n){e[t]=n.value},o="function"==typeof Symbol?Symbol:{},s=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function l(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{l({},"")}catch(e){l=function(e,t,n){return e[t]=n}}function c(e,t,n,r){var o=t&&t.prototype instanceof g?t:g,s=Object.create(o.prototype),a=new P(r||[]);return i(s,"_invoke",{value:A(e,n,a)}),s}function d(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}t.wrap=c;var h="suspendedStart",f="suspendedYield",p="executing",m="completed",v={};function g(){}function _(){}function y(){}var b={};l(b,s,(function(){return this}));var T=Object.getPrototypeOf,S=T&&T(T(N([])));S&&S!==n&&r.call(S,s)&&(b=S);var C=y.prototype=g.prototype=Object.create(b);function w(e){["next","throw","return"].forEach((function(t){l(e,t,(function(e){return this._invoke(t,e)}))}))}function E(e,t){function n(i,o,s,a){var u=d(e[i],e,o);if("throw"!==u.type){var l=u.arg,c=l.value;return c&&"object"==R(c)&&r.call(c,"__await")?t.resolve(c.__await).then((function(e){n("next",e,s,a)}),(function(e){n("throw",e,s,a)})):t.resolve(c).then((function(e){l.value=e,s(l)}),(function(e){return n("throw",e,s,a)}))}a(u.arg)}var o;i(this,"_invoke",{value:function(e,r){function i(){return new t((function(t,i){n(e,r,t,i)}))}return o=o?o.then(i,i):i()}})}function A(t,n,r){var i=h;return function(o,s){if(i===p)throw Error("Generator is already running");if(i===m){if("throw"===o)throw s;return{value:e,done:!0}}for(r.method=o,r.arg=s;;){var a=r.delegate;if(a){var u=k(a,r);if(u){if(u===v)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(i===h)throw i=m,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);i=p;var l=d(t,n,r);if("normal"===l.type){if(i=r.done?m:f,l.arg===v)continue;return{value:l.arg,done:r.done}}"throw"===l.type&&(i=m,r.method="throw",r.arg=l.arg)}}}function k(t,n){var r=n.method,i=t.iterator[r];if(i===e)return n.delegate=null,"throw"===r&&t.iterator.return&&(n.method="return",n.arg=e,k(t,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),v;var o=d(i,t.iterator,n.arg);if("throw"===o.type)return n.method="throw",n.arg=o.arg,n.delegate=null,v;var s=o.arg;return s?s.done?(n[t.resultName]=s.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=e),n.delegate=null,v):s:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,v)}function O(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function I(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function P(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(O,this),this.reset(!0)}function N(t){if(t||""===t){var n=t[s];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var i=-1,o=function n(){for(;++i<t.length;)if(r.call(t,i))return n.value=t[i],n.done=!1,n;return n.value=e,n.done=!0,n};return o.next=o}}throw new TypeError(R(t)+" is not iterable")}return _.prototype=y,i(C,"constructor",{value:y,configurable:!0}),i(y,"constructor",{value:_,configurable:!0}),_.displayName=l(y,u,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===_||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,y):(e.__proto__=y,l(e,u,"GeneratorFunction")),e.prototype=Object.create(C),e},t.awrap=function(e){return{__await:e}},w(E.prototype),l(E.prototype,a,(function(){return this})),t.AsyncIterator=E,t.async=function(e,n,r,i,o){void 0===o&&(o=Promise);var s=new E(c(e,n,r,i),o);return t.isGeneratorFunction(n)?s:s.next().then((function(e){return e.done?e.value:s.next()}))},w(C),l(C,u,"Generator"),l(C,s,(function(){return this})),l(C,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),n=[];for(var r in t)n.push(r);return n.reverse(),function e(){for(;n.length;){var r=n.pop();if(r in t)return e.value=r,e.done=!1,e}return e.done=!0,e}},t.values=N,P.prototype={constructor:P,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(I),!t)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var n=this;function i(r,i){return a.type="throw",a.arg=t,n.next=r,i&&(n.method="next",n.arg=e),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var s=this.tryEntries[o],a=s.completion;if("root"===s.tryLoc)return i("end");if(s.tryLoc<=this.prev){var u=r.call(s,"catchLoc"),l=r.call(s,"finallyLoc");if(u&&l){if(this.prev<s.catchLoc)return i(s.catchLoc,!0);if(this.prev<s.finallyLoc)return i(s.finallyLoc)}else if(u){if(this.prev<s.catchLoc)return i(s.catchLoc,!0)}else{if(!l)throw Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return i(s.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var s=o?o.completion:{};return s.type=e,s.arg=t,o?(this.method="next",this.next=o.finallyLoc,v):this.complete(s)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),v},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),I(n),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var i=r.arg;I(n)}return i}}throw Error("illegal catch attempt")},delegateYield:function(t,n,r){return this.delegate={iterator:N(t),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=e),v}},t}function k(e,t,n,r,i,o,s){try{var a=e[o](s),u=a.value}catch(e){return void n(e)}a.done?t(u):Promise.resolve(u).then(r,i)}function O(e){return function(){var t=this,n=arguments;return new Promise((function(r,i){var o=e.apply(t,n);function s(e){k(o,r,i,s,a,"next",e)}function a(e){k(o,r,i,s,a,"throw",e)}s(void 0)}))}}function I(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,M(r.key),r)}}function P(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(P=function(){return!!e})()}function N(e){return N=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},N(e)}function D(e,t){return D=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},D(e,t)}function L(e,t,n){return(t=M(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function M(e){var t=function(e){if("object"!=R(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=R(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==R(t)?t:t+""}var j=function(e){function t(e,n,r){var i;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),L(i=function(e,t,n){return t=N(t),function(e,t){if(t&&("object"==R(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,P()?Reflect.construct(t,n||[],N(e).constructor):t.apply(e,n))}(this,t,[e,n,r]),"onWebSocketClose",function(){var e=O(x().mark((function e(t){return x().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:console.log("onWebSocketClose >>>",t);case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()),L(i,"onWebSocketError",function(){var e=O(x().mark((function e(t){return x().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:console.log("onWebSocketError >>>",t);case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()),L(i,"onWebSocketOpen",function(){var e=O(x().mark((function e(t,n,r){var o;return x().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o={action:"AGENT_LOGIN",source:"AGENT",token:r,agentId:n,userAgent:window.navigator.userAgentData.brands[0].brand+" "+window.navigator.userAgentData.brands[0].version},e.next=3,i._ws.send(JSON.stringify(o));case 3:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}()),L(i,"onWebSocketMessage",function(){var e=O(x().mark((function e(t){var n,r,o,s;return x().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,JSON.parse(t.data);case 2:if(n=e.sent,e.prev=3,!n.action.startsWith("AGENT_")||"MANAGER"!==n.source){e.next=10;break}"function"==typeof ecxPhoneState&&window.ecxPhoneState(n);try{r=new CustomEvent("ecxPhoneState",{detail:n}),window.dispatchEvent(r)}catch(e){}"AGENT_LOGIN"===n.action?l.getState().setLogin(!0):"AGENT_IDLE"===n.action?l.getState().setIsIdle(!0):("AGENT_ACW"===n.action||"AGENT_AUX"===n.action||"AGENT_OUTBOUND"===n.action||"AGENT_DIALING"===n.action||"AGENT_ON_HOOK"===n.action)&&l.getState().setIsIdle(!1),e.next=27;break;case 10:if(!n.action.startsWith("AGENT_")||"AGENT"!==n.source){e.next=14;break}console.log("onWebSocketMessage AGENT >>>",n),e.next=27;break;case 14:if("EXTENSION_READY"!==n.action){e.next=18;break}i._phone=new A(n.extension,n.secret,n.pbxHttpHost),e.next=27;break;case 18:if("CHECK_EXTENSION_STATUS"!==n.action){e.next=25;break}return o={action:"EXTENSION_STATUS",source:"AGENT",agentId:l.getState().dataLogin,callId:n.callId,context:n.context,extension:n.extension,isRegistered:l.getState().sipRegister,isIdle:l.getState().isIdle},console.log("CHECK_EXTENSION_STATUS",o),e.next=23,i._ws.send(JSON.stringify(o));case 23:e.next=27;break;case 25:"function"==typeof ecxPhoneState&&window.ecxPhoneState(n);try{s=new CustomEvent("ecxPhoneState",{detail:n}),window.dispatchEvent(s)}catch(e){}case 27:e.next=32;break;case 29:e.prev=29,e.t0=e.catch(3),console.error(e.t0);case 32:case"end":return e.stop()}}),e,null,[[3,29]])})));return function(t){return e.apply(this,arguments)}}()),i._ws,i._phone;try{i._ws=new WebSocket("wss://"+r+":8080/ws/client/agent"),l.getState().setEcxSocket(i._ws),l.getState().setEcxAgentId(e),i._ws.binaryType="arraybuffer",i._ws.addEventListener("close",(function(e){return i.onWebSocketClose(e)})),i._ws.addEventListener("error",(function(e){return i.onWebSocketError(e)})),i._ws.addEventListener("open",(function(t){return i.onWebSocketOpen(t,e,n)})),i._ws.addEventListener("message",(function(e){return i.onWebSocketMessage(e)}))}catch(e){console.log(e)}return i.state={message:l.getState().responsePhone},i}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&D(e,t)}(t,e),n=t,(r=[{key:"componentDidMount",value:function(){var e=this;this.unsubscribe=l.subscribe((function(t){e.setState({message:t.message})}))}},{key:"componentWillUnmount",value:function(){this.unsubscribe&&this.unsubscribe()}}])&&I(n.prototype,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r}(i.Component);const U=Object.create(null);U.open="0",U.close="1",U.ping="2",U.pong="3",U.message="4",U.upgrade="5",U.noop="6";const q=Object.create(null);Object.keys(U).forEach((e=>{q[U[e]]=e}));const H={type:"error",data:"parser error"},F="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),B="function"==typeof ArrayBuffer,G=e=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,W=({type:e,data:t},n,r)=>F&&t instanceof Blob?n?r(t):V(t,r):B&&(t instanceof ArrayBuffer||G(t))?n?r(t):V(new Blob([t]),r):r(U[e]+(t||"")),V=(e,t)=>{const n=new FileReader;return n.onload=function(){const e=n.result.split(",")[1];t("b"+(e||""))},n.readAsDataURL(e)};function z(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}let K;const $="undefined"==typeof Uint8Array?[]:new Uint8Array(256);for(let e=0;e<64;e++)$["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(e)]=e;const Y="function"==typeof ArrayBuffer,J=(e,t)=>{if("string"!=typeof e)return{type:"message",data:Q(e,t)};const n=e.charAt(0);return"b"===n?{type:"message",data:X(e.substring(1),t)}:q[n]?e.length>1?{type:q[n],data:e.substring(1)}:{type:q[n]}:H},X=(e,t)=>{if(Y){const n=(e=>{let t,n,r,i,o,s=.75*e.length,a=e.length,u=0;"="===e[e.length-1]&&(s--,"="===e[e.length-2]&&s--);const l=new ArrayBuffer(s),c=new Uint8Array(l);for(t=0;t<a;t+=4)n=$[e.charCodeAt(t)],r=$[e.charCodeAt(t+1)],i=$[e.charCodeAt(t+2)],o=$[e.charCodeAt(t+3)],c[u++]=n<<2|r>>4,c[u++]=(15&r)<<4|i>>2,c[u++]=(3&i)<<6|63&o;return l})(e);return Q(n,t)}return{base64:!0,data:e}},Q=(e,t)=>"blob"===t?e instanceof Blob?e:new Blob([e]):e instanceof ArrayBuffer?e:e.buffer,Z=String.fromCharCode(30);let ee;function te(e){return e.reduce(((e,t)=>e+t.length),0)}function ne(e,t){if(e[0].length===t)return e.shift();const n=new Uint8Array(t);let r=0;for(let i=0;i<t;i++)n[i]=e[0][r++],r===e[0].length&&(e.shift(),r=0);return e.length&&r<e[0].length&&(e[0]=e[0].slice(r)),n}function re(e){if(e)return function(e){for(var t in re.prototype)e[t]=re.prototype[t];return e}(e)}re.prototype.on=re.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},re.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},re.prototype.off=re.prototype.removeListener=re.prototype.removeAllListeners=re.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+e];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var i=0;i<r.length;i++)if((n=r[i])===t||n.fn===t){r.splice(i,1);break}return 0===r.length&&delete this._callbacks["$"+e],this},re.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),n=this._callbacks["$"+e],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(n){r=0;for(var i=(n=n.slice(0)).length;r<i;++r)n[r].apply(this,t)}return this},re.prototype.emitReserved=re.prototype.emit,re.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]},re.prototype.hasListeners=function(e){return!!this.listeners(e).length};const ie="function"==typeof Promise&&"function"==typeof Promise.resolve?e=>Promise.resolve().then(e):(e,t)=>t(e,0),oe="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function se(e,...t){return t.reduce(((t,n)=>(e.hasOwnProperty(n)&&(t[n]=e[n]),t)),{})}const ae=oe.setTimeout,ue=oe.clearTimeout;function le(e,t){t.useNativeTimers?(e.setTimeoutFn=ae.bind(oe),e.clearTimeoutFn=ue.bind(oe)):(e.setTimeoutFn=oe.setTimeout.bind(oe),e.clearTimeoutFn=oe.clearTimeout.bind(oe))}function ce(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}class de extends Error{constructor(e,t,n){super(e),this.description=t,this.context=n,this.type="TransportError"}}class he extends re{constructor(e){super(),this.writable=!1,le(this,e),this.opts=e,this.query=e.query,this.socket=e.socket,this.supportsBinary=!e.forceBase64}onError(e,t,n){return super.emitReserved("error",new de(e,t,n)),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=J(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 n in e)e.hasOwnProperty(n)&&(t.length&&(t+="&"),t+=encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t}(e);return t.length?"?"+t:""}}class fe extends he{constructor(){super(...arguments),this._polling=!1}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 n=e.split(Z),r=[];for(let e=0;e<n.length;e++){const i=J(n[e],t);if(r.push(i),"error"===i.type)break}return r})(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 n=e.length,r=new Array(n);let i=0;e.forEach(((e,o)=>{W(e,!1,(e=>{r[o]=e,++i===n&&t(r.join(Z))}))}))})(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]=ce()),this.supportsBinary||t.sid||(t.b64=1),this.createUri(e,t)}}let pe=!1;try{pe="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(e){}const me=pe;function ve(){}class ge extends fe{constructor(e){if(super(e),"undefined"!=typeof location){const t="https:"===location.protocol;let n=location.port;n||(n=t?"443":"80"),this.xd="undefined"!=typeof location&&e.hostname!==location.hostname||n!==e.port}}doWrite(e,t){const n=this.request({method:"POST",data:e});n.on("success",t),n.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}}class _e extends re{constructor(e,t,n){super(),this.createRequest=e,le(this,n),this._opts=n,this._method=n.method||"GET",this._uri=t,this._data=void 0!==n.data?n.data:null,this._create()}_create(){var e;const t=se(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this._opts.xd;const n=this._xhr=this.createRequest(t);try{n.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){n.setDisableHeaderCheck&&n.setDisableHeaderCheck(!0);for(let e in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(e)&&n.setRequestHeader(e,this._opts.extraHeaders[e])}}catch(e){}if("POST"===this._method)try{n.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(e){}try{n.setRequestHeader("Accept","*/*")}catch(e){}null===(e=this._opts.cookieJar)||void 0===e||e.addCookies(n),"withCredentials"in n&&(n.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(n.timeout=this._opts.requestTimeout),n.onreadystatechange=()=>{var e;3===n.readyState&&(null===(e=this._opts.cookieJar)||void 0===e||e.parseCookies(n.getResponseHeader("set-cookie"))),4===n.readyState&&(200===n.status||1223===n.status?this._onLoad():this.setTimeoutFn((()=>{this._onError("number"==typeof n.status?n.status:0)}),0))},n.send(this._data)}catch(e){return void this.setTimeoutFn((()=>{this._onError(e)}),0)}"undefined"!=typeof document&&(this._index=_e.requestsCount++,_e.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=ve,e)try{this._xhr.abort()}catch(e){}"undefined"!=typeof document&&delete _e.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 ye(){for(let e in _e.requests)_e.requests.hasOwnProperty(e)&&_e.requests[e].abort()}_e.requestsCount=0,_e.requests={},"undefined"!=typeof document&&("function"==typeof attachEvent?attachEvent("onunload",ye):"function"==typeof addEventListener&&addEventListener("onpagehide"in oe?"pagehide":"unload",ye,!1));const be=function(){const e=Te({xdomain:!1});return e&&null!==e.responseType}();function Te(e){const t=e.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!t||me))return new XMLHttpRequest}catch(e){}if(!t)try{return new(oe[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(e){}}const Se="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase();class Ce extends he{get name(){return"websocket"}doOpen(){const e=this.uri(),t=this.opts.protocols,n=Se?{}:se(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(n.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(e,t,n)}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 n=e[t],r=t===e.length-1;W(n,this.supportsBinary,(e=>{try{this.doWrite(n,e)}catch(e){}r&&ie((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){void 0!==this.ws&&(this.ws.onerror=()=>{},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]=ce()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}}const we=oe.WebSocket||oe.MozWebSocket,Ee={websocket:class extends Ce{createSocket(e,t,n){return Se?new we(e,t,n):t?new we(e,t):new we(e)}doWrite(e,t){this.ws.send(t)}},webtransport:class extends he{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(e){return this.emitReserved("error",e)}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){ee||(ee=new TextDecoder);const n=[];let r=0,i=-1,o=!1;return new TransformStream({transform(s,a){for(n.push(s);;){if(0===r){if(te(n)<1)break;const e=ne(n,1);o=!(128&~e[0]),i=127&e[0],r=i<126?3:126===i?1:2}else if(1===r){if(te(n)<2)break;const e=ne(n,2);i=new DataView(e.buffer,e.byteOffset,e.length).getUint16(0),r=3}else if(2===r){if(te(n)<8)break;const e=ne(n,8),t=new DataView(e.buffer,e.byteOffset,e.length),o=t.getUint32(0);if(o>Math.pow(2,21)-1){a.enqueue(H);break}i=o*Math.pow(2,32)+t.getUint32(4),r=3}else{if(te(n)<i)break;const e=ne(n,i);a.enqueue(J(o?e:ee.decode(e),t)),r=0}if(0===i||i>e){a.enqueue(H);break}}}})}(Number.MAX_SAFE_INTEGER,this.socket.binaryType),n=e.readable.pipeThrough(t).getReader(),r=new TransformStream({transform(e,t){!function(e,t){F&&e.data instanceof Blob?e.data.arrayBuffer().then(z).then(t):B&&(e.data instanceof ArrayBuffer||G(e.data))?t(z(e.data)):W(e,!1,(e=>{K||(K=new TextEncoder),t(K.encode(e))}))}(e,(n=>{const r=n.length;let i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);const e=new DataView(i.buffer);e.setUint8(0,126),e.setUint16(1,r)}else{i=new Uint8Array(9);const e=new DataView(i.buffer);e.setUint8(0,127),e.setBigUint64(1,BigInt(r))}e.data&&"string"!=typeof e.data&&(i[0]|=128),t.enqueue(i),t.enqueue(n)}))}});r.readable.pipeTo(e.writable),this._writer=r.writable.getWriter();const i=()=>{n.read().then((({done:e,value:t})=>{e||(this.onPacket(t),i())})).catch((e=>{}))};i();const o={type:"open"};this.query.sid&&(o.data=`{"sid":"${this.query.sid}"}`),this._writer.write(o).then((()=>this.onOpen()))}))}))}write(e){this.writable=!1;for(let t=0;t<e.length;t++){const n=e[t],r=t===e.length-1;this._writer.write(n).then((()=>{r&&ie((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){var e;null===(e=this._transport)||void 0===e||e.close()}},polling:class extends ge{constructor(e){super(e);const t=e&&e.forceBase64;this.supportsBinary=be&&!t}request(e={}){return Object.assign(e,{xd:this.xd},this.opts),new _e(Te,this.uri(),e)}}},Ae=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,Re=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function xe(e){if(e.length>8e3)throw"URI too long";const t=e,n=e.indexOf("["),r=e.indexOf("]");-1!=n&&-1!=r&&(e=e.substring(0,n)+e.substring(n,r).replace(/:/g,";")+e.substring(r,e.length));let i=Ae.exec(e||""),o={},s=14;for(;s--;)o[Re[s]]=i[s]||"";return-1!=n&&-1!=r&&(o.source=t,o.host=o.host.substring(1,o.host.length-1).replace(/;/g,":"),o.authority=o.authority.replace("[","").replace("]","").replace(/;/g,":"),o.ipv6uri=!0),o.pathNames=function(e,t){const n=t.replace(/\/{2,9}/g,"/").split("/");return"/"!=t.slice(0,1)&&0!==t.length||n.splice(0,1),"/"==t.slice(-1)&&n.splice(n.length-1,1),n}(0,o.path),o.queryKey=function(e,t){const n={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,(function(e,t,r){t&&(n[t]=r)})),n}(0,o.query),o}const ke="function"==typeof addEventListener&&"function"==typeof removeEventListener,Oe=[];ke&&addEventListener("offline",(()=>{Oe.forEach((e=>e()))}),!1);class Ie extends re{constructor(e,t){if(super(),this.binaryType="arraybuffer",this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,e&&"object"==typeof e&&(t=e,e=null),e){const n=xe(e);t.hostname=n.host,t.secure="https"===n.protocol||"wss"===n.protocol,t.port=n.port,n.query&&(t.query=n.query)}else t.host&&(t.hostname=xe(t.host).host);le(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=[],this._transportsByName={},t.transports.forEach((e=>{const t=e.prototype.name;this.transports.push(t),this._transportsByName[t]=e})),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={},n=e.split("&");for(let e=0,r=n.length;e<r;e++){let r=n[e].split("=");t[decodeURIComponent(r[0])]=decodeURIComponent(r[1])}return t}(this.opts.query)),ke&&(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"})},Oe.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(e){const t=Object.assign({},this.opts.query);t.EIO=4,t.transport=e,this.id&&(t.sid=this.id);const n=Object.assign({},this.opts,{query:t,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[e]);return new this._transportsByName[e](n)}_open(){if(0===this.transports.length)return void this.setTimeoutFn((()=>{this.emitReserved("error","No transports available")}),0);const e=this.opts.rememberUpgrade&&Ie.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket")?"websocket":this.transports[0];this.readyState="opening";const t=this.createTransport(e);t.open(),this.setTransport(t)}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)))}onOpen(){this.readyState="open",Ie.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush()}_onPacket(e){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",e),this.emitReserved("heartbeat"),e.type){case"open":this.onHandshake(JSON.parse(e.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();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._pingInterval=e.pingInterval,this._pingTimeout=e.pingTimeout,this._maxPayload=e.maxPayload,this.onOpen(),"closed"!==this.readyState&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const e=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+e,this._pingTimeoutTimer=this.setTimeoutFn((()=>{this._onClose("ping timeout")}),e),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 n=0;n<this.writeBuffer.length;n++){const r=this.writeBuffer[n].data;if(r&&(e+="string"==typeof(t=r)?function(e){let t=0,n=0;for(let r=0,i=e.length;r<i;r++)t=e.charCodeAt(r),t<128?n+=1:t<2048?n+=2:t<55296||t>=57344?n+=3:(r++,n+=4);return n}(t):Math.ceil(1.33*(t.byteLength||t.size))),n>0&&e>this._maxPayload)return this.writeBuffer.slice(0,n);e+=2}var t;return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const e=Date.now()>this._pingTimeoutTime;return e&&(this._pingTimeoutTime=0,ie((()=>{this._onClose("ping timeout")}),this.setTimeoutFn)),e}write(e,t,n){return this._sendPacket("message",e,t,n),this}send(e,t,n){return this._sendPacket("message",e,t,n),this}_sendPacket(e,t,n,r){if("function"==typeof t&&(r=t,t=void 0),"function"==typeof n&&(r=n,n=null),"closing"===this.readyState||"closed"===this.readyState)return;(n=n||{}).compress=!1!==n.compress;const i={type:e,data:t,options:n};this.emitReserved("packetCreate",i),this.writeBuffer.push(i),r&&this.once("flush",r),this.flush()}close(){const e=()=>{this._onClose("forced close"),this.transport.close()},t=()=>{this.off("upgrade",t),this.off("upgradeError",t),e()},n=()=>{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?n():e()})):this.upgrading?n():e()),this}_onError(e){if(Ie.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&"opening"===this.readyState)return this.transports.shift(),this._open();this.emitReserved("error",e),this._onClose("transport error",e)}_onClose(e,t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),ke&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const e=Oe.indexOf(this._offlineEventListener);-1!==e&&Oe.splice(e,1)}this.readyState="closed",this.id=null,this.emitReserved("close",e,t),this.writeBuffer=[],this._prevBufferLen=0}}}Ie.protocol=4;class Pe extends Ie{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),"open"===this.readyState&&this.opts.upgrade)for(let e=0;e<this._upgrades.length;e++)this._probe(this._upgrades[e])}_probe(e){let t=this.createTransport(e),n=!1;Ie.priorWebsocketSuccess=!1;const r=()=>{n||(t.send([{type:"ping",data:"probe"}]),t.once("packet",(e=>{if(!n)if("pong"===e.type&&"probe"===e.data){if(this.upgrading=!0,this.emitReserved("upgrading",t),!t)return;Ie.priorWebsocketSuccess="websocket"===t.name,this.transport.pause((()=>{n||"closed"!==this.readyState&&(l(),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 i(){n||(n=!0,l(),t.close(),t=null)}const o=e=>{const n=new Error("probe error: "+e);n.transport=t.name,i(),this.emitReserved("upgradeError",n)};function s(){o("transport closed")}function a(){o("socket closed")}function u(e){t&&e.name!==t.name&&