1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-26 14:59:22 +00:00

Handles join / leave events

This commit is contained in:
Pierre HUBERT 2020-04-20 14:24:35 +02:00
parent 9154fe47e1
commit 08d357fc72
4 changed files with 44 additions and 1 deletions

View File

@ -70,6 +70,22 @@ class DeletedConversationMessageEvent {
DeletedConversationMessageEvent(this.msg); DeletedConversationMessageEvent(this.msg);
} }
/// User joined call event
class UserJoinedCallEvent {
final int callID;
final int userID;
UserJoinedCallEvent(this.callID, this.userID);
}
/// User left call event
class UserLeftCallEvent {
final int callID;
final int userID;
UserLeftCallEvent(this.callID, this.userID);
}
class EventsHelper { class EventsHelper {
static EventBus _mgr = EventBus(); static EventBus _mgr = EventBus();

View File

@ -161,6 +161,18 @@ class WebSocketHelper {
ConversationsHelper.apiToConversationMessage(msg.data))); ConversationsHelper.apiToConversationMessage(msg.data)));
break; break;
// A user joined a call
case "user_joined_call":
EventsHelper.emit(
UserJoinedCallEvent(msg.data["callID"], msg.data["userID"]));
break;
// A user left a call
case "user_left_call":
EventsHelper.emit(
UserLeftCallEvent(msg.data["callID"], msg.data["userID"]));
break;
default: default:
throw Exception("Unknown message type: ${msg.title}"); throw Exception("Unknown message type: ${msg.title}");
} }

View File

@ -12,7 +12,7 @@ class CallMember {
const CallMember({ const CallMember({
@required this.id, @required this.id,
@required this.status, this.status = MemberStatus.JOINED,
}) : assert(id != null), }) : assert(id != null),
assert(status != null); assert(status != null);
} }

View File

@ -1,5 +1,6 @@
import 'package:comunic/helpers/calls_helper.dart'; import 'package:comunic/helpers/calls_helper.dart';
import 'package:comunic/helpers/conversations_helper.dart'; import 'package:comunic/helpers/conversations_helper.dart';
import 'package:comunic/helpers/events_helper.dart';
import 'package:comunic/helpers/users_helper.dart'; import 'package:comunic/helpers/users_helper.dart';
import 'package:comunic/lists/call_members_list.dart'; import 'package:comunic/lists/call_members_list.dart';
import 'package:comunic/lists/users_list.dart'; import 'package:comunic/lists/users_list.dart';
@ -78,6 +79,15 @@ class _CallScreenState extends SafeState<CallScreen> {
_membersList = membersList; _membersList = membersList;
setState(() {}); setState(() {});
// Register to events
this.listenChangeState<UserJoinedCallEvent>((e) {
if (e.callID == convID) _membersList.add(CallMember(id: e.userID));
});
this.listen<UserLeftCallEvent>((e) {
if (e.callID == convID) _removeMember(e.userID);
});
} catch (e, stack) { } catch (e, stack) {
print("Could not initialize call! $e\n$stack"); print("Could not initialize call! $e\n$stack");
setState(() => _error = true); setState(() => _error = true);
@ -93,6 +103,11 @@ class _CallScreenState extends SafeState<CallScreen> {
} }
} }
void _removeMember(int memberID) {
_membersList.removeUser(memberID);
setState(() {});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(