47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using WebSocketSharp;
|
|
|
|
namespace RelayClient;
|
|
|
|
public static class MauiProgram
|
|
{
|
|
// public static event Action<ChatMessage>? MessageSent;
|
|
public static WebSocket wsc = new WebSocket("ws://localhost:1337");
|
|
public static MauiApp CreateMauiApp()
|
|
{
|
|
wsc.OnMessage += (sender, e) => OnWebSocketRecieved(sender, e);
|
|
wsc.Connect();
|
|
var builder = MauiApp.CreateBuilder();
|
|
builder.UseMauiApp<App>().ConfigureFonts(fonts =>
|
|
{
|
|
fonts.AddFont("AnonymousPro-Bold.ttf", "AnonymousProBold");
|
|
fonts.AddFont("AnonymousPro-BoldItalic.ttf", "AnonymousProBoldItalic");
|
|
fonts.AddFont("AnonymousPro-Italic.ttf", "AnonymousProItalic");
|
|
fonts.AddFont("AnonymousPro-Regular.ttf", "AnonymousProRegular");
|
|
});
|
|
|
|
|
|
|
|
#if DEBUG
|
|
builder.Logging.AddDebug();
|
|
#endif
|
|
|
|
return builder.Build();
|
|
}
|
|
|
|
public static void OnWebSocketRecieved(object? sender, MessageEventArgs e)
|
|
{
|
|
Console.WriteLine(sender.ToString());
|
|
|
|
ChatSimulator.Send(e.Data.Split(":")[0], e.Data.Split(":")[1]);
|
|
|
|
// var message = new ChatMessage
|
|
// {
|
|
// SenderUsername = e.Data.Split(":")[0],
|
|
// Text = e.Data.Split(":")[1],
|
|
// Timestamp = DateTime.Now
|
|
// };
|
|
//
|
|
// MessageSent?.Invoke(message);
|
|
}
|
|
} |