Built motion from commit b0a9a629.|2.6.33
[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 _0x1aa6=['uuid','../../../../../config/logger','routing','squeue','realtime','handleRun','bind','handleTimeout','drained','handleDrained','prototype','push','handleCheckReject','agents','agentId','channel','debug','[%s][QUEUE]\x20available\x20again\x20%s','intervals','done','queue','[%s][QUEUE]\x20try\x20with\x20%s','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','isAgentAvailable','busy','name','saveWaitingNotification','showNotification','notificationId','writeLog','RINGING','[%s][QUEUE]\x20agent\x20skipped,\x20not\x20available\x20id\x20%s','[%s][QUEUE]\x20timeout\x20with\x20%s','hideNotification','TIMEOUT','busyQueue','exports','lodash'];(function(_0xccf869,_0x2556a5){var _0x21a9db=function(_0xcc4835){while(--_0xcc4835){_0xccf869['push'](_0xccf869['shift']());}};_0x21a9db(++_0x2556a5);}(_0x1aa6,0xe3));var _0x61aa=function(_0x152fe3,_0x12b0c8){_0x152fe3=_0x152fe3-0x0;var _0xc5bb39=_0x1aa6[_0x152fe3];return _0xc5bb39;};'use strict';var rr=require('rr');var _=require(_0x61aa('0x0'));var uuid=require(_0x61aa('0x1'));var util=require('./util');var logger=require(_0x61aa('0x2'))(_0x61aa('0x3'));var RRMemory=function(_0x3bdb54,_0x1c65ef,_0x4090a7,_0x451596){this['notificationId']=uuid['v4']();this[_0x61aa('0x4')]=_0x3bdb54;this['queue']=_0x1c65ef;this[_0x61aa('0x5')]=_0x4090a7;this[_0x61aa('0x3')]=_0x451596;this['intervals']={};this['squeue']['push'](this[_0x61aa('0x6')][_0x61aa('0x7')](this),this['handleTimeout']['bind'](this),this['module']);this['squeue']['on']('timeout',this[_0x61aa('0x8')][_0x61aa('0x7')](this));this['squeue']['on'](_0x61aa('0x9'),this[_0x61aa('0xa')][_0x61aa('0x7')](this));};RRMemory[_0x61aa('0xb')][_0x61aa('0xc')]=function(){this[_0x61aa('0x4')][_0x61aa('0xc')](this[_0x61aa('0x6')][_0x61aa('0x7')](this),this['handleTimeout'][_0x61aa('0x7')](this));};RRMemory[_0x61aa('0xb')]['handleDrained']=function(){this[_0x61aa('0x8')](!![]);};RRMemory[_0x61aa('0xb')][_0x61aa('0xd')]=function(_0x5a759c){if(util['isAgentAvailable'](this[_0x61aa('0x4')]['id'],this[_0x61aa('0x5')][_0x61aa('0xe')][this[_0x61aa('0xf')]],this[_0x61aa('0x4')][_0x61aa('0x10')],!![])){logger[_0x61aa('0x11')](_0x61aa('0x12'),this[_0x61aa('0x4')]['id'],this[_0x61aa('0xf')]);clearInterval(this[_0x61aa('0x13')][this[_0x61aa('0xf')]]);_0x5a759c[_0x61aa('0x14')]();setTimeout(this['push']['bind'](this),0x3e8);}};RRMemory['prototype'][_0x61aa('0x6')]=function(_0x50dff7){this['agentId']=rr(this[_0x61aa('0x15')]['mapAgentsId']);logger['debug'](_0x61aa('0x16'),this['squeue']['id'],this['agentId']);if(_['isNil'](this['realtime'][_0x61aa('0xe')][this[_0x61aa('0xf')]])){logger[_0x61aa('0x11')](_0x61aa('0x17'),this[_0x61aa('0x4')]['id'],this[_0x61aa('0xf')]);_0x50dff7[_0x61aa('0x14')]();setTimeout(this[_0x61aa('0xc')][_0x61aa('0x7')](this),0x3e8);}else{if(util[_0x61aa('0x18')](this[_0x61aa('0x4')]['id'],this[_0x61aa('0x5')][_0x61aa('0xe')][this[_0x61aa('0xf')]],this['squeue'][_0x61aa('0x10')],!![])){this[_0x61aa('0x5')]['agents'][this['agentId']][_0x61aa('0x19')]=!![];this[_0x61aa('0x5')][_0x61aa('0xe')][this[_0x61aa('0xf')]]['busyQueue']=this[_0x61aa('0x15')][_0x61aa('0x1a')];util[_0x61aa('0x1b')](this[_0x61aa('0x5')],this[_0x61aa('0x3')],this[_0x61aa('0x5')][_0x61aa('0xe')][this[_0x61aa('0xf')]],this['squeue']['channel']);util[_0x61aa('0x1c')](this[_0x61aa('0x1d')],this[_0x61aa('0x4')]['id'],this[_0x61aa('0x5')][_0x61aa('0xe')][this['agentId']],this[_0x61aa('0x15')],this[_0x61aa('0x3')]);util[_0x61aa('0x1e')](this[_0x61aa('0x4')]['id'],this[_0x61aa('0x5')][_0x61aa('0xe')][this['agentId']],_0x61aa('0x1f'));this[_0x61aa('0x13')][this[_0x61aa('0xf')]]=setInterval(this['handleCheckReject'][_0x61aa('0x7')](this,_0x50dff7),0x3e8);}else{logger['debug'](_0x61aa('0x20'),this['squeue']['id'],this['agentId']);_0x50dff7[_0x61aa('0x14')]();setTimeout(this[_0x61aa('0xc')][_0x61aa('0x7')](this),0x3e8);}}};RRMemory['prototype']['handleTimeout']=function(_0x443bb0){logger['debug'](_0x61aa('0x21'),this[_0x61aa('0x4')]['id'],this[_0x61aa('0xf')]);if(_['isNil'](this[_0x61aa('0x5')][_0x61aa('0xe')][this['agentId']])){logger[_0x61aa('0x11')](_0x61aa('0x17'),this[_0x61aa('0x4')]['id'],this[_0x61aa('0xf')]);}else{clearInterval(this['intervals'][this['agentId']]);util[_0x61aa('0x22')](this[_0x61aa('0x1d')],this[_0x61aa('0x4')]['id'],this[_0x61aa('0x5')][_0x61aa('0xe')][this[_0x61aa('0xf')]],this[_0x61aa('0x15')],this['routing']);util['writeLog'](this['squeue']['id'],this['realtime'][_0x61aa('0xe')][this[_0x61aa('0xf')]],_0x61aa('0x23'));this['realtime'][_0x61aa('0xe')][this[_0x61aa('0xf')]]['busy']=![];this[_0x61aa('0x5')]['agents'][this[_0x61aa('0xf')]][_0x61aa('0x24')]=undefined;util['removeWaitingNotification'](this['realtime'],this[_0x61aa('0x3')],this[_0x61aa('0x5')][_0x61aa('0xe')][this[_0x61aa('0xf')]],this[_0x61aa('0x4')][_0x61aa('0x10')]);}if(!_0x443bb0){setTimeout(this['push'][_0x61aa('0x7')](this),0x3e8);}};function rrmemory(_0x5d73e5,_0x56b9d3,_0x38fba7,_0x23f8f3){return new RRMemory(_0x5d73e5,_0x56b9d3,_0x38fba7,_0x23f8f3);}module[_0x61aa('0x25')]=rrmemory;