Skip to content

Commit

Permalink
R!! Update client
Browse files Browse the repository at this point in the history
  • Loading branch information
Gesma94 committed Mar 23, 2024
1 parent dbd3ed9 commit 0775069
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
7 changes: 2 additions & 5 deletions client/src/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { PARAM_KEY } from "@shared/constants/SharedConstants";

/** Specifies the base URL for API calls */
export const BASE_API_URL = import.meta.env.VITE_SERVER_BASE_URL;

Expand All @@ -12,11 +14,6 @@ export const LOCAL_STORAGE_CONST = {
USER_USERNAME_KEY: '__word_impostor_user_username__'
} as const;

/** Object that contains constants related to query parameter keys */
export const PARAM_KEY = {
MASTER_UUID: "master-uuid"
} as const;

export const ROUTES = {
ROOM: "/room",
ERROR: "/error",
Expand Down
14 changes: 10 additions & 4 deletions client/src/routes/JoinRoom/JoinRoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,19 @@ export const JoinRoom = () => {
try {
const apiResponse = await fetch(`${apiUrl}/room/${roomId()}/exists`);
await Utils.delay(1000);

if (apiResponse.ok) {
navigate(`/room/${roomId()}`);
if (!apiResponse.ok) {
setError(`Error while communicating with the server`);
}
else {

const apiResult = new Boolean(apiResponse.text());

if (!apiResult) {
setError(`Cannot connect to room '${roomId()}'`);
return;
}

navigate(`/room/${roomId()}`);
}
catch (e) {
setError(`Error while communicating with the server`);
Expand Down
7 changes: 7 additions & 0 deletions client/src/routes/Room/Master/RoomMaster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ export const RoomMaster = () => {
return;
}

const apiResult = new Boolean(apiResponse.text());

if (!apiResult) {
navigate('/error');
return;
}

const wsUrl = import.meta.env.VITE_SERVER_BASE_WS_URL;

webSocket = new WebSocket(wsUrl);
Expand Down

0 comments on commit 0775069

Please sign in to comment.