Built motion from commit (unavailable).|2.4.3
[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 _0x7de9=['Queue','substring','indexOf','mobile','phone','accountcode','peer','address','status','exports','lodash','util','../../../config/environment','../../../config/logger','ami','../ami','redis','trunks','agents','registryentry','syncRegistry','registry','bind','devicestatechange','syncDeviceState','peerstatus','syncPeerStatus','loopSyncRealTimeShow','resolve','then','actionSipShowRegistry','actionDeviceStateList','actionSipPeerStatus','catch','[loopSyncRealTimeShow]','error','inspect','prototype','isNotNull','emit','find','username','stateRegistry','omit','event','trunk:%s','[syncRegistry][UserReport]','device','local','state','inuse','toLowerCase','stateTime','format','updateStatusRealtime','telephones','toNumber','telephone:%s','telephone:save','name','trunk:save','startsWith'];(function(_0x4cc17e,_0xbff357){var _0x4ee2e9=function(_0x3633d8){while(--_0x3633d8){_0x4cc17e['push'](_0x4cc17e['shift']());}};_0x4ee2e9(++_0xbff357);}(_0x7de9,0x86));var _0x97de=function(_0x556bb1,_0x34830d){_0x556bb1=_0x556bb1-0x0;var _0x45455f=_0x7de9[_0x556bb1];return _0x45455f;};'use strict';var _=require(_0x97de('0x0'));var moment=require('moment');var BPromise=require('bluebird');var util=require(_0x97de('0x1'));var Redis=require('ioredis');var config=require(_0x97de('0x2'));var logger=require(_0x97de('0x3'))(_0x97de('0x4'));var ami=require(_0x97de('0x5'));config['redis']=_['defaults'](config[_0x97de('0x6')],{'host':'localhost','port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x97de('0x6')]));function UserReport(_0x3aaf75){this['trunks']=_0x3aaf75[_0x97de('0x7')];this[_0x97de('0x8')]=_0x3aaf75[_0x97de('0x8')];this['telephones']=_0x3aaf75['telephones'];ami['on'](_0x97de('0x9'),this[_0x97de('0xa')]['bind'](this));ami['on'](_0x97de('0xb'),this[_0x97de('0xa')][_0x97de('0xc')](this));ami['on'](_0x97de('0xd'),this[_0x97de('0xe')]['bind'](this));ami['on'](_0x97de('0xf'),this[_0x97de('0x10')][_0x97de('0xc')](this));this[_0x97de('0x11')]();return BPromise[_0x97de('0x12')]()[_0x97de('0x13')](ami[_0x97de('0x14')]())[_0x97de('0x13')](ami[_0x97de('0x15')]())[_0x97de('0x13')](ami[_0x97de('0x16')]())[_0x97de('0x17')](loggerCatch(_0x97de('0x18')));}function loggerCatch(_0x5e1cb5){return function(_0x3fd98a){logger[_0x97de('0x19')](_0x5e1cb5,util[_0x97de('0x1a')](_0x3fd98a,{'showHidden':![],'depth':null}));};}UserReport[_0x97de('0x1b')][_0x97de('0x11')]=function(){setInterval(function(){BPromise[_0x97de('0x12')]()[_0x97de('0x13')](ami['actionSipShowRegistry']())[_0x97de('0x13')](ami['actionDeviceStateList']())[_0x97de('0x13')](ami['actionSipPeerStatus']())[_0x97de('0x17')](loggerCatch('[loopSyncRealTimeShow]'));},0x32c8);};UserReport[_0x97de('0x1b')][_0x97de('0x1c')]=function(_0x3e8fe0){return _0x3e8fe0!==null&&!_['isUndefined'](_0x3e8fe0);};UserReport[_0x97de('0x1b')]['emit']=function(_0x117db6,_0x23f5a8,_0x3de779){io['to'](_0x117db6)[_0x97de('0x1d')](_0x23f5a8,_0x3de779);};UserReport[_0x97de('0x1b')][_0x97de('0xa')]=function(_0x2c87ae){try{if(this[_0x97de('0x1c')](_0x2c87ae)){var _0x518859=_[_0x97de('0x1e')](this[_0x97de('0x7')],{'registry':_0x2c87ae[_0x97de('0x1f')]});if(_0x518859){_0x2c87ae[_0x97de('0x20')]=_0x2c87ae['state'];_['merge'](_0x518859,_[_0x97de('0x21')](_0x2c87ae,[_0x97de('0x22'),'actionid',_0x97de('0x1f'),'state']));this[_0x97de('0x1d')](util['format'](_0x97de('0x23'),_0x518859['name']),'trunk:save',_0x518859);}}}catch(_0x1f0fa8){logger[_0x97de('0x19')](_0x97de('0x24'),util['inspect'](_0x1f0fa8,{'showHidden':![],'depth':null}));}};UserReport[_0x97de('0x1b')][_0x97de('0xe')]=function(_0x4c6812){try{if(this[_0x97de('0x1c')](_0x4c6812)){if(this[_0x97de('0x8')][_0x4c6812[_0x97de('0x25')]]){if(!this[_0x97de('0x8')][_0x4c6812['device']][_0x97de('0x26')]||_0x4c6812[_0x97de('0x27')]['toLowerCase']()==_0x97de('0x28')){this[_0x97de('0x8')][_0x4c6812['device']][_0x97de('0x26')]=![];if(this['agents'][_0x4c6812[_0x97de('0x25')]]['state']!==_0x4c6812[_0x97de('0x27')][_0x97de('0x29')]()){this['agents'][_0x4c6812['device']][_0x97de('0x2a')]=_['toNumber'](moment()[_0x97de('0x2b')]('x'));}this[_0x97de('0x8')][_0x4c6812['device']][_0x97de('0x27')]=_0x4c6812[_0x97de('0x27')]['toLowerCase']();this[_0x97de('0x8')][_0x4c6812[_0x97de('0x25')]][_0x97de('0x2c')](_0x4c6812);}}else if(this[_0x97de('0x2d')][_0x4c6812[_0x97de('0x25')]]){if(this[_0x97de('0x2d')][_0x4c6812[_0x97de('0x25')]][_0x97de('0x27')]!==_0x4c6812[_0x97de('0x27')][_0x97de('0x29')]()){this[_0x97de('0x2d')][_0x4c6812['device']]['stateTime']=_[_0x97de('0x2e')](moment()[_0x97de('0x2b')]('x'));}this['telephones'][_0x4c6812[_0x97de('0x25')]][_0x97de('0x27')]=_0x4c6812[_0x97de('0x27')][_0x97de('0x29')]();this['emit'](util[_0x97de('0x2b')](_0x97de('0x2f'),this[_0x97de('0x2d')][_0x4c6812[_0x97de('0x25')]]['name']),_0x97de('0x30'),this[_0x97de('0x2d')][_0x4c6812[_0x97de('0x25')]]);}else if(this[_0x97de('0x7')][_0x4c6812[_0x97de('0x25')]]){if(this[_0x97de('0x7')][_0x4c6812[_0x97de('0x25')]][_0x97de('0x27')]!==_0x4c6812[_0x97de('0x27')][_0x97de('0x29')]()){this[_0x97de('0x7')][_0x4c6812['device']][_0x97de('0x2a')]=_['toNumber'](moment()['format']('x'));}this[_0x97de('0x7')][_0x4c6812[_0x97de('0x25')]]['state']=_0x4c6812[_0x97de('0x27')][_0x97de('0x29')]();this[_0x97de('0x1d')](util['format']('trunk:%s',this[_0x97de('0x7')][_0x4c6812[_0x97de('0x25')]][_0x97de('0x31')]),_0x97de('0x32'),this[_0x97de('0x7')][_0x4c6812[_0x97de('0x25')]]);}else if(_[_0x97de('0x33')](_0x4c6812[_0x97de('0x25')],_0x97de('0x34'))){}else if(_[_0x97de('0x33')](_0x4c6812['device'],'Local')){var _0x3b69a4=_0x4c6812[_0x97de('0x25')];var _0x14548f=_0x3b69a4[_0x97de('0x35')](_0x3b69a4[_0x97de('0x36')]('/')+0x1,_0x3b69a4[_0x97de('0x36')]('@'));var _0x306388=_['find'](this[_0x97de('0x8')],function(_0x1e7132){return _0x1e7132[_0x97de('0x37')]==_0x14548f||_0x1e7132[_0x97de('0x38')]==_0x14548f||_0x1e7132[_0x97de('0x39')]==_0x14548f;});if(_0x306388){if(_0x306388[_0x97de('0x27')]!==_0x4c6812['state']['toLowerCase']()){_0x306388[_0x97de('0x2a')]=_[_0x97de('0x2e')](moment()[_0x97de('0x2b')]('x'));}_0x306388['state']=_0x4c6812[_0x97de('0x27')][_0x97de('0x29')]();_0x306388['local']=!![];_0x306388[_0x97de('0x2c')](_0x4c6812);}}else{}}}catch(_0x4b4817){logger[_0x97de('0x19')]('[syncDeviceState][UserReport]',util[_0x97de('0x1a')](_0x4b4817,{'showHidden':![],'depth':null}));}};UserReport['prototype'][_0x97de('0x10')]=function(_0x4931c9){try{if(this[_0x97de('0x1c')](_0x4931c9)&&this[_0x97de('0x1c')](_0x4931c9[_0x97de('0xf')])){if(this[_0x97de('0x8')][_0x4931c9[_0x97de('0x3a')]]){if(!this[_0x97de('0x8')][_0x4931c9[_0x97de('0x3a')]][_0x97de('0x26')]||_0x4931c9[_0x97de('0xf')][_0x97de('0x29')]()=='registered'){this[_0x97de('0x8')][_0x4931c9[_0x97de('0x3a')]]['local']=![];this[_0x97de('0x8')][_0x4931c9[_0x97de('0x3a')]]['status']=_0x4931c9[_0x97de('0xf')][_0x97de('0x29')]();this['agents'][_0x4931c9[_0x97de('0x3a')]]['address']=_0x4931c9[_0x97de('0x3b')];this[_0x97de('0x8')][_0x4931c9[_0x97de('0x3a')]][_0x97de('0x2c')](_0x4931c9);}}else if(this['telephones'][_0x4931c9[_0x97de('0x3a')]]){this[_0x97de('0x2d')][_0x4931c9[_0x97de('0x3a')]][_0x97de('0x3c')]=_0x4931c9[_0x97de('0xf')][_0x97de('0x29')]();this[_0x97de('0x2d')][_0x4931c9['peer']][_0x97de('0x3b')]=_0x4931c9[_0x97de('0x3b')];this[_0x97de('0x1d')](util[_0x97de('0x2b')](_0x97de('0x2f'),this[_0x97de('0x2d')][_0x4931c9[_0x97de('0x3a')]]['name']),_0x97de('0x30'),this['telephones'][_0x4931c9[_0x97de('0x3a')]]);}else if(this[_0x97de('0x7')][_0x4931c9[_0x97de('0x3a')]]){this[_0x97de('0x7')][_0x4931c9[_0x97de('0x3a')]]['status']=_0x4931c9[_0x97de('0xf')][_0x97de('0x29')]();this[_0x97de('0x7')][_0x4931c9[_0x97de('0x3a')]]['address']=_0x4931c9['address'];this['emit'](util[_0x97de('0x2b')](_0x97de('0x23'),this[_0x97de('0x7')][_0x4931c9[_0x97de('0x3a')]][_0x97de('0x31')]),_0x97de('0x32'),this[_0x97de('0x7')][_0x4931c9['peer']]);}else{}}}catch(_0x4f05e3){logger['error']('[syncPeerStatus][UserReport]',util[_0x97de('0x1a')](_0x4f05e3,{'showHidden':![],'depth':null}));}};module[_0x97de('0x3d')]=UserReport;