Use turn/stun server

The webrtc connection now use the TURN and STUN config specified in the account to setup the ice servers.

GitLab: #11

Change-Id: I9c7eff51e3e6da3cab1c04b3a1be6c1501d5c94b
diff --git a/client/src/contexts/WebRtcProvider.tsx b/client/src/contexts/WebRtcProvider.tsx
index 3999259..a56efab 100644
--- a/client/src/contexts/WebRtcProvider.tsx
+++ b/client/src/contexts/WebRtcProvider.tsx
@@ -20,6 +20,7 @@
 import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
 
 import { WithChildren } from '../utils/utils';
+import { useAuthContext } from './AuthProvider';
 import { ConversationContext } from './ConversationProvider';
 import { WebSocketContext } from './WebSocketProvider';
 
@@ -42,6 +43,7 @@
 export const WebRtcContext = createContext<IWebRtcContext>(defaultWebRtcContext);
 
 export default ({ children }: WithChildren) => {
+  const { account } = useAuthContext();
   const webSocket = useContext(WebSocketContext);
   const { conversation } = useContext(ConversationContext);
   const [webRtcConnection, setWebRtcConnection] = useState<RTCPeerConnection | undefined>();
@@ -52,12 +54,26 @@
   const contactUri = useMemo(() => conversation.getFirstMember().contact.getUri(), [conversation]);
 
   useEffect(() => {
-    if (!webRtcConnection) {
-      // TODO: Use SFL iceServers
-      const iceConfig = { iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] };
-      setWebRtcConnection(new RTCPeerConnection(iceConfig));
+    if (!webRtcConnection && account) {
+      const iceServers: RTCIceServer[] = [];
+
+      if (account.getDetails()['TURN.enable'] === 'true') {
+        iceServers.push({
+          urls: 'turn:' + account.getDetails()['TURN.server'],
+          username: account.getDetails()['TURN.username'],
+          credential: account.getDetails()['TURN.password'],
+        });
+      }
+
+      if (account.getDetails()['STUN.enable'] === 'true') {
+        iceServers.push({
+          urls: 'stun:' + account.getDetails()['STUN.server'],
+        });
+      }
+
+      setWebRtcConnection(new RTCPeerConnection({ iceServers: iceServers }));
     }
-  }, [webRtcConnection]);
+  }, [account, webRtcConnection]);
 
   const sendWebRtcOffer = useCallback(
     async (sdp: RTCSessionDescriptionInit) => {