getSessionParticipantCounts method

Future<Map<String, num>> getSessionParticipantCounts(
  1. String projectId,
  2. String sessionId
)

Implementation

Future<Map<String, num>> getSessionParticipantCounts(String projectId, String sessionId) async {
  final encodedProjectId = Uri.encodeComponent(projectId);
  final encodedSessionId = Uri.encodeComponent(sessionId);
  final uri = Uri.parse('$baseUrl/accounts/projects/$encodedProjectId/sessions/$encodedSessionId/participants');
  final response = await httpClient.get(uri);

  if (response.statusCode >= 400) {
    throw MeshagentException(
      'Failed to get session participant counts. '
      'Status code: ${response.statusCode}, body: ${response.body}',
    );
  }
  final data = jsonDecode(response.body) as Map<String, dynamic>;
  final participants = data['participants'] as Map<String, dynamic>? ?? {};
  return {
    for (final entry in participants.entries)
      if (entry.value is num) entry.key: entry.value as num,
  };
}