Skip to content

Commit

Permalink
notify both players of game start
Browse files Browse the repository at this point in the history
  • Loading branch information
h908714124 committed Oct 8, 2024
1 parent 770f117 commit 5b18c3e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main/client/src/feature/lobby/Lobby.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function Lobby() {
initialized.current = true
let sub = stompClient.subscribe("/topic/gamestart", (message) => {
let r = JSON.parse(message.body)
if (r.opponent === auth.name) {
if (r.players.includes(auth.name)) {
navigate(base + "/game/" + r.id)
}
})
Expand Down
9 changes: 1 addition & 8 deletions src/main/client/src/feature/lobby/Requests.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import {
twJoin,
} from "tailwind-merge"
import {
useNavigate,
} from "react-router-dom"
import {
base,
StompContext,
tfetch,
doTry,
Expand All @@ -24,7 +20,6 @@ export function Requests({lobbyState}) {
let [requests, setRequests] = useState([])
let openGameId = lobbyState.openGameId
let stompClient = useContext(StompContext)
let navigate = useNavigate()
let auth = useAuthStore(state => state.auth)
let initialized = useRef()
useEffect(() => {
Expand All @@ -47,7 +42,7 @@ export function Requests({lobbyState}) {
return () => {
sub1.unsubscribe()
}
}, [auth, initialized, stompClient, navigate, openGameId])
}, [auth, initialized, stompClient, openGameId])
if (!openGameId) {
return <div />
}
Expand All @@ -65,7 +60,6 @@ export function Requests({lobbyState}) {
}

function Request({request}) {
let navigate = useNavigate()
let auth = useAuthStore(state => state.auth)
return (
<div
Expand All @@ -79,7 +73,6 @@ function Request({request}) {
},
body: JSON.stringify(request),
})
navigate(base + "/game/" + request.game.id)
})
}}
className={twJoin(
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/bernd/GameController.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public ResponseEntity<?> start(@RequestBody AcceptRequest acceptRequest) {
chat.messages().add(startMessage);
operations.convertAndSend("/topic/chat/" + chat.id(), startMessage);
operations.convertAndSend("/topic/gamestart", Map.of(
"opponent", acceptRequest.opponent(),
"players", List.of(principal, acceptRequest.opponent()),
"id", openGame.id()));
operations.convertAndSend("/topic/lobby/open_games", openGames.games());
operations.convertAndSend("/topic/lobby/active_games", activeGames.games());
Expand Down

0 comments on commit 5b18c3e

Please sign in to comment.