diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2023-07-15 02:46:14 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2023-07-15 02:46:14 +0530 |
commit | 72e89afac0f11d59e4399f245e6dcc728bec38d9 (patch) | |
tree | 481d5b9fb330f1a3528aa772dacf4a20e035fe65 /src/components/MultiplayerGrid.js | |
parent | 6036a220e251a9963e62508ae7dfeb68b2f289a2 (diff) |
cleaned up code, added timeout, etc
Diffstat (limited to 'src/components/MultiplayerGrid.js')
-rw-r--r-- | src/components/MultiplayerGrid.js | 11 |
1 files changed, 9 insertions, 2 deletions
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); |