fc70d7de65a282cedfa6271c94b53fc95088b795
[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 _0xadb9=['waiting','updateRouting','updateRealtime','prototype','_rr','loggedIn','paused','length','online','chatPause','available','stringify','format','chat:queue:%s','md5','../../../config/environment','redis','defaults','localhost','socket.io-emitter','name','timeout','strategy','beepall','Agents','mapAgentsId'];(function(_0x6cf19c,_0x2f3f02){var _0xce14f3=function(_0x474587){while(--_0x474587){_0x6cf19c['push'](_0x6cf19c['shift']());}};_0xce14f3(++_0x2f3f02);}(_0xadb9,0x12c));var _0x9adb=function(_0x384412,_0x6ad830){_0x384412=_0x384412-0x0;var _0x4c3e4f=_0xadb9[_0x384412];return _0x4c3e4f;};'use strict';var _=require('lodash');var md5=require(_0x9adb('0x0'));var util=require('util');var Redis=require('ioredis');var config=require(_0x9adb('0x1'));config[_0x9adb('0x2')]=_[_0x9adb('0x3')](config[_0x9adb('0x2')],{'host':_0x9adb('0x4'),'port':0x18eb});var io=require(_0x9adb('0x5'))(new Redis(config[_0x9adb('0x2')]));function ChatQueue(_0x1d9f30){this['id']=_0x1d9f30['id']||0x0;this[_0x9adb('0x6')]=_0x1d9f30[_0x9adb('0x6')]||'';this[_0x9adb('0x7')]=_0x1d9f30['timeout']||0xa;this[_0x9adb('0x8')]=_0x1d9f30[_0x9adb('0x8')]||_0x9adb('0x9');this[_0x9adb('0xa')]=_0x1d9f30[_0x9adb('0xa')];this[_0x9adb('0xb')]={};this[_0x9adb('0xc')]=0x0;this[_0x9adb('0x0')]='';this[_0x9adb('0xd')]();this[_0x9adb('0xe')]();}ChatQueue[_0x9adb('0xf')][_0x9adb('0xd')]=function(){var _0x57243a=this[_0x9adb('0xb')][_0x9adb('0x10')];this[_0x9adb('0xb')]=_['map'](this[_0x9adb('0xa')],'id');this[_0x9adb('0xb')][_0x9adb('0x10')]=_0x57243a;};ChatQueue[_0x9adb('0xf')][_0x9adb('0xe')]=function(){this[_0x9adb('0x11')]=0x0;this[_0x9adb('0x12')]=0x0;for(var _0x2ad45c=0x0;_0x2ad45c<this[_0x9adb('0xa')][_0x9adb('0x13')];_0x2ad45c+=0x1){if(this[_0x9adb('0xa')][_0x2ad45c][_0x9adb('0x14')]){this[_0x9adb('0x11')]+=0x1;}if(this[_0x9adb('0xa')][_0x2ad45c][_0x9adb('0x15')]){this['paused']+=0x1;}}this[_0x9adb('0x16')]=this[_0x9adb('0x11')]-this[_0x9adb('0x12')];this[_0x9adb('0x16')]=this[_0x9adb('0x16')]>=0x0?this[_0x9adb('0x16')]:0x0;var _0x3f3244={'id':this['id'],'available':this[_0x9adb('0x16')],'loggedIn':this[_0x9adb('0x11')],'name':this['name'],'paused':this[_0x9adb('0x12')],'waiting':this[_0x9adb('0xc')]};var _0x4b5b7f=md5(JSON[_0x9adb('0x17')](_0x3f3244));if(this[_0x9adb('0x0')]!==_0x4b5b7f){this['md5']=_0x4b5b7f;io['to'](util[_0x9adb('0x18')](_0x9adb('0x19'),_0x3f3244[_0x9adb('0x6')]))['emit']('chat_queue:save',_0x3f3244);}};module['exports']=ChatQueue;