Skip to content

Commit

Permalink
Merge pull request #380 from Game-as-a-Service/fix/game-ending-refetc…
Browse files Browse the repository at this point in the history
…h-room-info

fix: game end not getting the correct room status bug
  • Loading branch information
JohnsonMao authored Mar 19, 2024
2 parents 2480f27 + 29d0fd3 commit 5cf5fab
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pages/rooms/[roomId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default function Room() {
const player = roomInfo.players.find(
(player) => player.id === currentUser?.id
);
const isHost = roomInfo.host.id === currentUser?.id;

useEffect(() => {
async function getRoomInfo() {
Expand Down Expand Up @@ -101,6 +102,7 @@ export default function Room() {
firePopup({
title: `遊戲已結束!`,
});
fetch(getRoomInfoEndpoint(roomId)).then(initializeRoom);
});

socket.on(SOCKET_EVENT.ROOM_CLOSED, () => {
Expand All @@ -113,13 +115,16 @@ export default function Room() {
token,
socket,
currentUser?.id,
roomId,
addPlayer,
removePlayer,
updateUserReadyStatus,
updateHost,
updateRoomStatus,
replace,
firePopup,
fetch,
initializeRoom,
]);

// Event: kick user
Expand Down Expand Up @@ -169,10 +174,9 @@ export default function Room() {
};

firePopup({
title:
roomInfo.host.id === currentUser?.id
? `當您離開房間後,房主的位子將會自動移交給其他成員,若房間內沒有成員則會自動關閉房間,是否確定要離開房間?`
: `是否確定要離開房間?`,
title: isHost
? `當您離開房間後,房主的位子將會自動移交給其他成員,若房間內沒有成員則會自動關閉房間,是否確定要離開房間?`
: `是否確定要離開房間?`,
showCancelButton: true,
onConfirm: leave,
});
Expand Down Expand Up @@ -216,8 +220,8 @@ export default function Room() {
onClickClose={handleClickClose}
onClickLeave={handleLeave}
onClickStart={handleStart}
isHost={roomInfo.host.id === currentUser?.id}
isReady={player?.isReady || false}
isHost={isHost}
isReady={isHost || !!player?.isReady}
/>
</div>
{gameUrl && <GameWindow gameUrl={gameUrl} />}
Expand Down

0 comments on commit 5cf5fab

Please sign in to comment.