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

172 lines
3.5 KiB
Dart
Raw Normal View History

2020-04-18 11:48:21 +00:00
import 'dart:async';
2020-04-18 14:35:53 +00:00
import 'package:comunic/models/comment.dart';
2020-04-19 11:58:24 +00:00
import 'package:comunic/models/conversation_message.dart';
2020-04-18 11:48:21 +00:00
import 'package:event_bus/event_bus.dart';
2021-02-07 16:09:08 +00:00
import 'package:flutter_webrtc/flutter_webrtc.dart';
2020-04-18 11:48:21 +00:00
/// Events helper
///
/// @author Pierre Hubert
/// Invalid login token
class InvalidLoginTokensEvent {}
2020-04-18 11:48:21 +00:00
/// Main WebSocket closed
class WSClosedEvent {}
/// New number of notifications
class NewNumberNotifsEvent {
final int? newNum;
NewNumberNotifsEvent(this.newNum);
}
/// New number of unread conversations
class NewNumberUnreadConversations {
final int? newNum;
NewNumberUnreadConversations(this.newNum);
}
2020-04-18 14:35:53 +00:00
/// New comment
class NewCommentEvent {
final Comment comment;
NewCommentEvent(this.comment);
}
2020-04-18 14:46:55 +00:00
/// Updated comment
class UpdatedCommentEvent {
final Comment comment;
UpdatedCommentEvent(this.comment);
}
2020-04-18 14:57:00 +00:00
/// Deleted comment
class DeletedCommentEvent {
final int? commentID;
2020-04-18 14:57:00 +00:00
DeletedCommentEvent(this.commentID);
}
2021-03-13 08:29:54 +00:00
/// Writing message in conversation event
class WritingMessageInConversationEvent {
final int? convID;
final int? userID;
2021-03-13 08:29:54 +00:00
WritingMessageInConversationEvent(this.convID, this.userID);
}
2020-04-19 11:58:24 +00:00
/// New conversation message
class NewConversationMessageEvent {
final ConversationMessage msg;
NewConversationMessageEvent(this.msg);
}
2020-04-19 12:16:35 +00:00
/// Updated conversation message
class UpdatedConversationMessageEvent {
final ConversationMessage msg;
UpdatedConversationMessageEvent(this.msg);
}
2020-04-19 12:29:01 +00:00
/// Deleted conversation message
class DeletedConversationMessageEvent {
final ConversationMessage msg;
DeletedConversationMessageEvent(this.msg);
}
2020-04-18 14:57:00 +00:00
/// Remove user from conversation
2021-03-13 12:52:18 +00:00
class RemovedUserFromConversationEvent {
final int? convID;
final int? userID;
2021-03-13 12:52:18 +00:00
RemovedUserFromConversationEvent(this.convID, this.userID);
}
/// Deleted conversation
class DeletedConversationEvent {
final int? convID;
2021-03-13 12:52:18 +00:00
DeletedConversationEvent(this.convID);
}
2020-04-20 12:24:35 +00:00
/// User joined call event
class UserJoinedCallEvent {
final int? callID;
final int? userID;
2020-04-20 12:24:35 +00:00
UserJoinedCallEvent(this.callID, this.userID);
}
/// User left call event
class UserLeftCallEvent {
final int? callID;
final int? userID;
2020-04-20 12:24:35 +00:00
UserLeftCallEvent(this.callID, this.userID);
}
2020-04-20 14:23:33 +00:00
/// New call signal event
class NewCallSignalEvent {
final int callID;
final int peerID;
final RTCSessionDescription? sessionDescription;
final RTCIceCandidate? candidate;
2020-04-20 14:23:33 +00:00
const NewCallSignalEvent({
required this.callID,
required this.peerID,
2020-04-20 14:23:33 +00:00
this.sessionDescription,
this.candidate,
2022-03-11 15:27:01 +00:00
}) : assert(sessionDescription != null || candidate != null);
2020-04-20 14:23:33 +00:00
}
/// Call peer ready event
class CallPeerReadyEvent {
final int? callID;
final int? peerID;
CallPeerReadyEvent(this.callID, this.peerID);
}
/// Call peer interrupted streaming event
class CallPeerInterruptedStreamingEvent {
final int? callID;
final int? peerID;
CallPeerInterruptedStreamingEvent(this.callID, this.peerID);
}
2020-04-20 12:32:57 +00:00
/// Call closed event
class CallClosedEvent {
final int? callID;
2020-04-20 12:32:57 +00:00
CallClosedEvent(this.callID);
}
2020-04-18 11:48:21 +00:00
class EventsHelper {
static EventBus _mgr = EventBus();
/// Listen to event
///
/// Do not use this method directly. You should instead prefer to use
/// [SafeState.listen] to handle safely widgets lifecycle...
///
/// You can not register to global events
static StreamSubscription<T> on<T>(void onData(T event)) {
if (T == dynamic) throw Exception("Do not register to all events!");
final stream = _mgr.on<T>();
return stream.listen(onData);
}
/// Propagate an event
static void emit<T>(T event) {
_mgr.fire(event);
}
}