8d726448ce27a8b0d9c7e2c39cdc216226f9e8ca
[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 _0x6575=['map','loggedIn','online','chatPause','paused','available','stringify','format','chat:queue:%s','chat_queue:save','exports','md5','util','../../../config/environment','redis','defaults','localhost','socket.io-emitter','name','timeout','strategy','beepall','Agents','mapAgentsId','waiting','updateRouting','updateRealtime','prototype','_rr'];(function(_0xc3e74b,_0x1c3983){var _0x5e1745=function(_0x1b043e){while(--_0x1b043e){_0xc3e74b['push'](_0xc3e74b['shift']());}};_0x5e1745(++_0x1c3983);}(_0x6575,0x184));var _0x5657=function(_0xa148b7,_0x2f3eb2){_0xa148b7=_0xa148b7-0x0;var _0x51efd3=_0x6575[_0xa148b7];return _0x51efd3;};'use strict';var _=require('lodash');var md5=require(_0x5657('0x0'));var util=require(_0x5657('0x1'));var Redis=require('ioredis');var config=require(_0x5657('0x2'));config[_0x5657('0x3')]=_[_0x5657('0x4')](config[_0x5657('0x3')],{'host':_0x5657('0x5'),'port':0x18eb});var io=require(_0x5657('0x6'))(new Redis(config[_0x5657('0x3')]));function ChatQueue(_0x30f4f9){this['id']=_0x30f4f9['id']||0x0;this[_0x5657('0x7')]=_0x30f4f9[_0x5657('0x7')]||'';this[_0x5657('0x8')]=_0x30f4f9[_0x5657('0x8')]||0xa;this[_0x5657('0x9')]=_0x30f4f9[_0x5657('0x9')]||_0x5657('0xa');this[_0x5657('0xb')]=_0x30f4f9[_0x5657('0xb')];this[_0x5657('0xc')]={};this[_0x5657('0xd')]=0x0;this[_0x5657('0x0')]='';this[_0x5657('0xe')]();this[_0x5657('0xf')]();}ChatQueue[_0x5657('0x10')][_0x5657('0xe')]=function(){var _0x1d6f14=this[_0x5657('0xc')][_0x5657('0x11')];this['mapAgentsId']=_[_0x5657('0x12')](this[_0x5657('0xb')],'id');this['mapAgentsId'][_0x5657('0x11')]=_0x1d6f14;};ChatQueue[_0x5657('0x10')][_0x5657('0xf')]=function(){this[_0x5657('0x13')]=0x0;this['paused']=0x0;for(var _0x2f206e=0x0;_0x2f206e<this[_0x5657('0xb')]['length'];_0x2f206e+=0x1){if(this['Agents'][_0x2f206e][_0x5657('0x14')]){this[_0x5657('0x13')]+=0x1;}if(this['Agents'][_0x2f206e][_0x5657('0x15')]){this[_0x5657('0x16')]+=0x1;}}this[_0x5657('0x17')]=this[_0x5657('0x13')]-this[_0x5657('0x16')];this[_0x5657('0x17')]=this[_0x5657('0x17')]>=0x0?this[_0x5657('0x17')]:0x0;var _0x504afc={'id':this['id'],'available':this[_0x5657('0x17')],'loggedIn':this[_0x5657('0x13')],'name':this[_0x5657('0x7')],'paused':this['paused'],'waiting':this[_0x5657('0xd')]};var _0x573ccb=md5(JSON[_0x5657('0x18')](_0x504afc));if(this[_0x5657('0x0')]!==_0x573ccb){this[_0x5657('0x0')]=_0x573ccb;io['to'](util[_0x5657('0x19')](_0x5657('0x1a'),_0x504afc[_0x5657('0x7')]))['emit'](_0x5657('0x1b'),_0x504afc);}};module[_0x5657('0x1c')]=ChatQueue;