d7ebbffc301118b69eb2bbf0f3e24f7557671747
[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 _0x8a36=['[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','hideNotification','removeWaitingNotification','uuid','./util','../../../../../config/logger','routing','notificationId','squeue','queue','intervals','push','bind','handleTimeout','timeout','drained','handleDrained','prototype','handleRun','handleCheckReject','isAgentAvailable','realtime','agents','agentId','debug','done','mapAgentsId','channel','busyQueue','name','saveWaitingNotification','showNotification','writeLog','RINGING','[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s','[%s][QUEUE]\x20timeout\x20with\x20%s','isNil'];(function(_0x24237f,_0x4cf32c){var _0x48298e=function(_0x3f7511){while(--_0x3f7511){_0x24237f['push'](_0x24237f['shift']());}};_0x48298e(++_0x4cf32c);}(_0x8a36,0x175));var _0x68a3=function(_0x530f95,_0x44de23){_0x530f95=_0x530f95-0x0;var _0x2d4673=_0x8a36[_0x530f95];return _0x2d4673;};'use strict';var rr=require('rr');var _=require('lodash');var uuid=require(_0x68a3('0x0'));var util=require(_0x68a3('0x1'));var logger=require(_0x68a3('0x2'))(_0x68a3('0x3'));var RRMemory=function(_0x58bde5,_0x204a56,_0x10ce28,_0x2bdc1d){this[_0x68a3('0x4')]=uuid['v4']();this[_0x68a3('0x5')]=_0x58bde5;this[_0x68a3('0x6')]=_0x204a56;this['realtime']=_0x10ce28;this[_0x68a3('0x3')]=_0x2bdc1d;this[_0x68a3('0x7')]={};this[_0x68a3('0x5')][_0x68a3('0x8')](this['handleRun'][_0x68a3('0x9')](this),this[_0x68a3('0xa')][_0x68a3('0x9')](this),this['module']);this[_0x68a3('0x5')]['on'](_0x68a3('0xb'),this['handleTimeout'][_0x68a3('0x9')](this));this[_0x68a3('0x5')]['on'](_0x68a3('0xc'),this[_0x68a3('0xd')][_0x68a3('0x9')](this));};RRMemory[_0x68a3('0xe')][_0x68a3('0x8')]=function(){this['squeue']['push'](this[_0x68a3('0xf')][_0x68a3('0x9')](this),this[_0x68a3('0xa')][_0x68a3('0x9')](this));};RRMemory['prototype'][_0x68a3('0xd')]=function(){this[_0x68a3('0xa')](!![]);};RRMemory[_0x68a3('0xe')][_0x68a3('0x10')]=function(_0x2529fe){if(util[_0x68a3('0x11')](this['squeue']['id'],this[_0x68a3('0x12')][_0x68a3('0x13')][this[_0x68a3('0x14')]],this[_0x68a3('0x5')]['channel'],!![])){logger[_0x68a3('0x15')]('[%s][QUEUE]\x20available\x20again\x20%s',this[_0x68a3('0x5')]['id'],this['agentId']);clearInterval(this[_0x68a3('0x7')][this[_0x68a3('0x14')]]);_0x2529fe[_0x68a3('0x16')]();setTimeout(this[_0x68a3('0x8')][_0x68a3('0x9')](this),0x3e8);}};RRMemory[_0x68a3('0xe')][_0x68a3('0xf')]=function(_0x3afcbf){this[_0x68a3('0x14')]=rr(this[_0x68a3('0x6')][_0x68a3('0x17')]);logger[_0x68a3('0x15')]('[%s][QUEUE]\x20try\x20with\x20%s',this['squeue']['id'],this[_0x68a3('0x14')]);if(_['isNil'](this[_0x68a3('0x12')][_0x68a3('0x13')][this[_0x68a3('0x14')]])){logger[_0x68a3('0x15')]('[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0x68a3('0x5')]['id'],this[_0x68a3('0x14')]);_0x3afcbf[_0x68a3('0x16')]();setTimeout(this[_0x68a3('0x8')][_0x68a3('0x9')](this),0x3e8);}else{if(util[_0x68a3('0x11')](this[_0x68a3('0x5')]['id'],this[_0x68a3('0x12')][_0x68a3('0x13')][this['agentId']],this['squeue'][_0x68a3('0x18')],!![])){this[_0x68a3('0x12')][_0x68a3('0x13')][this[_0x68a3('0x14')]]['busy']=!![];this[_0x68a3('0x12')]['agents'][this[_0x68a3('0x14')]][_0x68a3('0x19')]=this[_0x68a3('0x6')][_0x68a3('0x1a')];util[_0x68a3('0x1b')](this[_0x68a3('0x12')],this[_0x68a3('0x3')],this[_0x68a3('0x12')][_0x68a3('0x13')][this[_0x68a3('0x14')]],this[_0x68a3('0x5')][_0x68a3('0x18')]);util[_0x68a3('0x1c')](this[_0x68a3('0x4')],this['squeue']['id'],this[_0x68a3('0x12')][_0x68a3('0x13')][this['agentId']],this[_0x68a3('0x6')],this['routing']);util[_0x68a3('0x1d')](this['squeue']['id'],this[_0x68a3('0x12')][_0x68a3('0x13')][this['agentId']],_0x68a3('0x1e'));this['intervals'][this[_0x68a3('0x14')]]=setInterval(this[_0x68a3('0x10')][_0x68a3('0x9')](this,_0x3afcbf),0x3e8);}else{logger[_0x68a3('0x15')](_0x68a3('0x1f'),this[_0x68a3('0x5')]['id'],this['agentId']);_0x3afcbf[_0x68a3('0x16')]();setTimeout(this[_0x68a3('0x8')][_0x68a3('0x9')](this),0x3e8);}}};RRMemory[_0x68a3('0xe')]['handleTimeout']=function(_0x5338ed){logger[_0x68a3('0x15')](_0x68a3('0x20'),this[_0x68a3('0x5')]['id'],this[_0x68a3('0x14')]);if(_[_0x68a3('0x21')](this['realtime']['agents'][this['agentId']])){logger[_0x68a3('0x15')](_0x68a3('0x22'),this[_0x68a3('0x5')]['id'],this[_0x68a3('0x14')]);}else{clearInterval(this[_0x68a3('0x7')][this[_0x68a3('0x14')]]);util[_0x68a3('0x23')](this[_0x68a3('0x4')],this['squeue']['id'],this[_0x68a3('0x12')]['agents'][this[_0x68a3('0x14')]],this[_0x68a3('0x6')],this[_0x68a3('0x3')]);util[_0x68a3('0x1d')](this[_0x68a3('0x5')]['id'],this[_0x68a3('0x12')][_0x68a3('0x13')][this[_0x68a3('0x14')]],'TIMEOUT');this[_0x68a3('0x12')][_0x68a3('0x13')][this[_0x68a3('0x14')]]['busy']=![];this[_0x68a3('0x12')][_0x68a3('0x13')][this[_0x68a3('0x14')]][_0x68a3('0x19')]=undefined;util[_0x68a3('0x24')](this[_0x68a3('0x12')],this[_0x68a3('0x3')],this[_0x68a3('0x12')][_0x68a3('0x13')][this[_0x68a3('0x14')]],this[_0x68a3('0x5')][_0x68a3('0x18')]);}if(!_0x5338ed){setTimeout(this[_0x68a3('0x8')][_0x68a3('0x9')](this),0x3e8);}};function rrmemory(_0x430d30,_0xcab9c,_0x118f9e,_0x530c7b){return new RRMemory(_0x430d30,_0xcab9c,_0x118f9e,_0x530c7b);}module['exports']=rrmemory;