6be5ffd8a2b1137e84710a17980c53846258cd10
[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 _0x24b5=['agentId','channel','done','[%s][QUEUE]\x20try\x20with\x20%s','info','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','isAgentAvailable','busy','name','showNotification','RINGING','[%s][QUEUE]\x20timeout\x20with\x20%s','hideNotification','writeLog','TIMEOUT','busyQueue','exports','uuid','./util','../../../../../config/logger','routing','notificationId','squeue','queue','realtime','intervals','push','handleRun','handleTimeout','bind','timeout','drained','handleDrained','prototype','agents'];(function(_0x580576,_0x2f107d){var _0x3f55a0=function(_0x2e180b){while(--_0x2e180b){_0x580576['push'](_0x580576['shift']());}};_0x3f55a0(++_0x2f107d);}(_0x24b5,0xe3));var _0x524b=function(_0x3382fb,_0xf3de39){_0x3382fb=_0x3382fb-0x0;var _0x5e687e=_0x24b5[_0x3382fb];return _0x5e687e;};'use strict';var rr=require('rr');var _=require('lodash');var uuid=require(_0x524b('0x0'));var util=require(_0x524b('0x1'));var logger=require(_0x524b('0x2'))(_0x524b('0x3'));var RRMemory=function(_0x1f19bf,_0xa55e35,_0x7baa0d,_0x55cf7b){this[_0x524b('0x4')]=uuid['v4']();this[_0x524b('0x5')]=_0x1f19bf;this[_0x524b('0x6')]=_0xa55e35;this[_0x524b('0x7')]=_0x7baa0d;this[_0x524b('0x3')]=_0x55cf7b;this[_0x524b('0x8')]={};this[_0x524b('0x5')][_0x524b('0x9')](this[_0x524b('0xa')]['bind'](this),this[_0x524b('0xb')][_0x524b('0xc')](this),this['module']);this[_0x524b('0x5')]['on'](_0x524b('0xd'),this['handleTimeout'][_0x524b('0xc')](this));this[_0x524b('0x5')]['on'](_0x524b('0xe'),this[_0x524b('0xf')][_0x524b('0xc')](this));};RRMemory[_0x524b('0x10')][_0x524b('0x9')]=function(){this[_0x524b('0x5')][_0x524b('0x9')](this[_0x524b('0xa')][_0x524b('0xc')](this),this[_0x524b('0xb')][_0x524b('0xc')](this));};RRMemory['prototype']['handleDrained']=function(_0x4b0937){this[_0x524b('0xb')](!![]);};RRMemory[_0x524b('0x10')]['handleCheckReject']=function(_0x1d3ba3){if(util['isAgentAvailable'](this[_0x524b('0x5')]['id'],this[_0x524b('0x7')][_0x524b('0x11')][this[_0x524b('0x12')]],this['squeue'][_0x524b('0x13')],!![])){logger['info']('[%s][QUEUE]\x20available\x20again\x20%s',this[_0x524b('0x5')]['id'],this[_0x524b('0x12')]);clearInterval(this[_0x524b('0x8')][this[_0x524b('0x12')]]);_0x1d3ba3[_0x524b('0x14')]();setTimeout(this[_0x524b('0x9')][_0x524b('0xc')](this),0x3e8);}};RRMemory[_0x524b('0x10')][_0x524b('0xa')]=function(_0x114e91){this['agentId']=rr(this[_0x524b('0x6')]['mapAgentsId']);logger['info'](_0x524b('0x15'),this[_0x524b('0x5')]['id'],this['agentId']);if(_['isNil'](this['realtime'][_0x524b('0x11')][this['agentId']])){logger[_0x524b('0x16')](_0x524b('0x17'),this[_0x524b('0x5')]['id'],this[_0x524b('0x12')]);_0x114e91[_0x524b('0x14')]();setTimeout(this[_0x524b('0x9')]['bind'](this),0x3e8);}else{if(util[_0x524b('0x18')](this[_0x524b('0x5')]['id'],this[_0x524b('0x7')]['agents'][this[_0x524b('0x12')]],this[_0x524b('0x5')]['channel'],!![])){this[_0x524b('0x7')]['agents'][this[_0x524b('0x12')]][_0x524b('0x19')]=!![];this[_0x524b('0x7')][_0x524b('0x11')][this['agentId']]['busyQueue']=this['queue'][_0x524b('0x1a')];util[_0x524b('0x1b')](this[_0x524b('0x4')],this[_0x524b('0x5')]['id'],this['realtime'][_0x524b('0x11')][this[_0x524b('0x12')]],this['queue'],this[_0x524b('0x3')]);util['writeLog'](this['squeue']['id'],this[_0x524b('0x7')]['agents'][this[_0x524b('0x12')]],_0x524b('0x1c'));this[_0x524b('0x8')][this[_0x524b('0x12')]]=setInterval(this['handleCheckReject']['bind'](this,_0x114e91),0x3e8);}else{logger[_0x524b('0x16')]('[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s',this[_0x524b('0x5')]['id'],this['agentId']);_0x114e91[_0x524b('0x14')]();setTimeout(this[_0x524b('0x9')][_0x524b('0xc')](this),0x3e8);}}};RRMemory[_0x524b('0x10')][_0x524b('0xb')]=function(_0x2db18e){logger[_0x524b('0x16')](_0x524b('0x1d'),this['squeue']['id'],this[_0x524b('0x12')]);if(_['isNil'](this['realtime']['agents'][this['agentId']])){logger['info'](_0x524b('0x17'),this[_0x524b('0x5')]['id'],this[_0x524b('0x12')]);}else{clearInterval(this[_0x524b('0x8')][this[_0x524b('0x12')]]);util[_0x524b('0x1e')](this[_0x524b('0x4')],this['squeue']['id'],this['realtime'][_0x524b('0x11')][this['agentId']],this[_0x524b('0x6')],this[_0x524b('0x3')]);util[_0x524b('0x1f')](this[_0x524b('0x5')]['id'],this['realtime'][_0x524b('0x11')][this[_0x524b('0x12')]],_0x524b('0x20'));this['realtime'][_0x524b('0x11')][this[_0x524b('0x12')]]['busy']=![];this[_0x524b('0x7')]['agents'][this['agentId']][_0x524b('0x21')]=undefined;}if(!_0x2db18e){setTimeout(this[_0x524b('0x9')][_0x524b('0xc')](this),0x3e8);}};function rrmemory(_0x46a471,_0x543712,_0x34a688,_0x1429b1){return new RRMemory(_0x46a471,_0x543712,_0x34a688,_0x1429b1);}module[_0x524b('0x22')]=rrmemory;