'use strict'; const config = require('config'); // this is a mock version of the Redis API, // emulating Redis if it is not available locally var notRedis = { state: {}, topics: {}, publish: function(topic, msg, cb) { if (!this.topics[topic]) { this.topics[topic] = { subscribers: [] }; } var t=this.topics[topic]; for (var i=0; i { cb(); }); }, rateLimit: function(namespace, ip, cb) { const key = "limit_"+ namespace + "_"+ ip; const redis = this.connection; redis.get(key, (err, count)=> { if (count) { if(count < 150) { redis.incr(key, (err, newCount) => { if (newCount==150) { // limit } cb(true); }); } else { cb(false); } } else { redis.set(key, 1, (err, count) => { redis.expire(key, 1800, (err, expResult) => { cb(true); }); }); } }); }, isOnlineInSpace: function(user, space, cb) { this.connection.smembers("space_" + space._id.toString(), function(err, list) { if (err) cb(err); else { var users = list.filter(function(item) { return user._id.toString() === item; }); cb(null, (users.length > 0)); } }); } }; return module.exports;