forked from rickyrauch/Balloons.IO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.js
60 lines (45 loc) · 1.24 KB
/
init.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Initialize the application
*/
/*
* Module dependencies
*/
var fs = require('fs');
/*
* Initialize the
*
* @param {Object} Redis client instance
* API @public
*/
module.exports = function(client) {
/*
* Clean all forgoten sockets in Redis.io
*/
// Delete all users sockets from their lists
client.keys('sockets:for:*', function(err, keys) {
if(keys.length) client.del(keys);
console.log('Deletion of sockets reference for each user >> ', err || "Done!");
});
// No one is online when starting up
client.keys('rooms:*:online', function(err, keys) {
var roomNames = [];
if(keys.length) {
roomNames = roomNames.concat(keys);
client.del(keys);
}
roomNames.forEach(function(roomName, index) {
var key = roomName.replace(':online', ':info');
client.hset(key, 'online', 0);
});
console.log('Deletion of online users from rooms >> ', err || "Done!");
});
// Delete all socket.io's sockets data from Redis
client.smembers('socketio:sockets', function(err, sockets) {
if(sockets.length) client.del(sockets);
console.log('Deletion of socket.io stored sockets data >> ', err || "Done!");
});
/*
* Create 'chats' dir
*/
// fs.mkdir('./chats');
};