b4b2e40c0fbba4bde30df12a8d3f9dddfc2e4d75
[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 _0x7e32=['busy','name','saveWaitingNotification','showNotification','writeLog','[%s][QUEUE]\x20timeout\x20with\x20%s','hideNotification','TIMEOUT','busyQueue','removeWaitingNotification','lodash','./util','../../../../../config/logger','notificationId','squeue','queue','realtime','routing','push','handleRun','bind','handleTimeout','module','timeout','drained','prototype','handleDrained','handleCheckReject','isAgentAvailable','agents','agentId','channel','intervals','done','mapAgentsId','[%s][QUEUE]\x20try\x20with\x20%s','isNil','debug','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s'];(function(_0x36feb2,_0x53abef){var _0x292b43=function(_0x52a460){while(--_0x52a460){_0x36feb2['push'](_0x36feb2['shift']());}};_0x292b43(++_0x53abef);}(_0x7e32,0xa6));var _0x27e3=function(_0x15b69a,_0x48ccf8){_0x15b69a=_0x15b69a-0x0;var _0x1b8e45=_0x7e32[_0x15b69a];return _0x1b8e45;};'use strict';var rr=require('rr');var _=require(_0x27e3('0x0'));var uuid=require('uuid');var util=require(_0x27e3('0x1'));var logger=require(_0x27e3('0x2'))('routing');var RRMemory=function(_0x42343c,_0x1e64b0,_0x5350de,_0x1bac50){this[_0x27e3('0x3')]=uuid['v4']();this[_0x27e3('0x4')]=_0x42343c;this[_0x27e3('0x5')]=_0x1e64b0;this[_0x27e3('0x6')]=_0x5350de;this[_0x27e3('0x7')]=_0x1bac50;this['intervals']={};this[_0x27e3('0x4')][_0x27e3('0x8')](this[_0x27e3('0x9')][_0x27e3('0xa')](this),this[_0x27e3('0xb')]['bind'](this),this[_0x27e3('0xc')]);this['squeue']['on'](_0x27e3('0xd'),this['handleTimeout'][_0x27e3('0xa')](this));this[_0x27e3('0x4')]['on'](_0x27e3('0xe'),this['handleDrained'][_0x27e3('0xa')](this));};RRMemory[_0x27e3('0xf')]['push']=function(){this['squeue'][_0x27e3('0x8')](this[_0x27e3('0x9')][_0x27e3('0xa')](this),this['handleTimeout']['bind'](this));};RRMemory[_0x27e3('0xf')][_0x27e3('0x10')]=function(){this[_0x27e3('0xb')](!![]);};RRMemory[_0x27e3('0xf')][_0x27e3('0x11')]=function(_0x2234f6){if(util[_0x27e3('0x12')](this['squeue']['id'],this[_0x27e3('0x6')][_0x27e3('0x13')][this[_0x27e3('0x14')]],this[_0x27e3('0x4')][_0x27e3('0x15')],!![])){logger['debug']('[%s][QUEUE]\x20available\x20again\x20%s',this[_0x27e3('0x4')]['id'],this[_0x27e3('0x14')]);clearInterval(this[_0x27e3('0x16')][this['agentId']]);_0x2234f6[_0x27e3('0x17')]();setTimeout(this[_0x27e3('0x8')]['bind'](this),0x3e8);}};RRMemory[_0x27e3('0xf')][_0x27e3('0x9')]=function(_0x389c08){this[_0x27e3('0x14')]=rr(this[_0x27e3('0x5')][_0x27e3('0x18')]);logger['debug'](_0x27e3('0x19'),this[_0x27e3('0x4')]['id'],this['agentId']);if(_[_0x27e3('0x1a')](this[_0x27e3('0x6')]['agents'][this[_0x27e3('0x14')]])){logger[_0x27e3('0x1b')](_0x27e3('0x1c'),this[_0x27e3('0x4')]['id'],this[_0x27e3('0x14')]);_0x389c08[_0x27e3('0x17')]();setTimeout(this[_0x27e3('0x8')][_0x27e3('0xa')](this),0x3e8);}else{if(util[_0x27e3('0x12')](this[_0x27e3('0x4')]['id'],this[_0x27e3('0x6')]['agents'][this[_0x27e3('0x14')]],this['squeue'][_0x27e3('0x15')],!![])){this[_0x27e3('0x6')]['agents'][this[_0x27e3('0x14')]][_0x27e3('0x1d')]=!![];this[_0x27e3('0x6')][_0x27e3('0x13')][this[_0x27e3('0x14')]]['busyQueue']=this[_0x27e3('0x5')][_0x27e3('0x1e')];util[_0x27e3('0x1f')](this['realtime'],this[_0x27e3('0x7')],this[_0x27e3('0x6')][_0x27e3('0x13')][this['agentId']],this[_0x27e3('0x4')]['channel']);util[_0x27e3('0x20')](this[_0x27e3('0x3')],this[_0x27e3('0x4')]['id'],this[_0x27e3('0x6')][_0x27e3('0x13')][this[_0x27e3('0x14')]],this[_0x27e3('0x5')],this[_0x27e3('0x7')]);util[_0x27e3('0x21')](this[_0x27e3('0x4')]['id'],this[_0x27e3('0x6')][_0x27e3('0x13')][this['agentId']],'RINGING');this['intervals'][this[_0x27e3('0x14')]]=setInterval(this[_0x27e3('0x11')][_0x27e3('0xa')](this,_0x389c08),0x3e8);}else{logger[_0x27e3('0x1b')]('[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s',this[_0x27e3('0x4')]['id'],this[_0x27e3('0x14')]);_0x389c08[_0x27e3('0x17')]();setTimeout(this[_0x27e3('0x8')][_0x27e3('0xa')](this),0x3e8);}}};RRMemory[_0x27e3('0xf')][_0x27e3('0xb')]=function(_0x21f88a){logger[_0x27e3('0x1b')](_0x27e3('0x22'),this['squeue']['id'],this[_0x27e3('0x14')]);if(_['isNil'](this[_0x27e3('0x6')][_0x27e3('0x13')][this[_0x27e3('0x14')]])){logger[_0x27e3('0x1b')](_0x27e3('0x1c'),this['squeue']['id'],this[_0x27e3('0x14')]);}else{clearInterval(this[_0x27e3('0x16')][this[_0x27e3('0x14')]]);util[_0x27e3('0x23')](this[_0x27e3('0x3')],this[_0x27e3('0x4')]['id'],this[_0x27e3('0x6')][_0x27e3('0x13')][this['agentId']],this[_0x27e3('0x5')],this['routing']);util[_0x27e3('0x21')](this['squeue']['id'],this['realtime'][_0x27e3('0x13')][this['agentId']],_0x27e3('0x24'));this['realtime'][_0x27e3('0x13')][this[_0x27e3('0x14')]]['busy']=![];this['realtime'][_0x27e3('0x13')][this[_0x27e3('0x14')]][_0x27e3('0x25')]=undefined;util[_0x27e3('0x26')](this[_0x27e3('0x6')],this[_0x27e3('0x7')],this[_0x27e3('0x6')][_0x27e3('0x13')][this[_0x27e3('0x14')]],this[_0x27e3('0x4')][_0x27e3('0x15')]);}if(!_0x21f88a){setTimeout(this['push'][_0x27e3('0xa')](this),0x3e8);}};function rrmemory(_0x912f6,_0x394891,_0x150612,_0x1e0b12){return new RRMemory(_0x912f6,_0x394891,_0x150612,_0x1e0b12);}module['exports']=rrmemory;