From 391d3150dd86f6fdce2f48fab8a8cbf125c297be Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 20 Apr 2020 13:24:40 +0200 Subject: [PATCH] Can join & leave the call --- lib/helpers/calls_helper.dart | 15 +++++++++++++++ lib/ui/screens/call_screen.dart | 13 ++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 lib/helpers/calls_helper.dart diff --git a/lib/helpers/calls_helper.dart b/lib/helpers/calls_helper.dart new file mode 100644 index 0000000..63847b3 --- /dev/null +++ b/lib/helpers/calls_helper.dart @@ -0,0 +1,15 @@ +import 'package:comunic/helpers/websocket_helper.dart'; + +/// Calls helper +/// +/// @author Pierre Hubert + +class CallsHelper { + /// Join a call + static Future join(int convID) async => + ws("calls/join", {"convID": convID}); + + /// Leave a call + static Future leave(int convID) async => + ws("calls/leave", {"convID": convID}); +} diff --git a/lib/ui/screens/call_screen.dart b/lib/ui/screens/call_screen.dart index 14ddd4e..e5c7903 100644 --- a/lib/ui/screens/call_screen.dart +++ b/lib/ui/screens/call_screen.dart @@ -1,3 +1,4 @@ +import 'package:comunic/helpers/calls_helper.dart'; import 'package:comunic/helpers/conversations_helper.dart'; import 'package:comunic/models/conversation.dart'; import 'package:comunic/ui/widgets/comunic_back_button_widget.dart'; @@ -54,13 +55,23 @@ class _CallScreenState extends SafeState { assert(_convName != null); setState(() {}); + + // Join the call + await CallsHelper.join(convID); } catch (e, stack) { print("Could not initialize call! $e\n$stack"); setState(() => _error = true); } } - void _endCall() async {} + void _endCall() async { + try { + // Leave the call + await CallsHelper.leave(convID); + } catch (e, stack) { + print("Could not end call properly! $e\n$stack"); + } + } @override Widget build(BuildContext context) {