66 lines
2.7 KiB
C#
66 lines
2.7 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();
|
|
});
|
|
//TODO: Add call for if channelId has active call returning boolean value
|
|
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);
|
|
//TODO: Needs to include offer data as JSON
|
|
});
|
|
|
|
app.MapPost("/api/rtc/answer", async (RtcAnswer request, RtcCallService rtcCallService) =>
|
|
{
|
|
await rtcCallService.WriteAnswerAsync(request.ChannelId, request.OfferUser, request.AnswerUser, request.Sdp);
|
|
//TODO: Add call to clients already in call that a new answer has been made with answer details
|
|
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
|
|
);
|
|
//TODO: Add call to clients already in call that a new ICE candidate has been made with ICE candidate details
|
|
|
|
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();
|
|
});
|
|
}
|
|
} |