connect method

void connect()

Implementation

void connect() async {
  print("Connect....");
  connectionState = ConnectionState.connecting;
  notifyListeners();

  try {
    // Generate random room and participant names
    // In a real app, you'd likely use meaningful names
    final roomName = 'room-${(1000 + DateTime.now().millisecondsSinceEpoch % 9000)}';
    final participantName = 'user-${(1000 + DateTime.now().millisecondsSinceEpoch % 9000)}';

    // Get connection details from token service
    final connectionDetails = await tokenService.fetchConnectionDetails(
      roomName: roomName,
      participantName: participantName,
    );

    print("Fetched Connection Details: $connectionDetails, connecting to room...");

    await room.connect(
      connectionDetails.serverUrl,
      connectionDetails.participantToken,
    );

    print("Connected to room");

    await room.localParticipant?.setMicrophoneEnabled(true);

    print("Microphone enabled");

    connectionState = ConnectionState.connected;
    appScreenState = AppScreenState.agent;
    notifyListeners();
  } catch (error) {
    print('Connection error: $error');

    connectionState = ConnectionState.disconnected;
    appScreenState = AppScreenState.welcome;
    notifyListeners();
  }
}