Skip to content

Commit

Permalink
fix: group call voipIds not considering backend, application and scope
Browse files Browse the repository at this point in the history
  • Loading branch information
td-famedly committed May 12, 2024
1 parent 9cc7c0e commit f010b51
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 24 deletions.
35 changes: 22 additions & 13 deletions lib/src/voip/models/voip_id.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
class VoipId {
final String roomId;
final String callId;
final String? callBackendType;
final String? application;
final String? scope;

String get id => '$roomId:$callId';

factory VoipId.fromId(String id) {
final int lastIndex = id.lastIndexOf(':');
return VoipId(
roomId: id.substring(0, lastIndex),
callId: id.substring(lastIndex + 1),
);
}

VoipId({required this.roomId, required this.callId});
VoipId({
required this.roomId,
required this.callId,
this.callBackendType,
this.application,
this.scope,
});

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is VoipId && roomId == other.roomId && callId == other.callId;
other is VoipId &&
roomId == other.roomId &&
callId == other.callId &&
callBackendType == other.callBackendType &&
application == other.application &&
scope == other.scope;

@override
int get hashCode => roomId.hashCode ^ callId.hashCode;
int get hashCode =>
roomId.hashCode ^
callId.hashCode ^
callBackendType.hashCode ^
application.hashCode ^
scope.hashCode;
}
11 changes: 11 additions & 0 deletions lib/src/voip/utils/famedly_call_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ extension FamedlyCallMemberEventsExtension on Room {
return mem ?? [];
}

/// returns a list of memberships in the room for `callParticipant`
List<CallMembership> getCallMembershipsForUserWithDeviceId(
CallParticipant callParticipant,
) {
final userMems = getCallMembershipsForUser(callParticipant.userId);
final mem = userMems
.where((element) => element.deviceId == callParticipant.deviceId)
.toList();
return mem;
}

/// returns the user count (not sessions, yet) for the group call with id: `groupCallId`.
/// returns 0 if group call not found
int groupCallParticipantCount(String groupCallId) {
Expand Down
22 changes: 11 additions & 11 deletions lib/src/voip/voip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,6 @@ class VoIP {
String? application,
String? scope,
) async {
if (getGroupCallById(room.id, groupCallId) != null) {
Logs().v('[VOIP] [$groupCallId] already exists.');
return getGroupCallById(room.id, groupCallId)!;
}

final groupCall = GroupCallSession(
groupCallId: groupCallId,
client: client,
Expand Down Expand Up @@ -764,14 +759,21 @@ class VoIP {
String? application,
String? scope,
) async {
final groupCall = getGroupCallById(room.id, groupCallId);
final existingGroupCall = getGroupCallById(VoipId(
roomId: room.id,
callId: groupCallId,
callBackendType: backend.type,
application: application,
scope: scope,
));

if (groupCall != null) {
if (existingGroupCall != null) {
if (!room.canJoinGroupCall) {
throw Exception(
'User is not allowed to join famedly calls in the room');
}
return groupCall;
Logs().v('[VOIP] [$groupCallId] already exists.');
return existingGroupCall;
}

if (!room.groupCallsEnabledForEveryone) {
Expand All @@ -788,9 +790,7 @@ class VoIP {
);
}

GroupCallSession? getGroupCallById(String roomId, String groupCallId) {
return groupCalls[VoipId(roomId: roomId, callId: groupCallId)];
}
GroupCallSession? getGroupCallById(VoipId voipId) => groupCalls[voipId];

void setGroupCallById(GroupCallSession groupCallSession) {
groupCalls[VoipId(
Expand Down

0 comments on commit f010b51

Please sign in to comment.