joinRoom method
Implementation
@override
Future<Result<Meeting>> joinRoom({
required Meeting meeting,
required String password,
required int? userId,
}) async {
if (!_webSocket.isConnected) return Result.failure(ServerFailure());
late final Result<Meeting> room;
if (password.isEmpty) {
room = await _meetingRepository.joinMeetingWithoutPassword(
CreateMeetingParams(
meeting: meeting,
password: password,
userId: userId,
),
);
} else {
room = await _meetingRepository.joinMeetingWithPassword(
CreateMeetingParams(
meeting: meeting,
password: password,
userId: userId,
),
);
}
if (room.isSuccess) {
final Meeting? meeting = room.value;
if (meeting == null) return Result.failure(room.error ?? ServerFailure());
final int mParticipantIndex = meeting.participants.lastIndexWhere(
(participant) => participant.isMe,
);
if (mParticipantIndex < 0) return Result.failure(ServerFailure());
await _joinRoom(
roomId: meeting.code.toString(),
participantId: meeting.participants[mParticipantIndex].id,
);
final List<String> targetIds = meeting.participants
.where((participant) => !participant.isMe)
.map((participant) => participant.id.toString())
.toList();
_subscribe(targetIds);
return Result.success(meeting);
} else {
return Result.failure(room.error ?? ServerFailure());
}
}