9de92696961fc4046a7e8a74747f4044ce9c1b0f
[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 _0xa803=['format','trunk:%s','name','trunk:save','[userReport][devicestatechange]\x20device:%s\x20state:%s','device','[userReport][devicestatechange]','local','inuse','toLowerCase','stateTime','updateStatusRealtime','telephones','toNumber','[userReport][devicestatechange]\x20sending\x20telephone:save\x20event:','telephone:%s','telephone:save','startsWith','substring','phone','accountcode','syncPeerStatus','[userReport][peerstatus]\x20peer:%s\x20address:%s\x20status:%s','address','[userReport][peerstatus]','peer','registered','status','[userReport][peerstatus]\x20sending\x20trunk:save\x20event:','exports','lodash','moment','util','ioredis','bluebird','../../../config/logger','ami','../ami','redis','defaults','localhost','trunks','agents','syncRegistry','registry','bind','devicestatechange','syncDeviceState','peerstatus','syncRealtimeShow','error','resolve','then','actionDeviceStateList','catch','inspect','[userReport][sippeerstatus]','prototype','isNotNull','isUndefined','emit','info','[userReport][registry]\x20registry:%s\x20state:%s','state','debug','[userReport][registry]','find','username','stateRegistry','merge','omit','event','actionid'];(function(_0x32af1c,_0x2411e0){var _0x172042=function(_0x5c5921){while(--_0x5c5921){_0x32af1c['push'](_0x32af1c['shift']());}};_0x172042(++_0x2411e0);}(_0xa803,0x18b));var _0x3a80=function(_0x46cd75,_0x34eb0a){_0x46cd75=_0x46cd75-0x0;var _0x336c8e=_0xa803[_0x46cd75];return _0x336c8e;};'use strict';var _=require(_0x3a80('0x0'));var moment=require(_0x3a80('0x1'));var util=require(_0x3a80('0x2'));var Redis=require(_0x3a80('0x3'));var BPromise=require(_0x3a80('0x4'));var config=require('../../../config/environment');var logger=require(_0x3a80('0x5'))(_0x3a80('0x6'));var ami=require(_0x3a80('0x7'));config[_0x3a80('0x8')]=_[_0x3a80('0x9')](config[_0x3a80('0x8')],{'host':_0x3a80('0xa'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config['redis']));function UserReport(_0x52024e){this[_0x3a80('0xb')]=_0x52024e[_0x3a80('0xb')];this[_0x3a80('0xc')]=_0x52024e['agents'];this['telephones']=_0x52024e['telephones'];ami['on']('registryentry',this[_0x3a80('0xd')]['bind'](this));ami['on'](_0x3a80('0xe'),this[_0x3a80('0xd')][_0x3a80('0xf')](this));ami['on'](_0x3a80('0x10'),this[_0x3a80('0x11')][_0x3a80('0xf')](this));ami['on'](_0x3a80('0x12'),this['syncPeerStatus'][_0x3a80('0xf')](this));return this[_0x3a80('0x13')]();}function showSipRegistrations(){Promise['resolve']()['then'](ami['actionSipShowRegistry']())['catch'](function(_0x50c82a){logger[_0x3a80('0x14')]('[userReport][sipshowregistry]',util['inspect'](_0x50c82a,{'showHidden':![],'depth':null}));});}function listDeviceStates(){Promise[_0x3a80('0x15')]()[_0x3a80('0x16')](ami[_0x3a80('0x17')]())[_0x3a80('0x18')](function(_0x161cc9){logger[_0x3a80('0x14')]('[userReport][devicestatelist]',util[_0x3a80('0x19')](_0x161cc9,{'showHidden':![],'depth':null}));});}function showPeersStatus(){Promise[_0x3a80('0x15')]()[_0x3a80('0x16')](ami['actionSipPeerStatus']())[_0x3a80('0x18')](function(_0x5eed1a){logger[_0x3a80('0x14')](_0x3a80('0x1a'),util[_0x3a80('0x19')](_0x5eed1a,{'showHidden':![],'depth':null}));});}UserReport['prototype'][_0x3a80('0x13')]=function(){setInterval(function(){BPromise['resolve']()[_0x3a80('0x16')](showSipRegistrations())[_0x3a80('0x16')](listDeviceStates())[_0x3a80('0x16')](showPeersStatus());},0x32c8);};UserReport[_0x3a80('0x1b')][_0x3a80('0x1c')]=function(_0x18b1ef){return _0x18b1ef!==null&&!_[_0x3a80('0x1d')](_0x18b1ef);};UserReport[_0x3a80('0x1b')][_0x3a80('0x1e')]=function(_0x3d8968,_0x4e4d43,_0x4c0007){io['to'](_0x3d8968)[_0x3a80('0x1e')](_0x4e4d43,_0x4c0007);};UserReport[_0x3a80('0x1b')][_0x3a80('0xd')]=function(_0x50ee2a){try{if(this['isNotNull'](_0x50ee2a)){logger[_0x3a80('0x1f')](_0x3a80('0x20'),_0x50ee2a['username'],_0x50ee2a[_0x3a80('0x21')]);logger[_0x3a80('0x22')](_0x3a80('0x23'),util[_0x3a80('0x19')](_0x50ee2a,{'showHidden':![],'depth':null}));var _0x1cc668=_[_0x3a80('0x24')](this[_0x3a80('0xb')],{'defaultuser':_0x50ee2a[_0x3a80('0x25')]});if(_0x1cc668){_0x50ee2a[_0x3a80('0x26')]=_0x50ee2a[_0x3a80('0x21')];_[_0x3a80('0x27')](_0x1cc668,_[_0x3a80('0x28')](_0x50ee2a,[_0x3a80('0x29'),_0x3a80('0x2a'),_0x3a80('0x25'),'state']));logger['debug']('[userReport][registry]\x20sending\x20trunk:save\x20event:',util['inspect'](_0x1cc668,{'showHidden':![],'depth':null}));this[_0x3a80('0x1e')](util[_0x3a80('0x2b')](_0x3a80('0x2c'),_0x1cc668[_0x3a80('0x2d')]),_0x3a80('0x2e'),_0x1cc668);}}}catch(_0x40ce52){logger[_0x3a80('0x14')](_0x3a80('0x23'),util[_0x3a80('0x19')](_0x40ce52,{'showHidden':![],'depth':null}));}};UserReport['prototype'][_0x3a80('0x11')]=function(_0x2795b5){try{if(this[_0x3a80('0x1c')](_0x2795b5)){logger[_0x3a80('0x1f')](_0x3a80('0x2f'),_0x2795b5[_0x3a80('0x30')],_0x2795b5[_0x3a80('0x21')]);logger[_0x3a80('0x22')](_0x3a80('0x31'),util['inspect'](_0x2795b5,{'showHidden':![],'depth':null}));if(this[_0x3a80('0xc')][_0x2795b5['device']]){if(!this[_0x3a80('0xc')][_0x2795b5['device']][_0x3a80('0x32')]||_0x2795b5[_0x3a80('0x21')]['toLowerCase']()==_0x3a80('0x33')){this['agents'][_0x2795b5['device']]['local']=![];if(this['agents'][_0x2795b5[_0x3a80('0x30')]]['state']!==_0x2795b5['state'][_0x3a80('0x34')]()){this[_0x3a80('0xc')][_0x2795b5['device']][_0x3a80('0x35')]=_['toNumber'](moment()[_0x3a80('0x2b')]('x'));}this[_0x3a80('0xc')][_0x2795b5[_0x3a80('0x30')]]['state']=_0x2795b5['state'][_0x3a80('0x34')]();this[_0x3a80('0xc')][_0x2795b5[_0x3a80('0x30')]][_0x3a80('0x36')](_0x2795b5);}}else if(this[_0x3a80('0x37')][_0x2795b5[_0x3a80('0x30')]]){if(this[_0x3a80('0x37')][_0x2795b5[_0x3a80('0x30')]]['state']!==_0x2795b5[_0x3a80('0x21')]['toLowerCase']()){this[_0x3a80('0x37')][_0x2795b5[_0x3a80('0x30')]][_0x3a80('0x35')]=_[_0x3a80('0x38')](moment()[_0x3a80('0x2b')]('x'));}this['telephones'][_0x2795b5[_0x3a80('0x30')]][_0x3a80('0x21')]=_0x2795b5['state']['toLowerCase']();logger[_0x3a80('0x22')](_0x3a80('0x39'),util[_0x3a80('0x19')](this['telephones'][_0x2795b5[_0x3a80('0x30')]],{'showHidden':![],'depth':null}));this[_0x3a80('0x1e')](util[_0x3a80('0x2b')](_0x3a80('0x3a'),this['telephones'][_0x2795b5['device']][_0x3a80('0x2d')]),_0x3a80('0x3b'),this['telephones'][_0x2795b5[_0x3a80('0x30')]]);}else if(this[_0x3a80('0xb')][_0x2795b5['device']]){if(this[_0x3a80('0xb')][_0x2795b5[_0x3a80('0x30')]][_0x3a80('0x21')]!==_0x2795b5['state'][_0x3a80('0x34')]()){this['trunks'][_0x2795b5['device']][_0x3a80('0x35')]=_[_0x3a80('0x38')](moment()[_0x3a80('0x2b')]('x'));}this[_0x3a80('0xb')][_0x2795b5[_0x3a80('0x30')]][_0x3a80('0x21')]=_0x2795b5[_0x3a80('0x21')][_0x3a80('0x34')]();logger[_0x3a80('0x22')]('[userReport][devicestatechange]\x20sending\x20trunk:save\x20event:',util[_0x3a80('0x19')](this['trunks'][_0x2795b5[_0x3a80('0x30')]],{'showHidden':![],'depth':null}));this[_0x3a80('0x1e')](util[_0x3a80('0x2b')](_0x3a80('0x2c'),this['trunks'][_0x2795b5[_0x3a80('0x30')]][_0x3a80('0x2d')]),_0x3a80('0x2e'),this['trunks'][_0x2795b5[_0x3a80('0x30')]]);}else if(_[_0x3a80('0x3c')](_0x2795b5[_0x3a80('0x30')],'Local')){var _0x2e6db5=_0x2795b5['device'];var _0x21e295=_0x2e6db5[_0x3a80('0x3d')](_0x2e6db5['indexOf']('/')+0x1,_0x2e6db5['indexOf']('@'));var _0xa3a6a2=_[_0x3a80('0x24')](this[_0x3a80('0xc')],function(_0x39b3db){return _0x39b3db['mobile']==_0x21e295||_0x39b3db[_0x3a80('0x3e')]==_0x21e295||_0x39b3db[_0x3a80('0x3f')]==_0x21e295;});if(_0xa3a6a2){if(_0xa3a6a2[_0x3a80('0x21')]!==_0x2795b5[_0x3a80('0x21')]['toLowerCase']()){_0xa3a6a2[_0x3a80('0x35')]=_['toNumber'](moment()[_0x3a80('0x2b')]('x'));}_0xa3a6a2[_0x3a80('0x21')]=_0x2795b5[_0x3a80('0x21')]['toLowerCase']();_0xa3a6a2[_0x3a80('0x32')]=!![];_0xa3a6a2['updateStatusRealtime'](_0x2795b5);}}}}catch(_0x495395){logger['error'](_0x3a80('0x31'),util[_0x3a80('0x19')](_0x495395,{'showHidden':![],'depth':null}));}};UserReport[_0x3a80('0x1b')][_0x3a80('0x40')]=function(_0x3c099e){try{if(this[_0x3a80('0x1c')](_0x3c099e)&&this['isNotNull'](_0x3c099e[_0x3a80('0x12')])){logger['info'](_0x3a80('0x41'),_0x3c099e['peer'],_0x3c099e[_0x3a80('0x42')],_0x3c099e[_0x3a80('0x12')]);logger[_0x3a80('0x22')](_0x3a80('0x43'),util['inspect'](_0x3c099e,{'showHidden':![],'depth':null}));if(this[_0x3a80('0xc')][_0x3c099e[_0x3a80('0x44')]]){if(!this['agents'][_0x3c099e[_0x3a80('0x44')]]['local']||_0x3c099e[_0x3a80('0x12')]['toLowerCase']()==_0x3a80('0x45')){this[_0x3a80('0xc')][_0x3c099e['peer']][_0x3a80('0x32')]=![];this['agents'][_0x3c099e['peer']]['status']=_0x3c099e[_0x3a80('0x12')][_0x3a80('0x34')]();this[_0x3a80('0xc')][_0x3c099e[_0x3a80('0x44')]]['address']=_0x3c099e[_0x3a80('0x42')];this[_0x3a80('0xc')][_0x3c099e[_0x3a80('0x44')]][_0x3a80('0x36')](_0x3c099e);}}else if(this[_0x3a80('0x37')][_0x3c099e[_0x3a80('0x44')]]){this[_0x3a80('0x37')][_0x3c099e[_0x3a80('0x44')]]['status']=_0x3c099e[_0x3a80('0x12')][_0x3a80('0x34')]();this[_0x3a80('0x37')][_0x3c099e[_0x3a80('0x44')]][_0x3a80('0x42')]=_0x3c099e[_0x3a80('0x42')];logger[_0x3a80('0x22')]('[userReport][peerstatus]\x20sending\x20telephone:save\x20event:',util[_0x3a80('0x19')](this[_0x3a80('0x37')][_0x3c099e[_0x3a80('0x44')]],{'showHidden':![],'depth':null}));this[_0x3a80('0x1e')](util[_0x3a80('0x2b')](_0x3a80('0x3a'),this[_0x3a80('0x37')][_0x3c099e[_0x3a80('0x44')]][_0x3a80('0x2d')]),'telephone:save',this[_0x3a80('0x37')][_0x3c099e[_0x3a80('0x44')]]);}else if(this[_0x3a80('0xb')][_0x3c099e[_0x3a80('0x44')]]){this[_0x3a80('0xb')][_0x3c099e[_0x3a80('0x44')]][_0x3a80('0x46')]=_0x3c099e[_0x3a80('0x12')]['toLowerCase']();this[_0x3a80('0xb')][_0x3c099e[_0x3a80('0x44')]][_0x3a80('0x42')]=_0x3c099e['address'];logger[_0x3a80('0x22')](_0x3a80('0x47'),util[_0x3a80('0x19')](this[_0x3a80('0xb')][_0x3c099e[_0x3a80('0x44')]],{'showHidden':![],'depth':null}));this[_0x3a80('0x1e')](util[_0x3a80('0x2b')](_0x3a80('0x2c'),this[_0x3a80('0xb')][_0x3c099e[_0x3a80('0x44')]][_0x3a80('0x2d')]),_0x3a80('0x2e'),this[_0x3a80('0xb')][_0x3c099e[_0x3a80('0x44')]]);}}}catch(_0x208678){logger[_0x3a80('0x14')](_0x3a80('0x43'),util[_0x3a80('0x19')](_0x208678,{'showHidden':![],'depth':null}));}};module[_0x3a80('0x48')]=UserReport;