-
Notifications
You must be signed in to change notification settings - Fork 2
/
socketio.js
33 lines (33 loc) · 1.04 KB
/
socketio.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
(function() {
var listen, parseCookie;
parseCookie = require('connect').utils.parseCookie;
listen = function(app) {
var db, io;
db = app.db;
io = app.io;
io.configure(function() {
return io.set('authorization', function(handshakeData, callback) {
var cookie;
cookie = parseCookie(handshakeData.headers.cookie);
return app.sessionStore.get(cookie['connect.sid'], function(err, session) {
if (err || !session) {
return callback(null, false);
} else {
handshakeData.user_id = session.user_id;
return callback(null, true);
}
});
});
});
io.sockets.on('connection', function(socket) {
app.clients[socket.handshake.user_id] = socket.id;
return socket.on('disconnect', function(a) {
return delete app.clients[socket.handshake.user_id];
});
});
return io.sockets.on('error', function(reason) {
return console.log('socket.io error:', reason);
});
};
exports.listen = listen;
}).call(this);