Created
January 6, 2017 12:37
-
-
Save thompsonemerson/2f15bc42bad106c0a50a3e1655c52ad8 to your computer and use it in GitHub Desktop.
Some methods to use with socket.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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