Class TwirpClient
Base class for LiveKit Twirp client services.
Provides a common implementation for making authenticated HTTP requests to LiveKit's Twirp-based services. This class handles JSON serialization of protobuf messages and authentication token management.
public abstract class TwirpClient
- Inheritance
-
TwirpClient
- Derived
- Inherited Members
Constructors
TwirpClient(HttpClient, ILogger, string, ILiveKitTokenService)
Initializes a new instance of the TwirpClient class.
protected TwirpClient(HttpClient httpClient, ILogger logger, string serviceName, ILiveKitTokenService tokenService)
Parameters
httpClientHttpClientThe HTTP client for making requests.
loggerILoggerThe logger for diagnostic messages.
serviceNamestringThe name of the Twirp service.
tokenServiceILiveKitTokenServiceThe LiveKit token service for authentication.
Methods
MakeRequestAsync<TResponse>(string, string?, IMessage?, CancellationToken)
Makes an authenticated HTTP request to a LiveKit Twirp service.
protected Task<TResponse> MakeRequestAsync<TResponse>(string methodName, string? roomName, IMessage? requestBody, CancellationToken cancellationToken = default) where TResponse : IMessage<TResponse>, new()
Parameters
methodNamestringThe name of the Twirp method to call.
roomNamestringThe name of the room (optional, used to create server token).
requestBodyIMessageThe request body as a protobuf message.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<TResponse>
The response as a protobuf message.
Type Parameters
TResponseThe protobuf message type for the response.
Exceptions
- LiveKitApiException
Thrown when the server returns a non-success HTTP status code. Contains the parsed Twirp error code, message, and HTTP status code.