Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: handle room_joined errors #117

Merged
merged 2 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tasty-geese-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@whereby.com/core": minor
---

Handle errors while joining a room
19 changes: 18 additions & 1 deletion packages/core/src/redux/slices/__tests__/roomConnection.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ describe("roomConnectionSlice", () => {
const result = roomConnectionSlice.reducer(
undefined,
signalEvents.roomJoined({
error: "room_locked",
selfId: "selfId",
isLocked: false,
}),
Expand All @@ -39,6 +38,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,
Expand Down
12 changes: 10 additions & 2 deletions packages/core/src/redux/slices/roomConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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) {
Expand All @@ -74,6 +73,14 @@ export const roomConnectionSlice = createSlice({
};
}

if (error) {
return {
...state,
status: "disconnected",
error,
};
}

return {
...state,
status: "connected",
Expand Down Expand Up @@ -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
Expand Down
Loading