bf88b907cbb7077ec9a58ba11492e494e6cabfa1
[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 _0xfe60=['nextTick','inherits','exports','net','EventEmitter','./error','./channel','127.0.0.1','call','error','listening','connection','getConnections','emit','E_AGI_SERVER_ERROR','ready','code','close','E_AGI_SERVER_CLOSE'];(function(_0xe65499,_0x2e7f76){var _0x3b89b0=function(_0x470e84){while(--_0x470e84){_0xe65499['push'](_0xe65499['shift']());}};_0x3b89b0(++_0x2e7f76);}(_0xfe60,0x1cb));var _0x0fe6=function(_0x4cd34b,_0x2d8e36){_0x4cd34b=_0x4cd34b-0x0;var _0x22f1d2=_0xfe60[_0x4cd34b];return _0x22f1d2;};'use strict';var util=require('util');var net=require(_0x0fe6('0x0'));var EventEmitter=require('events')[_0x0fe6('0x1')];var AGIError=require(_0x0fe6('0x2'));var AGIChannel=require(_0x0fe6('0x3'));var AGIServer=function(_0x4aa401,_0x40740,_0x244c56){var _0x402912=this,_0x4aa401=_0x4aa401||0x11dd,_0x40740=_0x40740||_0x0fe6('0x4'),_0x1281fc=null,_0x13b947=0x0;EventEmitter[_0x0fe6('0x5')](_0x402912);function _0x24e88f(){if(!_0x4aa401){_0x402912['emit'](_0x0fe6('0x6'),new AGIError('E_AGI_ARGUMENT_PORT'));return![];}_0x1281fc=net['createServer']();_0x1281fc['listen'](_0x4aa401,_0x40740);_0x1281fc['on'](_0x0fe6('0x7'),function(){_0x402912['emit'](_0x0fe6('0x7'));});_0x1281fc['on'](_0x0fe6('0x8'),function(_0x1a14f3){_0x1281fc[_0x0fe6('0x9')](function(_0x299994,_0x2498a0){if(_0x299994){_0x402912[_0x0fe6('0xa')]('error',new AGIError(_0x0fe6('0xb'),_0x299994));}else if(_0x244c56&&_0x244c56<0x0){_0x402912[_0x0fe6('0xa')](_0x0fe6('0x6'),new AGIError('E_AGI_SERVER_VOICE_DISABLED'));_0x1a14f3['destroy']();}else if(_0x244c56&&_0x244c56>0x0&&_0x244c56<_0x2498a0){_0x13b947+=0x1;_0x402912[_0x0fe6('0xa')]('error',new AGIError('E_AGI_SERVER_MAXCONNECTION',_0x13b947));_0x1a14f3['destroy']();}else{var _0x225253=new AGIChannel(_0x1a14f3);_0x225253['on'](_0x0fe6('0xc'),function(){_0x402912[_0x0fe6('0xa')](_0x0fe6('0x8'),_0x225253);});}});});_0x1281fc['on'](_0x0fe6('0x6'),function(_0x16f2f6){_0x402912[_0x0fe6('0xa')](_0x0fe6('0x6'),new AGIError(_0x0fe6('0xb'),_0x16f2f6[_0x0fe6('0xd')]));});_0x1281fc['on'](_0x0fe6('0xe'),function(){_0x402912[_0x0fe6('0xa')]('close',new AGIError(_0x0fe6('0xf')));});}process[_0x0fe6('0x10')](function(){_0x24e88f();});};util[_0x0fe6('0x11')](AGIServer,EventEmitter);module[_0x0fe6('0x12')]=function(_0x38bdeb,_0x3738bd,_0xf351d5){return new AGIServer(_0x38bdeb,_0x3738bd,_0xf351d5);};