diff --git a/lib/helpers/calls_helper.dart b/lib/helpers/calls_helper.dart index 24270e5..b9dcc98 100644 --- a/lib/helpers/calls_helper.dart +++ b/lib/helpers/calls_helper.dart @@ -4,6 +4,7 @@ import 'package:comunic/helpers/websocket_helper.dart'; import 'package:comunic/lists/call_members_list.dart'; import 'package:comunic/models/call_config.dart'; import 'package:comunic/models/call_member.dart'; +import 'package:flutter_webrtc/rtc_ice_candidate.dart'; import 'package:flutter_webrtc/rtc_session_description.dart'; /// Calls helper @@ -51,4 +52,14 @@ class CallsHelper { "type": "SDP", "data": jsonEncode(sdp.toMap()) }); + + /// Send an IceCandidate + static Future sendIceCandidate( + int callID, int peerID, RTCIceCandidate candidate) async => + await ws("calls/signal", { + "callID": callID, + "peerID": peerID, + "type": "CANDIDATE", + "data": jsonEncode(candidate) + }); } diff --git a/lib/ui/screens/call_screen.dart b/lib/ui/screens/call_screen.dart index 538bfb6..6268d41 100644 --- a/lib/ui/screens/call_screen.dart +++ b/lib/ui/screens/call_screen.dart @@ -168,6 +168,10 @@ class _CallScreenState extends SafeState { _peersConnections[memberID] = peerConnection; + // Register callbacks + peerConnection.onIceCandidate = + (c) => CallsHelper.sendIceCandidate(convID, memberID, c); + // Request an offer to establish a peer connection await CallsHelper.requestOffer(convID, memberID); } catch (e, stack) {