Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get ws url from config service #2

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("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