| | | 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 Egress service: records or streams rooms, participants, tracks and web pages. |
| | | 8 | | /// See <see href="https://docs.livekit.io/transport/media/ingress-egress/egress/">Egress overview</see>. |
| | | 9 | | /// </summary> |
| | | 10 | | public class EgressServiceClient : 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 EgressServiceClient( |
| | | 20 | | string host, |
| | | 21 | | string apiKey = null, |
| | | 22 | | string apiSecret = null, |
| | | 23 | | HttpClient client = null |
| | | 24 | | ) |
| | 36 | 25 | | : base(host, apiKey, apiSecret, client) { } |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Starts a room composite egress: records or streams the whole room, rendered by a web template. |
| | | 29 | | /// </summary> |
| | | 30 | | /// <param name="request">Room name, layout, template and the file, stream, segment or image outputs.</param> |
| | | 31 | | /// <returns>The started egress, with its ID and status.</returns> |
| | | 32 | | public async Task<EgressInfo> StartRoomCompositeEgress(RoomCompositeEgressRequest request) |
| | 3 | 33 | | { |
| | 3 | 34 | | return await SendAsync( |
| | 3 | 35 | | Twirp.Routes.Egress.StartRoomCompositeEgress, |
| | 3 | 36 | | request, |
| | 3 | 37 | | EgressInfo.Parser, |
| | 3 | 38 | | AuthHeader(new VideoGrants { RoomRecord = true }) |
| | 3 | 39 | | ) |
| | 3 | 40 | | .ConfigureAwait(false); |
| | 3 | 41 | | } |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Starts a web egress: records or streams an arbitrary web page. |
| | | 45 | | /// </summary> |
| | | 46 | | /// <param name="request">URL to render and the outputs.</param> |
| | | 47 | | /// <returns>The started egress, with its ID and status.</returns> |
| | | 48 | | public async Task<EgressInfo> StartWebEgress(WebEgressRequest request) |
| | 1 | 49 | | { |
| | 1 | 50 | | return await SendAsync( |
| | 1 | 51 | | Twirp.Routes.Egress.StartWebEgress, |
| | 1 | 52 | | request, |
| | 1 | 53 | | EgressInfo.Parser, |
| | 1 | 54 | | AuthHeader(new VideoGrants { RoomRecord = true }) |
| | 1 | 55 | | ) |
| | 1 | 56 | | .ConfigureAwait(false); |
| | 1 | 57 | | } |
| | | 58 | | |
| | | 59 | | /// <summary> |
| | | 60 | | /// Starts a participant egress: records or streams the tracks of one participant. |
| | | 61 | | /// </summary> |
| | | 62 | | /// <param name="request">Room name, participant identity and the outputs.</param> |
| | | 63 | | /// <returns>The started egress, with its ID and status.</returns> |
| | | 64 | | public async Task<EgressInfo> StartParticipantEgress(ParticipantEgressRequest request) |
| | 1 | 65 | | { |
| | 1 | 66 | | return await SendAsync( |
| | 1 | 67 | | Twirp.Routes.Egress.StartParticipantEgress, |
| | 1 | 68 | | request, |
| | 1 | 69 | | EgressInfo.Parser, |
| | 1 | 70 | | AuthHeader(new VideoGrants { RoomRecord = true }) |
| | 1 | 71 | | ) |
| | 1 | 72 | | .ConfigureAwait(false); |
| | 1 | 73 | | } |
| | | 74 | | |
| | | 75 | | /// <summary> |
| | | 76 | | /// Starts a track composite egress: records or streams one audio and one video track mixed together. |
| | | 77 | | /// </summary> |
| | | 78 | | /// <param name="request">Room name, the audio and video track SIDs and the outputs.</param> |
| | | 79 | | /// <returns>The started egress, with its ID and status.</returns> |
| | | 80 | | public async Task<EgressInfo> StartTrackCompositeEgress(TrackCompositeEgressRequest request) |
| | 1 | 81 | | { |
| | 1 | 82 | | return await SendAsync( |
| | 1 | 83 | | Twirp.Routes.Egress.StartTrackCompositeEgress, |
| | 1 | 84 | | request, |
| | 1 | 85 | | EgressInfo.Parser, |
| | 1 | 86 | | AuthHeader(new VideoGrants { RoomRecord = true }) |
| | 1 | 87 | | ) |
| | 1 | 88 | | .ConfigureAwait(false); |
| | 1 | 89 | | } |
| | | 90 | | |
| | | 91 | | /// <summary> |
| | | 92 | | /// Starts a track egress: exports a single track to a file or to a WebSocket. |
| | | 93 | | /// </summary> |
| | | 94 | | /// <param name="request">Room name, track SID and the file or WebSocket output.</param> |
| | | 95 | | /// <returns>The started egress, with its ID and status.</returns> |
| | | 96 | | public async Task<EgressInfo> StartTrackEgress(TrackEgressRequest request) |
| | 1 | 97 | | { |
| | 1 | 98 | | return await SendAsync( |
| | 1 | 99 | | Twirp.Routes.Egress.StartTrackEgress, |
| | 1 | 100 | | request, |
| | 1 | 101 | | EgressInfo.Parser, |
| | 1 | 102 | | AuthHeader(new VideoGrants { RoomRecord = true }) |
| | 1 | 103 | | ) |
| | 1 | 104 | | .ConfigureAwait(false); |
| | 1 | 105 | | } |
| | | 106 | | |
| | | 107 | | /// <summary> |
| | | 108 | | /// Start any type of egress. The request's source and outputs determine the egress type. |
| | | 109 | | /// </summary> |
| | | 110 | | /// <param name="request">Which kind of egress to start, with its own options.</param> |
| | | 111 | | /// <returns>The started egress, with its ID and status.</returns> |
| | | 112 | | public async Task<EgressInfo> StartEgress(StartEgressRequest request) |
| | 1 | 113 | | { |
| | 1 | 114 | | return await SendAsync( |
| | 1 | 115 | | Twirp.Routes.Egress.StartEgress, |
| | 1 | 116 | | request, |
| | 1 | 117 | | EgressInfo.Parser, |
| | 1 | 118 | | AuthHeader(new VideoGrants { RoomRecord = true }) |
| | 1 | 119 | | ) |
| | 1 | 120 | | .ConfigureAwait(false); |
| | 1 | 121 | | } |
| | | 122 | | |
| | | 123 | | /// <summary> |
| | | 124 | | /// Changes the layout of a running room composite egress. |
| | | 125 | | /// </summary> |
| | | 126 | | /// <param name="request">Egress ID and the new layout.</param> |
| | | 127 | | /// <returns>The updated egress.</returns> |
| | | 128 | | public async Task<EgressInfo> UpdateLayout(UpdateLayoutRequest request) |
| | 1 | 129 | | { |
| | 1 | 130 | | return await SendAsync( |
| | 1 | 131 | | Twirp.Routes.Egress.UpdateLayout, |
| | 1 | 132 | | request, |
| | 1 | 133 | | EgressInfo.Parser, |
| | 1 | 134 | | AuthHeader(new VideoGrants { RoomRecord = true }) |
| | 1 | 135 | | ) |
| | 1 | 136 | | .ConfigureAwait(false); |
| | 1 | 137 | | } |
| | | 138 | | |
| | | 139 | | /// <summary> |
| | | 140 | | /// Adds or removes stream destinations (RTMP, SRT) of a running stream egress. |
| | | 141 | | /// </summary> |
| | | 142 | | /// <param name="request">Egress ID and the stream URLs to add or remove.</param> |
| | | 143 | | /// <returns>The updated egress.</returns> |
| | | 144 | | public async Task<EgressInfo> UpdateStream(UpdateStreamRequest request) |
| | 1 | 145 | | { |
| | 1 | 146 | | return await SendAsync( |
| | 1 | 147 | | Twirp.Routes.Egress.UpdateStream, |
| | 1 | 148 | | request, |
| | 1 | 149 | | EgressInfo.Parser, |
| | 1 | 150 | | AuthHeader(new VideoGrants { RoomRecord = true }) |
| | 1 | 151 | | ) |
| | 1 | 152 | | .ConfigureAwait(false); |
| | 1 | 153 | | } |
| | | 154 | | |
| | | 155 | | /// <summary> |
| | | 156 | | /// Lists the egresses, optionally filtered by room, egress ID or active state. |
| | | 157 | | /// </summary> |
| | | 158 | | /// <param name="request">Optional filters: room name, egress ID, active egresses only.</param> |
| | | 159 | | /// <returns>The matching egresses.</returns> |
| | | 160 | | public async Task<ListEgressResponse> ListEgress(ListEgressRequest request) |
| | 58 | 161 | | { |
| | 58 | 162 | | return await SendAsync( |
| | 58 | 163 | | Twirp.Routes.Egress.ListEgress, |
| | 58 | 164 | | request, |
| | 58 | 165 | | ListEgressResponse.Parser, |
| | 58 | 166 | | AuthHeader(new VideoGrants { RoomRecord = true }) |
| | 58 | 167 | | ) |
| | 58 | 168 | | .ConfigureAwait(false); |
| | 58 | 169 | | } |
| | | 170 | | |
| | | 171 | | /// <summary> |
| | | 172 | | /// Stops a running egress. |
| | | 173 | | /// </summary> |
| | | 174 | | /// <param name="request">Egress ID.</param> |
| | | 175 | | /// <returns>The stopped egress.</returns> |
| | | 176 | | public async Task<EgressInfo> StopEgress(StopEgressRequest request) |
| | 3 | 177 | | { |
| | 3 | 178 | | return await SendAsync( |
| | 3 | 179 | | Twirp.Routes.Egress.StopEgress, |
| | 3 | 180 | | request, |
| | 3 | 181 | | EgressInfo.Parser, |
| | 3 | 182 | | AuthHeader(new VideoGrants { RoomRecord = true }) |
| | 3 | 183 | | ) |
| | 3 | 184 | | .ConfigureAwait(false); |
| | 3 | 185 | | } |
| | | 186 | | } |
| | | 187 | | } |