making ice candidates write to DB properly
This commit is contained in:
@@ -478,9 +478,22 @@ public partial class MainPage : ContentPage
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async void WriteIceCandidate(string json)
|
public async void WriteIceCandidate(string json)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
IceCandidate? candidate = JsonSerializer.Deserialize<IceCandidate>(json);
|
IceCandidate? candidate = JsonSerializer.Deserialize<IceCandidate>(json);
|
||||||
await ServerAPI.PostIceCandidateAsync(candidate);
|
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)
|
public async void IceCandidateCallback(string json)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ window.setChannelId = function(channelId) {
|
|||||||
currentChannelId = channelId;
|
currentChannelId = channelId;
|
||||||
LogMessage("Channel set to: " + currentChannelId);
|
LogMessage("Channel set to: " + currentChannelId);
|
||||||
};
|
};
|
||||||
|
let userMedia = getUserMedia()
|
||||||
function LogMessage(msg) {
|
function LogMessage(msg) {
|
||||||
const messageLog = document.getElementById("messageLog");
|
const messageLog = document.getElementById("messageLog");
|
||||||
messageLog.value += '\r\n' + msg;
|
messageLog.value += '\r\n' + msg;
|
||||||
@@ -212,9 +212,10 @@ async function ensurePeerConnection2()
|
|||||||
console.log(`ICE connection state change: ${peerConnection.iceConnectionState}`);
|
console.log(`ICE connection state change: ${peerConnection.iceConnectionState}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
peerConnection.onicecandidate = (event) => {
|
peerConnection.onicecandidate = async (event) => {
|
||||||
console.log(`Ice Candidate: ${JSON.stringify(event.candidate)}`);
|
console.log(`Ice Candidate: ${JSON.stringify(event.candidate)}`);
|
||||||
LogMessage(`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) => {
|
peerConnection.ontrack = (event) => {
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public class ServerAPI
|
|||||||
return response.Headers.Location;
|
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);
|
HttpResponseMessage response = await client.PostAsJsonAsync("api/rtc/candidate", candidate);
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
@@ -127,8 +127,18 @@ public class DBOffer
|
|||||||
}
|
}
|
||||||
public class IceCandidate
|
public class IceCandidate
|
||||||
{
|
{
|
||||||
public string type { get; set; }
|
public required string candidate { get; set; }
|
||||||
public string sdp { 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
|
public class RtcLeave
|
||||||
|
|||||||
@@ -78,15 +78,15 @@ public static class RtcEndpoints
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Store a new ICE candidate for the specified channel call.
|
// 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(
|
await rtcCallService.WriteIceCandidateAsync(
|
||||||
request.ChannelId,
|
request.ChannelId,
|
||||||
request.Username,
|
request.Username,
|
||||||
request.Candidate,
|
request.Candidate.candidate,
|
||||||
request.SdpMid,
|
request.Candidate.sdpMid,
|
||||||
request.SdpMLineIndex,
|
request.Candidate.sdpMLineIndex
|
||||||
request.Direction
|
// request.Candidate.direction
|
||||||
);
|
);
|
||||||
|
|
||||||
RtcNotificationService.BroadcastToChannel(new RtcNotificationMessage
|
RtcNotificationService.BroadcastToChannel(new RtcNotificationMessage
|
||||||
@@ -94,7 +94,7 @@ public static class RtcEndpoints
|
|||||||
Type = "rtc_candidate_added",
|
Type = "rtc_candidate_added",
|
||||||
ChannelId = request.ChannelId,
|
ChannelId = request.ChannelId,
|
||||||
Username = request.Username,
|
Username = request.Username,
|
||||||
Direction = request.Direction
|
/*Direction = request.Direction*/
|
||||||
});
|
});
|
||||||
|
|
||||||
return Results.Ok();
|
return Results.Ok();
|
||||||
|
|||||||
@@ -9,6 +9,22 @@ public class RtcIceCandidate : Record
|
|||||||
public required string Candidate { get; set; }
|
public required string Candidate { get; set; }
|
||||||
public string? SdpMid { get; set; }
|
public string? SdpMid { get; set; }
|
||||||
public int? SdpMLineIndex { 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 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; }
|
||||||
|
|
||||||
|
}
|
||||||
@@ -163,8 +163,8 @@ public sealed class RtcCallService
|
|||||||
string username,
|
string username,
|
||||||
string candidate,
|
string candidate,
|
||||||
string? sdpMid,
|
string? sdpMid,
|
||||||
int? sdpMLineIndex,
|
int? sdpMLineIndex/*,
|
||||||
string direction)
|
string direction*/)
|
||||||
{
|
{
|
||||||
await _db.Create("rtc_ice_candidates", new RtcIceCandidate
|
await _db.Create("rtc_ice_candidates", new RtcIceCandidate
|
||||||
{
|
{
|
||||||
@@ -173,7 +173,7 @@ public sealed class RtcCallService
|
|||||||
Candidate = candidate,
|
Candidate = candidate,
|
||||||
SdpMid = sdpMid,
|
SdpMid = sdpMid,
|
||||||
SdpMLineIndex = sdpMLineIndex,
|
SdpMLineIndex = sdpMLineIndex,
|
||||||
Direction = direction,
|
// Direction = direction,
|
||||||
CreatedAt = DateTime.UtcNow
|
CreatedAt = DateTime.UtcNow
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -208,7 +208,7 @@ public sealed class RtcCallService
|
|||||||
{
|
{
|
||||||
var candidates = await _db.Select<RtcIceCandidate>("rtc_ice_candidates");
|
var candidates = await _db.Select<RtcIceCandidate>("rtc_ice_candidates");
|
||||||
return 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)
|
.OrderBy(x => x.CreatedAt)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user