6960f762398b62253d7fc0d96821f3f7191b52b7
[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 _0x2576=['loggedIn','chatPause','available','stringify','format','emit','chat_queue:save','md5','util','ioredis','../../../config/environment','redis','localhost','name','timeout','strategy','beepall','Agents','mapAgentsId','waiting','updateRealtime','prototype','updateRouting','_rr','map','paused','length','online'];(function(_0xacb1e2,_0x55e0ab){var _0x463815=function(_0x413c3b){while(--_0x413c3b){_0xacb1e2['push'](_0xacb1e2['shift']());}};_0x463815(++_0x55e0ab);}(_0x2576,0xcb));var _0x6257=function(_0x4e69e2,_0x2c8598){_0x4e69e2=_0x4e69e2-0x0;var _0x54eac0=_0x2576[_0x4e69e2];return _0x54eac0;};'use strict';var _=require('lodash');var md5=require(_0x6257('0x0'));var util=require(_0x6257('0x1'));var Redis=require(_0x6257('0x2'));var config=require(_0x6257('0x3'));config[_0x6257('0x4')]=_['defaults'](config['redis'],{'host':_0x6257('0x5'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config['redis']));function ChatQueue(_0x5eb791){this['id']=_0x5eb791['id']||0x0;this[_0x6257('0x6')]=_0x5eb791[_0x6257('0x6')]||'';this[_0x6257('0x7')]=_0x5eb791[_0x6257('0x7')]||0xa;this[_0x6257('0x8')]=_0x5eb791[_0x6257('0x8')]||_0x6257('0x9');this['Agents']=_0x5eb791[_0x6257('0xa')];this[_0x6257('0xb')]={};this[_0x6257('0xc')]=0x0;this['md5']='';this['updateRouting']();this[_0x6257('0xd')]();}ChatQueue[_0x6257('0xe')][_0x6257('0xf')]=function(){var _0x11c43a=this['mapAgentsId'][_0x6257('0x10')];this[_0x6257('0xb')]=_[_0x6257('0x11')](this['Agents'],'id');this[_0x6257('0xb')][_0x6257('0x10')]=_0x11c43a;};ChatQueue[_0x6257('0xe')][_0x6257('0xd')]=function(){this['loggedIn']=0x0;this[_0x6257('0x12')]=0x0;for(var _0x2d42e7=0x0;_0x2d42e7<this[_0x6257('0xa')][_0x6257('0x13')];_0x2d42e7+=0x1){if(this[_0x6257('0xa')][_0x2d42e7][_0x6257('0x14')]){this[_0x6257('0x15')]+=0x1;}if(this[_0x6257('0xa')][_0x2d42e7][_0x6257('0x16')]){this[_0x6257('0x12')]+=0x1;}}this[_0x6257('0x17')]=this[_0x6257('0x15')]-this['paused'];this[_0x6257('0x17')]=this[_0x6257('0x17')]>=0x0?this['available']:0x0;var _0x4eccf2={'id':this['id'],'available':this[_0x6257('0x17')],'loggedIn':this[_0x6257('0x15')],'name':this[_0x6257('0x6')],'paused':this[_0x6257('0x12')],'waiting':this[_0x6257('0xc')]};var _0x1f41ab=md5(JSON[_0x6257('0x18')](_0x4eccf2));if(this[_0x6257('0x0')]!==_0x1f41ab){this[_0x6257('0x0')]=_0x1f41ab;io['to'](util[_0x6257('0x19')]('chat:queue:%s',_0x4eccf2[_0x6257('0x6')]))[_0x6257('0x1a')](_0x6257('0x1b'),_0x4eccf2);}};module['exports']=ChatQueue;