5b600841e3087d51b5f0bb598225e3493dd35c87
[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 _0x034e=['handleTimeout','drained','handleDrained','prototype','isNil','queue','Agents','length','debug','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','channel','writeLog','busy','busyQueue','name','saveWaitingNotification','showNotification','agents','[%s][QUEUE]\x20ALL\x20AGENTS\x20ARE\x20BUSY','hideNotification','TIMEOUT','removeWaitingNotification','exports','lodash','notificationId','squeue','realtime','routing','push','handleRun','bind'];(function(_0x35b18a,_0x6b2fbe){var _0x4db1bd=function(_0x389e62){while(--_0x389e62){_0x35b18a['push'](_0x35b18a['shift']());}};_0x4db1bd(++_0x6b2fbe);}(_0x034e,0x16c));var _0xe034=function(_0x1c712a,_0x2b1ad4){_0x1c712a=_0x1c712a-0x0;var _0x49d160=_0x034e[_0x1c712a];return _0x49d160;};'use strict';var _=require(_0xe034('0x0'));var uuid=require('uuid');var util=require('./util');var logger=require('../../../../../config/logger')('routing');var Beepall=function(_0x440444,_0x4bd0df,_0x426c6b,_0x38bd7b){this[_0xe034('0x1')]=uuid['v4']();this[_0xe034('0x2')]=_0x440444;this['queue']=_0x4bd0df;this[_0xe034('0x3')]=_0x426c6b;this[_0xe034('0x4')]=_0x38bd7b;this[_0xe034('0x2')][_0xe034('0x5')](this[_0xe034('0x6')][_0xe034('0x7')](this),this['handleTimeout'][_0xe034('0x7')](this));this[_0xe034('0x2')]['on']('timeout',this[_0xe034('0x8')][_0xe034('0x7')](this));this[_0xe034('0x2')]['on'](_0xe034('0x9'),this[_0xe034('0xa')][_0xe034('0x7')](this));};Beepall[_0xe034('0xb')]['push']=function(){this[_0xe034('0x2')][_0xe034('0x5')](this['handleRun'][_0xe034('0x7')](this),this[_0xe034('0x8')][_0xe034('0x7')](this));};Beepall[_0xe034('0xb')][_0xe034('0xa')]=function(){this[_0xe034('0x8')](!![]);};Beepall[_0xe034('0xb')][_0xe034('0x6')]=function(){var _0x5a60e=!![];if(!_[_0xe034('0xc')](this['queue'])&&!_[_0xe034('0xc')](this[_0xe034('0xd')][_0xe034('0xe')])&&this[_0xe034('0xd')]['Agents']['length']>0x0){for(var _0x1047db=0x0,_0x423d63;_0x1047db<this[_0xe034('0xd')][_0xe034('0xe')][_0xe034('0xf')];_0x1047db+=0x1){_0x423d63=this['queue'][_0xe034('0xe')][_0x1047db]['id'];if(_[_0xe034('0xc')](this[_0xe034('0x3')]['agents'][_0x423d63])){logger[_0xe034('0x10')](_0xe034('0x11'),this['squeue']['id'],_0x423d63);}else{if(util['isAgentAvailable'](this[_0xe034('0x2')]['id'],this[_0xe034('0x3')]['agents'][_0x423d63],this[_0xe034('0x2')][_0xe034('0x12')],!![])){_0x5a60e=![];util[_0xe034('0x13')](this['squeue']['id'],this[_0xe034('0x3')]['agents'][_0x423d63],'RINGING');this[_0xe034('0x3')]['agents'][_0x423d63][_0xe034('0x14')]=!![];this['realtime']['agents'][_0x423d63][_0xe034('0x15')]=this[_0xe034('0xd')][_0xe034('0x16')];util[_0xe034('0x17')](this['realtime'],this[_0xe034('0x4')],this[_0xe034('0xd')][_0xe034('0xe')][_0x1047db],this[_0xe034('0x2')][_0xe034('0x12')]);util[_0xe034('0x18')](this[_0xe034('0x1')],this[_0xe034('0x2')]['id'],this['realtime'][_0xe034('0x19')][_0x423d63],this[_0xe034('0xd')],this[_0xe034('0x4')]);}}}if(_0x5a60e){logger[_0xe034('0x10')](_0xe034('0x1a'),this[_0xe034('0x2')]['id']);setTimeout(this[_0xe034('0x5')][_0xe034('0x7')](this),0x3e8);}}else{logger[_0xe034('0x10')]('[%s][QUEUE]\x20EMPTY',this[_0xe034('0x2')]['id']);setTimeout(this[_0xe034('0x5')][_0xe034('0x7')](this),0x3e8);}};Beepall[_0xe034('0xb')]['handleTimeout']=function(_0x41c547){if(!_[_0xe034('0xc')](this[_0xe034('0xd')])&&!_[_0xe034('0xc')](this[_0xe034('0xd')][_0xe034('0xe')])){for(var _0x566094=0x0,_0x5a3105;_0x566094<this[_0xe034('0xd')]['Agents'][_0xe034('0xf')];_0x566094+=0x1){_0x5a3105=this[_0xe034('0xd')]['Agents'][_0x566094]['id'];if(_[_0xe034('0xc')](this[_0xe034('0x3')]['agents'][_0x5a3105])){logger[_0xe034('0x10')]('[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0xe034('0x2')]['id'],_0x5a3105);}else{util[_0xe034('0x1b')](this['notificationId'],this[_0xe034('0x2')]['id'],this[_0xe034('0x3')][_0xe034('0x19')][_0x5a3105],this[_0xe034('0xd')],this['routing']);util['writeLog'](this[_0xe034('0x2')]['id'],this[_0xe034('0x3')][_0xe034('0x19')][_0x5a3105],_0x41c547?'STOP':_0xe034('0x1c'));this[_0xe034('0x3')][_0xe034('0x19')][_0x5a3105][_0xe034('0x14')]=![];this['realtime'][_0xe034('0x19')][_0x5a3105][_0xe034('0x15')]=undefined;util[_0xe034('0x1d')](this['realtime'],this[_0xe034('0x4')],this[_0xe034('0x3')][_0xe034('0x19')][_0x5a3105],this[_0xe034('0x2')]['channel']);}}}if(!_0x41c547){setTimeout(this[_0xe034('0x5')][_0xe034('0x7')](this),0x3e8);}};function beepall(_0x1f1227,_0x1a533e,_0x455fed,_0x7abefb){return new Beepall(_0x1f1227,_0x1a533e,_0x455fed,_0x7abefb);}module[_0xe034('0x1e')]=beepall;