b94c07c14f0cafd3797b6e90e3ee2fb4caecf478
[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 _0xa16a=['drained','handleDrained','prototype','handleCheckReject','isAgentAvailable','agents','agentId','debug','[%s][QUEUE]\x20available\x20again\x20%s','mapAgentsId','[%s][QUEUE]\x20try\x20with\x20%s','isNil','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','done','channel','busy','busyQueue','showNotification','RINGING','intervals','[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s','[%s][QUEUE]\x20timeout\x20with\x20%s','hideNotification','TIMEOUT','removeWaitingNotification','exports','lodash','uuid','./util','../../../../../config/logger','notificationId','queue','realtime','routing','squeue','push','handleRun','handleTimeout','bind','module'];(function(_0x35bad0,_0x21927d){var _0x4fe50f=function(_0x1873df){while(--_0x1873df){_0x35bad0['push'](_0x35bad0['shift']());}};_0x4fe50f(++_0x21927d);}(_0xa16a,0x1aa));var _0xaa16=function(_0x2ef8f1,_0x1280a3){_0x2ef8f1=_0x2ef8f1-0x0;var _0x17498d=_0xa16a[_0x2ef8f1];return _0x17498d;};'use strict';var rr=require('rr');var _=require(_0xaa16('0x0'));var uuid=require(_0xaa16('0x1'));var util=require(_0xaa16('0x2'));var logger=require(_0xaa16('0x3'))('routing');var RRMemory=function(_0x17818d,_0x481660,_0x55ad01,_0x2150a4){this[_0xaa16('0x4')]=uuid['v4']();this['squeue']=_0x17818d;this[_0xaa16('0x5')]=_0x481660;this[_0xaa16('0x6')]=_0x55ad01;this[_0xaa16('0x7')]=_0x2150a4;this['intervals']={};this[_0xaa16('0x8')][_0xaa16('0x9')](this[_0xaa16('0xa')]['bind'](this),this[_0xaa16('0xb')][_0xaa16('0xc')](this),this[_0xaa16('0xd')]);this[_0xaa16('0x8')]['on']('timeout',this[_0xaa16('0xb')]['bind'](this));this['squeue']['on'](_0xaa16('0xe'),this[_0xaa16('0xf')][_0xaa16('0xc')](this));};RRMemory[_0xaa16('0x10')][_0xaa16('0x9')]=function(){this[_0xaa16('0x8')][_0xaa16('0x9')](this['handleRun'][_0xaa16('0xc')](this),this['handleTimeout'][_0xaa16('0xc')](this));};RRMemory[_0xaa16('0x10')]['handleDrained']=function(){this[_0xaa16('0xb')](!![]);};RRMemory[_0xaa16('0x10')][_0xaa16('0x11')]=function(_0x2a2493){if(util[_0xaa16('0x12')](this[_0xaa16('0x8')]['id'],this[_0xaa16('0x6')][_0xaa16('0x13')][this[_0xaa16('0x14')]],this[_0xaa16('0x8')]['channel'],!![])){logger[_0xaa16('0x15')](_0xaa16('0x16'),this[_0xaa16('0x8')]['id'],this['agentId']);clearInterval(this['intervals'][this[_0xaa16('0x14')]]);_0x2a2493['done']();setTimeout(this[_0xaa16('0x9')][_0xaa16('0xc')](this),0x3e8);}};RRMemory[_0xaa16('0x10')][_0xaa16('0xa')]=function(_0x3e037a){this['agentId']=rr(this[_0xaa16('0x5')][_0xaa16('0x17')]);logger['debug'](_0xaa16('0x18'),this[_0xaa16('0x8')]['id'],this[_0xaa16('0x14')]);if(_[_0xaa16('0x19')](this[_0xaa16('0x6')][_0xaa16('0x13')][this['agentId']])){logger[_0xaa16('0x15')](_0xaa16('0x1a'),this[_0xaa16('0x8')]['id'],this['agentId']);_0x3e037a[_0xaa16('0x1b')]();setTimeout(this[_0xaa16('0x9')][_0xaa16('0xc')](this),0x3e8);}else{if(util['isAgentAvailable'](this[_0xaa16('0x8')]['id'],this[_0xaa16('0x6')][_0xaa16('0x13')][this['agentId']],this[_0xaa16('0x8')][_0xaa16('0x1c')],!![])){this['realtime'][_0xaa16('0x13')][this[_0xaa16('0x14')]][_0xaa16('0x1d')]=!![];this['realtime'][_0xaa16('0x13')][this[_0xaa16('0x14')]][_0xaa16('0x1e')]=this[_0xaa16('0x5')]['name'];util['saveWaitingNotification'](this[_0xaa16('0x6')],this['routing'],this[_0xaa16('0x6')][_0xaa16('0x13')][this[_0xaa16('0x14')]],this['squeue'][_0xaa16('0x1c')]);util[_0xaa16('0x1f')](this['notificationId'],this[_0xaa16('0x8')]['id'],this[_0xaa16('0x6')][_0xaa16('0x13')][this['agentId']],this[_0xaa16('0x5')],this[_0xaa16('0x7')]);util['writeLog'](this[_0xaa16('0x8')]['id'],this['realtime'][_0xaa16('0x13')][this[_0xaa16('0x14')]],_0xaa16('0x20'));this[_0xaa16('0x21')][this['agentId']]=setInterval(this[_0xaa16('0x11')][_0xaa16('0xc')](this,_0x3e037a),0x3e8);}else{logger['debug'](_0xaa16('0x22'),this[_0xaa16('0x8')]['id'],this[_0xaa16('0x14')]);_0x3e037a['done']();setTimeout(this[_0xaa16('0x9')][_0xaa16('0xc')](this),0x3e8);}}};RRMemory[_0xaa16('0x10')]['handleTimeout']=function(_0x24780e){logger[_0xaa16('0x15')](_0xaa16('0x23'),this[_0xaa16('0x8')]['id'],this[_0xaa16('0x14')]);if(_['isNil'](this[_0xaa16('0x6')]['agents'][this[_0xaa16('0x14')]])){logger['debug'](_0xaa16('0x1a'),this[_0xaa16('0x8')]['id'],this[_0xaa16('0x14')]);}else{clearInterval(this[_0xaa16('0x21')][this[_0xaa16('0x14')]]);util[_0xaa16('0x24')](this[_0xaa16('0x4')],this[_0xaa16('0x8')]['id'],this[_0xaa16('0x6')][_0xaa16('0x13')][this[_0xaa16('0x14')]],this['queue'],this[_0xaa16('0x7')]);util['writeLog'](this[_0xaa16('0x8')]['id'],this['realtime']['agents'][this[_0xaa16('0x14')]],_0xaa16('0x25'));this[_0xaa16('0x6')]['agents'][this[_0xaa16('0x14')]]['busy']=![];this['realtime'][_0xaa16('0x13')][this[_0xaa16('0x14')]]['busyQueue']=undefined;util[_0xaa16('0x26')](this[_0xaa16('0x6')],this['routing'],this[_0xaa16('0x6')][_0xaa16('0x13')][this['agentId']],this[_0xaa16('0x8')][_0xaa16('0x1c')]);}if(!_0x24780e){setTimeout(this['push'][_0xaa16('0xc')](this),0x3e8);}};function rrmemory(_0x24b699,_0x4e106f,_0x257fba,_0x3521c5){return new RRMemory(_0x24b699,_0x4e106f,_0x257fba,_0x3521c5);}module[_0xaa16('0x27')]=rrmemory;