78e9ba97cb9ab77368e55dcadd92e0c9ef042073
[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 _0x57e1=['notificationId','squeue','queue','realtime','bind','handleTimeout','drained','handleDrained','prototype','push','handleRun','isNil','Agents','length','agents','isAgentAvailable','writeLog','busy','name','saveWaitingNotification','showNotification','debug','[%s][QUEUE]\x20EMPTY','[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s','STOP','TIMEOUT','busyQueue','removeWaitingNotification','exports','uuid','./util','../../../../../config/logger','routing'];(function(_0x48ec2f,_0x38d621){var _0x54c899=function(_0x5a99ff){while(--_0x5a99ff){_0x48ec2f['push'](_0x48ec2f['shift']());}};_0x54c899(++_0x38d621);}(_0x57e1,0x167));var _0x157e=function(_0x3dc85,_0x4f2d39){_0x3dc85=_0x3dc85-0x0;var _0x3e938e=_0x57e1[_0x3dc85];return _0x3e938e;};'use strict';var _=require('lodash');var uuid=require(_0x157e('0x0'));var util=require(_0x157e('0x1'));var logger=require(_0x157e('0x2'))(_0x157e('0x3'));var Beepall=function(_0x5eef3a,_0x35fdff,_0x34c5d5,_0x3345ca){this[_0x157e('0x4')]=uuid['v4']();this[_0x157e('0x5')]=_0x5eef3a;this[_0x157e('0x6')]=_0x35fdff;this[_0x157e('0x7')]=_0x34c5d5;this[_0x157e('0x3')]=_0x3345ca;this[_0x157e('0x5')]['push'](this['handleRun'][_0x157e('0x8')](this),this[_0x157e('0x9')][_0x157e('0x8')](this));this[_0x157e('0x5')]['on']('timeout',this['handleTimeout'][_0x157e('0x8')](this));this[_0x157e('0x5')]['on'](_0x157e('0xa'),this[_0x157e('0xb')][_0x157e('0x8')](this));};Beepall[_0x157e('0xc')]['push']=function(){this[_0x157e('0x5')][_0x157e('0xd')](this[_0x157e('0xe')][_0x157e('0x8')](this),this[_0x157e('0x9')][_0x157e('0x8')](this));};Beepall[_0x157e('0xc')]['handleDrained']=function(){this['handleTimeout'](!![]);};Beepall['prototype'][_0x157e('0xe')]=function(){var _0xa34097=!![];if(!_[_0x157e('0xf')](this['queue'])&&!_[_0x157e('0xf')](this['queue']['Agents'])&&this[_0x157e('0x6')][_0x157e('0x10')]['length']>0x0){for(var _0x260ee3=0x0,_0x48ccc0;_0x260ee3<this['queue'][_0x157e('0x10')][_0x157e('0x11')];_0x260ee3+=0x1){_0x48ccc0=this[_0x157e('0x6')][_0x157e('0x10')][_0x260ee3]['id'];if(_['isNil'](this[_0x157e('0x7')][_0x157e('0x12')][_0x48ccc0])){logger['debug']('[%s][QUEUE]\x20agent\x20skipped,\x20unknown\x20id\x20%s',this[_0x157e('0x5')]['id'],_0x48ccc0);}else{if(util[_0x157e('0x13')](this[_0x157e('0x5')]['id'],this['realtime'][_0x157e('0x12')][_0x48ccc0],this[_0x157e('0x5')]['channel'],!![])){_0xa34097=![];util[_0x157e('0x14')](this[_0x157e('0x5')]['id'],this[_0x157e('0x7')][_0x157e('0x12')][_0x48ccc0],'RINGING');this[_0x157e('0x7')][_0x157e('0x12')][_0x48ccc0][_0x157e('0x15')]=!![];this[_0x157e('0x7')][_0x157e('0x12')][_0x48ccc0]['busyQueue']=this[_0x157e('0x6')][_0x157e('0x16')];util[_0x157e('0x17')](this['realtime'],this[_0x157e('0x3')],this[_0x157e('0x6')][_0x157e('0x10')][_0x260ee3],this[_0x157e('0x5')]['channel']);util[_0x157e('0x18')](this[_0x157e('0x4')],this[_0x157e('0x5')]['id'],this['realtime']['agents'][_0x48ccc0],this[_0x157e('0x6')],this[_0x157e('0x3')]);}}}if(_0xa34097){logger[_0x157e('0x19')]('[%s][QUEUE]\x20ALL\x20AGENTS\x20ARE\x20BUSY',this[_0x157e('0x5')]['id']);setTimeout(this[_0x157e('0xd')][_0x157e('0x8')](this),0x3e8);}}else{logger[_0x157e('0x19')](_0x157e('0x1a'),this['squeue']['id']);setTimeout(this[_0x157e('0xd')]['bind'](this),0x3e8);}};Beepall['prototype'][_0x157e('0x9')]=function(_0x388d6a){if(!_['isNil'](this[_0x157e('0x6')])&&!_[_0x157e('0xf')](this[_0x157e('0x6')][_0x157e('0x10')])){for(var _0x527fa8=0x0,_0x5844a2;_0x527fa8<this[_0x157e('0x6')][_0x157e('0x10')]['length'];_0x527fa8+=0x1){_0x5844a2=this['queue'][_0x157e('0x10')][_0x527fa8]['id'];if(_[_0x157e('0xf')](this[_0x157e('0x7')][_0x157e('0x12')][_0x5844a2])){logger[_0x157e('0x19')](_0x157e('0x1b'),this[_0x157e('0x5')]['id'],_0x5844a2);}else{util['hideNotification'](this[_0x157e('0x4')],this[_0x157e('0x5')]['id'],this['realtime'][_0x157e('0x12')][_0x5844a2],this[_0x157e('0x6')],this[_0x157e('0x3')]);util['writeLog'](this[_0x157e('0x5')]['id'],this[_0x157e('0x7')]['agents'][_0x5844a2],_0x388d6a?_0x157e('0x1c'):_0x157e('0x1d'));this['realtime'][_0x157e('0x12')][_0x5844a2][_0x157e('0x15')]=![];this[_0x157e('0x7')][_0x157e('0x12')][_0x5844a2][_0x157e('0x1e')]=undefined;util[_0x157e('0x1f')](this[_0x157e('0x7')],this['routing'],this['realtime']['agents'][_0x5844a2],this[_0x157e('0x5')]['channel']);}}}if(!_0x388d6a){setTimeout(this[_0x157e('0xd')][_0x157e('0x8')](this),0x3e8);}};function beepall(_0x47690d,_0x1d7851,_0x484531,_0x3f68e3){return new Beepall(_0x47690d,_0x1d7851,_0x484531,_0x3f68e3);}module[_0x157e('0x20')]=beepall;