End call when connection is lost
- Automatically end call when WebRTC connection is lost
- Remove state when in call
GitLab: 182
Change-Id: I259eccda82db7304542bef863c429c9313b4145a
diff --git a/client/src/contexts/WebRtcProvider.tsx b/client/src/contexts/WebRtcProvider.tsx
index 397bd83..63e2ca2 100644
--- a/client/src/contexts/WebRtcProvider.tsx
+++ b/client/src/contexts/WebRtcProvider.tsx
@@ -26,7 +26,7 @@
import { IWebSocketContext, WebSocketContext } from './WebSocketProvider';
interface IWebRtcContext {
- isConnected: boolean;
+ iceConnectionState: RTCIceConnectionState | undefined;
remoteStreams: readonly MediaStream[] | undefined;
webRtcConnection: RTCPeerConnection | undefined;
@@ -35,7 +35,7 @@
}
const defaultWebRtcContext: IWebRtcContext = {
- isConnected: false,
+ iceConnectionState: undefined,
remoteStreams: undefined,
webRtcConnection: undefined,
sendWebRtcOffer: async () => {},
@@ -91,7 +91,7 @@
}) => {
const { conversation, conversationId } = useContext(ConversationContext);
const [remoteStreams, setRemoteStreams] = useState<readonly MediaStream[]>();
- const [isConnected, setIsConnected] = useState(false);
+ const [iceConnectionState, setIceConnectionState] = useState<RTCIceConnectionState | undefined>();
// TODO: This logic will have to change to support multiple people in a call
const contactUri = useMemo(() => conversation.getFirstMember().contact.getUri(), [conversation]);
@@ -208,11 +208,9 @@
setRemoteStreams(event.streams);
};
- const iceConnectionStateChangeEventListener = (event: Event) => {
- console.info(`Received WebRTC event on iceconnectionstatechange: ${webRtcConnection.iceConnectionState}`, event);
- setIsConnected(
- webRtcConnection.iceConnectionState === 'connected' || webRtcConnection.iceConnectionState === 'completed'
- );
+ const iceConnectionStateChangeEventListener = () => {
+ console.info('ICE connection state changed:', webRtcConnection.iceConnectionState);
+ setIceConnectionState(webRtcConnection.iceConnectionState);
};
webRtcConnection.addEventListener('track', trackEventListener);
@@ -227,7 +225,7 @@
return (
<WebRtcContext.Provider
value={{
- isConnected,
+ iceConnectionState,
remoteStreams,
webRtcConnection,
sendWebRtcOffer,