| | | 1 | | using System.Net.Http; |
| | | 2 | | using System.Threading.Tasks; |
| | | 3 | | |
| | | 4 | | namespace 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 | | ) |
| | 54 | 25 | | : 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) |
| | 1 | 38 | | { |
| | 1 | 39 | | return await SendAsync( |
| | 1 | 40 | | Twirp.Routes.SIP.ListSIPTrunk, |
| | 1 | 41 | | request, |
| | 1 | 42 | | ListSIPTrunkResponse.Parser, |
| | 1 | 43 | | AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true }) |
| | 1 | 44 | | ) |
| | 1 | 45 | | .ConfigureAwait(false); |
| | 1 | 46 | | } |
| | | 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 | | ) |
| | 5 | 56 | | { |
| | 5 | 57 | | return await SendAsync( |
| | 5 | 58 | | Twirp.Routes.SIP.CreateSIPInboundTrunk, |
| | 5 | 59 | | request, |
| | 5 | 60 | | SIPInboundTrunkInfo.Parser, |
| | 5 | 61 | | AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true }) |
| | 5 | 62 | | ) |
| | 5 | 63 | | .ConfigureAwait(false); |
| | 4 | 64 | | } |
| | | 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 | | ) |
| | 8 | 74 | | { |
| | 8 | 75 | | return await SendAsync( |
| | 8 | 76 | | Twirp.Routes.SIP.CreateSIPOutboundTrunk, |
| | 8 | 77 | | request, |
| | 8 | 78 | | SIPOutboundTrunkInfo.Parser, |
| | 8 | 79 | | AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true }) |
| | 8 | 80 | | ) |
| | 8 | 81 | | .ConfigureAwait(false); |
| | 5 | 82 | | } |
| | | 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 | | ) |
| | 1 | 92 | | { |
| | 1 | 93 | | return await SendAsync( |
| | 1 | 94 | | Twirp.Routes.SIP.GetSIPInboundTrunk, |
| | 1 | 95 | | request, |
| | 1 | 96 | | GetSIPInboundTrunkResponse.Parser, |
| | 1 | 97 | | AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true }) |
| | 1 | 98 | | ) |
| | 1 | 99 | | .ConfigureAwait(false); |
| | 1 | 100 | | } |
| | | 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 | | ) |
| | 1 | 110 | | { |
| | 1 | 111 | | return await SendAsync( |
| | 1 | 112 | | Twirp.Routes.SIP.GetSIPOutboundTrunk, |
| | 1 | 113 | | request, |
| | 1 | 114 | | GetSIPOutboundTrunkResponse.Parser, |
| | 1 | 115 | | AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true }) |
| | 1 | 116 | | ) |
| | 1 | 117 | | .ConfigureAwait(false); |
| | 1 | 118 | | } |
| | | 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 | | ) |
| | 4 | 128 | | { |
| | 4 | 129 | | return await SendAsync( |
| | 4 | 130 | | Twirp.Routes.SIP.ListSIPInboundTrunk, |
| | 4 | 131 | | request, |
| | 4 | 132 | | ListSIPInboundTrunkResponse.Parser, |
| | 4 | 133 | | AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true }) |
| | 4 | 134 | | ) |
| | 4 | 135 | | .ConfigureAwait(false); |
| | 4 | 136 | | } |
| | | 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 | | ) |
| | 1 | 146 | | { |
| | 1 | 147 | | return await SendAsync( |
| | 1 | 148 | | Twirp.Routes.SIP.ListSIPOutboundTrunk, |
| | 1 | 149 | | request, |
| | 1 | 150 | | ListSIPOutboundTrunkResponse.Parser, |
| | 1 | 151 | | AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true }) |
| | 1 | 152 | | ) |
| | 1 | 153 | | .ConfigureAwait(false); |
| | 1 | 154 | | } |
| | | 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) |
| | 1 | 162 | | { |
| | 1 | 163 | | return await SendAsync( |
| | 1 | 164 | | Twirp.Routes.SIP.DeleteSIPTrunk, |
| | 1 | 165 | | request, |
| | 1 | 166 | | SIPTrunkInfo.Parser, |
| | 1 | 167 | | AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true }) |
| | 1 | 168 | | ) |
| | 1 | 169 | | .ConfigureAwait(false); |
| | 1 | 170 | | } |
| | | 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 | | ) |
| | 2 | 180 | | { |
| | 2 | 181 | | return await SendAsync( |
| | 2 | 182 | | Twirp.Routes.SIP.CreateSIPDispatchRule, |
| | 2 | 183 | | request, |
| | 2 | 184 | | SIPDispatchRuleInfo.Parser, |
| | 2 | 185 | | AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true }) |
| | 2 | 186 | | ) |
| | 2 | 187 | | .ConfigureAwait(false); |
| | 2 | 188 | | } |
| | | 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 | | ) |
| | 3 | 198 | | { |
| | 3 | 199 | | return await SendAsync( |
| | 3 | 200 | | Twirp.Routes.SIP.ListSIPDispatchRule, |
| | 3 | 201 | | request, |
| | 3 | 202 | | ListSIPDispatchRuleResponse.Parser, |
| | 3 | 203 | | AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true }) |
| | 3 | 204 | | ) |
| | 3 | 205 | | .ConfigureAwait(false); |
| | 3 | 206 | | } |
| | | 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 | | ) |
| | 1 | 216 | | { |
| | 1 | 217 | | return await SendAsync( |
| | 1 | 218 | | Twirp.Routes.SIP.DeleteSIPDispatchRule, |
| | 1 | 219 | | request, |
| | 1 | 220 | | SIPDispatchRuleInfo.Parser, |
| | 1 | 221 | | AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true }) |
| | 1 | 222 | | ) |
| | 1 | 223 | | .ConfigureAwait(false); |
| | 1 | 224 | | } |
| | | 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 | | ) |
| | 6 | 234 | | { |
| | 6 | 235 | | return await SendAsync( |
| | 6 | 236 | | Twirp.Routes.SIP.CreateSIPParticipant, |
| | 6 | 237 | | request, |
| | 6 | 238 | | SIPParticipantInfo.Parser, |
| | 6 | 239 | | AuthHeader(new VideoGrants { }, new SIPGrants { Call = true }) |
| | 6 | 240 | | ) |
| | 6 | 241 | | .ConfigureAwait(false); |
| | 2 | 242 | | } |
| | | 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 | | ) |
| | 4 | 252 | | { |
| | 4 | 253 | | return await SendAsync( |
| | 4 | 254 | | Twirp.Routes.SIP.TransferSIPParticipant, |
| | 4 | 255 | | request, |
| | 4 | 256 | | TransferSIPParticipantResponse.Parser, |
| | 4 | 257 | | AuthHeader( |
| | 4 | 258 | | new VideoGrants { RoomAdmin = true, Room = request.RoomName }, |
| | 4 | 259 | | new SIPGrants { Call = true } |
| | 4 | 260 | | ) |
| | 4 | 261 | | ) |
| | 4 | 262 | | .ConfigureAwait(false); |
| | 0 | 263 | | } |
| | | 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 | | ) |
| | 1 | 273 | | { |
| | 1 | 274 | | return await SendAsync( |
| | 1 | 275 | | Twirp.Routes.SIP.UpdateSIPInboundTrunk, |
| | 1 | 276 | | request, |
| | 1 | 277 | | SIPInboundTrunkInfo.Parser, |
| | 1 | 278 | | AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true }) |
| | 1 | 279 | | ) |
| | 1 | 280 | | .ConfigureAwait(false); |
| | 1 | 281 | | } |
| | | 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 | | ) |
| | 1 | 291 | | { |
| | 1 | 292 | | return await SendAsync( |
| | 1 | 293 | | Twirp.Routes.SIP.UpdateSIPOutboundTrunk, |
| | 1 | 294 | | request, |
| | 1 | 295 | | SIPOutboundTrunkInfo.Parser, |
| | 1 | 296 | | AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true }) |
| | 1 | 297 | | ) |
| | 1 | 298 | | .ConfigureAwait(false); |
| | 1 | 299 | | } |
| | | 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 | | ) |
| | 1 | 309 | | { |
| | 1 | 310 | | return await SendAsync( |
| | 1 | 311 | | Twirp.Routes.SIP.UpdateSIPDispatchRule, |
| | 1 | 312 | | request, |
| | 1 | 313 | | SIPDispatchRuleInfo.Parser, |
| | 1 | 314 | | AuthHeader(new VideoGrants { }, new SIPGrants { Admin = true }) |
| | 1 | 315 | | ) |
| | 1 | 316 | | .ConfigureAwait(false); |
| | 1 | 317 | | } |
| | | 318 | | } |
| | | 319 | | } |