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

@@ -479,8 +479,21 @@ public partial class MainPage : ContentPage
public async void WriteIceCandidate(string json)
{
IceCandidate? candidate = JsonSerializer.Deserialize<IceCandidate>(json);
await ServerAPI.PostIceCandidateAsync(candidate);
try
{
IceCandidate? candidate = JsonSerializer.Deserialize<IceCandidate>(json);
DBIceCandidate DBCandidate = new DBIceCandidate
{
ChannelId = _currentChannelId,
Username = _username,
Candidate = candidate
};
await ServerAPI.PostIceCandidateAsync(DBCandidate);
}
catch (Exception ex)
{
SafeSendRawToWebView("WriteIceCandidate failed: " + ex.Message);
}
}
public async void IceCandidateCallback(string json)

View File

@@ -24,7 +24,7 @@ window.setChannelId = function(channelId) {
currentChannelId = channelId;
LogMessage("Channel set to: " + currentChannelId);
};
let userMedia = getUserMedia()
function LogMessage(msg) {
const messageLog = document.getElementById("messageLog");
messageLog.value += '\r\n' + msg;
@@ -212,9 +212,10 @@ async function ensurePeerConnection2()
console.log(`ICE connection state change: ${peerConnection.iceConnectionState}`);
};
peerConnection.onicecandidate = (event) => {
peerConnection.onicecandidate = async (event) => {
console.log(`Ice Candidate: ${JSON.stringify(event.candidate)}`);
LogMessage(`Ice Candidate: ${JSON.stringify(event.candidate)}`);
await window.HybridWebView.InvokeDotNet("WriteIceCandidate", [JSON.stringify(event.candidate)]);
};
peerConnection.ontrack = (event) => {

View File

@@ -71,7 +71,7 @@ public class ServerAPI
return response.Headers.Location;
}
public static async Task<Uri> PostIceCandidateAsync(IceCandidate candidate)
public static async Task<Uri> PostIceCandidateAsync(DBIceCandidate candidate)
{
HttpResponseMessage response = await client.PostAsJsonAsync("api/rtc/candidate", candidate);
response.EnsureSuccessStatusCode();
@@ -127,8 +127,18 @@ public class DBOffer
}
public class IceCandidate
{
public string type { get; set; }
public string sdp { get; set; }
public required string candidate { get; set; }
public required string sdpMid { get; set; }
public required int sdpMLineIndex { get; set; }
public required string usernameFragment { 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 RtcLeave