From 04693cc16364c0512410ede5154f0431f74a4d12 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 20 Apr 2020 13:43:17 +0200 Subject: [PATCH] Get calls configuration --- lib/helpers/calls_helper.dart | 13 +++++++++++-- lib/models/call_config.dart | 13 +++++++++++++ lib/ui/screens/call_screen.dart | 5 +++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 lib/models/call_config.dart diff --git a/lib/helpers/calls_helper.dart b/lib/helpers/calls_helper.dart index 63847b3..f02e673 100644 --- a/lib/helpers/calls_helper.dart +++ b/lib/helpers/calls_helper.dart @@ -1,4 +1,5 @@ import 'package:comunic/helpers/websocket_helper.dart'; +import 'package:comunic/models/call_config.dart'; /// Calls helper /// @@ -7,9 +8,17 @@ import 'package:comunic/helpers/websocket_helper.dart'; class CallsHelper { /// Join a call static Future join(int convID) async => - ws("calls/join", {"convID": convID}); + await ws("calls/join", {"convID": convID}); /// Leave a call static Future leave(int convID) async => - ws("calls/leave", {"convID": convID}); + await ws("calls/leave", {"convID": convID}); + + /// Get calls configuration + static Future getConfig() async { + final response = await ws("calls/config", {}); + return CallConfig( + iceServers: response["iceServers"].cast(), + ); + } } diff --git a/lib/models/call_config.dart b/lib/models/call_config.dart new file mode 100644 index 0000000..b34eee7 --- /dev/null +++ b/lib/models/call_config.dart @@ -0,0 +1,13 @@ +import 'package:flutter/material.dart'; + +/// Call configuration +/// +/// @author Pierre Hubert + +class CallConfig { + final List iceServers; + + const CallConfig({ + @required this.iceServers, + }) : assert(iceServers != null); +} diff --git a/lib/ui/screens/call_screen.dart b/lib/ui/screens/call_screen.dart index e5c7903..44d7b87 100644 --- a/lib/ui/screens/call_screen.dart +++ b/lib/ui/screens/call_screen.dart @@ -1,5 +1,6 @@ import 'package:comunic/helpers/calls_helper.dart'; import 'package:comunic/helpers/conversations_helper.dart'; +import 'package:comunic/models/call_config.dart'; import 'package:comunic/models/conversation.dart'; import 'package:comunic/ui/widgets/comunic_back_button_widget.dart'; import 'package:comunic/ui/widgets/safe_state.dart'; @@ -30,6 +31,7 @@ class _CallScreenState extends SafeState { // State properties Conversation _conversation; String _convName; + CallConfig _conf; var _error = false; @override @@ -58,6 +60,9 @@ class _CallScreenState extends SafeState { // Join the call await CallsHelper.join(convID); + + // Get call configuration + _conf = await CallsHelper.getConfig(); } catch (e, stack) { print("Could not initialize call! $e\n$stack"); setState(() => _error = true);