Verify RTS Push to JS (fixes to application)
This commit is contained in:
@@ -198,13 +198,13 @@ public partial class MainPage : ContentPage
|
||||
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);
|
||||
if (rtcNotification is null)
|
||||
return;
|
||||
|
||||
var notificationType = rtcNotification.Type ?? null;
|
||||
var notificationType = rtcNotification.Type;
|
||||
var notificationChannelId = rtcNotification.ChannelId ?? string.Empty;
|
||||
|
||||
if (notificationChannelId != _currentChannelId)
|
||||
@@ -218,6 +218,9 @@ public partial class MainPage : ContentPage
|
||||
{
|
||||
case SignalType.OfferUpdated:
|
||||
{
|
||||
if (rtcNotification.Username == _username)
|
||||
break;
|
||||
|
||||
var offer = await GetRtcOffer();
|
||||
await SendRtcSignalToJsAsync(offer);
|
||||
break;
|
||||
@@ -233,9 +236,16 @@ public partial class MainPage : ContentPage
|
||||
}
|
||||
case SignalType.CandidateAdded:
|
||||
{
|
||||
if (rtcNotification.Username == _username)
|
||||
break;
|
||||
|
||||
try
|
||||
{
|
||||
IceCandidate? iceCandidate = JsonSerializer.Deserialize<IceCandidate>(rtcNotification.Direction);
|
||||
|
||||
if (iceCandidate is null)
|
||||
break;
|
||||
|
||||
IceCandidateCallback(iceCandidate);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -600,6 +610,11 @@ public partial class MainPage : ContentPage
|
||||
Console.WriteLine($"[{_username}] sent RTC signal: {rtcSignal.Type} -> {rtcSignal.ChannelId}");
|
||||
} //Remove?
|
||||
|
||||
//public async Task<string> GetRtcParticipants() // TODO: UNCOMMENT AND ADD
|
||||
//{
|
||||
// var participants = await ServerAPI.GetRtcParticipantsAsync(_currentChannelId);
|
||||
// return JsonSerializer.Serialize(participants);
|
||||
//}
|
||||
|
||||
#endregion
|
||||
private void OnSendMessageButtonClicked(object sender, EventArgs e)
|
||||
@@ -615,7 +630,7 @@ public partial class MainPage : ContentPage
|
||||
return;
|
||||
}
|
||||
|
||||
await DisplayAlertAsync("Raw Message Received", e.Message, "OK");
|
||||
SafeSendRawToWebView($"JS RAW -> C#: {e.Message}");
|
||||
}
|
||||
|
||||
private void SafeSendRawToWebView(string message)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
let peerConnection = null;
|
||||
let peerConnections = {};
|
||||
let remoteStreams = {};
|
||||
let localStream = null;
|
||||
let currentUsername = null;
|
||||
let currentChannelId = null;
|
||||
@@ -241,7 +243,7 @@ async function joinChannelCall() {
|
||||
// }
|
||||
} //Combine with channelCallJoin
|
||||
|
||||
async function ensurePeerConnection2()
|
||||
async function ensurePeerConnectionForUser(username)
|
||||
{
|
||||
if (peerConnection) return;
|
||||
peerConnection = new RTCPeerConnection(configuration);
|
||||
@@ -263,7 +265,7 @@ async function ensurePeerConnection2()
|
||||
console.log(`Ice Candidate: ${JSON.stringify(event.candidate)}`);
|
||||
// LogMessage(`Ice Candidate: ${JSON.stringify(event.candidate)}`);
|
||||
await window.HybridWebView.InvokeDotNet("WriteIceCandidate", [JSON.stringify(event.candidate)]);
|
||||
await IceCandidateAdded(event.candidate);
|
||||
//await IceCandidateAdded(event.candidate);
|
||||
};
|
||||
|
||||
peerConnection.ontrack = (event) => {
|
||||
@@ -297,7 +299,7 @@ async function ensurePeerConnection2()
|
||||
async function channelCallJoin(activeCall)
|
||||
{
|
||||
// LogMessage("Active call: " + activeCall);
|
||||
await ensurePeerConnection2();
|
||||
await ensurePeerConnectionForUser();
|
||||
await ensureLocalMedia();
|
||||
await applyLocalStreamToPeerConnection();
|
||||
|
||||
@@ -529,7 +531,7 @@ async function waitForIceGatheringComplete(pc) {
|
||||
});
|
||||
} //Remove?
|
||||
|
||||
// window.handleRtcSignal = handleRtcSignal;
|
||||
window.handleRtcSignal = handleRtcSignal;
|
||||
|
||||
window.addEventListener("HybridWebViewMessageReceived", function (e) {
|
||||
LogMessage("Raw message: " + e.detail.message);
|
||||
|
||||
@@ -71,6 +71,12 @@ public static class RtcEndpoints
|
||||
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.
|
||||
app.MapGet("/api/rtc/answer/{channelId}", async (string channelId, RtcCallService rtcCallService) =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user