5 Commits

Author SHA1 Message Date
4974663128 removed test delay 2026-05-02 16:13:19 -04:00
3901542141 AUDIO FUCKING WORKS - Test Camera. 2026-05-02 16:04:23 -04:00
dd1aa45f6e Fixed connections 2026-04-29 14:39:28 -04:00
38662f6655 Fix attempts for RTC calls 2026-04-29 13:52:35 -04:00
777328caed Merge branch 'RTC-Rewrite' 2026-04-29 09:13:58 -04:00
4 changed files with 92 additions and 30 deletions

View File

@@ -49,4 +49,25 @@ window.addEventListener("load", async () => {
Media.wireDeviceSelectors(); Media.wireDeviceSelectors();
await Media.loadDevices(); await Media.loadDevices();
await Media.ensureLocalMedia(); await Media.ensureLocalMedia();
}); });
function testIndex(rawJson)
{
const data = typeof rawJson === "string" ? JSON.parse(rawJson) : rawJson;
if (data.sdp) {
data.sdp = data.sdp.replaceAll("(rn)", "\r\n");
}
handleRtcSignal(JSON.stringify(data));
// if (data.type === "rtc_offer") {
// handleOffer(data)
// }
// if (data.type === "rtc_answer") {
// data.sdp = data.sdp.replaceAll("(rn)", "\r\n");
// handleAnswer(data)
// }
}
function noDataTest()
{
LogMessage("No Data Called!!");
}

View File

@@ -1,4 +1,4 @@
const peerConnections = {}; const peerConnections = {};
async function joinChannelCall() { async function joinChannelCall() {
LogMessage("Current username: " + currentUsername); LogMessage("Current username: " + currentUsername);
@@ -24,7 +24,7 @@ async function joinChannelCall() {
} }
for (const username of existingUsers) { for (const username of existingUsers) {
await sendOffer(username); await sendOffer(username); //Creates an offer to each person in call for MESH RTC
} }
} }
@@ -34,6 +34,7 @@ async function sendOffer(username) {
await Media.applyLocalStreamToPeerConnection(pc, username); await Media.applyLocalStreamToPeerConnection(pc, username);
const offer = await pc.createOffer(); const offer = await pc.createOffer();
// LogMessage(`Offer created: ${JSON.stringify(offer)}`);
await pc.setLocalDescription(offer); await pc.setLocalDescription(offer);
await RelaySocket.sendRtcSignal({ await RelaySocket.sendRtcSignal({
@@ -88,11 +89,12 @@ async function handleRtcSignal(rawJson) {
} }
async function handleOffer(msg) { async function handleOffer(msg) {
LogMessage(`Offer handler: ${msg}`);
const pc = await ensurePeerConnectionForUser(msg.from); const pc = await ensurePeerConnectionForUser(msg.from);
await Media.ensureLocalMedia(); await Media.ensureLocalMedia();
await Media.applyLocalStreamToPeerConnection(pc, msg.from); await Media.applyLocalStreamToPeerConnection(pc, msg.from);
// const offer = JSON.parse(msg.offer);
await pc.setRemoteDescription({ await pc.setRemoteDescription({
type: "offer", type: "offer",
sdp: msg.sdp sdp: msg.sdp
@@ -137,8 +139,14 @@ async function handleIce(msg) {
} }
if (!msg.candidate) return; if (!msg.candidate) return;
const candidateInit = {
candidate: msg.candidate,
sdpMid: msg.sdpMid,
sdpMLineIndex: msg.sdpMLineIndex
};
await pc.addIceCandidate(msg.candidate); await pc.addIceCandidate(candidateInit);
LogMessage(`Applied ICE from ${msg.from}`); LogMessage(`Applied ICE from ${msg.from}`);
} }
@@ -159,7 +167,9 @@ async function ensurePeerConnectionForUser(username) {
channelId: currentChannelId, channelId: currentChannelId,
from: currentUsername, from: currentUsername,
to: username, to: username,
candidate: JSON.stringify(event.candidate) candidate: event.candidate.candidate,
sdpMid: event.candidate.sdpMid,
sdpMLineIndex: event.candidate.sdpMLineIndex
}); });
}; };

View File

@@ -1,4 +1,5 @@
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization;
using RelayClient.Crypto; using RelayClient.Crypto;
using RelayShared.Rtc; using RelayShared.Rtc;
using RelayShared.Services; using RelayShared.Services;
@@ -70,6 +71,7 @@ public sealed class RtcBridgeService
rtcSignal.ChannelId ??= _getCurrentChannelId(); rtcSignal.ChannelId ??= _getCurrentChannelId();
rtcSignal.From ??= _username; rtcSignal.From ??= _username;
// _sendRawToWebView($"RTC_SIGNAL file: {JsonSerializer.Serialize(rtcSignal)}");
if (string.IsNullOrWhiteSpace(rtcSignal.ChannelId)) if (string.IsNullOrWhiteSpace(rtcSignal.ChannelId))
{ {
_sendRawToWebView("SendRtcSignal failed: missing channel id."); _sendRawToWebView("SendRtcSignal failed: missing channel id.");
@@ -116,16 +118,23 @@ public sealed class RtcBridgeService
public async Task HandleIncomingRtcSignalAsync(SocketRtcSignalMessage payload) public async Task HandleIncomingRtcSignalAsync(SocketRtcSignalMessage payload)
{ {
// _sendRawToWebView("HandleIncomingRtcSignal called");
var currentChannelId = _getCurrentChannelId(); var currentChannelId = _getCurrentChannelId();
if (payload.ChannelId != currentChannelId) if (payload.ChannelId != currentChannelId)
{
_sendRawToWebView("Channel id does not match");
return; return;
}
if (payload.SenderUsername == _username) if (payload.SenderUsername == _username)
{
_sendRawToWebView("Received own message");
return; return;
}
string decryptedJson; string decryptedJson;
try try
{ {
var privateKey = KeyStorage.LoadPrivateKey(_username); var privateKey = KeyStorage.LoadPrivateKey(_username);
@@ -152,6 +161,7 @@ public sealed class RtcBridgeService
try try
{ {
rtcSignal = JsonSerializer.Deserialize<RtcSignalMessage>(decryptedJson); rtcSignal = JsonSerializer.Deserialize<RtcSignalMessage>(decryptedJson);
// _sendRawToWebView($"Received Encrypted Signal: [{rtcSignal.From}]: {rtcSignal.Offer}");
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -160,7 +170,10 @@ public sealed class RtcBridgeService
} }
if (rtcSignal is null) if (rtcSignal is null)
{
_sendRawToWebView("rtcSignal is null");
return; return;
}
if (!string.IsNullOrWhiteSpace(rtcSignal.To) && if (!string.IsNullOrWhiteSpace(rtcSignal.To) &&
!string.Equals(rtcSignal.To, _username, StringComparison.OrdinalIgnoreCase)) !string.Equals(rtcSignal.To, _username, StringComparison.OrdinalIgnoreCase))
@@ -169,9 +182,9 @@ public sealed class RtcBridgeService
return; return;
} }
_sendRawToWebView("Received encrypted RTC signal: " + decryptedJson); // _sendRawToWebView("Received encrypted RTC signal: " + decryptedJson);
await SendRtcSignalToJsAsync(decryptedJson); await SendRtcSignalToJsAsync(rtcSignal);
} }
public Task PushRtcContextToJsAsync() public Task PushRtcContextToJsAsync()
@@ -188,37 +201,55 @@ public sealed class RtcBridgeService
return Task.CompletedTask; return Task.CompletedTask;
} }
private Task SendRtcSignalToJsAsync(string rawJson) private Task SendRtcSignalToJsAsync(RtcSignalMessage data)
{ {
if (data.Type == "rtc_offer" || data.Type == "rtc_answer")
{
data.Sdp = data.Sdp.Replace("\r\n", "(rn)");
}
MainThread.BeginInvokeOnMainThread(async () => MainThread.BeginInvokeOnMainThread(async () =>
{ {
try try
{ {
var jsArg = JsonSerializer.Serialize(rawJson); // await _hybridWebView.InvokeJavaScriptAsync("testIndex", [JsonSerializer.Serialize(data)], [RtcJsType.Default.String]);
await _hybridWebView.InvokeJavaScriptAsync("testIndex", [data], [RtcJsType.Default.RtcSignalMessage]);
await _hybridWebView.EvaluateJavaScriptAsync($@" #region OldDebugger
try {{ // var jsArg = JsonSerializer.Serialize(data);
window.HybridWebView.SendRawMessage('C# eval entered'); //
// await _hybridWebView.EvaluateJavaScriptAsync($@"
if (!window.RelaySocket) {{ // try {{
window.HybridWebView.SendRawMessage('window.RelaySocket missing'); // window.HybridWebView.SendRawMessage('C# eval entered');
}} else if (typeof window.RelaySocket.receiveRtcSignal !== 'function') {{ //
window.HybridWebView.SendRawMessage('RelaySocket.receiveRtcSignal missing'); // if (!window.RelaySocket) {{
}} else {{ // window.HybridWebView.SendRawMessage('window.RelaySocket missing');
window.HybridWebView.SendRawMessage('Calling RelaySocket.receiveRtcSignal'); // }} else if (typeof window.RelaySocket.receiveRtcSignal !== 'function') {{
window.RelaySocket.receiveRtcSignal({jsArg}); // window.HybridWebView.SendRawMessage('RelaySocket.receiveRtcSignal missing');
}} // }} else {{
}} catch (err) {{ // window.HybridWebView.SendRawMessage('Calling RelaySocket.receiveRtcSignal');
window.HybridWebView.SendRawMessage('RTC JS dispatch failed: ' + err); // window.RelaySocket.receiveRtcSignal({jsArg});
}} // }}
"); // }} catch (err) {{
// window.HybridWebView.SendRawMessage('RTC JS dispatch failed: ' + err);
// }}
// ");
#endregion
} }
catch (Exception ex) catch (Exception ex)
{ {
_sendRawToWebView("SendRtcSignalToJsAsync failed: " + ex.Message); _sendRawToWebView("SendRtcSignalToJsAsync failed: " + ex.Message);
} }
}); });
return Task.CompletedTask; return Task.CompletedTask;
} }
}
[JsonSourceGenerationOptions(WriteIndented = false)]
[JsonSerializable(typeof(RtcDescription))]
[JsonSerializable(typeof(List<RtcSignalMessage>))]
[JsonSerializable(typeof(RtcSignalMessage))]
[JsonSerializable(typeof(IceCandidate))]
[JsonSerializable(typeof(List<IceCandidate>))]
[JsonSerializable(typeof(string))]
internal partial class RtcJsType : JsonSerializerContext
{
} }

View File

@@ -66,7 +66,7 @@ Start-Sleep -Seconds 5
$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 5
& '$clientExe' --user Test & '$clientExe' --user Test
"@ "@