8773c2d05db6392a6c7f47ca15f1196e00e37bf6
[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 _0xde13=['handleTimeout','bind','module','timeout','handleDrained','prototype','isAgentAvailable','agentId','channel','debug','[%s][QUEUE]\x20available\x20again\x20%s','intervals','mapAgentsId','[%s][QUEUE]\x20try\x20with\x20%s','agents','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','done','busy','busyQueue','saveWaitingNotification','[%s][QUEUE]\x20timeout\x20with\x20%s','isNil','hideNotification','writeLog','TIMEOUT','removeWaitingNotification','exports','lodash','uuid','../../../../../config/logger','notificationId','squeue','queue','realtime','routing','push','handleRun'];(function(_0x2249db,_0x42ccd8){var _0x56adba=function(_0x5b85d9){while(--_0x5b85d9){_0x2249db['push'](_0x2249db['shift']());}};_0x56adba(++_0x42ccd8);}(_0xde13,0x11e));var _0x3de1=function(_0x140669,_0x2f783e){_0x140669=_0x140669-0x0;var _0xd35dc7=_0xde13[_0x140669];return _0xd35dc7;};'use strict';var rr=require('rr');var _=require(_0x3de1('0x0'));var uuid=require(_0x3de1('0x1'));var util=require('./util');var logger=require(_0x3de1('0x2'))('routing');var RRMemory=function(_0x822fda,_0x348a4d,_0x38dd55,_0x1cacdc){this[_0x3de1('0x3')]=uuid['v4']();this[_0x3de1('0x4')]=_0x822fda;this[_0x3de1('0x5')]=_0x348a4d;this[_0x3de1('0x6')]=_0x38dd55;this[_0x3de1('0x7')]=_0x1cacdc;this['intervals']={};this[_0x3de1('0x4')][_0x3de1('0x8')](this[_0x3de1('0x9')]['bind'](this),this[_0x3de1('0xa')][_0x3de1('0xb')](this),this[_0x3de1('0xc')]);this[_0x3de1('0x4')]['on'](_0x3de1('0xd'),this[_0x3de1('0xa')]['bind'](this));this[_0x3de1('0x4')]['on']('drained',this[_0x3de1('0xe')]['bind'](this));};RRMemory[_0x3de1('0xf')]['push']=function(){this[_0x3de1('0x4')][_0x3de1('0x8')](this[_0x3de1('0x9')][_0x3de1('0xb')](this),this[_0x3de1('0xa')][_0x3de1('0xb')](this));};RRMemory[_0x3de1('0xf')][_0x3de1('0xe')]=function(){this[_0x3de1('0xa')](!![]);};RRMemory['prototype']['handleCheckReject']=function(_0x1759c2){if(util[_0x3de1('0x10')](this[_0x3de1('0x4')]['id'],this[_0x3de1('0x6')]['agents'][this[_0x3de1('0x11')]],this[_0x3de1('0x4')][_0x3de1('0x12')],!![])){logger[_0x3de1('0x13')](_0x3de1('0x14'),this[_0x3de1('0x4')]['id'],this['agentId']);clearInterval(this[_0x3de1('0x15')][this[_0x3de1('0x11')]]);_0x1759c2['done']();setTimeout(this['push']['bind'](this),0x3e8);}};RRMemory[_0x3de1('0xf')]['handleRun']=function(_0x1aee99){this[_0x3de1('0x11')]=rr(this['queue'][_0x3de1('0x16')]);logger['debug'](_0x3de1('0x17'),this[_0x3de1('0x4')]['id'],this[_0x3de1('0x11')]);if(_['isNil'](this[_0x3de1('0x6')][_0x3de1('0x18')][this['agentId']])){logger[_0x3de1('0x13')](_0x3de1('0x19'),this[_0x3de1('0x4')]['id'],this[_0x3de1('0x11')]);_0x1aee99[_0x3de1('0x1a')]();setTimeout(this[_0x3de1('0x8')][_0x3de1('0xb')](this),0x3e8);}else{if(util['isAgentAvailable'](this[_0x3de1('0x4')]['id'],this[_0x3de1('0x6')]['agents'][this['agentId']],this[_0x3de1('0x4')][_0x3de1('0x12')],!![])){this[_0x3de1('0x6')][_0x3de1('0x18')][this[_0x3de1('0x11')]][_0x3de1('0x1b')]=!![];this['realtime']['agents'][this[_0x3de1('0x11')]][_0x3de1('0x1c')]=this[_0x3de1('0x5')]['name'];util[_0x3de1('0x1d')](this[_0x3de1('0x6')],this[_0x3de1('0x7')],this[_0x3de1('0x6')]['agents'][this[_0x3de1('0x11')]],this[_0x3de1('0x4')]['channel']);util['showNotification'](this[_0x3de1('0x3')],this[_0x3de1('0x4')]['id'],this[_0x3de1('0x6')]['agents'][this[_0x3de1('0x11')]],this[_0x3de1('0x5')],this[_0x3de1('0x7')]);util['writeLog'](this[_0x3de1('0x4')]['id'],this[_0x3de1('0x6')][_0x3de1('0x18')][this[_0x3de1('0x11')]],'RINGING');this[_0x3de1('0x15')][this[_0x3de1('0x11')]]=setInterval(this['handleCheckReject'][_0x3de1('0xb')](this,_0x1aee99),0x3e8);}else{logger[_0x3de1('0x13')]('[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s',this['squeue']['id'],this[_0x3de1('0x11')]);_0x1aee99[_0x3de1('0x1a')]();setTimeout(this['push'][_0x3de1('0xb')](this),0x3e8);}}};RRMemory[_0x3de1('0xf')]['handleTimeout']=function(_0x3792f6){logger['debug'](_0x3de1('0x1e'),this[_0x3de1('0x4')]['id'],this[_0x3de1('0x11')]);if(_[_0x3de1('0x1f')](this[_0x3de1('0x6')][_0x3de1('0x18')][this['agentId']])){logger[_0x3de1('0x13')](_0x3de1('0x19'),this[_0x3de1('0x4')]['id'],this[_0x3de1('0x11')]);}else{clearInterval(this[_0x3de1('0x15')][this[_0x3de1('0x11')]]);util[_0x3de1('0x20')](this[_0x3de1('0x3')],this[_0x3de1('0x4')]['id'],this['realtime'][_0x3de1('0x18')][this[_0x3de1('0x11')]],this['queue'],this[_0x3de1('0x7')]);util[_0x3de1('0x21')](this[_0x3de1('0x4')]['id'],this[_0x3de1('0x6')][_0x3de1('0x18')][this[_0x3de1('0x11')]],_0x3de1('0x22'));this['realtime'][_0x3de1('0x18')][this[_0x3de1('0x11')]]['busy']=![];this[_0x3de1('0x6')]['agents'][this['agentId']][_0x3de1('0x1c')]=undefined;util[_0x3de1('0x23')](this['realtime'],this['routing'],this[_0x3de1('0x6')][_0x3de1('0x18')][this['agentId']],this['squeue'][_0x3de1('0x12')]);}if(!_0x3792f6){setTimeout(this[_0x3de1('0x8')][_0x3de1('0xb')](this),0x3e8);}};function rrmemory(_0x205365,_0x47a960,_0x11d814,_0x368751){return new RRMemory(_0x205365,_0x47a960,_0x11d814,_0x368751);}module[_0x3de1('0x24')]=rrmemory;