Built motion from commit (unavailable).|2.5.14
[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 _0x91b5=['[%s][QUEUE]\x20try\x20with\x20%s','isNil','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','done','channel','busy','name','showNotification','writeLog','RINGING','[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s','hideNotification','TIMEOUT','./util','../../../../../config/logger','notificationId','squeue','queue','realtime','routing','intervals','push','handleRun','bind','handleTimeout','module','handleDrained','prototype','handleCheckReject','isAgentAvailable','agents','agentId','info','[%s][QUEUE]\x20available\x20again\x20%s'];(function(_0x111d44,_0x169f7e){var _0x53e96b=function(_0x2af72b){while(--_0x2af72b){_0x111d44['push'](_0x111d44['shift']());}};_0x53e96b(++_0x169f7e);}(_0x91b5,0xb7));var _0x591b=function(_0x3aecc1,_0x527393){_0x3aecc1=_0x3aecc1-0x0;var _0x3d032d=_0x91b5[_0x3aecc1];return _0x3d032d;};'use strict';var rr=require('rr');var _=require('lodash');var uuid=require('uuid');var util=require(_0x591b('0x0'));var logger=require(_0x591b('0x1'))('routing');var RRMemory=function(_0x3de47b,_0x5964c0,_0xcd392e,_0x924f30){this[_0x591b('0x2')]=uuid['v4']();this[_0x591b('0x3')]=_0x3de47b;this[_0x591b('0x4')]=_0x5964c0;this[_0x591b('0x5')]=_0xcd392e;this[_0x591b('0x6')]=_0x924f30;this[_0x591b('0x7')]={};this[_0x591b('0x3')][_0x591b('0x8')](this[_0x591b('0x9')][_0x591b('0xa')](this),this[_0x591b('0xb')]['bind'](this),this[_0x591b('0xc')]);this[_0x591b('0x3')]['on']('timeout',this[_0x591b('0xb')][_0x591b('0xa')](this));this[_0x591b('0x3')]['on']('drained',this[_0x591b('0xd')]['bind'](this));};RRMemory[_0x591b('0xe')][_0x591b('0x8')]=function(){this[_0x591b('0x3')][_0x591b('0x8')](this[_0x591b('0x9')][_0x591b('0xa')](this),this['handleTimeout'][_0x591b('0xa')](this));};RRMemory[_0x591b('0xe')][_0x591b('0xd')]=function(_0x3967b0){this[_0x591b('0xb')](!![]);};RRMemory[_0x591b('0xe')][_0x591b('0xf')]=function(_0x1854c2){if(util[_0x591b('0x10')](this[_0x591b('0x3')]['id'],this[_0x591b('0x5')][_0x591b('0x11')][this[_0x591b('0x12')]],this[_0x591b('0x3')]['channel'],!![])){logger[_0x591b('0x13')](_0x591b('0x14'),this[_0x591b('0x3')]['id'],this[_0x591b('0x12')]);clearInterval(this['intervals'][this[_0x591b('0x12')]]);_0x1854c2['done']();setTimeout(this['push'][_0x591b('0xa')](this),0x3e8);}};RRMemory[_0x591b('0xe')][_0x591b('0x9')]=function(_0x33671f){this['agentId']=rr(this['queue']['mapAgentsId']);logger[_0x591b('0x13')](_0x591b('0x15'),this['squeue']['id'],this['agentId']);if(_[_0x591b('0x16')](this[_0x591b('0x5')]['agents'][this[_0x591b('0x12')]])){logger['info'](_0x591b('0x17'),this[_0x591b('0x3')]['id'],this['agentId']);_0x33671f[_0x591b('0x18')]();setTimeout(this[_0x591b('0x8')][_0x591b('0xa')](this),0x3e8);}else{if(util['isAgentAvailable'](this['squeue']['id'],this[_0x591b('0x5')][_0x591b('0x11')][this['agentId']],this[_0x591b('0x3')][_0x591b('0x19')],!![])){this[_0x591b('0x5')]['agents'][this[_0x591b('0x12')]][_0x591b('0x1a')]=!![];this[_0x591b('0x5')][_0x591b('0x11')][this['agentId']]['busyQueue']=this[_0x591b('0x4')][_0x591b('0x1b')];util[_0x591b('0x1c')](this[_0x591b('0x2')],this[_0x591b('0x3')]['id'],this['realtime'][_0x591b('0x11')][this['agentId']],this[_0x591b('0x4')],this[_0x591b('0x6')]);util[_0x591b('0x1d')](this[_0x591b('0x3')]['id'],this[_0x591b('0x5')][_0x591b('0x11')][this[_0x591b('0x12')]],_0x591b('0x1e'));this[_0x591b('0x7')][this['agentId']]=setInterval(this[_0x591b('0xf')][_0x591b('0xa')](this,_0x33671f),0x3e8);}else{logger['info'](_0x591b('0x1f'),this['squeue']['id'],this['agentId']);_0x33671f[_0x591b('0x18')]();setTimeout(this[_0x591b('0x8')][_0x591b('0xa')](this),0x3e8);}}};RRMemory[_0x591b('0xe')]['handleTimeout']=function(_0x19803e){logger[_0x591b('0x13')]('[%s][QUEUE]\x20timeout\x20with\x20%s',this[_0x591b('0x3')]['id'],this[_0x591b('0x12')]);if(_['isNil'](this[_0x591b('0x5')][_0x591b('0x11')][this['agentId']])){logger['info']('[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0x591b('0x3')]['id'],this[_0x591b('0x12')]);}else{clearInterval(this[_0x591b('0x7')][this[_0x591b('0x12')]]);util[_0x591b('0x20')](this[_0x591b('0x2')],this[_0x591b('0x3')]['id'],this[_0x591b('0x5')][_0x591b('0x11')][this[_0x591b('0x12')]],this['queue'],this[_0x591b('0x6')]);util[_0x591b('0x1d')](this[_0x591b('0x3')]['id'],this[_0x591b('0x5')][_0x591b('0x11')][this['agentId']],_0x591b('0x21'));this[_0x591b('0x5')][_0x591b('0x11')][this[_0x591b('0x12')]][_0x591b('0x1a')]=![];this[_0x591b('0x5')][_0x591b('0x11')][this[_0x591b('0x12')]]['busyQueue']=undefined;}if(!_0x19803e){setTimeout(this[_0x591b('0x8')][_0x591b('0xa')](this),0x3e8);}};function rrmemory(_0x336c4a,_0xbc73e0,_0x55780a,_0x403cab){return new RRMemory(_0x336c4a,_0xbc73e0,_0x55780a,_0x403cab);}module['exports']=rrmemory;