< Summary

Information
Class: Livekit.Server.Sdk.Dotnet.SipServiceClient
Assembly: LivekitApi
File(s): /home/runner/work/livekit-server-sdk-dotnet/livekit-server-sdk-dotnet/LivekitApi/SipServiceClient.cs
Line coverage
99%
Covered lines: 147
Uncovered lines: 1
Coverable lines: 148
Total lines: 319
Line coverage: 99.3%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ListSIPTrunk()100%11100%
CreateSIPInboundTrunk()100%11100%
CreateSIPOutboundTrunk()100%11100%
GetSIPInboundTrunk()100%11100%
GetSIPOutboundTrunk()100%11100%
ListSIPInboundTrunk()100%11100%
ListSIPOutboundTrunk()100%11100%
DeleteSIPTrunk()100%11100%
CreateSIPDispatchRule()100%11100%
ListSIPDispatchRule()100%11100%
DeleteSIPDispatchRule()100%11100%
CreateSIPParticipant()100%11100%
TransferSIPParticipant()100%1191.66%
UpdateSIPInboundTrunk()100%11100%
UpdateSIPOutboundTrunk()100%11100%
UpdateSIPDispatchRule()100%11100%

File(s)

/home/runner/work/livekit-server-sdk-dotnet/livekit-server-sdk-dotnet/LivekitApi/SipServiceClient.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 SIP service: inbound and outbound trunks, dispatch rules and SIP participants
 8    /// (outbound calls, transfers).
 9    /// </summary>
 10    public class SipServiceClient : 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 SipServiceClient(
 20            string host,
 21            string apiKey = null,
 22            string apiSecret = null,
 23            HttpClient client = null
 24        )
 5425            : base(host, apiKey, apiSecret, client) { }
 26
 27        /// <summary>
 28        /// Lists the legacy SIP trunks. Deprecated by LiveKit: use <see cref="ListSIPInboundTrunk"/> or
 29        /// <see cref="ListSIPOutboundTrunk"/>.
 30        /// </summary>
 31        /// <param name="request">Empty request.</param>
 32        /// <returns>The legacy trunks.</returns>
 33        [System.Obsolete(
 34            "This method is obsolete. Call ListSIPInboundTrunk or ListSIPOutboundTrunk instead.",
 35            false
 36        )]
 37        public async Task<ListSIPTrunkResponse> ListSIPTrunk(ListSIPTrunkRequest request)
 138        {
 139            return await SendAsync(
 140                    Twirp.Routes.SIP.ListSIPTrunk,
 141                    request,
 142                    ListSIPTrunkResponse.Parser,
 143                    AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true })
 144                )
 145                .ConfigureAwait(false);
 146        }
 47
 48        /// <summary>
 49        /// Creates a SIP inbound trunk.
 50        /// </summary>
 51        /// <param name="request">Trunk to create: name, numbers, allowed addresses and numbers, authentication, media o
 52        /// <returns>The created trunk.</returns>
 53        public async Task<SIPInboundTrunkInfo> CreateSIPInboundTrunk(
 54            CreateSIPInboundTrunkRequest request
 55        )
 556        {
 557            return await SendAsync(
 558                    Twirp.Routes.SIP.CreateSIPInboundTrunk,
 559                    request,
 560                    SIPInboundTrunkInfo.Parser,
 561                    AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true })
 562                )
 563                .ConfigureAwait(false);
 464        }
 65
 66        /// <summary>
 67        /// Creates a SIP outbound trunk.
 68        /// </summary>
 69        /// <param name="request">Trunk to create: name, SIP address, numbers, authentication, media options.</param>
 70        /// <returns>The created trunk.</returns>
 71        public async Task<SIPOutboundTrunkInfo> CreateSIPOutboundTrunk(
 72            CreateSIPOutboundTrunkRequest request
 73        )
 874        {
 875            return await SendAsync(
 876                    Twirp.Routes.SIP.CreateSIPOutboundTrunk,
 877                    request,
 878                    SIPOutboundTrunkInfo.Parser,
 879                    AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true })
 880                )
 881                .ConfigureAwait(false);
 582        }
 83
 84        /// <summary>
 85        /// Gets a SIP inbound trunk by ID.
 86        /// </summary>
 87        /// <param name="request">Trunk ID.</param>
 88        /// <returns>The trunk.</returns>
 89        public async Task<GetSIPInboundTrunkResponse> GetSIPInboundTrunk(
 90            GetSIPInboundTrunkRequest request
 91        )
 192        {
 193            return await SendAsync(
 194                    Twirp.Routes.SIP.GetSIPInboundTrunk,
 195                    request,
 196                    GetSIPInboundTrunkResponse.Parser,
 197                    AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true })
 198                )
 199                .ConfigureAwait(false);
 1100        }
 101
 102        /// <summary>
 103        /// Gets a SIP outbound trunk by ID.
 104        /// </summary>
 105        /// <param name="request">Trunk ID.</param>
 106        /// <returns>The trunk.</returns>
 107        public async Task<GetSIPOutboundTrunkResponse> GetSIPOutboundTrunk(
 108            GetSIPOutboundTrunkRequest request
 109        )
 1110        {
 1111            return await SendAsync(
 1112                    Twirp.Routes.SIP.GetSIPOutboundTrunk,
 1113                    request,
 1114                    GetSIPOutboundTrunkResponse.Parser,
 1115                    AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true })
 1116                )
 1117                .ConfigureAwait(false);
 1118        }
 119
 120        /// <summary>
 121        /// Lists the SIP inbound trunks.
 122        /// </summary>
 123        /// <param name="request">Optional filters: trunk IDs, numbers, page.</param>
 124        /// <returns>The matching trunks.</returns>
 125        public async Task<ListSIPInboundTrunkResponse> ListSIPInboundTrunk(
 126            ListSIPInboundTrunkRequest request
 127        )
 4128        {
 4129            return await SendAsync(
 4130                    Twirp.Routes.SIP.ListSIPInboundTrunk,
 4131                    request,
 4132                    ListSIPInboundTrunkResponse.Parser,
 4133                    AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true })
 4134                )
 4135                .ConfigureAwait(false);
 4136        }
 137
 138        /// <summary>
 139        /// Lists the SIP outbound trunks.
 140        /// </summary>
 141        /// <param name="request">Optional filters: trunk IDs, numbers, page.</param>
 142        /// <returns>The matching trunks.</returns>
 143        public async Task<ListSIPOutboundTrunkResponse> ListSIPOutboundTrunk(
 144            ListSIPOutboundTrunkRequest request
 145        )
 1146        {
 1147            return await SendAsync(
 1148                    Twirp.Routes.SIP.ListSIPOutboundTrunk,
 1149                    request,
 1150                    ListSIPOutboundTrunkResponse.Parser,
 1151                    AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true })
 1152                )
 1153                .ConfigureAwait(false);
 1154        }
 155
 156        /// <summary>
 157        /// Deletes a SIP trunk.
 158        /// </summary>
 159        /// <param name="request">Trunk ID.</param>
 160        /// <returns>The deleted trunk.</returns>
 161        public async Task<SIPTrunkInfo> DeleteSIPTrunk(DeleteSIPTrunkRequest request)
 1162        {
 1163            return await SendAsync(
 1164                    Twirp.Routes.SIP.DeleteSIPTrunk,
 1165                    request,
 1166                    SIPTrunkInfo.Parser,
 1167                    AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true })
 1168                )
 1169                .ConfigureAwait(false);
 1170        }
 171
 172        /// <summary>
 173        /// Creates a SIP dispatch rule, which decides the room an inbound call joins.
 174        /// </summary>
 175        /// <param name="request">Rule to create: the trunks it applies to, how calls are dispatched (a shared room or o
 176        /// <returns>The created rule.</returns>
 177        public async Task<SIPDispatchRuleInfo> CreateSIPDispatchRule(
 178            CreateSIPDispatchRuleRequest request
 179        )
 2180        {
 2181            return await SendAsync(
 2182                    Twirp.Routes.SIP.CreateSIPDispatchRule,
 2183                    request,
 2184                    SIPDispatchRuleInfo.Parser,
 2185                    AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true })
 2186                )
 2187                .ConfigureAwait(false);
 2188        }
 189
 190        /// <summary>
 191        /// Lists the SIP dispatch rules, optionally filtered.
 192        /// </summary>
 193        /// <param name="request">Optional filters: rule IDs, trunk IDs, page.</param>
 194        /// <returns>The matching rules.</returns>
 195        public async Task<ListSIPDispatchRuleResponse> ListSIPDispatchRule(
 196            ListSIPDispatchRuleRequest request
 197        )
 3198        {
 3199            return await SendAsync(
 3200                    Twirp.Routes.SIP.ListSIPDispatchRule,
 3201                    request,
 3202                    ListSIPDispatchRuleResponse.Parser,
 3203                    AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true })
 3204                )
 3205                .ConfigureAwait(false);
 3206        }
 207
 208        /// <summary>
 209        /// Deletes a SIP dispatch rule.
 210        /// </summary>
 211        /// <param name="request">Rule ID.</param>
 212        /// <returns>The deleted rule.</returns>
 213        public async Task<SIPDispatchRuleInfo> DeleteSIPDispatchRule(
 214            DeleteSIPDispatchRuleRequest request
 215        )
 1216        {
 1217            return await SendAsync(
 1218                    Twirp.Routes.SIP.DeleteSIPDispatchRule,
 1219                    request,
 1220                    SIPDispatchRuleInfo.Parser,
 1221                    AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true })
 1222                )
 1223                .ConfigureAwait(false);
 1224        }
 225
 226        /// <summary>
 227        /// Places an outbound call through a SIP trunk and adds the callee to a room as a SIP participant.
 228        /// </summary>
 229        /// <param name="request">Outbound call to place: trunk ID, number to call, room and participant identity, DTMF 
 230        /// <returns>The SIP participant placing the call.</returns>
 231        public async Task<SIPParticipantInfo> CreateSIPParticipant(
 232            CreateSIPParticipantRequest request
 233        )
 6234        {
 6235            return await SendAsync(
 6236                    Twirp.Routes.SIP.CreateSIPParticipant,
 6237                    request,
 6238                    SIPParticipantInfo.Parser,
 6239                    AuthHeader(new VideoGrants { }, new SIPGrants { Call = true })
 6240                )
 6241                .ConfigureAwait(false);
 2242        }
 243
 244        /// <summary>
 245        /// Transfers the call of a SIP participant to another phone number or SIP URI, with a SIP REFER.
 246        /// </summary>
 247        /// <param name="request">Room name, participant identity and the number or SIP URI to transfer the call to.</pa
 248        /// <returns>The outcome of the transfer.</returns>
 249        public async Task<TransferSIPParticipantResponse> TransferSIPParticipant(
 250            TransferSIPParticipantRequest request
 251        )
 4252        {
 4253            return await SendAsync(
 4254                    Twirp.Routes.SIP.TransferSIPParticipant,
 4255                    request,
 4256                    TransferSIPParticipantResponse.Parser,
 4257                    AuthHeader(
 4258                        new VideoGrants { RoomAdmin = true, Room = request.RoomName },
 4259                        new SIPGrants { Call = true }
 4260                    )
 4261                )
 4262                .ConfigureAwait(false);
 0263        }
 264
 265        /// <summary>
 266        /// Updates an existing SIP inbound trunk.
 267        /// </summary>
 268        /// <param name="request">Trunk ID and the fields to change, or a full replacement.</param>
 269        /// <returns>The updated trunk.</returns>
 270        public async Task<SIPInboundTrunkInfo> UpdateSIPInboundTrunk(
 271            UpdateSIPInboundTrunkRequest request
 272        )
 1273        {
 1274            return await SendAsync(
 1275                    Twirp.Routes.SIP.UpdateSIPInboundTrunk,
 1276                    request,
 1277                    SIPInboundTrunkInfo.Parser,
 1278                    AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true })
 1279                )
 1280                .ConfigureAwait(false);
 1281        }
 282
 283        /// <summary>
 284        /// Updates an existing SIP outbound trunk.
 285        /// </summary>
 286        /// <param name="request">Trunk ID and the fields to change, or a full replacement.</param>
 287        /// <returns>The updated trunk.</returns>
 288        public async Task<SIPOutboundTrunkInfo> UpdateSIPOutboundTrunk(
 289            UpdateSIPOutboundTrunkRequest request
 290        )
 1291        {
 1292            return await SendAsync(
 1293                    Twirp.Routes.SIP.UpdateSIPOutboundTrunk,
 1294                    request,
 1295                    SIPOutboundTrunkInfo.Parser,
 1296                    AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true })
 1297                )
 1298                .ConfigureAwait(false);
 1299        }
 300
 301        /// <summary>
 302        /// Updates an existing SIP dispatch rule.
 303        /// </summary>
 304        /// <param name="request">Rule ID and the fields to change, or a full replacement.</param>
 305        /// <returns>The updated rule.</returns>
 306        public async Task<SIPDispatchRuleInfo> UpdateSIPDispatchRule(
 307            UpdateSIPDispatchRuleRequest request
 308        )
 1309        {
 1310            return await SendAsync(
 1311                    Twirp.Routes.SIP.UpdateSIPDispatchRule,
 1312                    request,
 1313                    SIPDispatchRuleInfo.Parser,
 1314                    AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true })
 1315                )
 1316                .ConfigureAwait(false);
 1317        }
 318    }
 319}