Fixed connections
This commit is contained in:
@@ -54,7 +54,18 @@ window.addEventListener("load", async () => {
|
||||
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#!")
|
||||
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!!");
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public sealed class RtcBridgeService
|
||||
|
||||
public async Task HandleIncomingRtcSignalAsync(SocketRtcSignalMessage payload)
|
||||
{
|
||||
_sendRawToWebView("HandleIncomingRtcSignal called");
|
||||
// _sendRawToWebView("HandleIncomingRtcSignal called");
|
||||
var currentChannelId = _getCurrentChannelId();
|
||||
|
||||
if (payload.ChannelId != currentChannelId)
|
||||
@@ -134,7 +134,7 @@ public sealed class RtcBridgeService
|
||||
}
|
||||
|
||||
string decryptedJson;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
var privateKey = KeyStorage.LoadPrivateKey(_username);
|
||||
@@ -170,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))
|
||||
@@ -200,37 +203,42 @@ public sealed class RtcBridgeService
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
// await _hybridWebView.InvokeJavaScriptAsync("testIndex", [JsonSerializer.Serialize(data)], [RtcJsType.Default.String]);
|
||||
await _hybridWebView.InvokeJavaScriptAsync("testIndex", [data], [RtcJsType.Default.RtcSignalMessage]);
|
||||
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);
|
||||
}}
|
||||
");
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user