5ba29b67fb3818d0cdfb69a568f4c44663cbfc54
[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 _0x46f6=['busyQueue','name','saveWaitingNotification','routing','showNotification','notificationId','writeLog','[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s','done','isNil','removeWaitingNotification','exports','lodash','./util','../../../../../config/logger','squeue','queue','intervals','push','bind','timeout','handleTimeout','drained','handleDrained','prototype','handleRun','handleCheckReject','isAgentAvailable','realtime','channel','debug','[%s][QUEUE]\x20available\x20again\x20%s','agentId','mapAgentsId','[%s][QUEUE]\x20try\x20with\x20%s','agents','busy'];(function(_0x42ea4b,_0x56c87a){var _0x2fc0c6=function(_0x2e1b27){while(--_0x2e1b27){_0x42ea4b['push'](_0x42ea4b['shift']());}};_0x2fc0c6(++_0x56c87a);}(_0x46f6,0x1c8));var _0x646f=function(_0x45ead9,_0x1887e4){_0x45ead9=_0x45ead9-0x0;var _0x9166c=_0x46f6[_0x45ead9];return _0x9166c;};'use strict';var rr=require('rr');var _=require(_0x646f('0x0'));var uuid=require('uuid');var util=require(_0x646f('0x1'));var logger=require(_0x646f('0x2'))('routing');var RRMemory=function(_0x491de7,_0x1041eb,_0x4d9310,_0x452526){this['notificationId']=uuid['v4']();this[_0x646f('0x3')]=_0x491de7;this[_0x646f('0x4')]=_0x1041eb;this['realtime']=_0x4d9310;this['routing']=_0x452526;this[_0x646f('0x5')]={};this[_0x646f('0x3')][_0x646f('0x6')](this['handleRun'][_0x646f('0x7')](this),this['handleTimeout'][_0x646f('0x7')](this),this['module']);this[_0x646f('0x3')]['on'](_0x646f('0x8'),this[_0x646f('0x9')][_0x646f('0x7')](this));this['squeue']['on'](_0x646f('0xa'),this[_0x646f('0xb')][_0x646f('0x7')](this));};RRMemory[_0x646f('0xc')][_0x646f('0x6')]=function(){this[_0x646f('0x3')][_0x646f('0x6')](this[_0x646f('0xd')][_0x646f('0x7')](this),this[_0x646f('0x9')][_0x646f('0x7')](this));};RRMemory[_0x646f('0xc')][_0x646f('0xb')]=function(){this[_0x646f('0x9')](!![]);};RRMemory['prototype'][_0x646f('0xe')]=function(_0x697658){if(util[_0x646f('0xf')](this[_0x646f('0x3')]['id'],this[_0x646f('0x10')]['agents'][this['agentId']],this[_0x646f('0x3')][_0x646f('0x11')],!![])){logger[_0x646f('0x12')](_0x646f('0x13'),this[_0x646f('0x3')]['id'],this[_0x646f('0x14')]);clearInterval(this[_0x646f('0x5')][this[_0x646f('0x14')]]);_0x697658['done']();setTimeout(this[_0x646f('0x6')][_0x646f('0x7')](this),0x3e8);}};RRMemory[_0x646f('0xc')]['handleRun']=function(_0x58ed7f){this['agentId']=rr(this[_0x646f('0x4')][_0x646f('0x15')]);logger['debug'](_0x646f('0x16'),this[_0x646f('0x3')]['id'],this[_0x646f('0x14')]);if(_['isNil'](this['realtime']['agents'][this[_0x646f('0x14')]])){logger['debug']('[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this['squeue']['id'],this[_0x646f('0x14')]);_0x58ed7f['done']();setTimeout(this[_0x646f('0x6')][_0x646f('0x7')](this),0x3e8);}else{if(util[_0x646f('0xf')](this[_0x646f('0x3')]['id'],this[_0x646f('0x10')][_0x646f('0x17')][this[_0x646f('0x14')]],this[_0x646f('0x3')]['channel'],!![])){this[_0x646f('0x10')][_0x646f('0x17')][this[_0x646f('0x14')]][_0x646f('0x18')]=!![];this[_0x646f('0x10')]['agents'][this[_0x646f('0x14')]][_0x646f('0x19')]=this[_0x646f('0x4')][_0x646f('0x1a')];util[_0x646f('0x1b')](this[_0x646f('0x10')],this[_0x646f('0x1c')],this['realtime'][_0x646f('0x17')][this[_0x646f('0x14')]],this['squeue'][_0x646f('0x11')]);util[_0x646f('0x1d')](this[_0x646f('0x1e')],this[_0x646f('0x3')]['id'],this[_0x646f('0x10')][_0x646f('0x17')][this['agentId']],this[_0x646f('0x4')],this['routing']);util[_0x646f('0x1f')](this['squeue']['id'],this[_0x646f('0x10')][_0x646f('0x17')][this[_0x646f('0x14')]],'RINGING');this['intervals'][this[_0x646f('0x14')]]=setInterval(this[_0x646f('0xe')]['bind'](this,_0x58ed7f),0x3e8);}else{logger[_0x646f('0x12')](_0x646f('0x20'),this[_0x646f('0x3')]['id'],this[_0x646f('0x14')]);_0x58ed7f[_0x646f('0x21')]();setTimeout(this[_0x646f('0x6')][_0x646f('0x7')](this),0x3e8);}}};RRMemory[_0x646f('0xc')][_0x646f('0x9')]=function(_0x2a2f05){logger[_0x646f('0x12')]('[%s][QUEUE]\x20timeout\x20with\x20%s',this[_0x646f('0x3')]['id'],this['agentId']);if(_[_0x646f('0x22')](this[_0x646f('0x10')][_0x646f('0x17')][this[_0x646f('0x14')]])){logger[_0x646f('0x12')]('[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0x646f('0x3')]['id'],this[_0x646f('0x14')]);}else{clearInterval(this['intervals'][this['agentId']]);util['hideNotification'](this[_0x646f('0x1e')],this['squeue']['id'],this['realtime'][_0x646f('0x17')][this[_0x646f('0x14')]],this[_0x646f('0x4')],this['routing']);util[_0x646f('0x1f')](this['squeue']['id'],this[_0x646f('0x10')][_0x646f('0x17')][this[_0x646f('0x14')]],'TIMEOUT');this[_0x646f('0x10')][_0x646f('0x17')][this['agentId']][_0x646f('0x18')]=![];this[_0x646f('0x10')][_0x646f('0x17')][this[_0x646f('0x14')]]['busyQueue']=undefined;util[_0x646f('0x23')](this[_0x646f('0x10')],this[_0x646f('0x1c')],this[_0x646f('0x10')][_0x646f('0x17')][this[_0x646f('0x14')]],this[_0x646f('0x3')]['channel']);}if(!_0x2a2f05){setTimeout(this[_0x646f('0x6')][_0x646f('0x7')](this),0x3e8);}};function rrmemory(_0x83bc9f,_0x231c4b,_0x2865b7,_0x3ac580){return new RRMemory(_0x83bc9f,_0x231c4b,_0x2865b7,_0x3ac580);}module[_0x646f('0x24')]=rrmemory;