9529ffc4f4cc1cf0c407930871e2af5e13d6ba11
[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 _0x7bd8=['handleDrained','prototype','handleCheckReject','isAgentAvailable','realtime','agentId','channel','[%s][QUEUE]\x20available\x20again\x20%s','info','[%s][QUEUE]\x20try\x20with\x20%s','isNil','agents','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','done','busy','name','writeLog','RINGING','hideNotification','routing','lodash','../../../../../config/logger','notificationId','queue','intervals','push','handleRun','bind','handleTimeout','squeue','timeout','drained'];(function(_0x36c6eb,_0x4fb127){var _0x30675b=function(_0x3a788b){while(--_0x3a788b){_0x36c6eb['push'](_0x36c6eb['shift']());}};_0x30675b(++_0x4fb127);}(_0x7bd8,0x154));var _0x87bd=function(_0x1b680f,_0x304e7b){_0x1b680f=_0x1b680f-0x0;var _0x48edb6=_0x7bd8[_0x1b680f];return _0x48edb6;};'use strict';var rr=require('rr');var _=require(_0x87bd('0x0'));var uuid=require('uuid');var util=require('./util');var logger=require(_0x87bd('0x1'))('routing');var RRMemory=function(_0x163f47,_0x13ac3b,_0x49d42f,_0x14e41e){this[_0x87bd('0x2')]=uuid['v4']();this['squeue']=_0x163f47;this[_0x87bd('0x3')]=_0x13ac3b;this['realtime']=_0x49d42f;this['routing']=_0x14e41e;this[_0x87bd('0x4')]={};this['squeue'][_0x87bd('0x5')](this[_0x87bd('0x6')][_0x87bd('0x7')](this),this[_0x87bd('0x8')][_0x87bd('0x7')](this),this['module']);this[_0x87bd('0x9')]['on'](_0x87bd('0xa'),this[_0x87bd('0x8')][_0x87bd('0x7')](this));this[_0x87bd('0x9')]['on'](_0x87bd('0xb'),this[_0x87bd('0xc')]['bind'](this));};RRMemory[_0x87bd('0xd')][_0x87bd('0x5')]=function(){this[_0x87bd('0x9')][_0x87bd('0x5')](this[_0x87bd('0x6')][_0x87bd('0x7')](this),this[_0x87bd('0x8')][_0x87bd('0x7')](this));};RRMemory[_0x87bd('0xd')][_0x87bd('0xc')]=function(_0x539a56){this[_0x87bd('0x8')](!![]);};RRMemory[_0x87bd('0xd')][_0x87bd('0xe')]=function(_0x33de6a){if(util[_0x87bd('0xf')](this[_0x87bd('0x9')]['id'],this[_0x87bd('0x10')]['agents'][this[_0x87bd('0x11')]],this[_0x87bd('0x9')][_0x87bd('0x12')],!![])){logger['info'](_0x87bd('0x13'),this['squeue']['id'],this['agentId']);clearInterval(this[_0x87bd('0x4')][this[_0x87bd('0x11')]]);_0x33de6a['done']();setTimeout(this[_0x87bd('0x5')][_0x87bd('0x7')](this),0x3e8);}};RRMemory[_0x87bd('0xd')][_0x87bd('0x6')]=function(_0x110e47){this[_0x87bd('0x11')]=rr(this['queue']['mapAgentsId']);logger[_0x87bd('0x14')](_0x87bd('0x15'),this[_0x87bd('0x9')]['id'],this['agentId']);if(_[_0x87bd('0x16')](this['realtime'][_0x87bd('0x17')][this[_0x87bd('0x11')]])){logger[_0x87bd('0x14')](_0x87bd('0x18'),this[_0x87bd('0x9')]['id'],this['agentId']);_0x110e47[_0x87bd('0x19')]();setTimeout(this[_0x87bd('0x5')][_0x87bd('0x7')](this),0x3e8);}else{if(util[_0x87bd('0xf')](this[_0x87bd('0x9')]['id'],this[_0x87bd('0x10')][_0x87bd('0x17')][this[_0x87bd('0x11')]],this[_0x87bd('0x9')][_0x87bd('0x12')],!![])){this[_0x87bd('0x10')]['agents'][this[_0x87bd('0x11')]][_0x87bd('0x1a')]=!![];this[_0x87bd('0x10')]['agents'][this['agentId']]['busyQueue']=this[_0x87bd('0x3')][_0x87bd('0x1b')];util['showNotification'](this[_0x87bd('0x2')],this[_0x87bd('0x9')]['id'],this['realtime'][_0x87bd('0x17')][this['agentId']],this[_0x87bd('0x3')],this['routing']);util[_0x87bd('0x1c')](this['squeue']['id'],this[_0x87bd('0x10')]['agents'][this[_0x87bd('0x11')]],_0x87bd('0x1d'));this[_0x87bd('0x4')][this[_0x87bd('0x11')]]=setInterval(this[_0x87bd('0xe')][_0x87bd('0x7')](this,_0x110e47),0x3e8);}else{logger[_0x87bd('0x14')]('[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s',this[_0x87bd('0x9')]['id'],this[_0x87bd('0x11')]);_0x110e47[_0x87bd('0x19')]();setTimeout(this['push'][_0x87bd('0x7')](this),0x3e8);}}};RRMemory[_0x87bd('0xd')][_0x87bd('0x8')]=function(_0x2a2617){logger[_0x87bd('0x14')]('[%s][QUEUE]\x20timeout\x20with\x20%s',this[_0x87bd('0x9')]['id'],this['agentId']);if(_[_0x87bd('0x16')](this[_0x87bd('0x10')][_0x87bd('0x17')][this[_0x87bd('0x11')]])){logger[_0x87bd('0x14')](_0x87bd('0x18'),this[_0x87bd('0x9')]['id'],this[_0x87bd('0x11')]);}else{clearInterval(this[_0x87bd('0x4')][this[_0x87bd('0x11')]]);util[_0x87bd('0x1e')](this[_0x87bd('0x2')],this[_0x87bd('0x9')]['id'],this[_0x87bd('0x10')][_0x87bd('0x17')][this['agentId']],this[_0x87bd('0x3')],this[_0x87bd('0x1f')]);util[_0x87bd('0x1c')](this['squeue']['id'],this[_0x87bd('0x10')][_0x87bd('0x17')][this[_0x87bd('0x11')]],'TIMEOUT');this[_0x87bd('0x10')][_0x87bd('0x17')][this['agentId']][_0x87bd('0x1a')]=![];this['realtime']['agents'][this['agentId']]['busyQueue']=undefined;}if(!_0x2a2617){setTimeout(this[_0x87bd('0x5')][_0x87bd('0x7')](this),0x3e8);}};function rrmemory(_0x186fcc,_0xe954bf,_0x581d7f,_0x47e715){return new RRMemory(_0x186fcc,_0xe954bf,_0x581d7f,_0x47e715);}module['exports']=rrmemory;