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

@@ -50,3 +50,24 @@ window.addEventListener("load", async () => {
await Media.loadDevices();
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() {
LogMessage("Current username: " + currentUsername);
@@ -24,7 +24,7 @@ async function joinChannelCall() {
}
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);
const offer = await pc.createOffer();
// LogMessage(`Offer created: ${JSON.stringify(offer)}`);
await pc.setLocalDescription(offer);
await RelaySocket.sendRtcSignal({
@@ -88,11 +89,12 @@ async function handleRtcSignal(rawJson) {
}
async function handleOffer(msg) {
LogMessage(`Offer handler: ${msg}`);
const pc = await ensurePeerConnectionForUser(msg.from);
await Media.ensureLocalMedia();
await Media.applyLocalStreamToPeerConnection(pc, msg.from);
// const offer = JSON.parse(msg.offer);
await pc.setRemoteDescription({
type: "offer",
sdp: msg.sdp
@@ -138,7 +140,13 @@ async function handleIce(msg) {
if (!msg.candidate) return;
await pc.addIceCandidate(msg.candidate);
const candidateInit = {
candidate: msg.candidate,
sdpMid: msg.sdpMid,
sdpMLineIndex: msg.sdpMLineIndex
};
await pc.addIceCandidate(candidateInit);
LogMessage(`Applied ICE from ${msg.from}`);
}
@@ -159,7 +167,9 @@ async function ensurePeerConnectionForUser(username) {
channelId: currentChannelId,
from: currentUsername,
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.Serialization;
using RelayClient.Crypto;
using RelayShared.Rtc;
using RelayShared.Services;
@@ -70,6 +71,7 @@ public sealed class RtcBridgeService
rtcSignal.ChannelId ??= _getCurrentChannelId();
rtcSignal.From ??= _username;
// _sendRawToWebView($"RTC_SIGNAL file: {JsonSerializer.Serialize(rtcSignal)}");
if (string.IsNullOrWhiteSpace(rtcSignal.ChannelId))
{
_sendRawToWebView("SendRtcSignal failed: missing channel id.");
@@ -116,13 +118,20 @@ public sealed class RtcBridgeService
public async Task HandleIncomingRtcSignalAsync(SocketRtcSignalMessage payload)
{
// _sendRawToWebView("HandleIncomingRtcSignal called");
var currentChannelId = _getCurrentChannelId();
if (payload.ChannelId != currentChannelId)
{
_sendRawToWebView("Channel id does not match");
return;
}
if (payload.SenderUsername == _username)
{
_sendRawToWebView("Received own message");
return;
}
string decryptedJson;
@@ -152,6 +161,7 @@ public sealed class RtcBridgeService
try
{
rtcSignal = JsonSerializer.Deserialize<RtcSignalMessage>(decryptedJson);
// _sendRawToWebView($"Received Encrypted Signal: [{rtcSignal.From}]: {rtcSignal.Offer}");
}
catch (Exception ex)
{
@@ -160,7 +170,10 @@ public sealed class RtcBridgeService
}
if (rtcSignal is null)
{
_sendRawToWebView("rtcSignal is null");
return;
}
if (!string.IsNullOrWhiteSpace(rtcSignal.To) &&
!string.Equals(rtcSignal.To, _username, StringComparison.OrdinalIgnoreCase))
@@ -169,9 +182,9 @@ public sealed class RtcBridgeService
return;
}
_sendRawToWebView("Received encrypted RTC signal: " + decryptedJson);
// _sendRawToWebView("Received encrypted RTC signal: " + decryptedJson);
await SendRtcSignalToJsAsync(decryptedJson);
await SendRtcSignalToJsAsync(rtcSignal);
}
public Task PushRtcContextToJsAsync()
@@ -188,37 +201,55 @@ public sealed class RtcBridgeService
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 () =>
{
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);
}}
");
// await _hybridWebView.InvokeJavaScriptAsync("testIndex", [JsonSerializer.Serialize(data)], [RtcJsType.Default.String]);
await _hybridWebView.InvokeJavaScriptAsync("testIndex", [data], [RtcJsType.Default.RtcSignalMessage]);
#region OldDebugger
// var jsArg = JsonSerializer.Serialize(data);
//
// 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);
// }}
// ");
#endregion
}
catch (Exception ex)
{
_sendRawToWebView("SendRtcSignalToJsAsync failed: " + ex.Message);
}
});
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 @"
Set-Location '$root'
Start-Sleep -Seconds 25
Start-Sleep -Seconds 5
& '$clientExe' --user Test
"@