Built motion from commit e02f907f.|2.6.14
[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 _0x0056=['bluebird','util','../../config/logger','ami','../../config/environment','asterisk','port','keepConnected','action','error','format','username','inspect','actionSipShowRegistry','Action','sipshowregistry','devicestatelist','actionSipPeerStatus','actionQueueSummary','queuesummary','actionCoreShowChannels','info','Manager\x20\x22%s\x22\x20logged\x20on\x20to\x20%s:%s','once','close','shutdown','Shutdown\x20\x22%s\x22\x20to\x20%s:%s\x20with:\x0a%s','fullybooted','Fullybooted\x20\x22%s\x22\x20to\x20%s:%s','resolve','actionDeviceStateList','then','catch','[ami.js][fullybooted]','exports'];(function(_0x49c73d,_0x19e162){var _0x12c80b=function(_0x5909ae){while(--_0x5909ae){_0x49c73d['push'](_0x49c73d['shift']());}};_0x12c80b(++_0x19e162);}(_0x0056,0x8c));var _0x6005=function(_0x2df507,_0x553862){_0x2df507=_0x2df507-0x0;var _0x1f7167=_0x0056[_0x2df507];return _0x1f7167;};'use strict';var Manager=require('asterisk-manager');var BPromise=require(_0x6005('0x0'));var util=require(_0x6005('0x1'));var logger=require(_0x6005('0x2'))(_0x6005('0x3'));var config=require(_0x6005('0x4'));var ami=new Manager(config[_0x6005('0x5')][_0x6005('0x6')],config[_0x6005('0x5')]['ip'],config['asterisk']['username'],config['asterisk']['password'],!![]);ami[_0x6005('0x7')]();ami['Action']=BPromise['promisify'](ami[_0x6005('0x8')]);function error(_0x566629){logger[_0x6005('0x9')](util[_0x6005('0xa')]('Manager\x20\x22%s\x22\x20error\x20to\x20%s:%s\x20with:\x0a%s',config[_0x6005('0x5')][_0x6005('0xb')],config[_0x6005('0x5')]['ip'],config[_0x6005('0x5')][_0x6005('0x6')],util[_0x6005('0xc')](_0x566629,![],null)));}function close(){logger[_0x6005('0x9')](util['format']('Manager\x20\x22%s\x22\x20closed\x20to\x20%s:%s',config[_0x6005('0x5')]['username'],config[_0x6005('0x5')]['ip'],config[_0x6005('0x5')][_0x6005('0x6')]));}ami[_0x6005('0xd')]=function(){return function(){return ami[_0x6005('0xe')]({'action':_0x6005('0xf')});};};ami['actionDeviceStateList']=function(){return function(){return ami[_0x6005('0xe')]({'action':_0x6005('0x10')});};};ami[_0x6005('0x11')]=function(){return function(){return ami[_0x6005('0xe')]({'action':'sippeerstatus'});};};ami[_0x6005('0x12')]=function(){return function(){return ami[_0x6005('0xe')]({'action':_0x6005('0x13')});};};ami[_0x6005('0x14')]=function(){return function(){return ami['Action']({'action':'coreshowchannels'});};};function connect(){logger[_0x6005('0x15')](util['format'](_0x6005('0x16'),config[_0x6005('0x5')][_0x6005('0xb')],config[_0x6005('0x5')]['ip'],config[_0x6005('0x5')][_0x6005('0x6')]));ami['once']('error',error);ami[_0x6005('0x17')](_0x6005('0x18'),close);}ami['on']('connect',connect);ami['on'](_0x6005('0x19'),function(_0x3e9dc2){logger[_0x6005('0x15')](util[_0x6005('0xa')](_0x6005('0x1a'),config[_0x6005('0x5')][_0x6005('0xb')],config[_0x6005('0x5')]['ip'],config[_0x6005('0x5')][_0x6005('0x6')],util[_0x6005('0xc')](_0x3e9dc2,![],null)));});ami['on'](_0x6005('0x1b'),function(){logger['info'](util[_0x6005('0xa')](_0x6005('0x1c'),config[_0x6005('0x5')]['username'],config[_0x6005('0x5')]['ip'],config['asterisk']['port']));return Promise[_0x6005('0x1d')]()['then'](ami[_0x6005('0xd')]())['then'](ami[_0x6005('0x1e')]())[_0x6005('0x1f')](ami['actionSipPeerStatus']())[_0x6005('0x1f')](ami[_0x6005('0x12')]())[_0x6005('0x1f')](ami['actionCoreShowChannels']())[_0x6005('0x20')](function(_0x27ed5d){logger[_0x6005('0x9')](_0x6005('0x21'),util[_0x6005('0xc')](_0x27ed5d,{'showHidden':![],'depth':null}));});});ami[_0x6005('0x17')](_0x6005('0x9'),error);ami['once'](_0x6005('0x18'),close);module[_0x6005('0x22')]=ami;