Built motion from commit (unavailable).|2.5.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 _0x842f=['Action','devicestatelist','sippeerstatus','actionQueueSummary','queuesummary','actionCoreShowChannels','coreshowchannels','Manager\x20\x22%s\x22\x20logged\x20on\x20to\x20%s:%s','once','close','connect','info','Shutdown\x20\x22%s\x22\x20to\x20%s:%s\x20with:\x0a%s','then','actionDeviceStateList','actionSipPeerStatus','catch','log','exports','asterisk-manager','moment','../../config/logger','ami','asterisk','username','password','keepConnected','action','error','format','Manager\x20\x22%s\x22\x20error\x20to\x20%s:%s\x20with:\x0a%s','port','inspect','actionSipShowRegistry'];(function(_0x34fa6a,_0x4ae7ff){var _0xc8aae5=function(_0x358b91){while(--_0x358b91){_0x34fa6a['push'](_0x34fa6a['shift']());}};_0xc8aae5(++_0x4ae7ff);}(_0x842f,0x1ef));var _0xf842=function(_0x1de2bd,_0x953fb){_0x1de2bd=_0x1de2bd-0x0;var _0x595960=_0x842f[_0x1de2bd];return _0x595960;};'use strict';var Manager=require(_0xf842('0x0'));var BPromise=require('bluebird');var moment=require(_0xf842('0x1'));var util=require('util');var _=require('lodash');var logger=require(_0xf842('0x2'))(_0xf842('0x3'));var config=require('../../config/environment');var ami=new Manager(config[_0xf842('0x4')]['port'],config[_0xf842('0x4')]['ip'],config[_0xf842('0x4')][_0xf842('0x5')],config['asterisk'][_0xf842('0x6')],!![]);ami[_0xf842('0x7')]();ami['Action']=BPromise['promisify'](ami[_0xf842('0x8')]);function error(_0x53b91d){logger[_0xf842('0x9')](util[_0xf842('0xa')](_0xf842('0xb'),config[_0xf842('0x4')][_0xf842('0x5')],config[_0xf842('0x4')]['ip'],config[_0xf842('0x4')][_0xf842('0xc')],util[_0xf842('0xd')](_0x53b91d,![],null)));}function close(){logger[_0xf842('0x9')](util[_0xf842('0xa')]('Manager\x20\x22%s\x22\x20closed\x20to\x20%s:%s',config['asterisk'][_0xf842('0x5')],config[_0xf842('0x4')]['ip'],config['asterisk'][_0xf842('0xc')]));}ami[_0xf842('0xe')]=function(){return function(){return ami[_0xf842('0xf')]({'action':'sipshowregistry'});};};ami['actionDeviceStateList']=function(){return function(){return ami[_0xf842('0xf')]({'action':_0xf842('0x10')});};};ami['actionSipPeerStatus']=function(){return function(){return ami[_0xf842('0xf')]({'action':_0xf842('0x11')});};};ami[_0xf842('0x12')]=function(){return function(){return ami[_0xf842('0xf')]({'action':_0xf842('0x13')});};};ami[_0xf842('0x14')]=function(){return function(){return ami[_0xf842('0xf')]({'action':_0xf842('0x15')});};};function connect(_0x36bdec){logger['info'](util['format'](_0xf842('0x16'),config[_0xf842('0x4')][_0xf842('0x5')],config[_0xf842('0x4')]['ip'],config[_0xf842('0x4')]['port']));ami['once'](_0xf842('0x9'),error);ami[_0xf842('0x17')](_0xf842('0x18'),close);}ami['on'](_0xf842('0x19'),connect);ami['on']('shutdown',function(_0x19aa71){logger[_0xf842('0x1a')](util[_0xf842('0xa')](_0xf842('0x1b'),config[_0xf842('0x4')][_0xf842('0x5')],config[_0xf842('0x4')]['ip'],config[_0xf842('0x4')][_0xf842('0xc')],util[_0xf842('0xd')](_0x19aa71,![],null)));});ami['on']('fullybooted',function(_0x5ba5a3){logger[_0xf842('0x1a')](util['format']('Fullybooted\x20\x22%s\x22\x20to\x20%s:%s',config[_0xf842('0x4')]['username'],config['asterisk']['ip'],config[_0xf842('0x4')]['port']));return BPromise['resolve']()['then'](ami['actionSipShowRegistry']())[_0xf842('0x1c')](ami[_0xf842('0x1d')]())[_0xf842('0x1c')](ami[_0xf842('0x1e')]())[_0xf842('0x1c')](ami[_0xf842('0x12')]())[_0xf842('0x1c')](ami[_0xf842('0x14')]())[_0xf842('0x1f')](function(_0x11da94){console[_0xf842('0x20')](_0x11da94);});});ami['once']('error',error);ami[_0xf842('0x17')](_0xf842('0x18'),close);module[_0xf842('0x21')]=ami;