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