b90a2f46f0e3c7faab944d0842af076b3761ce2e
[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 _0xa3e9=['exports','net','events','EventEmitter','./channel','127.0.0.1','call','emit','error','E_AGI_ARGUMENT_PORT','listening','getConnections','destroy','E_AGI_SERVER_MAXCONNECTION','connection','E_AGI_SERVER_ERROR','close','nextTick','inherits'];(function(_0xb49d84,_0x40e45c){var _0x4a5a56=function(_0x4093b7){while(--_0x4093b7){_0xb49d84['push'](_0xb49d84['shift']());}};_0x4a5a56(++_0x40e45c);}(_0xa3e9,0x11e));var _0x9a3e=function(_0x21cbaa,_0x1407f2){_0x21cbaa=_0x21cbaa-0x0;var _0x4807bc=_0xa3e9[_0x21cbaa];return _0x4807bc;};'use strict';var util=require('util');var net=require(_0x9a3e('0x0'));var EventEmitter=require(_0x9a3e('0x1'))[_0x9a3e('0x2')];var AGIError=require('./error');var AGIChannel=require(_0x9a3e('0x3'));var AGIServer=function(_0x3c4e1c,_0x1b55b9,_0x47888b){var _0xda639a=this,_0x3c4e1c=_0x3c4e1c||0x11dd,_0x1b55b9=_0x1b55b9||_0x9a3e('0x4'),_0x592c82=null,_0x342283=0x0;EventEmitter[_0x9a3e('0x5')](_0xda639a);function _0xdfc412(){if(!_0x3c4e1c){_0xda639a[_0x9a3e('0x6')](_0x9a3e('0x7'),new AGIError(_0x9a3e('0x8')));return![];}_0x592c82=net['createServer']();_0x592c82['listen'](_0x3c4e1c,_0x1b55b9);_0x592c82['on'](_0x9a3e('0x9'),function(){_0xda639a['emit']('listening');});_0x592c82['on']('connection',function(_0x5176e8){_0x592c82[_0x9a3e('0xa')](function(_0x2d8db6,_0x5f02c3){if(_0x2d8db6){_0xda639a[_0x9a3e('0x6')](_0x9a3e('0x7'),new AGIError('E_AGI_SERVER_ERROR',_0x2d8db6));}else if(_0x47888b&&_0x47888b<0x0){_0xda639a[_0x9a3e('0x6')](_0x9a3e('0x7'),new AGIError('E_AGI_SERVER_VOICE_DISABLED'));_0x5176e8[_0x9a3e('0xb')]();}else if(_0x47888b&&_0x47888b>0x0&&_0x47888b<_0x5f02c3){_0x342283+=0x1;_0xda639a[_0x9a3e('0x6')]('error',new AGIError(_0x9a3e('0xc'),_0x342283));_0x5176e8[_0x9a3e('0xb')]();}else{var _0xeb54a5=new AGIChannel(_0x5176e8);_0xeb54a5['on']('ready',function(){_0xda639a[_0x9a3e('0x6')](_0x9a3e('0xd'),_0xeb54a5);});}});});_0x592c82['on'](_0x9a3e('0x7'),function(_0xfddd74){_0xda639a['emit']('error',new AGIError(_0x9a3e('0xe'),_0xfddd74['code']));});_0x592c82['on'](_0x9a3e('0xf'),function(){_0xda639a[_0x9a3e('0x6')](_0x9a3e('0xf'),new AGIError('E_AGI_SERVER_CLOSE'));});}process[_0x9a3e('0x10')](function(){_0xdfc412();});};util[_0x9a3e('0x11')](AGIServer,EventEmitter);module[_0x9a3e('0x12')]=function(_0x12081e,_0x47450,_0x1572cc){return new AGIServer(_0x12081e,_0x47450,_0x1572cc);};