socket.io : fix for functions used in storing data associated with client. Closes #734

This commit is contained in:
basarat
2013-09-07 00:04:38 +10:00
parent 37b4cae7d7
commit a12a8fdfda
2 changed files with 15 additions and 1 deletions

View File

@@ -7,4 +7,18 @@ socketManager.sockets.on('connection', socket => {
socket.on('my other event', data => {
console.log(data);
});
});
// Storing data Associated to a client.
// Server side sample
io.listen(80).sockets.on('connection', function (socket) {
socket.on('set nickname', function (name) {
socket.set('nickname', name, function () { socket.emit('ready'); });
});
socket.on('msg', function () {
socket.get('nickname', function (err, name) {
console.log('Chat message by ', name);
});
});
});

View File

@@ -24,7 +24,7 @@ interface Socket {
join(name: string, fn: Function): Socket;
unjoin(name: string, fn: Function): Socket;
set(key: string, value: any, fn: Function): Socket;
get(key: string, value: any, fn: Function): Socket;
get(key: string, fn: Function): Socket;
has(key: string, fn: Function): Socket;
del(key: string, fn: Function): Socket;
disconnect(): Socket;