77cac55ad888821625662a6c519b15582226fa91
[motion2.git] / server / services / routing / server / applications / strategy / beepall.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 _0xe135=['STOP','busyQueue','exports','uuid','./util','../../../../../config/logger','routing','notificationId','queue','handleRun','handleTimeout','bind','squeue','timeout','drained','prototype','push','handleDrained','isNil','Agents','length','agents','info','isAgentAvailable','realtime','channel','writeLog','busy','name','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','hideNotification'];(function(_0x283738,_0x44bed4){var _0x2407a4=function(_0x3950ad){while(--_0x3950ad){_0x283738['push'](_0x283738['shift']());}};_0x2407a4(++_0x44bed4);}(_0xe135,0xdc));var _0x5e13=function(_0x35a6f8,_0x2a19d0){_0x35a6f8=_0x35a6f8-0x0;var _0x11d2da=_0xe135[_0x35a6f8];return _0x11d2da;};'use strict';var _=require('lodash');var uuid=require(_0x5e13('0x0'));var util=require(_0x5e13('0x1'));var logger=require(_0x5e13('0x2'))(_0x5e13('0x3'));var Beepall=function(_0x1620df,_0x4248d9,_0x4c6a09,_0x3cbdec){this[_0x5e13('0x4')]=uuid['v4']();this['squeue']=_0x1620df;this[_0x5e13('0x5')]=_0x4248d9;this['realtime']=_0x4c6a09;this['routing']=_0x3cbdec;this['squeue']['push'](this[_0x5e13('0x6')]['bind'](this),this[_0x5e13('0x7')][_0x5e13('0x8')](this));this[_0x5e13('0x9')]['on'](_0x5e13('0xa'),this['handleTimeout'][_0x5e13('0x8')](this));this[_0x5e13('0x9')]['on'](_0x5e13('0xb'),this['handleDrained'][_0x5e13('0x8')](this));};Beepall[_0x5e13('0xc')][_0x5e13('0xd')]=function(){this['squeue']['push'](this[_0x5e13('0x6')]['bind'](this),this[_0x5e13('0x7')][_0x5e13('0x8')](this));};Beepall[_0x5e13('0xc')][_0x5e13('0xe')]=function(_0x2a6d26){this[_0x5e13('0x7')](!![]);};Beepall[_0x5e13('0xc')][_0x5e13('0x6')]=function(_0x5231d3){var _0x1fc4ff=!![];if(!_[_0x5e13('0xf')](this[_0x5e13('0x5')])&&!_[_0x5e13('0xf')](this[_0x5e13('0x5')][_0x5e13('0x10')])&&this['queue']['Agents'][_0x5e13('0x11')]>0x0){for(var _0x2a3f13=0x0,_0x34c5af;_0x2a3f13<this['queue'][_0x5e13('0x10')][_0x5e13('0x11')];_0x2a3f13+=0x1){_0x34c5af=this[_0x5e13('0x5')][_0x5e13('0x10')][_0x2a3f13]['id'];if(_['isNil'](this['realtime'][_0x5e13('0x12')][_0x34c5af])){logger[_0x5e13('0x13')]('[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this['squeue']['id'],_0x34c5af);}else{if(util[_0x5e13('0x14')](this['squeue']['id'],this[_0x5e13('0x15')][_0x5e13('0x12')][_0x34c5af],this[_0x5e13('0x9')][_0x5e13('0x16')],!![])){_0x1fc4ff=![];util[_0x5e13('0x17')](this[_0x5e13('0x9')]['id'],this['realtime'][_0x5e13('0x12')][_0x34c5af],'RINGING');this['realtime'][_0x5e13('0x12')][_0x34c5af][_0x5e13('0x18')]=!![];this[_0x5e13('0x15')]['agents'][_0x34c5af]['busyQueue']=this['queue'][_0x5e13('0x19')];util['showNotification'](this[_0x5e13('0x4')],this[_0x5e13('0x9')]['id'],this[_0x5e13('0x15')]['agents'][_0x34c5af],this['queue'],this['routing']);}}}if(_0x1fc4ff){logger[_0x5e13('0x13')]('[%s][QUEUE]\x20ALL\x20AGENTS\x20ARE\x20BUSY',this[_0x5e13('0x9')]['id']);setTimeout(this[_0x5e13('0xd')]['bind'](this),0x3e8);}}else{logger[_0x5e13('0x13')]('[%s][QUEUE]\x20EMPTY',this['squeue']['id']);setTimeout(this[_0x5e13('0xd')][_0x5e13('0x8')](this),0x3e8);}};Beepall[_0x5e13('0xc')][_0x5e13('0x7')]=function(_0x25561e){if(!_['isNil'](this[_0x5e13('0x5')])&&!_[_0x5e13('0xf')](this['queue'][_0x5e13('0x10')])){for(var _0x51b3b1=0x0,_0x4aebca;_0x51b3b1<this['queue'][_0x5e13('0x10')][_0x5e13('0x11')];_0x51b3b1+=0x1){_0x4aebca=this[_0x5e13('0x5')]['Agents'][_0x51b3b1]['id'];if(_[_0x5e13('0xf')](this[_0x5e13('0x15')][_0x5e13('0x12')][_0x4aebca])){logger[_0x5e13('0x13')](_0x5e13('0x1a'),this[_0x5e13('0x9')]['id'],_0x4aebca);}else{util[_0x5e13('0x1b')](this[_0x5e13('0x4')],this[_0x5e13('0x9')]['id'],this['realtime'][_0x5e13('0x12')][_0x4aebca],this['queue'],this[_0x5e13('0x3')]);util[_0x5e13('0x17')](this[_0x5e13('0x9')]['id'],this[_0x5e13('0x15')][_0x5e13('0x12')][_0x4aebca],_0x25561e?_0x5e13('0x1c'):'TIMEOUT');this['realtime'][_0x5e13('0x12')][_0x4aebca][_0x5e13('0x18')]=![];this[_0x5e13('0x15')][_0x5e13('0x12')][_0x4aebca][_0x5e13('0x1d')]=undefined;}}}if(!_0x25561e){setTimeout(this['push']['bind'](this),0x3e8);}};function beepall(_0x12f3eb,_0x28e8bf,_0x1dd356,_0x4e70c6){return new Beepall(_0x12f3eb,_0x28e8bf,_0x1dd356,_0x4e70c6);}module[_0x5e13('0x1e')]=beepall;