1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 12:59:21 +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);
}
/// 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 {
static EventBus _mgr = EventBus();

View File

@ -161,6 +161,18 @@ class WebSocketHelper {
ConversationsHelper.apiToConversationMessage(msg.data)));
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:
throw Exception("Unknown message type: ${msg.title}");
}

View File

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

View File

@ -1,5 +1,6 @@
import 'package:comunic/helpers/calls_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/lists/call_members_list.dart';
import 'package:comunic/lists/users_list.dart';
@ -78,6 +79,15 @@ class _CallScreenState extends SafeState<CallScreen> {
_membersList = membersList;
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) {
print("Could not initialize call! $e\n$stack");
setState(() => _error = true);
@ -93,6 +103,11 @@ class _CallScreenState extends SafeState<CallScreen> {
}
}
void _removeMember(int memberID) {
_membersList.removeUser(memberID);
setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(