Built motion from commit (unavailable).|2.5.21
[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 _0x0e6c=['length','agents','info','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','writeLog','busy','busyQueue','showNotification','[%s][QUEUE]\x20EMPTY','hideNotification','STOP','TIMEOUT','exports','./util','../../../../../config/logger','routing','notificationId','queue','realtime','squeue','push','bind','timeout','handleTimeout','prototype','handleRun','handleDrained','isNil','Agents'];(function(_0x3b477a,_0x1e22ed){var _0x338aba=function(_0x1a2e74){while(--_0x1a2e74){_0x3b477a['push'](_0x3b477a['shift']());}};_0x338aba(++_0x1e22ed);}(_0x0e6c,0x64));var _0xc0e6=function(_0x5950a1,_0x56a4fb){_0x5950a1=_0x5950a1-0x0;var _0x49d2fb=_0x0e6c[_0x5950a1];return _0x49d2fb;};'use strict';var _=require('lodash');var uuid=require('uuid');var util=require(_0xc0e6('0x0'));var logger=require(_0xc0e6('0x1'))(_0xc0e6('0x2'));var Beepall=function(_0x5f24d8,_0x4237a3,_0x41c97c,_0xcc5037){this[_0xc0e6('0x3')]=uuid['v4']();this['squeue']=_0x5f24d8;this[_0xc0e6('0x4')]=_0x4237a3;this[_0xc0e6('0x5')]=_0x41c97c;this[_0xc0e6('0x2')]=_0xcc5037;this[_0xc0e6('0x6')][_0xc0e6('0x7')](this['handleRun']['bind'](this),this['handleTimeout'][_0xc0e6('0x8')](this));this[_0xc0e6('0x6')]['on'](_0xc0e6('0x9'),this[_0xc0e6('0xa')]['bind'](this));this[_0xc0e6('0x6')]['on']('drained',this['handleDrained'][_0xc0e6('0x8')](this));};Beepall[_0xc0e6('0xb')][_0xc0e6('0x7')]=function(){this[_0xc0e6('0x6')]['push'](this[_0xc0e6('0xc')][_0xc0e6('0x8')](this),this[_0xc0e6('0xa')][_0xc0e6('0x8')](this));};Beepall[_0xc0e6('0xb')][_0xc0e6('0xd')]=function(_0x4ac859){this['handleTimeout'](!![]);};Beepall[_0xc0e6('0xb')][_0xc0e6('0xc')]=function(_0x3984c8){var _0x229330=!![];if(!_['isNil'](this[_0xc0e6('0x4')])&&!_[_0xc0e6('0xe')](this[_0xc0e6('0x4')][_0xc0e6('0xf')])&&this[_0xc0e6('0x4')][_0xc0e6('0xf')]['length']>0x0){for(var _0x57f846=0x0,_0x386e20;_0x57f846<this[_0xc0e6('0x4')][_0xc0e6('0xf')][_0xc0e6('0x10')];_0x57f846+=0x1){_0x386e20=this['queue'][_0xc0e6('0xf')][_0x57f846]['id'];if(_[_0xc0e6('0xe')](this[_0xc0e6('0x5')][_0xc0e6('0x11')][_0x386e20])){logger[_0xc0e6('0x12')](_0xc0e6('0x13'),this[_0xc0e6('0x6')]['id'],_0x386e20);}else{if(util['isAgentAvailable'](this[_0xc0e6('0x6')]['id'],this['realtime'][_0xc0e6('0x11')][_0x386e20],this[_0xc0e6('0x6')]['channel'],!![])){_0x229330=![];util[_0xc0e6('0x14')](this[_0xc0e6('0x6')]['id'],this['realtime'][_0xc0e6('0x11')][_0x386e20],'RINGING');this[_0xc0e6('0x5')]['agents'][_0x386e20][_0xc0e6('0x15')]=!![];this[_0xc0e6('0x5')]['agents'][_0x386e20][_0xc0e6('0x16')]=this[_0xc0e6('0x4')]['name'];util[_0xc0e6('0x17')](this[_0xc0e6('0x3')],this[_0xc0e6('0x6')]['id'],this[_0xc0e6('0x5')][_0xc0e6('0x11')][_0x386e20],this['queue'],this[_0xc0e6('0x2')]);}}}if(_0x229330){logger[_0xc0e6('0x12')]('[%s][QUEUE]\x20ALL\x20AGENTS\x20ARE\x20BUSY',this['squeue']['id']);setTimeout(this[_0xc0e6('0x7')][_0xc0e6('0x8')](this),0x3e8);}}else{logger[_0xc0e6('0x12')](_0xc0e6('0x18'),this[_0xc0e6('0x6')]['id']);setTimeout(this['push'][_0xc0e6('0x8')](this),0x3e8);}};Beepall[_0xc0e6('0xb')]['handleTimeout']=function(_0x465d95){if(!_[_0xc0e6('0xe')](this[_0xc0e6('0x4')])&&!_[_0xc0e6('0xe')](this[_0xc0e6('0x4')]['Agents'])){for(var _0x5b42a5=0x0,_0x51e544;_0x5b42a5<this[_0xc0e6('0x4')]['Agents'][_0xc0e6('0x10')];_0x5b42a5+=0x1){_0x51e544=this['queue'][_0xc0e6('0xf')][_0x5b42a5]['id'];if(_[_0xc0e6('0xe')](this[_0xc0e6('0x5')]['agents'][_0x51e544])){logger[_0xc0e6('0x12')]('[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0xc0e6('0x6')]['id'],_0x51e544);}else{util[_0xc0e6('0x19')](this[_0xc0e6('0x3')],this[_0xc0e6('0x6')]['id'],this[_0xc0e6('0x5')]['agents'][_0x51e544],this['queue'],this[_0xc0e6('0x2')]);util[_0xc0e6('0x14')](this[_0xc0e6('0x6')]['id'],this['realtime'][_0xc0e6('0x11')][_0x51e544],_0x465d95?_0xc0e6('0x1a'):_0xc0e6('0x1b'));this['realtime'][_0xc0e6('0x11')][_0x51e544]['busy']=![];this[_0xc0e6('0x5')][_0xc0e6('0x11')][_0x51e544][_0xc0e6('0x16')]=undefined;}}}if(!_0x465d95){setTimeout(this[_0xc0e6('0x7')][_0xc0e6('0x8')](this),0x3e8);}};function beepall(_0x377ff7,_0x4b637e,_0x46c594,_0x51d0c0){return new Beepall(_0x377ff7,_0x4b637e,_0x46c594,_0x51d0c0);}module[_0xc0e6('0x1c')]=beepall;