Built motion from commit 67e5df37.|2.0.66
[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 _0xa3e8=['lodash','moment','bluebird','../../../config/logger','ami','../ami','socket.io-emitter','localhost','agents','telephones','registryentry','syncRegistry','bind','registry','devicestatechange','syncDeviceState','syncPeerStatus','loopSyncRealTimeShow','then','actionSipShowRegistry','actionDeviceStateList','actionSipPeerStatus','catch','[loopSyncRealTimeShow]','error','inspect','prototype','resolve','isNotNull','isUndefined','emit','trunks','username','state','merge','omit','event','actionid','format','trunk:%s','name','trunk:save','device','toLowerCase','stateTime','toNumber','updateStatusRealtime','telephone:%s','startsWith','Queue','[syncDeviceState][UserReport]','peerstatus','peer','user:save','status','address','telephone:save','[syncPeerStatus][UserReport]','exports'];(function(_0x59236b,_0x5b2bff){var _0x24cded=function(_0x411bc6){while(--_0x411bc6){_0x59236b['push'](_0x59236b['shift']());}};_0x24cded(++_0x5b2bff);}(_0xa3e8,0x127));var _0x8a3e=function(_0x210ee4,_0x26a2a2){_0x210ee4=_0x210ee4-0x0;var _0x296e13=_0xa3e8[_0x210ee4];return _0x296e13;};'use strict';var _=require(_0x8a3e('0x0'));var moment=require(_0x8a3e('0x1'));var BPromise=require(_0x8a3e('0x2'));var util=require('util');var logger=require(_0x8a3e('0x3'))(_0x8a3e('0x4'));var ami=require(_0x8a3e('0x5'));var io=require(_0x8a3e('0x6'))({'host':_0x8a3e('0x7'),'port':0x18eb});function UserReport(_0x5a81bb){this['trunks']=_0x5a81bb['trunks'];this[_0x8a3e('0x8')]=_0x5a81bb[_0x8a3e('0x8')];this[_0x8a3e('0x9')]=_0x5a81bb['telephones'];ami['on'](_0x8a3e('0xa'),this[_0x8a3e('0xb')][_0x8a3e('0xc')](this));ami['on'](_0x8a3e('0xd'),this[_0x8a3e('0xb')][_0x8a3e('0xc')](this));ami['on'](_0x8a3e('0xe'),this[_0x8a3e('0xf')][_0x8a3e('0xc')](this));ami['on']('peerstatus',this[_0x8a3e('0x10')][_0x8a3e('0xc')](this));this[_0x8a3e('0x11')]();return BPromise['resolve']()[_0x8a3e('0x12')](ami[_0x8a3e('0x13')]())[_0x8a3e('0x12')](ami[_0x8a3e('0x14')]())[_0x8a3e('0x12')](ami[_0x8a3e('0x15')]())[_0x8a3e('0x16')](loggerCatch(_0x8a3e('0x17')));}function loggerCatch(_0x107cda){return function(_0x4290ab){logger[_0x8a3e('0x18')](_0x107cda,util[_0x8a3e('0x19')](_0x4290ab,{'showHidden':![],'depth':null}));};}UserReport[_0x8a3e('0x1a')]['loopSyncRealTimeShow']=function(){setInterval(function(){BPromise[_0x8a3e('0x1b')]()[_0x8a3e('0x12')](ami[_0x8a3e('0x13')]())[_0x8a3e('0x12')](ami[_0x8a3e('0x14')]())[_0x8a3e('0x12')](ami['actionSipPeerStatus']())[_0x8a3e('0x16')](loggerCatch('[loopSyncRealTimeShow]'));},0x32c8);};UserReport['prototype'][_0x8a3e('0x1c')]=function(_0xb2f9c3){return _0xb2f9c3!==null&&!_[_0x8a3e('0x1d')](_0xb2f9c3);};UserReport[_0x8a3e('0x1a')][_0x8a3e('0x1e')]=function(_0x2e7b33,_0x18bb0e,_0x1cc792){io['to'](_0x2e7b33)['emit'](_0x18bb0e,_0x1cc792);};UserReport[_0x8a3e('0x1a')]['syncRegistry']=function(_0x103eab){try{if(this[_0x8a3e('0x1c')](_0x103eab)){var _0x79983e=_['find'](this[_0x8a3e('0x1f')],{'registry':_0x103eab[_0x8a3e('0x20')]});if(_0x79983e){_0x103eab['stateRegistry']=_0x103eab[_0x8a3e('0x21')];_[_0x8a3e('0x22')](_0x79983e,_[_0x8a3e('0x23')](_0x103eab,[_0x8a3e('0x24'),_0x8a3e('0x25'),_0x8a3e('0x20'),_0x8a3e('0x21')]));this[_0x8a3e('0x1e')](util[_0x8a3e('0x26')](_0x8a3e('0x27'),_0x79983e[_0x8a3e('0x28')]),_0x8a3e('0x29'),_0x79983e);}}}catch(_0x489015){logger[_0x8a3e('0x18')]('[syncRegistry][UserReport]',util[_0x8a3e('0x19')](_0x489015,{'showHidden':![],'depth':null}));}};UserReport['prototype'][_0x8a3e('0xf')]=function(_0x3e0cdb){try{if(this[_0x8a3e('0x1c')](_0x3e0cdb)){if(this[_0x8a3e('0x8')][_0x3e0cdb[_0x8a3e('0x2a')]]){if(this[_0x8a3e('0x8')][_0x3e0cdb[_0x8a3e('0x2a')]]['state']!==_0x3e0cdb[_0x8a3e('0x21')][_0x8a3e('0x2b')]()){this[_0x8a3e('0x8')][_0x3e0cdb[_0x8a3e('0x2a')]][_0x8a3e('0x2c')]=_[_0x8a3e('0x2d')](moment()[_0x8a3e('0x26')]('x'));}this['agents'][_0x3e0cdb[_0x8a3e('0x2a')]][_0x8a3e('0x21')]=_0x3e0cdb[_0x8a3e('0x21')][_0x8a3e('0x2b')]();this[_0x8a3e('0x8')][_0x3e0cdb[_0x8a3e('0x2a')]][_0x8a3e('0x2e')](_0x3e0cdb);}else if(this[_0x8a3e('0x9')][_0x3e0cdb[_0x8a3e('0x2a')]]){if(this[_0x8a3e('0x9')][_0x3e0cdb[_0x8a3e('0x2a')]][_0x8a3e('0x21')]!==_0x3e0cdb[_0x8a3e('0x21')][_0x8a3e('0x2b')]()){this[_0x8a3e('0x9')][_0x3e0cdb['device']]['stateTime']=_['toNumber'](moment()[_0x8a3e('0x26')]('x'));}this[_0x8a3e('0x9')][_0x3e0cdb['device']]['state']=_0x3e0cdb[_0x8a3e('0x21')]['toLowerCase']();this['emit'](util[_0x8a3e('0x26')](_0x8a3e('0x2f'),this[_0x8a3e('0x9')][_0x3e0cdb[_0x8a3e('0x2a')]][_0x8a3e('0x28')]),'telephone:save',this[_0x8a3e('0x9')][_0x3e0cdb[_0x8a3e('0x2a')]]);}else if(this['trunks'][_0x3e0cdb[_0x8a3e('0x2a')]]){if(this['trunks'][_0x3e0cdb[_0x8a3e('0x2a')]][_0x8a3e('0x21')]!==_0x3e0cdb[_0x8a3e('0x21')][_0x8a3e('0x2b')]()){this[_0x8a3e('0x1f')][_0x3e0cdb[_0x8a3e('0x2a')]][_0x8a3e('0x2c')]=_[_0x8a3e('0x2d')](moment()['format']('x'));}this[_0x8a3e('0x1f')][_0x3e0cdb[_0x8a3e('0x2a')]][_0x8a3e('0x21')]=_0x3e0cdb[_0x8a3e('0x21')][_0x8a3e('0x2b')]();this[_0x8a3e('0x1e')](util['format'](_0x8a3e('0x27'),this[_0x8a3e('0x1f')][_0x3e0cdb[_0x8a3e('0x2a')]][_0x8a3e('0x28')]),'trunk:save',this[_0x8a3e('0x1f')][_0x3e0cdb['device']]);}else if(_[_0x8a3e('0x30')](_0x3e0cdb[_0x8a3e('0x2a')],_0x8a3e('0x31'))){}else{}}}catch(_0x161382){logger[_0x8a3e('0x18')](_0x8a3e('0x32'),util[_0x8a3e('0x19')](_0x161382,{'showHidden':![],'depth':null}));}};UserReport[_0x8a3e('0x1a')][_0x8a3e('0x10')]=function(_0x218367){try{if(this['isNotNull'](_0x218367)&&this['isNotNull'](_0x218367[_0x8a3e('0x33')])){if(this[_0x8a3e('0x8')][_0x218367['peer']]){this[_0x8a3e('0x8')][_0x218367[_0x8a3e('0x34')]]['status']=_0x218367[_0x8a3e('0x33')]['toLowerCase']();this['agents'][_0x218367[_0x8a3e('0x34')]]['address']=_0x218367['address'];this[_0x8a3e('0x1e')](util[_0x8a3e('0x26')]('user:%s',this[_0x8a3e('0x8')][_0x218367[_0x8a3e('0x34')]]['name']),_0x8a3e('0x35'),this['agents'][_0x218367['peer']]);}else if(this[_0x8a3e('0x9')][_0x218367[_0x8a3e('0x34')]]){this[_0x8a3e('0x9')][_0x218367['peer']][_0x8a3e('0x36')]=_0x218367[_0x8a3e('0x33')]['toLowerCase']();this[_0x8a3e('0x9')][_0x218367[_0x8a3e('0x34')]]['address']=_0x218367[_0x8a3e('0x37')];this[_0x8a3e('0x1e')](util['format']('telephone:%s',this[_0x8a3e('0x9')][_0x218367[_0x8a3e('0x34')]]['name']),_0x8a3e('0x38'),this[_0x8a3e('0x9')][_0x218367[_0x8a3e('0x34')]]);}else if(this[_0x8a3e('0x1f')][_0x218367[_0x8a3e('0x34')]]){this['trunks'][_0x218367['peer']][_0x8a3e('0x36')]=_0x218367[_0x8a3e('0x33')]['toLowerCase']();this[_0x8a3e('0x1f')][_0x218367['peer']][_0x8a3e('0x37')]=_0x218367[_0x8a3e('0x37')];this['emit'](util[_0x8a3e('0x26')](_0x8a3e('0x27'),this[_0x8a3e('0x1f')][_0x218367[_0x8a3e('0x34')]]['name']),_0x8a3e('0x29'),this['trunks'][_0x218367[_0x8a3e('0x34')]]);}else{}}}catch(_0x17ea70){logger['error'](_0x8a3e('0x39'),util[_0x8a3e('0x19')](_0x17ea70,{'showHidden':![],'depth':null}));}};module[_0x8a3e('0x3a')]=UserReport;