Compare commits
10 Commits
5486795f4d
...
RTC-Rewrit
| Author | SHA1 | Date | |
|---|---|---|---|
| 87ade75f1d | |||
| 798652cb4d | |||
| 6a650a282b | |||
| 5b10afcec2 | |||
| 1220654656 | |||
| be797c55c2 | |||
| 20e99fefec | |||
| f77a5eb823 | |||
| d6ecb63b5f | |||
| 687387b105 |
@@ -1,17 +1,17 @@
|
|||||||
using RelayClient.Crypto;
|
using System.Text.Json.Serialization;
|
||||||
using WebSocketSharp;
|
using RelayClient.Crypto;
|
||||||
using System.Text.Json;
|
using RelayClient.Services;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
using RelayShared.Rtc;
|
using RelayShared.Rtc;
|
||||||
|
using RelayShared.Services;
|
||||||
|
|
||||||
namespace RelayClient;
|
namespace RelayClient;
|
||||||
|
|
||||||
|
|
||||||
public partial class MainPage : ContentPage
|
public partial class MainPage : ContentPage
|
||||||
{
|
{
|
||||||
private readonly string _username;
|
private readonly string _username;
|
||||||
private readonly WebSocket _wsc;
|
private readonly RelaySocketClient _socket;
|
||||||
private string? _serverPublicKey;
|
private readonly RtcBridgeService _rtc;
|
||||||
|
|
||||||
private string? _currentChannelId;
|
private string? _currentChannelId;
|
||||||
private string? _currentChannelName;
|
private string? _currentChannelName;
|
||||||
|
|
||||||
@@ -32,19 +32,31 @@ public partial class MainPage : ContentPage
|
|||||||
KeyStorage.SavePublicKey(_username, keys.publicKey);
|
KeyStorage.SavePublicKey(_username, keys.publicKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
_wsc = new WebSocket("ws://localhost:1337/");
|
|
||||||
|
|
||||||
_wsc.OnMessage += WscOnMessage;
|
|
||||||
_wsc.Connect();
|
|
||||||
|
|
||||||
var publicKey = KeyStorage.LoadPublicKey(_username);
|
|
||||||
_wsc.Send($"REGISTER_KEY|{_username}|{publicKey}");
|
|
||||||
_wsc.Send("GET_SERVER_KEY");
|
|
||||||
_wsc.Send("GET_CHANNELS");
|
|
||||||
|
|
||||||
hybridWebView.SetInvokeJavaScriptTarget(this);
|
|
||||||
ServerAPI.setupClient();
|
ServerAPI.setupClient();
|
||||||
|
|
||||||
|
_socket = new RelaySocketClient(_username);
|
||||||
|
_rtc = new RtcBridgeService(
|
||||||
|
_username,
|
||||||
|
_socket,
|
||||||
|
hybridWebView,
|
||||||
|
() => _currentChannelId,
|
||||||
|
SafeSendRawToWebView
|
||||||
|
);
|
||||||
|
|
||||||
|
hybridWebView.SetInvokeJavaScriptTarget(_rtc);
|
||||||
|
|
||||||
|
_socket.Log += Console.WriteLine;
|
||||||
|
_socket.ChannelListReceived += HandleChannelList;
|
||||||
|
_socket.EncryptedChatReceived += HandleEncryptedChat;
|
||||||
|
_socket.EncryptedRtcSignalReceived += payload =>
|
||||||
|
{
|
||||||
|
MainThread.BeginInvokeOnMainThread(async () =>
|
||||||
|
{
|
||||||
|
await _rtc.HandleIncomingRtcSignalAsync(payload);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
_socket.Connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SendButton_OnClicked(object? sender, EventArgs e)
|
private void SendButton_OnClicked(object? sender, EventArgs e)
|
||||||
@@ -64,7 +76,7 @@ public partial class MainPage : ContentPage
|
|||||||
if (string.IsNullOrWhiteSpace(text))
|
if (string.IsNullOrWhiteSpace(text))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(_serverPublicKey))
|
if (string.IsNullOrWhiteSpace(_socket.ServerPublicKey))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Server public key not loaded yet.");
|
Console.WriteLine("Server public key not loaded yet.");
|
||||||
return;
|
return;
|
||||||
@@ -76,7 +88,7 @@ public partial class MainPage : ContentPage
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var encrypted = E2EeHelper.EncryptForRecipient(text, _serverPublicKey);
|
var encrypted = E2EeHelper.EncryptForRecipient(text, _socket.ServerPublicKey);
|
||||||
|
|
||||||
var payload = new SocketEncryptedMessage
|
var payload = new SocketEncryptedMessage
|
||||||
{
|
{
|
||||||
@@ -89,8 +101,7 @@ public partial class MainPage : ContentPage
|
|||||||
EncryptedKey = encrypted.EncryptedKey
|
EncryptedKey = encrypted.EncryptedKey
|
||||||
};
|
};
|
||||||
|
|
||||||
var json = JsonSerializer.Serialize(payload);
|
_socket.SendJson(payload);
|
||||||
_wsc.Send(json);
|
|
||||||
|
|
||||||
Console.WriteLine($"[{_username}] sent encrypted message.");
|
Console.WriteLine($"[{_username}] sent encrypted message.");
|
||||||
|
|
||||||
@@ -98,34 +109,8 @@ public partial class MainPage : ContentPage
|
|||||||
MessageEntry.Focus();
|
MessageEntry.Focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WscOnMessage(object? sender, MessageEventArgs e)
|
private void HandleChannelList(SocketChannelList channelList)
|
||||||
{
|
{
|
||||||
if (e.Data.StartsWith("SERVER:REGISTERED_KEY:"))
|
|
||||||
{
|
|
||||||
Console.WriteLine(e.Data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// SafeSendRawToWebView($"[{_username}] RAW WS DATA: {e.Data}");
|
|
||||||
|
|
||||||
Console.WriteLine($"[{_username}] RAW WS DATA: {e.Data}");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
using var doc = JsonDocument.Parse(e.Data);
|
|
||||||
var root = doc.RootElement;
|
|
||||||
|
|
||||||
if (!root.TryGetProperty("Type", out var typeElement))
|
|
||||||
return;
|
|
||||||
|
|
||||||
var type = (SignalType) typeElement.GetInt32();
|
|
||||||
|
|
||||||
if (type == SignalType.ChannelList)
|
|
||||||
{
|
|
||||||
var channelList = JsonSerializer.Deserialize<SocketChannelList>(e.Data);
|
|
||||||
if (channelList is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_channels.Clear();
|
_channels.Clear();
|
||||||
_channels.AddRange(channelList.Channels.OrderBy(c => c.CreatedAt));
|
_channels.AddRange(channelList.Channels.OrderBy(c => c.CreatedAt));
|
||||||
|
|
||||||
@@ -135,8 +120,8 @@ public partial class MainPage : ContentPage
|
|||||||
.FirstOrDefault()
|
.FirstOrDefault()
|
||||||
?? _channels.OrderBy(c => c.CreatedAt).FirstOrDefault();
|
?? _channels.OrderBy(c => c.CreatedAt).FirstOrDefault();
|
||||||
|
|
||||||
if (defaultChannel is not null)
|
if (defaultChannel is null) return;
|
||||||
{
|
|
||||||
_currentChannelId = defaultChannel.ChannelId;
|
_currentChannelId = defaultChannel.ChannelId;
|
||||||
_currentChannelName = defaultChannel.Name;
|
_currentChannelName = defaultChannel.Name;
|
||||||
|
|
||||||
@@ -144,42 +129,23 @@ public partial class MainPage : ContentPage
|
|||||||
{
|
{
|
||||||
ChannelLabel.Text = $"#{_currentChannelName}";
|
ChannelLabel.Text = $"#{_currentChannelName}";
|
||||||
RenderChannelList();
|
RenderChannelList();
|
||||||
await PushRtcContextToJsAsync();
|
await _rtc.PushRtcContextToJsAsync();
|
||||||
});
|
});
|
||||||
|
|
||||||
_wsc.Send($"GET_HISTORY|{_username}|{_currentChannelId}");
|
_socket.SendRaw($"GET_HISTORY|{_username}|{_currentChannelId}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void HandleEncryptedChat(SocketEncryptedMessage payload) {
|
||||||
|
if (payload.RecipientUsername != _username)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (type == SignalType.ServerPublicKey)
|
string decryptedText;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var serverKeyMessage = JsonSerializer.Deserialize<ServerPublicKeyMessage>(e.Data);
|
|
||||||
if (serverKeyMessage is not null)
|
|
||||||
{
|
|
||||||
_serverPublicKey = serverKeyMessage.PublicKey;
|
|
||||||
Console.WriteLine($"[{_username}] loaded server public key.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == SignalType.EncryptedSignal)
|
|
||||||
{
|
|
||||||
var payload = JsonSerializer.Deserialize<SocketRtcSignalMessage>(e.Data);
|
|
||||||
if (payload is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (payload.ChannelId != _currentChannelId)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (payload.SenderUsername == _username)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var privateKey = KeyStorage.LoadPrivateKey(_username);
|
var privateKey = KeyStorage.LoadPrivateKey(_username);
|
||||||
|
|
||||||
var decryptedJson = E2EeHelper.DecryptForRecipient(
|
decryptedText = E2EeHelper.DecryptForRecipient(
|
||||||
new EncryptedPayload
|
new EncryptedPayload
|
||||||
{
|
{
|
||||||
CipherText = payload.CipherText,
|
CipherText = payload.CipherText,
|
||||||
@@ -189,140 +155,26 @@ public partial class MainPage : ContentPage
|
|||||||
},
|
},
|
||||||
privateKey
|
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 () =>
|
|
||||||
{
|
|
||||||
await SendRtcSignalToJsAsync(decryptedJson);
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type is SignalType.OfferUpdated or SignalType.AnswerUpdated or SignalType.CandidateAdded or SignalType.CallLeft)
|
|
||||||
{
|
|
||||||
var rtcNotification = JsonSerializer.Deserialize<RtcNotificationMessage>(e.Data);
|
|
||||||
if (rtcNotification is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var notificationType = rtcNotification.Type;
|
|
||||||
var notificationChannelId = rtcNotification.ChannelId ?? string.Empty;
|
|
||||||
|
|
||||||
if (notificationChannelId != _currentChannelId)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// SafeSendRawToWebView("RTC notification received: " + notificationType + " for " + notificationChannelId);
|
|
||||||
|
|
||||||
MainThread.BeginInvokeOnMainThread(async () =>
|
|
||||||
{
|
|
||||||
switch (notificationType)
|
|
||||||
{
|
|
||||||
case SignalType.OfferUpdated:
|
|
||||||
{
|
|
||||||
if (rtcNotification.Username == _username)
|
|
||||||
break;
|
|
||||||
|
|
||||||
var offer = await GetRtcOffer();
|
|
||||||
await SendRtcSignalToJsAsync(offer);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SignalType.AnswerUpdated:
|
|
||||||
{
|
|
||||||
var answer = await ServerAPI.GetAnswerForChannelAsync(_currentChannelId);
|
|
||||||
if (answer is not null)
|
|
||||||
{
|
|
||||||
await AnswerCallback(answer);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SignalType.CandidateAdded:
|
|
||||||
{
|
|
||||||
if (rtcNotification.Username == _username)
|
|
||||||
break;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
IceCandidate? iceCandidate = JsonSerializer.Deserialize<IceCandidate>(rtcNotification.Direction);
|
|
||||||
|
|
||||||
if (iceCandidate is null)
|
|
||||||
break;
|
|
||||||
|
|
||||||
IceCandidateCallback(iceCandidate);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
SafeSendRawToWebView($"Candidate rejected: {ex.Message}");
|
Console.WriteLine($"[{_username}] failed to decrypt chat: {ex.Message}");
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SignalType.CallLeft:
|
|
||||||
{
|
|
||||||
SafeSendRawToWebView("RTC call left notification received.");
|
|
||||||
RtcLeaveCallback();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type != SignalType.EncryptedChat)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var pyload = JsonSerializer.Deserialize<SocketEncryptedMessage>(e.Data);
|
|
||||||
if (pyload is null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (pyload.RecipientUsername != _username)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Console.WriteLine($"[{_username}] received encrypted payload for {pyload.RecipientUsername}");
|
|
||||||
|
|
||||||
var privKey = KeyStorage.LoadPrivateKey(_username);
|
|
||||||
|
|
||||||
var decryptedText = E2EeHelper.DecryptForRecipient(
|
|
||||||
new EncryptedPayload
|
|
||||||
{
|
|
||||||
CipherText = pyload.CipherText,
|
|
||||||
Nonce = pyload.Nonce,
|
|
||||||
Tag = pyload.Tag,
|
|
||||||
EncryptedKey = pyload.EncryptedKey
|
|
||||||
},
|
|
||||||
privKey
|
|
||||||
);
|
|
||||||
|
|
||||||
Console.WriteLine($"[{_username}] decrypted message from {pyload.SenderUsername}: {decryptedText}");
|
|
||||||
|
|
||||||
var message = new ChatMessage
|
var message = new ChatMessage
|
||||||
{
|
{
|
||||||
SenderUsername = pyload.SenderUsername,
|
SenderUsername = payload.SenderUsername,
|
||||||
Text = decryptedText,
|
Text = decryptedText,
|
||||||
Timestamp = DateTime.Now
|
Timestamp = DateTime.Now
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!_messagesByChannel.ContainsKey(pyload.ChannelId))
|
if (!_messagesByChannel.ContainsKey(payload.ChannelId))
|
||||||
{
|
_messagesByChannel[payload.ChannelId] = [];
|
||||||
_messagesByChannel[pyload.ChannelId] = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
_messagesByChannel[pyload.ChannelId].Add(message);
|
_messagesByChannel[payload.ChannelId].Add(message);
|
||||||
|
|
||||||
if (pyload.ChannelId == _currentChannelId)
|
if (payload.ChannelId == _currentChannelId)
|
||||||
{
|
{
|
||||||
MainThread.BeginInvokeOnMainThread(() =>
|
MainThread.BeginInvokeOnMainThread(() =>
|
||||||
{
|
{
|
||||||
@@ -330,16 +182,10 @@ public partial class MainPage : ContentPage
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"[{_username}] failed to process websocket message: {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnDisappearing()
|
protected override void OnDisappearing()
|
||||||
{
|
{
|
||||||
_wsc.OnMessage -= WscOnMessage;
|
_socket.Disconnect();
|
||||||
_wsc.Close();
|
|
||||||
base.OnDisappearing();
|
base.OnDisappearing();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,11 +209,14 @@ public partial class MainPage : ContentPage
|
|||||||
|
|
||||||
MainThread.BeginInvokeOnMainThread(async () =>
|
MainThread.BeginInvokeOnMainThread(async () =>
|
||||||
{
|
{
|
||||||
await PushRtcContextToJsAsync();
|
await _rtc.PushRtcContextToJsAsync();
|
||||||
|
|
||||||
if (channel.Type == ChannelType.Voice)
|
if (channel.Type == ChannelType.Voice)
|
||||||
{
|
{
|
||||||
|
if (!RtcView.IsVisible)
|
||||||
SwapView();
|
SwapView();
|
||||||
// JoinRtcChannel(); //TODO: Join voice calls when clicking channel rather than a separate button
|
|
||||||
|
_ = _rtc.JoinRtcChannel();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -375,9 +224,7 @@ public partial class MainPage : ContentPage
|
|||||||
RenderCurrentChannelMessages();
|
RenderCurrentChannelMessages();
|
||||||
|
|
||||||
if (!_messagesByChannel.ContainsKey(channel.ChannelId))
|
if (!_messagesByChannel.ContainsKey(channel.ChannelId))
|
||||||
{
|
_socket.SendRaw($"GET_HISTORY|{_username}|{channel.ChannelId}");
|
||||||
_wsc.Send($"GET_HISTORY|{_username}|{channel.ChannelId}");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
SidebarList.Children.Add(button);
|
SidebarList.Children.Add(button);
|
||||||
@@ -402,7 +249,7 @@ public partial class MainPage : ContentPage
|
|||||||
|
|
||||||
private async void RenderSingleMessage(ChatMessage message)
|
private async void RenderSingleMessage(ChatMessage message)
|
||||||
{
|
{
|
||||||
bool isOwnMessage = message.SenderUsername == _username;
|
var isOwnMessage = message.SenderUsername == _username;
|
||||||
|
|
||||||
var bubble = new Border
|
var bubble = new Border
|
||||||
{
|
{
|
||||||
@@ -437,7 +284,6 @@ public partial class MainPage : ContentPage
|
|||||||
MessagesScrollView.IsVisible = true;
|
MessagesScrollView.IsVisible = true;
|
||||||
RtcView.IsVisible = false;
|
RtcView.IsVisible = false;
|
||||||
ViewSwapped.Text = "Swap to Web View";
|
ViewSwapped.Text = "Swap to Web View";
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -446,254 +292,17 @@ public partial class MainPage : ContentPage
|
|||||||
ViewSwapped.Text = "Swap to Message View";
|
ViewSwapped.Text = "Swap to Message View";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SwapView_OnClicked(object? sender, EventArgs e)
|
private void SwapView_OnClicked(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
SwapView();
|
SwapView();
|
||||||
}
|
}
|
||||||
|
|
||||||
#region RTC Functions
|
|
||||||
public async Task JoinRtcChannel()
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(_currentChannelId))
|
|
||||||
return; //false;
|
|
||||||
|
|
||||||
_wsc.Send($"RTC_JOIN_CHANNEL|{_username}|{_currentChannelId}");
|
|
||||||
|
|
||||||
// SafeSendRawToWebView($"Attempting to join RTC Channel {_currentChannelName} | {_currentChannelId} ");
|
|
||||||
|
|
||||||
//bool active = await ServerAPI.GetIsChannelActiveAsync(_currentChannelId);
|
|
||||||
|
|
||||||
//SafeSendRawToWebView($"Rtc Channel {_currentChannelName} | {_currentChannelId} is active: {active}");
|
|
||||||
|
|
||||||
return; //active;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LeaveRtcChannel()
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(_currentChannelId))
|
|
||||||
return;
|
|
||||||
|
|
||||||
_wsc.Send($"RTC_LEAVE_CHANNEL|{_username}|{_currentChannelId}");
|
|
||||||
}
|
|
||||||
|
|
||||||
public async void WriteRtcOffer(string json)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
RtcDescription? description = JsonSerializer.Deserialize<RtcDescription>(json);
|
|
||||||
DBOffer offer = new DBOffer
|
|
||||||
{
|
|
||||||
ChannelId = _currentChannelId,
|
|
||||||
Username = _username,
|
|
||||||
SessionDescription = description
|
|
||||||
};
|
|
||||||
var response = await ServerAPI.PostOfferAsync(offer);
|
|
||||||
SafeSendRawToWebView(response.ToString());
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
SafeSendRawToWebView($"WriteRtcOffer failed: {ex.Message}");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
public async Task<string> GetRtcOffer()
|
|
||||||
{
|
|
||||||
RtcDescription? offer = await ServerAPI.GetOffersForChannelAsync(_currentChannelId);
|
|
||||||
return JsonSerializer.Serialize(offer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async void WriteRtcAnswer(string json)
|
|
||||||
{
|
|
||||||
// SafeSendRawToWebView("WriteRtcAnswer entered with: " + json);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
RtcDescription? description = JsonSerializer.Deserialize<RtcDescription>(json);
|
|
||||||
DBOffer answer = new DBOffer
|
|
||||||
{
|
|
||||||
ChannelId = _currentChannelId,
|
|
||||||
Username = _username,
|
|
||||||
SessionDescription = description
|
|
||||||
};
|
|
||||||
await ServerAPI.PostAnswerAsync(answer);
|
|
||||||
SafeSendRawToWebView("WriteRtcAnswer posted successfully");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
SafeSendRawToWebView("WriteRtcAnswer failed: " + ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async void WriteIceCandidate(string json)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
IceCandidate? candidate = JsonSerializer.Deserialize<IceCandidate>(json);
|
|
||||||
DBIceCandidate DBCandidate = new DBIceCandidate
|
|
||||||
{
|
|
||||||
ChannelId = _currentChannelId,
|
|
||||||
Username = _username,
|
|
||||||
Candidate = candidate
|
|
||||||
};
|
|
||||||
if (candidate == null) return;
|
|
||||||
await ServerAPI.PostIceCandidateAsync(DBCandidate);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
SafeSendRawToWebView("WriteIceCandidate failed: " + ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async void IceCandidateCallback(IceCandidate candidate)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await hybridWebView.InvokeJavaScriptAsync("IceCandidateAdded", [candidate], [HybridJSType.Default.IceCandidate]);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
SafeSendRawToWebView("WriteIceCandidate failed: " + ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public async Task AnswerCallback(RtcDescription answer)
|
|
||||||
{
|
|
||||||
answer.sdp = answer.sdp.Replace("\r\n", "(rn)");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await hybridWebView.InvokeJavaScriptAsync("AnswerCallbackJS", [answer], [HybridJSType.Default.RtcDescription]);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
SafeSendRawToWebView("AnswerCallback failed: " + ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async void RtcLeaveCallback()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await hybridWebView.InvokeJavaScriptAsync("RtcLeaveCall", [], []);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
SafeSendRawToWebView("RtcLeaveCallback failed: " + ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Task SendRtcSignalToJsAsync(string rawJson)
|
|
||||||
{
|
|
||||||
MainThread.BeginInvokeOnMainThread(async () =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
SafeSendRawToWebView("Dispatching RTC signal to JS");
|
|
||||||
|
|
||||||
var jsArg = JsonSerializer.Serialize(rawJson);
|
|
||||||
|
|
||||||
await hybridWebView.EvaluateJavaScriptAsync(
|
|
||||||
$"window.RelaySocket.receiveRtcSignal({jsArg})"
|
|
||||||
);
|
|
||||||
|
|
||||||
SafeSendRawToWebView("RTC signal dispatched to JS");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
SafeSendRawToWebView("SendRtcSignalToJsAsync failed: " + ex.Message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
|
||||||
} //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)
|
|
||||||
{
|
|
||||||
SafeSendRawToWebView("SendRtcSignal entered: " + json);
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(_serverPublicKey))
|
|
||||||
{
|
|
||||||
SafeSendRawToWebView("SendRtcSignal failed: server public key not loaded.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
RtcSignalMessage? rtcSignal;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
rtcSignal = JsonSerializer.Deserialize<RtcSignalMessage>(json);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
SafeSendRawToWebView("SendRtcSignal failed to parse RTC signal: " + ex.Message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rtcSignal is null)
|
|
||||||
{
|
|
||||||
SafeSendRawToWebView("SendRtcSignal failed: rtcSignal was null.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
var participants = await ServerAPI.GetRtcParticipantsAsync(_currentChannelId);
|
|
||||||
return JsonSerializer.Serialize(participants);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
private void OnSendMessageButtonClicked(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
SafeSendRawToWebView($"Hello from C#!");
|
|
||||||
}
|
|
||||||
|
|
||||||
private async void OnHybridWebViewRawMessageReceived(object sender, HybridWebViewRawMessageReceivedEventArgs e)
|
private async void OnHybridWebViewRawMessageReceived(object sender, HybridWebViewRawMessageReceivedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Message == "rtc_page_ready")
|
if (e.Message == "rtc_page_ready")
|
||||||
{
|
{
|
||||||
await PushRtcContextToJsAsync();
|
await _rtc.PushRtcContextToJsAsync();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -718,7 +327,7 @@ public partial class MainPage : ContentPage
|
|||||||
public class ChannelButton : Button
|
public class ChannelButton : Button
|
||||||
{
|
{
|
||||||
public ChannelType Type { get; set; }
|
public ChannelType Type { get; set; }
|
||||||
public string Group { get; set; }
|
public string Group { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonSourceGenerationOptions(WriteIndented = false)]
|
[JsonSourceGenerationOptions(WriteIndented = false)]
|
||||||
@@ -729,8 +338,5 @@ public partial class MainPage : ContentPage
|
|||||||
[JsonSerializable(typeof(string))]
|
[JsonSerializable(typeof(string))]
|
||||||
internal partial class HybridJSType : JsonSerializerContext
|
internal partial class HybridJSType : JsonSerializerContext
|
||||||
{
|
{
|
||||||
// This type's attributes specify JSON serialization info to preserve type structure
|
|
||||||
// for trimmed builds.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,11 +5,8 @@ namespace RelayClient;
|
|||||||
|
|
||||||
public static class MauiProgram
|
public static class MauiProgram
|
||||||
{
|
{
|
||||||
// public static event Action<ChatMessage>? MessageSent;
|
|
||||||
public static MauiApp CreateMauiApp()
|
public static MauiApp CreateMauiApp()
|
||||||
{
|
{
|
||||||
//wsc.OnMessage += (sender, e) => OnWebSocketRecieved(sender, e);
|
|
||||||
//wsc.Connect();
|
|
||||||
var builder = MauiApp.CreateBuilder();
|
var builder = MauiApp.CreateBuilder();
|
||||||
builder.UseMauiApp<App>().ConfigureFonts(fonts =>
|
builder.UseMauiApp<App>().ConfigureFonts(fonts =>
|
||||||
{
|
{
|
||||||
@@ -19,8 +16,6 @@ public static class MauiProgram
|
|||||||
fonts.AddFont("AnonymousPro-Regular.ttf", "AnonymousProRegular");
|
fonts.AddFont("AnonymousPro-Regular.ttf", "AnonymousProRegular");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
builder.Services.AddHybridWebViewDeveloperTools();
|
builder.Services.AddHybridWebViewDeveloperTools();
|
||||||
builder.Logging.AddDebug();
|
builder.Logging.AddDebug();
|
||||||
@@ -28,19 +23,4 @@ public static class MauiProgram
|
|||||||
|
|
||||||
return builder.Build();
|
return builder.Build();
|
||||||
}
|
}
|
||||||
|
|
||||||
//public static void OnWebSocketRecieved(object? sender, MessageEventArgs e)
|
|
||||||
//{
|
|
||||||
// Console.WriteLine(sender.ToString());
|
|
||||||
//
|
|
||||||
// ChatSimulator.Send(e.Data.Split(":")[0], e.Data.Split(":")[1]);
|
|
||||||
// // var message = new ChatMessage
|
|
||||||
// // {
|
|
||||||
// // SenderUsername = e.Data.Split(":")[0],
|
|
||||||
// // Text = e.Data.Split(":")[1],
|
|
||||||
// // Timestamp = DateTime.Now
|
|
||||||
// // };
|
|
||||||
// //
|
|
||||||
// // MessageSent?.Invoke(message);
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
127
RelayClient/Services/RelaySocketClient.cs
Normal file
127
RelayClient/Services/RelaySocketClient.cs
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using RelayClient.Crypto;
|
||||||
|
using RelayShared.Services;
|
||||||
|
using WebSocketSharp;
|
||||||
|
|
||||||
|
namespace RelayClient.Services;
|
||||||
|
|
||||||
|
public sealed class RelaySocketClient
|
||||||
|
{
|
||||||
|
private readonly string _username;
|
||||||
|
private readonly WebSocket _socket;
|
||||||
|
|
||||||
|
public string? ServerPublicKey { get; private set; }
|
||||||
|
|
||||||
|
public event Action<string>? RawMessageReceived;
|
||||||
|
public event Action<SocketChannelList>? ChannelListReceived;
|
||||||
|
public event Action<SocketEncryptedMessage>? EncryptedChatReceived;
|
||||||
|
public event Action<SocketRtcSignalMessage>? EncryptedRtcSignalReceived;
|
||||||
|
public event Action<string>? ServerPublicKeyReceived;
|
||||||
|
public event Action<string>? Log;
|
||||||
|
|
||||||
|
public RelaySocketClient(string username, string url = "ws://localhost:1337/")
|
||||||
|
{
|
||||||
|
_username = username;
|
||||||
|
_socket = new WebSocket(url);
|
||||||
|
_socket.OnMessage += OnMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Connect()
|
||||||
|
{
|
||||||
|
_socket.Connect();
|
||||||
|
|
||||||
|
var publicKey = KeyStorage.LoadPublicKey(_username);
|
||||||
|
|
||||||
|
SendRaw($"REGISTER_KEY|{_username}|{publicKey}");
|
||||||
|
SendRaw("GET_SERVER_KEY");
|
||||||
|
SendRaw("GET_CHANNELS");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SendRaw(string message)
|
||||||
|
{
|
||||||
|
if (_socket.ReadyState == WebSocketState.Open)
|
||||||
|
_socket.Send(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SendJson<T>(T payload)
|
||||||
|
{
|
||||||
|
SendRaw(JsonSerializer.Serialize(payload));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Disconnect()
|
||||||
|
{
|
||||||
|
_socket.OnMessage -= OnMessage;
|
||||||
|
|
||||||
|
if (_socket.ReadyState == WebSocketState.Open)
|
||||||
|
_socket.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
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}");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var doc = JsonDocument.Parse(e.Data);
|
||||||
|
var root = doc.RootElement;
|
||||||
|
|
||||||
|
if (!root.TryGetProperty("Type", out var typeElement))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var type = (SignalType)typeElement.GetInt32();
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case SignalType.ChannelList:
|
||||||
|
{
|
||||||
|
var channelList = JsonSerializer.Deserialize<SocketChannelList>(e.Data);
|
||||||
|
if (channelList is not null)
|
||||||
|
ChannelListReceived?.Invoke(channelList);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
case SignalType.ServerPublicKey:
|
||||||
|
{
|
||||||
|
var serverKeyMessage = JsonSerializer.Deserialize<ServerPublicKeyMessage>(e.Data);
|
||||||
|
if (serverKeyMessage is not null)
|
||||||
|
{
|
||||||
|
ServerPublicKey = serverKeyMessage.PublicKey;
|
||||||
|
ServerPublicKeyReceived?.Invoke(serverKeyMessage.PublicKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
case SignalType.EncryptedSignal:
|
||||||
|
{
|
||||||
|
var payload = JsonSerializer.Deserialize<SocketRtcSignalMessage>(e.Data);
|
||||||
|
if (payload is not null)
|
||||||
|
EncryptedRtcSignalReceived?.Invoke(payload);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
case SignalType.EncryptedChat:
|
||||||
|
{
|
||||||
|
var payload = JsonSerializer.Deserialize<SocketEncryptedMessage>(e.Data);
|
||||||
|
if (payload is not null)
|
||||||
|
EncryptedChatReceived?.Invoke(payload);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log?.Invoke($"[{_username}] failed to process websocket message: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
224
RelayClient/Services/RtcBridgeService.cs
Normal file
224
RelayClient/Services/RtcBridgeService.cs
Normal file
@@ -0,0 +1,224 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using RelayClient.Crypto;
|
||||||
|
using RelayShared.Rtc;
|
||||||
|
using RelayShared.Services;
|
||||||
|
|
||||||
|
namespace RelayClient.Services;
|
||||||
|
|
||||||
|
public sealed class RtcBridgeService
|
||||||
|
{
|
||||||
|
private readonly string _username;
|
||||||
|
private readonly RelaySocketClient _socket;
|
||||||
|
private readonly HybridWebView _hybridWebView;
|
||||||
|
private readonly Func<string?> _getCurrentChannelId;
|
||||||
|
private readonly Action<string> _sendRawToWebView;
|
||||||
|
|
||||||
|
public RtcBridgeService(string username, RelaySocketClient socket, HybridWebView hybridWebView,
|
||||||
|
Func<string?> getCurrentChannelId, Action<string> sendRawToWebView)
|
||||||
|
{
|
||||||
|
_username = username;
|
||||||
|
_socket = socket;
|
||||||
|
_hybridWebView = hybridWebView;
|
||||||
|
_getCurrentChannelId = getCurrentChannelId;
|
||||||
|
_sendRawToWebView = sendRawToWebView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task JoinRtcChannel()
|
||||||
|
{
|
||||||
|
var channelId = _getCurrentChannelId();
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(channelId))
|
||||||
|
return Task.CompletedTask;
|
||||||
|
|
||||||
|
_socket.SendRaw($"RTC_JOIN_CHANNEL|{_username}|{channelId}");
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LeaveRtcChannel()
|
||||||
|
{
|
||||||
|
var channelId = _getCurrentChannelId();
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(channelId))
|
||||||
|
return;
|
||||||
|
|
||||||
|
_socket.SendRaw($"RTC_LEAVE_CHANNEL|{_username}|{channelId}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SendRtcSignal(string json)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(_socket.ServerPublicKey))
|
||||||
|
{
|
||||||
|
_sendRawToWebView("SendRtcSignal failed: server public key not loaded.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RtcSignalMessage? rtcSignal;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rtcSignal = JsonSerializer.Deserialize<RtcSignalMessage>(json);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_sendRawToWebView("SendRtcSignal failed to parse RTC signal: " + ex.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rtcSignal is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
rtcSignal.ChannelId ??= _getCurrentChannelId();
|
||||||
|
rtcSignal.From ??= _username;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(rtcSignal.ChannelId))
|
||||||
|
{
|
||||||
|
_sendRawToWebView("SendRtcSignal failed: missing channel id.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var outgoingJson = JsonSerializer.Serialize(rtcSignal);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var encrypted = E2EeHelper.EncryptForRecipient(outgoingJson, _socket.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
|
||||||
|
};
|
||||||
|
|
||||||
|
_socket.SendJson(payload);
|
||||||
|
|
||||||
|
_sendRawToWebView($"SendRtcSignal sent: {rtcSignal.Type} -> {rtcSignal.To}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_sendRawToWebView("SendRtcSignal failed: " + ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<string> GetRtcParticipants()
|
||||||
|
{
|
||||||
|
var channelId = _getCurrentChannelId();
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(channelId))
|
||||||
|
return "[]";
|
||||||
|
|
||||||
|
var participants = await ServerAPI.GetRtcParticipantsAsync(channelId);
|
||||||
|
return JsonSerializer.Serialize(participants ?? []);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task HandleIncomingRtcSignalAsync(SocketRtcSignalMessage payload)
|
||||||
|
{
|
||||||
|
var currentChannelId = _getCurrentChannelId();
|
||||||
|
|
||||||
|
if (payload.ChannelId != currentChannelId)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (payload.SenderUsername == _username)
|
||||||
|
return;
|
||||||
|
|
||||||
|
string decryptedJson;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var privateKey = KeyStorage.LoadPrivateKey(_username);
|
||||||
|
|
||||||
|
decryptedJson = E2EeHelper.DecryptForRecipient(
|
||||||
|
new EncryptedPayload
|
||||||
|
{
|
||||||
|
CipherText = payload.CipherText,
|
||||||
|
Nonce = payload.Nonce,
|
||||||
|
Tag = payload.Tag,
|
||||||
|
EncryptedKey = payload.EncryptedKey
|
||||||
|
},
|
||||||
|
privateKey
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_sendRawToWebView("RTC decrypt failed: " + ex.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RtcSignalMessage? rtcSignal;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rtcSignal = JsonSerializer.Deserialize<RtcSignalMessage>(decryptedJson);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_sendRawToWebView("RTC signal parse failed: " + ex.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rtcSignal is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(rtcSignal.To) &&
|
||||||
|
!string.Equals(rtcSignal.To, _username, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
_sendRawToWebView($"Ignoring RTC signal meant for {rtcSignal.To}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_sendRawToWebView("Received encrypted RTC signal: " + decryptedJson);
|
||||||
|
|
||||||
|
await SendRtcSignalToJsAsync(decryptedJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task PushRtcContextToJsAsync()
|
||||||
|
{
|
||||||
|
MainThread.BeginInvokeOnMainThread(async () =>
|
||||||
|
{
|
||||||
|
var usernameJson = JsonSerializer.Serialize(_username);
|
||||||
|
var channelIdJson = JsonSerializer.Serialize(_getCurrentChannelId());
|
||||||
|
|
||||||
|
await _hybridWebView.EvaluateJavaScriptAsync($"window.setUsername({usernameJson})");
|
||||||
|
await _hybridWebView.EvaluateJavaScriptAsync($"window.setChannelId({channelIdJson})");
|
||||||
|
});
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task SendRtcSignalToJsAsync(string rawJson)
|
||||||
|
{
|
||||||
|
MainThread.BeginInvokeOnMainThread(async () =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var jsArg = JsonSerializer.Serialize(rawJson);
|
||||||
|
|
||||||
|
await _hybridWebView.EvaluateJavaScriptAsync($@"
|
||||||
|
try {{
|
||||||
|
window.HybridWebView.SendRawMessage('C# eval entered');
|
||||||
|
|
||||||
|
if (!window.RelaySocket) {{
|
||||||
|
window.HybridWebView.SendRawMessage('window.RelaySocket missing');
|
||||||
|
}} else if (typeof window.RelaySocket.receiveRtcSignal !== 'function') {{
|
||||||
|
window.HybridWebView.SendRawMessage('RelaySocket.receiveRtcSignal missing');
|
||||||
|
}} else {{
|
||||||
|
window.HybridWebView.SendRawMessage('Calling RelaySocket.receiveRtcSignal');
|
||||||
|
window.RelaySocket.receiveRtcSignal({jsArg});
|
||||||
|
}}
|
||||||
|
}} catch (err) {{
|
||||||
|
window.HybridWebView.SendRawMessage('RTC JS dispatch failed: ' + err);
|
||||||
|
}}
|
||||||
|
");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_sendRawToWebView("SendRtcSignalToJsAsync failed: " + ex.Message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using RelayShared.Rtc;
|
using RelayShared.Rtc;
|
||||||
using RelayServer.Services.Rtc;
|
using RelayServer.Services.Rtc;
|
||||||
|
using RelayShared.Services;
|
||||||
|
|
||||||
namespace RelayServer.Endpoints;
|
namespace RelayServer.Endpoints;
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,4 @@
|
|||||||
<ProjectReference Include="..\RelayShared\RelayShared.csproj" />
|
<ProjectReference Include="..\RelayShared\RelayShared.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Models\Rtc\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using RelayServer.Services.Rtc;
|
|||||||
using WebSocketSharp;
|
using WebSocketSharp;
|
||||||
using WebSocketSharp.Server;
|
using WebSocketSharp.Server;
|
||||||
using ErrorEventArgs = WebSocketSharp.ErrorEventArgs;
|
using ErrorEventArgs = WebSocketSharp.ErrorEventArgs;
|
||||||
using RelayShared.Rtc;
|
using RelayShared.Services;
|
||||||
|
|
||||||
namespace RelayServer.Services.Chat;
|
namespace RelayServer.Services.Chat;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using RelayShared.Rtc;
|
using RelayShared.Rtc;
|
||||||
using SurrealDb.Net;
|
using SurrealDb.Net;
|
||||||
|
using RelayShared.Rtc;
|
||||||
|
|
||||||
namespace RelayServer.Services.Rtc;
|
namespace RelayServer.Services.Rtc;
|
||||||
|
|
||||||
|
|||||||
40
RelayShared/Rtc/RTCDatabase.cs
Normal file
40
RelayShared/Rtc/RTCDatabase.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using SurrealDb.Net.Models;
|
||||||
|
|
||||||
|
namespace RelayShared.Rtc;
|
||||||
|
|
||||||
|
public sealed class DBActiveCall : Record
|
||||||
|
{
|
||||||
|
public string ChannelId { get; set; } = string.Empty;
|
||||||
|
public string? OfferUser { get; set; }
|
||||||
|
public RtcSessionDescription? Offer { get; set; }
|
||||||
|
public RtcSessionDescription? Answer { get; set; }
|
||||||
|
public DateTime CreatedAt { get; set; }
|
||||||
|
public DateTime UpdatedAt { get; set; }
|
||||||
|
public bool IsActive { get; set; }
|
||||||
|
public string[] IceCandidates { get; set; } = []; //TODO: Should be array of DBIceCandidates IDs
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class DBOffer : Record
|
||||||
|
{
|
||||||
|
public string ChannelId { get; set; } = string.Empty;
|
||||||
|
public string Username { get; set; } = string.Empty;
|
||||||
|
public string Type { get; set; } = string.Empty;
|
||||||
|
public string Sdp { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
public sealed class DBAnswer : Record
|
||||||
|
{
|
||||||
|
public string ChannelId { get; set; } = string.Empty;
|
||||||
|
public string Username { get; set; } = string.Empty;
|
||||||
|
public string Type { get; set; } = string.Empty;
|
||||||
|
public string Sdp { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DBIceCandidate : Record
|
||||||
|
{
|
||||||
|
public required string ChannelId { get; set; }
|
||||||
|
public required string Username { get; set; }
|
||||||
|
public required string Candidate { get; set; }
|
||||||
|
public string? SdpMid { get; set; }
|
||||||
|
public int? SdpMLineIndex { get; set; }
|
||||||
|
public DateTime CreatedAt { get; set; }
|
||||||
|
}
|
||||||
93
RelayShared/Rtc/RTCTransmissions.cs
Normal file
93
RelayShared/Rtc/RTCTransmissions.cs
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using RelayShared.Services;
|
||||||
|
|
||||||
|
namespace RelayShared.Rtc;
|
||||||
|
|
||||||
|
public sealed class RtcSessionDescription
|
||||||
|
{
|
||||||
|
public string Type { get; set; } = string.Empty;
|
||||||
|
public string Sdp { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class RtcOffer
|
||||||
|
{
|
||||||
|
public string ChannelId { get; set; } = string.Empty;
|
||||||
|
public string Username { get; set; } = string.Empty;
|
||||||
|
public RtcSessionDescription SessionDescription { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class RtcAnswer
|
||||||
|
{
|
||||||
|
public string ChannelId { get; set; } = string.Empty;
|
||||||
|
public string Username { get; set; } = string.Empty;
|
||||||
|
public RtcSessionDescription SessionDescription { get; set; } = new();
|
||||||
|
}
|
||||||
|
public class RtcIceCandidate
|
||||||
|
{
|
||||||
|
public required string ChannelId { get; set; }
|
||||||
|
public required string Username { get; set; }
|
||||||
|
public required IceCandidate Candidate { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class IceCandidate
|
||||||
|
{
|
||||||
|
public required string candidate { get; set; }
|
||||||
|
public required string sdpMid { get; set; }
|
||||||
|
public required int sdpMLineIndex { get; set; }
|
||||||
|
public required string usernameFragment { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class RtcJoinRequest
|
||||||
|
{
|
||||||
|
public string ChannelId { get; set; } = string.Empty;
|
||||||
|
public string Username { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class RtcJoinResponse
|
||||||
|
{
|
||||||
|
public string ChannelId { get; set; } = string.Empty;
|
||||||
|
public string[] Participants { get; set; } = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class RtcLeaveRequest
|
||||||
|
{
|
||||||
|
public string ChannelId { get; set; } = string.Empty;
|
||||||
|
public string Username { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
public sealed class RtcNotificationMessage //TODO: Review for removal
|
||||||
|
{
|
||||||
|
public SignalType? Type { get; set; }
|
||||||
|
public string? ChannelId { get; set; }
|
||||||
|
public string? Username { get; set; }
|
||||||
|
public string? Direction { get; set; }
|
||||||
|
}
|
||||||
|
public sealed class RtcSignalMessage //TODO: Review for removal.
|
||||||
|
{
|
||||||
|
[JsonPropertyName("type")]
|
||||||
|
public string Type { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[JsonPropertyName("from")]
|
||||||
|
public string From { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[JsonPropertyName("to")]
|
||||||
|
public string To { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[JsonPropertyName("channelId")]
|
||||||
|
public string ChannelId { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[JsonPropertyName("sdp")]
|
||||||
|
public string? Sdp { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("candidate")]
|
||||||
|
public string? Candidate { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("sdpMid")]
|
||||||
|
public string? SdpMid { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("sdpMLineIndex")]
|
||||||
|
public int? SdpMLineIndex { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("isInitiator")]
|
||||||
|
public bool IsInitiator { get; set; }
|
||||||
|
}
|
||||||
@@ -1,198 +0,0 @@
|
|||||||
using System.Text.Json.Serialization;
|
|
||||||
using RelayShared.Rtc;
|
|
||||||
using SurrealDb.Net.Models;
|
|
||||||
|
|
||||||
#region Resharper Stuff
|
|
||||||
// ReSharper disable ClassNeverInstantiated.Global
|
|
||||||
// ReSharper disable PropertyCanBeMadeInitOnly.Global
|
|
||||||
// ReSharper disable InconsistentNaming
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
namespace RelayShared.Rtc;
|
|
||||||
|
|
||||||
public enum SignalType
|
|
||||||
{
|
|
||||||
Offer,
|
|
||||||
Answer,
|
|
||||||
Candidate,
|
|
||||||
OfferUpdated,
|
|
||||||
AnswerUpdated,
|
|
||||||
CandidateAdded,
|
|
||||||
CallLeft,
|
|
||||||
ChannelList,
|
|
||||||
ServerPublicKey,
|
|
||||||
EncryptedSignal,
|
|
||||||
EncryptedChat,
|
|
||||||
ClientEncryptedChat
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum ChannelType
|
|
||||||
{
|
|
||||||
Text, //Default channel type, handles text, links, files*, all in a linear live chat format
|
|
||||||
Voice, //Used for general voice and video calls, utilizes WebRTC in its intended use
|
|
||||||
File, //File browser for connected text channels, used for browsing files rather than scrolling through text channel
|
|
||||||
Forum, //Specific forum posts, meant to keep conversations grouped and on topic while keeping all in an easy to find place
|
|
||||||
Stage //Used for announcements and presentations, voice/video call utilizing a modified WebRTC protocol through server
|
|
||||||
}
|
|
||||||
public sealed class RtcSignalMessage
|
|
||||||
{
|
|
||||||
[JsonPropertyName("type")]
|
|
||||||
public string Type { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
[JsonPropertyName("from")]
|
|
||||||
public string From { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
[JsonPropertyName("to")]
|
|
||||||
public string To { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
[JsonPropertyName("channelId")]
|
|
||||||
public string ChannelId { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
[JsonPropertyName("sdp")]
|
|
||||||
public string? Sdp { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("candidate")]
|
|
||||||
public string? Candidate { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("sdpMid")]
|
|
||||||
public string? SdpMid { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("sdpMLineIndex")]
|
|
||||||
public int? SdpMLineIndex { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("isInitiator")]
|
|
||||||
public bool IsInitiator { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class RtcNotificationMessage
|
|
||||||
{
|
|
||||||
public SignalType? Type { get; set; }
|
|
||||||
public string? ChannelId { get; set; }
|
|
||||||
public string? Username { get; set; }
|
|
||||||
public string? Direction { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class ServerPublicKeyMessage
|
|
||||||
{
|
|
||||||
public SignalType Type { get; set; } = SignalType.ServerPublicKey;
|
|
||||||
public string PublicKey { get; set; } = string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class SocketRtcSignalMessage
|
|
||||||
{
|
|
||||||
public SignalType Type { get; set; }
|
|
||||||
public string SenderUsername { get; set; } = string.Empty;
|
|
||||||
public string ChannelId { get; set; } = string.Empty;
|
|
||||||
public string CipherText { get; set; } = string.Empty;
|
|
||||||
public string Nonce { get; set; } = string.Empty;
|
|
||||||
public string Tag { get; set; } = string.Empty;
|
|
||||||
public string EncryptedKey { get; set; } = string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class SocketEncryptedMessage
|
|
||||||
{
|
|
||||||
public SignalType Type { get; set; } = SignalType.EncryptedChat;
|
|
||||||
public string SenderUsername { get; set; } = string.Empty;
|
|
||||||
public string RecipientUsername { get; set; } = string.Empty;
|
|
||||||
public string ChannelId { get; set; } = string.Empty;
|
|
||||||
public string CipherText { get; set; } = string.Empty;
|
|
||||||
public string Nonce { get; set; } = string.Empty;
|
|
||||||
public string Tag { get; set; } = string.Empty;
|
|
||||||
public string EncryptedKey { get; set; } = string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class ChannelItem
|
|
||||||
{
|
|
||||||
public string ChannelId { get; set; } = string.Empty;
|
|
||||||
public string Name { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
public ChannelType Type { get; set; }
|
|
||||||
|
|
||||||
public string Group { get; set; } = string.Empty;
|
|
||||||
public DateTime CreatedAt { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class SocketChannelList
|
|
||||||
{
|
|
||||||
public SignalType Type { get; set; } = SignalType.ChannelList;
|
|
||||||
public List<ChannelItem> Channels { get; set; } = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class RtcJoinRequest
|
|
||||||
{
|
|
||||||
public string ChannelId { get; set; } = string.Empty;
|
|
||||||
public string Username { get; set; } = string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class RtcJoinResponse
|
|
||||||
{
|
|
||||||
public string ChannelId { get; set; } = string.Empty;
|
|
||||||
public bool HasActiveCall { get; set; }
|
|
||||||
public bool IsOfferer { get; set; }
|
|
||||||
public string? OfferUser { get; set; }
|
|
||||||
public RtcSessionDescription? OfferSdp { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class RtcLeaveRequest
|
|
||||||
{
|
|
||||||
public string ChannelId { get; set; } = string.Empty;
|
|
||||||
public string Username { get; set; } = string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class RtcSessionDescription
|
|
||||||
{
|
|
||||||
public string Type { get; set; } = string.Empty;
|
|
||||||
public string Sdp { get; set; } = string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class RtcOffer
|
|
||||||
{
|
|
||||||
public string ChannelId { get; set; } = string.Empty;
|
|
||||||
public string Username { get; set; } = string.Empty;
|
|
||||||
public RtcSessionDescription SessionDescription { get; set; } = new();
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class RtcAnswer
|
|
||||||
{
|
|
||||||
public string ChannelId { get; set; } = string.Empty;
|
|
||||||
public string Username { get; set; } = string.Empty;
|
|
||||||
public RtcSessionDescription SessionDescription { get; set; } = new();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DBIceCandidate : Record
|
|
||||||
{
|
|
||||||
public required string ChannelId { get; set; }
|
|
||||||
public required string Username { get; set; }
|
|
||||||
public required string Candidate { get; set; }
|
|
||||||
public string? SdpMid { get; set; }
|
|
||||||
public int? SdpMLineIndex { get; set; }
|
|
||||||
// public required string Direction { get; set; } // "offer" or "answer"
|
|
||||||
public DateTime CreatedAt { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class RtcIceCandidate
|
|
||||||
{
|
|
||||||
public required string ChannelId { get; set; }
|
|
||||||
public required string Username { get; set; }
|
|
||||||
public required IceCandidate Candidate { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class IceCandidate
|
|
||||||
{
|
|
||||||
public required string candidate { get; set; }
|
|
||||||
public required string sdpMid { get; set; }
|
|
||||||
public required int sdpMLineIndex { get; set; }
|
|
||||||
public required string usernameFragment { get; set; }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class DBActiveCall : Record
|
|
||||||
{
|
|
||||||
public string ChannelId { get; set; } = string.Empty;
|
|
||||||
public string? OfferUser { get; set; }
|
|
||||||
public RtcSessionDescription? Offer { get; set; }
|
|
||||||
public RtcSessionDescription? Answer { get; set; }
|
|
||||||
public DateTime CreatedAt { get; set; }
|
|
||||||
public DateTime UpdatedAt { get; set; }
|
|
||||||
public bool IsActive { get; set; }
|
|
||||||
}
|
|
||||||
10
RelayShared/Services/ChannelEnums.cs
Normal file
10
RelayShared/Services/ChannelEnums.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace RelayShared.Services;
|
||||||
|
|
||||||
|
public enum ChannelType
|
||||||
|
{
|
||||||
|
Text, //Default channel type, handles text, links, files*, all in a linear live chat format
|
||||||
|
Voice, //Used for general voice and video calls, utilizes WebRTC in its intended use
|
||||||
|
File, //File browser for connected text channels, used for browsing files rather than scrolling through text channel
|
||||||
|
Forum, //Specific forum posts, meant to keep conversations grouped and on topic while keeping all in an easy to find place
|
||||||
|
Stage //Used for announcements and presentations, voice/video call utilizing a modified WebRTC protocol through server
|
||||||
|
}
|
||||||
18
RelayShared/Services/ChannelTransmissions.cs
Normal file
18
RelayShared/Services/ChannelTransmissions.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace RelayShared.Services;
|
||||||
|
|
||||||
|
public sealed class ChannelItem
|
||||||
|
{
|
||||||
|
public string ChannelId { get; set; } = string.Empty;
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public ChannelType Type { get; set; }
|
||||||
|
|
||||||
|
public string Group { get; set; } = string.Empty;
|
||||||
|
public DateTime CreatedAt { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class SocketChannelList
|
||||||
|
{
|
||||||
|
public SignalType Type { get; set; } = SignalType.ChannelList;
|
||||||
|
public List<ChannelItem> Channels { get; set; } = [];
|
||||||
|
}
|
||||||
48
RelayShared/Services/SocketTransmissions.cs
Normal file
48
RelayShared/Services/SocketTransmissions.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
namespace RelayShared.Services;
|
||||||
|
|
||||||
|
//TODO: review name of file, potentially rename for Encryption services rather than sockets
|
||||||
|
|
||||||
|
public sealed class SocketRtcSignalMessage
|
||||||
|
{
|
||||||
|
public SignalType Type { get; set; }
|
||||||
|
public string SenderUsername { get; set; } = string.Empty;
|
||||||
|
public string ChannelId { get; set; } = string.Empty;
|
||||||
|
public string CipherText { get; set; } = string.Empty;
|
||||||
|
public string Nonce { get; set; } = string.Empty;
|
||||||
|
public string Tag { get; set; } = string.Empty;
|
||||||
|
public string EncryptedKey { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class SocketEncryptedMessage
|
||||||
|
{
|
||||||
|
public SignalType Type { get; set; } = SignalType.EncryptedChat;
|
||||||
|
public string SenderUsername { get; set; } = string.Empty;
|
||||||
|
public string RecipientUsername { get; set; } = string.Empty;
|
||||||
|
public string ChannelId { get; set; } = string.Empty;
|
||||||
|
public string CipherText { get; set; } = string.Empty;
|
||||||
|
public string Nonce { get; set; } = string.Empty;
|
||||||
|
public string Tag { get; set; } = string.Empty;
|
||||||
|
public string EncryptedKey { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class ServerPublicKeyMessage
|
||||||
|
{
|
||||||
|
public SignalType Type { get; set; } = SignalType.ServerPublicKey;
|
||||||
|
public string PublicKey { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum SignalType
|
||||||
|
{
|
||||||
|
Offer,
|
||||||
|
Answer,
|
||||||
|
Candidate,
|
||||||
|
OfferUpdated,
|
||||||
|
AnswerUpdated,
|
||||||
|
CandidateAdded,
|
||||||
|
CallLeft,
|
||||||
|
ChannelList,
|
||||||
|
ServerPublicKey,
|
||||||
|
EncryptedSignal,
|
||||||
|
EncryptedChat,
|
||||||
|
ClientEncryptedChat
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user