Compare commits
5 Commits
RTC-Rewrit
...
4974663128
| Author | SHA1 | Date | |
|---|---|---|---|
| 4974663128 | |||
| 3901542141 | |||
| dd1aa45f6e | |||
| 38662f6655 | |||
| 777328caed |
@@ -49,4 +49,25 @@ window.addEventListener("load", async () => {
|
||||
Media.wireDeviceSelectors();
|
||||
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!!");
|
||||
}
|
||||
@@ -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
|
||||
@@ -137,8 +139,14 @@ async function handleIce(msg) {
|
||||
}
|
||||
|
||||
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}`);
|
||||
}
|
||||
@@ -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
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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,16 +118,23 @@ 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;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
var privateKey = KeyStorage.LoadPrivateKey(_username);
|
||||
@@ -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
|
||||
{
|
||||
}
|
||||
@@ -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
|
||||
"@
|
||||
|
||||
|
||||
Reference in New Issue
Block a user