e185f3cc1a4c9a8ecedbe038cfce38921f4ae07d
[motion2.git] / server / services / ami / ami.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 _0xfc2f=['actionSipShowRegistry','actionDeviceStateList','devicestatelist','actionSipPeerStatus','queuesummary','actionCoreShowChannels','coreshowchannels','info','Manager\x20\x22%s\x22\x20logged\x20on\x20to\x20%s:%s','once','shutdown','Shutdown\x20\x22%s\x22\x20to\x20%s:%s\x20with:\x0a%s','fullybooted','Fullybooted\x20\x22%s\x22\x20to\x20%s:%s','then','actionQueueSummary','catch','[ami.js][fullybooted]','close','bluebird','util','../../config/logger','ami','../../config/environment','asterisk','username','keepConnected','Action','action','error','format','port','inspect'];(function(_0xade2e7,_0x373f3f){var _0x5778aa=function(_0x56234){while(--_0x56234){_0xade2e7['push'](_0xade2e7['shift']());}};_0x5778aa(++_0x373f3f);}(_0xfc2f,0x1c0));var _0xffc2=function(_0x15924d,_0x792b1a){_0x15924d=_0x15924d-0x0;var _0x213f0c=_0xfc2f[_0x15924d];return _0x213f0c;};'use strict';var Manager=require('asterisk-manager');var BPromise=require(_0xffc2('0x0'));var util=require(_0xffc2('0x1'));var logger=require(_0xffc2('0x2'))(_0xffc2('0x3'));var config=require(_0xffc2('0x4'));var ami=new Manager(config['asterisk']['port'],config[_0xffc2('0x5')]['ip'],config[_0xffc2('0x5')][_0xffc2('0x6')],config[_0xffc2('0x5')]['password'],!![]);ami[_0xffc2('0x7')]();ami[_0xffc2('0x8')]=BPromise['promisify'](ami[_0xffc2('0x9')]);function error(_0x2ae3b7){logger[_0xffc2('0xa')](util[_0xffc2('0xb')]('Manager\x20\x22%s\x22\x20error\x20to\x20%s:%s\x20with:\x0a%s',config['asterisk'][_0xffc2('0x6')],config[_0xffc2('0x5')]['ip'],config[_0xffc2('0x5')][_0xffc2('0xc')],util[_0xffc2('0xd')](_0x2ae3b7,![],null)));}function close(){logger['error'](util['format']('Manager\x20\x22%s\x22\x20closed\x20to\x20%s:%s',config[_0xffc2('0x5')]['username'],config[_0xffc2('0x5')]['ip'],config[_0xffc2('0x5')]['port']));}ami[_0xffc2('0xe')]=function(){return function(){return ami[_0xffc2('0x8')]({'action':'sipshowregistry'});};};ami[_0xffc2('0xf')]=function(){return function(){return ami[_0xffc2('0x8')]({'action':_0xffc2('0x10')});};};ami[_0xffc2('0x11')]=function(){return function(){return ami[_0xffc2('0x8')]({'action':'sippeerstatus'});};};ami['actionQueueSummary']=function(){return function(){return ami[_0xffc2('0x8')]({'action':_0xffc2('0x12')});};};ami[_0xffc2('0x13')]=function(){return function(){return ami[_0xffc2('0x8')]({'action':_0xffc2('0x14')});};};function connect(){logger[_0xffc2('0x15')](util[_0xffc2('0xb')](_0xffc2('0x16'),config['asterisk']['username'],config[_0xffc2('0x5')]['ip'],config[_0xffc2('0x5')]['port']));ami['once'](_0xffc2('0xa'),error);ami[_0xffc2('0x17')]('close',close);}ami['on']('connect',connect);ami['on'](_0xffc2('0x18'),function(_0x443cd8){logger['info'](util[_0xffc2('0xb')](_0xffc2('0x19'),config[_0xffc2('0x5')][_0xffc2('0x6')],config['asterisk']['ip'],config[_0xffc2('0x5')][_0xffc2('0xc')],util[_0xffc2('0xd')](_0x443cd8,![],null)));});ami['on'](_0xffc2('0x1a'),function(){logger[_0xffc2('0x15')](util[_0xffc2('0xb')](_0xffc2('0x1b'),config['asterisk'][_0xffc2('0x6')],config[_0xffc2('0x5')]['ip'],config[_0xffc2('0x5')][_0xffc2('0xc')]));return Promise['resolve']()[_0xffc2('0x1c')](ami[_0xffc2('0xe')]())[_0xffc2('0x1c')](ami[_0xffc2('0xf')]())['then'](ami[_0xffc2('0x11')]())['then'](ami[_0xffc2('0x1d')]())['then'](ami[_0xffc2('0x13')]())[_0xffc2('0x1e')](function(_0x51c33e){logger[_0xffc2('0xa')](_0xffc2('0x1f'),util[_0xffc2('0xd')](_0x51c33e,{'showHidden':![],'depth':null}));});});ami[_0xffc2('0x17')](_0xffc2('0xa'),error);ami['once'](_0xffc2('0x20'),close);module['exports']=ami;