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