Skip to content

Instantly share code, notes, and snippets.

@thompsonemerson
Created January 6, 2017 12:37
Show Gist options
  • Select an option

  • Save thompsonemerson/2f15bc42bad106c0a50a3e1655c52ad8 to your computer and use it in GitHub Desktop.

Select an option

Save thompsonemerson/2f15bc42bad106c0a50a3e1655c52ad8 to your computer and use it in GitHub Desktop.
Some methods to use with socket.io
// Send only to the current client
client.emit('message', "this is a test");
// Send to all customers, including the current
io.emit('message', "this is a test");
// Send to all clients except current
client.broadcast.emit('message', "this is a test");
// Send to all clients (exception current) for a specific room
socket.broadcast.to('game').emit('message', 'nice game');
// Send to all customers in a specific room
io.in('game').emit('message', 'cool game');
// Send to the current one, if he is in the room
client.to('game').emit('message', 'enjoy the game');
// Send to all clients in a namespace 'namespace-example'
io.of('namespace-example').emit('message', 'gg');
// Sending to an individual socketid
client.broadcast.to(socketid).emit('message', 'for your eyes only');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment