b93ab11f281779e741145f8eb3e39a417612260e
[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 _0xe910=['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','sippeerstatus','actionQueueSummary','queuesummary','actionCoreShowChannels','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','then','[ami.js][fullybooted]','exports','asterisk-manager','bluebird','util','../../config/logger','ami','../../config/environment','asterisk','port','username','password','keepConnected','Action','promisify','action'];(function(_0xcf6d6b,_0x2b15b7){var _0x337966=function(_0x1aba20){while(--_0x1aba20){_0xcf6d6b['push'](_0xcf6d6b['shift']());}};_0x337966(++_0x2b15b7);}(_0xe910,0x1ed));var _0x0e91=function(_0x3a07c1,_0x34d57f){_0x3a07c1=_0x3a07c1-0x0;var _0x2bbe15=_0xe910[_0x3a07c1];return _0x2bbe15;};'use strict';var Manager=require(_0x0e91('0x0'));var BPromise=require(_0x0e91('0x1'));var util=require(_0x0e91('0x2'));var logger=require(_0x0e91('0x3'))(_0x0e91('0x4'));var config=require(_0x0e91('0x5'));var ami=new Manager(config[_0x0e91('0x6')][_0x0e91('0x7')],config[_0x0e91('0x6')]['ip'],config[_0x0e91('0x6')][_0x0e91('0x8')],config[_0x0e91('0x6')][_0x0e91('0x9')],!![]);ami[_0x0e91('0xa')]();ami[_0x0e91('0xb')]=BPromise[_0x0e91('0xc')](ami[_0x0e91('0xd')]);function error(_0x3a4866){logger[_0x0e91('0xe')](util[_0x0e91('0xf')](_0x0e91('0x10'),config['asterisk'][_0x0e91('0x8')],config[_0x0e91('0x6')]['ip'],config[_0x0e91('0x6')][_0x0e91('0x7')],util[_0x0e91('0x11')](_0x3a4866,![],null)));}function close(){logger['error'](util[_0x0e91('0xf')](_0x0e91('0x12'),config[_0x0e91('0x6')][_0x0e91('0x8')],config[_0x0e91('0x6')]['ip'],config['asterisk'][_0x0e91('0x7')]));}ami[_0x0e91('0x13')]=function(){return function(){return ami[_0x0e91('0xb')]({'action':_0x0e91('0x14')});};};ami[_0x0e91('0x15')]=function(){return function(){return ami[_0x0e91('0xb')]({'action':'devicestatelist'});};};ami[_0x0e91('0x16')]=function(){return function(){return ami[_0x0e91('0xb')]({'action':_0x0e91('0x17')});};};ami[_0x0e91('0x18')]=function(){return function(){return ami[_0x0e91('0xb')]({'action':_0x0e91('0x19')});};};ami[_0x0e91('0x1a')]=function(){return function(){return ami[_0x0e91('0xb')]({'action':'coreshowchannels'});};};function connect(){logger[_0x0e91('0x1b')](util['format'](_0x0e91('0x1c'),config[_0x0e91('0x6')][_0x0e91('0x8')],config[_0x0e91('0x6')]['ip'],config[_0x0e91('0x6')][_0x0e91('0x7')]));ami[_0x0e91('0x1d')]('error',error);ami[_0x0e91('0x1d')](_0x0e91('0x1e'),close);}ami['on'](_0x0e91('0x1f'),connect);ami['on'](_0x0e91('0x20'),function(_0x45127a){logger['info'](util[_0x0e91('0xf')](_0x0e91('0x21'),config[_0x0e91('0x6')][_0x0e91('0x8')],config['asterisk']['ip'],config[_0x0e91('0x6')][_0x0e91('0x7')],util[_0x0e91('0x11')](_0x45127a,![],null)));});ami['on'](_0x0e91('0x22'),function(){logger[_0x0e91('0x1b')](util['format'](_0x0e91('0x23'),config[_0x0e91('0x6')][_0x0e91('0x8')],config['asterisk']['ip'],config[_0x0e91('0x6')]['port']));return Promise['resolve']()[_0x0e91('0x24')](ami[_0x0e91('0x13')]())[_0x0e91('0x24')](ami[_0x0e91('0x15')]())[_0x0e91('0x24')](ami[_0x0e91('0x16')]())[_0x0e91('0x24')](ami[_0x0e91('0x18')]())[_0x0e91('0x24')](ami[_0x0e91('0x1a')]())['catch'](function(_0x2d5575){logger[_0x0e91('0xe')](_0x0e91('0x25'),util['inspect'](_0x2d5575,{'showHidden':![],'depth':null}));});});ami[_0x0e91('0x1d')](_0x0e91('0xe'),error);ami[_0x0e91('0x1d')](_0x0e91('0x1e'),close);module[_0x0e91('0x26')]=ami;