Built motion from commit 746c7d2a.|2.5.35
[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 _0xa729=['info','done','isNil','agents','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','channel','busy','busyQueue','showNotification','writeLog','RINGING','handleCheckReject','[%s][QUEUE]\x20timeout\x20with\x20%s','hideNotification','TIMEOUT','exports','uuid','./util','notificationId','queue','realtime','routing','intervals','squeue','push','handleRun','handleTimeout','bind','module','timeout','drained','prototype','handleDrained','isAgentAvailable','agentId'];(function(_0x6c9e92,_0x45399a){var _0x4a8367=function(_0x5d3112){while(--_0x5d3112){_0x6c9e92['push'](_0x6c9e92['shift']());}};_0x4a8367(++_0x45399a);}(_0xa729,0x1d7));var _0x9a72=function(_0x2b3dfe,_0x2e9db2){_0x2b3dfe=_0x2b3dfe-0x0;var _0xe18ef1=_0xa729[_0x2b3dfe];return _0xe18ef1;};'use strict';var rr=require('rr');var _=require('lodash');var uuid=require(_0x9a72('0x0'));var util=require(_0x9a72('0x1'));var logger=require('../../../../../config/logger')('routing');var RRMemory=function(_0x405117,_0x2fcf55,_0x25ef39,_0x4fcb13){this[_0x9a72('0x2')]=uuid['v4']();this['squeue']=_0x405117;this[_0x9a72('0x3')]=_0x2fcf55;this[_0x9a72('0x4')]=_0x25ef39;this[_0x9a72('0x5')]=_0x4fcb13;this[_0x9a72('0x6')]={};this[_0x9a72('0x7')][_0x9a72('0x8')](this[_0x9a72('0x9')]['bind'](this),this[_0x9a72('0xa')][_0x9a72('0xb')](this),this[_0x9a72('0xc')]);this[_0x9a72('0x7')]['on'](_0x9a72('0xd'),this['handleTimeout']['bind'](this));this[_0x9a72('0x7')]['on'](_0x9a72('0xe'),this['handleDrained']['bind'](this));};RRMemory[_0x9a72('0xf')]['push']=function(){this['squeue'][_0x9a72('0x8')](this[_0x9a72('0x9')]['bind'](this),this[_0x9a72('0xa')]['bind'](this));};RRMemory[_0x9a72('0xf')][_0x9a72('0x10')]=function(_0x251ba9){this['handleTimeout'](!![]);};RRMemory['prototype']['handleCheckReject']=function(_0x310035){if(util[_0x9a72('0x11')](this[_0x9a72('0x7')]['id'],this[_0x9a72('0x4')]['agents'][this[_0x9a72('0x12')]],this['squeue']['channel'],!![])){logger[_0x9a72('0x13')]('[%s][QUEUE]\x20available\x20again\x20%s',this[_0x9a72('0x7')]['id'],this[_0x9a72('0x12')]);clearInterval(this[_0x9a72('0x6')][this['agentId']]);_0x310035[_0x9a72('0x14')]();setTimeout(this[_0x9a72('0x8')][_0x9a72('0xb')](this),0x3e8);}};RRMemory['prototype']['handleRun']=function(_0x2854b6){this[_0x9a72('0x12')]=rr(this['queue']['mapAgentsId']);logger['info']('[%s][QUEUE]\x20try\x20with\x20%s',this[_0x9a72('0x7')]['id'],this[_0x9a72('0x12')]);if(_[_0x9a72('0x15')](this['realtime'][_0x9a72('0x16')][this['agentId']])){logger[_0x9a72('0x13')](_0x9a72('0x17'),this['squeue']['id'],this['agentId']);_0x2854b6['done']();setTimeout(this[_0x9a72('0x8')]['bind'](this),0x3e8);}else{if(util[_0x9a72('0x11')](this['squeue']['id'],this[_0x9a72('0x4')][_0x9a72('0x16')][this[_0x9a72('0x12')]],this[_0x9a72('0x7')][_0x9a72('0x18')],!![])){this['realtime'][_0x9a72('0x16')][this[_0x9a72('0x12')]][_0x9a72('0x19')]=!![];this[_0x9a72('0x4')]['agents'][this[_0x9a72('0x12')]][_0x9a72('0x1a')]=this['queue']['name'];util[_0x9a72('0x1b')](this[_0x9a72('0x2')],this[_0x9a72('0x7')]['id'],this[_0x9a72('0x4')][_0x9a72('0x16')][this[_0x9a72('0x12')]],this['queue'],this[_0x9a72('0x5')]);util[_0x9a72('0x1c')](this['squeue']['id'],this[_0x9a72('0x4')]['agents'][this[_0x9a72('0x12')]],_0x9a72('0x1d'));this['intervals'][this[_0x9a72('0x12')]]=setInterval(this[_0x9a72('0x1e')][_0x9a72('0xb')](this,_0x2854b6),0x3e8);}else{logger[_0x9a72('0x13')]('[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s',this[_0x9a72('0x7')]['id'],this[_0x9a72('0x12')]);_0x2854b6['done']();setTimeout(this['push'][_0x9a72('0xb')](this),0x3e8);}}};RRMemory['prototype'][_0x9a72('0xa')]=function(_0x2e5f0e){logger[_0x9a72('0x13')](_0x9a72('0x1f'),this[_0x9a72('0x7')]['id'],this[_0x9a72('0x12')]);if(_['isNil'](this['realtime'][_0x9a72('0x16')][this[_0x9a72('0x12')]])){logger[_0x9a72('0x13')]('[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0x9a72('0x7')]['id'],this[_0x9a72('0x12')]);}else{clearInterval(this[_0x9a72('0x6')][this[_0x9a72('0x12')]]);util[_0x9a72('0x20')](this[_0x9a72('0x2')],this[_0x9a72('0x7')]['id'],this[_0x9a72('0x4')][_0x9a72('0x16')][this['agentId']],this[_0x9a72('0x3')],this[_0x9a72('0x5')]);util[_0x9a72('0x1c')](this[_0x9a72('0x7')]['id'],this[_0x9a72('0x4')]['agents'][this[_0x9a72('0x12')]],_0x9a72('0x21'));this[_0x9a72('0x4')][_0x9a72('0x16')][this['agentId']][_0x9a72('0x19')]=![];this[_0x9a72('0x4')][_0x9a72('0x16')][this[_0x9a72('0x12')]][_0x9a72('0x1a')]=undefined;}if(!_0x2e5f0e){setTimeout(this[_0x9a72('0x8')][_0x9a72('0xb')](this),0x3e8);}};function rrmemory(_0x174c97,_0x599872,_0x5c9d13,_0x375b80){return new RRMemory(_0x174c97,_0x599872,_0x5c9d13,_0x375b80);}module[_0x9a72('0x22')]=rrmemory;