From 0de5018f77cae705e2e09700aca9b6911b8b3588 Mon Sep 17 00:00:00 2001 From: Kevin Hanna Date: Wed, 20 Mar 2024 13:41:19 +0100 Subject: [PATCH 1/2] core: handle room_joined errors Currently for any error except `room_locked`, the SDK thinks it joins the room successfully. Rather than explicily handle all possible errors, we can fall back to this handler and add more specific cases as they are required by the SDK --- .changeset/tasty-geese-sit.md | 5 +++++ .../slices/__tests__/roomConnection.unit.ts | 18 ++++++++++++++++++ .../core/src/redux/slices/roomConnection.ts | 12 ++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 .changeset/tasty-geese-sit.md diff --git a/.changeset/tasty-geese-sit.md b/.changeset/tasty-geese-sit.md new file mode 100644 index 000000000..c3739625c --- /dev/null +++ b/.changeset/tasty-geese-sit.md @@ -0,0 +1,5 @@ +--- +"@whereby.com/core": minor +--- + +Handle errors while joining a room diff --git a/packages/core/src/redux/slices/__tests__/roomConnection.unit.ts b/packages/core/src/redux/slices/__tests__/roomConnection.unit.ts index 9fc1924e8..1b7c16fd6 100644 --- a/packages/core/src/redux/slices/__tests__/roomConnection.unit.ts +++ b/packages/core/src/redux/slices/__tests__/roomConnection.unit.ts @@ -39,6 +39,24 @@ describe("roomConnectionSlice", () => { }); }); + it("should set status to disconnected and populate the error if the there is an error", () => { + const result = roomConnectionSlice.reducer( + undefined, + signalEvents.roomJoined({ + error: "room_full", + selfId: "selfId", + isLocked: false, + }), + ); + + expect(result).toEqual({ + status: "disconnected", + session: null, + error: "room_full", + }); + }); + }); + describe("signalEvents.clientKicked", () => { it("should set status to kicked if the client is kicked", () => { const result = roomConnectionSlice.reducer( undefined, diff --git a/packages/core/src/redux/slices/roomConnection.ts b/packages/core/src/redux/slices/roomConnection.ts index 742ef6407..b4c9aec26 100644 --- a/packages/core/src/redux/slices/roomConnection.ts +++ b/packages/core/src/redux/slices/roomConnection.ts @@ -42,7 +42,7 @@ export type ConnectionStatus = export interface RoomConnectionState { session: { createdAt: string; id: string } | null; status: ConnectionStatus; - error: unknown; + error: string | null; } const initialState: RoomConnectionState = { @@ -64,7 +64,6 @@ export const roomConnectionSlice = createSlice({ }, extraReducers: (builder) => { builder.addCase(signalEvents.roomJoined, (state, action) => { - //TODO: Handle error const { error, isLocked } = action.payload; if (error === "room_locked" && isLocked) { @@ -74,6 +73,14 @@ export const roomConnectionSlice = createSlice({ }; } + if (error) { + return { + ...state, + status: "disconnected", + error, + }; + } + return { ...state, status: "connected", @@ -192,6 +199,7 @@ export const selectRoomConnectionRaw = (state: RootState) => state.roomConnectio export const selectRoomConnectionSession = (state: RootState) => state.roomConnection.session; export const selectRoomConnectionSessionId = (state: RootState) => state.roomConnection.session?.id; export const selectRoomConnectionStatus = (state: RootState) => state.roomConnection.status; +export const selectRoomConnectionError = (state: RootState) => state.roomConnection.error; /** * Reactors From d4937dd95a53718b4a03a8e2f8da73e6533c4ed3 Mon Sep 17 00:00:00 2001 From: Kevin Hanna Date: Wed, 20 Mar 2024 14:15:25 +0100 Subject: [PATCH 2/2] core: fix incorrect test cases We don't return room_full without the isLocked: true --- packages/core/src/redux/slices/__tests__/roomConnection.unit.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core/src/redux/slices/__tests__/roomConnection.unit.ts b/packages/core/src/redux/slices/__tests__/roomConnection.unit.ts index 1b7c16fd6..116f1e486 100644 --- a/packages/core/src/redux/slices/__tests__/roomConnection.unit.ts +++ b/packages/core/src/redux/slices/__tests__/roomConnection.unit.ts @@ -26,7 +26,6 @@ describe("roomConnectionSlice", () => { const result = roomConnectionSlice.reducer( undefined, signalEvents.roomJoined({ - error: "room_locked", selfId: "selfId", isLocked: false, }),