Built motion from commit (unavailable).|2.5.31
[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 _0x0170=['registryentry','syncRegistry','bind','registry','devicestatechange','syncDeviceState','peerstatus','resolve','then','actionSipShowRegistry','catch','error','[userReport][sipshowregistry]','inspect','actionDeviceStateList','[userReport][devicestatelist]','actionSipPeerStatus','prototype','syncRealtimeShow','isNotNull','emit','info','[userReport][registry]\x20registry:%s\x20state:%s','username','state','debug','stateRegistry','merge','omit','event','actionid','[userReport][registry]\x20sending\x20trunk:save\x20event:','format','name','trunk:save','[userReport][registry]','[userReport][devicestatechange]\x20device:%s\x20state:%s','device','[userReport][devicestatechange]','toLowerCase','inuse','stateTime','[userReport][devicestatechange]\x20sending\x20telephone:save\x20event:','telephone:save','toNumber','trunk:%s','startsWith','Local','substring','indexOf','mobile','accountcode','local','updateStatusRealtime','[userReport][peerstatus]\x20peer:%s\x20address:%s\x20status:%s','peer','address','[userReport][peerstatus]','registered','status','telephone:%s','[userReport][peerstatus]\x20sending\x20trunk:save\x20event:','exports','lodash','moment','util','ioredis','bluebird','../../../config/environment','../../../config/logger','ami','../ami','localhost','socket.io-emitter','trunks','agents','telephones'];(function(_0x4cf98e,_0xba4b79){var _0x1623ac=function(_0x459bc0){while(--_0x459bc0){_0x4cf98e['push'](_0x4cf98e['shift']());}};_0x1623ac(++_0xba4b79);}(_0x0170,0x173));var _0x0017=function(_0x139fb0,_0x3b2293){_0x139fb0=_0x139fb0-0x0;var _0x58a9b7=_0x0170[_0x139fb0];return _0x58a9b7;};'use strict';var _=require(_0x0017('0x0'));var moment=require(_0x0017('0x1'));var util=require(_0x0017('0x2'));var Redis=require(_0x0017('0x3'));var BPromise=require(_0x0017('0x4'));var config=require(_0x0017('0x5'));var logger=require(_0x0017('0x6'))(_0x0017('0x7'));var ami=require(_0x0017('0x8'));config['redis']=_['defaults'](config['redis'],{'host':_0x0017('0x9'),'port':0x18eb});var io=require(_0x0017('0xa'))(new Redis(config['redis']));function UserReport(_0x5eba05){this[_0x0017('0xb')]=_0x5eba05[_0x0017('0xb')];this['agents']=_0x5eba05[_0x0017('0xc')];this[_0x0017('0xd')]=_0x5eba05[_0x0017('0xd')];ami['on'](_0x0017('0xe'),this[_0x0017('0xf')][_0x0017('0x10')](this));ami['on'](_0x0017('0x11'),this[_0x0017('0xf')]['bind'](this));ami['on'](_0x0017('0x12'),this[_0x0017('0x13')][_0x0017('0x10')](this));ami['on'](_0x0017('0x14'),this['syncPeerStatus'][_0x0017('0x10')](this));return this['syncRealtimeShow']();}function showSipRegistrations(){Promise[_0x0017('0x15')]()[_0x0017('0x16')](ami[_0x0017('0x17')]())[_0x0017('0x18')](function(_0xe47815){logger[_0x0017('0x19')](_0x0017('0x1a'),util[_0x0017('0x1b')](_0xe47815,{'showHidden':![],'depth':null}));});}function listDeviceStates(){Promise[_0x0017('0x15')]()['then'](ami[_0x0017('0x1c')]())[_0x0017('0x18')](function(_0x3bfdba){logger[_0x0017('0x19')](_0x0017('0x1d'),util[_0x0017('0x1b')](_0x3bfdba,{'showHidden':![],'depth':null}));});}function showPeersStatus(){Promise[_0x0017('0x15')]()['then'](ami[_0x0017('0x1e')]())[_0x0017('0x18')](function(_0x8fbaec){logger[_0x0017('0x19')]('[userReport][sippeerstatus]',util[_0x0017('0x1b')](_0x8fbaec,{'showHidden':![],'depth':null}));});}UserReport[_0x0017('0x1f')][_0x0017('0x20')]=function(){setInterval(function(){BPromise[_0x0017('0x15')]()[_0x0017('0x16')](showSipRegistrations())[_0x0017('0x16')](listDeviceStates())[_0x0017('0x16')](showPeersStatus());},0x32c8);};UserReport[_0x0017('0x1f')][_0x0017('0x21')]=function(_0x40548d){return _0x40548d!==null&&!_['isUndefined'](_0x40548d);};UserReport[_0x0017('0x1f')][_0x0017('0x22')]=function(_0x3b48aa,_0x1b0032,_0x214196){io['to'](_0x3b48aa)[_0x0017('0x22')](_0x1b0032,_0x214196);};UserReport[_0x0017('0x1f')]['syncRegistry']=function(_0x158019){try{if(this[_0x0017('0x21')](_0x158019)){logger[_0x0017('0x23')](_0x0017('0x24'),_0x158019[_0x0017('0x25')],_0x158019[_0x0017('0x26')]);logger[_0x0017('0x27')]('[userReport][registry]',util[_0x0017('0x1b')](_0x158019,{'showHidden':![],'depth':null}));var _0x5e4b9a=_['find'](this[_0x0017('0xb')],{'defaultuser':_0x158019['username']});if(_0x5e4b9a){_0x158019[_0x0017('0x28')]=_0x158019[_0x0017('0x26')];_[_0x0017('0x29')](_0x5e4b9a,_[_0x0017('0x2a')](_0x158019,[_0x0017('0x2b'),_0x0017('0x2c'),_0x0017('0x25'),_0x0017('0x26')]));logger[_0x0017('0x27')](_0x0017('0x2d'),util[_0x0017('0x1b')](_0x5e4b9a,{'showHidden':![],'depth':null}));this[_0x0017('0x22')](util[_0x0017('0x2e')]('trunk:%s',_0x5e4b9a[_0x0017('0x2f')]),_0x0017('0x30'),_0x5e4b9a);}}}catch(_0x29ab5f){logger[_0x0017('0x19')](_0x0017('0x31'),util[_0x0017('0x1b')](_0x29ab5f,{'showHidden':![],'depth':null}));}};UserReport['prototype']['syncDeviceState']=function(_0x54027f){try{if(this[_0x0017('0x21')](_0x54027f)){logger[_0x0017('0x23')](_0x0017('0x32'),_0x54027f[_0x0017('0x33')],_0x54027f[_0x0017('0x26')]);logger[_0x0017('0x27')](_0x0017('0x34'),util[_0x0017('0x1b')](_0x54027f,{'showHidden':![],'depth':null}));if(this[_0x0017('0xc')][_0x54027f[_0x0017('0x33')]]){if(!this[_0x0017('0xc')][_0x54027f[_0x0017('0x33')]]['local']||_0x54027f[_0x0017('0x26')][_0x0017('0x35')]()==_0x0017('0x36')){this[_0x0017('0xc')][_0x54027f[_0x0017('0x33')]]['local']=![];if(this[_0x0017('0xc')][_0x54027f[_0x0017('0x33')]][_0x0017('0x26')]!==_0x54027f[_0x0017('0x26')][_0x0017('0x35')]()){this['agents'][_0x54027f[_0x0017('0x33')]][_0x0017('0x37')]=_['toNumber'](moment()[_0x0017('0x2e')]('x'));}this[_0x0017('0xc')][_0x54027f[_0x0017('0x33')]][_0x0017('0x26')]=_0x54027f[_0x0017('0x26')][_0x0017('0x35')]();this[_0x0017('0xc')][_0x54027f['device']]['updateStatusRealtime'](_0x54027f);}}else if(this['telephones'][_0x54027f[_0x0017('0x33')]]){if(this[_0x0017('0xd')][_0x54027f['device']][_0x0017('0x26')]!==_0x54027f[_0x0017('0x26')]['toLowerCase']()){this[_0x0017('0xd')][_0x54027f['device']][_0x0017('0x37')]=_['toNumber'](moment()['format']('x'));}this[_0x0017('0xd')][_0x54027f[_0x0017('0x33')]]['state']=_0x54027f['state'][_0x0017('0x35')]();logger[_0x0017('0x27')](_0x0017('0x38'),util[_0x0017('0x1b')](this[_0x0017('0xd')][_0x54027f['device']],{'showHidden':![],'depth':null}));this[_0x0017('0x22')](util[_0x0017('0x2e')]('telephone:%s',this[_0x0017('0xd')][_0x54027f[_0x0017('0x33')]]['name']),_0x0017('0x39'),this[_0x0017('0xd')][_0x54027f[_0x0017('0x33')]]);}else if(this[_0x0017('0xb')][_0x54027f[_0x0017('0x33')]]){if(this['trunks'][_0x54027f[_0x0017('0x33')]]['state']!==_0x54027f[_0x0017('0x26')][_0x0017('0x35')]()){this[_0x0017('0xb')][_0x54027f[_0x0017('0x33')]][_0x0017('0x37')]=_[_0x0017('0x3a')](moment()[_0x0017('0x2e')]('x'));}this[_0x0017('0xb')][_0x54027f[_0x0017('0x33')]][_0x0017('0x26')]=_0x54027f['state'][_0x0017('0x35')]();logger[_0x0017('0x27')]('[userReport][devicestatechange]\x20sending\x20trunk:save\x20event:',util['inspect'](this['trunks'][_0x54027f[_0x0017('0x33')]],{'showHidden':![],'depth':null}));this[_0x0017('0x22')](util[_0x0017('0x2e')](_0x0017('0x3b'),this['trunks'][_0x54027f[_0x0017('0x33')]][_0x0017('0x2f')]),'trunk:save',this[_0x0017('0xb')][_0x54027f[_0x0017('0x33')]]);}else if(_[_0x0017('0x3c')](_0x54027f[_0x0017('0x33')],_0x0017('0x3d'))){var _0x327bdf=_0x54027f[_0x0017('0x33')];var _0x26e765=_0x327bdf[_0x0017('0x3e')](_0x327bdf['indexOf']('/')+0x1,_0x327bdf[_0x0017('0x3f')]('@'));var _0x4025a2=_['find'](this[_0x0017('0xc')],function(_0x4ad773){return _0x4ad773[_0x0017('0x40')]==_0x26e765||_0x4ad773['phone']==_0x26e765||_0x4ad773[_0x0017('0x41')]==_0x26e765;});if(_0x4025a2){if(_0x4025a2['state']!==_0x54027f[_0x0017('0x26')][_0x0017('0x35')]()){_0x4025a2[_0x0017('0x37')]=_[_0x0017('0x3a')](moment()[_0x0017('0x2e')]('x'));}_0x4025a2[_0x0017('0x26')]=_0x54027f[_0x0017('0x26')][_0x0017('0x35')]();_0x4025a2[_0x0017('0x42')]=!![];_0x4025a2[_0x0017('0x43')](_0x54027f);}}}}catch(_0x24b996){logger[_0x0017('0x19')](_0x0017('0x34'),util['inspect'](_0x24b996,{'showHidden':![],'depth':null}));}};UserReport[_0x0017('0x1f')]['syncPeerStatus']=function(_0x533631){try{if(this[_0x0017('0x21')](_0x533631)&&this[_0x0017('0x21')](_0x533631[_0x0017('0x14')])){logger[_0x0017('0x23')](_0x0017('0x44'),_0x533631[_0x0017('0x45')],_0x533631[_0x0017('0x46')],_0x533631[_0x0017('0x14')]);logger['debug'](_0x0017('0x47'),util[_0x0017('0x1b')](_0x533631,{'showHidden':![],'depth':null}));if(this[_0x0017('0xc')][_0x533631[_0x0017('0x45')]]){if(!this[_0x0017('0xc')][_0x533631[_0x0017('0x45')]][_0x0017('0x42')]||_0x533631['peerstatus'][_0x0017('0x35')]()==_0x0017('0x48')){this[_0x0017('0xc')][_0x533631[_0x0017('0x45')]]['local']=![];this[_0x0017('0xc')][_0x533631['peer']]['status']=_0x533631[_0x0017('0x14')][_0x0017('0x35')]();this[_0x0017('0xc')][_0x533631[_0x0017('0x45')]][_0x0017('0x46')]=_0x533631[_0x0017('0x46')];this[_0x0017('0xc')][_0x533631[_0x0017('0x45')]][_0x0017('0x43')](_0x533631);}}else if(this[_0x0017('0xd')][_0x533631[_0x0017('0x45')]]){this['telephones'][_0x533631[_0x0017('0x45')]][_0x0017('0x49')]=_0x533631[_0x0017('0x14')][_0x0017('0x35')]();this[_0x0017('0xd')][_0x533631[_0x0017('0x45')]][_0x0017('0x46')]=_0x533631[_0x0017('0x46')];logger[_0x0017('0x27')]('[userReport][peerstatus]\x20sending\x20telephone:save\x20event:',util['inspect'](this[_0x0017('0xd')][_0x533631[_0x0017('0x45')]],{'showHidden':![],'depth':null}));this['emit'](util['format'](_0x0017('0x4a'),this[_0x0017('0xd')][_0x533631['peer']][_0x0017('0x2f')]),'telephone:save',this['telephones'][_0x533631[_0x0017('0x45')]]);}else if(this['trunks'][_0x533631[_0x0017('0x45')]]){this[_0x0017('0xb')][_0x533631['peer']]['status']=_0x533631[_0x0017('0x14')][_0x0017('0x35')]();this[_0x0017('0xb')][_0x533631[_0x0017('0x45')]][_0x0017('0x46')]=_0x533631[_0x0017('0x46')];logger[_0x0017('0x27')](_0x0017('0x4b'),util[_0x0017('0x1b')](this[_0x0017('0xb')][_0x533631[_0x0017('0x45')]],{'showHidden':![],'depth':null}));this[_0x0017('0x22')](util['format']('trunk:%s',this[_0x0017('0xb')][_0x533631[_0x0017('0x45')]][_0x0017('0x2f')]),_0x0017('0x30'),this[_0x0017('0xb')][_0x533631['peer']]);}}}catch(_0x131c2d){logger[_0x0017('0x19')](_0x0017('0x47'),util['inspect'](_0x131c2d,{'showHidden':![],'depth':null}));}};module[_0x0017('0x4c')]=UserReport;