making ice candidates write to DB properly

This commit is contained in:
2026-04-08 18:48:15 -04:00
parent dff05dd596
commit cec2d7593f
6 changed files with 58 additions and 18 deletions

View File

@@ -78,15 +78,15 @@ public static class RtcEndpoints
});
// Store a new ICE candidate for the specified channel call.
app.MapPost("/api/rtc/candidate", async (RtcIceCandidate request, RtcCallService rtcCallService) =>
app.MapPost("/api/rtc/candidate", async (DBIceCandidate request, RtcCallService rtcCallService) =>
{
await rtcCallService.WriteIceCandidateAsync(
request.ChannelId,
request.Username,
request.Candidate,
request.SdpMid,
request.SdpMLineIndex,
request.Direction
request.Candidate.candidate,
request.Candidate.sdpMid,
request.Candidate.sdpMLineIndex
// request.Candidate.direction
);
RtcNotificationService.BroadcastToChannel(new RtcNotificationMessage
@@ -94,7 +94,7 @@ public static class RtcEndpoints
Type = "rtc_candidate_added",
ChannelId = request.ChannelId,
Username = request.Username,
Direction = request.Direction
/*Direction = request.Direction*/
});
return Results.Ok();

View File

@@ -9,6 +9,22 @@ public class RtcIceCandidate : Record
public required string Candidate { get; set; }
public string? SdpMid { get; set; }
public int? SdpMLineIndex { get; set; }
public required string Direction { get; set; } // "offer" or "answer"
// public required string Direction { get; set; } // "offer" or "answer"
public DateTime CreatedAt { get; set; }
}
public class DBIceCandidate
{
public required string ChannelId { get; set; }
public required string Username { get; set; }
public required IceCandidate Candidate { get; set; }
}
public class IceCandidate
{
public required string candidate { get; set; }
public required string sdpMid { get; set; }
public required int sdpMLineIndex { get; set; }
public required string usernameFragment { get; set; }
}

View File

@@ -163,8 +163,8 @@ public sealed class RtcCallService
string username,
string candidate,
string? sdpMid,
int? sdpMLineIndex,
string direction)
int? sdpMLineIndex/*,
string direction*/)
{
await _db.Create("rtc_ice_candidates", new RtcIceCandidate
{
@@ -173,7 +173,7 @@ public sealed class RtcCallService
Candidate = candidate,
SdpMid = sdpMid,
SdpMLineIndex = sdpMLineIndex,
Direction = direction,
// Direction = direction,
CreatedAt = DateTime.UtcNow
});
}
@@ -208,7 +208,7 @@ public sealed class RtcCallService
{
var candidates = await _db.Select<RtcIceCandidate>("rtc_ice_candidates");
return candidates
.Where(x => x.ChannelId == channelId && x.Username != username && x.Direction == direction)
.Where(x => x.ChannelId == channelId && x.Username != username /*&& x.Direction == direction*/)
.OrderBy(x => x.CreatedAt)
.ToList();
}