Implement proper WebRTC call management

This is a big CR that implements the whole proper call logic.

-- Other Contributors --

This CR was created in pair programming with:

-  Charlie Duquette <charlie_duquette@hotmail.fr>

-- New files --

- `ConversationProvider`: Provides the conversation object to its children. Also contains the function to begin a call (first step in the flow) which sends the `BeginCall` event.
- `CallProvider`: Contains the call logic that was previously in WebRTCProvider. From now on, WebRTCProvider contains only the WebRTC logic, while CallProvider
  contains everything related to the call (get the media devices, start/accept calls...)
- `NotificationManager`: Wrapper component to bind the WebSocket CallBegin event listener. That listener will fire when a `BeginCall` event is received and will then redirect the user to the call receiving page.

-- New routes --

When a `conversationId` is included in the URL, all pages are inside a `<ConversationProvider />`.

When starting a call, the caller is redirected to:

> http://localhost:3000/conversation/:conversationId/call?role=caller

When receiving a call, the receiver is redirected to:

> http://localhost:3000/conversation/:conversationId/call?role=receiver&hostId={HOST_ID}

When the user is in a `.../call` route, the `WebRTCContext` and
`CallContext` are provided

The `hostId` is the account URI of the caller. It's used when the receiver wants to send their answer back to the caller.

```
/
|-- login: <Welcome />
|-- settings: <AccountSettings />
|-- ...
`-- conversation: <Messenger />
    |-- add-contact/:contactId
    `-- :conversationId: <ConversationProvider />
        |-- /: <ConversationView />
        `-- /call: <WebRTCProvider>
                     <CallProvider>
                       <CallInterface />
                     </CallProvider>
                    </WebRTCProvider>
```

-- Call flow --

1. Caller:

- Clicks "Call" button
- Sends `BeginCall` event
- Redirects to call page `/call?role=caller`
- Sets `callStatus` to "Ringing"

2. Receiver:

- Receieves `BeginCall` event
- The callback in `NotificationManager` is called
- Redirects to the call receiving page `/conversation/{CONVERSATION_ID}/call?role=receiver`

3. Receiver:

- Clicks the "Answer call" button
- Sends a `CallAccept` event
- Sets `callStatus` to "Connecting"

4. Caller:

- Receives `CallAccept` event
- The callback in `CallProvider` is called
- Sets `callStatus` to "Connecting"
- Creates WebRTC Offer
- Sends `WebRTCOffer` event containing the offer SDP

5. Receiver:

- Receives `WebRTCOffer` event
- The callback in `WebRTCProvider` is called
- Sets WebRTC remote description.
- WebRTC `icecandidate` event fired. Sends `IceCandidate` WebSocket event
- Creates WebRTC answer
- Sends `WebRTCAnswer` event
- Sets WebRTC local description
- Sets connected status to true. Call page now shows the call interface

6. Caller:

- Receives `WebRTCAnswer` event
- Sets WebRTC local description
- Sets WebRTC remote description
- WebRTC `icecandidate` event fired. Sends `IceCandidate` WebSocket event
- Sets connected status to true. Call page now shows the call interface

-- Misc Changes --

- Improve CallPending and CallInterface UI
- Move `useUrlParams` hook from the (now deleted) `client/src/utils/hooks.ts` file to `client/src/hooks/useUrlParams.ts`
- Disable StrictMode. This was causing issues, because some event would be sent twice. There is a TODO comment to fix the problem and reenable it.
- Improvements in server `webrtc-handler.ts`. This is still a WIP
- Rename dash-case client files to camelCase

GitLab: #70
Change-Id: I6c75f6b867e8acb9ccaaa118b0123bba30431f78
diff --git a/client/src/pages/CallInterface.tsx b/client/src/pages/CallInterface.tsx
index db1e19f..d49a367 100644
--- a/client/src/pages/CallInterface.tsx
+++ b/client/src/pages/CallInterface.tsx
@@ -15,13 +15,14 @@
  * License along with this program.  If not, see
  * <https://www.gnu.org/licenses/>.
  */
-import { Box, Button, Card, Grid, Stack, Typography } from '@mui/material';
+import { Box, Card, Grid, Stack, Typography } from '@mui/material';
 import {
   ComponentType,
   Fragment,
   ReactNode,
   useCallback,
   useContext,
+  useEffect,
   useLayoutEffect,
   useMemo,
   useRef,
@@ -43,19 +44,21 @@
   CallingVideoCameraButton,
   CallingVolumeButton,
 } from '../components/CallButtons';
-import WebRTCProvider, { WebRTCContext } from '../contexts/WebRTCProvider';
-import { CallRouteParams } from '../router';
-import { useUrlParams } from '../utils/hooks';
+import { CallContext, CallStatus } from '../contexts/CallProvider';
+import { CallPending } from './CallPending';
 
 export default () => {
-  const {
-    queryParams: { video },
-  } = useUrlParams<CallRouteParams>();
+  const { callRole, callStatus } = useContext(CallContext);
+
+  if (callStatus === CallStatus.InCall) {
+    return <CallInterface />;
+  }
   return (
-    //TODO: set contactID
-    <WebRTCProvider isVideoOn={video === 'true'} contactId={'contactIdToBeAdded'}>
-      <CallInterface />
-    </WebRTCProvider>
+    <CallPending
+      pending={callRole}
+      caller={callStatus === CallStatus.Ringing ? 'calling' : 'connecting'}
+      medium="audio"
+    />
   );
 };
 
@@ -64,8 +67,22 @@
 }
 
 const CallInterface = () => {
-  const { localVideoRef, remoteVideoRef, isVideoOn } = useContext(WebRTCContext);
+  const { isVideoOn, localStream, remoteStream } = useContext(CallContext);
   const gridItemRef = useRef(null);
+  const remoteVideoRef = useRef<HTMLVideoElement | null>(null);
+  const localVideoRef = useRef<HTMLVideoElement | null>(null);
+
+  useEffect(() => {
+    if (localStream && localVideoRef.current) {
+      localVideoRef.current.srcObject = localStream;
+    }
+  }, [localStream]);
+
+  useEffect(() => {
+    if (remoteStream && remoteVideoRef.current) {
+      remoteVideoRef.current.srcObject = remoteStream;
+    }
+  }, [remoteStream]);
 
   return (
     <>
@@ -73,7 +90,7 @@
       <video
         ref={remoteVideoRef}
         autoPlay
-        style={{ backgroundColor: 'black', width: '100%', height: '100%', position: 'absolute' }}
+        style={{ zIndex: -1, backgroundColor: 'black', width: '100%', height: '100%', position: 'absolute' }}
       />
       <Stack
         position="absolute"
@@ -88,24 +105,23 @@
         </Box>
         {/* Local video, with empty space to be moved around and stickied to walls */}
         <Box height="100%">
-          {isVideoOn && (
-            <Draggable bounds="parent" nodeRef={localVideoRef ?? undefined}>
-              <video
-                ref={localVideoRef}
-                autoPlay
-                style={{
-                  position: 'absolute',
-                  right: 0,
-                  zIndex: 2,
-                  borderRadius: '12px',
-                  minWidth: '25%',
-                  minHeight: '25%',
-                  maxWidth: '50%',
-                  maxHeight: '50%',
-                }}
-              />
-            </Draggable>
-          )}
+          <Draggable bounds="parent" nodeRef={localVideoRef ?? undefined}>
+            <video
+              ref={localVideoRef}
+              autoPlay
+              style={{
+                position: 'absolute',
+                right: 0,
+                zIndex: 2,
+                borderRadius: '12px',
+                minWidth: '25%',
+                minHeight: '25%',
+                maxWidth: '50%',
+                maxHeight: '50%',
+                visibility: isVideoOn ? 'visible' : 'hidden',
+              }}
+            />
+          </Draggable>
         </Box>
         {/* Bottom panel with calling buttons */}
         <Grid container>
@@ -138,21 +154,9 @@
 };
 
 const CallInterfacePrimaryButtons = () => {
-  const { sendWebRTCOffer } = useContext(WebRTCContext);
-
   return (
     <Card sx={{ backgroundColor: '#00000088', overflow: 'visible' }}>
       <Stack direction="row" justifyContent="center" alignItems="center">
-        <Button
-          variant="contained"
-          size="small"
-          onClick={() => {
-            sendWebRTCOffer();
-          }}
-        >
-          {/* TODO: Remove this button and make calling automatic (https://git.jami.net/savoirfairelinux/jami-web/-/issues/91)*/}
-          Call
-        </Button>
         <CallingMicButton />
         <CallingEndButton />
         <CallingVideoCameraButton />