a3b4b2d346882d8887e81011532f99f463dbd06a
[motion2.git] / server / services / routing / server / applications / strategy / rrmemory.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 _0xd912=['module','squeue','timeout','handleDrained','prototype','handleCheckReject','isAgentAvailable','agents','agentId','debug','[%s][QUEUE]\x20available\x20again\x20%s','intervals','done','mapAgentsId','[%s][QUEUE]\x20try\x20with\x20%s','isNil','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','channel','busy','busyQueue','name','saveWaitingNotification','showNotification','writeLog','[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s','hideNotification','TIMEOUT','exports','uuid','./util','../../../../../config/logger','routing','queue','realtime','push','handleRun','bind','handleTimeout'];(function(_0x485d7b,_0x3f3b52){var _0x899877=function(_0x34639c){while(--_0x34639c){_0x485d7b['push'](_0x485d7b['shift']());}};_0x899877(++_0x3f3b52);}(_0xd912,0x172));var _0x2d91=function(_0x432682,_0x253044){_0x432682=_0x432682-0x0;var _0x463d05=_0xd912[_0x432682];return _0x463d05;};'use strict';var rr=require('rr');var _=require('lodash');var uuid=require(_0x2d91('0x0'));var util=require(_0x2d91('0x1'));var logger=require(_0x2d91('0x2'))(_0x2d91('0x3'));var RRMemory=function(_0xaf76c6,_0x540130,_0x35a006,_0x5a0277){this['notificationId']=uuid['v4']();this['squeue']=_0xaf76c6;this[_0x2d91('0x4')]=_0x540130;this[_0x2d91('0x5')]=_0x35a006;this[_0x2d91('0x3')]=_0x5a0277;this['intervals']={};this['squeue'][_0x2d91('0x6')](this[_0x2d91('0x7')][_0x2d91('0x8')](this),this[_0x2d91('0x9')]['bind'](this),this[_0x2d91('0xa')]);this[_0x2d91('0xb')]['on'](_0x2d91('0xc'),this[_0x2d91('0x9')]['bind'](this));this['squeue']['on']('drained',this[_0x2d91('0xd')][_0x2d91('0x8')](this));};RRMemory[_0x2d91('0xe')][_0x2d91('0x6')]=function(){this['squeue'][_0x2d91('0x6')](this['handleRun'][_0x2d91('0x8')](this),this[_0x2d91('0x9')]['bind'](this));};RRMemory['prototype'][_0x2d91('0xd')]=function(){this['handleTimeout'](!![]);};RRMemory[_0x2d91('0xe')][_0x2d91('0xf')]=function(_0x152754){if(util[_0x2d91('0x10')](this[_0x2d91('0xb')]['id'],this[_0x2d91('0x5')][_0x2d91('0x11')][this[_0x2d91('0x12')]],this[_0x2d91('0xb')]['channel'],!![])){logger[_0x2d91('0x13')](_0x2d91('0x14'),this[_0x2d91('0xb')]['id'],this[_0x2d91('0x12')]);clearInterval(this[_0x2d91('0x15')][this[_0x2d91('0x12')]]);_0x152754[_0x2d91('0x16')]();setTimeout(this['push'][_0x2d91('0x8')](this),0x3e8);}};RRMemory[_0x2d91('0xe')][_0x2d91('0x7')]=function(_0x5882a8){this['agentId']=rr(this[_0x2d91('0x4')][_0x2d91('0x17')]);logger['debug'](_0x2d91('0x18'),this[_0x2d91('0xb')]['id'],this[_0x2d91('0x12')]);if(_[_0x2d91('0x19')](this['realtime'][_0x2d91('0x11')][this[_0x2d91('0x12')]])){logger[_0x2d91('0x13')](_0x2d91('0x1a'),this['squeue']['id'],this['agentId']);_0x5882a8['done']();setTimeout(this[_0x2d91('0x6')][_0x2d91('0x8')](this),0x3e8);}else{if(util[_0x2d91('0x10')](this[_0x2d91('0xb')]['id'],this[_0x2d91('0x5')][_0x2d91('0x11')][this[_0x2d91('0x12')]],this[_0x2d91('0xb')][_0x2d91('0x1b')],!![])){this['realtime'][_0x2d91('0x11')][this[_0x2d91('0x12')]][_0x2d91('0x1c')]=!![];this[_0x2d91('0x5')][_0x2d91('0x11')][this[_0x2d91('0x12')]][_0x2d91('0x1d')]=this[_0x2d91('0x4')][_0x2d91('0x1e')];util[_0x2d91('0x1f')](this[_0x2d91('0x5')],this['routing'],this[_0x2d91('0x5')][_0x2d91('0x11')][this[_0x2d91('0x12')]],this[_0x2d91('0xb')]['channel']);util[_0x2d91('0x20')](this['notificationId'],this[_0x2d91('0xb')]['id'],this[_0x2d91('0x5')][_0x2d91('0x11')][this['agentId']],this[_0x2d91('0x4')],this['routing']);util[_0x2d91('0x21')](this[_0x2d91('0xb')]['id'],this['realtime']['agents'][this[_0x2d91('0x12')]],'RINGING');this[_0x2d91('0x15')][this[_0x2d91('0x12')]]=setInterval(this[_0x2d91('0xf')][_0x2d91('0x8')](this,_0x5882a8),0x3e8);}else{logger['debug'](_0x2d91('0x22'),this[_0x2d91('0xb')]['id'],this['agentId']);_0x5882a8[_0x2d91('0x16')]();setTimeout(this[_0x2d91('0x6')][_0x2d91('0x8')](this),0x3e8);}}};RRMemory[_0x2d91('0xe')]['handleTimeout']=function(_0x4f7753){logger['debug']('[%s][QUEUE]\x20timeout\x20with\x20%s',this[_0x2d91('0xb')]['id'],this[_0x2d91('0x12')]);if(_[_0x2d91('0x19')](this[_0x2d91('0x5')][_0x2d91('0x11')][this['agentId']])){logger[_0x2d91('0x13')]('[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0x2d91('0xb')]['id'],this['agentId']);}else{clearInterval(this[_0x2d91('0x15')][this['agentId']]);util[_0x2d91('0x23')](this['notificationId'],this[_0x2d91('0xb')]['id'],this[_0x2d91('0x5')][_0x2d91('0x11')][this[_0x2d91('0x12')]],this['queue'],this[_0x2d91('0x3')]);util[_0x2d91('0x21')](this[_0x2d91('0xb')]['id'],this[_0x2d91('0x5')][_0x2d91('0x11')][this[_0x2d91('0x12')]],_0x2d91('0x24'));this[_0x2d91('0x5')][_0x2d91('0x11')][this[_0x2d91('0x12')]][_0x2d91('0x1c')]=![];this[_0x2d91('0x5')][_0x2d91('0x11')][this[_0x2d91('0x12')]][_0x2d91('0x1d')]=undefined;util['removeWaitingNotification'](this[_0x2d91('0x5')],this[_0x2d91('0x3')],this[_0x2d91('0x5')][_0x2d91('0x11')][this[_0x2d91('0x12')]],this['squeue']['channel']);}if(!_0x4f7753){setTimeout(this[_0x2d91('0x6')]['bind'](this),0x3e8);}};function rrmemory(_0x563621,_0x1efc4c,_0x19ba9a,_0x33ea15){return new RRMemory(_0x563621,_0x1efc4c,_0x19ba9a,_0x33ea15);}module[_0x2d91('0x25')]=rrmemory;