You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
914 B
38 lines
914 B
const WSProtocol = window.location.protocol === "https:" ? "wss" : "ws";
|
|
const RPSSocket = new WebSocket(
|
|
WSProtocol
|
|
+ '://'
|
|
+ window.location.host
|
|
+ '/rps/'
|
|
+ ROOM_ID
|
|
);
|
|
|
|
RPSSocket.onmessage = function(e) {
|
|
console.log("Receiving...");
|
|
console.log(e.data);
|
|
console.log(JSON.parse(e.data));
|
|
|
|
data = JSON.parse(e.data);
|
|
message = data.message;
|
|
if (data.event === 'warning')
|
|
{
|
|
write_message(message);
|
|
} else if (data.event === 'game_over') {
|
|
write_message("<b>" + message + "</b>");
|
|
} else if (data.event === 'info') {
|
|
write_message("<i>" + message + "</i>");
|
|
}
|
|
}
|
|
|
|
for (btn of document.querySelectorAll(".rpsbtn"))
|
|
{
|
|
btn.addEventListener('click', e => {
|
|
write_message("You selected " + e.target.id);
|
|
RPSSocket.send(
|
|
JSON.stringify({
|
|
'choice': e.target.id
|
|
})
|
|
);
|
|
})
|
|
}
|