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/contexts/ConversationProvider.tsx b/client/src/contexts/ConversationProvider.tsx
new file mode 100644
index 0000000..89fb450
--- /dev/null
+++ b/client/src/contexts/ConversationProvider.tsx
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2022 Savoir-faire Linux Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this program.  If not, see
+ * <https://www.gnu.org/licenses/>.
+ */
+import { Conversation, WebSocketMessageType } from 'jami-web-common';
+import { createContext, useCallback, useContext, useEffect, useState } from 'react';
+import { useNavigate } from 'react-router-dom';
+
+import LoadingPage from '../components/Loading';
+import { useUrlParams } from '../hooks/useUrlParams';
+import { ConversationRouteParams } from '../router';
+import { useConversationQuery } from '../services/Conversation';
+import { WithChildren } from '../utils/utils';
+import { useAuthContext } from './AuthProvider';
+import { WebSocketContext } from './WebSocketProvider';
+
+interface IConversationProvider {
+  conversationId: string;
+  conversation: Conversation;
+
+  beginCall: () => void;
+}
+
+export const ConversationContext = createContext<IConversationProvider>(undefined!);
+
+export default ({ children }: WithChildren) => {
+  const {
+    urlParams: { conversationId },
+  } = useUrlParams<ConversationRouteParams>();
+  const { account, accountId } = useAuthContext();
+  const webSocket = useContext(WebSocketContext);
+  const [isLoading, setIsLoading] = useState(false);
+  const [isError, setIsError] = useState(false);
+  const [conversation, setConversation] = useState<Conversation | undefined>();
+  const navigate = useNavigate();
+
+  const conversationQuery = useConversationQuery(conversationId);
+
+  useEffect(() => {
+    if (conversationQuery.isSuccess) {
+      const conversation = Conversation.from(accountId, conversationQuery.data);
+      setConversation(conversation);
+    }
+  }, [accountId, conversationQuery.isSuccess, conversationQuery.data]);
+
+  useEffect(() => {
+    setIsLoading(conversationQuery.isLoading);
+  }, [conversationQuery.isLoading]);
+
+  useEffect(() => {
+    setIsError(conversationQuery.isError);
+  }, [conversationQuery.isError]);
+
+  const beginCall = useCallback(() => {
+    if (!webSocket || !conversation) {
+      throw new Error('Could not begin call');
+    }
+
+    // TODO: Could we move this logic to the server? The client could make a single request with the conversationId, and the server is tasked with sending all the individual requests to the members of the conversation
+    for (const member of conversation.getMembers()) {
+      const callBegin = {
+        from: account.getId(),
+        to: member.contact.getUri(),
+        message: {
+          conversationId,
+        },
+      };
+
+      console.info('Sending CallBegin', callBegin);
+      webSocket.send(WebSocketMessageType.CallBegin, callBegin);
+    }
+
+    navigate(`/conversation/${conversationId}/call?role=caller`);
+  }, [conversationId, webSocket, conversation, account, navigate]);
+
+  useEffect(() => {
+    if (!conversation || !webSocket) {
+      return;
+    }
+    webSocket.send(WebSocketMessageType.ConversationView, { accountId, conversationId });
+  }, [accountId, conversation, conversationId, webSocket]);
+
+  if (isLoading) {
+    return <LoadingPage />;
+  }
+  if (isError || !conversation || !conversationId) {
+    return <div>Error loading conversation: {conversationId}</div>;
+  }
+
+  return (
+    <ConversationContext.Provider
+      value={{
+        conversationId,
+        conversation,
+        beginCall,
+      }}
+    >
+      {children}
+    </ConversationContext.Provider>
+  );
+};