Skip to content

Commit

Permalink
Merge pull request #2 from CasaVinteUm/fix/ws-url-from-config
Browse files Browse the repository at this point in the history
get ws url from config service
  • Loading branch information
jaonoctus authored Apr 4, 2024
2 parents 3c556f7 + f063b64 commit faee6f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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

0 comments on commit faee6f8

Please sign in to comment.