Fix attempts for RTC calls
This commit is contained in:
@@ -49,4 +49,12 @@ 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.type === "rtc_offer")
|
||||
HandleOffer(rawJson)
|
||||
LogMessage("Called by SendRtcSignalToJsAsync from C#!")
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
@@ -169,9 +179,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,13 +198,15 @@ public sealed class RtcBridgeService
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private Task SendRtcSignalToJsAsync(string rawJson)
|
||||
private Task SendRtcSignalToJsAsync(RtcSignalMessage data)
|
||||
{
|
||||
MainThread.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var jsArg = JsonSerializer.Serialize(rawJson);
|
||||
|
||||
await _hybridWebView.InvokeJavaScriptAsync("testIndex", [data], [RtcJsType.Default.RtcSignalMessage]);
|
||||
var jsArg = JsonSerializer.Serialize(data);
|
||||
|
||||
await _hybridWebView.EvaluateJavaScriptAsync($@"
|
||||
try {{
|
||||
@@ -221,4 +233,15 @@ public sealed class RtcBridgeService
|
||||
|
||||
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
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user