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