510266da0103d062d1d8160cd9225396a4099421
[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 _0x6257=['isNil','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','done','isAgentAvailable','busyQueue','name','writeLog','handleCheckReject','[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s','[%s][QUEUE]\x20timeout\x20with\x20%s','hideNotification','busy','exports','lodash','./util','notificationId','squeue','queue','realtime','routing','intervals','handleRun','bind','module','handleTimeout','drained','push','prototype','handleDrained','agents','channel','debug','[%s][QUEUE]\x20available\x20again\x20%s','agentId','[%s][QUEUE]\x20try\x20with\x20%s'];(function(_0x3054be,_0x1bdc8b){var _0x3df150=function(_0x56cfbf){while(--_0x56cfbf){_0x3054be['push'](_0x3054be['shift']());}};_0x3df150(++_0x1bdc8b);}(_0x6257,0x1d4));var _0x7625=function(_0x95bb02,_0x5ca77a){_0x95bb02=_0x95bb02-0x0;var _0x145e21=_0x6257[_0x95bb02];return _0x145e21;};'use strict';var rr=require('rr');var _=require(_0x7625('0x0'));var uuid=require('uuid');var util=require(_0x7625('0x1'));var logger=require('../../../../../config/logger')('routing');var RRMemory=function(_0x2078ab,_0x15d0d9,_0x203b40,_0x2eefab){this[_0x7625('0x2')]=uuid['v4']();this[_0x7625('0x3')]=_0x2078ab;this[_0x7625('0x4')]=_0x15d0d9;this[_0x7625('0x5')]=_0x203b40;this[_0x7625('0x6')]=_0x2eefab;this[_0x7625('0x7')]={};this['squeue']['push'](this[_0x7625('0x8')][_0x7625('0x9')](this),this['handleTimeout'][_0x7625('0x9')](this),this[_0x7625('0xa')]);this[_0x7625('0x3')]['on']('timeout',this[_0x7625('0xb')][_0x7625('0x9')](this));this['squeue']['on'](_0x7625('0xc'),this['handleDrained']['bind'](this));};RRMemory['prototype'][_0x7625('0xd')]=function(){this['squeue']['push'](this['handleRun'][_0x7625('0x9')](this),this[_0x7625('0xb')][_0x7625('0x9')](this));};RRMemory[_0x7625('0xe')][_0x7625('0xf')]=function(){this[_0x7625('0xb')](!![]);};RRMemory['prototype']['handleCheckReject']=function(_0x42f087){if(util['isAgentAvailable'](this[_0x7625('0x3')]['id'],this[_0x7625('0x5')][_0x7625('0x10')][this['agentId']],this['squeue'][_0x7625('0x11')],!![])){logger[_0x7625('0x12')](_0x7625('0x13'),this[_0x7625('0x3')]['id'],this[_0x7625('0x14')]);clearInterval(this[_0x7625('0x7')][this[_0x7625('0x14')]]);_0x42f087['done']();setTimeout(this[_0x7625('0xd')]['bind'](this),0x3e8);}};RRMemory[_0x7625('0xe')]['handleRun']=function(_0x4ba21a){this[_0x7625('0x14')]=rr(this['queue']['mapAgentsId']);logger[_0x7625('0x12')](_0x7625('0x15'),this['squeue']['id'],this[_0x7625('0x14')]);if(_[_0x7625('0x16')](this[_0x7625('0x5')]['agents'][this[_0x7625('0x14')]])){logger[_0x7625('0x12')](_0x7625('0x17'),this[_0x7625('0x3')]['id'],this[_0x7625('0x14')]);_0x4ba21a[_0x7625('0x18')]();setTimeout(this[_0x7625('0xd')][_0x7625('0x9')](this),0x3e8);}else{if(util[_0x7625('0x19')](this['squeue']['id'],this['realtime']['agents'][this['agentId']],this['squeue'][_0x7625('0x11')],!![])){this[_0x7625('0x5')]['agents'][this[_0x7625('0x14')]]['busy']=!![];this[_0x7625('0x5')][_0x7625('0x10')][this['agentId']][_0x7625('0x1a')]=this['queue'][_0x7625('0x1b')];util['showNotification'](this[_0x7625('0x2')],this[_0x7625('0x3')]['id'],this[_0x7625('0x5')][_0x7625('0x10')][this[_0x7625('0x14')]],this[_0x7625('0x4')],this[_0x7625('0x6')]);util[_0x7625('0x1c')](this['squeue']['id'],this['realtime'][_0x7625('0x10')][this[_0x7625('0x14')]],'RINGING');this[_0x7625('0x7')][this[_0x7625('0x14')]]=setInterval(this[_0x7625('0x1d')][_0x7625('0x9')](this,_0x4ba21a),0x3e8);}else{logger[_0x7625('0x12')](_0x7625('0x1e'),this[_0x7625('0x3')]['id'],this['agentId']);_0x4ba21a[_0x7625('0x18')]();setTimeout(this['push'][_0x7625('0x9')](this),0x3e8);}}};RRMemory[_0x7625('0xe')][_0x7625('0xb')]=function(_0x286273){logger[_0x7625('0x12')](_0x7625('0x1f'),this[_0x7625('0x3')]['id'],this[_0x7625('0x14')]);if(_[_0x7625('0x16')](this[_0x7625('0x5')][_0x7625('0x10')][this[_0x7625('0x14')]])){logger[_0x7625('0x12')](_0x7625('0x17'),this[_0x7625('0x3')]['id'],this[_0x7625('0x14')]);}else{clearInterval(this['intervals'][this['agentId']]);util[_0x7625('0x20')](this['notificationId'],this['squeue']['id'],this[_0x7625('0x5')][_0x7625('0x10')][this['agentId']],this[_0x7625('0x4')],this[_0x7625('0x6')]);util[_0x7625('0x1c')](this[_0x7625('0x3')]['id'],this[_0x7625('0x5')][_0x7625('0x10')][this['agentId']],'TIMEOUT');this[_0x7625('0x5')]['agents'][this['agentId']][_0x7625('0x21')]=![];this[_0x7625('0x5')][_0x7625('0x10')][this[_0x7625('0x14')]][_0x7625('0x1a')]=undefined;}if(!_0x286273){setTimeout(this[_0x7625('0xd')][_0x7625('0x9')](this),0x3e8);}};function rrmemory(_0x5d18ea,_0x322a58,_0x5b8cf0,_0x28eb67){return new RRMemory(_0x5d18ea,_0x322a58,_0x5b8cf0,_0x28eb67);}module[_0x7625('0x22')]=rrmemory;