Skip to content

Commit

Permalink
Merge pull request #1836 from famedly/td/participantChangeStreams
Browse files Browse the repository at this point in the history
feat: add participant changed streams
  • Loading branch information
td-famedly authored May 30, 2024
2 parents 579546b + 2e1e3a4 commit 0330d9b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/matrix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export 'src/voip/models/call_events.dart';
export 'src/voip/models/webrtc_delegate.dart';
export 'src/voip/models/call_participant.dart';
export 'src/voip/models/key_provider.dart';
export 'src/voip/models/matrixrtc_call_event.dart';
export 'src/voip/utils/conn_tester.dart';
export 'src/voip/utils/voip_constants.dart';
export 'src/voip/utils/rtc_candidate_extension.dart';
Expand Down
7 changes: 7 additions & 0 deletions lib/src/voip/group_call_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class GroupCallSession {
final CachedStreamController<GroupCallStateChange> onGroupCallEvent =
CachedStreamController();

final CachedStreamController<MatrixRTCCallEvent> matrixRTCEventStream =
CachedStreamController();

Timer? _resendMemberStateEventTimer;

factory GroupCallSession.withAutoGenId(
Expand Down Expand Up @@ -254,6 +257,8 @@ class GroupCallSession {
await backend.onNewParticipant(this, nonLocalAnyJoined.toList());
}
_participants.addAll(anyJoined);
matrixRTCEventStream
.add(ParticipantsJoinEvent(participants: anyJoined.toList()));
}
if (anyLeft.isNotEmpty) {
final nonLocalAnyLeft = Set<CallParticipant>.from(anyLeft)
Expand All @@ -264,6 +269,8 @@ class GroupCallSession {
await backend.onLeftParticipant(this, nonLocalAnyLeft.toList());
}
_participants.removeAll(anyLeft);
matrixRTCEventStream
.add(ParticipantsLeftEvent(participants: anyLeft.toList()));
}

onGroupCallEvent.add(GroupCallStateChange.participantsChanged);
Expand Down
20 changes: 20 additions & 0 deletions lib/src/voip/models/matrixrtc_call_event.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:matrix/matrix.dart';

/// UNSTABLE API WARNING
/// The class herirachy is currently experimental and could have breaking changes
/// often.
sealed class MatrixRTCCallEvent {}

sealed class ParticipantsChangeEvent implements MatrixRTCCallEvent {}

final class ParticipantsJoinEvent implements ParticipantsChangeEvent {
final List<CallParticipant> participants;

ParticipantsJoinEvent({required this.participants});
}

final class ParticipantsLeftEvent implements ParticipantsChangeEvent {
final List<CallParticipant> participants;

ParticipantsLeftEvent({required this.participants});
}

0 comments on commit 0330d9b

Please sign in to comment.