diff --git a/Services/ConfigService.cs b/Services/ConfigService.cs index 40d2ceb..adfe870 100644 --- a/Services/ConfigService.cs +++ b/Services/ConfigService.cs @@ -25,6 +25,14 @@ public Uri GetLnBitsHost() return new Uri(host); } + public Uri GetWsHost() + { + var lnbitsHost = this.GetLnBitsHost(); + var deviceId = this.GetSwitchId(); + var wsHost = lnbitsHost.ToString().Replace("http", "ws"); + return new Uri($"{wsHost}api/v1/ws/{deviceId}"); + } + public bool IsKiosk() { return _configuration["IsKiosk"] == "1" || _configuration["IsKiosk"]?.ToLowerInvariant() == "true"; diff --git a/Views/QRCodeWindow.axaml.cs b/Views/QRCodeWindow.axaml.cs index f84c09a..14c1816 100644 --- a/Views/QRCodeWindow.axaml.cs +++ b/Views/QRCodeWindow.axaml.cs @@ -16,6 +16,7 @@ public partial class QRCodeWindow : Window private readonly string _deviceId; private readonly int _pinId; private readonly string _lnUrl; + private readonly Uri _wsUrl; public string? WebSocketResult { get; private set; } @@ -47,6 +48,8 @@ public QRCodeWindow(string deviceId, int pinId, string lnUrl, ConfigService conf Cursor = new Avalonia.Input.Cursor(Avalonia.Input.StandardCursorType.None); } + _wsUrl = configService.GetWsHost(); + Dispatcher.UIThread.InvokeAsync(() => OpenWebSocketAsync()); } @@ -59,7 +62,7 @@ private async void OpenWebSocketAsync() { try { - await _webSocket.ConnectAsync(new Uri($"wss://lnbits.casa21.space/api/v1/ws/{_deviceId}"), CancellationToken.None); + await _webSocket.ConnectAsync(_wsUrl, CancellationToken.None); StartListening(); } catch (Exception ex)