CALL WORKS, NEEDS TO HAVE LEAVE CALL SETUP AND HOTSWAP FIXED
This commit is contained in:
@@ -234,6 +234,16 @@ public partial class MainPage : ContentPage
|
|||||||
}
|
}
|
||||||
case "rtc_candidate_added":
|
case "rtc_candidate_added":
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IceCandidate? iceCandidate = JsonSerializer.Deserialize<IceCandidate>(rtcNotification.Direction);
|
||||||
|
IceCandidateCallback(iceCandidate);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
SafeSendRawToWebView($"Candidate rejected: {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "rtc_call_left":
|
case "rtc_call_left":
|
||||||
@@ -254,7 +264,7 @@ public partial class MainPage : ContentPage
|
|||||||
if (pyload is null)
|
if (pyload is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (pyload.RecipientUsername != _username)
|
if (pyload.RecipientUsername == _username)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Console.WriteLine($"[{_username}] received encrypted payload for {pyload.RecipientUsername}");
|
Console.WriteLine($"[{_username}] received encrypted payload for {pyload.RecipientUsername}");
|
||||||
@@ -488,6 +498,7 @@ public partial class MainPage : ContentPage
|
|||||||
Username = _username,
|
Username = _username,
|
||||||
Candidate = candidate
|
Candidate = candidate
|
||||||
};
|
};
|
||||||
|
if (candidate == null) return;
|
||||||
await ServerAPI.PostIceCandidateAsync(DBCandidate);
|
await ServerAPI.PostIceCandidateAsync(DBCandidate);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -496,11 +507,11 @@ public partial class MainPage : ContentPage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void IceCandidateCallback(string json)
|
public async void IceCandidateCallback(IceCandidate candidate)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await hybridWebView.InvokeJavaScriptAsync("IceCandidateAdded");
|
await hybridWebView.InvokeJavaScriptAsync("IceCandidateAdded", [candidate], [HybridJSType.Default.IceCandidate]);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -610,6 +621,8 @@ public partial class MainPage : ContentPage
|
|||||||
[JsonSourceGenerationOptions(WriteIndented = false)]
|
[JsonSourceGenerationOptions(WriteIndented = false)]
|
||||||
[JsonSerializable(typeof(RtcDescription))]
|
[JsonSerializable(typeof(RtcDescription))]
|
||||||
[JsonSerializable(typeof(List<RtcSignalMessage>))]
|
[JsonSerializable(typeof(List<RtcSignalMessage>))]
|
||||||
|
[JsonSerializable(typeof(IceCandidate))]
|
||||||
|
[JsonSerializable(typeof(List<IceCandidate>))]
|
||||||
[JsonSerializable(typeof(string))]
|
[JsonSerializable(typeof(string))]
|
||||||
internal partial class HybridJSType : JsonSerializerContext
|
internal partial class HybridJSType : JsonSerializerContext
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ public sealed class RtcNotificationMessage
|
|||||||
public string? ChannelId { get; set; }
|
public string? ChannelId { get; set; }
|
||||||
public string? Username { get; set; }
|
public string? Username { get; set; }
|
||||||
public string? Direction { get; set; }
|
public string? Direction { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ let currentUsername = null;
|
|||||||
let currentChannelId = null;
|
let currentChannelId = null;
|
||||||
let availableCameras = [];
|
let availableCameras = [];
|
||||||
let availableMics = [];
|
let availableMics = [];
|
||||||
|
let candidateQueue = [];
|
||||||
const configuration = {
|
const configuration = {
|
||||||
iceServers:[
|
iceServers:[
|
||||||
{
|
{
|
||||||
@@ -262,6 +263,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);
|
||||||
};
|
};
|
||||||
|
|
||||||
peerConnection.ontrack = (event) => {
|
peerConnection.ontrack = (event) => {
|
||||||
@@ -334,11 +336,22 @@ async function AnswerCallbackJS(answer)
|
|||||||
LogMessage("Current answer: " + JSON.stringify(answer));
|
LogMessage("Current answer: " + JSON.stringify(answer));
|
||||||
const desc = new RTCSessionDescription(answer);
|
const desc = new RTCSessionDescription(answer);
|
||||||
await peerConnection.setRemoteDescription(desc);
|
await peerConnection.setRemoteDescription(desc);
|
||||||
|
for (const candidate of candidateQueue) {
|
||||||
|
await peerConnection.addIceCandidate(candidate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function IceCandidateAdded(candidate)
|
async function IceCandidateAdded(candidate)
|
||||||
{
|
{
|
||||||
await peerConnection.addIceCandidate(candidate);
|
if (peerConnection.currentRemoteDescription) {
|
||||||
|
await peerConnection.addIceCandidate(candidate);
|
||||||
|
LogMessage("ICE CANDIDATE ADDED: " + JSON.stringify(candidate));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogMessage("RemoteDescription Missing")
|
||||||
|
candidateQueue.push(candidate);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
async function handleRtcSignal(rawJson) {
|
async function handleRtcSignal(rawJson) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using RelayServer.Models.Rtc;
|
using System.Text.Json;
|
||||||
|
using RelayServer.Models.Rtc;
|
||||||
using RelayServer.Services.Rtc;
|
using RelayServer.Services.Rtc;
|
||||||
|
|
||||||
namespace RelayServer.Endpoints;
|
namespace RelayServer.Endpoints;
|
||||||
@@ -86,7 +87,6 @@ public static class RtcEndpoints
|
|||||||
request.Candidate.candidate,
|
request.Candidate.candidate,
|
||||||
request.Candidate.sdpMid,
|
request.Candidate.sdpMid,
|
||||||
request.Candidate.sdpMLineIndex
|
request.Candidate.sdpMLineIndex
|
||||||
// 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 = JsonSerializer.Serialize(request.Candidate)
|
||||||
});
|
});
|
||||||
|
|
||||||
return Results.Ok();
|
return Results.Ok();
|
||||||
|
|||||||
@@ -6,4 +6,12 @@ public sealed class RtcNotificationMessage
|
|||||||
public required string ChannelId { get; set; }
|
public required string ChannelId { get; set; }
|
||||||
public string? Username { get; set; }
|
public string? Username { get; set; }
|
||||||
public string? Direction { get; set; }
|
public string? Direction { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class RtcIceNotificationMessage
|
||||||
|
{
|
||||||
|
public required string Type { get; set; }
|
||||||
|
public required string ChannelId { get; set; }
|
||||||
|
public string? Username { get; set; }
|
||||||
|
public required IceCandidate Candidate { get; set; }
|
||||||
}
|
}
|
||||||
@@ -25,4 +25,22 @@ public static class RtcNotificationService
|
|||||||
host.Sessions.SendTo(json, sessionId);
|
host.Sessions.SendTo(json, sessionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void BroadcastToChannel(RtcIceNotificationMessage message)
|
||||||
|
{
|
||||||
|
if (Server is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var host = Server.WebSocketServices["/"];
|
||||||
|
if (host is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var json = JsonSerializer.Serialize(message);
|
||||||
|
var sessionIds = RtcChannelPresenceService.GetSessionsInChannel(message.ChannelId);
|
||||||
|
|
||||||
|
foreach (var sessionId in sessionIds)
|
||||||
|
{
|
||||||
|
host.Sessions.SendTo(json, sessionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user