19d72b932dfae20b89b37415d35274805cb390c7
[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 _0x908f=['realtime','routing','intervals','push','handleRun','handleTimeout','bind','module','timeout','drained','handleDrained','prototype','handleCheckReject','isAgentAvailable','agents','agentId','[%s][QUEUE]\x20available\x20again\x20%s','queue','debug','[%s][QUEUE]\x20try\x20with\x20%s','isNil','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','channel','busy','busyQueue','name','saveWaitingNotification','showNotification','writeLog','RINGING','done','[%s][QUEUE]\x20timeout\x20with\x20%s','TIMEOUT','removeWaitingNotification','exports','lodash','uuid','./util','notificationId','squeue'];(function(_0x1beae6,_0x43bff5){var _0x166332=function(_0x58f01a){while(--_0x58f01a){_0x1beae6['push'](_0x1beae6['shift']());}};_0x166332(++_0x43bff5);}(_0x908f,0x9b));var _0xf908=function(_0x15dfe8,_0x842b22){_0x15dfe8=_0x15dfe8-0x0;var _0x4ca4e6=_0x908f[_0x15dfe8];return _0x4ca4e6;};'use strict';var rr=require('rr');var _=require(_0xf908('0x0'));var uuid=require(_0xf908('0x1'));var util=require(_0xf908('0x2'));var logger=require('../../../../../config/logger')('routing');var RRMemory=function(_0x40223a,_0x4668fe,_0x4bea81,_0x133565){this[_0xf908('0x3')]=uuid['v4']();this[_0xf908('0x4')]=_0x40223a;this['queue']=_0x4668fe;this[_0xf908('0x5')]=_0x4bea81;this[_0xf908('0x6')]=_0x133565;this[_0xf908('0x7')]={};this['squeue'][_0xf908('0x8')](this[_0xf908('0x9')]['bind'](this),this[_0xf908('0xa')][_0xf908('0xb')](this),this[_0xf908('0xc')]);this[_0xf908('0x4')]['on'](_0xf908('0xd'),this['handleTimeout'][_0xf908('0xb')](this));this[_0xf908('0x4')]['on'](_0xf908('0xe'),this[_0xf908('0xf')]['bind'](this));};RRMemory['prototype'][_0xf908('0x8')]=function(){this[_0xf908('0x4')]['push'](this['handleRun']['bind'](this),this['handleTimeout'][_0xf908('0xb')](this));};RRMemory[_0xf908('0x10')]['handleDrained']=function(){this[_0xf908('0xa')](!![]);};RRMemory[_0xf908('0x10')][_0xf908('0x11')]=function(_0x45dbfe){if(util[_0xf908('0x12')](this[_0xf908('0x4')]['id'],this[_0xf908('0x5')][_0xf908('0x13')][this[_0xf908('0x14')]],this['squeue']['channel'],!![])){logger['debug'](_0xf908('0x15'),this[_0xf908('0x4')]['id'],this[_0xf908('0x14')]);clearInterval(this['intervals'][this[_0xf908('0x14')]]);_0x45dbfe['done']();setTimeout(this['push'][_0xf908('0xb')](this),0x3e8);}};RRMemory['prototype'][_0xf908('0x9')]=function(_0x42b7dc){this[_0xf908('0x14')]=rr(this[_0xf908('0x16')]['mapAgentsId']);logger[_0xf908('0x17')](_0xf908('0x18'),this[_0xf908('0x4')]['id'],this[_0xf908('0x14')]);if(_[_0xf908('0x19')](this['realtime'][_0xf908('0x13')][this[_0xf908('0x14')]])){logger[_0xf908('0x17')](_0xf908('0x1a'),this[_0xf908('0x4')]['id'],this[_0xf908('0x14')]);_0x42b7dc['done']();setTimeout(this[_0xf908('0x8')][_0xf908('0xb')](this),0x3e8);}else{if(util[_0xf908('0x12')](this[_0xf908('0x4')]['id'],this[_0xf908('0x5')][_0xf908('0x13')][this[_0xf908('0x14')]],this['squeue'][_0xf908('0x1b')],!![])){this['realtime'][_0xf908('0x13')][this[_0xf908('0x14')]][_0xf908('0x1c')]=!![];this[_0xf908('0x5')][_0xf908('0x13')][this[_0xf908('0x14')]][_0xf908('0x1d')]=this[_0xf908('0x16')][_0xf908('0x1e')];util[_0xf908('0x1f')](this[_0xf908('0x5')],this[_0xf908('0x6')],this[_0xf908('0x5')][_0xf908('0x13')][this[_0xf908('0x14')]],this[_0xf908('0x4')][_0xf908('0x1b')]);util[_0xf908('0x20')](this['notificationId'],this['squeue']['id'],this['realtime'][_0xf908('0x13')][this['agentId']],this['queue'],this[_0xf908('0x6')]);util[_0xf908('0x21')](this[_0xf908('0x4')]['id'],this['realtime'][_0xf908('0x13')][this[_0xf908('0x14')]],_0xf908('0x22'));this[_0xf908('0x7')][this[_0xf908('0x14')]]=setInterval(this['handleCheckReject'][_0xf908('0xb')](this,_0x42b7dc),0x3e8);}else{logger[_0xf908('0x17')]('[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s',this[_0xf908('0x4')]['id'],this[_0xf908('0x14')]);_0x42b7dc[_0xf908('0x23')]();setTimeout(this[_0xf908('0x8')][_0xf908('0xb')](this),0x3e8);}}};RRMemory['prototype']['handleTimeout']=function(_0x22e55c){logger['debug'](_0xf908('0x24'),this[_0xf908('0x4')]['id'],this[_0xf908('0x14')]);if(_[_0xf908('0x19')](this[_0xf908('0x5')]['agents'][this[_0xf908('0x14')]])){logger[_0xf908('0x17')]('[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0xf908('0x4')]['id'],this[_0xf908('0x14')]);}else{clearInterval(this[_0xf908('0x7')][this[_0xf908('0x14')]]);util['hideNotification'](this[_0xf908('0x3')],this[_0xf908('0x4')]['id'],this[_0xf908('0x5')]['agents'][this[_0xf908('0x14')]],this[_0xf908('0x16')],this['routing']);util[_0xf908('0x21')](this['squeue']['id'],this[_0xf908('0x5')][_0xf908('0x13')][this[_0xf908('0x14')]],_0xf908('0x25'));this['realtime'][_0xf908('0x13')][this[_0xf908('0x14')]][_0xf908('0x1c')]=![];this[_0xf908('0x5')][_0xf908('0x13')][this[_0xf908('0x14')]]['busyQueue']=undefined;util[_0xf908('0x26')](this[_0xf908('0x5')],this[_0xf908('0x6')],this['realtime'][_0xf908('0x13')][this[_0xf908('0x14')]],this[_0xf908('0x4')][_0xf908('0x1b')]);}if(!_0x22e55c){setTimeout(this[_0xf908('0x8')][_0xf908('0xb')](this),0x3e8);}};function rrmemory(_0x187ae5,_0x2dc150,_0x10df37,_0x4f53aa){return new RRMemory(_0x187ae5,_0x2dc150,_0x10df37,_0x4f53aa);}module[_0xf908('0x27')]=rrmemory;