1
0
mirror of https://github.com/thib8956/tic-tac-toe-ws.git synced 2025-08-24 00:11:56 +00:00

handle remote websocketserver and handle game reset by client

This commit is contained in:
2024-09-25 22:15:10 +02:00
parent 6a729cc7ad
commit c9157e83ef
3 changed files with 35 additions and 10 deletions

View File

@@ -5,7 +5,11 @@ const GRID_SIZE = CELL_SIZE * 3;
const SHAPE_SIZE = 100;
const ANIMATE_DURATION = 500; // ms
const ws = new WebSocket("ws://localhost:1234");
let address = "ws://localhost:1234";
if (window.location.hostname !== "localhost") {
address = "wss://tic-tac-toe-ws-production.up.railway.app";
}
const ws = new WebSocket(address);
interface Point {
x: number;
@@ -221,6 +225,12 @@ function init() {
}
break;
}
case "reset": {
canvasMsg = `Game reset... Id #${myId}, playing as ${mySymbol}`;
grid = new Array(9);
pendingEvts = [];
break;
}
default: {
console.warn("unhandled message kind:", msg.kind);
break;