Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Created July 13, 2020 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BetterProgramming/7453824015c0907b6c500f0da3514448 to your computer and use it in GitHub Desktop.
Save BetterProgramming/7453824015c0907b6c500f0da3514448 to your computer and use it in GitHub Desktop.
io.on('connection', socket => {
console.log("New user connected")
socket.username = "Anonymous"
socket.on('change_username', data => {
socket.username = data.username
})
//handle the new message event
socket.on('new_message', data => {
console.log("new message")
io.sockets.emit('receive_message', {message: data.message, username: socket.username})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment