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:
12
client.ts
12
client.ts
@@ -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;
|
||||
|
Reference in New Issue
Block a user