Fix attempts for RTC calls

This commit is contained in:
2026-04-29 13:52:35 -04:00
parent 777328caed
commit 38662f6655
3 changed files with 41 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using RelayClient.Crypto;
using RelayShared.Rtc;
using RelayShared.Services;
@@ -70,6 +71,7 @@ public sealed class RtcBridgeService
rtcSignal.ChannelId ??= _getCurrentChannelId();
rtcSignal.From ??= _username;
// _sendRawToWebView($"RTC_SIGNAL file: {JsonSerializer.Serialize(rtcSignal)}");
if (string.IsNullOrWhiteSpace(rtcSignal.ChannelId))
{
_sendRawToWebView("SendRtcSignal failed: missing channel id.");
@@ -116,13 +118,20 @@ public sealed class RtcBridgeService
public async Task HandleIncomingRtcSignalAsync(SocketRtcSignalMessage payload)
{
_sendRawToWebView("HandleIncomingRtcSignal called");
var currentChannelId = _getCurrentChannelId();
if (payload.ChannelId != currentChannelId)
{
_sendRawToWebView("Channel id does not match");
return;
}
if (payload.SenderUsername == _username)
{
_sendRawToWebView("Received own message");
return;
}
string decryptedJson;
@@ -152,6 +161,7 @@ public sealed class RtcBridgeService
try
{
rtcSignal = JsonSerializer.Deserialize<RtcSignalMessage>(decryptedJson);
// _sendRawToWebView($"Received Encrypted Signal: [{rtcSignal.From}]: {rtcSignal.Offer}");
}
catch (Exception ex)
{
@@ -169,9 +179,9 @@ public sealed class RtcBridgeService
return;
}
_sendRawToWebView("Received encrypted RTC signal: " + decryptedJson);
// _sendRawToWebView("Received encrypted RTC signal: " + decryptedJson);
await SendRtcSignalToJsAsync(decryptedJson);
await SendRtcSignalToJsAsync(rtcSignal);
}
public Task PushRtcContextToJsAsync()
@@ -188,13 +198,15 @@ public sealed class RtcBridgeService
return Task.CompletedTask;
}
private Task SendRtcSignalToJsAsync(string rawJson)
private Task SendRtcSignalToJsAsync(RtcSignalMessage data)
{
MainThread.BeginInvokeOnMainThread(async () =>
{
try
{
var jsArg = JsonSerializer.Serialize(rawJson);
await _hybridWebView.InvokeJavaScriptAsync("testIndex", [data], [RtcJsType.Default.RtcSignalMessage]);
var jsArg = JsonSerializer.Serialize(data);
await _hybridWebView.EvaluateJavaScriptAsync($@"
try {{
@@ -221,4 +233,15 @@ public sealed class RtcBridgeService
return Task.CompletedTask;
}
}
[JsonSourceGenerationOptions(WriteIndented = false)]
[JsonSerializable(typeof(RtcDescription))]
[JsonSerializable(typeof(List<RtcSignalMessage>))]
[JsonSerializable(typeof(RtcSignalMessage))]
[JsonSerializable(typeof(IceCandidate))]
[JsonSerializable(typeof(List<IceCandidate>))]
[JsonSerializable(typeof(string))]
internal partial class RtcJsType : JsonSerializerContext
{
}