Built motion from commit e2351160.|2.5.50
[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 _0x61b1=['queue','realtime','intervals','squeue','push','handleRun','handleTimeout','bind','timeout','prototype','handleCheckReject','isAgentAvailable','agents','agentId','channel','done','mapAgentsId','info','[%s][QUEUE]\x20try\x20with\x20%s','isNil','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','busy','busyQueue','name','showNotification','writeLog','[%s][QUEUE]\x20timeout\x20with\x20%s','TIMEOUT','exports','lodash','uuid','./util','routing','notificationId'];(function(_0x18079d,_0x73a61c){var _0x698079=function(_0x4bcbb6){while(--_0x4bcbb6){_0x18079d['push'](_0x18079d['shift']());}};_0x698079(++_0x73a61c);}(_0x61b1,0x171));var _0x161b=function(_0x172725,_0x5bd46d){_0x172725=_0x172725-0x0;var _0x531ad1=_0x61b1[_0x172725];return _0x531ad1;};'use strict';var rr=require('rr');var _=require(_0x161b('0x0'));var uuid=require(_0x161b('0x1'));var util=require(_0x161b('0x2'));var logger=require('../../../../../config/logger')(_0x161b('0x3'));var RRMemory=function(_0x55c392,_0x26c994,_0x51fa43,_0x2a6140){this[_0x161b('0x4')]=uuid['v4']();this['squeue']=_0x55c392;this[_0x161b('0x5')]=_0x26c994;this[_0x161b('0x6')]=_0x51fa43;this['routing']=_0x2a6140;this[_0x161b('0x7')]={};this[_0x161b('0x8')][_0x161b('0x9')](this[_0x161b('0xa')]['bind'](this),this[_0x161b('0xb')][_0x161b('0xc')](this),this['module']);this[_0x161b('0x8')]['on'](_0x161b('0xd'),this['handleTimeout']['bind'](this));this[_0x161b('0x8')]['on']('drained',this['handleDrained'][_0x161b('0xc')](this));};RRMemory[_0x161b('0xe')][_0x161b('0x9')]=function(){this['squeue']['push'](this[_0x161b('0xa')][_0x161b('0xc')](this),this[_0x161b('0xb')]['bind'](this));};RRMemory[_0x161b('0xe')]['handleDrained']=function(_0x706984){this[_0x161b('0xb')](!![]);};RRMemory['prototype'][_0x161b('0xf')]=function(_0x5756ab){if(util[_0x161b('0x10')](this[_0x161b('0x8')]['id'],this[_0x161b('0x6')][_0x161b('0x11')][this[_0x161b('0x12')]],this[_0x161b('0x8')][_0x161b('0x13')],!![])){logger['info']('[%s][QUEUE]\x20available\x20again\x20%s',this[_0x161b('0x8')]['id'],this[_0x161b('0x12')]);clearInterval(this[_0x161b('0x7')][this[_0x161b('0x12')]]);_0x5756ab[_0x161b('0x14')]();setTimeout(this[_0x161b('0x9')][_0x161b('0xc')](this),0x3e8);}};RRMemory[_0x161b('0xe')][_0x161b('0xa')]=function(_0x2aa49f){this['agentId']=rr(this[_0x161b('0x5')][_0x161b('0x15')]);logger[_0x161b('0x16')](_0x161b('0x17'),this[_0x161b('0x8')]['id'],this[_0x161b('0x12')]);if(_[_0x161b('0x18')](this['realtime'][_0x161b('0x11')][this[_0x161b('0x12')]])){logger[_0x161b('0x16')](_0x161b('0x19'),this['squeue']['id'],this[_0x161b('0x12')]);_0x2aa49f['done']();setTimeout(this[_0x161b('0x9')][_0x161b('0xc')](this),0x3e8);}else{if(util[_0x161b('0x10')](this[_0x161b('0x8')]['id'],this['realtime'][_0x161b('0x11')][this[_0x161b('0x12')]],this[_0x161b('0x8')][_0x161b('0x13')],!![])){this[_0x161b('0x6')][_0x161b('0x11')][this[_0x161b('0x12')]][_0x161b('0x1a')]=!![];this[_0x161b('0x6')][_0x161b('0x11')][this[_0x161b('0x12')]][_0x161b('0x1b')]=this['queue'][_0x161b('0x1c')];util[_0x161b('0x1d')](this[_0x161b('0x4')],this['squeue']['id'],this['realtime'][_0x161b('0x11')][this['agentId']],this['queue'],this[_0x161b('0x3')]);util[_0x161b('0x1e')](this[_0x161b('0x8')]['id'],this[_0x161b('0x6')][_0x161b('0x11')][this[_0x161b('0x12')]],'RINGING');this['intervals'][this['agentId']]=setInterval(this['handleCheckReject'][_0x161b('0xc')](this,_0x2aa49f),0x3e8);}else{logger[_0x161b('0x16')]('[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s',this[_0x161b('0x8')]['id'],this[_0x161b('0x12')]);_0x2aa49f['done']();setTimeout(this[_0x161b('0x9')][_0x161b('0xc')](this),0x3e8);}}};RRMemory[_0x161b('0xe')]['handleTimeout']=function(_0x34a21e){logger[_0x161b('0x16')](_0x161b('0x1f'),this['squeue']['id'],this[_0x161b('0x12')]);if(_[_0x161b('0x18')](this[_0x161b('0x6')][_0x161b('0x11')][this['agentId']])){logger[_0x161b('0x16')]('[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0x161b('0x8')]['id'],this[_0x161b('0x12')]);}else{clearInterval(this[_0x161b('0x7')][this[_0x161b('0x12')]]);util['hideNotification'](this[_0x161b('0x4')],this[_0x161b('0x8')]['id'],this[_0x161b('0x6')][_0x161b('0x11')][this[_0x161b('0x12')]],this['queue'],this[_0x161b('0x3')]);util[_0x161b('0x1e')](this['squeue']['id'],this[_0x161b('0x6')]['agents'][this[_0x161b('0x12')]],_0x161b('0x20'));this[_0x161b('0x6')][_0x161b('0x11')][this[_0x161b('0x12')]][_0x161b('0x1a')]=![];this[_0x161b('0x6')][_0x161b('0x11')][this[_0x161b('0x12')]][_0x161b('0x1b')]=undefined;}if(!_0x34a21e){setTimeout(this[_0x161b('0x9')][_0x161b('0xc')](this),0x3e8);}};function rrmemory(_0x19ab04,_0x477556,_0x3473f9,_0x2941f9){return new RRMemory(_0x19ab04,_0x477556,_0x3473f9,_0x2941f9);}module[_0x161b('0x21')]=rrmemory;