An event handler for when a remote user sends a message
An event handler for when the socket initially connects
An event handler for when we succeed in making a new room
An event handler for when the socket disconnects
An event handler for errors due to incorrectly formatted requests
An event handler for when we request a room but already have one
An event handler for when we try to log in when we're already logged in
An event handler for errors due to not having a room
An event handler for errors due to not logging in first
An event handler for when the server says our username is taken
An event handler for when the server turns us away because it uses a different version of the protocol. The server disconnects right after.
An event handler for when we succeed in joining an existing room
An event handler for when a login request succeeds
An event handler for when a logout request succeeds
An event handler for when a broadcast is sent successfully
An event handler for when a remote user joins the room
An event handler for when a remote user exits the room
A socket for communicating with the server
The current state of the network stack
Connect to a server and start sending/receiving events
The address of the server to connect to
Forcibly disconnect from the server
Send a message to the server to try to create a new room
Send a message to the server to try to join an existing room
The Id of the room to join
Send a message to the server to try to log in
The desired userId
The desired userName
Send a request to the server to log out
Reset all of the event handlers. This is a good thing to do after disconnecting.
Broadcast a message to all other recipients in the room
The message to send
NetworkDevice interfaces with a server (see the "templates/server" folder) via socket.io to send and receive network events.
Naming convention: every incoming event handler is
onX(assign your own function to react to it); every outgoing action isrequestX(for anything the server can accept or reject) or a bare verb that pairs withconnect()(disconnect(),sendBroadcast()).