c2b2fc979279044a974ac2bcb232e0c16212aea2
[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 _0x14d8=['../../../../../config/logger','routing','notificationId','squeue','realtime','push','handleRun','bind','timeout','handleTimeout','drained','handleDrained','prototype','handleCheckReject','isAgentAvailable','agents','agentId','channel','debug','intervals','queue','mapAgentsId','done','busy','busyQueue','name','saveWaitingNotification','showNotification','RINGING','[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s','[%s][QUEUE]\x20timeout\x20with\x20%s','isNil','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','TIMEOUT','lodash'];(function(_0x3d44b0,_0x130dea){var _0x171346=function(_0xec00e){while(--_0xec00e){_0x3d44b0['push'](_0x3d44b0['shift']());}};_0x171346(++_0x130dea);}(_0x14d8,0x68));var _0x814d=function(_0x126558,_0x143c9a){_0x126558=_0x126558-0x0;var _0x1f6d14=_0x14d8[_0x126558];return _0x1f6d14;};'use strict';var rr=require('rr');var _=require(_0x814d('0x0'));var uuid=require('uuid');var util=require('./util');var logger=require(_0x814d('0x1'))(_0x814d('0x2'));var RRMemory=function(_0x58609f,_0x163348,_0x4ef1c5,_0xb65196){this[_0x814d('0x3')]=uuid['v4']();this[_0x814d('0x4')]=_0x58609f;this['queue']=_0x163348;this[_0x814d('0x5')]=_0x4ef1c5;this[_0x814d('0x2')]=_0xb65196;this['intervals']={};this[_0x814d('0x4')][_0x814d('0x6')](this[_0x814d('0x7')][_0x814d('0x8')](this),this['handleTimeout']['bind'](this),this['module']);this[_0x814d('0x4')]['on'](_0x814d('0x9'),this[_0x814d('0xa')][_0x814d('0x8')](this));this[_0x814d('0x4')]['on'](_0x814d('0xb'),this[_0x814d('0xc')][_0x814d('0x8')](this));};RRMemory[_0x814d('0xd')][_0x814d('0x6')]=function(){this[_0x814d('0x4')][_0x814d('0x6')](this['handleRun'][_0x814d('0x8')](this),this[_0x814d('0xa')][_0x814d('0x8')](this));};RRMemory[_0x814d('0xd')][_0x814d('0xc')]=function(){this[_0x814d('0xa')](!![]);};RRMemory[_0x814d('0xd')][_0x814d('0xe')]=function(_0x30c3b2){if(util[_0x814d('0xf')](this[_0x814d('0x4')]['id'],this[_0x814d('0x5')][_0x814d('0x10')][this[_0x814d('0x11')]],this[_0x814d('0x4')][_0x814d('0x12')],!![])){logger[_0x814d('0x13')]('[%s][QUEUE]\x20available\x20again\x20%s',this[_0x814d('0x4')]['id'],this[_0x814d('0x11')]);clearInterval(this[_0x814d('0x14')][this[_0x814d('0x11')]]);_0x30c3b2['done']();setTimeout(this['push'][_0x814d('0x8')](this),0x3e8);}};RRMemory[_0x814d('0xd')]['handleRun']=function(_0x10705b){this[_0x814d('0x11')]=rr(this[_0x814d('0x15')][_0x814d('0x16')]);logger[_0x814d('0x13')]('[%s][QUEUE]\x20try\x20with\x20%s',this['squeue']['id'],this[_0x814d('0x11')]);if(_['isNil'](this[_0x814d('0x5')][_0x814d('0x10')][this[_0x814d('0x11')]])){logger[_0x814d('0x13')]('[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0x814d('0x4')]['id'],this[_0x814d('0x11')]);_0x10705b[_0x814d('0x17')]();setTimeout(this[_0x814d('0x6')][_0x814d('0x8')](this),0x3e8);}else{if(util['isAgentAvailable'](this['squeue']['id'],this[_0x814d('0x5')][_0x814d('0x10')][this['agentId']],this[_0x814d('0x4')][_0x814d('0x12')],!![])){this[_0x814d('0x5')][_0x814d('0x10')][this[_0x814d('0x11')]][_0x814d('0x18')]=!![];this[_0x814d('0x5')][_0x814d('0x10')][this['agentId']][_0x814d('0x19')]=this['queue'][_0x814d('0x1a')];util[_0x814d('0x1b')](this[_0x814d('0x5')],this[_0x814d('0x2')],this['realtime'][_0x814d('0x10')][this[_0x814d('0x11')]],this[_0x814d('0x4')]['channel']);util[_0x814d('0x1c')](this[_0x814d('0x3')],this[_0x814d('0x4')]['id'],this['realtime'][_0x814d('0x10')][this[_0x814d('0x11')]],this[_0x814d('0x15')],this['routing']);util['writeLog'](this['squeue']['id'],this['realtime'][_0x814d('0x10')][this[_0x814d('0x11')]],_0x814d('0x1d'));this[_0x814d('0x14')][this[_0x814d('0x11')]]=setInterval(this[_0x814d('0xe')][_0x814d('0x8')](this,_0x10705b),0x3e8);}else{logger[_0x814d('0x13')](_0x814d('0x1e'),this[_0x814d('0x4')]['id'],this[_0x814d('0x11')]);_0x10705b['done']();setTimeout(this['push'][_0x814d('0x8')](this),0x3e8);}}};RRMemory[_0x814d('0xd')]['handleTimeout']=function(_0x1db4a6){logger['debug'](_0x814d('0x1f'),this[_0x814d('0x4')]['id'],this[_0x814d('0x11')]);if(_[_0x814d('0x20')](this[_0x814d('0x5')]['agents'][this[_0x814d('0x11')]])){logger[_0x814d('0x13')](_0x814d('0x21'),this['squeue']['id'],this[_0x814d('0x11')]);}else{clearInterval(this['intervals'][this[_0x814d('0x11')]]);util['hideNotification'](this[_0x814d('0x3')],this[_0x814d('0x4')]['id'],this['realtime'][_0x814d('0x10')][this[_0x814d('0x11')]],this[_0x814d('0x15')],this[_0x814d('0x2')]);util['writeLog'](this['squeue']['id'],this[_0x814d('0x5')][_0x814d('0x10')][this[_0x814d('0x11')]],_0x814d('0x22'));this[_0x814d('0x5')][_0x814d('0x10')][this[_0x814d('0x11')]]['busy']=![];this['realtime']['agents'][this[_0x814d('0x11')]]['busyQueue']=undefined;util['removeWaitingNotification'](this['realtime'],this[_0x814d('0x2')],this[_0x814d('0x5')][_0x814d('0x10')][this[_0x814d('0x11')]],this['squeue'][_0x814d('0x12')]);}if(!_0x1db4a6){setTimeout(this[_0x814d('0x6')][_0x814d('0x8')](this),0x3e8);}};function rrmemory(_0x20f4a6,_0xf98d76,_0x1c2e6f,_0x38859e){return new RRMemory(_0x20f4a6,_0xf98d76,_0x1c2e6f,_0x38859e);}module['exports']=rrmemory;