Built motion from commit 10af8726.|2.6.34
[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 _0xab01=['socket.io-emitter','name','timeout','strategy','beepall','mapAgentsId','updateRealtime','_rr','map','prototype','Agents','length','online','loggedIn','chatPause','paused','available','waiting','stringify','chat:queue:%s','emit','chat_queue:save','exports','md5','ioredis','../../../config/environment','redis','defaults','localhost'];(function(_0x2a7b50,_0x545d55){var _0x4224c9=function(_0x2b96f6){while(--_0x2b96f6){_0x2a7b50['push'](_0x2a7b50['shift']());}};_0x4224c9(++_0x545d55);}(_0xab01,0x139));var _0x1ab0=function(_0x483657,_0x4c9172){_0x483657=_0x483657-0x0;var _0xe9877c=_0xab01[_0x483657];return _0xe9877c;};'use strict';var _=require('lodash');var md5=require(_0x1ab0('0x0'));var util=require('util');var Redis=require(_0x1ab0('0x1'));var config=require(_0x1ab0('0x2'));config[_0x1ab0('0x3')]=_[_0x1ab0('0x4')](config[_0x1ab0('0x3')],{'host':_0x1ab0('0x5'),'port':0x18eb});var io=require(_0x1ab0('0x6'))(new Redis(config[_0x1ab0('0x3')]));function ChatQueue(_0x375911){this['id']=_0x375911['id']||0x0;this[_0x1ab0('0x7')]=_0x375911['name']||'';this[_0x1ab0('0x8')]=_0x375911[_0x1ab0('0x8')]||0xa;this[_0x1ab0('0x9')]=_0x375911['strategy']||_0x1ab0('0xa');this['Agents']=_0x375911['Agents'];this[_0x1ab0('0xb')]={};this['waiting']=0x0;this['md5']='';this['updateRouting']();this[_0x1ab0('0xc')]();}ChatQueue['prototype']['updateRouting']=function(){var _0x5eeb54=this[_0x1ab0('0xb')][_0x1ab0('0xd')];this['mapAgentsId']=_[_0x1ab0('0xe')](this['Agents'],'id');this[_0x1ab0('0xb')][_0x1ab0('0xd')]=_0x5eeb54;};ChatQueue[_0x1ab0('0xf')][_0x1ab0('0xc')]=function(){this['loggedIn']=0x0;this['paused']=0x0;for(var _0xc55fa2=0x0;_0xc55fa2<this[_0x1ab0('0x10')][_0x1ab0('0x11')];_0xc55fa2+=0x1){if(this[_0x1ab0('0x10')][_0xc55fa2][_0x1ab0('0x12')]){this[_0x1ab0('0x13')]+=0x1;}if(this[_0x1ab0('0x10')][_0xc55fa2][_0x1ab0('0x14')]){this[_0x1ab0('0x15')]+=0x1;}}this[_0x1ab0('0x16')]=this[_0x1ab0('0x13')]-this[_0x1ab0('0x15')];this[_0x1ab0('0x16')]=this['available']>=0x0?this['available']:0x0;var _0x1268d6={'id':this['id'],'available':this[_0x1ab0('0x16')],'loggedIn':this[_0x1ab0('0x13')],'name':this[_0x1ab0('0x7')],'paused':this['paused'],'waiting':this[_0x1ab0('0x17')]};var _0x742e02=md5(JSON[_0x1ab0('0x18')](_0x1268d6));if(this[_0x1ab0('0x0')]!==_0x742e02){this[_0x1ab0('0x0')]=_0x742e02;io['to'](util['format'](_0x1ab0('0x19'),_0x1268d6['name']))[_0x1ab0('0x1a')](_0x1ab0('0x1b'),_0x1268d6);}};module[_0x1ab0('0x1c')]=ChatQueue;