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) {