af338efbdbdcb0dfb88afb73a24d1c6045ff2ff9
[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 _0xcc99=['[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','busy','busyQueue','showNotification','notificationId','writeLog','RINGING','[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s','done','[%s][QUEUE]\x20timeout\x20with\x20%s','TIMEOUT','exports','lodash','uuid','routing','queue','realtime','squeue','push','bind','handleTimeout','module','timeout','drained','handleDrained','prototype','handleRun','handleCheckReject','isAgentAvailable','agents','agentId','channel','info','[%s][QUEUE]\x20available\x20again\x20%s','intervals','mapAgentsId','isNil'];(function(_0x4e44b9,_0x58314a){var _0xbaefcb=function(_0x59700c){while(--_0x59700c){_0x4e44b9['push'](_0x4e44b9['shift']());}};_0xbaefcb(++_0x58314a);}(_0xcc99,0x10f));var _0x9cc9=function(_0x1b0cb4,_0x1b8571){_0x1b0cb4=_0x1b0cb4-0x0;var _0x34581f=_0xcc99[_0x1b0cb4];return _0x34581f;};'use strict';var rr=require('rr');var _=require(_0x9cc9('0x0'));var uuid=require(_0x9cc9('0x1'));var util=require('./util');var logger=require('../../../../../config/logger')(_0x9cc9('0x2'));var RRMemory=function(_0x2cb6b0,_0x5ef946,_0xbf4ea8,_0x2fd361){this['notificationId']=uuid['v4']();this['squeue']=_0x2cb6b0;this[_0x9cc9('0x3')]=_0x5ef946;this[_0x9cc9('0x4')]=_0xbf4ea8;this[_0x9cc9('0x2')]=_0x2fd361;this['intervals']={};this[_0x9cc9('0x5')][_0x9cc9('0x6')](this['handleRun'][_0x9cc9('0x7')](this),this[_0x9cc9('0x8')][_0x9cc9('0x7')](this),this[_0x9cc9('0x9')]);this[_0x9cc9('0x5')]['on'](_0x9cc9('0xa'),this[_0x9cc9('0x8')]['bind'](this));this[_0x9cc9('0x5')]['on'](_0x9cc9('0xb'),this[_0x9cc9('0xc')][_0x9cc9('0x7')](this));};RRMemory[_0x9cc9('0xd')][_0x9cc9('0x6')]=function(){this[_0x9cc9('0x5')][_0x9cc9('0x6')](this[_0x9cc9('0xe')][_0x9cc9('0x7')](this),this[_0x9cc9('0x8')][_0x9cc9('0x7')](this));};RRMemory[_0x9cc9('0xd')][_0x9cc9('0xc')]=function(_0xcf712){this[_0x9cc9('0x8')](!![]);};RRMemory[_0x9cc9('0xd')][_0x9cc9('0xf')]=function(_0x34d3a6){if(util[_0x9cc9('0x10')](this[_0x9cc9('0x5')]['id'],this[_0x9cc9('0x4')][_0x9cc9('0x11')][this[_0x9cc9('0x12')]],this['squeue'][_0x9cc9('0x13')],!![])){logger[_0x9cc9('0x14')](_0x9cc9('0x15'),this[_0x9cc9('0x5')]['id'],this[_0x9cc9('0x12')]);clearInterval(this[_0x9cc9('0x16')][this[_0x9cc9('0x12')]]);_0x34d3a6['done']();setTimeout(this[_0x9cc9('0x6')]['bind'](this),0x3e8);}};RRMemory[_0x9cc9('0xd')][_0x9cc9('0xe')]=function(_0x5cfe72){this[_0x9cc9('0x12')]=rr(this[_0x9cc9('0x3')][_0x9cc9('0x17')]);logger[_0x9cc9('0x14')]('[%s][QUEUE]\x20try\x20with\x20%s',this[_0x9cc9('0x5')]['id'],this[_0x9cc9('0x12')]);if(_[_0x9cc9('0x18')](this[_0x9cc9('0x4')]['agents'][this['agentId']])){logger[_0x9cc9('0x14')](_0x9cc9('0x19'),this[_0x9cc9('0x5')]['id'],this[_0x9cc9('0x12')]);_0x5cfe72['done']();setTimeout(this[_0x9cc9('0x6')][_0x9cc9('0x7')](this),0x3e8);}else{if(util['isAgentAvailable'](this['squeue']['id'],this[_0x9cc9('0x4')][_0x9cc9('0x11')][this[_0x9cc9('0x12')]],this[_0x9cc9('0x5')][_0x9cc9('0x13')],!![])){this[_0x9cc9('0x4')][_0x9cc9('0x11')][this[_0x9cc9('0x12')]][_0x9cc9('0x1a')]=!![];this['realtime'][_0x9cc9('0x11')][this[_0x9cc9('0x12')]][_0x9cc9('0x1b')]=this['queue']['name'];util[_0x9cc9('0x1c')](this[_0x9cc9('0x1d')],this[_0x9cc9('0x5')]['id'],this[_0x9cc9('0x4')]['agents'][this[_0x9cc9('0x12')]],this['queue'],this[_0x9cc9('0x2')]);util[_0x9cc9('0x1e')](this[_0x9cc9('0x5')]['id'],this[_0x9cc9('0x4')][_0x9cc9('0x11')][this[_0x9cc9('0x12')]],_0x9cc9('0x1f'));this['intervals'][this['agentId']]=setInterval(this[_0x9cc9('0xf')][_0x9cc9('0x7')](this,_0x5cfe72),0x3e8);}else{logger['info'](_0x9cc9('0x20'),this['squeue']['id'],this[_0x9cc9('0x12')]);_0x5cfe72[_0x9cc9('0x21')]();setTimeout(this['push'][_0x9cc9('0x7')](this),0x3e8);}}};RRMemory[_0x9cc9('0xd')][_0x9cc9('0x8')]=function(_0x23c4cb){logger[_0x9cc9('0x14')](_0x9cc9('0x22'),this[_0x9cc9('0x5')]['id'],this[_0x9cc9('0x12')]);if(_[_0x9cc9('0x18')](this[_0x9cc9('0x4')][_0x9cc9('0x11')][this[_0x9cc9('0x12')]])){logger[_0x9cc9('0x14')](_0x9cc9('0x19'),this[_0x9cc9('0x5')]['id'],this[_0x9cc9('0x12')]);}else{clearInterval(this[_0x9cc9('0x16')][this['agentId']]);util['hideNotification'](this['notificationId'],this['squeue']['id'],this[_0x9cc9('0x4')][_0x9cc9('0x11')][this[_0x9cc9('0x12')]],this[_0x9cc9('0x3')],this['routing']);util['writeLog'](this[_0x9cc9('0x5')]['id'],this[_0x9cc9('0x4')]['agents'][this[_0x9cc9('0x12')]],_0x9cc9('0x23'));this['realtime'][_0x9cc9('0x11')][this['agentId']][_0x9cc9('0x1a')]=![];this['realtime'][_0x9cc9('0x11')][this['agentId']][_0x9cc9('0x1b')]=undefined;}if(!_0x23c4cb){setTimeout(this[_0x9cc9('0x6')][_0x9cc9('0x7')](this),0x3e8);}};function rrmemory(_0x519596,_0x546975,_0x130b1c,_0x17fb81){return new RRMemory(_0x519596,_0x546975,_0x130b1c,_0x17fb81);}module[_0x9cc9('0x24')]=rrmemory;