Updated, the update... should be working now hopefully...

This commit is contained in:
2026-05-30 21:11:33 -04:00
parent 1ed3efcc68
commit b62ceb1949
6 changed files with 568 additions and 413 deletions

View File

@@ -137,11 +137,11 @@ public partial class MainPage : ContentPage
await _rtc.PushRtcContextToJsAsync();
});
_socket.SendRaw($"GET_HISTORY|{_username}|{_currentChannelId}");
_socket.SendGetHistory(_currentChannelId);
}
private void HandleEncryptedChat(SocketEncryptedMessage payload) {
if (payload.RecipientUsername != _username)
if (!payload.RecipientUsername.Equals(_username, StringComparison.OrdinalIgnoreCase))
return;
string decryptedText;
@@ -229,7 +229,7 @@ public partial class MainPage : ContentPage
RenderCurrentChannelMessages();
if (!_messagesByChannel.ContainsKey(channel.ChannelId))
_socket.SendRaw($"GET_HISTORY|{_username}|{channel.ChannelId}");
_socket.SendGetHistory(channel.ChannelId);
};
SidebarList.Children.Add(button);

View File

@@ -1,4 +1,4 @@
using System.Text.Json;
using System.Text.Json;
using RelayClient.Crypto;
using RelayShared.Services;
using WebSocketSharp;
@@ -19,7 +19,7 @@ public sealed class RelaySocketClient
public event Action<string>? ServerPublicKeyReceived;
public event Action<string>? Log;
public RelaySocketClient(string username, string url = "ws://192.168.1.85:5001/")
public RelaySocketClient(string username, string url = "ws://127.0.0.1:5001/")
{
_username = username;
_socket = new WebSocket(url);
@@ -32,10 +32,57 @@ public sealed class RelaySocketClient
var publicKey = KeyStorage.LoadPublicKey(_username);
SendRaw($"AUTHENTICATE_USER|{_username}|{MainPage._userToken}");
SendRaw($"REGISTER_KEY|{_username}|{publicKey}");
SendRaw("GET_SERVER_KEY");
SendRaw("GET_CHANNELS");
SendControlMessage(new WsControlMessage
{
Action = WsAction.Authenticate,
Username = _username,
Token = MainPage._userToken
});
SendControlMessage(new WsControlMessage
{
Action = WsAction.RegisterKey,
Username = _username,
PublicKey = publicKey
});
SendControlMessage(new WsControlMessage { Action = WsAction.GetServerKey });
SendControlMessage(new WsControlMessage { Action = WsAction.GetChannels });
}
public void SendControlMessage(WsControlMessage message)
{
SendRaw(JsonSerializer.Serialize(message));
}
public void SendGetHistory(string channelId)
{
SendControlMessage(new WsControlMessage
{
Action = WsAction.GetHistory,
Username = _username,
ChannelId = channelId
});
}
public void SendRtcJoinChannel(string channelId)
{
SendControlMessage(new WsControlMessage
{
Action = WsAction.RtcJoin,
Username = _username,
ChannelId = channelId
});
}
public void SendRtcLeaveChannel(string channelId)
{
SendControlMessage(new WsControlMessage
{
Action = WsAction.RtcLeave,
Username = _username,
ChannelId = channelId
});
}
public void SendRaw(string message)
@@ -59,12 +106,6 @@ public sealed class RelaySocketClient
private void OnMessage(object? sender, MessageEventArgs e)
{
if (e.Data.StartsWith("SERVER:REGISTERED_KEY:"))
{
Log?.Invoke(e.Data);
return;
}
RawMessageReceived?.Invoke(e.Data);
Log?.Invoke($"[{_username}] RAW WS DATA: {e.Data}");
@@ -73,6 +114,31 @@ public sealed class RelaySocketClient
using var doc = JsonDocument.Parse(e.Data);
var root = doc.RootElement;
// Control event responses (WsEvent)
if (root.TryGetProperty("Event", out var eventElement))
{
var wsEvent = (WsEvent)eventElement.GetInt32();
switch (wsEvent)
{
case WsEvent.KeyRegistered:
Log?.Invoke($"[{_username}] Key registered on server.");
return;
case WsEvent.Authenticated:
Log?.Invoke($"[{_username}] Authenticated with server.");
return;
case WsEvent.Error:
var detail = root.TryGetProperty("Detail", out var d) ? d.GetString() : null;
Log?.Invoke($"[{_username}] Server error: {detail}");
return;
}
return;
}
// Data messages (SignalType)
if (!root.TryGetProperty("Type", out var typeElement))
return;
@@ -125,4 +191,4 @@ public sealed class RelaySocketClient
Log?.Invoke($"[{_username}] failed to process websocket message: {ex.Message}");
}
}
}
}

View File

@@ -31,7 +31,7 @@ public sealed class RtcBridgeService
if (string.IsNullOrWhiteSpace(channelId))
return Task.CompletedTask;
_socket.SendRaw($"RTC_JOIN_CHANNEL|{_username}|{channelId}");
_socket.SendRtcJoinChannel(channelId);
return Task.CompletedTask;
}
@@ -42,7 +42,7 @@ public sealed class RtcBridgeService
if (string.IsNullOrWhiteSpace(channelId))
return;
_socket.SendRaw($"RTC_LEAVE_CHANNEL|{_username}|{channelId}");
_socket.SendRtcLeaveChannel(channelId);
}
public void SendRtcSignal(string json)