Encryption Sent, Encrpytion Decoded, Offer Sent, Offer Recieved, JS -> C# / C# -> JS Broke (some disconnect here) SendRtcSignalToJsAsync
This commit is contained in:
@@ -189,6 +189,20 @@ public partial class MainPage : ContentPage
|
||||
},
|
||||
privateKey
|
||||
);
|
||||
|
||||
var rtcSignal = JsonSerializer.Deserialize<RtcSignalMessage>(decryptedJson);
|
||||
|
||||
if (rtcSignal is null)
|
||||
return;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(rtcSignal.To) &&
|
||||
!string.Equals(rtcSignal.To, _username, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
SafeSendRawToWebView($"Ignoring RTC signal meant for {rtcSignal.To}");
|
||||
return;
|
||||
}
|
||||
|
||||
SafeSendRawToWebView("Received encrypted RTC signal: " + decryptedJson);
|
||||
|
||||
MainThread.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
@@ -438,20 +452,20 @@ public partial class MainPage : ContentPage
|
||||
}
|
||||
|
||||
#region RTC Functions
|
||||
public async Task<bool> JoinRtcChannel()
|
||||
public async Task JoinRtcChannel()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_currentChannelId))
|
||||
return false;
|
||||
return; //false;
|
||||
|
||||
_wsc.Send($"RTC_JOIN_CHANNEL|{_username}|{_currentChannelId}");
|
||||
|
||||
// SafeSendRawToWebView($"Attempting to join RTC Channel {_currentChannelName} | {_currentChannelId} ");
|
||||
|
||||
bool active = await ServerAPI.GetIsChannelActiveAsync(_currentChannelId);
|
||||
//bool active = await ServerAPI.GetIsChannelActiveAsync(_currentChannelId);
|
||||
|
||||
SafeSendRawToWebView($"Rtc Channel {_currentChannelName} | {_currentChannelId} is active: {active}");
|
||||
//SafeSendRawToWebView($"Rtc Channel {_currentChannelName} | {_currentChannelId} is active: {active}");
|
||||
|
||||
return active;
|
||||
return; //active;
|
||||
}
|
||||
|
||||
public void LeaveRtcChannel()
|
||||
@@ -566,10 +580,36 @@ public partial class MainPage : ContentPage
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SendRtcSignalToJsAsync(string rawJson)
|
||||
private Task SendRtcSignalToJsAsync(string rawJson)
|
||||
{
|
||||
var jsArg = JsonSerializer.Serialize(rawJson);
|
||||
await hybridWebView.EvaluateJavaScriptAsync($"window.handleRtcSignal({jsArg})");
|
||||
MainThread.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
SafeSendRawToWebView("Dispatching RTC signal to JS");
|
||||
|
||||
var jsArg = JsonSerializer.Serialize(rawJson);
|
||||
|
||||
await hybridWebView.EvaluateJavaScriptAsync($@"
|
||||
window.HybridWebView.SendRawMessage('JS dispatch wrapper hit');
|
||||
const fn = window.handleRtcSignal || window.dispatchRtcSignal;
|
||||
if (!fn) {{
|
||||
window.HybridWebView.SendRawMessage('No RTC signal handler found on window');
|
||||
}} else {{
|
||||
window.HybridWebView.SendRawMessage('Calling RTC signal handler');
|
||||
fn({jsArg});
|
||||
}}
|
||||
");
|
||||
|
||||
SafeSendRawToWebView("RTC signal dispatched to JS");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SafeSendRawToWebView("SendRtcSignalToJsAsync failed: " + ex.Message);
|
||||
}
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
} //Remove?
|
||||
|
||||
private async Task PushRtcContextToJsAsync()
|
||||
@@ -585,41 +625,63 @@ public partial class MainPage : ContentPage
|
||||
|
||||
public void SendRtcSignal(string json)
|
||||
{
|
||||
SafeSendRawToWebView("SendRtcSignal entered: " + json);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(_serverPublicKey))
|
||||
{
|
||||
Console.WriteLine("Server public key not loaded yet.");
|
||||
SafeSendRawToWebView("SendRtcSignal failed: server public key not loaded.");
|
||||
return;
|
||||
}
|
||||
|
||||
RtcSignalMessage? rtcSignal;
|
||||
|
||||
try
|
||||
{
|
||||
rtcSignal = JsonSerializer.Deserialize<RtcSignalMessage>(json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Failed to parse RTC signal from JS: {ex.Message}");
|
||||
SafeSendRawToWebView("SendRtcSignal failed to parse RTC signal: " + ex.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (rtcSignal is null)
|
||||
return;
|
||||
|
||||
var encrypted = E2EeHelper.EncryptForRecipient(json, _serverPublicKey);
|
||||
|
||||
var payload = new SocketRtcSignalMessage
|
||||
{
|
||||
Type = SignalType.EncryptedSignal,
|
||||
SenderUsername = _username,
|
||||
ChannelId = rtcSignal.ChannelId,
|
||||
CipherText = encrypted.CipherText,
|
||||
Nonce = encrypted.Nonce,
|
||||
Tag = encrypted.Tag,
|
||||
EncryptedKey = encrypted.EncryptedKey
|
||||
};
|
||||
SafeSendRawToWebView("SendRtcSignal failed: rtcSignal was null.");
|
||||
return;
|
||||
}
|
||||
|
||||
_wsc.Send(JsonSerializer.Serialize(payload));
|
||||
Console.WriteLine($"[{_username}] sent RTC signal: {rtcSignal.Type} -> {rtcSignal.ChannelId}");
|
||||
if (string.IsNullOrWhiteSpace(rtcSignal.ChannelId))
|
||||
{
|
||||
SafeSendRawToWebView("SendRtcSignal failed: channelId was empty.");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var encrypted = E2EeHelper.EncryptForRecipient(json, _serverPublicKey);
|
||||
|
||||
var payload = new SocketRtcSignalMessage
|
||||
{
|
||||
Type = SignalType.EncryptedSignal,
|
||||
SenderUsername = _username,
|
||||
ChannelId = rtcSignal.ChannelId,
|
||||
CipherText = encrypted.CipherText,
|
||||
Nonce = encrypted.Nonce,
|
||||
Tag = encrypted.Tag,
|
||||
EncryptedKey = encrypted.EncryptedKey
|
||||
};
|
||||
|
||||
var socketJson = JsonSerializer.Serialize(payload);
|
||||
_wsc.Send(socketJson);
|
||||
|
||||
SafeSendRawToWebView($"SendRtcSignal sent: {rtcSignal.Type} -> {rtcSignal.ChannelId}");
|
||||
Console.WriteLine($"[{_username}] sent RTC signal: {rtcSignal.Type} -> {rtcSignal.ChannelId}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SafeSendRawToWebView("SendRtcSignal websocket/encrypt failed: " + ex.Message);
|
||||
}
|
||||
} //Remove?
|
||||
|
||||
public async Task<string> GetRtcParticipants()
|
||||
|
||||
Reference in New Issue
Block a user