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/managers/NotificationManager.tsx b/client/src/managers/NotificationManager.tsx
index 4154c33..dacc3c1 100644
--- a/client/src/managers/NotificationManager.tsx
+++ b/client/src/managers/NotificationManager.tsx
@@ -20,6 +20,7 @@
import { useNavigate } from 'react-router-dom';
import { useAuthContext } from '../contexts/AuthProvider';
+import { CallStatus } from '../contexts/CallProvider';
import { WebSocketContext } from '../contexts/WebSocketProvider';
import { WithChildren } from '../utils/utils';
@@ -38,7 +39,11 @@
const callBeginListener = (data: CallAction) => {
console.info('Received event on CallBegin', data);
- navigate(`/conversation/${data.conversationId}/call?role=receiver`);
+ navigate(`/conversation/${data.conversationId}/call?role=receiver`, {
+ state: {
+ callStatus: CallStatus.Ringing,
+ },
+ });
};
webSocket.bind(WebSocketMessageType.CallBegin, callBeginListener);