updated to shared lib

This commit is contained in:
2026-04-11 18:42:29 -04:00
parent a67f94b08e
commit 085507519a
6 changed files with 46 additions and 62 deletions

View File

@@ -2,7 +2,6 @@
using WebSocketSharp;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization.Metadata;
using RelayShared.Rtc;
namespace RelayClient;
@@ -82,7 +81,7 @@ public partial class MainPage : ContentPage
var payload = new SocketEncryptedMessage
{
ChannelId = _currentChannelId!,
Type = "client_encrypted_chat",
Type = SignalType.ClientEncryptedChat,
SenderUsername = _username,
CipherText = encrypted.CipherText,
Nonce = encrypted.Nonce,
@@ -119,9 +118,9 @@ public partial class MainPage : ContentPage
if (!root.TryGetProperty("Type", out var typeElement))
return;
var type = typeElement.GetString();
var type = (SignalType) typeElement.GetInt32();
if (type == "channel_list")
if (type == SignalType.ChannelList)
{
var channelList = JsonSerializer.Deserialize<SocketChannelList>(e.Data);
if (channelList is null)
@@ -154,7 +153,7 @@ public partial class MainPage : ContentPage
return;
}
if (type == "server_public_key")
if (type == SignalType.ServerPublicKey)
{
var serverKeyMessage = JsonSerializer.Deserialize<ServerPublicKeyMessage>(e.Data);
if (serverKeyMessage is not null)
@@ -166,7 +165,7 @@ public partial class MainPage : ContentPage
return;
}
if (type == "encrypted_rtc_signal")
if (type == SignalType.EncryptedSignal)
{
var payload = JsonSerializer.Deserialize<SocketRtcSignalMessage>(e.Data);
if (payload is null)
@@ -199,13 +198,13 @@ public partial class MainPage : ContentPage
return;
}
if (type == "rtc_offer_updated" || type == "rtc_answer_updated" || type == "rtc_candidate_added" || type == "rtc_call_left")
if (type == SignalType.OfferUpdated || type == SignalType.AnswerUpdated || type == SignalType.CandidateAdded || type == SignalType.CallLeft)
{
var rtcNotification = JsonSerializer.Deserialize<RtcNotificationMessage>(e.Data);
if (rtcNotification is null)
return;
var notificationType = rtcNotification.Type ?? string.Empty;
var notificationType = rtcNotification.Type ?? null;
var notificationChannelId = rtcNotification.ChannelId ?? string.Empty;
if (notificationChannelId != _currentChannelId)
@@ -217,13 +216,13 @@ public partial class MainPage : ContentPage
{
switch (notificationType)
{
case "rtc_offer_updated":
case SignalType.OfferUpdated :
{
var offer = await GetRtcOffer();
await SendRtcSignalToJsAsync(offer);
break;
}
case "rtc_answer_updated":
case SignalType.AnswerUpdated:
{
var answer = await ServerAPI.GetAnswerForChannelAsync(_currentChannelId);
if (answer is not null)
@@ -232,7 +231,7 @@ public partial class MainPage : ContentPage
}
break;
}
case "rtc_candidate_added":
case SignalType.CandidateAdded:
{
try
{
@@ -246,7 +245,7 @@ public partial class MainPage : ContentPage
break;
}
case "rtc_call_left":
case SignalType.CallLeft:
{
SafeSendRawToWebView("RTC call left notification received.");
RtcLeaveCallback();
@@ -258,7 +257,7 @@ public partial class MainPage : ContentPage
return;
}
if (type != "encrypted_chat")
if (type != SignalType.EncryptedChat)
return;
var pyload = JsonSerializer.Deserialize<SocketEncryptedMessage>(e.Data);
@@ -429,7 +428,7 @@ public partial class MainPage : ContentPage
bool active = await ServerAPI.GetIsChannelActiveAsync(_currentChannelId);
// SafeSendRawToWebView($"Rtc Channel {_currentChannelName} | {_currentChannelId} is active: {active}");
SafeSendRawToWebView($"Rtc Channel {_currentChannelName} | {_currentChannelId} is active: {active}");
return active;
}
@@ -588,7 +587,7 @@ public partial class MainPage : ContentPage
var payload = new SocketRtcSignalMessage
{
Type = "encrypted_rtc_signal",
Type = SignalType.EncryptedSignal,
SenderUsername = _username,
ChannelId = rtcSignal.ChannelId,
CipherText = encrypted.CipherText,

View File

@@ -261,7 +261,7 @@ async function ensurePeerConnection2()
peerConnection.onicecandidate = async (event) => {
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 IceCandidateAdded(event.candidate);
};
@@ -312,8 +312,6 @@ async function channelCallJoin(activeCall)
// LogMessage("Joining call with media answer: " + JSON.stringify(answer));
// LogMessage("Calling C# WriteRtcAnswer with: " + JSON.stringify(answer));
await window.HybridWebView.InvokeDotNet("WriteRtcAnswer", [JSON.stringify(answer)]);
LogMessage("C# WriteRtcAnswer invoked");
//TODO: Update offer in SurrealDB to include answer
}
else
{
@@ -345,10 +343,10 @@ async function IceCandidateAdded(candidate)
{
if (peerConnection.currentRemoteDescription) {
await peerConnection.addIceCandidate(candidate);
LogMessage("ICE CANDIDATE ADDED: " + JSON.stringify(candidate));
// LogMessage("ICE CANDIDATE ADDED: " + JSON.stringify(candidate));
}
else {
LogMessage("RemoteDescription Missing")
// LogMessage("RemoteDescription Missing")
candidateQueue.push(candidate);
}