5d8afa44acab5ae7642b0047a1bae5e2c3489fda
[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 _0xa8ce=['shutdown','Shutdown\x20\x22%s\x22\x20to\x20%s:%s\x20with:\x0a%s','fullybooted','resolve','then','catch','[ami.js][fullybooted]','asterisk-manager','bluebird','util','../../config/logger','ami','port','asterisk','username','password','Action','promisify','action','error','format','Manager\x20\x22%s\x22\x20error\x20to\x20%s:%s\x20with:\x0a%s','inspect','Manager\x20\x22%s\x22\x20closed\x20to\x20%s:%s','actionSipShowRegistry','sipshowregistry','actionDeviceStateList','actionSipPeerStatus','actionQueueSummary','queuesummary','actionCoreShowChannels','coreshowchannels','Manager\x20\x22%s\x22\x20logged\x20on\x20to\x20%s:%s','once','close','connect'];(function(_0x13d07a,_0x41efc3){var _0x5ee0ee=function(_0x4ca94a){while(--_0x4ca94a){_0x13d07a['push'](_0x13d07a['shift']());}};_0x5ee0ee(++_0x41efc3);}(_0xa8ce,0x16f));var _0xea8c=function(_0x55f601,_0x50d0bc){_0x55f601=_0x55f601-0x0;var _0x3ecd7d=_0xa8ce[_0x55f601];return _0x3ecd7d;};'use strict';var Manager=require(_0xea8c('0x0'));var BPromise=require(_0xea8c('0x1'));var util=require(_0xea8c('0x2'));var logger=require(_0xea8c('0x3'))(_0xea8c('0x4'));var config=require('../../config/environment');var ami=new Manager(config['asterisk'][_0xea8c('0x5')],config[_0xea8c('0x6')]['ip'],config[_0xea8c('0x6')][_0xea8c('0x7')],config['asterisk'][_0xea8c('0x8')],!![]);ami['keepConnected']();ami[_0xea8c('0x9')]=BPromise[_0xea8c('0xa')](ami[_0xea8c('0xb')]);function error(_0x13b659){logger[_0xea8c('0xc')](util[_0xea8c('0xd')](_0xea8c('0xe'),config['asterisk']['username'],config[_0xea8c('0x6')]['ip'],config[_0xea8c('0x6')]['port'],util[_0xea8c('0xf')](_0x13b659,![],null)));}function close(){logger[_0xea8c('0xc')](util['format'](_0xea8c('0x10'),config[_0xea8c('0x6')][_0xea8c('0x7')],config[_0xea8c('0x6')]['ip'],config[_0xea8c('0x6')][_0xea8c('0x5')]));}ami[_0xea8c('0x11')]=function(){return function(){return ami[_0xea8c('0x9')]({'action':_0xea8c('0x12')});};};ami[_0xea8c('0x13')]=function(){return function(){return ami['Action']({'action':'devicestatelist'});};};ami[_0xea8c('0x14')]=function(){return function(){return ami[_0xea8c('0x9')]({'action':'sippeerstatus'});};};ami[_0xea8c('0x15')]=function(){return function(){return ami[_0xea8c('0x9')]({'action':_0xea8c('0x16')});};};ami[_0xea8c('0x17')]=function(){return function(){return ami['Action']({'action':_0xea8c('0x18')});};};function connect(){logger['info'](util['format'](_0xea8c('0x19'),config['asterisk']['username'],config[_0xea8c('0x6')]['ip'],config[_0xea8c('0x6')]['port']));ami[_0xea8c('0x1a')](_0xea8c('0xc'),error);ami[_0xea8c('0x1a')](_0xea8c('0x1b'),close);}ami['on'](_0xea8c('0x1c'),connect);ami['on'](_0xea8c('0x1d'),function(_0x16d549){logger['info'](util[_0xea8c('0xd')](_0xea8c('0x1e'),config[_0xea8c('0x6')][_0xea8c('0x7')],config['asterisk']['ip'],config[_0xea8c('0x6')][_0xea8c('0x5')],util[_0xea8c('0xf')](_0x16d549,![],null)));});ami['on'](_0xea8c('0x1f'),function(){logger['info'](util[_0xea8c('0xd')]('Fullybooted\x20\x22%s\x22\x20to\x20%s:%s',config[_0xea8c('0x6')][_0xea8c('0x7')],config['asterisk']['ip'],config[_0xea8c('0x6')][_0xea8c('0x5')]));return Promise[_0xea8c('0x20')]()[_0xea8c('0x21')](ami[_0xea8c('0x11')]())['then'](ami[_0xea8c('0x13')]())[_0xea8c('0x21')](ami[_0xea8c('0x14')]())['then'](ami[_0xea8c('0x15')]())['then'](ami[_0xea8c('0x17')]())[_0xea8c('0x22')](function(_0x22ebdb){logger[_0xea8c('0xc')](_0xea8c('0x23'),util[_0xea8c('0xf')](_0x22ebdb,{'showHidden':![],'depth':null}));});});ami[_0xea8c('0x1a')](_0xea8c('0xc'),error);ami[_0xea8c('0x1a')](_0xea8c('0x1b'),close);module['exports']=ami;