Files
Relay/RelayServer/Endpoints/RtcEndpoints.cs

63 lines
2.3 KiB
C#

using RelayServer.Models.Rtc;
using RelayServer.Services.Rtc;
namespace RelayServer.Endpoints;
public static class RtcEndpoints
{
public static void MapRtcEndpoints(this WebApplication app)
{
app.MapPost("/api/rtc/join", async (RtcJoinRequest request, RtcCallService rtcCallService) =>
{
return Results.Ok(await rtcCallService.JoinCallAsync(request.ChannelId, request.Username));
});
app.MapPost("/api/rtc/offer", async (RtcOffer request, RtcCallService rtcCallService) =>
{
await rtcCallService.WriteOfferAsync(request.ChannelId, request.Username, request.Sdp);
return Results.Ok();
});
app.MapGet("/api/rtc/offer/{channelId}", async (string channelId, RtcCallService rtcCallService) =>
{
var offer = await rtcCallService.GetOfferAsync(channelId);
return offer is null ? Results.NotFound() : Results.Ok(offer);
});
app.MapPost("/api/rtc/answer", async (RtcAnswer request, RtcCallService rtcCallService) =>
{
await rtcCallService.WriteAnswerAsync(request.ChannelId, request.OfferUser, request.AnswerUser, request.Sdp);
return Results.Ok();
});
app.MapGet("/api/rtc/answers/{channelId}", async (string channelId, RtcCallService rtcCallService) =>
{
return Results.Ok(await rtcCallService.GetAnswersAsync(channelId));
});
app.MapPost("/api/rtc/candidate", async (RtcIceCandidate request, RtcCallService rtcCallService) =>
{
await rtcCallService.WriteIceCandidateAsync(
request.ChannelId,
request.Username,
request.Candidate,
request.SdpMid,
request.SdpMLineIndex,
request.Direction
);
return Results.Ok();
});
app.MapGet("/api/rtc/candidates/{channelId}", async (string channelId, RtcCallService rtcCallService) =>
{
return Results.Ok(await rtcCallService.GetIceCandidatesAsync(channelId));
});
app.MapPost("/api/rtc/leave", async (RtcLeaveRequest request, RtcCallService rtcCallService) =>
{
await rtcCallService.LeaveCallAsync(request.ChannelId, request.Username);
return Results.Ok();
});
}
}