joinMeeting method

  1. @override
Future<JitsiMeetingResponse> joinMeeting(
  1. JitsiMeetingOptions options, {
  2. JitsiMeetingListener? listener,
  3. Map<RoomNameConstraintType, RoomNameConstraint>? roomNameConstraints,
})
override

Joins a meeting based on the JitsiMeetingOptions passed in. A JitsiMeetingListener can be attached to this meeting that will automatically be removed when the meeting has ended

Implementation

@override
Future<JitsiMeetingResponse> joinMeeting(JitsiMeetingOptions options,
    {JitsiMeetingListener? listener,
    Map<RoomNameConstraintType, RoomNameConstraint>?
        roomNameConstraints}) async {
  // encode `options` Map to Json to avoid error
  // in interoperability conversions
  String webOptions = jsonEncode(options.webOptions);
  String serverURL = options.serverURL ?? "meet.jit.si";
  serverURL = serverURL.replaceAll(cleanDomain, "");
  api = jitsi.JitsiMeetAPI(serverURL, webOptions);

  // setup listeners
  if (listener != null) {
    listener.onOpened?.call();

    api?.on("chatUpdated", allowInterop((message) {
      Map<String, dynamic> data = {
        'isOpen': !kReleaseMode ? message.isOpen : false,
        'unreadCount': !kReleaseMode ? message.unreadCount : 0,
      };

      listener.onChatToggled?.call(
        parseBool(data["isOpen"]),
      );
    }));

    api?.on("incomingMessage", allowInterop((message) {
      Map<String, dynamic> data = {
        'senderId': !kReleaseMode ? message.from : '?',
        'nick': !kReleaseMode ? message.nick : '?',
        'isPrivate': !kReleaseMode ? message.privateMessage : false,
        'message': !kReleaseMode ? message.message : '?',
        'timestamp': DateTime.now().toUtc(),
      };

      listener.onChatMessageReceived?.call(
        data["senderId"]?.toString() ?? '?',
        data["message"]?.toString() ?? '?',
        parseBool(data["isPrivate"]),
        data["timestamp"].toString(),
      );
    }));

    api?.on("audioMuteStatusChanged", allowInterop((message) {
      Map<String, dynamic> data = {
        'muted': !kReleaseMode ? message.muted : false,
      };

      listener.onAudioMutedChanged?.call(
        parseBool(data["muted"]),
      );
    }));

    api?.on("videoMuteStatusChanged", allowInterop((message) {
      Map<String, dynamic> data = {
        'muted': !kReleaseMode ? message.muted : false,
      };

      listener.onVideoMutedChanged?.call(
        parseBool(data["muted"], isVideoMutedChanged: true),
      );
    }));

    api?.on("screenSharingStatusChanged", allowInterop((message) {
      Map<String, dynamic> data = {
        'sharing': !kReleaseMode ? message.on : false,
        'details': !kReleaseMode ? message.details : {},
        'participantId': !kReleaseMode ? message.id : '?',
      };

      listener.onScreenShareToggled?.call(
        data["participantId"]?.toString() ?? '?',
        parseBool(data["sharing"]),
      );
    }));

    api?.on("participantsInfoRetrieved", allowInterop((message) {
      Map<String, dynamic> data = {
        'participantsInfo': !kReleaseMode ? message.participantsInfo : {},
        'requestId': !kReleaseMode ? message.requestId : '?'
      };

      listener.onParticipantsInfoRetrieved?.call(
        data["participantsInfo"] ?? {},
        data["requestId"]?.toString() ?? '?',
      );
    }));

    api?.on("videoConferenceJoined", allowInterop((message) {
      Map<String, dynamic> data = {
        'url': !kReleaseMode ? message.roomName : '?',
        'id': !kReleaseMode ? message.id : '?',
        'displayName': !kReleaseMode ? message.displayName : '?',
        'avatarURL': !kReleaseMode ? message.avatarURL : '',
        'breakoutRoom': !kReleaseMode ? message.breakoutRoom : false,
      };

      listener.onConferenceJoined?.call(
        data["url"].toString(),
      );
    }));

    api?.on("videoConferenceLeft", allowInterop((message) {
      Map<String, dynamic> data = {
        'url': !kReleaseMode ? message.roomName : '?',
        'error': message?.error,
      };

      listener.onConferenceTerminated?.call(
        data["url"].toString(),
        data["error"],
      );

      listener.onClosed?.call();
    }));

    api?.on("participantJoined", allowInterop((message) {
      Map<String, dynamic> data = {
        'email': !kReleaseMode ? message.email : '?',
        'name': !kReleaseMode ? message.displayName : '?',
        'role': !kReleaseMode ? message.role : '?',
        'participantId': !kReleaseMode ? message.id : '?',
      };

      listener.onParticipantJoined?.call(
          data["email"]?.toString() ?? "?",
          data["name"]?.toString() ?? "?",
          data["role"]?.toString() ?? "?",
          data["participantId"]?.toString() ?? "?");
    }));

    api?.on("participantLeft", allowInterop((message) {
      Map<String, dynamic> data = {
        "participantId": !kReleaseMode ? message.id : '?',
      };

      listener.onParticipantLeft?.call(
        data["participantId"]?.toString() ?? "?",
      );
    }));

    api?.on("feedbackSubmitted", allowInterop((message) {
      Map<String, dynamic> data = {
        "error": !kReleaseMode ? message.error : '?',
      };

      listener.onError?.call(
        data["error"]?.toString() ?? "?",
      );
    }));

    // NOTE: `onConferenceWillJoin` is not supported or nof found event in web
    // add generic listener
    _addGenericListeners(listener);
    api?.on("readyToClose", allowInterop((message) {
      listener.onClosed?.call();
      api?.dispose();
    }));
  }

  return JitsiMeetingResponse(isSuccess: true);
}