Built motion from commit (unavailable).|2.3.7
[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 _0x4dc8=['resolve','actionSipPeerStatus','prototype','emit','isNotNull','username','stateRegistry','state','merge','omit','event','actionid','trunk:%s','trunk:save','error','[syncRegistry][UserReport]','device','local','toLowerCase','inuse','format','updateStatusRealtime','telephone:%s','name','telephone:save','stateTime','toNumber','startsWith','indexOf','find','mobile','registered','peer','status','address','[syncPeerStatus][UserReport]','exports','bluebird','util','ioredis','../../../config/environment','../../../config/logger','ami','../ami','redis','localhost','socket.io-emitter','trunks','agents','telephones','registryentry','syncRegistry','bind','devicestatechange','syncDeviceState','peerstatus','syncPeerStatus','loopSyncRealTimeShow','then','actionSipShowRegistry','actionDeviceStateList','catch','[loopSyncRealTimeShow]','inspect'];(function(_0x450d77,_0xfc79f4){var _0xdea070=function(_0x2fdf4b){while(--_0x2fdf4b){_0x450d77['push'](_0x450d77['shift']());}};_0xdea070(++_0xfc79f4);}(_0x4dc8,0x125));var _0x84dc=function(_0x358db6,_0x12291e){_0x358db6=_0x358db6-0x0;var _0x3a945e=_0x4dc8[_0x358db6];return _0x3a945e;};'use strict';var _=require('lodash');var moment=require('moment');var BPromise=require(_0x84dc('0x0'));var util=require(_0x84dc('0x1'));var Redis=require(_0x84dc('0x2'));var config=require(_0x84dc('0x3'));var logger=require(_0x84dc('0x4'))(_0x84dc('0x5'));var ami=require(_0x84dc('0x6'));config[_0x84dc('0x7')]=_['defaults'](config['redis'],{'host':_0x84dc('0x8'),'port':0x18eb});var io=require(_0x84dc('0x9'))(new Redis(config[_0x84dc('0x7')]));function UserReport(_0x2fb797){this[_0x84dc('0xa')]=_0x2fb797[_0x84dc('0xa')];this[_0x84dc('0xb')]=_0x2fb797[_0x84dc('0xb')];this[_0x84dc('0xc')]=_0x2fb797[_0x84dc('0xc')];ami['on'](_0x84dc('0xd'),this[_0x84dc('0xe')][_0x84dc('0xf')](this));ami['on']('registry',this[_0x84dc('0xe')][_0x84dc('0xf')](this));ami['on'](_0x84dc('0x10'),this[_0x84dc('0x11')][_0x84dc('0xf')](this));ami['on'](_0x84dc('0x12'),this[_0x84dc('0x13')][_0x84dc('0xf')](this));this[_0x84dc('0x14')]();return BPromise['resolve']()[_0x84dc('0x15')](ami[_0x84dc('0x16')]())['then'](ami[_0x84dc('0x17')]())[_0x84dc('0x15')](ami['actionSipPeerStatus']())[_0x84dc('0x18')](loggerCatch(_0x84dc('0x19')));}function loggerCatch(_0x45a279){return function(_0x3ee72a){logger['error'](_0x45a279,util[_0x84dc('0x1a')](_0x3ee72a,{'showHidden':![],'depth':null}));};}UserReport['prototype']['loopSyncRealTimeShow']=function(){setInterval(function(){BPromise[_0x84dc('0x1b')]()[_0x84dc('0x15')](ami[_0x84dc('0x16')]())['then'](ami[_0x84dc('0x17')]())[_0x84dc('0x15')](ami[_0x84dc('0x1c')]())[_0x84dc('0x18')](loggerCatch(_0x84dc('0x19')));},0x32c8);};UserReport[_0x84dc('0x1d')]['isNotNull']=function(_0x104799){return _0x104799!==null&&!_['isUndefined'](_0x104799);};UserReport[_0x84dc('0x1d')][_0x84dc('0x1e')]=function(_0x4e1957,_0x3fbc69,_0x40ae54){io['to'](_0x4e1957)[_0x84dc('0x1e')](_0x3fbc69,_0x40ae54);};UserReport['prototype'][_0x84dc('0xe')]=function(_0x2f8f36){try{if(this[_0x84dc('0x1f')](_0x2f8f36)){var _0x33a86b=_['find'](this[_0x84dc('0xa')],{'registry':_0x2f8f36[_0x84dc('0x20')]});if(_0x33a86b){_0x2f8f36[_0x84dc('0x21')]=_0x2f8f36[_0x84dc('0x22')];_[_0x84dc('0x23')](_0x33a86b,_[_0x84dc('0x24')](_0x2f8f36,[_0x84dc('0x25'),_0x84dc('0x26'),_0x84dc('0x20'),_0x84dc('0x22')]));this['emit'](util['format'](_0x84dc('0x27'),_0x33a86b['name']),_0x84dc('0x28'),_0x33a86b);}}}catch(_0xb90179){logger[_0x84dc('0x29')](_0x84dc('0x2a'),util[_0x84dc('0x1a')](_0xb90179,{'showHidden':![],'depth':null}));}};UserReport[_0x84dc('0x1d')][_0x84dc('0x11')]=function(_0x275d94){try{if(this[_0x84dc('0x1f')](_0x275d94)){if(this[_0x84dc('0xb')][_0x275d94[_0x84dc('0x2b')]]){if(!this[_0x84dc('0xb')][_0x275d94[_0x84dc('0x2b')]][_0x84dc('0x2c')]||_0x275d94[_0x84dc('0x22')][_0x84dc('0x2d')]()==_0x84dc('0x2e')){this['agents'][_0x275d94[_0x84dc('0x2b')]][_0x84dc('0x2c')]=![];if(this[_0x84dc('0xb')][_0x275d94[_0x84dc('0x2b')]][_0x84dc('0x22')]!==_0x275d94[_0x84dc('0x22')][_0x84dc('0x2d')]()){this[_0x84dc('0xb')][_0x275d94[_0x84dc('0x2b')]]['stateTime']=_['toNumber'](moment()[_0x84dc('0x2f')]('x'));}this[_0x84dc('0xb')][_0x275d94['device']][_0x84dc('0x22')]=_0x275d94[_0x84dc('0x22')][_0x84dc('0x2d')]();this[_0x84dc('0xb')][_0x275d94[_0x84dc('0x2b')]][_0x84dc('0x30')](_0x275d94);}}else if(this[_0x84dc('0xc')][_0x275d94['device']]){if(this['telephones'][_0x275d94[_0x84dc('0x2b')]][_0x84dc('0x22')]!==_0x275d94[_0x84dc('0x22')][_0x84dc('0x2d')]()){this[_0x84dc('0xc')][_0x275d94['device']]['stateTime']=_['toNumber'](moment()[_0x84dc('0x2f')]('x'));}this[_0x84dc('0xc')][_0x275d94[_0x84dc('0x2b')]][_0x84dc('0x22')]=_0x275d94['state']['toLowerCase']();this[_0x84dc('0x1e')](util[_0x84dc('0x2f')](_0x84dc('0x31'),this[_0x84dc('0xc')][_0x275d94[_0x84dc('0x2b')]][_0x84dc('0x32')]),_0x84dc('0x33'),this[_0x84dc('0xc')][_0x275d94['device']]);}else if(this[_0x84dc('0xa')][_0x275d94[_0x84dc('0x2b')]]){if(this['trunks'][_0x275d94['device']][_0x84dc('0x22')]!==_0x275d94[_0x84dc('0x22')][_0x84dc('0x2d')]()){this['trunks'][_0x275d94[_0x84dc('0x2b')]][_0x84dc('0x34')]=_[_0x84dc('0x35')](moment()[_0x84dc('0x2f')]('x'));}this[_0x84dc('0xa')][_0x275d94[_0x84dc('0x2b')]][_0x84dc('0x22')]=_0x275d94[_0x84dc('0x22')][_0x84dc('0x2d')]();this['emit'](util[_0x84dc('0x2f')]('trunk:%s',this[_0x84dc('0xa')][_0x275d94['device']]['name']),'trunk:save',this[_0x84dc('0xa')][_0x275d94[_0x84dc('0x2b')]]);}else if(_[_0x84dc('0x36')](_0x275d94[_0x84dc('0x2b')],'Queue')){}else if(_['startsWith'](_0x275d94[_0x84dc('0x2b')],'Local')){var _0x5e4a71=_0x275d94[_0x84dc('0x2b')];var _0x32e8de=_0x5e4a71['substring'](_0x5e4a71[_0x84dc('0x37')]('/')+0x1,_0x5e4a71[_0x84dc('0x37')]('@'));var _0x2d635a=_[_0x84dc('0x38')](this[_0x84dc('0xb')],function(_0x4a5ce1){return _0x4a5ce1[_0x84dc('0x39')]==_0x32e8de||_0x4a5ce1['phone']==_0x32e8de||_0x4a5ce1['accountcode']==_0x32e8de;});if(_0x2d635a){if(_0x2d635a[_0x84dc('0x22')]!==_0x275d94[_0x84dc('0x22')][_0x84dc('0x2d')]()){_0x2d635a[_0x84dc('0x34')]=_[_0x84dc('0x35')](moment()[_0x84dc('0x2f')]('x'));}_0x2d635a[_0x84dc('0x22')]=_0x275d94[_0x84dc('0x22')][_0x84dc('0x2d')]();_0x2d635a[_0x84dc('0x2c')]=!![];_0x2d635a[_0x84dc('0x30')](_0x275d94);}}else{}}}catch(_0x3fbfcb){logger[_0x84dc('0x29')]('[syncDeviceState][UserReport]',util[_0x84dc('0x1a')](_0x3fbfcb,{'showHidden':![],'depth':null}));}};UserReport[_0x84dc('0x1d')][_0x84dc('0x13')]=function(_0x189053){try{if(this[_0x84dc('0x1f')](_0x189053)&&this[_0x84dc('0x1f')](_0x189053[_0x84dc('0x12')])){if(this['agents'][_0x189053['peer']]){if(!this['agents'][_0x189053['peer']][_0x84dc('0x2c')]||_0x189053[_0x84dc('0x12')][_0x84dc('0x2d')]()==_0x84dc('0x3a')){this['agents'][_0x189053[_0x84dc('0x3b')]][_0x84dc('0x2c')]=![];this[_0x84dc('0xb')][_0x189053[_0x84dc('0x3b')]][_0x84dc('0x3c')]=_0x189053[_0x84dc('0x12')]['toLowerCase']();this['agents'][_0x189053['peer']][_0x84dc('0x3d')]=_0x189053[_0x84dc('0x3d')];this[_0x84dc('0xb')][_0x189053[_0x84dc('0x3b')]]['updateStatusRealtime'](_0x189053);}}else if(this[_0x84dc('0xc')][_0x189053[_0x84dc('0x3b')]]){this[_0x84dc('0xc')][_0x189053['peer']][_0x84dc('0x3c')]=_0x189053[_0x84dc('0x12')][_0x84dc('0x2d')]();this[_0x84dc('0xc')][_0x189053[_0x84dc('0x3b')]][_0x84dc('0x3d')]=_0x189053['address'];this['emit'](util[_0x84dc('0x2f')](_0x84dc('0x31'),this[_0x84dc('0xc')][_0x189053[_0x84dc('0x3b')]][_0x84dc('0x32')]),_0x84dc('0x33'),this[_0x84dc('0xc')][_0x189053['peer']]);}else if(this[_0x84dc('0xa')][_0x189053[_0x84dc('0x3b')]]){this[_0x84dc('0xa')][_0x189053[_0x84dc('0x3b')]][_0x84dc('0x3c')]=_0x189053[_0x84dc('0x12')][_0x84dc('0x2d')]();this['trunks'][_0x189053['peer']][_0x84dc('0x3d')]=_0x189053[_0x84dc('0x3d')];this[_0x84dc('0x1e')](util[_0x84dc('0x2f')](_0x84dc('0x27'),this[_0x84dc('0xa')][_0x189053[_0x84dc('0x3b')]][_0x84dc('0x32')]),'trunk:save',this['trunks'][_0x189053['peer']]);}else{}}}catch(_0x58e11f){logger[_0x84dc('0x29')](_0x84dc('0x3e'),util[_0x84dc('0x1a')](_0x58e11f,{'showHidden':![],'depth':null}));}};module[_0x84dc('0x3f')]=UserReport;