Built motion from commit (unavailable).|2.5.10
[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 _0x323e=['telephone:save','[userReport][devicestatechange]\x20sending\x20trunk:save\x20event:','startsWith','Local','indexOf','mobile','phone','accountcode','[userReport][devicestatechange]','[userReport][peerstatus]\x20peer:%s\x20address:%s\x20status:%s','address','peerstatus','[userReport][peerstatus]','peer','status','[userReport][peerstatus]\x20sending\x20telephone:save\x20event:','telephone:%s','[userReport][peerstatus]\x20sending\x20trunk:save\x20event:','exports','moment','util','bluebird','../../../config/environment','../../../config/logger','ami','redis','defaults','localhost','socket.io-emitter','trunks','agents','telephones','registryentry','syncRegistry','registry','devicestatechange','syncDeviceState','bind','syncPeerStatus','then','actionSipShowRegistry','catch','error','[userReport][sipshowregistry]','inspect','resolve','[userReport][devicestatelist]','actionSipPeerStatus','[userReport][sippeerstatus]','prototype','syncRealtimeShow','isUndefined','emit','isNotNull','info','username','[userReport][registry]','find','stateRegistry','state','merge','debug','[userReport][registry]\x20sending\x20trunk:save\x20event:','format','trunk:%s','name','trunk:save','[userReport][devicestatechange]\x20device:%s\x20state:%s','device','toLowerCase','local','stateTime','toNumber','updateStatusRealtime','[userReport][devicestatechange]\x20sending\x20telephone:save\x20event:'];(function(_0x4f4d8c,_0xc21097){var _0x54352e=function(_0x59db3a){while(--_0x59db3a){_0x4f4d8c['push'](_0x4f4d8c['shift']());}};_0x54352e(++_0xc21097);}(_0x323e,0xa9));var _0xe323=function(_0x5702d1,_0x8e1bea){_0x5702d1=_0x5702d1-0x0;var _0x5c844b=_0x323e[_0x5702d1];return _0x5c844b;};'use strict';var _=require('lodash');var moment=require(_0xe323('0x0'));var util=require(_0xe323('0x1'));var Redis=require('ioredis');var BPromise=require(_0xe323('0x2'));var config=require(_0xe323('0x3'));var logger=require(_0xe323('0x4'))(_0xe323('0x5'));var ami=require('../ami');config[_0xe323('0x6')]=_[_0xe323('0x7')](config['redis'],{'host':_0xe323('0x8'),'port':0x18eb});var io=require(_0xe323('0x9'))(new Redis(config[_0xe323('0x6')]));function UserReport(_0xd3aeed){this[_0xe323('0xa')]=_0xd3aeed[_0xe323('0xa')];this[_0xe323('0xb')]=_0xd3aeed[_0xe323('0xb')];this['telephones']=_0xd3aeed[_0xe323('0xc')];ami['on'](_0xe323('0xd'),this[_0xe323('0xe')]['bind'](this));ami['on'](_0xe323('0xf'),this[_0xe323('0xe')]['bind'](this));ami['on'](_0xe323('0x10'),this[_0xe323('0x11')][_0xe323('0x12')](this));ami['on']('peerstatus',this[_0xe323('0x13')][_0xe323('0x12')](this));return this['syncRealtimeShow']();}function showSipRegistrations(){Promise['resolve']()[_0xe323('0x14')](ami[_0xe323('0x15')]())[_0xe323('0x16')](function(_0x123fcd){logger[_0xe323('0x17')](_0xe323('0x18'),util[_0xe323('0x19')](_0x123fcd,{'showHidden':![],'depth':null}));});}function listDeviceStates(){Promise[_0xe323('0x1a')]()[_0xe323('0x14')](ami['actionDeviceStateList']())[_0xe323('0x16')](function(_0x2ca281){logger[_0xe323('0x17')](_0xe323('0x1b'),util['inspect'](_0x2ca281,{'showHidden':![],'depth':null}));});}function showPeersStatus(){Promise[_0xe323('0x1a')]()[_0xe323('0x14')](ami[_0xe323('0x1c')]())[_0xe323('0x16')](function(_0x48e002){logger[_0xe323('0x17')](_0xe323('0x1d'),util['inspect'](_0x48e002,{'showHidden':![],'depth':null}));});}UserReport[_0xe323('0x1e')][_0xe323('0x1f')]=function(){setInterval(function(){BPromise[_0xe323('0x1a')]()[_0xe323('0x14')](showSipRegistrations())[_0xe323('0x14')](listDeviceStates())[_0xe323('0x14')](showPeersStatus());},0x32c8);};UserReport['prototype']['isNotNull']=function(_0x11729b){return _0x11729b!==null&&!_[_0xe323('0x20')](_0x11729b);};UserReport[_0xe323('0x1e')][_0xe323('0x21')]=function(_0x24e40e,_0x586583,_0x355f19){io['to'](_0x24e40e)[_0xe323('0x21')](_0x586583,_0x355f19);};UserReport[_0xe323('0x1e')]['syncRegistry']=function(_0x31ffea){try{if(this[_0xe323('0x22')](_0x31ffea)){logger[_0xe323('0x23')]('[userReport][registry]\x20registry:%s\x20state:%s',_0x31ffea[_0xe323('0x24')],_0x31ffea['state']);logger['debug'](_0xe323('0x25'),util[_0xe323('0x19')](_0x31ffea,{'showHidden':![],'depth':null}));var _0x2ef158=_[_0xe323('0x26')](this['trunks'],{'registry':_0x31ffea[_0xe323('0x24')]});if(_0x2ef158){_0x31ffea[_0xe323('0x27')]=_0x31ffea[_0xe323('0x28')];_[_0xe323('0x29')](_0x2ef158,_['omit'](_0x31ffea,['event','actionid',_0xe323('0x24'),_0xe323('0x28')]));logger[_0xe323('0x2a')](_0xe323('0x2b'),util[_0xe323('0x19')](_0x2ef158,{'showHidden':![],'depth':null}));this[_0xe323('0x21')](util[_0xe323('0x2c')](_0xe323('0x2d'),_0x2ef158[_0xe323('0x2e')]),_0xe323('0x2f'),_0x2ef158);}}}catch(_0x1fa5e2){logger[_0xe323('0x17')](_0xe323('0x25'),util[_0xe323('0x19')](_0x1fa5e2,{'showHidden':![],'depth':null}));}};UserReport[_0xe323('0x1e')][_0xe323('0x11')]=function(_0x5042e9){try{if(this['isNotNull'](_0x5042e9)){logger[_0xe323('0x23')](_0xe323('0x30'),_0x5042e9['device'],_0x5042e9['state']);logger[_0xe323('0x2a')]('[userReport][devicestatechange]',util[_0xe323('0x19')](_0x5042e9,{'showHidden':![],'depth':null}));if(this[_0xe323('0xb')][_0x5042e9[_0xe323('0x31')]]){if(!this[_0xe323('0xb')][_0x5042e9[_0xe323('0x31')]]['local']||_0x5042e9[_0xe323('0x28')][_0xe323('0x32')]()=='inuse'){this[_0xe323('0xb')][_0x5042e9[_0xe323('0x31')]][_0xe323('0x33')]=![];if(this['agents'][_0x5042e9[_0xe323('0x31')]]['state']!==_0x5042e9['state']['toLowerCase']()){this[_0xe323('0xb')][_0x5042e9['device']][_0xe323('0x34')]=_[_0xe323('0x35')](moment()[_0xe323('0x2c')]('x'));}this['agents'][_0x5042e9[_0xe323('0x31')]][_0xe323('0x28')]=_0x5042e9[_0xe323('0x28')][_0xe323('0x32')]();this[_0xe323('0xb')][_0x5042e9[_0xe323('0x31')]][_0xe323('0x36')](_0x5042e9);}}else if(this[_0xe323('0xc')][_0x5042e9[_0xe323('0x31')]]){if(this[_0xe323('0xc')][_0x5042e9[_0xe323('0x31')]][_0xe323('0x28')]!==_0x5042e9[_0xe323('0x28')][_0xe323('0x32')]()){this[_0xe323('0xc')][_0x5042e9[_0xe323('0x31')]]['stateTime']=_[_0xe323('0x35')](moment()[_0xe323('0x2c')]('x'));}this[_0xe323('0xc')][_0x5042e9[_0xe323('0x31')]]['state']=_0x5042e9[_0xe323('0x28')][_0xe323('0x32')]();logger[_0xe323('0x2a')](_0xe323('0x37'),util[_0xe323('0x19')](this[_0xe323('0xc')][_0x5042e9[_0xe323('0x31')]],{'showHidden':![],'depth':null}));this['emit'](util[_0xe323('0x2c')]('telephone:%s',this[_0xe323('0xc')][_0x5042e9[_0xe323('0x31')]][_0xe323('0x2e')]),_0xe323('0x38'),this[_0xe323('0xc')][_0x5042e9['device']]);}else if(this[_0xe323('0xa')][_0x5042e9['device']]){if(this[_0xe323('0xa')][_0x5042e9[_0xe323('0x31')]][_0xe323('0x28')]!==_0x5042e9[_0xe323('0x28')][_0xe323('0x32')]()){this['trunks'][_0x5042e9[_0xe323('0x31')]][_0xe323('0x34')]=_['toNumber'](moment()[_0xe323('0x2c')]('x'));}this['trunks'][_0x5042e9['device']]['state']=_0x5042e9['state']['toLowerCase']();logger[_0xe323('0x2a')](_0xe323('0x39'),util[_0xe323('0x19')](this[_0xe323('0xa')][_0x5042e9[_0xe323('0x31')]],{'showHidden':![],'depth':null}));this['emit'](util[_0xe323('0x2c')]('trunk:%s',this[_0xe323('0xa')][_0x5042e9[_0xe323('0x31')]][_0xe323('0x2e')]),_0xe323('0x2f'),this['trunks'][_0x5042e9[_0xe323('0x31')]]);}else if(_[_0xe323('0x3a')](_0x5042e9[_0xe323('0x31')],_0xe323('0x3b'))){var _0x5ea400=_0x5042e9[_0xe323('0x31')];var _0x719cb7=_0x5ea400['substring'](_0x5ea400[_0xe323('0x3c')]('/')+0x1,_0x5ea400[_0xe323('0x3c')]('@'));var _0x5a7f9e=_['find'](this[_0xe323('0xb')],function(_0x2bbc44){return _0x2bbc44[_0xe323('0x3d')]==_0x719cb7||_0x2bbc44[_0xe323('0x3e')]==_0x719cb7||_0x2bbc44[_0xe323('0x3f')]==_0x719cb7;});if(_0x5a7f9e){if(_0x5a7f9e[_0xe323('0x28')]!==_0x5042e9[_0xe323('0x28')][_0xe323('0x32')]()){_0x5a7f9e[_0xe323('0x34')]=_[_0xe323('0x35')](moment()[_0xe323('0x2c')]('x'));}_0x5a7f9e[_0xe323('0x28')]=_0x5042e9[_0xe323('0x28')][_0xe323('0x32')]();_0x5a7f9e['local']=!![];_0x5a7f9e[_0xe323('0x36')](_0x5042e9);}}}}catch(_0x31b1f8){logger[_0xe323('0x17')](_0xe323('0x40'),util[_0xe323('0x19')](_0x31b1f8,{'showHidden':![],'depth':null}));}};UserReport[_0xe323('0x1e')][_0xe323('0x13')]=function(_0x38c673){try{if(this['isNotNull'](_0x38c673)&&this['isNotNull'](_0x38c673['peerstatus'])){logger['info'](_0xe323('0x41'),_0x38c673['peer'],_0x38c673[_0xe323('0x42')],_0x38c673[_0xe323('0x43')]);logger[_0xe323('0x2a')](_0xe323('0x44'),util[_0xe323('0x19')](_0x38c673,{'showHidden':![],'depth':null}));if(this[_0xe323('0xb')][_0x38c673['peer']]){if(!this[_0xe323('0xb')][_0x38c673[_0xe323('0x45')]][_0xe323('0x33')]||_0x38c673[_0xe323('0x43')][_0xe323('0x32')]()=='registered'){this[_0xe323('0xb')][_0x38c673[_0xe323('0x45')]][_0xe323('0x33')]=![];this[_0xe323('0xb')][_0x38c673[_0xe323('0x45')]][_0xe323('0x46')]=_0x38c673[_0xe323('0x43')][_0xe323('0x32')]();this[_0xe323('0xb')][_0x38c673[_0xe323('0x45')]]['address']=_0x38c673[_0xe323('0x42')];this[_0xe323('0xb')][_0x38c673[_0xe323('0x45')]][_0xe323('0x36')](_0x38c673);}}else if(this[_0xe323('0xc')][_0x38c673[_0xe323('0x45')]]){this[_0xe323('0xc')][_0x38c673[_0xe323('0x45')]][_0xe323('0x46')]=_0x38c673[_0xe323('0x43')][_0xe323('0x32')]();this[_0xe323('0xc')][_0x38c673[_0xe323('0x45')]]['address']=_0x38c673['address'];logger[_0xe323('0x2a')](_0xe323('0x47'),util[_0xe323('0x19')](this[_0xe323('0xc')][_0x38c673[_0xe323('0x45')]],{'showHidden':![],'depth':null}));this[_0xe323('0x21')](util[_0xe323('0x2c')](_0xe323('0x48'),this[_0xe323('0xc')][_0x38c673['peer']][_0xe323('0x2e')]),_0xe323('0x38'),this[_0xe323('0xc')][_0x38c673[_0xe323('0x45')]]);}else if(this[_0xe323('0xa')][_0x38c673['peer']]){this['trunks'][_0x38c673['peer']][_0xe323('0x46')]=_0x38c673[_0xe323('0x43')]['toLowerCase']();this[_0xe323('0xa')][_0x38c673[_0xe323('0x45')]][_0xe323('0x42')]=_0x38c673[_0xe323('0x42')];logger[_0xe323('0x2a')](_0xe323('0x49'),util['inspect'](this[_0xe323('0xa')][_0x38c673[_0xe323('0x45')]],{'showHidden':![],'depth':null}));this[_0xe323('0x21')](util[_0xe323('0x2c')](_0xe323('0x2d'),this[_0xe323('0xa')][_0x38c673[_0xe323('0x45')]]['name']),_0xe323('0x2f'),this[_0xe323('0xa')][_0x38c673[_0xe323('0x45')]]);}}}catch(_0x205ff4){logger[_0xe323('0x17')]('[userReport][peerstatus]',util['inspect'](_0x205ff4,{'showHidden':![],'depth':null}));}};module[_0xe323('0x4a')]=UserReport;