Changed thread / added helper for UI based messages on MAIN thread.
This commit is contained in:
@@ -105,6 +105,9 @@ public partial class MainPage : ContentPage
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SafeSendRawToWebView($"[{_username}] RAW WS DATA: {e.Data}");
|
||||||
|
|
||||||
|
|
||||||
Console.WriteLine($"[{_username}] RAW WS DATA: {e.Data}");
|
Console.WriteLine($"[{_username}] RAW WS DATA: {e.Data}");
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -358,9 +361,9 @@ public partial class MainPage : ContentPage
|
|||||||
{
|
{
|
||||||
//TODO: get bool value for if channel ID has an active call
|
//TODO: get bool value for if channel ID has an active call
|
||||||
//TODO: Join RTC using current channel ID
|
//TODO: Join RTC using current channel ID
|
||||||
hybridWebView.SendRawMessage($"Attempting to join RTC Channel {_currentChannelName}");
|
SafeSendRawToWebView($"Attempting to join RTC Channel {_currentChannelName}");
|
||||||
bool active = await ServerAPI.GetIsChannelActiveAsync(_currentChannelId);
|
bool active = await ServerAPI.GetIsChannelActiveAsync(_currentChannelId);
|
||||||
hybridWebView.SendRawMessage($"Rtc Channel {_currentChannelName} is active: {active}");
|
SafeSendRawToWebView($"Rtc Channel {_currentChannelName} is active: {active}");
|
||||||
return active;
|
return active;
|
||||||
//await hybridWebView.EvaluateJavaScriptAsync($"window.channelCallJoin({active})");
|
//await hybridWebView.EvaluateJavaScriptAsync($"window.channelCallJoin({active})");
|
||||||
|
|
||||||
@@ -380,7 +383,7 @@ public partial class MainPage : ContentPage
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
hybridWebView.SendRawMessage(ex.Message);
|
SafeSendRawToWebView(ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -408,7 +411,7 @@ public partial class MainPage : ContentPage
|
|||||||
|
|
||||||
private void OnSendMessageButtonClicked(object sender, EventArgs e)
|
private void OnSendMessageButtonClicked(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
hybridWebView.SendRawMessage($"Hello from C#!");
|
SafeSendRawToWebView($"Hello from C#!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OnHybridWebViewRawMessageReceived(object sender, HybridWebViewRawMessageReceivedEventArgs e)
|
private async void OnHybridWebViewRawMessageReceived(object sender, HybridWebViewRawMessageReceivedEventArgs e)
|
||||||
@@ -477,4 +480,19 @@ public partial class MainPage : ContentPage
|
|||||||
|
|
||||||
Console.WriteLine($"[{_username}] pushed RTC context into HybridWebView.");
|
Console.WriteLine($"[{_username}] pushed RTC context into HybridWebView.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SafeSendRawToWebView(string message)
|
||||||
|
{
|
||||||
|
MainThread.BeginInvokeOnMainThread(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
hybridWebView.SendRawMessage(message);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[{_username}] failed to send raw message to HybridWebView: {ex.Message}");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ using RelayServer.Services.Data;
|
|||||||
using RelayServer.Services.Rtc;
|
using RelayServer.Services.Rtc;
|
||||||
using WebSocketSharp;
|
using WebSocketSharp;
|
||||||
using WebSocketSharp.Server;
|
using WebSocketSharp.Server;
|
||||||
|
using ErrorEventArgs = WebSocketSharp.ErrorEventArgs;
|
||||||
|
|
||||||
namespace RelayServer.Services.Chat;
|
namespace RelayServer.Services.Chat;
|
||||||
|
|
||||||
@@ -77,9 +78,16 @@ public class ChatSocketBehavior : WebSocketBehavior
|
|||||||
protected override void OnClose(CloseEventArgs e)
|
protected override void OnClose(CloseEventArgs e)
|
||||||
{
|
{
|
||||||
RtcChannelPresenceService.RemoveSession(ID);
|
RtcChannelPresenceService.RemoveSession(ID);
|
||||||
|
Console.WriteLine($"WebSocket closed: session={ID}, code={e.Code}, reason={e.Reason}");
|
||||||
base.OnClose(e);
|
base.OnClose(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnError(ErrorEventArgs e)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"WebSocket error: session={ID}, message={e.Message}");
|
||||||
|
base.OnError(e);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Extracts a display username from a stored user record id value.
|
/// Extracts a display username from a stored user record id value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user