participantToken function

ParticipantToken participantToken({
  1. required String participantName,
  2. required String roomName,
  3. String? role,
})

Create a participant token, requires environment variables to be set.

Implementation

ParticipantToken participantToken({required String participantName, required String roomName, String? role}) {
  final projectId = String.fromEnvironment('MESHAGENT_PROJECT_ID', defaultValue: "");
  final keyId = String.fromEnvironment('MESHAGENT_KEY_ID', defaultValue: "");

  if (projectId.isEmpty) {
    throw Exception('MESHAGENT_PROJECT_ID must be set. You can find this value in Meshagent Studio under API keys.');
  }

  if (keyId.isEmpty) {
    throw Exception('MESHAGENT_KEY_ID must be set. You can find this value in Meshagent Studio under API keys.');
  }

  final token = ParticipantToken(name: participantName, projectId: projectId, apiKeyId: keyId);

  token.addRoomGrant(roomName);

  if (role != null) {
    token.addRoleGrant(role);
  }

  return token;
}