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