53211fda9425bc2ccd46690c185d58410122e4c3
[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 _0x564e=['chat:queue:%s','emit','chat_queue:save','md5','util','ioredis','redis','localhost','socket.io-emitter','name','timeout','strategy','waiting','updateRouting','updateRealtime','prototype','mapAgentsId','_rr','map','Agents','loggedIn','paused','available','stringify','format'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0x564e,0x161));var _0xe564=function(_0x375b09,_0x4593fb){_0x375b09=_0x375b09-0x0;var _0x31f372=_0x564e[_0x375b09];return _0x31f372;};'use strict';var _=require('lodash');var md5=require(_0xe564('0x0'));var util=require(_0xe564('0x1'));var Redis=require(_0xe564('0x2'));var config=require('../../../config/environment');config[_0xe564('0x3')]=_['defaults'](config[_0xe564('0x3')],{'host':_0xe564('0x4'),'port':0x18eb});var io=require(_0xe564('0x5'))(new Redis(config[_0xe564('0x3')]));function ChatQueue(_0x5a1ef0){this['id']=_0x5a1ef0['id']||0x0;this['name']=_0x5a1ef0[_0xe564('0x6')]||'';this[_0xe564('0x7')]=_0x5a1ef0['timeout']||0xa;this[_0xe564('0x8')]=_0x5a1ef0[_0xe564('0x8')]||'beepall';this['Agents']=_0x5a1ef0['Agents'];this['mapAgentsId']={};this[_0xe564('0x9')]=0x0;this['md5']='';this[_0xe564('0xa')]();this[_0xe564('0xb')]();}ChatQueue[_0xe564('0xc')]['updateRouting']=function(){var _0x1ae99e=this[_0xe564('0xd')][_0xe564('0xe')];this[_0xe564('0xd')]=_[_0xe564('0xf')](this[_0xe564('0x10')],'id');this[_0xe564('0xd')][_0xe564('0xe')]=_0x1ae99e;};ChatQueue[_0xe564('0xc')][_0xe564('0xb')]=function(){this[_0xe564('0x11')]=0x0;this[_0xe564('0x12')]=0x0;for(var _0x2ad5d3=0x0;_0x2ad5d3<this[_0xe564('0x10')]['length'];_0x2ad5d3+=0x1){if(this[_0xe564('0x10')][_0x2ad5d3]['online']){this[_0xe564('0x11')]+=0x1;}if(this[_0xe564('0x10')][_0x2ad5d3]['chatPause']){this[_0xe564('0x12')]+=0x1;}}this[_0xe564('0x13')]=this[_0xe564('0x11')]-this[_0xe564('0x12')];this[_0xe564('0x13')]=this[_0xe564('0x13')]>=0x0?this[_0xe564('0x13')]:0x0;var _0x14e649={'id':this['id'],'available':this[_0xe564('0x13')],'loggedIn':this[_0xe564('0x11')],'name':this[_0xe564('0x6')],'paused':this[_0xe564('0x12')],'waiting':this[_0xe564('0x9')]};var _0x4e0ebb=md5(JSON[_0xe564('0x14')](_0x14e649));if(this[_0xe564('0x0')]!==_0x4e0ebb){this[_0xe564('0x0')]=_0x4e0ebb;io['to'](util[_0xe564('0x15')](_0xe564('0x16'),_0x14e649[_0xe564('0x6')]))[_0xe564('0x17')](_0xe564('0x18'),_0x14e649);}};module['exports']=ChatQueue;