aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/components/GolfPlayApp.client.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/app/components/GolfPlayApp.client.tsx')
-rw-r--r--frontend/app/components/GolfPlayApp.client.tsx18
1 files changed, 8 insertions, 10 deletions
diff --git a/frontend/app/components/GolfPlayApp.client.tsx b/frontend/app/components/GolfPlayApp.client.tsx
index 70c463f..eafbd1d 100644
--- a/frontend/app/components/GolfPlayApp.client.tsx
+++ b/frontend/app/components/GolfPlayApp.client.tsx
@@ -1,14 +1,15 @@
import { useEffect, useState } from "react";
-import useWebSocket, { ReadyState } from "react-use-websocket";
import { useDebouncedCallback } from "use-debounce";
import type { components } from "../.server/api/schema";
+import useWebSocket, { ReadyState } from "../hooks/useWebSocket";
import GolfPlayAppConnecting from "./GolfPlayApps/GolfPlayAppConnecting";
import GolfPlayAppFinished from "./GolfPlayApps/GolfPlayAppFinished";
import GolfPlayAppGaming from "./GolfPlayApps/GolfPlayAppGaming";
import GolfPlayAppStarting from "./GolfPlayApps/GolfPlayAppStarting";
import GolfPlayAppWaiting from "./GolfPlayApps/GolfPlayAppWaiting";
-type WebSocketMessage = components["schemas"]["GamePlayerMessageS2C"];
+type GamePlayerMessageS2C = components["schemas"]["GamePlayerMessageS2C"];
+type GamePlayerMessageC2S = components["schemas"]["GamePlayerMessageC2S"];
type Game = components["schemas"]["Game"];
@@ -26,8 +27,10 @@ export default function GolfPlayApp({
? `ws://localhost:8002/iosdc-japan/2024/code-battle/sock/golf/${game.game_id}/play?token=${sockToken}`
: `wss://t.nil.ninja/iosdc-japan/2024/code-battle/sock/golf/${game.game_id}/play?token=${sockToken}`;
- const { sendJsonMessage, lastJsonMessage, readyState } =
- useWebSocket<WebSocketMessage>(socketUrl, {});
+ const { sendJsonMessage, lastJsonMessage, readyState } = useWebSocket<
+ GamePlayerMessageS2C,
+ GamePlayerMessageC2S
+ >(socketUrl);
const [gameState, setGameState] = useState<GameState>("connecting");
@@ -101,10 +104,7 @@ export default function GolfPlayApp({
} else if (readyState === ReadyState.OPEN) {
if (lastJsonMessage !== null) {
console.log(lastJsonMessage.type);
- if (lastJsonMessage.type === "player:s2c:prepare") {
- console.log("player:c2s:ready");
- sendJsonMessage({ type: "player:c2s:ready" });
- } else if (lastJsonMessage.type === "player:s2c:start") {
+ if (lastJsonMessage.type === "player:s2c:start") {
if (
gameState !== "starting" &&
gameState !== "gaming" &&
@@ -128,8 +128,6 @@ export default function GolfPlayApp({
}
} else {
setGameState("waiting");
- console.log("player:c2s:entry");
- sendJsonMessage({ type: "player:c2s:entry" });
}
}
}, [sendJsonMessage, lastJsonMessage, readyState, gameState, currentScore]);