brokededed again

This commit is contained in:
2026-04-06 17:42:14 -04:00
parent 7d8755ca71
commit 3c1a4c7a2d
2 changed files with 45 additions and 8 deletions

View File

@@ -2,6 +2,8 @@
using RelayClient.Models;
using WebSocketSharp;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization.Metadata;
namespace RelayClient;
@@ -226,8 +228,7 @@ public partial class MainPage : ContentPage
var answer = await ServerAPI.GetAnswerForChannelAsync(_currentChannelId);
if (answer is not null)
{
var json = JsonSerializer.Serialize(answer);
await hybridWebView.EvaluateJavaScriptAsync($"window.AnswerCallback({json})");
await AnswerCallback(answer);
}
break;
}
@@ -476,10 +477,22 @@ public partial class MainPage : ContentPage
}
}
public async void AnswerCallback(RtcDescription answer)
public async Task AnswerCallback(RtcDescription answer)
{
var json = JsonSerializer.Serialize(answer);
await hybridWebView.EvaluateJavaScriptAsync($"window.AnswerCallback({json})");
string json = JsonSerializer.Serialize(answer);
SafeSendRawToWebView("WriteRtcAnswer answered with: " + json);
try
{
SafeSendRawToWebView("Pre");
// await hybridWebView.InvokeJavaScriptAsync("CSharpCallTest", ["value from C#"], [HybridJSTypeString.Default.String]);
// SafeSendRawToWebView("Mid");
await hybridWebView.InvokeJavaScriptAsync("AnswerCallback", [json], [HybridJSTypeString.Default.String]);
SafeSendRawToWebView("End");
}
catch (Exception ex)
{
SafeSendRawToWebView("WriteRtcAnswer failed: " + ex.Message);
}
}
private void OnSendMessageButtonClicked(object sender, EventArgs e)
@@ -568,4 +581,20 @@ public partial class MainPage : ContentPage
}
});
}
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(string))]
internal partial class HybridJSTypeString : JsonSerializerContext
{
// This type's attributes specify JSON serialization info to preserve type structure
// for trimmed builds.
}
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(RtcDescription))]
internal partial class HybridJSTypeRtcDescription : JsonSerializerContext
{
// This type's attributes specify JSON serialization info to preserve type structure
// for trimmed builds.
}
}