0.0.1 • Published 10 years ago

socket.io-with v0.0.1

Weekly downloads
6
License
-
Repository
-
Last release
10 years ago

io.sockets.withSession(pairs).emit(channel, message);

Emit an event on sockets on which their session match the provided key value pairs

io.sockets.withHandshake(pairs).emit(channel, message);

Emit an event on sockets on witch their handshake match the provided key value pairs

Sample :

var io = require('socket.io').listen(3000);
require('socket.io-with')(io);

io.set('authorization', function(handshake, accept) {
	
	findUserID(handshake, function(err, user) { // retrieve user
		if(err) return accept(err, false);

		handshake.userID = user._id; // attach user ID on handshake

		accept(null, true);
	});
});

io.sockets.on('connection', function(socket) {
	socket.set('role', 'User'); // set the 'User' role in socket session store
});
io.sockets.withSession({role: 'User'}).emit('message', 'Hello everybody !');
io.sockets.withHandshake({userID: 'SomeID'}).emit('message', 'Hello somebody !');
0.0.1

10 years ago