0818657bdef5ff9be3dc1cf63ad62fd3c02b34ef
[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 _0x5797=['name','timeout','strategy','beepall','Agents','mapAgentsId','waiting','updateRouting','prototype','_rr','updateRealtime','loggedIn','chatPause','paused','available','stringify','format','chat:queue:%s','chat_queue:save','lodash','md5','redis','socket.io-emitter'];(function(_0x20a584,_0xe384a5){var _0x4b41a8=function(_0x2127c6){while(--_0x2127c6){_0x20a584['push'](_0x20a584['shift']());}};_0x4b41a8(++_0xe384a5);}(_0x5797,0xf9));var _0x7579=function(_0x4c440b,_0x3ea627){_0x4c440b=_0x4c440b-0x0;var _0x2d48cf=_0x5797[_0x4c440b];return _0x2d48cf;};'use strict';var _=require(_0x7579('0x0'));var md5=require(_0x7579('0x1'));var util=require('util');var Redis=require('ioredis');var config=require('../../../config/environment');config[_0x7579('0x2')]=_['defaults'](config[_0x7579('0x2')],{'host':'localhost','port':0x18eb});var io=require(_0x7579('0x3'))(new Redis(config[_0x7579('0x2')]));function ChatQueue(_0x1766dd){this['id']=_0x1766dd['id']||0x0;this[_0x7579('0x4')]=_0x1766dd[_0x7579('0x4')]||'';this[_0x7579('0x5')]=_0x1766dd[_0x7579('0x5')]||0xa;this['strategy']=_0x1766dd[_0x7579('0x6')]||_0x7579('0x7');this[_0x7579('0x8')]=_0x1766dd['Agents'];this[_0x7579('0x9')]={};this[_0x7579('0xa')]=0x0;this[_0x7579('0x1')]='';this[_0x7579('0xb')]();this['updateRealtime']();}ChatQueue[_0x7579('0xc')]['updateRouting']=function(){var _0x533319=this[_0x7579('0x9')][_0x7579('0xd')];this[_0x7579('0x9')]=_['map'](this['Agents'],'id');this[_0x7579('0x9')]['_rr']=_0x533319;};ChatQueue['prototype'][_0x7579('0xe')]=function(){this[_0x7579('0xf')]=0x0;this['paused']=0x0;for(var _0x2c09c2=0x0;_0x2c09c2<this[_0x7579('0x8')]['length'];_0x2c09c2+=0x1){if(this['Agents'][_0x2c09c2]['online']){this[_0x7579('0xf')]+=0x1;}if(this['Agents'][_0x2c09c2][_0x7579('0x10')]){this[_0x7579('0x11')]+=0x1;}}this[_0x7579('0x12')]=this[_0x7579('0xf')]-this['paused'];this[_0x7579('0x12')]=this['available']>=0x0?this[_0x7579('0x12')]:0x0;var _0x3e3ccc={'id':this['id'],'available':this[_0x7579('0x12')],'loggedIn':this['loggedIn'],'name':this['name'],'paused':this[_0x7579('0x11')],'waiting':this[_0x7579('0xa')]};var _0x1c903e=md5(JSON[_0x7579('0x13')](_0x3e3ccc));if(this[_0x7579('0x1')]!==_0x1c903e){this[_0x7579('0x1')]=_0x1c903e;io['to'](util[_0x7579('0x14')](_0x7579('0x15'),_0x3e3ccc['name']))['emit'](_0x7579('0x16'),_0x3e3ccc);}};module['exports']=ChatQueue;