Some orgnization, and cleanup to come.
This commit is contained in:
63
RelayServer/Endpoints/RtcEndpoints.cs
Normal file
63
RelayServer/Endpoints/RtcEndpoints.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user