Built motion from commit b9b02fed.|2.6.5
[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 _0x426a=['trunk:%s','name','info','agents','device','toLowerCase','local','stateTime','toNumber','updateStatusRealtime','telephone:%s','telephone:save','[userReport][devicestatechange]\x20sending\x20trunk:save\x20event:','trunk:save','startsWith','Local','substring','indexOf','mobile','phone','accountcode','[userReport][devicestatechange]','address','[userReport][peerstatus]','peer','status','[userReport][peerstatus]\x20sending\x20telephone:save\x20event:','[userReport][peerstatus]\x20sending\x20trunk:save\x20event:','lodash','moment','util','ioredis','bluebird','../../../config/environment','ami','defaults','localhost','socket.io-emitter','redis','trunks','telephones','registryentry','syncRegistry','bind','registry','devicestatechange','syncDeviceState','peerstatus','syncPeerStatus','syncRealtimeShow','resolve','then','[userReport][sipshowregistry]','catch','error','inspect','actionSipPeerStatus','[userReport][sippeerstatus]','prototype','isNotNull','emit','debug','[userReport][registry]','find','username','state','omit','event','actionid','[userReport][registry]\x20sending\x20trunk:save\x20event:','format'];(function(_0x324912,_0x36bccd){var _0x4b54c0=function(_0x17f7e5){while(--_0x17f7e5){_0x324912['push'](_0x324912['shift']());}};_0x4b54c0(++_0x36bccd);}(_0x426a,0x1c6));var _0xa426=function(_0x27c192,_0x272779){_0x27c192=_0x27c192-0x0;var _0x488378=_0x426a[_0x27c192];return _0x488378;};'use strict';var _=require(_0xa426('0x0'));var moment=require(_0xa426('0x1'));var util=require(_0xa426('0x2'));var Redis=require(_0xa426('0x3'));var BPromise=require(_0xa426('0x4'));var config=require(_0xa426('0x5'));var logger=require('../../../config/logger')(_0xa426('0x6'));var ami=require('../ami');config['redis']=_[_0xa426('0x7')](config['redis'],{'host':_0xa426('0x8'),'port':0x18eb});var io=require(_0xa426('0x9'))(new Redis(config[_0xa426('0xa')]));function UserReport(_0x47ee9f){this[_0xa426('0xb')]=_0x47ee9f[_0xa426('0xb')];this['agents']=_0x47ee9f['agents'];this[_0xa426('0xc')]=_0x47ee9f[_0xa426('0xc')];ami['on'](_0xa426('0xd'),this[_0xa426('0xe')][_0xa426('0xf')](this));ami['on'](_0xa426('0x10'),this[_0xa426('0xe')][_0xa426('0xf')](this));ami['on'](_0xa426('0x11'),this[_0xa426('0x12')][_0xa426('0xf')](this));ami['on'](_0xa426('0x13'),this[_0xa426('0x14')][_0xa426('0xf')](this));return this[_0xa426('0x15')]();}function showSipRegistrations(){Promise[_0xa426('0x16')]()[_0xa426('0x17')](ami['actionSipShowRegistry']())['catch'](function(_0x35f9ca){logger['error'](_0xa426('0x18'),util['inspect'](_0x35f9ca,{'showHidden':![],'depth':null}));});}function listDeviceStates(){Promise['resolve']()[_0xa426('0x17')](ami['actionDeviceStateList']())[_0xa426('0x19')](function(_0x3de49a){logger[_0xa426('0x1a')]('[userReport][devicestatelist]',util[_0xa426('0x1b')](_0x3de49a,{'showHidden':![],'depth':null}));});}function showPeersStatus(){Promise[_0xa426('0x16')]()[_0xa426('0x17')](ami[_0xa426('0x1c')]())[_0xa426('0x19')](function(_0x4ce798){logger[_0xa426('0x1a')](_0xa426('0x1d'),util['inspect'](_0x4ce798,{'showHidden':![],'depth':null}));});}UserReport['prototype'][_0xa426('0x15')]=function(){setInterval(function(){BPromise[_0xa426('0x16')]()[_0xa426('0x17')](showSipRegistrations())[_0xa426('0x17')](listDeviceStates())[_0xa426('0x17')](showPeersStatus());},0x32c8);};UserReport[_0xa426('0x1e')][_0xa426('0x1f')]=function(_0xfc6f55){return _0xfc6f55!==null&&!_['isUndefined'](_0xfc6f55);};UserReport[_0xa426('0x1e')][_0xa426('0x20')]=function(_0x50f681,_0x34d53a,_0x428f04){io['to'](_0x50f681)[_0xa426('0x20')](_0x34d53a,_0x428f04);};UserReport[_0xa426('0x1e')][_0xa426('0xe')]=function(_0x4fa6c1){try{if(this[_0xa426('0x1f')](_0x4fa6c1)){logger['info']('[userReport][registry]\x20registry:%s\x20state:%s',_0x4fa6c1['username'],_0x4fa6c1['state']);logger[_0xa426('0x21')](_0xa426('0x22'),util[_0xa426('0x1b')](_0x4fa6c1,{'showHidden':![],'depth':null}));var _0x49c25b=_[_0xa426('0x23')](this[_0xa426('0xb')],{'defaultuser':_0x4fa6c1[_0xa426('0x24')]});if(_0x49c25b){_0x4fa6c1['stateRegistry']=_0x4fa6c1[_0xa426('0x25')];_['merge'](_0x49c25b,_[_0xa426('0x26')](_0x4fa6c1,[_0xa426('0x27'),_0xa426('0x28'),'username',_0xa426('0x25')]));logger['debug'](_0xa426('0x29'),util['inspect'](_0x49c25b,{'showHidden':![],'depth':null}));this[_0xa426('0x20')](util[_0xa426('0x2a')](_0xa426('0x2b'),_0x49c25b[_0xa426('0x2c')]),'trunk:save',_0x49c25b);}}}catch(_0x589d0b){logger[_0xa426('0x1a')]('[userReport][registry]',util[_0xa426('0x1b')](_0x589d0b,{'showHidden':![],'depth':null}));}};UserReport[_0xa426('0x1e')][_0xa426('0x12')]=function(_0x366df2){try{if(this[_0xa426('0x1f')](_0x366df2)){logger[_0xa426('0x2d')]('[userReport][devicestatechange]\x20device:%s\x20state:%s',_0x366df2['device'],_0x366df2[_0xa426('0x25')]);logger[_0xa426('0x21')]('[userReport][devicestatechange]',util[_0xa426('0x1b')](_0x366df2,{'showHidden':![],'depth':null}));if(this[_0xa426('0x2e')][_0x366df2[_0xa426('0x2f')]]){if(!this[_0xa426('0x2e')][_0x366df2[_0xa426('0x2f')]]['local']||_0x366df2['state'][_0xa426('0x30')]()=='inuse'){this[_0xa426('0x2e')][_0x366df2['device']][_0xa426('0x31')]=![];if(this[_0xa426('0x2e')][_0x366df2[_0xa426('0x2f')]][_0xa426('0x25')]!==_0x366df2[_0xa426('0x25')]['toLowerCase']()){this[_0xa426('0x2e')][_0x366df2[_0xa426('0x2f')]][_0xa426('0x32')]=_[_0xa426('0x33')](moment()['format']('x'));}this[_0xa426('0x2e')][_0x366df2['device']]['state']=_0x366df2[_0xa426('0x25')][_0xa426('0x30')]();this[_0xa426('0x2e')][_0x366df2[_0xa426('0x2f')]][_0xa426('0x34')](_0x366df2);}}else if(this[_0xa426('0xc')][_0x366df2[_0xa426('0x2f')]]){if(this[_0xa426('0xc')][_0x366df2['device']][_0xa426('0x25')]!==_0x366df2[_0xa426('0x25')][_0xa426('0x30')]()){this[_0xa426('0xc')][_0x366df2['device']][_0xa426('0x32')]=_[_0xa426('0x33')](moment()[_0xa426('0x2a')]('x'));}this['telephones'][_0x366df2[_0xa426('0x2f')]]['state']=_0x366df2['state']['toLowerCase']();logger['debug']('[userReport][devicestatechange]\x20sending\x20telephone:save\x20event:',util[_0xa426('0x1b')](this['telephones'][_0x366df2[_0xa426('0x2f')]],{'showHidden':![],'depth':null}));this['emit'](util[_0xa426('0x2a')](_0xa426('0x35'),this[_0xa426('0xc')][_0x366df2['device']][_0xa426('0x2c')]),_0xa426('0x36'),this['telephones'][_0x366df2[_0xa426('0x2f')]]);}else if(this[_0xa426('0xb')][_0x366df2[_0xa426('0x2f')]]){if(this[_0xa426('0xb')][_0x366df2[_0xa426('0x2f')]][_0xa426('0x25')]!==_0x366df2[_0xa426('0x25')][_0xa426('0x30')]()){this['trunks'][_0x366df2[_0xa426('0x2f')]]['stateTime']=_['toNumber'](moment()[_0xa426('0x2a')]('x'));}this['trunks'][_0x366df2[_0xa426('0x2f')]][_0xa426('0x25')]=_0x366df2[_0xa426('0x25')][_0xa426('0x30')]();logger['debug'](_0xa426('0x37'),util[_0xa426('0x1b')](this[_0xa426('0xb')][_0x366df2[_0xa426('0x2f')]],{'showHidden':![],'depth':null}));this[_0xa426('0x20')](util[_0xa426('0x2a')](_0xa426('0x2b'),this[_0xa426('0xb')][_0x366df2['device']][_0xa426('0x2c')]),_0xa426('0x38'),this['trunks'][_0x366df2[_0xa426('0x2f')]]);}else if(_[_0xa426('0x39')](_0x366df2[_0xa426('0x2f')],_0xa426('0x3a'))){var _0x41f0b8=_0x366df2[_0xa426('0x2f')];var _0x73665d=_0x41f0b8[_0xa426('0x3b')](_0x41f0b8[_0xa426('0x3c')]('/')+0x1,_0x41f0b8['indexOf']('@'));var _0x59d87c=_['find'](this[_0xa426('0x2e')],function(_0x4e869d){return _0x4e869d[_0xa426('0x3d')]==_0x73665d||_0x4e869d[_0xa426('0x3e')]==_0x73665d||_0x4e869d[_0xa426('0x3f')]==_0x73665d;});if(_0x59d87c){if(_0x59d87c['state']!==_0x366df2['state'][_0xa426('0x30')]()){_0x59d87c[_0xa426('0x32')]=_[_0xa426('0x33')](moment()['format']('x'));}_0x59d87c['state']=_0x366df2[_0xa426('0x25')]['toLowerCase']();_0x59d87c[_0xa426('0x31')]=!![];_0x59d87c['updateStatusRealtime'](_0x366df2);}}}}catch(_0x463d1a){logger[_0xa426('0x1a')](_0xa426('0x40'),util['inspect'](_0x463d1a,{'showHidden':![],'depth':null}));}};UserReport['prototype'][_0xa426('0x14')]=function(_0x59cdb0){try{if(this[_0xa426('0x1f')](_0x59cdb0)&&this[_0xa426('0x1f')](_0x59cdb0[_0xa426('0x13')])){logger[_0xa426('0x2d')]('[userReport][peerstatus]\x20peer:%s\x20address:%s\x20status:%s',_0x59cdb0['peer'],_0x59cdb0[_0xa426('0x41')],_0x59cdb0['peerstatus']);logger[_0xa426('0x21')](_0xa426('0x42'),util[_0xa426('0x1b')](_0x59cdb0,{'showHidden':![],'depth':null}));if(this[_0xa426('0x2e')][_0x59cdb0[_0xa426('0x43')]]){if(!this['agents'][_0x59cdb0['peer']][_0xa426('0x31')]||_0x59cdb0[_0xa426('0x13')][_0xa426('0x30')]()=='registered'){this[_0xa426('0x2e')][_0x59cdb0['peer']][_0xa426('0x31')]=![];this[_0xa426('0x2e')][_0x59cdb0['peer']]['status']=_0x59cdb0['peerstatus']['toLowerCase']();this[_0xa426('0x2e')][_0x59cdb0['peer']][_0xa426('0x41')]=_0x59cdb0[_0xa426('0x41')];this['agents'][_0x59cdb0[_0xa426('0x43')]][_0xa426('0x34')](_0x59cdb0);}}else if(this[_0xa426('0xc')][_0x59cdb0[_0xa426('0x43')]]){this['telephones'][_0x59cdb0[_0xa426('0x43')]][_0xa426('0x44')]=_0x59cdb0[_0xa426('0x13')][_0xa426('0x30')]();this[_0xa426('0xc')][_0x59cdb0[_0xa426('0x43')]][_0xa426('0x41')]=_0x59cdb0['address'];logger[_0xa426('0x21')](_0xa426('0x45'),util['inspect'](this[_0xa426('0xc')][_0x59cdb0[_0xa426('0x43')]],{'showHidden':![],'depth':null}));this[_0xa426('0x20')](util[_0xa426('0x2a')](_0xa426('0x35'),this[_0xa426('0xc')][_0x59cdb0[_0xa426('0x43')]][_0xa426('0x2c')]),'telephone:save',this[_0xa426('0xc')][_0x59cdb0[_0xa426('0x43')]]);}else if(this[_0xa426('0xb')][_0x59cdb0['peer']]){this['trunks'][_0x59cdb0[_0xa426('0x43')]][_0xa426('0x44')]=_0x59cdb0['peerstatus'][_0xa426('0x30')]();this[_0xa426('0xb')][_0x59cdb0[_0xa426('0x43')]][_0xa426('0x41')]=_0x59cdb0[_0xa426('0x41')];logger[_0xa426('0x21')](_0xa426('0x46'),util['inspect'](this[_0xa426('0xb')][_0x59cdb0[_0xa426('0x43')]],{'showHidden':![],'depth':null}));this[_0xa426('0x20')](util[_0xa426('0x2a')](_0xa426('0x2b'),this[_0xa426('0xb')][_0x59cdb0[_0xa426('0x43')]][_0xa426('0x2c')]),'trunk:save',this[_0xa426('0xb')][_0x59cdb0[_0xa426('0x43')]]);}}}catch(_0x19b7f3){logger[_0xa426('0x1a')](_0xa426('0x42'),util[_0xa426('0x1b')](_0x19b7f3,{'showHidden':![],'depth':null}));}};module['exports']=UserReport;