Created
July 13, 2020 20:43
-
-
Save BetterProgramming/7453824015c0907b6c500f0da3514448 to your computer and use it in GitHub Desktop.
This file contains 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
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