CreateRealtimeClientSecretResponse.fromJson constructor
CreateRealtimeClientSecretResponse.fromJson(
- Map<String, dynamic> j
)
Implementation
factory CreateRealtimeClientSecretResponse.fromJson(Map<String, dynamic> j) {
// Be lenient: support both top-level {value, expires_at} and nested {client_secret:{…}}
final String? value = (j['value'] as String?) ?? (j['client_secret'] is Map ? (j['client_secret']['value'] as String?) : null);
final int? expiresAt = (j['expires_at'] as int?) ?? (j['client_secret'] is Map ? (j['client_secret']['expires_at'] as int?) : null);
if (value == null || expiresAt == null) {
throw FormatException('Unexpected client secret response: missing value/expires_at.');
}
final sessionJson = j['session'];
if (sessionJson is! Map<String, dynamic>) {
throw FormatException('Unexpected client secret response: missing session.');
}
return CreateRealtimeClientSecretResponse(
value: value,
expiresAt: expiresAt,
session: RealtimeSession.fromJson(sessionJson),
);
}