Built motion from commit (unavailable).|2.5.4
[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 _0x5bd1=['registryentry','syncRegistry','bind','registry','peerstatus','syncPeerStatus','loopSyncRealTimeShow','resolve','actionSipShowRegistry','actionDeviceStateList','then','catch','[loopSyncRealTimeShow]','inspect','prototype','isNotNull','emit','username','stateRegistry','state','merge','actionid','format','trunk:%s','error','[syncRegistry][UserReport]','syncDeviceState','device','local','toLowerCase','inuse','stateTime','toNumber','telephone:%s','name','trunk:save','startsWith','Queue','Local','substring','indexOf','find','phone','accountcode','[syncDeviceState][UserReport]','peer','registered','status','address','updateStatusRealtime','lodash','moment','bluebird','util','ioredis','../../../config/environment','../../../config/logger','ami','../ami','defaults','socket.io-emitter','trunks','agents','telephones'];(function(_0x2658c5,_0x21732f){var _0x51c2e2=function(_0x2f0d36){while(--_0x2f0d36){_0x2658c5['push'](_0x2658c5['shift']());}};_0x51c2e2(++_0x21732f);}(_0x5bd1,0x1f2));var _0x15bd=function(_0x725a4c,_0x102507){_0x725a4c=_0x725a4c-0x0;var _0x37b2cc=_0x5bd1[_0x725a4c];return _0x37b2cc;};'use strict';var _=require(_0x15bd('0x0'));var moment=require(_0x15bd('0x1'));var BPromise=require(_0x15bd('0x2'));var util=require(_0x15bd('0x3'));var Redis=require(_0x15bd('0x4'));var config=require(_0x15bd('0x5'));var logger=require(_0x15bd('0x6'))(_0x15bd('0x7'));var ami=require(_0x15bd('0x8'));config['redis']=_[_0x15bd('0x9')](config['redis'],{'host':'localhost','port':0x18eb});var io=require(_0x15bd('0xa'))(new Redis(config['redis']));function UserReport(_0x58ac27){this['trunks']=_0x58ac27[_0x15bd('0xb')];this[_0x15bd('0xc')]=_0x58ac27['agents'];this[_0x15bd('0xd')]=_0x58ac27[_0x15bd('0xd')];ami['on'](_0x15bd('0xe'),this[_0x15bd('0xf')][_0x15bd('0x10')](this));ami['on'](_0x15bd('0x11'),this['syncRegistry'][_0x15bd('0x10')](this));ami['on']('devicestatechange',this['syncDeviceState'][_0x15bd('0x10')](this));ami['on'](_0x15bd('0x12'),this[_0x15bd('0x13')][_0x15bd('0x10')](this));this[_0x15bd('0x14')]();return BPromise[_0x15bd('0x15')]()['then'](ami[_0x15bd('0x16')]())['then'](ami[_0x15bd('0x17')]())[_0x15bd('0x18')](ami['actionSipPeerStatus']())[_0x15bd('0x19')](loggerCatch(_0x15bd('0x1a')));}function loggerCatch(_0x215b78){return function(_0x21dc66){logger['error'](_0x215b78,util[_0x15bd('0x1b')](_0x21dc66,{'showHidden':![],'depth':null}));};}UserReport[_0x15bd('0x1c')][_0x15bd('0x14')]=function(){setInterval(function(){BPromise['resolve']()[_0x15bd('0x18')](ami[_0x15bd('0x16')]())[_0x15bd('0x18')](ami[_0x15bd('0x17')]())[_0x15bd('0x18')](ami['actionSipPeerStatus']())[_0x15bd('0x19')](loggerCatch(_0x15bd('0x1a')));},0x32c8);};UserReport[_0x15bd('0x1c')][_0x15bd('0x1d')]=function(_0x296032){return _0x296032!==null&&!_['isUndefined'](_0x296032);};UserReport[_0x15bd('0x1c')][_0x15bd('0x1e')]=function(_0x301560,_0x7999c6,_0x32ce21){io['to'](_0x301560)[_0x15bd('0x1e')](_0x7999c6,_0x32ce21);};UserReport[_0x15bd('0x1c')][_0x15bd('0xf')]=function(_0x3a55f9){try{if(this['isNotNull'](_0x3a55f9)){var _0x5831af=_['find'](this[_0x15bd('0xb')],{'registry':_0x3a55f9[_0x15bd('0x1f')]});if(_0x5831af){_0x3a55f9[_0x15bd('0x20')]=_0x3a55f9[_0x15bd('0x21')];_[_0x15bd('0x22')](_0x5831af,_['omit'](_0x3a55f9,['event',_0x15bd('0x23'),_0x15bd('0x1f'),_0x15bd('0x21')]));this[_0x15bd('0x1e')](util[_0x15bd('0x24')](_0x15bd('0x25'),_0x5831af['name']),'trunk:save',_0x5831af);}}}catch(_0xaf73f6){logger[_0x15bd('0x26')](_0x15bd('0x27'),util[_0x15bd('0x1b')](_0xaf73f6,{'showHidden':![],'depth':null}));}};UserReport[_0x15bd('0x1c')][_0x15bd('0x28')]=function(_0x3e0b1a){try{if(this[_0x15bd('0x1d')](_0x3e0b1a)){if(this['agents'][_0x3e0b1a[_0x15bd('0x29')]]){if(!this['agents'][_0x3e0b1a[_0x15bd('0x29')]][_0x15bd('0x2a')]||_0x3e0b1a[_0x15bd('0x21')][_0x15bd('0x2b')]()==_0x15bd('0x2c')){this['agents'][_0x3e0b1a['device']][_0x15bd('0x2a')]=![];if(this[_0x15bd('0xc')][_0x3e0b1a['device']][_0x15bd('0x21')]!==_0x3e0b1a[_0x15bd('0x21')][_0x15bd('0x2b')]()){this[_0x15bd('0xc')][_0x3e0b1a[_0x15bd('0x29')]][_0x15bd('0x2d')]=_[_0x15bd('0x2e')](moment()[_0x15bd('0x24')]('x'));}this['agents'][_0x3e0b1a['device']]['state']=_0x3e0b1a['state'][_0x15bd('0x2b')]();this[_0x15bd('0xc')][_0x3e0b1a[_0x15bd('0x29')]]['updateStatusRealtime'](_0x3e0b1a);}}else if(this[_0x15bd('0xd')][_0x3e0b1a['device']]){if(this[_0x15bd('0xd')][_0x3e0b1a['device']][_0x15bd('0x21')]!==_0x3e0b1a[_0x15bd('0x21')][_0x15bd('0x2b')]()){this[_0x15bd('0xd')][_0x3e0b1a[_0x15bd('0x29')]][_0x15bd('0x2d')]=_[_0x15bd('0x2e')](moment()[_0x15bd('0x24')]('x'));}this[_0x15bd('0xd')][_0x3e0b1a['device']][_0x15bd('0x21')]=_0x3e0b1a[_0x15bd('0x21')][_0x15bd('0x2b')]();this[_0x15bd('0x1e')](util[_0x15bd('0x24')](_0x15bd('0x2f'),this[_0x15bd('0xd')][_0x3e0b1a[_0x15bd('0x29')]][_0x15bd('0x30')]),'telephone:save',this['telephones'][_0x3e0b1a['device']]);}else if(this[_0x15bd('0xb')][_0x3e0b1a['device']]){if(this[_0x15bd('0xb')][_0x3e0b1a[_0x15bd('0x29')]][_0x15bd('0x21')]!==_0x3e0b1a[_0x15bd('0x21')][_0x15bd('0x2b')]()){this[_0x15bd('0xb')][_0x3e0b1a[_0x15bd('0x29')]]['stateTime']=_[_0x15bd('0x2e')](moment()['format']('x'));}this[_0x15bd('0xb')][_0x3e0b1a['device']][_0x15bd('0x21')]=_0x3e0b1a[_0x15bd('0x21')][_0x15bd('0x2b')]();this[_0x15bd('0x1e')](util[_0x15bd('0x24')](_0x15bd('0x25'),this[_0x15bd('0xb')][_0x3e0b1a[_0x15bd('0x29')]][_0x15bd('0x30')]),_0x15bd('0x31'),this['trunks'][_0x3e0b1a['device']]);}else if(_[_0x15bd('0x32')](_0x3e0b1a[_0x15bd('0x29')],_0x15bd('0x33'))){}else if(_[_0x15bd('0x32')](_0x3e0b1a[_0x15bd('0x29')],_0x15bd('0x34'))){var _0x3cf1f2=_0x3e0b1a[_0x15bd('0x29')];var _0x2a0a92=_0x3cf1f2[_0x15bd('0x35')](_0x3cf1f2[_0x15bd('0x36')]('/')+0x1,_0x3cf1f2[_0x15bd('0x36')]('@'));var _0x40e0d9=_[_0x15bd('0x37')](this['agents'],function(_0x2acf2c){return _0x2acf2c['mobile']==_0x2a0a92||_0x2acf2c[_0x15bd('0x38')]==_0x2a0a92||_0x2acf2c[_0x15bd('0x39')]==_0x2a0a92;});if(_0x40e0d9){if(_0x40e0d9['state']!==_0x3e0b1a[_0x15bd('0x21')]['toLowerCase']()){_0x40e0d9[_0x15bd('0x2d')]=_['toNumber'](moment()[_0x15bd('0x24')]('x'));}_0x40e0d9[_0x15bd('0x21')]=_0x3e0b1a[_0x15bd('0x21')][_0x15bd('0x2b')]();_0x40e0d9['local']=!![];_0x40e0d9['updateStatusRealtime'](_0x3e0b1a);}}else{}}}catch(_0x1008cd){logger['error'](_0x15bd('0x3a'),util[_0x15bd('0x1b')](_0x1008cd,{'showHidden':![],'depth':null}));}};UserReport[_0x15bd('0x1c')][_0x15bd('0x13')]=function(_0x218b87){try{if(this['isNotNull'](_0x218b87)&&this['isNotNull'](_0x218b87[_0x15bd('0x12')])){if(this[_0x15bd('0xc')][_0x218b87['peer']]){if(!this['agents'][_0x218b87[_0x15bd('0x3b')]]['local']||_0x218b87['peerstatus']['toLowerCase']()==_0x15bd('0x3c')){this[_0x15bd('0xc')][_0x218b87['peer']]['local']=![];this[_0x15bd('0xc')][_0x218b87[_0x15bd('0x3b')]][_0x15bd('0x3d')]=_0x218b87[_0x15bd('0x12')]['toLowerCase']();this[_0x15bd('0xc')][_0x218b87[_0x15bd('0x3b')]][_0x15bd('0x3e')]=_0x218b87[_0x15bd('0x3e')];this['agents'][_0x218b87[_0x15bd('0x3b')]][_0x15bd('0x3f')](_0x218b87);}}else if(this[_0x15bd('0xd')][_0x218b87[_0x15bd('0x3b')]]){this[_0x15bd('0xd')][_0x218b87['peer']]['status']=_0x218b87[_0x15bd('0x12')][_0x15bd('0x2b')]();this['telephones'][_0x218b87[_0x15bd('0x3b')]][_0x15bd('0x3e')]=_0x218b87[_0x15bd('0x3e')];this[_0x15bd('0x1e')](util[_0x15bd('0x24')](_0x15bd('0x2f'),this['telephones'][_0x218b87[_0x15bd('0x3b')]][_0x15bd('0x30')]),'telephone:save',this[_0x15bd('0xd')][_0x218b87[_0x15bd('0x3b')]]);}else if(this[_0x15bd('0xb')][_0x218b87[_0x15bd('0x3b')]]){this[_0x15bd('0xb')][_0x218b87[_0x15bd('0x3b')]][_0x15bd('0x3d')]=_0x218b87['peerstatus'][_0x15bd('0x2b')]();this['trunks'][_0x218b87[_0x15bd('0x3b')]][_0x15bd('0x3e')]=_0x218b87['address'];this['emit'](util['format'](_0x15bd('0x25'),this[_0x15bd('0xb')][_0x218b87[_0x15bd('0x3b')]][_0x15bd('0x30')]),'trunk:save',this[_0x15bd('0xb')][_0x218b87[_0x15bd('0x3b')]]);}else{}}}catch(_0x2a4eb7){logger[_0x15bd('0x26')]('[syncPeerStatus][UserReport]',util[_0x15bd('0x1b')](_0x2a4eb7,{'showHidden':![],'depth':null}));}};module['exports']=UserReport;