joinRoom method

  1. @override
Future<Meeting?> joinRoom({
  1. required Meeting meeting,
  2. required String password,
  3. required int? userId,
})
override

Implementation

@override
Future<Meeting?> joinRoom({
  required Meeting meeting,
  required String password,
  required int? userId,
}) async {
  if (!_webSocket.isConnected) return null;

  late final 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 != null) {
    final int mParticipantIndex = room.participants.lastIndexWhere(
      (participant) => participant.isMe,
    );

    if (mParticipantIndex < 0) return null;

    await _joinRoom(
      roomId: room.code.toString(),
      participantId: room.participants[mParticipantIndex].id,
    );

    final List<String> targetIds = room.participants
        .where((participant) => !participant.isMe)
        .map((participant) => participant.id.toString())
        .toList();

    _subscribe(targetIds);
  }

  return room;
}