< Summary

Information
Class: Livekit.Server.Sdk.Dotnet.AgentDispatchServiceClient
Assembly: LivekitApi
File(s): /home/runner/work/livekit-server-sdk-dotnet/livekit-server-sdk-dotnet/LivekitApi/AgentDispatchServiceClient.cs
Line coverage
100%
Covered lines: 34
Uncovered lines: 0
Coverable lines: 34
Total lines: 89
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
CreateDispatch()100%11100%
DeleteDispatch()100%11100%
ListDispatch()100%11100%
GetDispatch()100%22100%

File(s)

/home/runner/work/livekit-server-sdk-dotnet/livekit-server-sdk-dotnet/LivekitApi/AgentDispatchServiceClient.cs

#LineLine coverage
 1using System.Net.Http;
 2using System.Threading.Tasks;
 3
 4namespace Livekit.Server.Sdk.Dotnet
 5{
 6    /// <summary>
 7    /// Client of the LiveKit Agent Dispatch service: dispatches agents to rooms explicitly, lists and deletes
 8    /// those dispatches.
 9    /// </summary>
 10    public class AgentDispatchServiceClient : BaseService
 11    {
 12        /// <summary>
 13        /// Creates the client.
 14        /// </summary>
 15        /// <param name="host">URL of the LiveKit server, <c>http(s)://</c> or <c>ws(s)://</c>; a subpath such as <c>htt
 16        /// <param name="apiKey">API key; the <c>LIVEKIT_API_KEY</c> environment variable when omitted.</param>
 17        /// <param name="apiSecret">API secret; the <c>LIVEKIT_API_SECRET</c> environment variable when omitted.</param>
 18        /// <param name="client">Optional <see cref="HttpClient"/> to send the requests with. The SDK never modifies it,
 19        public AgentDispatchServiceClient(
 20            string host,
 21            string apiKey = null,
 22            string apiSecret = null,
 23            HttpClient client = null
 24        )
 1525            : base(host, apiKey, apiSecret, client) { }
 26
 27        /// <summary>
 28        /// Dispatches an agent to a room.
 29        /// </summary>
 30        /// <param name="request">Room, agent name and optional metadata for the agent.</param>
 31        /// <returns>The created dispatch.</returns>
 32        public async Task<AgentDispatch> CreateDispatch(CreateAgentDispatchRequest request)
 233        {
 234            return await SendAsync(
 235                    Twirp.Routes.AgentDispatchService.CreateDispatch,
 236                    request,
 237                    AgentDispatch.Parser,
 238                    AuthHeader(new VideoGrants { RoomAdmin = true, Room = request.Room })
 239                )
 240                .ConfigureAwait(false);
 241        }
 42
 43        /// <summary>
 44        /// Deletes an agent dispatch.
 45        /// </summary>
 46        /// <param name="request">Dispatch ID and room.</param>
 47        /// <returns>The deleted dispatch.</returns>
 48        public async Task<AgentDispatch> DeleteDispatch(DeleteAgentDispatchRequest request)
 249        {
 250            return await SendAsync(
 251                    Twirp.Routes.AgentDispatchService.DeleteDispatch,
 252                    request,
 253                    AgentDispatch.Parser,
 254                    AuthHeader(new VideoGrants { RoomAdmin = true, Room = request.Room })
 255                )
 256                .ConfigureAwait(false);
 257        }
 58
 59        /// <summary>
 60        /// Lists the agent dispatches of a room.
 61        /// </summary>
 62        /// <param name="request">Room name, and optionally a dispatch ID to match.</param>
 63        /// <returns>The dispatches of the room.</returns>
 64        public async Task<ListAgentDispatchResponse> ListDispatch(ListAgentDispatchRequest request)
 565        {
 566            return await SendAsync(
 567                    Twirp.Routes.AgentDispatchService.ListDispatch,
 568                    request,
 569                    ListAgentDispatchResponse.Parser,
 570                    AuthHeader(new VideoGrants { RoomAdmin = true, Room = request.Room })
 571                )
 572                .ConfigureAwait(false);
 573        }
 74
 75        /// <summary>
 76        /// Gets an agent dispatch by its ID, or null when it does not exist.
 77        /// </summary>
 78        /// <param name="dispatchId">ID of the dispatch.</param>
 79        /// <param name="roomName">Room the dispatch belongs to.</param>
 80        /// <returns>The dispatch, or null when the room has no dispatch with that ID.</returns>
 81        public async Task<AgentDispatch> GetDispatch(string dispatchId, string roomName)
 482        {
 483            var response = await ListDispatch(
 484                new ListAgentDispatchRequest { DispatchId = dispatchId, Room = roomName }
 485            );
 486            return response.AgentDispatches.Count > 0 ? response.AgentDispatches[0] : null;
 487        }
 88    }
 89}