2e5c5ddb2479893ccf19d1c4ddc1e0e6b1191baa
[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 _0x41d0=['writeLog','TIMEOUT','removeWaitingNotification','exports','lodash','uuid','./util','../../../../../config/logger','notificationId','squeue','queue','realtime','intervals','bind','module','timeout','handleTimeout','drained','prototype','push','handleDrained','handleCheckReject','isAgentAvailable','agents','[%s][QUEUE]\x20available\x20again\x20%s','agentId','done','mapAgentsId','debug','isNil','channel','busy','busyQueue','saveWaitingNotification','routing','showNotification','RINGING','[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','hideNotification'];(function(_0x2bfc7d,_0x1e314f){var _0x148405=function(_0x43748a){while(--_0x43748a){_0x2bfc7d['push'](_0x2bfc7d['shift']());}};_0x148405(++_0x1e314f);}(_0x41d0,0x1bc));var _0x041d=function(_0x1cb74c,_0x248486){_0x1cb74c=_0x1cb74c-0x0;var _0x511253=_0x41d0[_0x1cb74c];return _0x511253;};'use strict';var rr=require('rr');var _=require(_0x041d('0x0'));var uuid=require(_0x041d('0x1'));var util=require(_0x041d('0x2'));var logger=require(_0x041d('0x3'))('routing');var RRMemory=function(_0x56c028,_0x23dc81,_0x573fa4,_0x16cdda){this[_0x041d('0x4')]=uuid['v4']();this[_0x041d('0x5')]=_0x56c028;this[_0x041d('0x6')]=_0x23dc81;this[_0x041d('0x7')]=_0x573fa4;this['routing']=_0x16cdda;this[_0x041d('0x8')]={};this[_0x041d('0x5')]['push'](this['handleRun'][_0x041d('0x9')](this),this['handleTimeout'][_0x041d('0x9')](this),this[_0x041d('0xa')]);this[_0x041d('0x5')]['on'](_0x041d('0xb'),this[_0x041d('0xc')][_0x041d('0x9')](this));this['squeue']['on'](_0x041d('0xd'),this['handleDrained'][_0x041d('0x9')](this));};RRMemory[_0x041d('0xe')][_0x041d('0xf')]=function(){this[_0x041d('0x5')]['push'](this['handleRun'][_0x041d('0x9')](this),this[_0x041d('0xc')][_0x041d('0x9')](this));};RRMemory[_0x041d('0xe')][_0x041d('0x10')]=function(){this['handleTimeout'](!![]);};RRMemory[_0x041d('0xe')][_0x041d('0x11')]=function(_0x2654ea){if(util[_0x041d('0x12')](this[_0x041d('0x5')]['id'],this[_0x041d('0x7')][_0x041d('0x13')][this['agentId']],this['squeue']['channel'],!![])){logger['debug'](_0x041d('0x14'),this[_0x041d('0x5')]['id'],this[_0x041d('0x15')]);clearInterval(this[_0x041d('0x8')][this[_0x041d('0x15')]]);_0x2654ea[_0x041d('0x16')]();setTimeout(this[_0x041d('0xf')][_0x041d('0x9')](this),0x3e8);}};RRMemory['prototype']['handleRun']=function(_0x9150f9){this['agentId']=rr(this[_0x041d('0x6')][_0x041d('0x17')]);logger[_0x041d('0x18')]('[%s][QUEUE]\x20try\x20with\x20%s',this['squeue']['id'],this[_0x041d('0x15')]);if(_[_0x041d('0x19')](this[_0x041d('0x7')][_0x041d('0x13')][this[_0x041d('0x15')]])){logger[_0x041d('0x18')]('[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this['squeue']['id'],this[_0x041d('0x15')]);_0x9150f9[_0x041d('0x16')]();setTimeout(this['push']['bind'](this),0x3e8);}else{if(util[_0x041d('0x12')](this[_0x041d('0x5')]['id'],this[_0x041d('0x7')][_0x041d('0x13')][this[_0x041d('0x15')]],this[_0x041d('0x5')][_0x041d('0x1a')],!![])){this[_0x041d('0x7')][_0x041d('0x13')][this[_0x041d('0x15')]][_0x041d('0x1b')]=!![];this[_0x041d('0x7')][_0x041d('0x13')][this[_0x041d('0x15')]][_0x041d('0x1c')]=this[_0x041d('0x6')]['name'];util[_0x041d('0x1d')](this['realtime'],this[_0x041d('0x1e')],this[_0x041d('0x7')][_0x041d('0x13')][this[_0x041d('0x15')]],this[_0x041d('0x5')][_0x041d('0x1a')]);util[_0x041d('0x1f')](this[_0x041d('0x4')],this[_0x041d('0x5')]['id'],this[_0x041d('0x7')][_0x041d('0x13')][this[_0x041d('0x15')]],this['queue'],this[_0x041d('0x1e')]);util['writeLog'](this['squeue']['id'],this[_0x041d('0x7')]['agents'][this['agentId']],_0x041d('0x20'));this['intervals'][this[_0x041d('0x15')]]=setInterval(this['handleCheckReject'][_0x041d('0x9')](this,_0x9150f9),0x3e8);}else{logger['debug'](_0x041d('0x21'),this[_0x041d('0x5')]['id'],this[_0x041d('0x15')]);_0x9150f9[_0x041d('0x16')]();setTimeout(this[_0x041d('0xf')][_0x041d('0x9')](this),0x3e8);}}};RRMemory[_0x041d('0xe')]['handleTimeout']=function(_0x33902f){logger[_0x041d('0x18')]('[%s][QUEUE]\x20timeout\x20with\x20%s',this[_0x041d('0x5')]['id'],this[_0x041d('0x15')]);if(_[_0x041d('0x19')](this['realtime'][_0x041d('0x13')][this[_0x041d('0x15')]])){logger[_0x041d('0x18')](_0x041d('0x22'),this[_0x041d('0x5')]['id'],this[_0x041d('0x15')]);}else{clearInterval(this[_0x041d('0x8')][this['agentId']]);util[_0x041d('0x23')](this[_0x041d('0x4')],this[_0x041d('0x5')]['id'],this[_0x041d('0x7')][_0x041d('0x13')][this[_0x041d('0x15')]],this[_0x041d('0x6')],this[_0x041d('0x1e')]);util[_0x041d('0x24')](this['squeue']['id'],this[_0x041d('0x7')][_0x041d('0x13')][this[_0x041d('0x15')]],_0x041d('0x25'));this[_0x041d('0x7')][_0x041d('0x13')][this[_0x041d('0x15')]][_0x041d('0x1b')]=![];this[_0x041d('0x7')]['agents'][this[_0x041d('0x15')]]['busyQueue']=undefined;util[_0x041d('0x26')](this['realtime'],this['routing'],this[_0x041d('0x7')]['agents'][this['agentId']],this[_0x041d('0x5')][_0x041d('0x1a')]);}if(!_0x33902f){setTimeout(this['push'][_0x041d('0x9')](this),0x3e8);}};function rrmemory(_0x47b022,_0x95708d,_0x11056b,_0x188727){return new RRMemory(_0x47b022,_0x95708d,_0x11056b,_0x188727);}module[_0x041d('0x27')]=rrmemory;