17b5074fcb726607dbed681dab73e7ffcf19ec14
[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 _0x7e73=['close','connect','shutdown','fullybooted','Fullybooted\x20\x22%s\x22\x20to\x20%s:%s','resolve','then','catch','[ami.js][fullybooted]','exports','asterisk-manager','util','ami','../../config/environment','port','asterisk','username','password','keepConnected','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','actionDeviceStateList','actionSipPeerStatus','actionQueueSummary','queuesummary','actionCoreShowChannels','coreshowchannels','info','once'];(function(_0x54ab02,_0x362f8e){var _0x1d5f24=function(_0x216b4f){while(--_0x216b4f){_0x54ab02['push'](_0x54ab02['shift']());}};_0x1d5f24(++_0x362f8e);}(_0x7e73,0x1a2));var _0x37e7=function(_0x30a89a,_0x5d4e8f){_0x30a89a=_0x30a89a-0x0;var _0x995bc9=_0x7e73[_0x30a89a];return _0x995bc9;};'use strict';var Manager=require(_0x37e7('0x0'));var BPromise=require('bluebird');var util=require(_0x37e7('0x1'));var logger=require('../../config/logger')(_0x37e7('0x2'));var config=require(_0x37e7('0x3'));var ami=new Manager(config['asterisk'][_0x37e7('0x4')],config[_0x37e7('0x5')]['ip'],config[_0x37e7('0x5')][_0x37e7('0x6')],config[_0x37e7('0x5')][_0x37e7('0x7')],!![]);ami[_0x37e7('0x8')]();ami[_0x37e7('0x9')]=BPromise['promisify'](ami['action']);function error(_0x3c25dc){logger[_0x37e7('0xa')](util[_0x37e7('0xb')](_0x37e7('0xc'),config['asterisk']['username'],config[_0x37e7('0x5')]['ip'],config[_0x37e7('0x5')][_0x37e7('0x4')],util[_0x37e7('0xd')](_0x3c25dc,![],null)));}function close(){logger[_0x37e7('0xa')](util[_0x37e7('0xb')](_0x37e7('0xe'),config['asterisk'][_0x37e7('0x6')],config[_0x37e7('0x5')]['ip'],config[_0x37e7('0x5')][_0x37e7('0x4')]));}ami[_0x37e7('0xf')]=function(){return function(){return ami[_0x37e7('0x9')]({'action':'sipshowregistry'});};};ami[_0x37e7('0x10')]=function(){return function(){return ami['Action']({'action':'devicestatelist'});};};ami[_0x37e7('0x11')]=function(){return function(){return ami[_0x37e7('0x9')]({'action':'sippeerstatus'});};};ami[_0x37e7('0x12')]=function(){return function(){return ami[_0x37e7('0x9')]({'action':_0x37e7('0x13')});};};ami[_0x37e7('0x14')]=function(){return function(){return ami[_0x37e7('0x9')]({'action':_0x37e7('0x15')});};};function connect(){logger[_0x37e7('0x16')](util[_0x37e7('0xb')]('Manager\x20\x22%s\x22\x20logged\x20on\x20to\x20%s:%s',config[_0x37e7('0x5')][_0x37e7('0x6')],config[_0x37e7('0x5')]['ip'],config['asterisk'][_0x37e7('0x4')]));ami['once'](_0x37e7('0xa'),error);ami[_0x37e7('0x17')](_0x37e7('0x18'),close);}ami['on'](_0x37e7('0x19'),connect);ami['on'](_0x37e7('0x1a'),function(_0xc40719){logger[_0x37e7('0x16')](util[_0x37e7('0xb')]('Shutdown\x20\x22%s\x22\x20to\x20%s:%s\x20with:\x0a%s',config[_0x37e7('0x5')]['username'],config[_0x37e7('0x5')]['ip'],config[_0x37e7('0x5')][_0x37e7('0x4')],util[_0x37e7('0xd')](_0xc40719,![],null)));});ami['on'](_0x37e7('0x1b'),function(){logger['info'](util[_0x37e7('0xb')](_0x37e7('0x1c'),config[_0x37e7('0x5')][_0x37e7('0x6')],config[_0x37e7('0x5')]['ip'],config[_0x37e7('0x5')]['port']));return Promise[_0x37e7('0x1d')]()[_0x37e7('0x1e')](ami[_0x37e7('0xf')]())['then'](ami[_0x37e7('0x10')]())[_0x37e7('0x1e')](ami[_0x37e7('0x11')]())['then'](ami[_0x37e7('0x12')]())[_0x37e7('0x1e')](ami['actionCoreShowChannels']())[_0x37e7('0x1f')](function(_0x26bc82){logger[_0x37e7('0xa')](_0x37e7('0x20'),util[_0x37e7('0xd')](_0x26bc82,{'showHidden':![],'depth':null}));});});ami[_0x37e7('0x17')](_0x37e7('0xa'),error);ami[_0x37e7('0x17')](_0x37e7('0x18'),close);module[_0x37e7('0x21')]=ami;