Table of Contents

Class TwirpClient

Namespace
LiveKit.Services
Assembly
LiveKit.AspNetCore.ServerSdk.dll

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

httpClient HttpClient

The HTTP client for making requests.

logger ILogger

The logger for diagnostic messages.

serviceName string

The name of the Twirp service.

tokenService ILiveKitTokenService

The 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

methodName string

The name of the Twirp method to call.

roomName string

The name of the room (optional, used to create server token).

requestBody IMessage

The request body as a protobuf message.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<TResponse>

The response as a protobuf message.

Type Parameters

TResponse

The 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.