2fb90c2b85013bf0f2f73c5193b8e27faaa288ce
[motion2.git] / server / services / routing / model / chatQueue.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 _0x5e95=['socket.io-emitter','name','timeout','strategy','Agents','mapAgentsId','waiting','md5','updateRealtime','prototype','_rr','loggedIn','paused','length','chatPause','available','stringify','chat:queue:%s','emit','exports','lodash','util','../../../config/environment','redis','defaults','localhost'];(function(_0x22339d,_0x1a2192){var _0x4d60b9=function(_0xd9d961){while(--_0xd9d961){_0x22339d['push'](_0x22339d['shift']());}};_0x4d60b9(++_0x1a2192);}(_0x5e95,0x7c));var _0x55e9=function(_0x14ae74,_0x4bdee5){_0x14ae74=_0x14ae74-0x0;var _0x1116f3=_0x5e95[_0x14ae74];return _0x1116f3;};'use strict';var _=require(_0x55e9('0x0'));var md5=require('md5');var util=require(_0x55e9('0x1'));var Redis=require('ioredis');var config=require(_0x55e9('0x2'));config[_0x55e9('0x3')]=_[_0x55e9('0x4')](config[_0x55e9('0x3')],{'host':_0x55e9('0x5'),'port':0x18eb});var io=require(_0x55e9('0x6'))(new Redis(config[_0x55e9('0x3')]));function ChatQueue(_0x5f37cf){this['id']=_0x5f37cf['id']||0x0;this['name']=_0x5f37cf[_0x55e9('0x7')]||'';this['timeout']=_0x5f37cf[_0x55e9('0x8')]||0xa;this['strategy']=_0x5f37cf[_0x55e9('0x9')]||'beepall';this['Agents']=_0x5f37cf[_0x55e9('0xa')];this[_0x55e9('0xb')]={};this[_0x55e9('0xc')]=0x0;this[_0x55e9('0xd')]='';this['updateRouting']();this[_0x55e9('0xe')]();}ChatQueue[_0x55e9('0xf')]['updateRouting']=function(){var _0x53908c=this[_0x55e9('0xb')][_0x55e9('0x10')];this[_0x55e9('0xb')]=_['map'](this[_0x55e9('0xa')],'id');this[_0x55e9('0xb')][_0x55e9('0x10')]=_0x53908c;};ChatQueue[_0x55e9('0xf')][_0x55e9('0xe')]=function(){this[_0x55e9('0x11')]=0x0;this[_0x55e9('0x12')]=0x0;for(var _0xf43c6b=0x0;_0xf43c6b<this[_0x55e9('0xa')][_0x55e9('0x13')];_0xf43c6b+=0x1){if(this[_0x55e9('0xa')][_0xf43c6b]['online']){this[_0x55e9('0x11')]+=0x1;}if(this[_0x55e9('0xa')][_0xf43c6b][_0x55e9('0x14')]){this['paused']+=0x1;}}this[_0x55e9('0x15')]=this[_0x55e9('0x11')]-this[_0x55e9('0x12')];this[_0x55e9('0x15')]=this[_0x55e9('0x15')]>=0x0?this[_0x55e9('0x15')]:0x0;var _0x560510={'id':this['id'],'available':this[_0x55e9('0x15')],'loggedIn':this['loggedIn'],'name':this['name'],'paused':this[_0x55e9('0x12')],'waiting':this[_0x55e9('0xc')]};var _0x1925fb=md5(JSON[_0x55e9('0x16')](_0x560510));if(this[_0x55e9('0xd')]!==_0x1925fb){this['md5']=_0x1925fb;io['to'](util['format'](_0x55e9('0x17'),_0x560510[_0x55e9('0x7')]))[_0x55e9('0x18')]('chat_queue:save',_0x560510);}};module[_0x55e9('0x19')]=ChatQueue;