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;