f292f9653537d496b7a5d9b57dc8547ba345d998
[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 _0x3024=['module','timeout','drained','handleDrained','prototype','handleCheckReject','isAgentAvailable','agents','agentId','channel','debug','[%s][QUEUE]\x20available\x20again\x20%s','intervals','done','queue','[%s][QUEUE]\x20try\x20with\x20%s','isNil','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','showNotification','writeLog','RINGING','[%s][QUEUE]\x20timeout\x20with\x20%s','hideNotification','TIMEOUT','busyQueue','exports','lodash','uuid','../../../../../config/logger','routing','notificationId','squeue','realtime','push','handleRun','bind','handleTimeout'];(function(_0x398294,_0x5ceb9d){var _0x2a872d=function(_0x390883){while(--_0x390883){_0x398294['push'](_0x398294['shift']());}};_0x2a872d(++_0x5ceb9d);}(_0x3024,0x64));var _0x4302=function(_0x4574d3,_0x3be983){_0x4574d3=_0x4574d3-0x0;var _0xc68f26=_0x3024[_0x4574d3];return _0xc68f26;};'use strict';var rr=require('rr');var _=require(_0x4302('0x0'));var uuid=require(_0x4302('0x1'));var util=require('./util');var logger=require(_0x4302('0x2'))(_0x4302('0x3'));var RRMemory=function(_0x583f26,_0x520133,_0x22cb7f,_0x4ba02d){this[_0x4302('0x4')]=uuid['v4']();this[_0x4302('0x5')]=_0x583f26;this['queue']=_0x520133;this[_0x4302('0x6')]=_0x22cb7f;this[_0x4302('0x3')]=_0x4ba02d;this['intervals']={};this[_0x4302('0x5')][_0x4302('0x7')](this[_0x4302('0x8')][_0x4302('0x9')](this),this[_0x4302('0xa')][_0x4302('0x9')](this),this[_0x4302('0xb')]);this['squeue']['on'](_0x4302('0xc'),this[_0x4302('0xa')][_0x4302('0x9')](this));this['squeue']['on'](_0x4302('0xd'),this[_0x4302('0xe')]['bind'](this));};RRMemory[_0x4302('0xf')][_0x4302('0x7')]=function(){this[_0x4302('0x5')]['push'](this[_0x4302('0x8')][_0x4302('0x9')](this),this['handleTimeout'][_0x4302('0x9')](this));};RRMemory[_0x4302('0xf')][_0x4302('0xe')]=function(){this['handleTimeout'](!![]);};RRMemory[_0x4302('0xf')][_0x4302('0x10')]=function(_0x5ab66e){if(util[_0x4302('0x11')](this[_0x4302('0x5')]['id'],this['realtime'][_0x4302('0x12')][this[_0x4302('0x13')]],this[_0x4302('0x5')][_0x4302('0x14')],!![])){logger[_0x4302('0x15')](_0x4302('0x16'),this[_0x4302('0x5')]['id'],this[_0x4302('0x13')]);clearInterval(this[_0x4302('0x17')][this[_0x4302('0x13')]]);_0x5ab66e[_0x4302('0x18')]();setTimeout(this[_0x4302('0x7')][_0x4302('0x9')](this),0x3e8);}};RRMemory[_0x4302('0xf')]['handleRun']=function(_0x161780){this['agentId']=rr(this[_0x4302('0x19')]['mapAgentsId']);logger['debug'](_0x4302('0x1a'),this[_0x4302('0x5')]['id'],this[_0x4302('0x13')]);if(_[_0x4302('0x1b')](this['realtime']['agents'][this[_0x4302('0x13')]])){logger[_0x4302('0x15')](_0x4302('0x1c'),this['squeue']['id'],this[_0x4302('0x13')]);_0x161780[_0x4302('0x18')]();setTimeout(this[_0x4302('0x7')][_0x4302('0x9')](this),0x3e8);}else{if(util['isAgentAvailable'](this['squeue']['id'],this['realtime']['agents'][this[_0x4302('0x13')]],this[_0x4302('0x5')]['channel'],!![])){this[_0x4302('0x6')][_0x4302('0x12')][this[_0x4302('0x13')]]['busy']=!![];this[_0x4302('0x6')]['agents'][this['agentId']]['busyQueue']=this[_0x4302('0x19')]['name'];util[_0x4302('0x1d')](this[_0x4302('0x4')],this['squeue']['id'],this[_0x4302('0x6')]['agents'][this[_0x4302('0x13')]],this[_0x4302('0x19')],this[_0x4302('0x3')]);util[_0x4302('0x1e')](this[_0x4302('0x5')]['id'],this[_0x4302('0x6')][_0x4302('0x12')][this[_0x4302('0x13')]],_0x4302('0x1f'));this['intervals'][this[_0x4302('0x13')]]=setInterval(this[_0x4302('0x10')][_0x4302('0x9')](this,_0x161780),0x3e8);}else{logger[_0x4302('0x15')]('[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s',this[_0x4302('0x5')]['id'],this[_0x4302('0x13')]);_0x161780[_0x4302('0x18')]();setTimeout(this[_0x4302('0x7')][_0x4302('0x9')](this),0x3e8);}}};RRMemory['prototype'][_0x4302('0xa')]=function(_0xeadc9a){logger[_0x4302('0x15')](_0x4302('0x20'),this[_0x4302('0x5')]['id'],this[_0x4302('0x13')]);if(_[_0x4302('0x1b')](this[_0x4302('0x6')][_0x4302('0x12')][this['agentId']])){logger[_0x4302('0x15')]('[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0x4302('0x5')]['id'],this['agentId']);}else{clearInterval(this['intervals'][this[_0x4302('0x13')]]);util[_0x4302('0x21')](this[_0x4302('0x4')],this['squeue']['id'],this[_0x4302('0x6')][_0x4302('0x12')][this[_0x4302('0x13')]],this[_0x4302('0x19')],this['routing']);util[_0x4302('0x1e')](this['squeue']['id'],this[_0x4302('0x6')][_0x4302('0x12')][this[_0x4302('0x13')]],_0x4302('0x22'));this[_0x4302('0x6')]['agents'][this[_0x4302('0x13')]]['busy']=![];this['realtime']['agents'][this[_0x4302('0x13')]][_0x4302('0x23')]=undefined;}if(!_0xeadc9a){setTimeout(this[_0x4302('0x7')][_0x4302('0x9')](this),0x3e8);}};function rrmemory(_0x3fb639,_0x34f1b8,_0x3e8e3e,_0x263950){return new RRMemory(_0x3fb639,_0x34f1b8,_0x3e8e3e,_0x263950);}module[_0x4302('0x24')]=rrmemory;