From dc37933fb8c0aca73951a6260df9f3202e6e28a1 Mon Sep 17 00:00:00 2001 From: Cody Larkin Date: Thu, 9 Apr 2026 16:53:29 -0400 Subject: [PATCH] cleanup prep and leave call prep --- RelayClient/MainPage.xaml.cs | 62 ++++++++++++++-------- RelayClient/Resources/Raw/wwwroot/index.js | 12 +++-- 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/RelayClient/MainPage.xaml.cs b/RelayClient/MainPage.xaml.cs index 9d66f62..7fccd16 100644 --- a/RelayClient/MainPage.xaml.cs +++ b/RelayClient/MainPage.xaml.cs @@ -249,6 +249,7 @@ public partial class MainPage : ContentPage case "rtc_call_left": { SafeSendRawToWebView("RTC call left notification received."); + RtcLeaveCallback(); break; } } @@ -416,6 +417,7 @@ public partial class MainPage : ContentPage } } + #region RTC Functions public async Task JoinRtcChannel() { if (string.IsNullOrWhiteSpace(_currentChannelId)) @@ -530,23 +532,36 @@ public partial class MainPage : ContentPage SafeSendRawToWebView("AnswerCallback failed: " + ex.Message); } } - - private void OnSendMessageButtonClicked(object sender, EventArgs e) - { - SafeSendRawToWebView($"Hello from C#!"); - } - private async void OnHybridWebViewRawMessageReceived(object sender, HybridWebViewRawMessageReceivedEventArgs e) + public async void RtcLeaveCallback() { - if (e.Message == "rtc_page_ready") + try { - await PushRtcContextToJsAsync(); - return; + await hybridWebView.InvokeJavaScriptAsync("RtcLeaveCall", [], []); + } + catch (Exception ex) + { + SafeSendRawToWebView("RtcLeaveCallback failed: " + ex.Message); } - - await DisplayAlertAsync("Raw Message Received", e.Message, "OK"); } + private async Task SendRtcSignalToJsAsync(string rawJson) + { + var jsArg = JsonSerializer.Serialize(rawJson); + await hybridWebView.EvaluateJavaScriptAsync($"window.handleRtcSignal({jsArg})"); + } //Remove? + + private async Task PushRtcContextToJsAsync() + { + var usernameJson = JsonSerializer.Serialize(_username); + var channelIdJson = JsonSerializer.Serialize(_currentChannelId); + + await hybridWebView.EvaluateJavaScriptAsync($"window.setUsername({usernameJson})"); + await hybridWebView.EvaluateJavaScriptAsync($"window.setChannelId({channelIdJson})"); + + Console.WriteLine($"[{_username}] pushed RTC context into HybridWebView."); + } //Remove? + public void SendRtcSignal(string json) { if (string.IsNullOrWhiteSpace(_serverPublicKey)) @@ -584,23 +599,24 @@ public partial class MainPage : ContentPage _wsc.Send(JsonSerializer.Serialize(payload)); Console.WriteLine($"[{_username}] sent RTC signal: {rtcSignal.Type} -> {rtcSignal.ChannelId}"); - } + } //Remove? - private async Task SendRtcSignalToJsAsync(string rawJson) - { - var jsArg = JsonSerializer.Serialize(rawJson); - await hybridWebView.EvaluateJavaScriptAsync($"window.handleRtcSignal({jsArg})"); - } - private async Task PushRtcContextToJsAsync() + #endregion + private void OnSendMessageButtonClicked(object sender, EventArgs e) { - var usernameJson = JsonSerializer.Serialize(_username); - var channelIdJson = JsonSerializer.Serialize(_currentChannelId); + SafeSendRawToWebView($"Hello from C#!"); + } - await hybridWebView.EvaluateJavaScriptAsync($"window.setUsername({usernameJson})"); - await hybridWebView.EvaluateJavaScriptAsync($"window.setChannelId({channelIdJson})"); + private async void OnHybridWebViewRawMessageReceived(object sender, HybridWebViewRawMessageReceivedEventArgs e) + { + if (e.Message == "rtc_page_ready") + { + await PushRtcContextToJsAsync(); + return; + } - Console.WriteLine($"[{_username}] pushed RTC context into HybridWebView."); + await DisplayAlertAsync("Raw Message Received", e.Message, "OK"); } private void SafeSendRawToWebView(string message) diff --git a/RelayClient/Resources/Raw/wwwroot/index.js b/RelayClient/Resources/Raw/wwwroot/index.js index da5125d..09db517 100644 --- a/RelayClient/Resources/Raw/wwwroot/index.js +++ b/RelayClient/Resources/Raw/wwwroot/index.js @@ -25,7 +25,6 @@ window.setChannelId = function(channelId) { currentChannelId = channelId; LogMessage("Channel set to: " + currentChannelId); }; -// let userMedia = getUserMedia() function LogMessage(msg) { const messageLog = document.getElementById("messageLog"); messageLog.value += '\r\n' + msg; @@ -96,7 +95,7 @@ async function ensurePeerConnection() { peerConnection.onicegatheringstatechange = () => { LogMessage("ICE gathering state: " + peerConnection.iceGatheringState); }; -} +} //Remove? async function ensureLocalMedia(forceReload = false) { const localMediaStatus = document.getElementById("localMediaStatus"); const localVideoStatus = document.getElementById("localVideoStatus"); @@ -239,7 +238,7 @@ async function joinChannelCall() { // } catch (err) { // LogMessage("joinChannelCall failed: " + err); // } -} +} //Combine with channelCallJoin async function ensurePeerConnection2() { @@ -353,6 +352,9 @@ async function IceCandidateAdded(candidate) } } + +async function RtcLeaveCall() +{} async function handleRtcSignal(rawJson) { try { const msg = typeof rawJson === "string" ? JSON.parse(rawJson) : rawJson; @@ -442,7 +444,7 @@ async function handleRtcSignal(rawJson) { } catch (err) { LogMessage("handleRtcSignal failed: " + err); } -} +} //Remove? async function loadDevices() { try { @@ -526,7 +528,7 @@ async function waitForIceGatheringComplete(pc) { pc.addEventListener("icegatheringstatechange", checkState); }); -} +} //Remove? window.handleRtcSignal = handleRtcSignal;