Verify RTS Push to JS (fixes to application)

This commit is contained in:
2026-04-17 16:47:30 -04:00
parent 88c5d597d3
commit b70189c619
3 changed files with 31 additions and 8 deletions

View File

@@ -198,13 +198,13 @@ public partial class MainPage : ContentPage
return; return;
} }
if (type == SignalType.OfferUpdated || type == SignalType.AnswerUpdated || type == SignalType.CandidateAdded || type == SignalType.CallLeft) if (type is SignalType.OfferUpdated or SignalType.AnswerUpdated or SignalType.CandidateAdded or SignalType.CallLeft)
{ {
var rtcNotification = JsonSerializer.Deserialize<RtcNotificationMessage>(e.Data); var rtcNotification = JsonSerializer.Deserialize<RtcNotificationMessage>(e.Data);
if (rtcNotification is null) if (rtcNotification is null)
return; return;
var notificationType = rtcNotification.Type ?? null; var notificationType = rtcNotification.Type;
var notificationChannelId = rtcNotification.ChannelId ?? string.Empty; var notificationChannelId = rtcNotification.ChannelId ?? string.Empty;
if (notificationChannelId != _currentChannelId) if (notificationChannelId != _currentChannelId)
@@ -216,8 +216,11 @@ public partial class MainPage : ContentPage
{ {
switch (notificationType) switch (notificationType)
{ {
case SignalType.OfferUpdated : case SignalType.OfferUpdated:
{ {
if (rtcNotification.Username == _username)
break;
var offer = await GetRtcOffer(); var offer = await GetRtcOffer();
await SendRtcSignalToJsAsync(offer); await SendRtcSignalToJsAsync(offer);
break; break;
@@ -233,9 +236,16 @@ public partial class MainPage : ContentPage
} }
case SignalType.CandidateAdded: case SignalType.CandidateAdded:
{ {
if (rtcNotification.Username == _username)
break;
try try
{ {
IceCandidate? iceCandidate = JsonSerializer.Deserialize<IceCandidate>(rtcNotification.Direction); IceCandidate? iceCandidate = JsonSerializer.Deserialize<IceCandidate>(rtcNotification.Direction);
if (iceCandidate is null)
break;
IceCandidateCallback(iceCandidate); IceCandidateCallback(iceCandidate);
} }
catch (Exception ex) catch (Exception ex)
@@ -600,6 +610,11 @@ public partial class MainPage : ContentPage
Console.WriteLine($"[{_username}] sent RTC signal: {rtcSignal.Type} -> {rtcSignal.ChannelId}"); Console.WriteLine($"[{_username}] sent RTC signal: {rtcSignal.Type} -> {rtcSignal.ChannelId}");
} //Remove? } //Remove?
//public async Task<string> GetRtcParticipants() // TODO: UNCOMMENT AND ADD
//{
// var participants = await ServerAPI.GetRtcParticipantsAsync(_currentChannelId);
// return JsonSerializer.Serialize(participants);
//}
#endregion #endregion
private void OnSendMessageButtonClicked(object sender, EventArgs e) private void OnSendMessageButtonClicked(object sender, EventArgs e)
@@ -615,7 +630,7 @@ public partial class MainPage : ContentPage
return; return;
} }
await DisplayAlertAsync("Raw Message Received", e.Message, "OK"); SafeSendRawToWebView($"JS RAW -> C#: {e.Message}");
} }
private void SafeSendRawToWebView(string message) private void SafeSendRawToWebView(string message)

View File

@@ -1,4 +1,6 @@
let peerConnection = null; let peerConnection = null;
let peerConnections = {};
let remoteStreams = {};
let localStream = null; let localStream = null;
let currentUsername = null; let currentUsername = null;
let currentChannelId = null; let currentChannelId = null;
@@ -241,7 +243,7 @@ async function joinChannelCall() {
// } // }
} //Combine with channelCallJoin } //Combine with channelCallJoin
async function ensurePeerConnection2() async function ensurePeerConnectionForUser(username)
{ {
if (peerConnection) return; if (peerConnection) return;
peerConnection = new RTCPeerConnection(configuration); peerConnection = new RTCPeerConnection(configuration);
@@ -263,7 +265,7 @@ async function ensurePeerConnection2()
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)]); await window.HybridWebView.InvokeDotNet("WriteIceCandidate", [JSON.stringify(event.candidate)]);
await IceCandidateAdded(event.candidate); //await IceCandidateAdded(event.candidate);
}; };
peerConnection.ontrack = (event) => { peerConnection.ontrack = (event) => {
@@ -297,7 +299,7 @@ async function ensurePeerConnection2()
async function channelCallJoin(activeCall) async function channelCallJoin(activeCall)
{ {
// LogMessage("Active call: " + activeCall); // LogMessage("Active call: " + activeCall);
await ensurePeerConnection2(); await ensurePeerConnectionForUser();
await ensureLocalMedia(); await ensureLocalMedia();
await applyLocalStreamToPeerConnection(); await applyLocalStreamToPeerConnection();
@@ -529,7 +531,7 @@ async function waitForIceGatheringComplete(pc) {
}); });
} //Remove? } //Remove?
// window.handleRtcSignal = handleRtcSignal; window.handleRtcSignal = handleRtcSignal;
window.addEventListener("HybridWebViewMessageReceived", function (e) { window.addEventListener("HybridWebViewMessageReceived", function (e) {
LogMessage("Raw message: " + e.detail.message); LogMessage("Raw message: " + e.detail.message);

View File

@@ -71,6 +71,12 @@ public static class RtcEndpoints
return Results.Ok(await rtcCallService.GetAnswersAsync(channelId)); return Results.Ok(await rtcCallService.GetAnswersAsync(channelId));
}); });
//app.MapGet("/api/rtc/participants/{channelId}", (string channelId) => // TODO: UNCOMMENT AND ADD
//{
// var participants = RtcChannelPresenceService.GetUsernamesInChannel(channelId);
// return Results.Ok(participants);
//});
// Return the latest answer stored for the specified channel. // Return the latest answer stored for the specified channel.
app.MapGet("/api/rtc/answer/{channelId}", async (string channelId, RtcCallService rtcCallService) => app.MapGet("/api/rtc/answer/{channelId}", async (string channelId, RtcCallService rtcCallService) =>
{ {