7c3b34e8d520b635abbfa108aac04d14d01e553f
[motion2.git] / server / services / agi / server.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x0aaf=['events','EventEmitter','./error','./channel','call','emit','E_AGI_ARGUMENT_PORT','createServer','listening','connection','getConnections','error','E_AGI_SERVER_ERROR','destroy','ready','code','close','nextTick','inherits'];(function(_0x202ba7,_0x5e0533){var _0x237086=function(_0x5ab13a){while(--_0x5ab13a){_0x202ba7['push'](_0x202ba7['shift']());}};_0x237086(++_0x5e0533);}(_0x0aaf,0x1c8));var _0xf0aa=function(_0xe7d07d,_0x52e4e3){_0xe7d07d=_0xe7d07d-0x0;var _0x229e46=_0x0aaf[_0xe7d07d];return _0x229e46;};'use strict';var util=require('util');var net=require('net');var EventEmitter=require(_0xf0aa('0x0'))[_0xf0aa('0x1')];var AGIError=require(_0xf0aa('0x2'));var AGIChannel=require(_0xf0aa('0x3'));var AGIServer=function(_0x5e7bdc,_0x507aaa,_0x3943ce){var _0x2f72d3=this,_0x5e7bdc=_0x5e7bdc||0x11dd,_0x507aaa=_0x507aaa||'127.0.0.1',_0x4c20b5=null,_0x752f1b=0x0;EventEmitter[_0xf0aa('0x4')](_0x2f72d3);function _0x244745(){if(!_0x5e7bdc){_0x2f72d3[_0xf0aa('0x5')]('error',new AGIError(_0xf0aa('0x6')));return![];}_0x4c20b5=net[_0xf0aa('0x7')]();_0x4c20b5['listen'](_0x5e7bdc,_0x507aaa);_0x4c20b5['on'](_0xf0aa('0x8'),function(){_0x2f72d3[_0xf0aa('0x5')](_0xf0aa('0x8'));});_0x4c20b5['on'](_0xf0aa('0x9'),function(_0x60a2c5){_0x4c20b5[_0xf0aa('0xa')](function(_0x34b218,_0x106b57){if(_0x34b218){_0x2f72d3[_0xf0aa('0x5')](_0xf0aa('0xb'),new AGIError(_0xf0aa('0xc'),_0x34b218));}else if(_0x3943ce&&_0x3943ce<0x0){_0x2f72d3[_0xf0aa('0x5')]('error',new AGIError('E_AGI_SERVER_VOICE_DISABLED'));_0x60a2c5[_0xf0aa('0xd')]();}else if(_0x3943ce&&_0x3943ce>0x0&&_0x3943ce<_0x106b57){_0x752f1b+=0x1;_0x2f72d3[_0xf0aa('0x5')]('error',new AGIError('E_AGI_SERVER_MAXCONNECTION',_0x752f1b));_0x60a2c5[_0xf0aa('0xd')]();}else{var _0x51bb2c=new AGIChannel(_0x60a2c5);_0x51bb2c['on'](_0xf0aa('0xe'),function(){_0x2f72d3['emit'](_0xf0aa('0x9'),_0x51bb2c);});}});});_0x4c20b5['on']('error',function(_0x3fb1fe){_0x2f72d3[_0xf0aa('0x5')](_0xf0aa('0xb'),new AGIError(_0xf0aa('0xc'),_0x3fb1fe[_0xf0aa('0xf')]));});_0x4c20b5['on'](_0xf0aa('0x10'),function(){_0x2f72d3[_0xf0aa('0x5')](_0xf0aa('0x10'),new AGIError('E_AGI_SERVER_CLOSE'));});}process[_0xf0aa('0x11')](function(){_0x244745();});};util[_0xf0aa('0x12')](AGIServer,EventEmitter);module['exports']=function(_0x31e85f,_0x16d578,_0x35f407){return new AGIServer(_0x31e85f,_0x16d578,_0x35f407);};