Skip to content

Commit

Permalink
[FCE-925] Show connection error (#189)
Browse files Browse the repository at this point in the history
## Description

Show connection error to user, in case of incorrect URL.

## Motivation and Context

This is small change to help with debugging example app.

## Types of changes

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to
      not work as expected)
  • Loading branch information
mironiasty authored Dec 2, 2024
1 parent 83b7b48 commit 7427032
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
40 changes: 24 additions & 16 deletions examples/react-client/fishjam-chat/src/components/JoinRoomCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,38 @@ export const JoinRoomCard: FC<Props> = (props) => {
roomName,
peerName,
}: RoomForm) => {
const { url, peerToken } = await getRoomCredentials(
roomManagerUrl,
roomName,
peerName,
);
persistFormValues({ roomManagerUrl, roomName, peerName });
await joinRoom({
url,
peerToken,
peerMetadata: { displayName: peerName },
});

await Promise.all([
camera.startStreaming({ simulcast: false }),
mic.startStreaming({ simulcast: false }),
]);
try {
const { url, peerToken } = await getRoomCredentials(
roomManagerUrl,
roomName,
peerName,
);
persistFormValues({ roomManagerUrl, roomName, peerName });
await joinRoom({
url,
peerToken,
peerMetadata: { displayName: peerName },
});

await Promise.all([
camera.startStreaming({ simulcast: false }),
mic.startStreaming({ simulcast: false }),
]);
form.clearErrors();
} catch (e) {
form.setError("root", { message: (e as { message?: string })?.message });
}
};

const error = form.formState.errors.root?.message;

return (
<Card {...props}>
<form onSubmit={form.handleSubmit(onJoinRoom)}>
<CardHeader>
<CardTitle>Fishjam Chat</CardTitle>
<CardDescription>Fill out the form to join the call.</CardDescription>
{error && <CardFooter className="text-red-500">{error}</CardFooter>}
</CardHeader>

<CardContent>
Expand Down
9 changes: 6 additions & 3 deletions examples/react-client/fishjam-chat/src/lib/roomManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ export const getRoomCredentials = async (
roomName: string,
peerName: string,
) => {
const res = await axios.get<RoomManagerResponse>(roomManagerUrl, {
params: { peerName, roomName },
});
// remove duplicate get params (in case user will just copy params from UI)
const url = new URL(roomManagerUrl)!;
url.searchParams.set("roomName", roomName);
url.searchParams.set("peerName", peerName);

const res = await axios.get<RoomManagerResponse>(url.toString());

return res.data;
};

0 comments on commit 7427032

Please sign in to comment.