1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-10-23 06:53:23 +00:00

Get calls configuration

This commit is contained in:
Pierre HUBERT 2020-04-20 13:43:17 +02:00
parent 391d3150dd
commit 04693cc163
3 changed files with 29 additions and 2 deletions

View File

@ -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<void> join(int convID) async =>
ws("calls/join", {"convID": convID});
await ws("calls/join", {"convID": convID});
/// Leave a call
static Future<void> leave(int convID) async =>
ws("calls/leave", {"convID": convID});
await ws("calls/leave", {"convID": convID});
/// Get calls configuration
static Future<CallConfig> getConfig() async {
final response = await ws("calls/config", {});
return CallConfig(
iceServers: response["iceServers"].cast<String>(),
);
}
}

View File

@ -0,0 +1,13 @@
import 'package:flutter/material.dart';
/// Call configuration
///
/// @author Pierre Hubert
class CallConfig {
final List<String> iceServers;
const CallConfig({
@required this.iceServers,
}) : assert(iceServers != null);
}

View File

@ -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<CallScreen> {
// State properties
Conversation _conversation;
String _convName;
CallConfig _conf;
var _error = false;
@override
@ -58,6 +60,9 @@ class _CallScreenState extends SafeState<CallScreen> {
// 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);