From 72e89afac0f11d59e4399f245e6dcc728bec38d9 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sat, 15 Jul 2023 02:46:14 +0530 Subject: cleaned up code, added timeout, etc --- src/components/MultiplayerGrid.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/components/MultiplayerGrid.js') diff --git a/src/components/MultiplayerGrid.js b/src/components/MultiplayerGrid.js index 7cd3835..4260e9b 100644 --- a/src/components/MultiplayerGrid.js +++ b/src/components/MultiplayerGrid.js @@ -21,7 +21,7 @@ import { io } from 'socket.io-client'; import Box from './Box'; import './style.css'; -const socket = io("http://localhost:5000"); +const socket = io("https://ttt.vidhukant.com/api"); const MultiplayerGrid = (props) => { // 0 is O, 1 is X, 2 is blank @@ -36,9 +36,16 @@ const MultiplayerGrid = (props) => { // host/join room useEffect(() => { if (isHost) { + const timeout = setTimeout(() => { + setMessage("Server Timed Out After 5 Seconds"); + setShowMessage(true); + setTimeout(() => window.location.reload(), 3000) + }, 5000); + socket.emit("host"); socket.on("broadcast code", (code) => { + clearTimeout(timeout); setMessage(`Game Code: ${code}`); setShowMessage(true); }); @@ -47,7 +54,7 @@ const MultiplayerGrid = (props) => { setMessage("Opponent Joined") setShowMessage(true) setTimeout(() => setShowMessage(false), 3000) - }) + }); } else { socket.emit("join", joinCode); -- cgit v1.2.3