Change conversation during call
- Add `CallManagerProvider` to manage calls when the user navigates away from the call interface.
- Delete `NotificationManager`. Move its logic to `CallManagerProvider`.
- Rework routing
- Rework `ConversationProvider` and `useConversationQuery` to remove
unecessary states
GitLab: #172
Change-Id: I4a786a3dd52159680e5712e598d9b831525fb63f
diff --git a/client/src/contexts/WebRtcProvider.tsx b/client/src/contexts/WebRtcProvider.tsx
index b7733bc..bb99717 100644
--- a/client/src/contexts/WebRtcProvider.tsx
+++ b/client/src/contexts/WebRtcProvider.tsx
@@ -20,9 +20,10 @@
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
import LoadingPage from '../components/Loading';
+import { Conversation } from '../models/conversation';
import { WithChildren } from '../utils/utils';
import { useAuthContext } from './AuthProvider';
-import { useConversationContext } from './ConversationProvider';
+import { CallManagerContext } from './CallManagerProvider';
import { IWebSocketContext, WebSocketContext } from './WebSocketProvider';
export type MediaDevicesInfo = Record<MediaDeviceKind, MediaDeviceInfo[]>;
@@ -61,6 +62,7 @@
const { account } = useAuthContext();
const [webRtcConnection, setWebRtcConnection] = useState<RTCPeerConnection | undefined>();
const webSocket = useContext(WebSocketContext);
+ const { callConversation, callData } = useContext(CallManagerContext);
useEffect(() => {
if (!webRtcConnection && account) {
@@ -84,12 +86,17 @@
}
}, [account, webRtcConnection]);
- if (!webRtcConnection || !webSocket) {
+ if (!webRtcConnection || !webSocket || !callConversation || !callData?.conversationId) {
return <LoadingPage />;
}
return (
- <WebRtcProvider webRtcConnection={webRtcConnection} webSocket={webSocket}>
+ <WebRtcProvider
+ webRtcConnection={webRtcConnection}
+ webSocket={webSocket}
+ conversation={callConversation}
+ conversationId={callData.conversationId}
+ >
{children}
</WebRtcProvider>
);
@@ -97,13 +104,16 @@
const WebRtcProvider = ({
children,
+ conversation,
+ conversationId,
webRtcConnection,
webSocket,
}: WithChildren & {
webRtcConnection: RTCPeerConnection;
webSocket: IWebSocketContext;
+ conversation: Conversation;
+ conversationId: string;
}) => {
- const { conversation, conversationId } = useConversationContext();
const [localStream, setLocalStream] = useState<MediaStream>();
const [screenShareLocalStream, setScreenShareLocalStream] = useState<MediaStream>();
const [remoteStreams, setRemoteStreams] = useState<readonly MediaStream[]>();