5f04df054d13e414f09c7d1731411f4f8b25f83d
[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 _0x3208=['showNotification','notificationId','[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s','[%s][QUEUE]\x20timeout\x20with\x20%s','writeLog','TIMEOUT','removeWaitingNotification','lodash','./util','../../../../../config/logger','squeue','queue','realtime','routing','intervals','push','handleRun','handleTimeout','module','timeout','handleDrained','bind','prototype','handleCheckReject','agentId','channel','debug','[%s][QUEUE]\x20try\x20with\x20%s','agents','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','done','isAgentAvailable','busy','busyQueue','name','saveWaitingNotification'];(function(_0xb95853,_0x13db4c){var _0x4b6f50=function(_0x5bb48d){while(--_0x5bb48d){_0xb95853['push'](_0xb95853['shift']());}};_0x4b6f50(++_0x13db4c);}(_0x3208,0xdf));var _0x8320=function(_0x3ab51d,_0x2fa01d){_0x3ab51d=_0x3ab51d-0x0;var _0x29a04e=_0x3208[_0x3ab51d];return _0x29a04e;};'use strict';var rr=require('rr');var _=require(_0x8320('0x0'));var uuid=require('uuid');var util=require(_0x8320('0x1'));var logger=require(_0x8320('0x2'))('routing');var RRMemory=function(_0x2aa4b0,_0x32762a,_0x38175d,_0x277eba){this['notificationId']=uuid['v4']();this[_0x8320('0x3')]=_0x2aa4b0;this[_0x8320('0x4')]=_0x32762a;this[_0x8320('0x5')]=_0x38175d;this[_0x8320('0x6')]=_0x277eba;this[_0x8320('0x7')]={};this['squeue'][_0x8320('0x8')](this[_0x8320('0x9')]['bind'](this),this[_0x8320('0xa')]['bind'](this),this[_0x8320('0xb')]);this['squeue']['on'](_0x8320('0xc'),this['handleTimeout']['bind'](this));this[_0x8320('0x3')]['on']('drained',this[_0x8320('0xd')][_0x8320('0xe')](this));};RRMemory[_0x8320('0xf')][_0x8320('0x8')]=function(){this['squeue']['push'](this[_0x8320('0x9')][_0x8320('0xe')](this),this[_0x8320('0xa')][_0x8320('0xe')](this));};RRMemory['prototype']['handleDrained']=function(){this[_0x8320('0xa')](!![]);};RRMemory[_0x8320('0xf')][_0x8320('0x10')]=function(_0x2bad14){if(util['isAgentAvailable'](this[_0x8320('0x3')]['id'],this[_0x8320('0x5')]['agents'][this[_0x8320('0x11')]],this['squeue'][_0x8320('0x12')],!![])){logger[_0x8320('0x13')]('[%s][QUEUE]\x20available\x20again\x20%s',this[_0x8320('0x3')]['id'],this[_0x8320('0x11')]);clearInterval(this['intervals'][this['agentId']]);_0x2bad14['done']();setTimeout(this[_0x8320('0x8')]['bind'](this),0x3e8);}};RRMemory[_0x8320('0xf')]['handleRun']=function(_0xf17e77){this[_0x8320('0x11')]=rr(this[_0x8320('0x4')]['mapAgentsId']);logger[_0x8320('0x13')](_0x8320('0x14'),this[_0x8320('0x3')]['id'],this[_0x8320('0x11')]);if(_['isNil'](this[_0x8320('0x5')][_0x8320('0x15')][this[_0x8320('0x11')]])){logger['debug'](_0x8320('0x16'),this[_0x8320('0x3')]['id'],this[_0x8320('0x11')]);_0xf17e77[_0x8320('0x17')]();setTimeout(this['push']['bind'](this),0x3e8);}else{if(util[_0x8320('0x18')](this[_0x8320('0x3')]['id'],this['realtime']['agents'][this[_0x8320('0x11')]],this['squeue']['channel'],!![])){this[_0x8320('0x5')][_0x8320('0x15')][this['agentId']][_0x8320('0x19')]=!![];this['realtime'][_0x8320('0x15')][this[_0x8320('0x11')]][_0x8320('0x1a')]=this['queue'][_0x8320('0x1b')];util[_0x8320('0x1c')](this[_0x8320('0x5')],this[_0x8320('0x6')],this[_0x8320('0x5')][_0x8320('0x15')][this[_0x8320('0x11')]],this['squeue'][_0x8320('0x12')]);util[_0x8320('0x1d')](this[_0x8320('0x1e')],this['squeue']['id'],this['realtime']['agents'][this[_0x8320('0x11')]],this[_0x8320('0x4')],this[_0x8320('0x6')]);util['writeLog'](this['squeue']['id'],this[_0x8320('0x5')][_0x8320('0x15')][this[_0x8320('0x11')]],'RINGING');this[_0x8320('0x7')][this[_0x8320('0x11')]]=setInterval(this[_0x8320('0x10')][_0x8320('0xe')](this,_0xf17e77),0x3e8);}else{logger[_0x8320('0x13')](_0x8320('0x1f'),this[_0x8320('0x3')]['id'],this['agentId']);_0xf17e77['done']();setTimeout(this[_0x8320('0x8')]['bind'](this),0x3e8);}}};RRMemory[_0x8320('0xf')][_0x8320('0xa')]=function(_0x500a78){logger[_0x8320('0x13')](_0x8320('0x20'),this[_0x8320('0x3')]['id'],this[_0x8320('0x11')]);if(_['isNil'](this[_0x8320('0x5')][_0x8320('0x15')][this['agentId']])){logger['debug'](_0x8320('0x16'),this[_0x8320('0x3')]['id'],this[_0x8320('0x11')]);}else{clearInterval(this[_0x8320('0x7')][this[_0x8320('0x11')]]);util['hideNotification'](this[_0x8320('0x1e')],this[_0x8320('0x3')]['id'],this['realtime']['agents'][this[_0x8320('0x11')]],this[_0x8320('0x4')],this[_0x8320('0x6')]);util[_0x8320('0x21')](this[_0x8320('0x3')]['id'],this[_0x8320('0x5')]['agents'][this[_0x8320('0x11')]],_0x8320('0x22'));this[_0x8320('0x5')][_0x8320('0x15')][this[_0x8320('0x11')]][_0x8320('0x19')]=![];this['realtime'][_0x8320('0x15')][this[_0x8320('0x11')]][_0x8320('0x1a')]=undefined;util[_0x8320('0x23')](this[_0x8320('0x5')],this[_0x8320('0x6')],this[_0x8320('0x5')][_0x8320('0x15')][this[_0x8320('0x11')]],this[_0x8320('0x3')][_0x8320('0x12')]);}if(!_0x500a78){setTimeout(this[_0x8320('0x8')]['bind'](this),0x3e8);}};function rrmemory(_0x416b08,_0x1d0bc7,_0xf0519d,_0x454be1){return new RRMemory(_0x416b08,_0x1d0bc7,_0xf0519d,_0x454be1);}module['exports']=rrmemory;