participantToken function
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;
}