Built motion from commit 746c7d2a.|2.5.35
[motion2.git] / server / services / ami / report / userReport.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 _0x152f=['event','actionid','username','[userReport][registry]\x20sending\x20trunk:save\x20event:','trunk:%s','name','trunk:save','[userReport][devicestatechange]\x20device:%s\x20state:%s','device','[userReport][devicestatechange]','local','toLowerCase','inuse','stateTime','format','updateStatusRealtime','toNumber','telephone:%s','telephone:save','Local','substring','mobile','phone','[userReport][peerstatus]\x20peer:%s\x20address:%s\x20status:%s','peer','address','[userReport][peerstatus]','registered','status','[userReport][peerstatus]\x20sending\x20telephone:save\x20event:','[userReport][peerstatus]\x20sending\x20trunk:save\x20event:','exports','lodash','moment','util','ioredis','bluebird','../../../config/logger','ami','../ami','redis','socket.io-emitter','agents','telephones','registryentry','bind','registry','syncRegistry','devicestatechange','syncDeviceState','peerstatus','syncPeerStatus','syncRealtimeShow','resolve','then','actionSipShowRegistry','error','inspect','catch','[userReport][devicestatelist]','prototype','isNotNull','emit','info','[userReport][registry]\x20registry:%s\x20state:%s','state','debug','[userReport][registry]','find','trunks','stateRegistry','merge','omit'];(function(_0x5f25b3,_0x35481a){var _0x4ab9bf=function(_0x49baf7){while(--_0x49baf7){_0x5f25b3['push'](_0x5f25b3['shift']());}};_0x4ab9bf(++_0x35481a);}(_0x152f,0x144));var _0xf152=function(_0x3ce3c,_0x319337){_0x3ce3c=_0x3ce3c-0x0;var _0x55a2c9=_0x152f[_0x3ce3c];return _0x55a2c9;};'use strict';var _=require(_0xf152('0x0'));var moment=require(_0xf152('0x1'));var util=require(_0xf152('0x2'));var Redis=require(_0xf152('0x3'));var BPromise=require(_0xf152('0x4'));var config=require('../../../config/environment');var logger=require(_0xf152('0x5'))(_0xf152('0x6'));var ami=require(_0xf152('0x7'));config[_0xf152('0x8')]=_['defaults'](config[_0xf152('0x8')],{'host':'localhost','port':0x18eb});var io=require(_0xf152('0x9'))(new Redis(config['redis']));function UserReport(_0x36498a){this['trunks']=_0x36498a['trunks'];this[_0xf152('0xa')]=_0x36498a[_0xf152('0xa')];this['telephones']=_0x36498a[_0xf152('0xb')];ami['on'](_0xf152('0xc'),this['syncRegistry'][_0xf152('0xd')](this));ami['on'](_0xf152('0xe'),this[_0xf152('0xf')][_0xf152('0xd')](this));ami['on'](_0xf152('0x10'),this[_0xf152('0x11')][_0xf152('0xd')](this));ami['on'](_0xf152('0x12'),this[_0xf152('0x13')][_0xf152('0xd')](this));return this[_0xf152('0x14')]();}function showSipRegistrations(){Promise[_0xf152('0x15')]()[_0xf152('0x16')](ami[_0xf152('0x17')]())['catch'](function(_0x321ef1){logger[_0xf152('0x18')]('[userReport][sipshowregistry]',util[_0xf152('0x19')](_0x321ef1,{'showHidden':![],'depth':null}));});}function listDeviceStates(){Promise[_0xf152('0x15')]()[_0xf152('0x16')](ami['actionDeviceStateList']())[_0xf152('0x1a')](function(_0x286f0a){logger['error'](_0xf152('0x1b'),util[_0xf152('0x19')](_0x286f0a,{'showHidden':![],'depth':null}));});}function showPeersStatus(){Promise[_0xf152('0x15')]()[_0xf152('0x16')](ami['actionSipPeerStatus']())[_0xf152('0x1a')](function(_0x5872d9){logger[_0xf152('0x18')]('[userReport][sippeerstatus]',util[_0xf152('0x19')](_0x5872d9,{'showHidden':![],'depth':null}));});}UserReport[_0xf152('0x1c')][_0xf152('0x14')]=function(){setInterval(function(){BPromise[_0xf152('0x15')]()[_0xf152('0x16')](showSipRegistrations())[_0xf152('0x16')](listDeviceStates())['then'](showPeersStatus());},0x32c8);};UserReport[_0xf152('0x1c')][_0xf152('0x1d')]=function(_0x2c0433){return _0x2c0433!==null&&!_['isUndefined'](_0x2c0433);};UserReport[_0xf152('0x1c')][_0xf152('0x1e')]=function(_0x2cb87f,_0x35442a,_0xc65d65){io['to'](_0x2cb87f)[_0xf152('0x1e')](_0x35442a,_0xc65d65);};UserReport['prototype']['syncRegistry']=function(_0x39d904){try{if(this[_0xf152('0x1d')](_0x39d904)){logger[_0xf152('0x1f')](_0xf152('0x20'),_0x39d904['username'],_0x39d904[_0xf152('0x21')]);logger[_0xf152('0x22')](_0xf152('0x23'),util['inspect'](_0x39d904,{'showHidden':![],'depth':null}));var _0xea6589=_[_0xf152('0x24')](this[_0xf152('0x25')],{'defaultuser':_0x39d904['username']});if(_0xea6589){_0x39d904[_0xf152('0x26')]=_0x39d904[_0xf152('0x21')];_[_0xf152('0x27')](_0xea6589,_[_0xf152('0x28')](_0x39d904,[_0xf152('0x29'),_0xf152('0x2a'),_0xf152('0x2b'),_0xf152('0x21')]));logger['debug'](_0xf152('0x2c'),util['inspect'](_0xea6589,{'showHidden':![],'depth':null}));this[_0xf152('0x1e')](util['format'](_0xf152('0x2d'),_0xea6589[_0xf152('0x2e')]),_0xf152('0x2f'),_0xea6589);}}}catch(_0x2bdf10){logger[_0xf152('0x18')](_0xf152('0x23'),util[_0xf152('0x19')](_0x2bdf10,{'showHidden':![],'depth':null}));}};UserReport['prototype'][_0xf152('0x11')]=function(_0x502eb5){try{if(this['isNotNull'](_0x502eb5)){logger[_0xf152('0x1f')](_0xf152('0x30'),_0x502eb5[_0xf152('0x31')],_0x502eb5[_0xf152('0x21')]);logger[_0xf152('0x22')](_0xf152('0x32'),util[_0xf152('0x19')](_0x502eb5,{'showHidden':![],'depth':null}));if(this['agents'][_0x502eb5['device']]){if(!this[_0xf152('0xa')][_0x502eb5[_0xf152('0x31')]][_0xf152('0x33')]||_0x502eb5[_0xf152('0x21')][_0xf152('0x34')]()==_0xf152('0x35')){this[_0xf152('0xa')][_0x502eb5['device']][_0xf152('0x33')]=![];if(this[_0xf152('0xa')][_0x502eb5['device']][_0xf152('0x21')]!==_0x502eb5[_0xf152('0x21')][_0xf152('0x34')]()){this['agents'][_0x502eb5[_0xf152('0x31')]][_0xf152('0x36')]=_['toNumber'](moment()[_0xf152('0x37')]('x'));}this['agents'][_0x502eb5['device']][_0xf152('0x21')]=_0x502eb5[_0xf152('0x21')]['toLowerCase']();this[_0xf152('0xa')][_0x502eb5[_0xf152('0x31')]][_0xf152('0x38')](_0x502eb5);}}else if(this[_0xf152('0xb')][_0x502eb5['device']]){if(this[_0xf152('0xb')][_0x502eb5[_0xf152('0x31')]][_0xf152('0x21')]!==_0x502eb5[_0xf152('0x21')][_0xf152('0x34')]()){this['telephones'][_0x502eb5[_0xf152('0x31')]]['stateTime']=_[_0xf152('0x39')](moment()['format']('x'));}this[_0xf152('0xb')][_0x502eb5[_0xf152('0x31')]][_0xf152('0x21')]=_0x502eb5[_0xf152('0x21')][_0xf152('0x34')]();logger[_0xf152('0x22')]('[userReport][devicestatechange]\x20sending\x20telephone:save\x20event:',util['inspect'](this['telephones'][_0x502eb5['device']],{'showHidden':![],'depth':null}));this['emit'](util[_0xf152('0x37')](_0xf152('0x3a'),this[_0xf152('0xb')][_0x502eb5['device']][_0xf152('0x2e')]),_0xf152('0x3b'),this[_0xf152('0xb')][_0x502eb5[_0xf152('0x31')]]);}else if(this['trunks'][_0x502eb5[_0xf152('0x31')]]){if(this[_0xf152('0x25')][_0x502eb5[_0xf152('0x31')]][_0xf152('0x21')]!==_0x502eb5[_0xf152('0x21')][_0xf152('0x34')]()){this[_0xf152('0x25')][_0x502eb5['device']]['stateTime']=_[_0xf152('0x39')](moment()[_0xf152('0x37')]('x'));}this['trunks'][_0x502eb5[_0xf152('0x31')]][_0xf152('0x21')]=_0x502eb5['state'][_0xf152('0x34')]();logger[_0xf152('0x22')]('[userReport][devicestatechange]\x20sending\x20trunk:save\x20event:',util[_0xf152('0x19')](this['trunks'][_0x502eb5[_0xf152('0x31')]],{'showHidden':![],'depth':null}));this[_0xf152('0x1e')](util['format'](_0xf152('0x2d'),this[_0xf152('0x25')][_0x502eb5[_0xf152('0x31')]]['name']),'trunk:save',this[_0xf152('0x25')][_0x502eb5[_0xf152('0x31')]]);}else if(_['startsWith'](_0x502eb5[_0xf152('0x31')],_0xf152('0x3c'))){var _0x575ba1=_0x502eb5[_0xf152('0x31')];var _0x19f8a9=_0x575ba1[_0xf152('0x3d')](_0x575ba1['indexOf']('/')+0x1,_0x575ba1['indexOf']('@'));var _0x15fcd5=_['find'](this['agents'],function(_0x4590e6){return _0x4590e6[_0xf152('0x3e')]==_0x19f8a9||_0x4590e6[_0xf152('0x3f')]==_0x19f8a9||_0x4590e6['accountcode']==_0x19f8a9;});if(_0x15fcd5){if(_0x15fcd5[_0xf152('0x21')]!==_0x502eb5[_0xf152('0x21')][_0xf152('0x34')]()){_0x15fcd5['stateTime']=_[_0xf152('0x39')](moment()[_0xf152('0x37')]('x'));}_0x15fcd5[_0xf152('0x21')]=_0x502eb5[_0xf152('0x21')][_0xf152('0x34')]();_0x15fcd5['local']=!![];_0x15fcd5[_0xf152('0x38')](_0x502eb5);}}}}catch(_0x1e8df5){logger[_0xf152('0x18')](_0xf152('0x32'),util['inspect'](_0x1e8df5,{'showHidden':![],'depth':null}));}};UserReport['prototype'][_0xf152('0x13')]=function(_0x284d32){try{if(this[_0xf152('0x1d')](_0x284d32)&&this[_0xf152('0x1d')](_0x284d32['peerstatus'])){logger[_0xf152('0x1f')](_0xf152('0x40'),_0x284d32[_0xf152('0x41')],_0x284d32[_0xf152('0x42')],_0x284d32[_0xf152('0x12')]);logger[_0xf152('0x22')](_0xf152('0x43'),util[_0xf152('0x19')](_0x284d32,{'showHidden':![],'depth':null}));if(this[_0xf152('0xa')][_0x284d32['peer']]){if(!this['agents'][_0x284d32[_0xf152('0x41')]]['local']||_0x284d32[_0xf152('0x12')][_0xf152('0x34')]()==_0xf152('0x44')){this[_0xf152('0xa')][_0x284d32['peer']][_0xf152('0x33')]=![];this[_0xf152('0xa')][_0x284d32['peer']][_0xf152('0x45')]=_0x284d32['peerstatus']['toLowerCase']();this[_0xf152('0xa')][_0x284d32['peer']][_0xf152('0x42')]=_0x284d32[_0xf152('0x42')];this['agents'][_0x284d32[_0xf152('0x41')]][_0xf152('0x38')](_0x284d32);}}else if(this[_0xf152('0xb')][_0x284d32[_0xf152('0x41')]]){this[_0xf152('0xb')][_0x284d32[_0xf152('0x41')]][_0xf152('0x45')]=_0x284d32[_0xf152('0x12')]['toLowerCase']();this['telephones'][_0x284d32['peer']][_0xf152('0x42')]=_0x284d32[_0xf152('0x42')];logger[_0xf152('0x22')](_0xf152('0x46'),util[_0xf152('0x19')](this[_0xf152('0xb')][_0x284d32['peer']],{'showHidden':![],'depth':null}));this[_0xf152('0x1e')](util[_0xf152('0x37')](_0xf152('0x3a'),this[_0xf152('0xb')][_0x284d32[_0xf152('0x41')]][_0xf152('0x2e')]),_0xf152('0x3b'),this[_0xf152('0xb')][_0x284d32[_0xf152('0x41')]]);}else if(this[_0xf152('0x25')][_0x284d32[_0xf152('0x41')]]){this[_0xf152('0x25')][_0x284d32[_0xf152('0x41')]]['status']=_0x284d32[_0xf152('0x12')]['toLowerCase']();this[_0xf152('0x25')][_0x284d32[_0xf152('0x41')]]['address']=_0x284d32['address'];logger['debug'](_0xf152('0x47'),util[_0xf152('0x19')](this[_0xf152('0x25')][_0x284d32['peer']],{'showHidden':![],'depth':null}));this[_0xf152('0x1e')](util[_0xf152('0x37')](_0xf152('0x2d'),this[_0xf152('0x25')][_0x284d32['peer']]['name']),'trunk:save',this[_0xf152('0x25')][_0x284d32['peer']]);}}}catch(_0x2994e4){logger[_0xf152('0x18')](_0xf152('0x43'),util[_0xf152('0x19')](_0x2994e4,{'showHidden':![],'depth':null}));}};module[_0xf152('0x48')]=UserReport;