I don't know when I should store something in the "socket session for the client". in the snippet below we use socket.username. I've seen other code that uses socket.id and that gets the id of a socket i think. Is there a list of properties to use on this socket object. right now I'm thinking that socket
is an object and that we can add a new property with the dot method(operator), in this case the made up property is username and the object is socket . and we get the username from socket.emit('add user', $usernameInput.val().trim());
from the client script.
socket.on('add user', function (username) {
// we store the username in the socket session for this client
socket.username = username;
// add the client's username to the global list
usernames[username] = username;
Since I'm not sure how to use this socket ?object? Im not sure if I need to use it for this small "game" I'm trying to make. basically there's a canvas on the client and its split up into 4 quadrants and if player1 clicks on the "top right", the top right quadrant on the client(player1) and players 2 canvas is filled. and the player go back and forth clicking quadrant filling up the canvas I get the quadrant info by doing something like
function checkCoord(left,top, right, bottom){
//x and y are retreived on mousemove
if(x < right && y < bottom){
return "topLeft"
}
if( x > left && y <bottom ){
return "top right"
}
}
Do I need to do something like socket.player
in the index.js file?
if so how would i do it
would this keep track of which player clicks on the quadrant?
After writing the above I looked over the code again I see
io.on('connection', function (socket) {
does this mean that when the socke.io code from the server(module) hears a connetion
event we do some callback that has a socket object? and now we could do something with the socket object?
sorry this is so long. just want to learn how to use this socket stuff.