ff7bedf137b9a26b16f3f710a09c38f1b6be8701
[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 _0x97a2=['./util','../../../../../config/logger','routing','notificationId','queue','realtime','squeue','push','handleRun','handleTimeout','bind','timeout','prototype','handleDrained','isNil','Agents','length','debug','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','isAgentAvailable','agents','channel','writeLog','busy','busyQueue','name','[%s][QUEUE]\x20ALL\x20AGENTS\x20ARE\x20BUSY','[%s][QUEUE]\x20EMPTY','hideNotification','TIMEOUT','lodash'];(function(_0x3c9cad,_0x4ad2e2){var _0x5da543=function(_0x3d4580){while(--_0x3d4580){_0x3c9cad['push'](_0x3c9cad['shift']());}};_0x5da543(++_0x4ad2e2);}(_0x97a2,0x1b1));var _0x297a=function(_0x2544cf,_0x15858c){_0x2544cf=_0x2544cf-0x0;var _0x241d1a=_0x97a2[_0x2544cf];return _0x241d1a;};'use strict';var _=require(_0x297a('0x0'));var uuid=require('uuid');var util=require(_0x297a('0x1'));var logger=require(_0x297a('0x2'))(_0x297a('0x3'));var Beepall=function(_0xfb9aa2,_0x14d6d3,_0x158737,_0x2cf730){this[_0x297a('0x4')]=uuid['v4']();this['squeue']=_0xfb9aa2;this[_0x297a('0x5')]=_0x14d6d3;this[_0x297a('0x6')]=_0x158737;this[_0x297a('0x3')]=_0x2cf730;this[_0x297a('0x7')][_0x297a('0x8')](this[_0x297a('0x9')]['bind'](this),this[_0x297a('0xa')][_0x297a('0xb')](this));this[_0x297a('0x7')]['on'](_0x297a('0xc'),this[_0x297a('0xa')][_0x297a('0xb')](this));this['squeue']['on']('drained',this['handleDrained'][_0x297a('0xb')](this));};Beepall[_0x297a('0xd')][_0x297a('0x8')]=function(){this[_0x297a('0x7')]['push'](this[_0x297a('0x9')][_0x297a('0xb')](this),this[_0x297a('0xa')][_0x297a('0xb')](this));};Beepall[_0x297a('0xd')][_0x297a('0xe')]=function(){this[_0x297a('0xa')](!![]);};Beepall['prototype']['handleRun']=function(){var _0x417def=!![];if(!_['isNil'](this[_0x297a('0x5')])&&!_[_0x297a('0xf')](this['queue'][_0x297a('0x10')])&&this[_0x297a('0x5')]['Agents'][_0x297a('0x11')]>0x0){for(var _0x333868=0x0,_0x2365ea;_0x333868<this['queue'][_0x297a('0x10')][_0x297a('0x11')];_0x333868+=0x1){_0x2365ea=this[_0x297a('0x5')]['Agents'][_0x333868]['id'];if(_[_0x297a('0xf')](this[_0x297a('0x6')]['agents'][_0x2365ea])){logger[_0x297a('0x12')](_0x297a('0x13'),this[_0x297a('0x7')]['id'],_0x2365ea);}else{if(util[_0x297a('0x14')](this[_0x297a('0x7')]['id'],this[_0x297a('0x6')][_0x297a('0x15')][_0x2365ea],this[_0x297a('0x7')][_0x297a('0x16')],!![])){_0x417def=![];util[_0x297a('0x17')](this[_0x297a('0x7')]['id'],this[_0x297a('0x6')]['agents'][_0x2365ea],'RINGING');this['realtime'][_0x297a('0x15')][_0x2365ea][_0x297a('0x18')]=!![];this['realtime'][_0x297a('0x15')][_0x2365ea][_0x297a('0x19')]=this[_0x297a('0x5')][_0x297a('0x1a')];util['showNotification'](this[_0x297a('0x4')],this[_0x297a('0x7')]['id'],this[_0x297a('0x6')]['agents'][_0x2365ea],this[_0x297a('0x5')],this[_0x297a('0x3')]);}}}if(_0x417def){logger[_0x297a('0x12')](_0x297a('0x1b'),this[_0x297a('0x7')]['id']);setTimeout(this[_0x297a('0x8')][_0x297a('0xb')](this),0x3e8);}}else{logger[_0x297a('0x12')](_0x297a('0x1c'),this[_0x297a('0x7')]['id']);setTimeout(this[_0x297a('0x8')]['bind'](this),0x3e8);}};Beepall[_0x297a('0xd')][_0x297a('0xa')]=function(_0xc30c85){if(!_['isNil'](this['queue'])&&!_[_0x297a('0xf')](this[_0x297a('0x5')][_0x297a('0x10')])){for(var _0xd9c747=0x0,_0x3eddd8;_0xd9c747<this[_0x297a('0x5')]['Agents']['length'];_0xd9c747+=0x1){_0x3eddd8=this[_0x297a('0x5')]['Agents'][_0xd9c747]['id'];if(_[_0x297a('0xf')](this[_0x297a('0x6')][_0x297a('0x15')][_0x3eddd8])){logger[_0x297a('0x12')](_0x297a('0x13'),this['squeue']['id'],_0x3eddd8);}else{util[_0x297a('0x1d')](this[_0x297a('0x4')],this[_0x297a('0x7')]['id'],this[_0x297a('0x6')][_0x297a('0x15')][_0x3eddd8],this[_0x297a('0x5')],this[_0x297a('0x3')]);util[_0x297a('0x17')](this[_0x297a('0x7')]['id'],this['realtime'][_0x297a('0x15')][_0x3eddd8],_0xc30c85?'STOP':_0x297a('0x1e'));this[_0x297a('0x6')][_0x297a('0x15')][_0x3eddd8][_0x297a('0x18')]=![];this['realtime'][_0x297a('0x15')][_0x3eddd8]['busyQueue']=undefined;}}}if(!_0xc30c85){setTimeout(this[_0x297a('0x8')][_0x297a('0xb')](this),0x3e8);}};function beepall(_0x5c9d41,_0x3e4dfb,_0x2a0df6,_0xd64cd9){return new Beepall(_0x5c9d41,_0x3e4dfb,_0x2a0df6,_0xd64cd9);}module['exports']=beepall;