Compare commits
7 Commits
9ad1d898ff
...
c3b8dc5061
| Author | SHA1 | Date | |
|---|---|---|---|
| c3b8dc5061 | |||
| e855948ca9 | |||
| 63a12b8d17 | |||
| dc37933fb8 | |||
| dad5de3d7f | |||
| c03e5102fb | |||
| 9e587ad7b5 |
@@ -1,5 +1,4 @@
|
|||||||
using RelayClient.Crypto;
|
using RelayClient.Crypto;
|
||||||
using RelayClient.Models;
|
|
||||||
using WebSocketSharp;
|
using WebSocketSharp;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
@@ -235,11 +234,22 @@ public partial class MainPage : ContentPage
|
|||||||
}
|
}
|
||||||
case "rtc_candidate_added":
|
case "rtc_candidate_added":
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IceCandidate? iceCandidate = JsonSerializer.Deserialize<IceCandidate>(rtcNotification.Direction);
|
||||||
|
IceCandidateCallback(iceCandidate);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
SafeSendRawToWebView($"Candidate rejected: {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "rtc_call_left":
|
case "rtc_call_left":
|
||||||
{
|
{
|
||||||
SafeSendRawToWebView("RTC call left notification received.");
|
SafeSendRawToWebView("RTC call left notification received.");
|
||||||
|
RtcLeaveCallback();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -255,7 +265,7 @@ public partial class MainPage : ContentPage
|
|||||||
if (pyload is null)
|
if (pyload is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (pyload.RecipientUsername != _username)
|
if (pyload.RecipientUsername == _username)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Console.WriteLine($"[{_username}] received encrypted payload for {pyload.RecipientUsername}");
|
Console.WriteLine($"[{_username}] received encrypted payload for {pyload.RecipientUsername}");
|
||||||
@@ -407,6 +417,7 @@ public partial class MainPage : ContentPage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region RTC Functions
|
||||||
public async Task<bool> JoinRtcChannel()
|
public async Task<bool> JoinRtcChannel()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(_currentChannelId))
|
if (string.IsNullOrWhiteSpace(_currentChannelId))
|
||||||
@@ -489,6 +500,7 @@ public partial class MainPage : ContentPage
|
|||||||
Username = _username,
|
Username = _username,
|
||||||
Candidate = candidate
|
Candidate = candidate
|
||||||
};
|
};
|
||||||
|
if (candidate == null) return;
|
||||||
await ServerAPI.PostIceCandidateAsync(DBCandidate);
|
await ServerAPI.PostIceCandidateAsync(DBCandidate);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -497,11 +509,11 @@ public partial class MainPage : ContentPage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void IceCandidateCallback(string json)
|
public async void IceCandidateCallback(IceCandidate candidate)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await hybridWebView.InvokeJavaScriptAsync("IceCandidateAdded");
|
await hybridWebView.InvokeJavaScriptAsync("IceCandidateAdded", [candidate], [HybridJSType.Default.IceCandidate]);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -520,23 +532,36 @@ public partial class MainPage : ContentPage
|
|||||||
SafeSendRawToWebView("AnswerCallback failed: " + ex.Message);
|
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();
|
await hybridWebView.InvokeJavaScriptAsync("RtcLeaveCall", [], []);
|
||||||
return;
|
}
|
||||||
|
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)
|
public void SendRtcSignal(string json)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(_serverPublicKey))
|
if (string.IsNullOrWhiteSpace(_serverPublicKey))
|
||||||
@@ -574,23 +599,24 @@ public partial class MainPage : ContentPage
|
|||||||
|
|
||||||
_wsc.Send(JsonSerializer.Serialize(payload));
|
_wsc.Send(JsonSerializer.Serialize(payload));
|
||||||
Console.WriteLine($"[{_username}] sent RTC signal: {rtcSignal.Type} -> {rtcSignal.ChannelId}");
|
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);
|
SafeSendRawToWebView($"Hello from C#!");
|
||||||
var channelIdJson = JsonSerializer.Serialize(_currentChannelId);
|
}
|
||||||
|
|
||||||
await hybridWebView.EvaluateJavaScriptAsync($"window.setUsername({usernameJson})");
|
private async void OnHybridWebViewRawMessageReceived(object sender, HybridWebViewRawMessageReceivedEventArgs e)
|
||||||
await hybridWebView.EvaluateJavaScriptAsync($"window.setChannelId({channelIdJson})");
|
{
|
||||||
|
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)
|
private void SafeSendRawToWebView(string message)
|
||||||
@@ -611,6 +637,8 @@ public partial class MainPage : ContentPage
|
|||||||
[JsonSourceGenerationOptions(WriteIndented = false)]
|
[JsonSourceGenerationOptions(WriteIndented = false)]
|
||||||
[JsonSerializable(typeof(RtcDescription))]
|
[JsonSerializable(typeof(RtcDescription))]
|
||||||
[JsonSerializable(typeof(List<RtcSignalMessage>))]
|
[JsonSerializable(typeof(List<RtcSignalMessage>))]
|
||||||
|
[JsonSerializable(typeof(IceCandidate))]
|
||||||
|
[JsonSerializable(typeof(List<IceCandidate>))]
|
||||||
[JsonSerializable(typeof(string))]
|
[JsonSerializable(typeof(string))]
|
||||||
internal partial class HybridJSType : JsonSerializerContext
|
internal partial class HybridJSType : JsonSerializerContext
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
namespace RelayClient.Models;
|
|
||||||
|
|
||||||
public class ChannelItem
|
|
||||||
{
|
|
||||||
public required string ChannelId { get; set; }
|
|
||||||
public required string Name { get; set; }
|
|
||||||
public required DateTime CreatedAt { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
namespace RelayClient.Models;
|
|
||||||
|
|
||||||
public sealed class RtcNotificationMessage
|
|
||||||
{
|
|
||||||
public string? Type { get; set; }
|
|
||||||
public string? ChannelId { get; set; }
|
|
||||||
public string? Username { get; set; }
|
|
||||||
public string? Direction { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
namespace RelayClient.Models;
|
|
||||||
|
|
||||||
public class RtcSignalMessage
|
|
||||||
{
|
|
||||||
public required string Type { get; set; } // rtc_join / rtc_offer / rtc_answer / rtc_ice_candidate / rtc_leave
|
|
||||||
public required string From { get; set; }
|
|
||||||
public required string ChannelId { get; set; }
|
|
||||||
|
|
||||||
public string? Sdp { get; set; }
|
|
||||||
public string? Candidate { get; set; }
|
|
||||||
public string? SdpMid { get; set; }
|
|
||||||
public int? SdpMLineIndex { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace RelayClient.Models;
|
|
||||||
|
|
||||||
public class ServerPublicKeyMessage
|
|
||||||
{
|
|
||||||
public required string Type { get; set; }
|
|
||||||
public required string PublicKey { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace RelayClient.Models;
|
|
||||||
|
|
||||||
public class SocketChannelList
|
|
||||||
{
|
|
||||||
public required string Type { get; set; }
|
|
||||||
public required List<ChannelItem> Channels { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
namespace RelayClient.Models;
|
|
||||||
|
|
||||||
public class SocketEncryptedMessage
|
|
||||||
{
|
|
||||||
public required string Type { get; set; }
|
|
||||||
public required string SenderUsername { get; set; }
|
|
||||||
public string? RecipientUsername { get; set; }
|
|
||||||
public required string ChannelId { get; set; }
|
|
||||||
public required string CipherText { get; set; }
|
|
||||||
public required string Nonce { get; set; }
|
|
||||||
public required string Tag { get; set; }
|
|
||||||
public required string EncryptedKey { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
namespace RelayClient.Models;
|
|
||||||
|
|
||||||
public class SocketRtcSignalMessage
|
|
||||||
{
|
|
||||||
public required string Type { get; set; } // encrypted_rtc_signal
|
|
||||||
public required string SenderUsername { get; set; }
|
|
||||||
public required string ChannelId { get; set; }
|
|
||||||
|
|
||||||
public required string CipherText { get; set; }
|
|
||||||
public required string Nonce { get; set; }
|
|
||||||
public required string Tag { get; set; }
|
|
||||||
public required string EncryptedKey { get; set; }
|
|
||||||
}
|
|
||||||
@@ -54,4 +54,8 @@
|
|||||||
<ProjectReference Include="..\RelayShared\RelayShared.csproj" />
|
<ProjectReference Include="..\RelayShared\RelayShared.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Models\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ let currentUsername = null;
|
|||||||
let currentChannelId = null;
|
let currentChannelId = null;
|
||||||
let availableCameras = [];
|
let availableCameras = [];
|
||||||
let availableMics = [];
|
let availableMics = [];
|
||||||
|
let candidateQueue = [];
|
||||||
const configuration = {
|
const configuration = {
|
||||||
iceServers:[
|
iceServers:[
|
||||||
{
|
{
|
||||||
@@ -24,7 +25,7 @@ window.setChannelId = function(channelId) {
|
|||||||
currentChannelId = channelId;
|
currentChannelId = channelId;
|
||||||
LogMessage("Channel set to: " + currentChannelId);
|
LogMessage("Channel set to: " + currentChannelId);
|
||||||
};
|
};
|
||||||
let userMedia = getUserMedia()
|
|
||||||
function LogMessage(msg) {
|
function LogMessage(msg) {
|
||||||
const messageLog = document.getElementById("messageLog");
|
const messageLog = document.getElementById("messageLog");
|
||||||
messageLog.value += '\r\n' + msg;
|
messageLog.value += '\r\n' + msg;
|
||||||
@@ -95,7 +96,7 @@ async function ensurePeerConnection() {
|
|||||||
peerConnection.onicegatheringstatechange = () => {
|
peerConnection.onicegatheringstatechange = () => {
|
||||||
LogMessage("ICE gathering state: " + peerConnection.iceGatheringState);
|
LogMessage("ICE gathering state: " + peerConnection.iceGatheringState);
|
||||||
};
|
};
|
||||||
}
|
} //Remove?
|
||||||
async function ensureLocalMedia(forceReload = false) {
|
async function ensureLocalMedia(forceReload = false) {
|
||||||
const localMediaStatus = document.getElementById("localMediaStatus");
|
const localMediaStatus = document.getElementById("localMediaStatus");
|
||||||
const localVideoStatus = document.getElementById("localVideoStatus");
|
const localVideoStatus = document.getElementById("localVideoStatus");
|
||||||
@@ -238,7 +239,7 @@ async function joinChannelCall() {
|
|||||||
// } catch (err) {
|
// } catch (err) {
|
||||||
// LogMessage("joinChannelCall failed: " + err);
|
// LogMessage("joinChannelCall failed: " + err);
|
||||||
// }
|
// }
|
||||||
}
|
} //Combine with channelCallJoin
|
||||||
|
|
||||||
async function ensurePeerConnection2()
|
async function ensurePeerConnection2()
|
||||||
{
|
{
|
||||||
@@ -262,6 +263,7 @@ async function ensurePeerConnection2()
|
|||||||
console.log(`Ice Candidate: ${JSON.stringify(event.candidate)}`);
|
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 window.HybridWebView.InvokeDotNet("WriteIceCandidate", [JSON.stringify(event.candidate)]);
|
||||||
|
await IceCandidateAdded(event.candidate);
|
||||||
};
|
};
|
||||||
|
|
||||||
peerConnection.ontrack = (event) => {
|
peerConnection.ontrack = (event) => {
|
||||||
@@ -334,12 +336,26 @@ async function AnswerCallbackJS(answer)
|
|||||||
LogMessage("Current answer: " + JSON.stringify(answer));
|
LogMessage("Current answer: " + JSON.stringify(answer));
|
||||||
const desc = new RTCSessionDescription(answer);
|
const desc = new RTCSessionDescription(answer);
|
||||||
await peerConnection.setRemoteDescription(desc);
|
await peerConnection.setRemoteDescription(desc);
|
||||||
|
for (const candidate of candidateQueue) {
|
||||||
|
await peerConnection.addIceCandidate(candidate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function IceCandidateAdded(candidate)
|
async function IceCandidateAdded(candidate)
|
||||||
{
|
{
|
||||||
await peerConnection.addIceCandidate(candidate);
|
if (peerConnection.currentRemoteDescription) {
|
||||||
|
await peerConnection.addIceCandidate(candidate);
|
||||||
|
LogMessage("ICE CANDIDATE ADDED: " + JSON.stringify(candidate));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogMessage("RemoteDescription Missing")
|
||||||
|
candidateQueue.push(candidate);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function RtcLeaveCall()
|
||||||
|
{}
|
||||||
async function handleRtcSignal(rawJson) {
|
async function handleRtcSignal(rawJson) {
|
||||||
try {
|
try {
|
||||||
const msg = typeof rawJson === "string" ? JSON.parse(rawJson) : rawJson;
|
const msg = typeof rawJson === "string" ? JSON.parse(rawJson) : rawJson;
|
||||||
@@ -354,7 +370,7 @@ async function handleRtcSignal(rawJson) {
|
|||||||
|
|
||||||
const offer = await peerConnection.createOffer();
|
const offer = await peerConnection.createOffer();
|
||||||
await peerConnection.setLocalDescription(offer);
|
await peerConnection.setLocalDescription(offer);
|
||||||
await waitForIceGatheringComplete(peerConnection);
|
// await waitForIceGatheringComplete(peerConnection);
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
type: "rtc_offer",
|
type: "rtc_offer",
|
||||||
@@ -386,7 +402,7 @@ async function handleRtcSignal(rawJson) {
|
|||||||
|
|
||||||
const answer = await peerConnection.createAnswer();
|
const answer = await peerConnection.createAnswer();
|
||||||
await peerConnection.setLocalDescription(answer);
|
await peerConnection.setLocalDescription(answer);
|
||||||
await waitForIceGatheringComplete(peerConnection);
|
// await waitForIceGatheringComplete(peerConnection);
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
type: "rtc_answer",
|
type: "rtc_answer",
|
||||||
@@ -429,7 +445,7 @@ async function handleRtcSignal(rawJson) {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
LogMessage("handleRtcSignal failed: " + err);
|
LogMessage("handleRtcSignal failed: " + err);
|
||||||
}
|
}
|
||||||
}
|
} //Remove?
|
||||||
|
|
||||||
async function loadDevices() {
|
async function loadDevices() {
|
||||||
try {
|
try {
|
||||||
@@ -513,9 +529,9 @@ async function waitForIceGatheringComplete(pc) {
|
|||||||
|
|
||||||
pc.addEventListener("icegatheringstatechange", checkState);
|
pc.addEventListener("icegatheringstatechange", checkState);
|
||||||
});
|
});
|
||||||
}
|
} //Remove?
|
||||||
|
|
||||||
window.handleRtcSignal = handleRtcSignal;
|
// window.handleRtcSignal = handleRtcSignal;
|
||||||
|
|
||||||
window.addEventListener("HybridWebViewMessageReceived", function (e) {
|
window.addEventListener("HybridWebViewMessageReceived", function (e) {
|
||||||
LogMessage("Raw message: " + e.detail.message);
|
LogMessage("Raw message: " + e.detail.message);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using RelayServer.Models.Rtc;
|
using System.Text.Json;
|
||||||
|
using RelayShared.Rtc;
|
||||||
using RelayServer.Services.Rtc;
|
using RelayServer.Services.Rtc;
|
||||||
|
|
||||||
namespace RelayServer.Endpoints;
|
namespace RelayServer.Endpoints;
|
||||||
@@ -86,7 +87,6 @@ public static class RtcEndpoints
|
|||||||
request.Candidate.candidate,
|
request.Candidate.candidate,
|
||||||
request.Candidate.sdpMid,
|
request.Candidate.sdpMid,
|
||||||
request.Candidate.sdpMLineIndex
|
request.Candidate.sdpMLineIndex
|
||||||
// request.Candidate.direction
|
|
||||||
);
|
);
|
||||||
|
|
||||||
RtcNotificationService.BroadcastToChannel(new RtcNotificationMessage
|
RtcNotificationService.BroadcastToChannel(new RtcNotificationMessage
|
||||||
@@ -94,7 +94,7 @@ public static class RtcEndpoints
|
|||||||
Type = "rtc_candidate_added",
|
Type = "rtc_candidate_added",
|
||||||
ChannelId = request.ChannelId,
|
ChannelId = request.ChannelId,
|
||||||
Username = request.Username,
|
Username = request.Username,
|
||||||
/*Direction = request.Direction*/
|
Direction = JsonSerializer.Serialize(request.Candidate)
|
||||||
});
|
});
|
||||||
|
|
||||||
return Results.Ok();
|
return Results.Ok();
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace RelayServer.Models;
|
|
||||||
|
|
||||||
public class SocketChannelList
|
|
||||||
{
|
|
||||||
public required string Type { get; set; }
|
|
||||||
public required List<SocketChannelInfo> Channels { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
namespace RelayServer.Models;
|
|
||||||
|
|
||||||
public class SocketEncryptedMessage
|
|
||||||
{
|
|
||||||
public required string Type { get; set; }
|
|
||||||
public required string SenderUsername { get; set; }
|
|
||||||
public string? RecipientUsername { get; set; }
|
|
||||||
public required string ChannelId { get; set; }
|
|
||||||
public required string CipherText { get; set; }
|
|
||||||
public required string Nonce { get; set; }
|
|
||||||
public required string Tag { get; set; }
|
|
||||||
public required string EncryptedKey { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
namespace RelayServer.Models;
|
|
||||||
|
|
||||||
public class RtcSignalMessage
|
|
||||||
{
|
|
||||||
public required string Type { get; set; } // rtc_join / rtc_offer / rtc_answer / rtc_ice_candidate / rtc_leave
|
|
||||||
public required string From { get; set; }
|
|
||||||
public required string ChannelId { get; set; }
|
|
||||||
|
|
||||||
public string? Sdp { get; set; }
|
|
||||||
public string? Candidate { get; set; }
|
|
||||||
public string? SdpMid { get; set; }
|
|
||||||
public int? SdpMLineIndex { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace RelayServer.Models;
|
|
||||||
|
|
||||||
public class ServerPublicKeyMessage
|
|
||||||
{
|
|
||||||
public required string Type { get; set; }
|
|
||||||
public required string PublicKey { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
namespace RelayServer.Models;
|
|
||||||
|
|
||||||
public class SocketRtcSignalMessage
|
|
||||||
{
|
|
||||||
public required string Type { get; set; } // encrypted_rtc_signal
|
|
||||||
public required string SenderUsername { get; set; }
|
|
||||||
public required string ChannelId { get; set; }
|
|
||||||
|
|
||||||
public required string CipherText { get; set; }
|
|
||||||
public required string Nonce { get; set; }
|
|
||||||
public required string Tag { get; set; }
|
|
||||||
public required string EncryptedKey { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
using SurrealDb.Net.Models;
|
|
||||||
|
|
||||||
namespace RelayServer.Models.Rtc;
|
|
||||||
|
|
||||||
public sealed class RtcActiveCall : Record
|
|
||||||
{
|
|
||||||
public required string ChannelId { get; set; }
|
|
||||||
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; }
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
using SurrealDb.Net.Models;
|
|
||||||
|
|
||||||
namespace RelayServer.Models.Rtc;
|
|
||||||
|
|
||||||
public class RtcAnswer : Record
|
|
||||||
{
|
|
||||||
public required string ChannelId { get; set; }
|
|
||||||
public required string OfferUser { get; set; }
|
|
||||||
public required string AnswerUser { get; set; }
|
|
||||||
public required string Sdp { get; set; }
|
|
||||||
public DateTime CreatedAt { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
using SurrealDb.Net.Models;
|
|
||||||
|
|
||||||
namespace RelayServer.Models.Rtc;
|
|
||||||
|
|
||||||
public class RtcIceCandidate : 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 DBIceCandidate
|
|
||||||
{
|
|
||||||
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; }
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace RelayServer.Models.Rtc;
|
|
||||||
|
|
||||||
public class RtcJoinRequest
|
|
||||||
{
|
|
||||||
public required string ChannelId { get; set; }
|
|
||||||
public required string Username { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
namespace RelayServer.Models.Rtc;
|
|
||||||
|
|
||||||
public class RtcJoinResponse
|
|
||||||
{
|
|
||||||
public required string ChannelId { get; set; }
|
|
||||||
public bool HasActiveCall { get; set; }
|
|
||||||
public bool IsOfferer { get; set; }
|
|
||||||
public string? OfferUser { get; set; }
|
|
||||||
public string? OfferSdp { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace RelayServer.Models.Rtc;
|
|
||||||
|
|
||||||
public class RtcLeaveRequest
|
|
||||||
{
|
|
||||||
public required string ChannelId { get; set; }
|
|
||||||
public required string Username { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
namespace RelayServer.Models.Rtc;
|
|
||||||
|
|
||||||
public sealed class RtcNotificationMessage
|
|
||||||
{
|
|
||||||
public required string Type { get; set; } // rtc_offer_updated / rtc_answer_updated / rtc_candidate_added
|
|
||||||
public required string ChannelId { get; set; }
|
|
||||||
public string? Username { get; set; }
|
|
||||||
public string? Direction { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
using SurrealDb.Net.Models;
|
|
||||||
|
|
||||||
namespace RelayServer.Models.Rtc;
|
|
||||||
|
|
||||||
public class RtcOffer : Record
|
|
||||||
{
|
|
||||||
public required string ChannelId { get; set; }
|
|
||||||
public required string Username { get; set; }
|
|
||||||
public required RtcSessionDescription SessionDescription { get; set; }
|
|
||||||
// public required string Type { get; set; }
|
|
||||||
// public required string Sdp { get; set; }
|
|
||||||
public DateTime CreatedAt { get; set; }
|
|
||||||
public DateTime UpdatedAt { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace RelayServer.Models.Rtc;
|
|
||||||
|
|
||||||
public sealed class RtcSessionDescription
|
|
||||||
{
|
|
||||||
public required string Type { get; set; }
|
|
||||||
public required string Sdp { get; set; }
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,7 @@ using RelayServer.Services.Chat;
|
|||||||
using RelayServer.Services.Core;
|
using RelayServer.Services.Core;
|
||||||
using RelayServer.Services.Data;
|
using RelayServer.Services.Data;
|
||||||
using RelayServer.Services.Rtc;
|
using RelayServer.Services.Rtc;
|
||||||
|
using RelayShared.Rtc;
|
||||||
using WebSocketSharp.Server;
|
using WebSocketSharp.Server;
|
||||||
|
|
||||||
var surrealService = new SurrealService();
|
var surrealService = new SurrealService();
|
||||||
|
|||||||
@@ -17,4 +17,8 @@
|
|||||||
<ProjectReference Include="..\RelayShared\RelayShared.csproj" />
|
<ProjectReference Include="..\RelayShared\RelayShared.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Models\Rtc\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -6,6 +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;
|
||||||
|
|
||||||
namespace RelayServer.Services.Chat;
|
namespace RelayServer.Services.Chat;
|
||||||
|
|
||||||
@@ -145,7 +146,7 @@ public class ChatSocketBehavior : WebSocketBehavior
|
|||||||
|
|
||||||
var channels = GetChannelsSync()
|
var channels = GetChannelsSync()
|
||||||
.OrderBy(c => c.CreatedAt)
|
.OrderBy(c => c.CreatedAt)
|
||||||
.Select(c => new SocketChannelInfo
|
.Select(c => new ChannelItem()
|
||||||
{
|
{
|
||||||
ChannelId = GetRecordId(c.Id),
|
ChannelId = GetRecordId(c.Id),
|
||||||
Name = c.Name,
|
Name = c.Name,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using RelayServer.Models.Rtc;
|
using RelayShared.Rtc;
|
||||||
using SurrealDb.Net;
|
using SurrealDb.Net;
|
||||||
|
|
||||||
namespace RelayServer.Services.Rtc;
|
namespace RelayServer.Services.Rtc;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using RelayServer.Models.Rtc;
|
using RelayShared.Rtc;
|
||||||
using WebSocketSharp.Server;
|
using WebSocketSharp.Server;
|
||||||
|
|
||||||
namespace RelayServer.Services.Rtc;
|
namespace RelayServer.Services.Rtc;
|
||||||
@@ -25,4 +25,22 @@ public static class RtcNotificationService
|
|||||||
host.Sessions.SendTo(json, sessionId);
|
host.Sessions.SendTo(json, sessionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void BroadcastToChannel(RtcIceNotificationMessage message)
|
||||||
|
{
|
||||||
|
if (Server is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var host = Server.WebSocketServices["/"];
|
||||||
|
if (host is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var json = JsonSerializer.Serialize(message);
|
||||||
|
var sessionIds = RtcChannelPresenceService.GetSessionsInChannel(message.ChannelId);
|
||||||
|
|
||||||
|
foreach (var sessionId in sessionIds)
|
||||||
|
{
|
||||||
|
host.Sessions.SendTo(json, sessionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,51 +2,118 @@
|
|||||||
|
|
||||||
namespace RelayShared.Rtc;
|
namespace RelayShared.Rtc;
|
||||||
|
|
||||||
public class RtcSignalTypes
|
public static class RtcSignalTypes
|
||||||
{
|
{
|
||||||
public const string Offer = "rtc_offer";
|
public const string Offer = "rtc_offer";
|
||||||
public const string Answer = "rtc_answer";
|
public const string Answer = "rtc_answer";
|
||||||
public const string Candidate = "rtc_candidate";
|
public const string Candidate = "rtc_candidate";
|
||||||
public const string OfferUpdated = "rtc_offer_updated";
|
public const string OfferUpdated = "rtc_offer_updated";
|
||||||
public const string AnswerUpdated = "rtc_answer_updated";
|
public const string AnswerUpdated = "rtc_answer_updated";
|
||||||
|
public const string CandidateAdded = "rtc_candidate_added";
|
||||||
|
public const string CallLeft = "rtc_call_left";
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RtcJoinRequest
|
public sealed class RtcSignalMessage
|
||||||
{
|
{
|
||||||
public required string ChannelId { get; set; }
|
public string Type { get; set; } = string.Empty;
|
||||||
public required string Username { get; set; }
|
public string From { get; set; } = string.Empty;
|
||||||
|
public string ChannelId { get; set; } = string.Empty;
|
||||||
|
public string? Sdp { get; set; }
|
||||||
|
public string? Candidate { get; set; }
|
||||||
|
public string? SdpMid { get; set; }
|
||||||
|
public int? SdpMLineIndex { get; set; }
|
||||||
|
public bool IsInitiator { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class RtcNotificationMessage
|
||||||
|
{
|
||||||
|
public string? Type { get; set; }
|
||||||
|
public string? ChannelId { get; set; }
|
||||||
|
public string? Username { get; set; }
|
||||||
|
public string? Direction { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class ServerPublicKeyMessage
|
||||||
|
{
|
||||||
|
public string Type { get; set; } = string.Empty;
|
||||||
|
public string PublicKey { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class SocketRtcSignalMessage
|
||||||
|
{
|
||||||
|
public string Type { get; set; } = string.Empty;
|
||||||
|
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 string Type { get; set; } = string.Empty;
|
||||||
|
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 DateTime CreatedAt { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class SocketChannelList
|
||||||
|
{
|
||||||
|
public string Type { get; set; } = string.Empty;
|
||||||
|
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 sealed class RtcSessionDescription
|
||||||
{
|
{
|
||||||
public required string Type { get; set; }
|
public string Type { get; set; } = string.Empty;
|
||||||
public required string Sdp { get; set; }
|
public string Sdp { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RtcOffer : Record
|
public sealed class RtcOffer
|
||||||
{
|
{
|
||||||
public required string ChannelId { get; set; }
|
public string ChannelId { get; set; } = string.Empty;
|
||||||
public required string Username { get; set; }
|
public string Username { get; set; } = string.Empty;
|
||||||
public required RtcSessionDescription SessionDescription { get; set; }
|
public RtcSessionDescription SessionDescription { get; set; } = new();
|
||||||
// public required string Type { get; set; }
|
|
||||||
// public required string Sdp { get; set; }
|
|
||||||
public DateTime CreatedAt { get; set; }
|
|
||||||
public DateTime UpdatedAt { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RtcLeaveRequest
|
public sealed class RtcAnswer
|
||||||
{
|
{
|
||||||
public required string ChannelId { get; set; }
|
public string ChannelId { get; set; } = string.Empty;
|
||||||
public required string Username { get; set; }
|
public string Username { get; set; } = string.Empty;
|
||||||
}
|
public RtcSessionDescription SessionDescription { get; set; } = new();
|
||||||
|
|
||||||
public class RtcJoinResponse
|
|
||||||
{
|
|
||||||
public required string ChannelId { get; set; }
|
|
||||||
public bool HasActiveCall { get; set; }
|
|
||||||
public bool IsOfferer { get; set; }
|
|
||||||
public string? OfferUser { get; set; }
|
|
||||||
public string? OfferSdp { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RtcIceCandidate : Record
|
public class RtcIceCandidate : Record
|
||||||
@@ -76,18 +143,9 @@ public class IceCandidate
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RtcAnswer : Record
|
|
||||||
{
|
|
||||||
public required string ChannelId { get; set; }
|
|
||||||
public required string OfferUser { get; set; }
|
|
||||||
public required string AnswerUser { get; set; }
|
|
||||||
public required string Sdp { get; set; }
|
|
||||||
public DateTime CreatedAt { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class RtcActiveCall : Record
|
public sealed class RtcActiveCall : Record
|
||||||
{
|
{
|
||||||
public required string ChannelId { get; set; }
|
public string ChannelId { get; set; } = string.Empty;
|
||||||
public string? OfferUser { get; set; }
|
public string? OfferUser { get; set; }
|
||||||
public RtcSessionDescription? Offer { get; set; }
|
public RtcSessionDescription? Offer { get; set; }
|
||||||
public RtcSessionDescription? Answer { get; set; }
|
public RtcSessionDescription? Answer { get; set; }
|
||||||
|
|||||||
@@ -64,19 +64,19 @@ Start-Sleep -Seconds 5
|
|||||||
& '$clientExe' --user Ru_Kira
|
& '$clientExe' --user Ru_Kira
|
||||||
"@
|
"@
|
||||||
|
|
||||||
#$testScript = New-TabScript -Name "Test" -Content @"
|
# $testScript = New-TabScript -Name "Test" -Content @"
|
||||||
#Set-Location '$root'
|
# Set-Location '$root'
|
||||||
#Start-Sleep -Seconds 25
|
# Start-Sleep -Seconds 25
|
||||||
#& '$clientExe' --user Test
|
# & '$clientExe' --user Test
|
||||||
#"@
|
# "@
|
||||||
|
|
||||||
$wtArgs = @(
|
$wtArgs = @(
|
||||||
"new-tab --title `"SurrealDB`" `"$ps`" -NoExit -ExecutionPolicy Bypass -File `"$dockerScript`"",
|
"new-tab --title `"SurrealDB`" `"$ps`" -NoExit -ExecutionPolicy Bypass -File `"$dockerScript`"",
|
||||||
"new-tab --title `"RelayCore`" `"$ps`" -NoExit -ExecutionPolicy Bypass -File `"$coreScript`"",
|
"new-tab --title `"RelayCore`" `"$ps`" -NoExit -ExecutionPolicy Bypass -File `"$coreScript`"",
|
||||||
"new-tab --title `"RelayServer`" `"$ps`" -NoExit -ExecutionPolicy Bypass -File `"$serverScript`"",
|
"new-tab --title `"RelayServer`" `"$ps`" -NoExit -ExecutionPolicy Bypass -File `"$serverScript`"",
|
||||||
"new-tab --title `"Keeper317`" `"$ps`" -NoExit -ExecutionPolicy Bypass -File `"$keeperScript`"",
|
"new-tab --title `"Keeper317`" `"$ps`" -NoExit -ExecutionPolicy Bypass -File `"$keeperScript`"",
|
||||||
|
# "new-tab --title `"Test`" `"$ps`" -NoExit -ExecutionPolicy Bypass -File `"$testScript`"",
|
||||||
"new-tab --title `"Ru_Kira`" `"$ps`" -NoExit -ExecutionPolicy Bypass -File `"$kiraScript`""
|
"new-tab --title `"Ru_Kira`" `"$ps`" -NoExit -ExecutionPolicy Bypass -File `"$kiraScript`""
|
||||||
#"new-tab --title `"Test`" `"$ps`" -NoExit -ExecutionPolicy Bypass -File `"$testScript`""
|
|
||||||
) -join " ; "
|
) -join " ; "
|
||||||
|
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
|
|||||||
Reference in New Issue
Block a user