/*! - Name HS_CTI - FileName hs-cti - Version 1.0.9 - JS Standard es5 - Author platformfe - Built on 2024/11/27 10:37:38 - GitHub - Branch main - CommitID 987d86cd91cde7d1c235ad106d79fc92c305b8ff - CommitMessage fix: 修改socket地址 */ import{Web as e,RequestPendingError as t,SessionState as n,UserAgent as r,UserAgentState as i,Registerer as o,RegistererState as s,Inviter as a,Invitation as c,Session as l,Messager as u}from"sip.js";import d from"socket.io-client";var g=function(e,t){return g=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},g(e,t)};function p(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}g(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var f=function(){return f=Object.assign||function(e){for(var t,n=1,r=arguments.length;n=0;a--)(i=e[a])&&(s=(o<3?i(s):o>3?i(t,n,s):i(t,n))||s);return o>3&&s&&Object.defineProperty(t,n,s),s}function b(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))}function v(e,t){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&o.optionsPingStart()},onDisconnect:function(e){return b(o,void 0,void 0,(function(){var t,n,r,i,o,s=this;return v(this,(function(a){return this.logger.log("Disconnected"),t=!1,this.options.optionsPingInterval>0&&(t=this.optionsPingFailure,this.optionsPingFailure=!1,this.optionsPingStop()),e||t?(this.registerer&&(this.logger.log("Disposing of registerer..."),this.registerer.dispose().catch((function(e){s.logger.debug("Error occurred disposing of registerer after connection with server was lost."),s.logger.debug(e.toString())})),this.registerer=void 0),this.managedSessions.slice().map((function(e){return e.session})).forEach((function(e){return b(s,void 0,void 0,(function(){var t=this;return v(this,(function(n){return this.logger.log("Disposing of session..."),e.dispose().catch((function(e){t.logger.debug("Error occurred disposing of a session after connection with server was lost."),t.logger.debug(e.toString())})),[2]}))}))})),this.shouldBeConnected&&(null===(r=null===(n=this.delegate)||void 0===n?void 0:n.onReconnectStart)||void 0===r||r.call(n),this.attemptReconnection())):null===(o=null===(i=this.delegate)||void 0===i?void 0:i.onServerDisconnect)||void 0===o||o.call(i,e),[2]}))}))},onInvite:function(e){o.logger.log("[".concat(e.id,"] Received INVITE"));var t=o.options.maxSimultaneousSessions;if(0!==t&&o.managedSessions.length>t)return o.logger.warn("[".concat(e.id,"] Session already in progress, rejecting INVITE...")),void e.reject().then((function(){o.logger.log("[".concat(e.id,"] Rejected INVITE"))})).catch((function(t){o.logger.error("[".concat(e.id,"] Failed to reject INVITE")),o.logger.error(t.toString())}));var n={sessionDescriptionHandlerOptions:{constraints:o.constraints}};o.initSession(e,n),o.delegate&&o.delegate.onCallReceived?o.delegate.onCallReceived(e):(o.logger.warn("[".concat(e.id,"] No handler available, rejecting INVITE...")),e.reject().then((function(){o.logger.log("[".concat(e.id,"] Rejected INVITE"))})).catch((function(t){o.logger.error("[".concat(e.id,"] Failed to reject INVITE")),o.logger.error(t.toString())})))},onMessage:function(e){e.accept().then((function(){o.delegate&&o.delegate.onMessageReceived&&o.delegate.onMessageReceived(e)}))},onNotify:function(e){e.accept().then((function(){o.delegate&&o.delegate.onNotificationReceived&&o.delegate.onNotificationReceived(e)}))}},this.registererOptions=f({},n.registererOptions),this.registererRegisterOptions=f({},n.registererRegisterOptions),this.options.registrationRetry){this.registererRegisterOptions.requestDelegate=this.registererRegisterOptions.requestDelegate||{};var c=this.registererRegisterOptions.requestDelegate.onReject;this.registererRegisterOptions.requestDelegate.onReject=function(e){c&&c(e),o.attemptRegistration()}}this.logger=this.userAgent.getLogger("sip.SessionManager"),window.addEventListener("online",(function(){o.logger.log("Online"),o.shouldBeConnected&&o.connect()})),this.options.autoStop&&window.addEventListener("beforeunload",(function(){return b(o,void 0,void 0,(function(){return v(this,(function(e){switch(e.label){case 0:return this.shouldBeConnected=!1,this.shouldBeRegistered=!1,this.userAgent.state===i.Stopped?[3,2]:[4,this.userAgent.stop()];case 1:e.sent(),e.label=2;case 2:return[2]}}))}))}))}return Object.defineProperty(d,"stripUndefinedProperties",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return Object.keys(e).reduce((function(t,n){return void 0!==e[n]&&(t[n]=e[n]),t}),{})}}),Object.defineProperty(d.prototype,"getLocalMediaStream",{enumerable:!1,configurable:!0,writable:!0,value:function(t){var n=t.sessionDescriptionHandler;if(n){if(!(n instanceof e.SessionDescriptionHandler))throw new Error("Session description handler not instance of web SessionDescriptionHandler");return n.localMediaStream}}}),Object.defineProperty(d.prototype,"getRemoteMediaStream",{enumerable:!1,configurable:!0,writable:!0,value:function(t){var n=t.sessionDescriptionHandler;if(n){if(!(n instanceof e.SessionDescriptionHandler))throw new Error("Session description handler not instance of web SessionDescriptionHandler");return n.remoteMediaStream}}}),Object.defineProperty(d.prototype,"getLocalAudioTrack",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t;return null===(t=this.getLocalMediaStream(e))||void 0===t?void 0:t.getTracks().find((function(e){return"audio"===e.kind}))}}),Object.defineProperty(d.prototype,"getLocalVideoTrack",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t;return null===(t=this.getLocalMediaStream(e))||void 0===t?void 0:t.getTracks().find((function(e){return"video"===e.kind}))}}),Object.defineProperty(d.prototype,"getRemoteAudioTrack",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t;return null===(t=this.getRemoteMediaStream(e))||void 0===t?void 0:t.getTracks().find((function(e){return"audio"===e.kind}))}}),Object.defineProperty(d.prototype,"getRemoteVideoTrack",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t;return null===(t=this.getRemoteMediaStream(e))||void 0===t?void 0:t.getTracks().find((function(e){return"video"===e.kind}))}}),Object.defineProperty(d.prototype,"connect",{enumerable:!1,configurable:!0,writable:!0,value:function(){return b(this,void 0,void 0,(function(){return v(this,(function(e){return this.logger.log("Connecting UserAgent..."),this.shouldBeConnected=!0,this.userAgent.state!==i.Started?[2,this.userAgent.start()]:[2,this.userAgent.reconnect()]}))}))}}),Object.defineProperty(d.prototype,"disconnect",{enumerable:!1,configurable:!0,writable:!0,value:function(){return b(this,void 0,void 0,(function(){return v(this,(function(e){return this.logger.log("Disconnecting UserAgent..."),this.userAgent.state===i.Stopped?[2,Promise.resolve()]:(this.shouldBeConnected=!1,this.shouldBeRegistered=!1,this.registerer=void 0,[2,this.userAgent.stop()])}))}))}}),Object.defineProperty(d.prototype,"isConnected",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.userAgent.isConnected()}}),Object.defineProperty(d.prototype,"register",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return b(this,void 0,void 0,(function(){var t=this;return v(this,(function(n){return this.logger.log("Registering UserAgent..."),this.shouldBeRegistered=!0,void 0!==e&&(this.registererRegisterOptions=f({},e)),this.registerer||(this.registerer=new o(this.userAgent,this.registererOptions),this.registerer.stateChange.addListener((function(e){switch(e){case s.Initial:break;case s.Registered:t.delegate&&t.delegate.onRegistered&&t.delegate.onRegistered();break;case s.Unregistered:t.delegate&&t.delegate.onUnregistered&&t.delegate.onUnregistered(),t.shouldBeRegistered&&t.attemptRegistration();break;case s.Terminated:break;default:throw new Error("Unknown registerer state.")}}))),[2,this.attemptRegistration(!0)]}))}))}}),Object.defineProperty(d.prototype,"unregister",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return b(this,void 0,void 0,(function(){return v(this,(function(t){return this.logger.log("Unregistering UserAgent..."),this.shouldBeRegistered=!1,this.registerer?[2,this.registerer.unregister(e).then((function(){}))]:(this.logger.warn("No registerer to unregister."),[2,Promise.resolve()])}))}))}}),Object.defineProperty(d.prototype,"call",{enumerable:!1,configurable:!0,writable:!0,value:function(t,n,i){return b(this,void 0,void 0,(function(){var o,s,c,l,u=this;return v(this,(function(d){return this.logger.log("Beginning Session..."),0!==(o=this.options.maxSimultaneousSessions)&&this.managedSessions.length>o?[2,Promise.reject(new Error("Maximum number of sessions already exists."))]:(s=r.makeURI(t))?(n||(n={}),n.sessionDescriptionHandlerOptions||(n.sessionDescriptionHandlerOptions={}),n.sessionDescriptionHandlerOptions.constraints||(n.sessionDescriptionHandlerOptions.constraints=this.constraints),n.earlyMedia&&((i=i||{}).requestDelegate=i.requestDelegate||{},c=i.requestDelegate.onProgress,i.requestDelegate.onProgress=function(e){183===e.message.statusCode&&u.setupRemoteMedia(l),c&&c(e)}),this.options.iceStopWaitingOnServerReflexive&&(n.delegate=n.delegate||{},n.delegate.onSessionDescriptionHandler=function(t){if(!(t instanceof e.SessionDescriptionHandler))throw new Error("Session description handler not instance of SessionDescriptionHandler");t.peerConnectionDelegate={onicecandidate:function(e){var n;"srflx"===(null===(n=e.candidate)||void 0===n?void 0:n.type)&&(u.logger.log("[".concat(l.id,"] Found srflx ICE candidate, stop waiting...")),t.iceGatheringComplete())}}}),l=new a(this.userAgent,s,n),[2,this.sendInvite(l,n,i).then((function(){return l}))]):[2,Promise.reject(new Error('Failed to create a valid URI from "'.concat(t,'"')))]}))}))}}),Object.defineProperty(d.prototype,"hangup",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return b(this,void 0,void 0,(function(){return v(this,(function(t){return this.logger.log("[".concat(e.id,"] Hangup...")),this.sessionExists(e)?[2,this.terminate(e)]:[2,Promise.reject(new Error("Session does not exist."))]}))}))}}),Object.defineProperty(d.prototype,"answer",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return b(this,void 0,void 0,(function(){return v(this,(function(n){return this.logger.log("[".concat(e.id,"] Accepting Invitation...")),this.sessionExists(e)?e instanceof c?(t||(t={}),t.sessionDescriptionHandlerOptions||(t.sessionDescriptionHandlerOptions={}),t.sessionDescriptionHandlerOptions.constraints||(t.sessionDescriptionHandlerOptions.constraints=this.constraints),[2,e.accept(t)]):[2,Promise.reject(new Error("Session not instance of Invitation."))]:[2,Promise.reject(new Error("Session does not exist."))]}))}))}}),Object.defineProperty(d.prototype,"decline",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return b(this,void 0,void 0,(function(){return v(this,(function(t){return this.logger.log("[".concat(e.id,"] Rejecting Invitation...")),this.sessionExists(e)?e instanceof c?[2,e.reject()]:[2,Promise.reject(new Error("Session not instance of Invitation."))]:[2,Promise.reject(new Error("Session does not exist."))]}))}))}}),Object.defineProperty(d.prototype,"hold",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return b(this,void 0,void 0,(function(){return v(this,(function(t){return this.logger.log("[".concat(e.id,"] Holding session...")),[2,this.setHold(e,!0)]}))}))}}),Object.defineProperty(d.prototype,"unhold",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return b(this,void 0,void 0,(function(){return v(this,(function(t){return this.logger.log("[".concat(e.id,"] Unholding session...")),[2,this.setHold(e,!1)]}))}))}}),Object.defineProperty(d.prototype,"isHeld",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.sessionManaged(e);return!!t&&t.held}}),Object.defineProperty(d.prototype,"mute",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.logger.log("[".concat(e.id,"] Disabling media tracks...")),this.setMute(e,!0)}}),Object.defineProperty(d.prototype,"unmute",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.logger.log("[".concat(e.id,"] Enabling media tracks...")),this.setMute(e,!1)}}),Object.defineProperty(d.prototype,"isMuted",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.sessionManaged(e);return!!t&&t.muted}}),Object.defineProperty(d.prototype,"sendDTMF",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return b(this,void 0,void 0,(function(){var n;return v(this,(function(r){return this.logger.log("[".concat(e.id,"] Sending DTMF...")),/^[0-9A-D#*,]$/.exec(t)?this.sessionExists(e)?(this.logger.log("[".concat(e.id,"] Sending DTMF tone: ").concat(t)),this.options.sendDTMFUsingSessionDescriptionHandler?e.sessionDescriptionHandler?e.sessionDescriptionHandler.sendDtmf(t)?[2,Promise.resolve()]:[2,Promise.reject(new Error("Failed to send DTMF"))]:[2,Promise.reject(new Error("Session desciption handler undefined."))]:(n={body:{contentDisposition:"render",contentType:"application/dtmf-relay",content:"Signal="+t+"\r\nDuration=2000"}},[2,e.info({requestOptions:n}).then((function(){}))])):[2,Promise.reject(new Error("Session does not exist."))]:[2,Promise.reject(new Error("Invalid DTMF tone."))]}))}))}}),Object.defineProperty(d.prototype,"transfer",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n){return b(this,void 0,void 0,(function(){var i;return v(this,(function(o){return this.logger.log("[".concat(e.id,"] Referring session...")),t instanceof l?[2,e.refer(t,n).then((function(){}))]:(i=r.makeURI(t))?[2,e.refer(i,n).then((function(){}))]:[2,Promise.reject(new Error('Failed to create a valid URI from "'.concat(t,'"')))]}))}))}}),Object.defineProperty(d.prototype,"message",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return b(this,void 0,void 0,(function(){var n;return v(this,(function(i){return this.logger.log("Sending message..."),(n=r.makeURI(e))?[2,new u(this.userAgent,n,t).message()]:[2,Promise.reject(new Error('Failed to create a valid URI from "'.concat(e,'"')))]}))}))}}),Object.defineProperty(d.prototype,"constraints",{get:function(){var e={audio:!0,video:!1};return this.options.media.constraints&&(e=f({},this.options.media.constraints)),e},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"attemptReconnection",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t,n,r=this;void 0===e&&(e=1);var i=this.options.reconnectionAttempts,o=this.options.reconnectionDelay;if(this.shouldBeConnected){if(this.attemptingReconnection&&this.logger.log("Reconnection attempt already in progress"),e>i)return this.logger.log("Reconnection maximum attempts reached"),void(null===(n=null===(t=this.delegate)||void 0===t?void 0:t.onReconnectFailed)||void 0===n||n.call(t));1===e?this.logger.log("Reconnection attempt ".concat(e," of ").concat(i," - trying")):this.logger.log("Reconnection attempt ".concat(e," of ").concat(i," - trying in ").concat(o," seconds")),this.attemptingReconnection=!0,setTimeout((function(){if(!r.shouldBeConnected)return r.logger.log("Reconnection attempt ".concat(e," of ").concat(i," - aborted")),void(r.attemptingReconnection=!1);r.userAgent.reconnect().then((function(){r.logger.log("Reconnection attempt ".concat(e," of ").concat(i," - succeeded")),r.attemptingReconnection=!1})).catch((function(t){r.logger.log("Reconnection attempt ".concat(e," of ").concat(i," - failed")),r.logger.error(t.message),r.attemptingReconnection=!1,r.attemptReconnection(++e)}))}),1===e?0:1e3*o)}else this.logger.log("Should not be connected currently")}}),Object.defineProperty(d.prototype,"attemptRegistration",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var n=this;if(void 0===e&&(e=!1),this.logger.log("Registration attempt ".concat(e?"without delay":"")),!this.shouldBeRegistered)return this.logger.log("Should not be registered currently"),Promise.resolve();if(void 0!==this.registrationAttemptTimeout)return this.logger.log("Registration attempt already in progress"),Promise.resolve();return new Promise((function(r,o){var s,a;n.registrationAttemptTimeout=setTimeout((function(){(n.registerer?n.isConnected()?n.userAgent.state===i.Stopped?(n.logger.log("User agent stopped"),Promise.resolve()):n.options.registerGuard?n.options.registerGuard().catch((function(e){throw n.logger.log("Register guard rejected will making registration attempt"),e})).then((function(e){return e||!n.registerer?Promise.resolve():n.registerer.register(n.registererRegisterOptions).then((function(){}))})):n.registerer.register(n.registererRegisterOptions).then((function(){})):(n.logger.log("User agent not connected"),Promise.resolve()):(n.logger.log("Registerer undefined"),Promise.resolve())).then((function(){n.registrationAttemptTimeout=void 0,r()})).catch((function(e){n.registrationAttemptTimeout=void 0,e instanceof t?r():o(e)}))}),e?0:(s=n.options.registrationRetryInterval,a=2*s,1e3*(Math.random()*(a-s)+s)))}))}}),Object.defineProperty(d.prototype,"cleanupMedia",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.sessionManaged(e);if(!t)throw new Error("Managed session does not exist.");t.mediaLocal&&t.mediaLocal.video&&(t.mediaLocal.video.srcObject=null,t.mediaLocal.video.pause()),t.mediaRemote&&(t.mediaRemote.audio&&(t.mediaRemote.audio.srcObject=null,t.mediaRemote.audio.pause()),t.mediaRemote.video&&(t.mediaRemote.video.srcObject=null,t.mediaRemote.video.pause()))}}),Object.defineProperty(d.prototype,"enableReceiverTracks",{enumerable:!1,configurable:!0,writable:!0,value:function(t,n){if(!this.sessionExists(t))throw new Error("Session does not exist.");var r=t.sessionDescriptionHandler;if(!(r instanceof e.SessionDescriptionHandler))throw new Error("Session's session description handler not instance of SessionDescriptionHandler.");r.enableReceiverTracks(n)}}),Object.defineProperty(d.prototype,"enableSenderTracks",{enumerable:!1,configurable:!0,writable:!0,value:function(t,n){if(!this.sessionExists(t))throw new Error("Session does not exist.");var r=t.sessionDescriptionHandler;if(!(r instanceof e.SessionDescriptionHandler))throw new Error("Session's session description handler not instance of SessionDescriptionHandler.");r.enableSenderTracks(n)}}),Object.defineProperty(d.prototype,"initSession",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this;this.sessionAdd(e),this.delegate&&this.delegate.onCallCreated&&this.delegate.onCallCreated(e),e.stateChange.addListener((function(t){switch(r.logger.log("[".concat(e.id,"] Session state changed to ").concat(t)),t){case n.Initial:case n.Establishing:break;case n.Established:r.setupLocalMedia(e),r.setupRemoteMedia(e),r.delegate&&r.delegate.onCallAnswered&&r.delegate.onCallAnswered(e);break;case n.Terminating:case n.Terminated:r.sessionExists(e)&&(r.cleanupMedia(e),r.sessionRemove(e),r.delegate&&r.delegate.onCallHangup&&r.delegate.onCallHangup(e));break;default:throw new Error("Unknown session state.")}})),e.delegate=e.delegate||{},e.delegate.onInfo=function(t){var n;if(void 0!==(null===(n=r.delegate)||void 0===n?void 0:n.onCallDTMFReceived)){var i=t.request.getHeader("content-type");if(i&&/^application\/dtmf-relay/i.exec(i)){var o=t.request.body.split("\r\n",2);if(2===o.length){var s,a=/^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/;if(void 0!==o[0]&&a.test(o[0])&&(s=o[0].replace(a,"$2")),s){var c,l=/^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;void 0!==o[1]&&l.test(o[1])&&(c=parseInt(o[1].replace(l,"$2"),10)),c?t.accept().then((function(){if(r.delegate&&r.delegate.onCallDTMFReceived){if(!s||!c)throw new Error("Tone or duration undefined.");r.delegate.onCallDTMFReceived(e,s,c)}})).catch((function(e){r.logger.error(e.message)})):t.reject()}else t.reject()}else t.reject()}else t.reject()}else t.reject()},e.delegate.onRefer=function(e){e.accept().then((function(){return r.sendInvite(e.makeInviter(t),t)})).catch((function(e){r.logger.error(e.message)}))}}}),Object.defineProperty(d.prototype,"optionsPingRun",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n){var r=this;if(this.options.optionsPingInterval<1)throw new Error("Invalid options ping interval.");this.optionsPingRunning||(this.optionsPingRunning=!0,this.optionsPingTimeout=setTimeout((function(){r.optionsPingTimeout=void 0;var i=function(){r.optionsPingFailure=!1,r.optionsPingRunning&&(r.optionsPingRunning=!1,r.optionsPingRun(e,t,n))},o=r.userAgent.userAgentCore,s=o.makeOutgoingRequestMessage("OPTIONS",e,t,n,{});r.optionsPingRequest=o.request(s,{onAccept:function(){r.optionsPingRequest=void 0,i()},onReject:function(e){r.optionsPingRequest=void 0,408===e.message.statusCode||503===e.message.statusCode?(r.logger.error("OPTIONS ping failed"),r.optionsPingFailure=!0,r.optionsPingRunning=!1,r.userAgent.transport.disconnect().catch((function(e){return r.logger.error(e)}))):i()}})}),1e3*this.options.optionsPingInterval))}}),Object.defineProperty(d.prototype,"optionsPingStart",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e,t,n;if(this.logger.log("OPTIONS pings started"),this.options.optionsPingRequestURI){if(!(e=r.makeURI(this.options.optionsPingRequestURI)))throw new Error("Failed to create Request URI.");t=this.userAgent.contact.uri.clone(),n=this.userAgent.contact.uri.clone()}else{if(!this.options.aor)return void this.logger.error("You have enabled sending OPTIONS pings and as such you must provide either a) an AOR to register, or b) an RURI to use for the target of the OPTIONS ping requests. ");var i=r.makeURI(this.options.aor);if(!i)throw new Error("Failed to create URI.");(e=i.clone()).user=void 0,t=i.clone(),n=i.clone()}this.optionsPingRun(e,t,n)}}),Object.defineProperty(d.prototype,"optionsPingStop",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.logger.log("OPTIONS pings stopped"),this.optionsPingRunning=!1,this.optionsPingFailure=!1,this.optionsPingRequest&&(this.optionsPingRequest.dispose(),this.optionsPingRequest=void 0),this.optionsPingTimeout&&(clearTimeout(this.optionsPingTimeout),this.optionsPingTimeout=void 0)}}),Object.defineProperty(d.prototype,"sendInvite",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n){return b(this,void 0,void 0,(function(){var r=this;return v(this,(function(i){return this.initSession(e,t),[2,e.invite(n).then((function(){r.logger.log("[".concat(e.id,"] Sent INVITE"))}))]}))}))}}),Object.defineProperty(d.prototype,"managedSessionFactory",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return{session:t,held:!1,muted:!1}}}),Object.defineProperty(d.prototype,"sessionAdd",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.managedSessionFactory(this,e);this.managedSessions.push(t)}}),Object.defineProperty(d.prototype,"sessionExists",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return void 0!==this.sessionManaged(e)}}),Object.defineProperty(d.prototype,"sessionManaged",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.managedSessions.find((function(t){return t.session.id===e.id}))}}),Object.defineProperty(d.prototype,"sessionRemove",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.managedSessions=this.managedSessions.filter((function(t){return t.session.id!==e.id}))}}),Object.defineProperty(d.prototype,"setHold",{enumerable:!1,configurable:!0,writable:!0,value:function(n,r){return b(this,void 0,void 0,(function(){var i,o,s,a=this;return v(this,(function(c){if(!this.sessionExists(n))return[2,Promise.reject(new Error("Session does not exist."))];if(this.isHeld(n)===r)return[2,Promise.resolve()];if(!(n.sessionDescriptionHandler instanceof e.SessionDescriptionHandler))throw new Error("Session's session description handler not instance of SessionDescriptionHandler.");if(i={requestDelegate:{onAccept:function(){var e=a.sessionManaged(n);void 0!==e&&(e.held=r,a.enableReceiverTracks(n,!e.held),a.enableSenderTracks(n,!e.held&&!e.muted),a.delegate&&a.delegate.onCallHold&&a.delegate.onCallHold(n,e.held))},onReject:function(){a.logger.warn("[".concat(n.id,"] Re-invite request was rejected"));var e=a.sessionManaged(n);void 0!==e&&(e.held=!r,a.enableReceiverTracks(n,!e.held),a.enableSenderTracks(n,!e.held&&!e.muted),a.delegate&&a.delegate.onCallHold&&a.delegate.onCallHold(n,e.held))}}},(o=n.sessionDescriptionHandlerOptionsReInvite).hold=r,n.sessionDescriptionHandlerOptionsReInvite=o,!(s=this.sessionManaged(n)))throw new Error("Managed session is undefiend.");return s.held=r,[2,n.invite(i).then((function(){var e=a.sessionManaged(n);void 0!==e&&(a.enableReceiverTracks(n,!e.held),a.enableSenderTracks(n,!e.held&&!e.muted))})).catch((function(e){throw s.held=!r,e instanceof t&&a.logger.error("[".concat(n.id,"] A hold request is already in progress.")),e}))]}))}))}}),Object.defineProperty(d.prototype,"setMute",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(this.sessionExists(e))if(e.state===n.Established){var r=this.sessionManaged(e);void 0!==r&&(r.muted=t,this.enableSenderTracks(e,!r.held&&!r.muted))}else this.logger.warn("[".concat(e.id,"] An established session is required to enable/disable media tracks"));else this.logger.warn("[".concat(e.id,"] A session is required to enabled/disable media tracks"))}}),Object.defineProperty(d.prototype,"setupLocalMedia",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this,n=this.sessionManaged(e);if(!n)throw new Error("Managed session does not exist.");var r="function"==typeof this.options.media.local?this.options.media.local(e):this.options.media.local;n.mediaLocal=r;var i=null==r?void 0:r.video;if(i){var o=this.getLocalMediaStream(e);if(!o)throw new Error("Local media stream undefiend.");i.srcObject=o,i.volume=0,i.play().catch((function(n){t.logger.error("[".concat(e.id,"] Failed to play local media")),t.logger.error(n.message)}))}}}),Object.defineProperty(d.prototype,"setupRemoteMedia",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this,n=this.sessionManaged(e);if(!n)throw new Error("Managed session does not exist.");var r="function"==typeof this.options.media.remote?this.options.media.remote(e):this.options.media.remote;n.mediaRemote=r;var i=(null==r?void 0:r.video)||(null==r?void 0:r.audio);if(i){var o=this.getRemoteMediaStream(e);if(!o)throw new Error("Remote media stream undefiend.");i.autoplay=!0,i.srcObject=o,i.play().catch((function(n){t.logger.error("[".concat(e.id,"] Failed to play remote media")),t.logger.error(n.message)})),o.onaddtrack=function(){t.logger.log("Remote media onaddtrack"),i.load(),i.play().catch((function(n){t.logger.error("[".concat(e.id,"] Failed to play remote media")),t.logger.error(n.message)}))}}}}),Object.defineProperty(d.prototype,"terminate",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return b(this,void 0,void 0,(function(){var t=this;return v(this,(function(r){switch(this.logger.log("[".concat(e.id,"] Terminating...")),e.state){case n.Initial:if(e instanceof a)return[2,e.cancel().then((function(){t.logger.log("[".concat(e.id,"] Inviter never sent INVITE (canceled)"))}))];if(e instanceof c)return[2,e.reject().then((function(){t.logger.log("[".concat(e.id,"] Invitation rejected (sent 480)"))}))];throw new Error("Unknown session type.");case n.Establishing:if(e instanceof a)return[2,e.cancel().then((function(){t.logger.log("[".concat(e.id,"] Inviter canceled (sent CANCEL)"))}))];if(e instanceof c)return[2,e.reject().then((function(){t.logger.log("[".concat(e.id,"] Invitation rejected (sent 480)"))}))];throw new Error("Unknown session type.");case n.Established:return[2,e.bye().then((function(){t.logger.log("[".concat(e.id,"] Session ended (sent BYE)"))}))];case n.Terminating:case n.Terminated:break;default:throw new Error("Unknown state")}return this.logger.log("[".concat(e.id,"] Terminating in state ").concat(e.state,", no action taken")),[2,Promise.resolve()]}))}))}}),d}(),S=function(){function e(e,t){void 0===t&&(t={});var n=this;Object.defineProperty(this,"delegate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"session",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"sessionManager",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.delegate=t.delegate,this.options=f({},t);var r={aor:this.options.aor,delegate:{onCallAnswered:function(){var e,t;return null===(t=null===(e=n.delegate)||void 0===e?void 0:e.onCallAnswered)||void 0===t?void 0:t.call(e)},onCallCreated:function(e){var t,r,i,o;n.session=e,null===(r=null===(t=n.delegate)||void 0===t?void 0:t.onCallBegin)||void 0===r||r.call(t,e),null===(o=null===(i=n.delegate)||void 0===i?void 0:i.onCallCreated)||void 0===o||o.call(i)},onCallReceived:function(e){var t,r,i,o;null===(r=null===(t=n.delegate)||void 0===t?void 0:t.onCallReceived)||void 0===r||r.call(t),null===(o=null===(i=n.delegate)||void 0===i?void 0:i.onInvite)||void 0===o||o.call(i,e)},onCallHangup:function(){var e,t;n.session=void 0,(null===(e=n.delegate)||void 0===e?void 0:e.onCallHangup)&&(null===(t=n.delegate)||void 0===t||t.onCallHangup())},onCallHold:function(e,t){var r,i;return null===(i=null===(r=n.delegate)||void 0===r?void 0:r.onCallHold)||void 0===i?void 0:i.call(r,t)},onCallDTMFReceived:function(e,t,r){var i,o;return null===(o=null===(i=n.delegate)||void 0===i?void 0:i.onCallDTMFReceived)||void 0===o?void 0:o.call(i,t,r)},onMessageReceived:function(e){var t,r;return null===(r=null===(t=n.delegate)||void 0===t?void 0:t.onMessageReceived)||void 0===r?void 0:r.call(t,e.request.body)},onRegistered:function(){var e,t;return null===(t=null===(e=n.delegate)||void 0===e?void 0:e.onRegistered)||void 0===t?void 0:t.call(e)},onUnregistered:function(){var e,t;return null===(t=null===(e=n.delegate)||void 0===e?void 0:e.onUnregistered)||void 0===t?void 0:t.call(e)},onServerConnect:function(){var e,t;return null===(t=null===(e=n.delegate)||void 0===e?void 0:e.onServerConnect)||void 0===t?void 0:t.call(e)},onServerDisconnect:function(){var e,t;return null===(t=null===(e=n.delegate)||void 0===e?void 0:e.onServerDisconnect)||void 0===t?void 0:t.call(e)},onReconnectFailed:function(){var e,t;return null===(t=null===(e=n.delegate)||void 0===e?void 0:e.onReconnectFailed)||void 0===t?void 0:t.call(e)},onReconnectStart:function(){var e,t;return null===(t=null===(e=n.delegate)||void 0===e?void 0:e.onReconnectStart)||void 0===t?void 0:t.call(e)}},maxSimultaneousSessions:1,media:this.options.media,optionsPingInterval:this.options.optionsPingInterval,optionsPingRequestURI:this.options.aor,reconnectionAttempts:this.options.reconnectionAttempts,reconnectionDelay:this.options.reconnectionDelay,registererOptions:this.options.registererOptions,sendDTMFUsingSessionDescriptionHandler:this.options.sendDTMFUsingSessionDescriptionHandler,userAgentOptions:this.options.userAgentOptions};this.sessionManager=new y(e,r),this.sessionManager.userAgent.stateChange.addListener((function(e){var t,r;null===(r=null===(t=n.delegate)||void 0===t?void 0:t.onUserAgentStateChange)||void 0===r||r.call(t,e)})),this.logger=this.sessionManager.userAgent.getLogger("sip.SimpleUser")}return Object.defineProperty(e.prototype,"id",{get:function(){return this.options.userAgentOptions&&this.options.userAgentOptions.displayName||"Anonymous"},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"localMediaStream",{get:function(){return this.session&&this.sessionManager.getLocalMediaStream(this.session)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"remoteMediaStream",{get:function(){return this.session&&this.sessionManager.getRemoteMediaStream(this.session)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"localAudioTrack",{get:function(){return this.session&&this.sessionManager.getLocalAudioTrack(this.session)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"localVideoTrack",{get:function(){return this.session&&this.sessionManager.getLocalVideoTrack(this.session)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"remoteAudioTrack",{get:function(){return this.session&&this.sessionManager.getRemoteAudioTrack(this.session)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"remoteVideoTrack",{get:function(){return this.session&&this.sessionManager.getRemoteVideoTrack(this.session)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"connect",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.logger.log("[".concat(this.id,"] Connecting UserAgent...")),this.sessionManager.connect()}}),Object.defineProperty(e.prototype,"disconnect",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.logger.log("[".concat(this.id,"] Disconnecting UserAgent...")),this.sessionManager.disconnect()}}),Object.defineProperty(e.prototype,"isConnected",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.sessionManager.isConnected()}}),Object.defineProperty(e.prototype,"register",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.logger.log("[".concat(this.id,"] Registering UserAgent...")),this.sessionManager.register(e)}}),Object.defineProperty(e.prototype,"unregister",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.logger.log("[".concat(this.id,"] Unregistering UserAgent...")),this.sessionManager.unregister(e)}}),Object.defineProperty(e.prototype,"call",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n){return this.logger.log("[".concat(this.id,"] Beginning Session...")),this.session?Promise.reject(new Error("Session already exists.")):this.sessionManager.call(e,t,n).then((function(){}))}}),Object.defineProperty(e.prototype,"hangup",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;return this.logger.log("[".concat(this.id,"] Hangup...")),this.session?this.sessionManager.hangup(this.session).then((function(){e.session=void 0})):Promise.reject(new Error("Session does not exist."))}}),Object.defineProperty(e.prototype,"answer",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.logger.log("[".concat(this.id,"] Accepting Invitation...")),this.session?this.sessionManager.answer(this.session,e):Promise.reject(new Error("Session does not exist."))}}),Object.defineProperty(e.prototype,"decline",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.logger.log("[".concat(this.id,"] rejecting Invitation...")),this.session?this.sessionManager.decline(this.session):Promise.reject(new Error("Session does not exist."))}}),Object.defineProperty(e.prototype,"hold",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.logger.log("[".concat(this.id,"] holding session...")),this.session?this.sessionManager.hold(this.session):Promise.reject(new Error("Session does not exist."))}}),Object.defineProperty(e.prototype,"unhold",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.logger.log("[".concat(this.id,"] unholding session...")),this.session?this.sessionManager.unhold(this.session):Promise.reject(new Error("Session does not exist."))}}),Object.defineProperty(e.prototype,"isHeld",{enumerable:!1,configurable:!0,writable:!0,value:function(){return!!this.session&&this.sessionManager.isHeld(this.session)}}),Object.defineProperty(e.prototype,"mute",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.logger.log("[".concat(this.id,"] disabling media tracks...")),this.session&&this.sessionManager.mute(this.session)}}),Object.defineProperty(e.prototype,"unmute",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.logger.log("[".concat(this.id,"] enabling media tracks...")),this.session&&this.sessionManager.unmute(this.session)}}),Object.defineProperty(e.prototype,"isMuted",{enumerable:!1,configurable:!0,writable:!0,value:function(){return!!this.session&&this.sessionManager.isMuted(this.session)}}),Object.defineProperty(e.prototype,"sendDTMF",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.logger.log("[".concat(this.id,"] sending DTMF...")),this.session?this.sessionManager.sendDTMF(this.session,e):Promise.reject(new Error("Session does not exist."))}}),Object.defineProperty(e.prototype,"message",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return this.logger.log("[".concat(this.id,"] sending message...")),this.sessionManager.message(e,t)}}),e}();let w=Object.prototype.hasOwnProperty,O="~";function P(){}function k(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function _(e,t,n,r,i){if("function"!=typeof n)throw new TypeError("The listener must be a function");const o=new k(n,r||e,i),s=O?O+t:t;return e._events[s]?e._events[s].fn?e._events[s]=[e._events[s],o]:e._events[s].push(o):(e._events[s]=o,e._eventsCount++),e}function j(e,t){0==--e._eventsCount?e._events=new P:delete e._events[t]}function R(){this._events=new P,this._eventsCount=0}Object.create&&(P.prototype=Object.create(null),(new P).__proto__||(O=!1)),R.prototype.eventNames=function(){let e,t,n=[];if(0===this._eventsCount)return n;for(t in e=this._events)w.call(e,t)&&n.push(O?t.slice(1):t);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(e)):n},R.prototype.listeners=function(e){const t=O?O+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var r=0,i=n.length,o=new Array(i);r=e&&this.print(e,this.category,this.label,t)}}),Object.defineProperty(e.prototype,"print",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n,r){if("string"==typeof r){var i=[(o=Date.now(),s=new Date(o),a=s.getFullYear(),c=String(s.getMonth()+1).padStart(2,"0"),l=String(s.getDate()).padStart(2,"0"),u=String(s.getHours()).padStart(2,"0"),d=String(s.getMinutes()).padStart(2,"0"),g=String(s.getSeconds()).padStart(2,"0"),p=String(s.getMilliseconds()).padStart(3,"0"),"".concat(a,"-").concat(c,"-").concat(l," ").concat(u,":").concat(d,":").concat(g,".").concat(p))];n&&i.push(n),r=i.concat(r).join(" | ")}var o,s,a,c,l,u,d,g,p;switch(e){case T.error:console.error("%c".concat(t),"color: blue;",r);break;case T.warn:console.warn("%c".concat(t),"color: blue;",r);break;case T.log:console.log("%c".concat(t),"color: blue;",r);break;case T.debug:console.debug("%c".concat(t),"color: blue;",r)}}}),Object.defineProperty(e.prototype,"level",{get:function(){return this._level},set:function(e){e>=0&&e<=3?this._level=e:e>3?this._level=3:T.hasOwnProperty(e)?this._level=e:this.error("invalid 'level' parameter value: "+JSON.stringify(e))},enumerable:!1,configurable:!0}),e}();!function(e){e.Manual="manual",e.Robot="robot",e.Monitor="monitor",e.Predictive="predictive",e.Wechat="wechat"}(I||(I={})),function(e){e.All="all",e.Manual="manual",e.Robot="robot",e.Predictive="predictive"}(A||(A={})),function(e){e.Initial="Initial",e.Connecting="Connecting",e.Connected="Connected",e.Ready="Ready",e.ReTry="ReTry",e.Terminated="Terminated"}(C||(C={})),function(e){e.Initial="Initial",e.Started="Started",e.Connecting="Connecting",e.Connected="Connected",e.Ready="Ready",e.ReTry="ReTry",e.Terminated="Terminated"}(E||(E={})),function(e){e.Initial="Initial",e.Ready="Ready",e.ReTry="ReTry",e.Terminated="Terminated"}(M||(M={})),function(e){e.Started="Started",e.Stopped="Stopped"}(D||(D={})),function(e){e.Initial="Initial",e.Establishing="Establishing",e.Established="Established",e.Terminating="Terminating",e.Terminated="Terminated"}(L||(L={})),function(e){e.SdkTerminated="SdkTerminated",e.SdkError="SdkError",e.ServerTerminated="ServerTerminated",e.ServerError="ServerError"}(x||(x={})),function(e){e.CTITerminated="100001",e.GetUserMedia="100002",e.GetInitConfig="100003",e.SocketOnError="110001",e.SocketOnConnectError="110002",e.SocketOnDisconnect="110003",e.SocketRepeatLogin="110004",e.SocketOnReconnectFailed="110007",e.SIPInitUserAgent="120001",e.SIPInitRegister="120002",e.SIPUserAgentStateStopped="120003",e.SIPTransportStateDisconnected="120004",e.SIPRegistererStateTerminated="120005",e.SIPOnDisconnect="120006",e.SIPInitTransport="120007",e.SipHeartBeatErr="120008",e.SIPUnRegistered="120009"}(H||(H={})),function(e){e.Answer="200001",e.Bye="200002",e.InvitationCancel="200003",e.AssignStream="200004",e.FetchError="200005"}(U||(U={})),function(e){e.OnCtiError="OnCtiError",e.OnSessionStatusChange="OnSessionStatusChange",e.OnInitalSuccess="OnInitalSuccess",e.OnAgentWorkReport="OnAgentWorkReport",e.OnRingStart="OnRingStart",e.OnRingEnd="OnRingEnd",e.OnDetectedTone="OnDetectedTone",e.OnAgentReport="OnAgentReport",e.OnCallReportInfo="OnCallReportInfo",e.OnCallRing="OnCallRing",e.OnCallEnd="OnCallEnd",e.OnCallAnswer="OnCallAnswer",e.OnAgentGroupQuery="OnAgentGroupQuery",e.OnMethodResponseEvent="OnMethodResponseEvent",e.OnEventPrompt="OnEventPrompt",e.OnPrompt="OnPrompt"}(F||(F={})),function(e){e.TrackParams="trackParams",e.ENV="env",e.LoggerLevel="loggerLevel"}(N||(N={}));var q=[[N.TrackParams,{}],[N.ENV,"test"],[N.LoggerLevel,T.debug]],J=new Map,W=function(){q.forEach((function(e,t){return J.set(e,t)}))};W();var V,G,$,Y,Q=function(e,t,n){void 0===n&&(n=!1),n||"object"!=typeof t?J.set(e,t):J.set(e,f(f({},J.get(e)),t))},X=function(){return window.HS_CTI_CLIENT_ID||(window.HS_CTI_CLIENT_ID="xxxxxxxxxxxx4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})).replace(/-/g,"")),window.HS_CTI_CLIENT_ID};!function(e){e.RingAudio="_ringAudio",e.WaitAudio="_waitAudio",e.ByeAudio="_byeAudio"}(V||(V={})),function(e){e.FeSocket="fe-socket",e.FeSIP="fe-sip",e.FeMethod="fe-method",e.FeAPI="fe-api",e.FeAPIError="fe-api-error",e.FeIMDown="fe-im-down",e.FeIMCmd="fe-im-cmd",e.FeMedia="fe-media",e.FeStatus="fe-status",e.FeEmit="fe-emit"}(G||(G={})),function(e){e.SetSocketStatus="SetSocketStatus",e.SocketDownEvent="SocketDownEvent"}($||($={})),function(e){e.CommonNetworkErrorMsg="对不起,网络状况暂时不佳,请刷新后重试。",e.CustomNetworkErrorMsg="对不起,连接失败,请刷新后重试。如果问题持续出现,请联系我们的技术人员。感谢您的理解和支持。",e.ManualCallAnswerErrorMsg="当前电话未接通,通话已结束,请重试。",e.RobotOrWeChatAnswerErrorMsg="对不起,由于用户挂机等原因,当前电话未接通,请等待下一通电话。",e.SipByeErrorMsg="请稍等,正在挂断。",e.CTIRepeatLoginMsg="当前坐席已被其他终端替代。"}(Y||(Y={}));var z,Z={checkIn:Y.CommonNetworkErrorMsg,checkOut:Y.CommonNetworkErrorMsg,setIdle:Y.CustomNetworkErrorMsg,setBusy:Y.CommonNetworkErrorMsg,makeCall:Y.CommonNetworkErrorMsg,answer:Y.CommonNetworkErrorMsg,bye:Y.CommonNetworkErrorMsg,loadAgentGroupData:Y.CommonNetworkErrorMsg,listen:Y.CommonNetworkErrorMsg,setActiveService:Y.CustomNetworkErrorMsg},K=["agent_id","saas_id","env","scene"],ee=m(m([],K,!0),["monitorScene"],!0),te=function(e){function t(t){var n=e.call(this)||this;return Object.defineProperty(n,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"socket",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"socketOptions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"heartBeatDelay",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"closeHeartBeatDelay",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"heartBeatTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"closeHeartBeatTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"imRetryCount",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"sessionId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),window.addEventListener("onunload",n.closeSocket),n.logger=new B(t.loggerLevel,"HsSocket"),n.socket=void 0,n.heartBeatTimer=null,n.closeHeartBeatTimer=null,n.sessionId="",n.socketOptions=t,n.heartBeatDelay=1e3*t.imHeartTime||3e3,n.closeHeartBeatDelay=1e3*t.imHeartTime||3e3,n.imRetryCount=t.imRetryCount||10,n}return p(t,e),Object.defineProperty(t.prototype,"initSocket",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;this.closeSocket(),this.emit($.SetSocketStatus,{status:C.Connecting}),this.socket=d(this.socketOptions.imWsServer,{transports:["websocket"],reconnectionAttempts:this.imRetryCount,reconnectionDelay:this.heartBeatDelay,reconnectionDelayMax:this.heartBeatDelay+1e3,timeout:this.heartBeatDelay,reconnection:!0}),this.socket.on("error",(function(t){e.logger.error("socket_error | ".concat(JSON.stringify(t)))})),this.socket.on("connect_error",(function(t){var n="socket_connect_error | ".concat(JSON.stringify(t));e.logger.warn(n)})),this.socket.on("reconnecting",(function(t){e.logger.error("socket_warn | socket_reconnecting | ".concat(t)),e.emit($.SetSocketStatus,{status:C.ReTry})})),this.socket.on("reconnect",(function(t){e.logger.error("socket_warn | socket_reconnect | ".concat(t)),e.emit($.SetSocketStatus,{status:C.Ready})})),this.socket.on("reconnect_failed",(function(t){e.logger.error("socket_warn | socket_reconnect_failed | ".concat(t)),e.emit($.SetSocketStatus,{status:C.Terminated,code:H.SocketOnReconnectFailed,error:"".concat(t)})})),this.socket.on("connect",(function(){e.emit($.SetSocketStatus,{status:C.Connected}),e.socketLogin()})),this.socket.on("disconnect",(function(t){var n="socket_disconnect | ".concat(t);e.logger.warn(n)})),this.socket.on("common_down_data",(function(t){console.log(t,3434343434),t&&JSON.parse(t)&&JSON.parse(t).data&&e.emit($.SocketDownEvent,{eventData:JSON.parse(JSON.parse(t).data)})})),this.socket.on("common_down_cmd",(function(t){var n=JSON.parse(t).clientSessionId;console.log("dsdsdsdsdsds",n),n===e.sessionId&&(e.logger.error("socket status | ".concat(C.Terminated," | 坐席在其他页面重新初始化,本页面被踢出")),e.emit($.SetSocketStatus,{status:C.Terminated,code:H.SocketRepeatLogin,error:"您已在其他页面签入,当前页面连接已断开"}))}))}}),Object.defineProperty(t.prototype,"socketLogin",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this,t={userId:this.socketOptions.agent_id};this.socket&&this.socket.emit("login",t,(function(t){console.log(t,"测试一下"),e.emit($.SetSocketStatus,{status:C.Ready}),Q(N.TrackParams,{socket_session_id:t}),e.sessionId=t,e.startHeartbeat()}))}}),Object.defineProperty(t.prototype,"closeSocket",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.socket&&(this.socket.io.opts.reconnection=!1,this.socket.close(),this.socket.removeAllListeners()),this.socket=void 0,this.sessionId="",this.heartBeatTimer&&(window.clearTimeout(this.heartBeatTimer),this.heartBeatTimer=null),this.closeHeartBeatTimer&&(window.clearTimeout(this.closeHeartBeatTimer),this.closeHeartBeatTimer=null)}}),Object.defineProperty(t.prototype,"startHeartbeat",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.heartBeatTimer&&(window.clearTimeout(this.heartBeatTimer),this.heartBeatTimer=null),this.closeHeartBeatTimer&&(window.clearTimeout(this.closeHeartBeatTimer),this.closeHeartBeatTimer=null),this.socket&&this.heartbeatEvent()}}),Object.defineProperty(t.prototype,"heartbeatEvent",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;this.heartBeatTimer=setTimeout((function(){e.socket&&e.sendHeartbeat(),e.closeHeartBeatTimer=setTimeout((function(){e.logger.warn("socket_heart_beat | 心跳超时,即将重新连接"),e.initSocket()}),e.closeHeartBeatDelay)}),this.heartBeatDelay)}}),Object.defineProperty(t.prototype,"sendHeartbeat",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;this.socket&&this.socket.emit("heartbeat",JSON.stringify(f({},this.socketOptions)),(function(){e.startHeartbeat()}))}}),t}(R),ne=new B(window.ctiLoggerLevel||(z=N.LoggerLevel,J.get(z)),"HsApi"),re=function(){return(65536|65536*Math.random()).toString(16).substr(1)};function ie(e){var t=e.baseUrl,n=e.url,r=e.data;return b(this,void 0,void 0,(function(){var e,i;return v(this,(function(o){switch(o.label){case 0:return e=re()+re()+re()+re(),[4,fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json","X-B3-TraceId":e,"X-B3-SpanId":e},body:JSON.stringify(r)})];case 1:return(i=o.sent()).ok||ne.error("api response | ".concat(n," | Request failed with status ").concat(i.status)),[2,i.json()]}}))}))}var oe=function(e){var t=e.baseUrl,n=e.url,r=void 0===n?"":n,i=e.data;return new Promise((function(e,n){return b(void 0,void 0,void 0,(function(){var o,s,a,c;return v(this,(function(l){switch(l.label){case 0:return l.trys.push([0,2,,3]),[4,ie({baseUrl:t,url:r,data:i})];case 1:return o=l.sent(),s=o.code,a=o.msg,console.log(a),0===s?ne.log("api response | ".concat(r," | ").concat(JSON.stringify(o))):ne.error("api response | ".concat(r," | ").concat(JSON.stringify(o))),e(o),[3,3];case 2:return c=l.sent(),ne.error("api response | ".concat(r," | ").concat(JSON.stringify(c))),n(c),[3,3];case 3:return[2]}}))}))}))},se="http://192.168.100.159:8090",ae=function(e){return oe({baseUrl:se,url:"/open/agent/get-init-config",data:e})},ce=function(e){return oe({baseUrl:se,url:"/open/agent/manual-call",data:e})},le=function(e){return oe({baseUrl:se,url:"/open/num/generate",data:e})};function ue(e){return function(t,n,r){var i=r.value;return r.value=function(){for(var t=[],r=0;r=300001&&e<=399999?x.ServerTerminated:x.ServerError}(i),c={type:s,code:i,msg:o,method:t},this.eventEmitAndTrack(F.OnCtiError,c),s===x.ServerTerminated&&this.setCTIStatus(M.Terminated),[2,Promise.reject(c)]):[2,Promise.resolve(n)];case 2:return a=l.sent(),c={type:"fetch_error",code:U.FetchError,msg:JSON.stringify(a),method:t},this.eventEmitAndTrack(F.OnCtiError,c),[2,Promise.reject(c)];case 3:return[2]}}))}))},n}}var ge={_ringAudio:"http://static.fuxicarbon.com/hs-cti/ring.wav",_waitAudio:"http://static.fuxicarbon.com/hs-cti/manual.wav",_byeAudio:"http://static.fuxicarbon.com/hs-cti/bye.wav"},pe=function(e){function t(t){var n=this,r=t.saas_id,i=t.agent_id,o=t.scene,s=t.env,a=t.loggerLevel;n=e.call(this)||this,Object.defineProperty(n,"logger",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"loggerLevel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"scene",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"agent_id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"saas_id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"_initOptions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"_socket",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"_sipUserAgent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"_callId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"_ctiFlowIdList",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"_baseParams",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"_waitAudio",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"_ringAudio",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"_byeAudio",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"_remoteAudio",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"_ctiStatus",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"_ctiStatusList",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"_sipStatus",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"_sipStatusList",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"_socketStatus",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"_socketStatusList",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"_callStatus",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"_terminatedStatusList",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),n.loggerLevel=window.ctiLoggerLevel||a||T.log,n.logger=new B(n.loggerLevel,"HsCTI"),n._waitAudio=new Audio,n._ringAudio=new Audio,n._byeAudio=new Audio,n._remoteAudio=new Audio,n.saas_id=r,n.agent_id=i,n.scene=o,n._callId="",Q(N.ENV,s),Q(N.LoggerLevel,n.loggerLevel),n._baseParams={agent_id:i,saas_id:r,scene:o};var c={agent_id:i,vcc_id:r,scene:o};if(o===I.Monitor){var l=t.monitorScene;n._baseParams=f(f({},n._baseParams),{monitorScene:l}),Q(N.TrackParams,f(f({},c),{monitor_scene:l}),!0)}else Q(N.TrackParams,c,!0);return n.initInstanceOptions(),n.setCTIStatus(M.Initial),n._callStatus=D.Stopped,n._terminatedStatusList=[],n}return p(t,e),Object.defineProperty(t.prototype,"getCTIStatus",{get:function(){return this._ctiStatus},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"getSocketStatus",{get:function(){return this._socketStatus},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"getSIPStatus",{get:function(){return this._sipStatus},enumerable:!1,configurable:!0}),Object.defineProperty(t,"getInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return t.instance||(t.instance=new t(e)),Q(N.TrackParams,{clientId:X()}),t.instance}}),Object.defineProperty(t.prototype,"initInstanceOptions",{enumerable:!1,configurable:!0,writable:!0,value:function(){this._ctiFlowIdList=[],this._ctiStatusList=[],this._sipStatusList=[],this._socketStatusList=[],t.instance=void 0,this._initOptions=void 0,W()}}),Object.defineProperty(t.prototype,"clearSocketAndSip",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e,t,n;null===(e=this._socket)||void 0===e||e.closeSocket(),null===(t=this._sipUserAgent)||void 0===t||t.unregister(),null===(n=this._sipUserAgent)||void 0===n||n.disconnect(),this._sipUserAgent=void 0}}),Object.defineProperty(t.prototype,"setAudioSrc",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){this.logger.debug("media | 设置等待音 src: ".concat(ge[e])),this[e].src=ge[e],this[e].currentTime=0,this[e].autoplay=!1,this[e].loop=t}}),Object.defineProperty(t.prototype,"playAudio",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.logger.debug("media | 播放音频:".concat(e)),this[e].play()}}),Object.defineProperty(t.prototype,"stopLocalAudio",{enumerable:!1,configurable:!0,writable:!0,value:function(){switch(this.scene){case I.Robot:case I.Monitor:this.stopAudio(V.RingAudio,!0);break;case I.Manual:this.stopAudio(V.WaitAudio,!0)}}}),Object.defineProperty(t.prototype,"stopAudio",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this;this.logger.debug("media | 停止音频播放:".concat(e)),this[e].src="",setTimeout((function(){n.setAudioSrc(e,t)}),1e3)}}),Object.defineProperty(t.prototype,"init",{enumerable:!1,configurable:!0,writable:!0,value:function(){if(this._ctiStatusList.slice(-1)[0]===M.Initial){switch(this.setAudioSrc(V.ByeAudio,!1),this.scene){case I.Robot:case I.Monitor:this.setAudioSrc(V.RingAudio,!0);break;case I.Manual:this.setAudioSrc(V.WaitAudio,!0)}this.getInitConfig()}}}),Object.defineProperty(t.prototype,"getInitConfig",{enumerable:!1,configurable:!0,writable:!0,value:function(){return b(this,void 0,void 0,(function(){var e,t,n,r,i;return v(this,(function(o){switch(o.label){case 0:return[4,ae(this._baseParams)];case 1:return e=o.sent(),t=e.code,n=e.data,r=e.msg,i=f(f({},i=n),{imHeartTime:3,imRetryCount:3,fsHeartTime:60,fsRetryCount:3,fsRetryTime:60,fsRegisterExpireTime:84e3,ctiSessionId:"id-"+Date.now()+"-"+Math.floor(1e4*Math.random()),imWsServer:"ws://192.168.100.159:8091/ws/cs-im",imWsPath:"ws/cs-im"}),0===t&&i?(Q(N.TrackParams,{sip_server:i.sipServer,cti_session_id:i.ctiSessionId}),this._initOptions=i,this.initSocket(i),this.initSip(i)):this.eventEmitAndTrack(F.OnCtiError,{type:x.ServerTerminated,code:H.GetInitConfig,msg:0!==t||i?r:"未查到坐席",method:"getInitConfig",res_code:t}),[2]}}))}))}}),Object.defineProperty(t.prototype,"initSocket",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;this.setSocketStatus({status:C.Initial}),this._socket=new te({agent_id:this.agent_id,saas_id:this.saas_id,imWsServer:e.imWsServer,imWsPath:e.imWsPath,imHeartTime:e.imHeartTime,imRetryCount:e.imRetryCount,ctiSessionId:e.ctiSessionId,loggerLevel:this.loggerLevel}),this._socket.on($.SocketDownEvent,(function(e){var n=e.eventData,r=n.eventName,i=n.ext;t.logger.log("socket server down | ".concat(r," | ").concat(JSON.stringify(i))),t.handleSocketDownEvent({eventName:r,ext:i})})),this._socket.on($.SetSocketStatus,(function(e){console.log("set socket statussdsdsdsdsdsdds | ".concat(JSON.stringify(e))),t.setSocketStatus(e)})),this._socket.initSocket()}}),Object.defineProperty(t.prototype,"handleSocketDownEvent",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e.eventName,n=e.ext,r=this._baseParams.ctiFlowId,i=n.ctiFlowId;[I.Manual,I.Monitor].includes(this.scene)&&r&&i&&r!==i?this.logger.error("cti_flow_id | 不一致! fe: ".concat(r,", server: ").concat(i,", eventName: ").concat(t)):this.serverEventEmit({eventName:t,ext:n})}}),Object.defineProperty(t.prototype,"serverEventEmit",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e.eventName,n=e.ext,r=[F.OnRingStart,F.OnDetectedTone,F.OnRingEnd];switch(t){case F.OnRingStart:case F.OnDetectedTone:this.stopLocalAudio();break;case F.OnAgentWorkReport:break;case F.OnCallEnd:this._callStatus=D.Stopped,Q(N.TrackParams,{call_id:""});case F.OnRingEnd:}r.includes(t)||this.eventEmitAndTrack(t,n)}}),Object.defineProperty(t.prototype,"initSip",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;this.setSipStatus({status:E.Initial});var n=e.wss_server,r={aor:e.sip_server,reconnectionAttempts:e.fsRetryCount,reconnectionDelay:e.fsRetryTime,optionsPingInterval:e.fsHeartTime,media:{remote:{audio:this._remoteAudio}},userAgentOptions:{gracefulShutdown:!0,authorizationPassword:e.phone_pwd,sessionDescriptionHandlerFactoryOptions:{constraints:{audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0},video:!1},peerConnectionConfiguration:{iceServers:[{urls:e.ice_server}]}}}};r.delegate=this.sipDelegate(),this._sipUserAgent=new S(n,r),this._sipUserAgent.connect().catch((function(e){var n="SIP UserAgent 启动失败:".concat(JSON.stringify(e));t.logger.error(n),t.setSipStatus({status:E.Terminated,code:H.SIPInitUserAgent,error:n,method:"initSIPJS"})}))}}),Object.defineProperty(t.prototype,"sipDelegate",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;return{onServerConnect:function(){e._sipUserAgent.register()},onServerDisconnect:function(){e.setSipStatus({status:E.Terminated})},onReconnectStart:function(){e.setSipStatus({status:E.ReTry})},onReconnectFailed:function(){e.setSipStatus({status:E.Terminated,code:H.SIPOnDisconnect,error:"超过重连次数,终止重连",method:"onReconnectFailed"}),e.setSipStatus({status:E.Terminated})},onRegistered:function(){e.setSipStatus({status:E.Ready})},onUserAgentStateChange:function(t){switch(t){case i.Started:e.setSipStatus({status:E.Started});break;case i.Stopped:e.setSipStatus({status:E.Terminated,code:e._sipStatusList.includes(E.Started)?H.SIPUserAgentStateStopped:H.SIPInitUserAgent,error:"SIP UserAgentState 状态停止",method:"onUserAgentStateChange"})}},onInvite:function(t){var r=t.request.getHeader("P-LIBRA-CallId")||"";console.log(r,2888888888),e._callId=r,console.log(r,1888888888),Q(N.TrackParams,{call_id:r}),e.sessionStateChangeAndTrack(t.state),[I.Robot,I.Monitor].includes(e.scene)&&(e.playAudio(V.RingAudio),console.log("playAudio",1888888888)),[I.Manual].includes(e.scene)&&(e.answer(),console.log("answer",1888888888)),t.delegate={onCancel:function(t){var n="sip_invitation_on_cancel | ".concat(JSON.stringify(t));e.logger.error(n),e.eventEmitAndTrack(F.OnCtiError,{type:x.SdkError,code:U.InvitationCancel,msg:"当前通话已结束",method:"sipDelegate"},n)}},t.stateChange.addListener((function(t){switch(e.sessionStateChangeAndTrack(t),t){case n.Initial:case n.Establishing:break;case n.Established:[I.Robot,I.Monitor].includes(e.scene)&&e.stopLocalAudio();break;case n.Terminating:break;case n.Terminated:e.playAudio(V.ByeAudio),setTimeout((function(){e.stopAudio(V.ByeAudio,!1)}),1e3),e.stopLocalAudio(),e._callStatus=D.Stopped,Q(N.TrackParams,{call_id:""})}}))}}}}),Object.defineProperty(t.prototype,"sessionStateChangeAndTrack",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.eventEmitAndTrack(F.OnSessionStatusChange,{status:e});var t="sip_session_state_".concat(e.replace(/\s/g,"").replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,"").replace(/_$/,""));this.logger.log(t)}}),Object.defineProperty(t.prototype,"setCTIStatus",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(e!==this.getCTIStatus){this._ctiStatus=e,this._ctiStatusList.push(e);var t="cti status | ".concat(e," | ").concat(this._ctiStatusList);e===M.Terminated?(this.setSocketStatus({status:C.Terminated}),this.setSipStatus({status:E.Terminated}),this.stopLocalAudio(),this.logger.warn(t)):this.logger.debug(t),e===M.Ready&&(this.setSocketStatus({status:C.Ready}),this.setSipStatus({status:E.Ready}),this._terminatedStatusList=[],this._ctiStatusList.includes(M.ReTry)||this.checkIn())}}}),Object.defineProperty(t.prototype,"setSocketStatus",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e.status,n=e.code,r=e.error;if(t!==this.getSocketStatus){this._socketStatus=t,this._socketStatusList.push(t);var i="socket status | ".concat(t," | ").concat(this._socketStatusList);t===C.Terminated?this.logger.warn(i):this.logger.debug(i),this.socketOrSipStatusChange(t,this.getSIPStatus),r&&(this._terminatedStatusList.push(n),this.eventEmitAndTrack(F.OnCtiError,{type:x.SdkTerminated,code:n,msg:n===H.SocketRepeatLogin?Y.CTIRepeatLoginMsg:Y.CommonNetworkErrorMsg,method:"setSocketStatus"},{error_msg:r,socket_status_list:this._socketStatusList,sip_status_list:this._sipStatusList,cti_status_list:this._ctiStatusList}),this.clearSocketAndSip())}}}),Object.defineProperty(t.prototype,"setSipStatus",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e.status,n=e.code,r=e.error,i=e.method;if(t!==this.getSIPStatus){this._sipStatus=t,this._sipStatusList.push(t);var o="sip status | ".concat(t," | ").concat(this._sipStatusList);t===E.Terminated?this.logger.warn(o):this.logger.debug(o),this.socketOrSipStatusChange(this.getSocketStatus,t),r&&(this._terminatedStatusList.push(n),this.eventEmitAndTrack(F.OnCtiError,{type:x.SdkTerminated,code:n,msg:Y.CommonNetworkErrorMsg,method:i||"setSipStatus"},{error_msg:r,socket_status_list:this._socketStatusList,sip_status_list:this._sipStatusList,cti_status_list:this._ctiStatusList}),this.clearSocketAndSip())}}}),Object.defineProperty(t.prototype,"socketOrSipStatusChange",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){e===C.Ready&&t===E.Ready&&this.setCTIStatus(M.Ready),e!==C.ReTry&&t!==E.ReTry||this.setCTIStatus(M.ReTry),e!==C.Terminated&&t!==E.Terminated||this.setCTIStatus(M.Terminated)}}),Object.defineProperty(t.prototype,"eventEmitAndTrack",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n){this.logger.debug("sdk emit | ".concat(e," | ").concat(JSON.stringify(t))),e===F.OnCtiError&&(this._callStatus=D.Stopped);try{this.emit(e,t),console.log(n)}catch(n){this.logger.error("业务监听 ".concat(e," 事件,处理回调时报错: ").concat(n))}}}),Object.defineProperty(t.prototype,"checkIn",{enumerable:!1,configurable:!0,writable:!0,value:function(){return b(this,void 0,void 0,(function(){var e;return v(this,(function(t){switch(t.label){case 0:return[4,(n=this._baseParams,oe({baseUrl:se,url:"/open/agent/check-in",data:n}))];case 1:return 0===(e=t.sent()).code&&this.eventEmitAndTrack(F.OnInitalSuccess,{saas_id:this.saas_id,agent_id:this.agent_id,scene:this.scene,phoneNum:this._initOptions.phone_num,sipServer:this._initOptions.sip_server}),[2,e]}var n}))}))}}),Object.defineProperty(t.prototype,"checkOut",{enumerable:!1,configurable:!0,writable:!0,value:function(){return b(this,void 0,void 0,(function(){return v(this,(function(e){switch(e.label){case 0:return[4,(t=this._baseParams,oe({baseUrl:se,url:"/open/agent/check-out",data:t}))];case 1:return[2,e.sent()]}var t}))}))}}),Object.defineProperty(t.prototype,"getCtiFlowId",{enumerable:!1,configurable:!0,writable:!0,value:function(){return b(this,void 0,void 0,(function(){var e,t,n;return v(this,(function(r){switch(r.label){case 0:return[4,le(this._baseParams)];case 1:return e=r.sent(),t=e.code,n=e.data,0===t&&(this._baseParams.ctiFlowId=n,this._ctiFlowIdList.push(n),Q(N.TrackParams,{cti_flow_id:n,cti_flow_id_list:JSON.stringify(this._ctiFlowIdList)})),[2,e]}}))}))}}),Object.defineProperty(t.prototype,"setIdle",{enumerable:!1,configurable:!0,writable:!0,value:function(){return b(this,void 0,void 0,(function(){return v(this,(function(e){switch(e.label){case 0:return[4,(t=this._baseParams,oe({baseUrl:se,url:"/open/agent/idle",data:t}))];case 1:return[2,e.sent()]}var t}))}))}}),Object.defineProperty(t.prototype,"setBusy",{enumerable:!1,configurable:!0,writable:!0,value:function(){return b(this,void 0,void 0,(function(){return v(this,(function(e){switch(e.label){case 0:return[4,(t=this._baseParams,oe({baseUrl:se,url:"/open/agent/busy",data:t}))];case 1:return[2,e.sent()]}var t}))}))}}),Object.defineProperty(t.prototype,"makeCall",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return b(this,void 0,void 0,(function(){return v(this,(function(t){switch(t.label){case 0:return this._callStatus===D.Started?[2]:(this._callStatus=D.Started,[4,this.getCtiFlowId()]);case 1:return t.sent(),this.playAudio(V.WaitAudio),[4,this.serverCall(e)];case 2:return[2,t.sent()]}}))}))}}),Object.defineProperty(t.prototype,"serverCall",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e.called,n=e.caller,r=e.ext;return b(this,void 0,void 0,(function(){var e,i,o,s;return v(this,(function(a){switch(a.label){case 0:return e=f(f(f({},this._baseParams),{called:t,caller:n}),r),[4,ce(e)];case 1:return i=a.sent(),o=i.code,s=i.data,0===o?""===this._callId&&s&&(this._callId=s,Q(N.TrackParams,{call_id:s})):(this._callStatus=D.Stopped,this.stopLocalAudio()),[2,i]}}))}))}}),Object.defineProperty(t.prototype,"answer",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;return new Promise((function(t,n){var r;null===(r=e._sipUserAgent)||void 0===r||r.answer({sessionDescriptionHandlerOptions:{constraints:{audio:!0,video:!1}}}).then((function(){t({code:0,data:"answer",msg:"SIP 接起电话成功"}),e.logger.debug("sip_accept_success")})).catch((function(t){var r={type:x.SdkError,code:U.Answer,msg:e.scene===I.Manual?Y.ManualCallAnswerErrorMsg:Y.RobotOrWeChatAnswerErrorMsg,method:"answer"};n(r),e.eventEmitAndTrack(F.OnCtiError,r,"".concat(t)),e.logger.error("".concat(F.OnCtiError," | ").concat(t))}))}))}}),Object.defineProperty(t.prototype,"bye",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;return new Promise((function(t,n){var r;null===(r=e._sipUserAgent)||void 0===r||r.hangup().then((function(){t({code:0,data:"bye",msg:"SIP 挂断电话成功"}),e.logger.debug("sip_bye_success")})).catch((function(t){var r={type:x.SdkError,code:U.Bye,msg:Y.SipByeErrorMsg,method:"bye"};n(r),"Session does not exist."!==t.message&&e.eventEmitAndTrack(F.OnCtiError,r,"".concat(t)),e.logger.error("".concat(F.OnCtiError," | ").concat(t))}))}))}}),Object.defineProperty(t.prototype,"serverBye",{enumerable:!1,configurable:!0,writable:!0,value:function(){return b(this,void 0,void 0,(function(){var e,t;return v(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),this.bye(),this._baseParams.ctiFlowId||this.scene!==I.Manual?[4,this.turnHang()]:[2];case 1:return e=n.sent(),[2,Promise.resolve(e)];case 2:return t=n.sent(),[2,Promise.reject(t)];case 3:return[2]}}))}))}}),Object.defineProperty(t.prototype,"turnHang",{enumerable:!1,configurable:!0,writable:!0,value:function(){return b(this,void 0,void 0,(function(){var e;return v(this,(function(t){switch(t.label){case 0:return[4,(n=f(f({},this._baseParams),{callId:this._callId}),oe({baseUrl:se,url:"/open/agent/manual-hang",data:n}))];case 1:return e=t.sent(),this._callId="",[2,e]}var n}))}))}}),Object.defineProperty(t.prototype,"getAgentStatus",{enumerable:!1,configurable:!0,writable:!0,value:function(){return b(this,void 0,void 0,(function(){return v(this,(function(e){switch(e.label){case 0:return[4,(t=this._baseParams,oe({baseUrl:se,url:"/open/agent/agent-state",data:t}))];case 1:return[2,e.sent()]}var t}))}))}}),Object.defineProperty(t.prototype,"loadAgentGroupData",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return b(this,void 0,void 0,(function(){return v(this,(function(t){switch(t.label){case 0:return[4,(n=f(f({},this._baseParams),{monitorIds:e}),oe({baseUrl:se,url:"/open/monitor/load-agent-group-data",data:n}))];case 1:return[2,t.sent()]}var n}))}))}}),Object.defineProperty(t.prototype,"listen",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return b(this,void 0,void 0,(function(){var t;return v(this,(function(n){switch(n.label){case 0:return[4,this.getCtiFlowId()];case 1:return(t=n.sent())&&0!==t.code?[2,t]:[4,(r=f(f({},this._baseParams),{agent_id:e,leaderAgentId:this.agent_id}),oe({baseUrl:se,url:"/open/agent/listen",data:r}))];case 2:return[2,n.sent()]}var r}))}))}}),Object.defineProperty(t.prototype,"setActiveService",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return b(this,void 0,void 0,(function(){return v(this,(function(t){switch(t.label){case 0:return[4,(n=f(f({},this._baseParams),{serviceId:e}),oe({baseUrl:se,url:"/open/human-service/member-active",data:n}))];case 1:return[2,t.sent()]}var n}))}))}}),Object.defineProperty(t.prototype,"unInit",{enumerable:!1,configurable:!0,writable:!0,value:function(){return b(this,void 0,void 0,(function(){return v(this,(function(e){switch(e.label){case 0:return[4,this.checkOut()];case 1:return e.sent(),this.setCTIStatus(M.Terminated),this.initInstanceOptions(),this.clearSocketAndSip(),this._callId="",[2]}}))}))}}),h([function(e,t,n){var r=n.value;return n.value=function(){for(var e=this,t=[],n=0;n