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 _0x4a51=['catch','[loopSyncRealTimeShow]','error','inspect','prototype','isUndefined','emit','isNotNull','find','username','state','merge','omit','event','format','[syncRegistry][UserReport]','device','local','inuse','toLowerCase','stateTime','updateStatusRealtime','toNumber','telephone:%s','telephone:save','trunk:%s','name','startsWith','Queue','Local','substring','indexOf','phone','[syncDeviceState][UserReport]','peerstatus','peer','address','status','trunk:save','[syncPeerStatus][UserReport]','exports','lodash','moment','ioredis','../../../config/logger','ami','redis','localhost','trunks','agents','telephones','syncRegistry','bind','devicestatechange','syncDeviceState','syncPeerStatus','loopSyncRealTimeShow','resolve','actionSipShowRegistry','then','actionDeviceStateList','actionSipPeerStatus'];(function(_0x2b044e,_0x31fe2c){var _0x3b9a84=function(_0x775ea0){while(--_0x775ea0){_0x2b044e['push'](_0x2b044e['shift']());}};_0x3b9a84(++_0x31fe2c);}(_0x4a51,0x19d));var _0x14a5=function(_0x279d37,_0x14de3f){_0x279d37=_0x279d37-0x0;var _0x530173=_0x4a51[_0x279d37];return _0x530173;};'use strict';var _=require(_0x14a5('0x0'));var moment=require(_0x14a5('0x1'));var BPromise=require('bluebird');var util=require('util');var Redis=require(_0x14a5('0x2'));var config=require('../../../config/environment');var logger=require(_0x14a5('0x3'))(_0x14a5('0x4'));var ami=require('../ami');config[_0x14a5('0x5')]=_['defaults'](config['redis'],{'host':_0x14a5('0x6'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x14a5('0x5')]));function UserReport(_0x303f39){this['trunks']=_0x303f39[_0x14a5('0x7')];this[_0x14a5('0x8')]=_0x303f39[_0x14a5('0x8')];this[_0x14a5('0x9')]=_0x303f39[_0x14a5('0x9')];ami['on']('registryentry',this[_0x14a5('0xa')]['bind'](this));ami['on']('registry',this[_0x14a5('0xa')][_0x14a5('0xb')](this));ami['on'](_0x14a5('0xc'),this[_0x14a5('0xd')][_0x14a5('0xb')](this));ami['on']('peerstatus',this[_0x14a5('0xe')][_0x14a5('0xb')](this));this[_0x14a5('0xf')]();return BPromise[_0x14a5('0x10')]()['then'](ami[_0x14a5('0x11')]())[_0x14a5('0x12')](ami[_0x14a5('0x13')]())[_0x14a5('0x12')](ami[_0x14a5('0x14')]())[_0x14a5('0x15')](loggerCatch(_0x14a5('0x16')));}function loggerCatch(_0x1374c5){return function(_0x4285ee){logger[_0x14a5('0x17')](_0x1374c5,util[_0x14a5('0x18')](_0x4285ee,{'showHidden':![],'depth':null}));};}UserReport[_0x14a5('0x19')][_0x14a5('0xf')]=function(){setInterval(function(){BPromise[_0x14a5('0x10')]()[_0x14a5('0x12')](ami[_0x14a5('0x11')]())[_0x14a5('0x12')](ami[_0x14a5('0x13')]())['then'](ami['actionSipPeerStatus']())[_0x14a5('0x15')](loggerCatch(_0x14a5('0x16')));},0x32c8);};UserReport[_0x14a5('0x19')]['isNotNull']=function(_0x4a6c5f){return _0x4a6c5f!==null&&!_[_0x14a5('0x1a')](_0x4a6c5f);};UserReport['prototype'][_0x14a5('0x1b')]=function(_0x1f03e8,_0x236579,_0x1158ab){io['to'](_0x1f03e8)[_0x14a5('0x1b')](_0x236579,_0x1158ab);};UserReport['prototype'][_0x14a5('0xa')]=function(_0x1518c7){try{if(this[_0x14a5('0x1c')](_0x1518c7)){var _0x463a71=_[_0x14a5('0x1d')](this[_0x14a5('0x7')],{'registry':_0x1518c7[_0x14a5('0x1e')]});if(_0x463a71){_0x1518c7['stateRegistry']=_0x1518c7[_0x14a5('0x1f')];_[_0x14a5('0x20')](_0x463a71,_[_0x14a5('0x21')](_0x1518c7,[_0x14a5('0x22'),'actionid',_0x14a5('0x1e'),'state']));this[_0x14a5('0x1b')](util[_0x14a5('0x23')]('trunk:%s',_0x463a71['name']),'trunk:save',_0x463a71);}}}catch(_0x19a9d4){logger[_0x14a5('0x17')](_0x14a5('0x24'),util[_0x14a5('0x18')](_0x19a9d4,{'showHidden':![],'depth':null}));}};UserReport[_0x14a5('0x19')][_0x14a5('0xd')]=function(_0x7abd3b){try{if(this['isNotNull'](_0x7abd3b)){if(this[_0x14a5('0x8')][_0x7abd3b[_0x14a5('0x25')]]){if(!this[_0x14a5('0x8')][_0x7abd3b[_0x14a5('0x25')]][_0x14a5('0x26')]||_0x7abd3b[_0x14a5('0x1f')]['toLowerCase']()==_0x14a5('0x27')){this[_0x14a5('0x8')][_0x7abd3b[_0x14a5('0x25')]][_0x14a5('0x26')]=![];if(this[_0x14a5('0x8')][_0x7abd3b[_0x14a5('0x25')]][_0x14a5('0x1f')]!==_0x7abd3b[_0x14a5('0x1f')][_0x14a5('0x28')]()){this['agents'][_0x7abd3b[_0x14a5('0x25')]][_0x14a5('0x29')]=_['toNumber'](moment()[_0x14a5('0x23')]('x'));}this['agents'][_0x7abd3b[_0x14a5('0x25')]][_0x14a5('0x1f')]=_0x7abd3b['state'][_0x14a5('0x28')]();this[_0x14a5('0x8')][_0x7abd3b['device']][_0x14a5('0x2a')](_0x7abd3b);}}else if(this[_0x14a5('0x9')][_0x7abd3b[_0x14a5('0x25')]]){if(this[_0x14a5('0x9')][_0x7abd3b['device']]['state']!==_0x7abd3b['state'][_0x14a5('0x28')]()){this[_0x14a5('0x9')][_0x7abd3b['device']]['stateTime']=_[_0x14a5('0x2b')](moment()[_0x14a5('0x23')]('x'));}this[_0x14a5('0x9')][_0x7abd3b['device']]['state']=_0x7abd3b[_0x14a5('0x1f')][_0x14a5('0x28')]();this[_0x14a5('0x1b')](util['format'](_0x14a5('0x2c'),this[_0x14a5('0x9')][_0x7abd3b[_0x14a5('0x25')]]['name']),_0x14a5('0x2d'),this[_0x14a5('0x9')][_0x7abd3b[_0x14a5('0x25')]]);}else if(this[_0x14a5('0x7')][_0x7abd3b[_0x14a5('0x25')]]){if(this['trunks'][_0x7abd3b[_0x14a5('0x25')]][_0x14a5('0x1f')]!==_0x7abd3b['state'][_0x14a5('0x28')]()){this[_0x14a5('0x7')][_0x7abd3b[_0x14a5('0x25')]]['stateTime']=_[_0x14a5('0x2b')](moment()[_0x14a5('0x23')]('x'));}this[_0x14a5('0x7')][_0x7abd3b[_0x14a5('0x25')]][_0x14a5('0x1f')]=_0x7abd3b[_0x14a5('0x1f')][_0x14a5('0x28')]();this[_0x14a5('0x1b')](util[_0x14a5('0x23')](_0x14a5('0x2e'),this['trunks'][_0x7abd3b[_0x14a5('0x25')]][_0x14a5('0x2f')]),'trunk:save',this[_0x14a5('0x7')][_0x7abd3b['device']]);}else if(_[_0x14a5('0x30')](_0x7abd3b[_0x14a5('0x25')],_0x14a5('0x31'))){}else if(_['startsWith'](_0x7abd3b[_0x14a5('0x25')],_0x14a5('0x32'))){var _0x1eccef=_0x7abd3b[_0x14a5('0x25')];var _0x3153f=_0x1eccef[_0x14a5('0x33')](_0x1eccef[_0x14a5('0x34')]('/')+0x1,_0x1eccef[_0x14a5('0x34')]('@'));var _0x27ff13=_[_0x14a5('0x1d')](this['agents'],function(_0x4a6f6d){return _0x4a6f6d['mobile']==_0x3153f||_0x4a6f6d[_0x14a5('0x35')]==_0x3153f||_0x4a6f6d['accountcode']==_0x3153f;});if(_0x27ff13){if(_0x27ff13['state']!==_0x7abd3b['state'][_0x14a5('0x28')]()){_0x27ff13[_0x14a5('0x29')]=_[_0x14a5('0x2b')](moment()[_0x14a5('0x23')]('x'));}_0x27ff13[_0x14a5('0x1f')]=_0x7abd3b[_0x14a5('0x1f')][_0x14a5('0x28')]();_0x27ff13[_0x14a5('0x26')]=!![];_0x27ff13[_0x14a5('0x2a')](_0x7abd3b);}}else{}}}catch(_0x165346){logger[_0x14a5('0x17')](_0x14a5('0x36'),util[_0x14a5('0x18')](_0x165346,{'showHidden':![],'depth':null}));}};UserReport[_0x14a5('0x19')][_0x14a5('0xe')]=function(_0x49d96e){try{if(this[_0x14a5('0x1c')](_0x49d96e)&&this['isNotNull'](_0x49d96e[_0x14a5('0x37')])){if(this[_0x14a5('0x8')][_0x49d96e[_0x14a5('0x38')]]){if(!this[_0x14a5('0x8')][_0x49d96e[_0x14a5('0x38')]][_0x14a5('0x26')]||_0x49d96e[_0x14a5('0x37')][_0x14a5('0x28')]()=='registered'){this[_0x14a5('0x8')][_0x49d96e[_0x14a5('0x38')]]['local']=![];this[_0x14a5('0x8')][_0x49d96e[_0x14a5('0x38')]]['status']=_0x49d96e['peerstatus'][_0x14a5('0x28')]();this[_0x14a5('0x8')][_0x49d96e['peer']][_0x14a5('0x39')]=_0x49d96e['address'];this[_0x14a5('0x8')][_0x49d96e['peer']][_0x14a5('0x2a')](_0x49d96e);}}else if(this[_0x14a5('0x9')][_0x49d96e[_0x14a5('0x38')]]){this[_0x14a5('0x9')][_0x49d96e[_0x14a5('0x38')]][_0x14a5('0x3a')]=_0x49d96e[_0x14a5('0x37')][_0x14a5('0x28')]();this['telephones'][_0x49d96e[_0x14a5('0x38')]][_0x14a5('0x39')]=_0x49d96e[_0x14a5('0x39')];this[_0x14a5('0x1b')](util[_0x14a5('0x23')](_0x14a5('0x2c'),this[_0x14a5('0x9')][_0x49d96e['peer']][_0x14a5('0x2f')]),'telephone:save',this['telephones'][_0x49d96e[_0x14a5('0x38')]]);}else if(this[_0x14a5('0x7')][_0x49d96e[_0x14a5('0x38')]]){this[_0x14a5('0x7')][_0x49d96e['peer']][_0x14a5('0x3a')]=_0x49d96e[_0x14a5('0x37')]['toLowerCase']();this[_0x14a5('0x7')][_0x49d96e['peer']][_0x14a5('0x39')]=_0x49d96e[_0x14a5('0x39')];this[_0x14a5('0x1b')](util[_0x14a5('0x23')](_0x14a5('0x2e'),this['trunks'][_0x49d96e['peer']][_0x14a5('0x2f')]),_0x14a5('0x3b'),this['trunks'][_0x49d96e[_0x14a5('0x38')]]);}else{}}}catch(_0x402428){logger[_0x14a5('0x17')](_0x14a5('0x3c'),util[_0x14a5('0x18')](_0x402428,{'showHidden':![],'depth':null}));}};module[_0x14a5('0x3d')]=UserReport;