2870606e60ad852da9decbb94664a132fed776b3
[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 _0x4986=['realtime','agents','agentId','info','[%s][QUEUE]\x20available\x20again\x20%s','done','[%s][QUEUE]\x20try\x20with\x20%s','isNil','isAgentAvailable','channel','busy','busyQueue','name','showNotification','writeLog','RINGING','handleCheckReject','[%s][QUEUE]\x20timeout\x20with\x20%s','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','hideNotification','TIMEOUT','exports','lodash','uuid','../../../../../config/logger','routing','notificationId','squeue','queue','intervals','push','handleRun','bind','handleTimeout','module','timeout','drained','handleDrained','prototype'];(function(_0x20d8fc,_0x118b7c){var _0x5750dc=function(_0x2df344){while(--_0x2df344){_0x20d8fc['push'](_0x20d8fc['shift']());}};_0x5750dc(++_0x118b7c);}(_0x4986,0x1c3));var _0x6498=function(_0x351ce8,_0x3febdc){_0x351ce8=_0x351ce8-0x0;var _0x22c2a9=_0x4986[_0x351ce8];return _0x22c2a9;};'use strict';var rr=require('rr');var _=require(_0x6498('0x0'));var uuid=require(_0x6498('0x1'));var util=require('./util');var logger=require(_0x6498('0x2'))(_0x6498('0x3'));var RRMemory=function(_0x3f71b5,_0x11b0dc,_0x103fd7,_0x330528){this[_0x6498('0x4')]=uuid['v4']();this[_0x6498('0x5')]=_0x3f71b5;this[_0x6498('0x6')]=_0x11b0dc;this['realtime']=_0x103fd7;this[_0x6498('0x3')]=_0x330528;this[_0x6498('0x7')]={};this[_0x6498('0x5')][_0x6498('0x8')](this[_0x6498('0x9')][_0x6498('0xa')](this),this[_0x6498('0xb')]['bind'](this),this[_0x6498('0xc')]);this[_0x6498('0x5')]['on'](_0x6498('0xd'),this[_0x6498('0xb')][_0x6498('0xa')](this));this[_0x6498('0x5')]['on'](_0x6498('0xe'),this[_0x6498('0xf')][_0x6498('0xa')](this));};RRMemory['prototype'][_0x6498('0x8')]=function(){this[_0x6498('0x5')][_0x6498('0x8')](this[_0x6498('0x9')]['bind'](this),this['handleTimeout'][_0x6498('0xa')](this));};RRMemory[_0x6498('0x10')]['handleDrained']=function(_0x41ef0e){this['handleTimeout'](!![]);};RRMemory[_0x6498('0x10')]['handleCheckReject']=function(_0x49ec2c){if(util['isAgentAvailable'](this['squeue']['id'],this[_0x6498('0x11')][_0x6498('0x12')][this[_0x6498('0x13')]],this[_0x6498('0x5')]['channel'],!![])){logger[_0x6498('0x14')](_0x6498('0x15'),this[_0x6498('0x5')]['id'],this[_0x6498('0x13')]);clearInterval(this[_0x6498('0x7')][this['agentId']]);_0x49ec2c[_0x6498('0x16')]();setTimeout(this['push'][_0x6498('0xa')](this),0x3e8);}};RRMemory[_0x6498('0x10')]['handleRun']=function(_0x35d9e7){this['agentId']=rr(this[_0x6498('0x6')]['mapAgentsId']);logger[_0x6498('0x14')](_0x6498('0x17'),this[_0x6498('0x5')]['id'],this[_0x6498('0x13')]);if(_[_0x6498('0x18')](this[_0x6498('0x11')]['agents'][this[_0x6498('0x13')]])){logger[_0x6498('0x14')]('[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0x6498('0x5')]['id'],this[_0x6498('0x13')]);_0x35d9e7['done']();setTimeout(this['push'][_0x6498('0xa')](this),0x3e8);}else{if(util[_0x6498('0x19')](this['squeue']['id'],this[_0x6498('0x11')][_0x6498('0x12')][this['agentId']],this[_0x6498('0x5')][_0x6498('0x1a')],!![])){this[_0x6498('0x11')][_0x6498('0x12')][this[_0x6498('0x13')]][_0x6498('0x1b')]=!![];this[_0x6498('0x11')][_0x6498('0x12')][this['agentId']][_0x6498('0x1c')]=this[_0x6498('0x6')][_0x6498('0x1d')];util[_0x6498('0x1e')](this['notificationId'],this[_0x6498('0x5')]['id'],this[_0x6498('0x11')][_0x6498('0x12')][this[_0x6498('0x13')]],this['queue'],this[_0x6498('0x3')]);util[_0x6498('0x1f')](this['squeue']['id'],this[_0x6498('0x11')][_0x6498('0x12')][this['agentId']],_0x6498('0x20'));this[_0x6498('0x7')][this[_0x6498('0x13')]]=setInterval(this[_0x6498('0x21')][_0x6498('0xa')](this,_0x35d9e7),0x3e8);}else{logger[_0x6498('0x14')]('[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s',this[_0x6498('0x5')]['id'],this[_0x6498('0x13')]);_0x35d9e7[_0x6498('0x16')]();setTimeout(this[_0x6498('0x8')][_0x6498('0xa')](this),0x3e8);}}};RRMemory['prototype'][_0x6498('0xb')]=function(_0x1af009){logger[_0x6498('0x14')](_0x6498('0x22'),this[_0x6498('0x5')]['id'],this[_0x6498('0x13')]);if(_[_0x6498('0x18')](this[_0x6498('0x11')][_0x6498('0x12')][this[_0x6498('0x13')]])){logger[_0x6498('0x14')](_0x6498('0x23'),this['squeue']['id'],this['agentId']);}else{clearInterval(this[_0x6498('0x7')][this['agentId']]);util[_0x6498('0x24')](this[_0x6498('0x4')],this[_0x6498('0x5')]['id'],this[_0x6498('0x11')][_0x6498('0x12')][this[_0x6498('0x13')]],this[_0x6498('0x6')],this[_0x6498('0x3')]);util[_0x6498('0x1f')](this['squeue']['id'],this[_0x6498('0x11')]['agents'][this[_0x6498('0x13')]],_0x6498('0x25'));this[_0x6498('0x11')][_0x6498('0x12')][this['agentId']]['busy']=![];this[_0x6498('0x11')]['agents'][this[_0x6498('0x13')]]['busyQueue']=undefined;}if(!_0x1af009){setTimeout(this[_0x6498('0x8')][_0x6498('0xa')](this),0x3e8);}};function rrmemory(_0x6efc9f,_0x36e9e9,_0x17d2e3,_0x3a9047){return new RRMemory(_0x6efc9f,_0x36e9e9,_0x17d2e3,_0x3a9047);}module[_0x6498('0x26')]=rrmemory;