From a12a8fdfda9020dbc1aec4170ce8afbb7688766c Mon Sep 17 00:00:00 2001 From: basarat Date: Sat, 7 Sep 2013 00:04:38 +1000 Subject: [PATCH] socket.io : fix for functions used in storing data associated with client. Closes #734 --- socket.io/socket.io-tests.ts | 14 ++++++++++++++ socket.io/socket.io.d.ts | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/socket.io/socket.io-tests.ts b/socket.io/socket.io-tests.ts index 8412666108..0b29890ca1 100644 --- a/socket.io/socket.io-tests.ts +++ b/socket.io/socket.io-tests.ts @@ -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); + }); + }); }); \ No newline at end of file diff --git a/socket.io/socket.io.d.ts b/socket.io/socket.io.d.ts index 2b44ff6ab0..0908bc6cab 100644 --- a/socket.io/socket.io.d.ts +++ b/socket.io/socket.io.d.ts @@ -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;