I have an online multiplayer checkers game project, I need a way to send messages of the last move made by an opponent to the other player. So I did some research and discovered that it is possible to create rooms on the server with JavaScript between two visitors on the same server. The players are technically viewing the same page but I mirror the move made by one player on the opponent pieces being viewed by the other player. How can I achieve this with JavaScript?
Right now the server am testing on is a development server on localhost.
if (isRedMoveValid(x1, y1, row, col)) {
let child = original.querySelector("div.red-piece");
if (child != null) {
original.removeChild(child);
}
//add that red piece to the tapped empty square
let div = document.createElement("div");
div.classList.add("red-piece");
//check if the move is valid
target.appendChild(div);
RED = false;
//submit the move made by this user to the server so it can reflect on the page
//of the second user
let message = "player A has moved from " + x1 + ":" + y1 + " to " + row + ":" + col;
//send the message to another user viewing the same page on a different device but on the same server in the same room
console.log(message);
}