Skip to content

Commit

Permalink
fix: get ws url from config service
Browse files Browse the repository at this point in the history
  • Loading branch information
jaonoctus committed Apr 3, 2024
1 parent 3c556f7 commit 51bb01e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Services/ConfigService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("https", "wss").Replace("http", "ws");
return new Uri($"{wsHost}api/v1/ws/{deviceId}");
}

public bool IsKiosk()
{
return _configuration["IsKiosk"] == "1" || _configuration["IsKiosk"]?.ToLowerInvariant() == "true";
Expand Down
5 changes: 4 additions & 1 deletion Views/QRCodeWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down Expand Up @@ -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());
}

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "8.0.203"
"version": "8.0.103"
}
}
}

0 comments on commit 51bb01e

Please sign in to comment.