Built motion from commit (unavailable).|2.0.70
[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 _0x52f4=['syncDeviceState','device','toLowerCase','stateTime','toNumber','telephone:%s','name','telephone:save','Queue','[syncDeviceState][UserReport]','peerstatus','peer','status','address','updateStatusRealtime','error','[syncPeerStatus][UserReport]','lodash','moment','bluebird','util','../../../config/logger','../ami','socket.io-emitter','localhost','trunks','agents','telephones','registryentry','syncRegistry','bind','registry','syncPeerStatus','loopSyncRealTimeShow','then','actionSipShowRegistry','actionDeviceStateList','actionSipPeerStatus','catch','[loopSyncRealTimeShow]','inspect','resolve','prototype','isNotNull','emit','find','username','state','event','actionid','format','trunk:%s','trunk:save','[syncRegistry][UserReport]'];(function(_0x5a8f4d,_0x45ef8b){var _0x413c9b=function(_0x2f561d){while(--_0x2f561d){_0x5a8f4d['push'](_0x5a8f4d['shift']());}};_0x413c9b(++_0x45ef8b);}(_0x52f4,0x18b));var _0x452f=function(_0x40f785,_0x457266){_0x40f785=_0x40f785-0x0;var _0xd7d39b=_0x52f4[_0x40f785];return _0xd7d39b;};'use strict';var _=require(_0x452f('0x0'));var moment=require(_0x452f('0x1'));var BPromise=require(_0x452f('0x2'));var util=require(_0x452f('0x3'));var logger=require(_0x452f('0x4'))('ami');var ami=require(_0x452f('0x5'));var io=require(_0x452f('0x6'))({'host':_0x452f('0x7'),'port':0x18eb});function UserReport(_0x5083c7){this[_0x452f('0x8')]=_0x5083c7[_0x452f('0x8')];this[_0x452f('0x9')]=_0x5083c7[_0x452f('0x9')];this[_0x452f('0xa')]=_0x5083c7['telephones'];ami['on'](_0x452f('0xb'),this[_0x452f('0xc')][_0x452f('0xd')](this));ami['on'](_0x452f('0xe'),this[_0x452f('0xc')][_0x452f('0xd')](this));ami['on']('devicestatechange',this['syncDeviceState']['bind'](this));ami['on']('peerstatus',this[_0x452f('0xf')][_0x452f('0xd')](this));this[_0x452f('0x10')]();return BPromise['resolve']()[_0x452f('0x11')](ami[_0x452f('0x12')]())[_0x452f('0x11')](ami[_0x452f('0x13')]())[_0x452f('0x11')](ami[_0x452f('0x14')]())[_0x452f('0x15')](loggerCatch(_0x452f('0x16')));}function loggerCatch(_0x18fc97){return function(_0x55ff23){logger['error'](_0x18fc97,util[_0x452f('0x17')](_0x55ff23,{'showHidden':![],'depth':null}));};}UserReport['prototype'][_0x452f('0x10')]=function(){setInterval(function(){BPromise[_0x452f('0x18')]()['then'](ami[_0x452f('0x12')]())[_0x452f('0x11')](ami[_0x452f('0x13')]())[_0x452f('0x11')](ami[_0x452f('0x14')]())[_0x452f('0x15')](loggerCatch(_0x452f('0x16')));},0x32c8);};UserReport[_0x452f('0x19')][_0x452f('0x1a')]=function(_0x792d78){return _0x792d78!==null&&!_['isUndefined'](_0x792d78);};UserReport['prototype'][_0x452f('0x1b')]=function(_0x5efc1c,_0x2e768e,_0x15e3cc){io['to'](_0x5efc1c)[_0x452f('0x1b')](_0x2e768e,_0x15e3cc);};UserReport[_0x452f('0x19')][_0x452f('0xc')]=function(_0x5108b3){try{if(this[_0x452f('0x1a')](_0x5108b3)){var _0x1fbe49=_[_0x452f('0x1c')](this[_0x452f('0x8')],{'registry':_0x5108b3[_0x452f('0x1d')]});if(_0x1fbe49){_0x5108b3['stateRegistry']=_0x5108b3[_0x452f('0x1e')];_['merge'](_0x1fbe49,_['omit'](_0x5108b3,[_0x452f('0x1f'),_0x452f('0x20'),'username',_0x452f('0x1e')]));this['emit'](util[_0x452f('0x21')](_0x452f('0x22'),_0x1fbe49['name']),_0x452f('0x23'),_0x1fbe49);}}}catch(_0x1a7a80){logger['error'](_0x452f('0x24'),util[_0x452f('0x17')](_0x1a7a80,{'showHidden':![],'depth':null}));}};UserReport[_0x452f('0x19')][_0x452f('0x25')]=function(_0x4b1f7a){try{if(this[_0x452f('0x1a')](_0x4b1f7a)){if(this[_0x452f('0x9')][_0x4b1f7a['device']]){if(this[_0x452f('0x9')][_0x4b1f7a[_0x452f('0x26')]][_0x452f('0x1e')]!==_0x4b1f7a['state'][_0x452f('0x27')]()){this[_0x452f('0x9')][_0x4b1f7a['device']][_0x452f('0x28')]=_['toNumber'](moment()[_0x452f('0x21')]('x'));}this[_0x452f('0x9')][_0x4b1f7a[_0x452f('0x26')]][_0x452f('0x1e')]=_0x4b1f7a[_0x452f('0x1e')][_0x452f('0x27')]();this['agents'][_0x4b1f7a['device']]['updateStatusRealtime'](_0x4b1f7a);}else if(this[_0x452f('0xa')][_0x4b1f7a['device']]){if(this[_0x452f('0xa')][_0x4b1f7a['device']][_0x452f('0x1e')]!==_0x4b1f7a[_0x452f('0x1e')][_0x452f('0x27')]()){this[_0x452f('0xa')][_0x4b1f7a['device']][_0x452f('0x28')]=_[_0x452f('0x29')](moment()[_0x452f('0x21')]('x'));}this[_0x452f('0xa')][_0x4b1f7a[_0x452f('0x26')]]['state']=_0x4b1f7a[_0x452f('0x1e')]['toLowerCase']();this[_0x452f('0x1b')](util[_0x452f('0x21')](_0x452f('0x2a'),this[_0x452f('0xa')][_0x4b1f7a['device']][_0x452f('0x2b')]),_0x452f('0x2c'),this[_0x452f('0xa')][_0x4b1f7a[_0x452f('0x26')]]);}else if(this[_0x452f('0x8')][_0x4b1f7a['device']]){if(this[_0x452f('0x8')][_0x4b1f7a[_0x452f('0x26')]][_0x452f('0x1e')]!==_0x4b1f7a['state'][_0x452f('0x27')]()){this['trunks'][_0x4b1f7a['device']]['stateTime']=_[_0x452f('0x29')](moment()[_0x452f('0x21')]('x'));}this[_0x452f('0x8')][_0x4b1f7a['device']][_0x452f('0x1e')]=_0x4b1f7a[_0x452f('0x1e')][_0x452f('0x27')]();this[_0x452f('0x1b')](util[_0x452f('0x21')](_0x452f('0x22'),this[_0x452f('0x8')][_0x4b1f7a['device']][_0x452f('0x2b')]),_0x452f('0x23'),this[_0x452f('0x8')][_0x4b1f7a['device']]);}else if(_['startsWith'](_0x4b1f7a[_0x452f('0x26')],_0x452f('0x2d'))){}else{}}}catch(_0x1ab1df){logger['error'](_0x452f('0x2e'),util[_0x452f('0x17')](_0x1ab1df,{'showHidden':![],'depth':null}));}};UserReport[_0x452f('0x19')][_0x452f('0xf')]=function(_0x7b6d63){try{if(this[_0x452f('0x1a')](_0x7b6d63)&&this[_0x452f('0x1a')](_0x7b6d63[_0x452f('0x2f')])){if(this[_0x452f('0x9')][_0x7b6d63[_0x452f('0x30')]]){this[_0x452f('0x9')][_0x7b6d63[_0x452f('0x30')]][_0x452f('0x31')]=_0x7b6d63[_0x452f('0x2f')][_0x452f('0x27')]();this[_0x452f('0x9')][_0x7b6d63[_0x452f('0x30')]][_0x452f('0x32')]=_0x7b6d63[_0x452f('0x32')];this[_0x452f('0x9')][_0x7b6d63[_0x452f('0x30')]][_0x452f('0x33')](_0x7b6d63);}else if(this[_0x452f('0xa')][_0x7b6d63[_0x452f('0x30')]]){this[_0x452f('0xa')][_0x7b6d63[_0x452f('0x30')]]['status']=_0x7b6d63[_0x452f('0x2f')][_0x452f('0x27')]();this[_0x452f('0xa')][_0x7b6d63[_0x452f('0x30')]][_0x452f('0x32')]=_0x7b6d63[_0x452f('0x32')];this['emit'](util[_0x452f('0x21')](_0x452f('0x2a'),this['telephones'][_0x7b6d63[_0x452f('0x30')]]['name']),_0x452f('0x2c'),this['telephones'][_0x7b6d63[_0x452f('0x30')]]);}else if(this[_0x452f('0x8')][_0x7b6d63[_0x452f('0x30')]]){this[_0x452f('0x8')][_0x7b6d63[_0x452f('0x30')]][_0x452f('0x31')]=_0x7b6d63['peerstatus'][_0x452f('0x27')]();this[_0x452f('0x8')][_0x7b6d63[_0x452f('0x30')]][_0x452f('0x32')]=_0x7b6d63[_0x452f('0x32')];this['emit'](util['format'](_0x452f('0x22'),this['trunks'][_0x7b6d63[_0x452f('0x30')]][_0x452f('0x2b')]),_0x452f('0x23'),this['trunks'][_0x7b6d63[_0x452f('0x30')]]);}else{}}}catch(_0x10da5c){logger[_0x452f('0x34')](_0x452f('0x35'),util[_0x452f('0x17')](_0x10da5c,{'showHidden':![],'depth':null}));}};module['exports']=UserReport;