Built motion from commit (unavailable).|2.4.21
[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 _0x5fcf=['log','bluebird','moment','../../config/logger','ami','asterisk','username','password','keepConnected','Action','promisify','action','format','port','inspect','Manager\x20\x22%s\x22\x20closed\x20to\x20%s:%s','actionSipShowRegistry','actionDeviceStateList','actionSipPeerStatus','sippeerstatus','actionQueueSummary','queuesummary','actionCoreShowChannels','coreshowchannels','info','once','error','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'];(function(_0x14dcee,_0x572c22){var _0x4e9354=function(_0x20e00d){while(--_0x20e00d){_0x14dcee['push'](_0x14dcee['shift']());}};_0x4e9354(++_0x572c22);}(_0x5fcf,0x182));var _0xf5fc=function(_0x51948f,_0x22bd85){_0x51948f=_0x51948f-0x0;var _0x4957d9=_0x5fcf[_0x51948f];return _0x4957d9;};'use strict';var Manager=require('asterisk-manager');var BPromise=require(_0xf5fc('0x0'));var moment=require(_0xf5fc('0x1'));var util=require('util');var _=require('lodash');var logger=require(_0xf5fc('0x2'))(_0xf5fc('0x3'));var config=require('../../config/environment');var ami=new Manager(config[_0xf5fc('0x4')]['port'],config[_0xf5fc('0x4')]['ip'],config[_0xf5fc('0x4')][_0xf5fc('0x5')],config[_0xf5fc('0x4')][_0xf5fc('0x6')],!![]);ami[_0xf5fc('0x7')]();ami[_0xf5fc('0x8')]=BPromise[_0xf5fc('0x9')](ami[_0xf5fc('0xa')]);function error(_0x55f10e){logger['error'](util[_0xf5fc('0xb')]('Manager\x20\x22%s\x22\x20error\x20to\x20%s:%s\x20with:\x0a%s',config['asterisk'][_0xf5fc('0x5')],config['asterisk']['ip'],config[_0xf5fc('0x4')][_0xf5fc('0xc')],util[_0xf5fc('0xd')](_0x55f10e,![],null)));}function close(){logger['error'](util[_0xf5fc('0xb')](_0xf5fc('0xe'),config['asterisk']['username'],config[_0xf5fc('0x4')]['ip'],config['asterisk'][_0xf5fc('0xc')]));}ami[_0xf5fc('0xf')]=function(){return function(){return ami[_0xf5fc('0x8')]({'action':'sipshowregistry'});};};ami[_0xf5fc('0x10')]=function(){return function(){return ami[_0xf5fc('0x8')]({'action':'devicestatelist'});};};ami[_0xf5fc('0x11')]=function(){return function(){return ami[_0xf5fc('0x8')]({'action':_0xf5fc('0x12')});};};ami[_0xf5fc('0x13')]=function(){return function(){return ami[_0xf5fc('0x8')]({'action':_0xf5fc('0x14')});};};ami[_0xf5fc('0x15')]=function(){return function(){return ami[_0xf5fc('0x8')]({'action':_0xf5fc('0x16')});};};function connect(_0x3638aa){logger[_0xf5fc('0x17')](util[_0xf5fc('0xb')]('Manager\x20\x22%s\x22\x20logged\x20on\x20to\x20%s:%s',config[_0xf5fc('0x4')][_0xf5fc('0x5')],config[_0xf5fc('0x4')]['ip'],config[_0xf5fc('0x4')]['port']));ami[_0xf5fc('0x18')](_0xf5fc('0x19'),error);ami[_0xf5fc('0x18')](_0xf5fc('0x1a'),close);}ami['on'](_0xf5fc('0x1b'),connect);ami['on'](_0xf5fc('0x1c'),function(_0x23ec68){logger['info'](util[_0xf5fc('0xb')](_0xf5fc('0x1d'),config[_0xf5fc('0x4')]['username'],config[_0xf5fc('0x4')]['ip'],config[_0xf5fc('0x4')][_0xf5fc('0xc')],util[_0xf5fc('0xd')](_0x23ec68,![],null)));});ami['on'](_0xf5fc('0x1e'),function(_0x294228){logger['info'](util[_0xf5fc('0xb')](_0xf5fc('0x1f'),config[_0xf5fc('0x4')][_0xf5fc('0x5')],config[_0xf5fc('0x4')]['ip'],config[_0xf5fc('0x4')][_0xf5fc('0xc')]));return BPromise[_0xf5fc('0x20')]()[_0xf5fc('0x21')](ami[_0xf5fc('0xf')]())[_0xf5fc('0x21')](ami[_0xf5fc('0x10')]())[_0xf5fc('0x21')](ami[_0xf5fc('0x11')]())['then'](ami[_0xf5fc('0x13')]())[_0xf5fc('0x21')](ami[_0xf5fc('0x15')]())['catch'](function(_0x527d01){console[_0xf5fc('0x22')](_0x527d01);});});ami[_0xf5fc('0x18')](_0xf5fc('0x19'),error);ami[_0xf5fc('0x18')](_0xf5fc('0x1a'),close);module['exports']=ami;