Redirect user from call page when not in call
When a user tries to access a call page while not in a call, redirect the user to the home page.
Misc changes:
- Add route state to the call route that includes the CallStatus.
- CallProvider redirects to home if the callStatus isn't set (meaning
the user isn't in a call).
- Remove `beginCall` function in `ConversationProvider`. Added `useStartCall` hook that redirects the user to the call page. The `CallProvider` automatically sends the `BeginCall` message when the user reaches the page for the first time.
- Reorder functions in CallProvider to have `useEffect` functions at the top
GitLab: #164
Change-Id: I6cec1b9f31cb308d92a69112f5b38d1bdf79e05f
diff --git a/client/src/router.tsx b/client/src/router.tsx
index 8e53188..5b6b71d 100644
--- a/client/src/router.tsx
+++ b/client/src/router.tsx
@@ -21,7 +21,7 @@
import ContactList from './components/ContactList';
import ConversationView from './components/ConversationView';
import AuthProvider from './contexts/AuthProvider';
-import CallProvider, { CallRole } from './contexts/CallProvider';
+import CallProvider, { CallRole, CallStatus } from './contexts/CallProvider';
import ConversationProvider from './contexts/ConversationProvider';
import WebRtcProvider from './contexts/WebRtcProvider';
import WebSocketProvider from './contexts/WebSocketProvider';
@@ -37,12 +37,17 @@
import { ThemeDemonstrator } from './themes/ThemeDemonstrator';
export type ConversationRouteParams = RouteParams<{ conversationId: string }, Record<string, never>>;
+
export type AddContactRouteParams = RouteParams<{ contactId: string }, Record<string, never>>;
-/**
- * Route parameters for the call routes.
- */
-export type CallRouteParams = RouteParams<{ conversationId: string }, { role?: CallRole }>;
+export type CallRouteParams = RouteParams<
+ { conversationId?: string },
+ { role?: CallRole },
+ {
+ isVideoOn?: boolean;
+ callStatus: CallStatus;
+ }
+>;
export const router = createBrowserRouter(
createRoutesFromElements(
@@ -64,7 +69,10 @@
>
<Route index element={<Messenger />} />
<Route path="conversation" element={<Messenger />}>
- <Route path="add-contact/:contactId" />
+ {/* TODO: Remove this route. Adding a contact should not change the route, we should instead use an internal
+ state in the Messenger component
+ */}
+ <Route path="add-contact" element={<div></div>} />
<Route
path=":conversationId"
element={