Built motion from commit a8c4dd89.|2.6.33
[motion2.git] / server / services / routing / model / smsQueue.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 _0x7a72=['mapAgentsId','updateRouting','updateRealtime','_rr','prototype','loggedIn','smsPause','paused','available','waiting','stringify','format','sms_queue:save','exports','md5','util','../../../config/environment','defaults','localhost','redis','name','strategy','beepall','Agents'];(function(_0x19950b,_0x53d0d7){var _0x3c6b41=function(_0x3924ad){while(--_0x3924ad){_0x19950b['push'](_0x19950b['shift']());}};_0x3c6b41(++_0x53d0d7);}(_0x7a72,0x1be));var _0x27a7=function(_0x4a0166,_0x45ef70){_0x4a0166=_0x4a0166-0x0;var _0x17597c=_0x7a72[_0x4a0166];return _0x17597c;};'use strict';var _=require('lodash');var md5=require(_0x27a7('0x0'));var util=require(_0x27a7('0x1'));var Redis=require('ioredis');var config=require(_0x27a7('0x2'));config['redis']=_[_0x27a7('0x3')](config['redis'],{'host':_0x27a7('0x4'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0x27a7('0x5')]));function SmsQueue(_0x5e56ac){this['id']=_0x5e56ac['id']||0x0;this[_0x27a7('0x6')]=_0x5e56ac[_0x27a7('0x6')]||'';this['timeout']=_0x5e56ac['timeout']||0xa;this[_0x27a7('0x7')]=_0x5e56ac['strategy']||_0x27a7('0x8');this[_0x27a7('0x9')]=_0x5e56ac[_0x27a7('0x9')];this[_0x27a7('0xa')]={};this['waiting']=0x0;this[_0x27a7('0x0')]='';this[_0x27a7('0xb')]();this[_0x27a7('0xc')]();}SmsQueue['prototype'][_0x27a7('0xb')]=function(){var _0x38a600=this['mapAgentsId'][_0x27a7('0xd')];this[_0x27a7('0xa')]=_['map'](this[_0x27a7('0x9')],'id');this[_0x27a7('0xa')][_0x27a7('0xd')]=_0x38a600;};SmsQueue[_0x27a7('0xe')][_0x27a7('0xc')]=function(){this[_0x27a7('0xf')]=0x0;this['paused']=0x0;for(var _0x4d3bfb=0x0;_0x4d3bfb<this[_0x27a7('0x9')]['length'];_0x4d3bfb+=0x1){if(this[_0x27a7('0x9')][_0x4d3bfb]['online']){this[_0x27a7('0xf')]+=0x1;}if(this[_0x27a7('0x9')][_0x4d3bfb][_0x27a7('0x10')]){this[_0x27a7('0x11')]+=0x1;}}this['available']=this['loggedIn']-this[_0x27a7('0x11')];this[_0x27a7('0x12')]=this['available']>=0x0?this[_0x27a7('0x12')]:0x0;var _0x2c82ab={'id':this['id'],'available':this[_0x27a7('0x12')],'loggedIn':this[_0x27a7('0xf')],'name':this[_0x27a7('0x6')],'paused':this['paused'],'waiting':this[_0x27a7('0x13')]};var _0x51253d=md5(JSON[_0x27a7('0x14')](_0x2c82ab));if(this[_0x27a7('0x0')]!==_0x51253d){this['md5']=_0x51253d;io['to'](util[_0x27a7('0x15')]('sms:queue:%s',_0x2c82ab[_0x27a7('0x6')]))['emit'](_0x27a7('0x16'),_0x2c82ab);}};module[_0x27a7('0x17')]=SmsQueue;