Built motion from commit 25580385.|2.6.2
[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 _0x9606=['info','[%s][QUEUE]\x20available\x20again\x20%s','done','queue','mapAgentsId','[%s][QUEUE]\x20try\x20with\x20%s','isNil','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','isAgentAvailable','channel','busy','busyQueue','name','showNotification','writeLog','RINGING','hideNotification','exports','lodash','uuid','./util','../../../../../config/logger','notificationId','squeue','realtime','routing','intervals','push','handleRun','handleTimeout','module','timeout','bind','drained','handleDrained','prototype','handleCheckReject','agents','agentId'];(function(_0x32ad62,_0x56598c){var _0x2179ab=function(_0xf6ff36){while(--_0xf6ff36){_0x32ad62['push'](_0x32ad62['shift']());}};_0x2179ab(++_0x56598c);}(_0x9606,0x14a));var _0x6960=function(_0x3b1025,_0x17ccfc){_0x3b1025=_0x3b1025-0x0;var _0xbb4860=_0x9606[_0x3b1025];return _0xbb4860;};'use strict';var rr=require('rr');var _=require(_0x6960('0x0'));var uuid=require(_0x6960('0x1'));var util=require(_0x6960('0x2'));var logger=require(_0x6960('0x3'))('routing');var RRMemory=function(_0x4ad528,_0x5e79d3,_0xa92580,_0x11ee7c){this[_0x6960('0x4')]=uuid['v4']();this[_0x6960('0x5')]=_0x4ad528;this['queue']=_0x5e79d3;this[_0x6960('0x6')]=_0xa92580;this[_0x6960('0x7')]=_0x11ee7c;this[_0x6960('0x8')]={};this['squeue'][_0x6960('0x9')](this[_0x6960('0xa')]['bind'](this),this[_0x6960('0xb')]['bind'](this),this[_0x6960('0xc')]);this[_0x6960('0x5')]['on'](_0x6960('0xd'),this['handleTimeout'][_0x6960('0xe')](this));this[_0x6960('0x5')]['on'](_0x6960('0xf'),this[_0x6960('0x10')][_0x6960('0xe')](this));};RRMemory['prototype'][_0x6960('0x9')]=function(){this[_0x6960('0x5')]['push'](this[_0x6960('0xa')][_0x6960('0xe')](this),this[_0x6960('0xb')][_0x6960('0xe')](this));};RRMemory[_0x6960('0x11')][_0x6960('0x10')]=function(_0x5e200e){this[_0x6960('0xb')](!![]);};RRMemory[_0x6960('0x11')][_0x6960('0x12')]=function(_0x490e49){if(util['isAgentAvailable'](this['squeue']['id'],this[_0x6960('0x6')][_0x6960('0x13')][this[_0x6960('0x14')]],this[_0x6960('0x5')]['channel'],!![])){logger[_0x6960('0x15')](_0x6960('0x16'),this[_0x6960('0x5')]['id'],this[_0x6960('0x14')]);clearInterval(this[_0x6960('0x8')][this[_0x6960('0x14')]]);_0x490e49[_0x6960('0x17')]();setTimeout(this['push'][_0x6960('0xe')](this),0x3e8);}};RRMemory[_0x6960('0x11')][_0x6960('0xa')]=function(_0x31d1f8){this['agentId']=rr(this[_0x6960('0x18')][_0x6960('0x19')]);logger[_0x6960('0x15')](_0x6960('0x1a'),this[_0x6960('0x5')]['id'],this['agentId']);if(_[_0x6960('0x1b')](this[_0x6960('0x6')][_0x6960('0x13')][this[_0x6960('0x14')]])){logger[_0x6960('0x15')](_0x6960('0x1c'),this[_0x6960('0x5')]['id'],this['agentId']);_0x31d1f8[_0x6960('0x17')]();setTimeout(this['push']['bind'](this),0x3e8);}else{if(util[_0x6960('0x1d')](this[_0x6960('0x5')]['id'],this['realtime'][_0x6960('0x13')][this['agentId']],this[_0x6960('0x5')][_0x6960('0x1e')],!![])){this[_0x6960('0x6')][_0x6960('0x13')][this[_0x6960('0x14')]][_0x6960('0x1f')]=!![];this[_0x6960('0x6')][_0x6960('0x13')][this[_0x6960('0x14')]][_0x6960('0x20')]=this[_0x6960('0x18')][_0x6960('0x21')];util[_0x6960('0x22')](this[_0x6960('0x4')],this[_0x6960('0x5')]['id'],this[_0x6960('0x6')]['agents'][this[_0x6960('0x14')]],this['queue'],this['routing']);util[_0x6960('0x23')](this['squeue']['id'],this['realtime'][_0x6960('0x13')][this['agentId']],_0x6960('0x24'));this[_0x6960('0x8')][this[_0x6960('0x14')]]=setInterval(this[_0x6960('0x12')]['bind'](this,_0x31d1f8),0x3e8);}else{logger[_0x6960('0x15')]('[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s',this[_0x6960('0x5')]['id'],this[_0x6960('0x14')]);_0x31d1f8[_0x6960('0x17')]();setTimeout(this[_0x6960('0x9')][_0x6960('0xe')](this),0x3e8);}}};RRMemory[_0x6960('0x11')]['handleTimeout']=function(_0x2c4ef7){logger[_0x6960('0x15')]('[%s][QUEUE]\x20timeout\x20with\x20%s',this[_0x6960('0x5')]['id'],this[_0x6960('0x14')]);if(_[_0x6960('0x1b')](this[_0x6960('0x6')][_0x6960('0x13')][this[_0x6960('0x14')]])){logger[_0x6960('0x15')]('[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0x6960('0x5')]['id'],this['agentId']);}else{clearInterval(this['intervals'][this[_0x6960('0x14')]]);util[_0x6960('0x25')](this[_0x6960('0x4')],this['squeue']['id'],this[_0x6960('0x6')][_0x6960('0x13')][this[_0x6960('0x14')]],this[_0x6960('0x18')],this[_0x6960('0x7')]);util[_0x6960('0x23')](this['squeue']['id'],this['realtime'][_0x6960('0x13')][this[_0x6960('0x14')]],'TIMEOUT');this[_0x6960('0x6')][_0x6960('0x13')][this[_0x6960('0x14')]]['busy']=![];this['realtime']['agents'][this[_0x6960('0x14')]][_0x6960('0x20')]=undefined;}if(!_0x2c4ef7){setTimeout(this['push']['bind'](this),0x3e8);}};function rrmemory(_0x28145e,_0xbe1519,_0x3a1b2d,_0x2c79e0){return new RRMemory(_0x28145e,_0xbe1519,_0x3a1b2d,_0x2c79e0);}module[_0x6960('0x26')]=rrmemory;