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