Rework Client Config To Use Single URL

This commit is contained in:
Alan Moon 2025-07-05 13:49:19 -07:00
parent 042671da91
commit 53fab11f88
4 changed files with 11 additions and 12 deletions

View File

@ -16,11 +16,8 @@ namespace qtc_net_client_2.ClientModel
[JsonRequired]
public bool MinimizeToTray { get; set; } = true;
[JsonPropertyName("apiEndpoint")]
[JsonPropertyName("serverUrl")]
[JsonRequired]
public string ApiEndpoint { get; set; } = "https://qtc.alanmoon.net/api";
[JsonPropertyName("gatewayEndpoint")]
[JsonRequired]
public string GatewayEndpoint { get; set; } = "https://qtc.alanmoon.net/chat";
public string ServerUrl { get; set; } = "https://qtc.alanmoon.net";
}
}

View File

@ -323,7 +323,7 @@ namespace qtc_net_client_2
guessTheNumber.Show();
break;
case "TicTacToeGame":
TicTacToeGame ticTacToeGame = new TicTacToeGame(_apiService);
TicTacToeGame ticTacToeGame = new TicTacToeGame(_apiService, _config);
ticTacToeGame.Show();
break;
}

View File

@ -6,6 +6,7 @@ using QtCNETAPI.Models;
using QtCNETAPI.Schema;
using QtCNETAPI.Services.ApiService;
using System.Threading.Tasks;
using qtc_net_client_2.ClientModel;
namespace qtc_net_client_2
{
@ -15,13 +16,15 @@ namespace qtc_net_client_2
private GameRoom? CurrentRoom { get; set; }
private IApiService _apiService;
private Config _config;
private AudioService _audioService = new();
private int WinCount { get; set; }
private bool JackpotWon { get; set; } = false;
public TicTacToeGame(IApiService apiService)
public TicTacToeGame(IApiService apiService, Config config)
{
_apiService = apiService;
_config = config;
InitializeComponent();
}
@ -30,7 +33,7 @@ namespace qtc_net_client_2
{
// first, connect to the game hub
GameHubConnection = new HubConnectionBuilder()
.WithUrl("http://localhost:5268/tttgame", options =>
.WithUrl($"{_config.ServerUrl}/tttgame", options =>
{
options.AccessTokenProvider = () => Task.FromResult(_apiService.SessionToken)!;
})

View File

@ -23,8 +23,7 @@ namespace qtc_net_client_2
if(System.Diagnostics.Debugger.IsAttached)
{
// use localhost
clientConfig.ApiEndpoint = "http://localhost:5268/api";
clientConfig.GatewayEndpoint = "http://localhost:5268/chat";
clientConfig.ServerUrl = "http://localhost:5268";
}
// find config file
@ -53,8 +52,8 @@ namespace qtc_net_client_2
// instantiate new ApiService and GatewayService for this session
// this will keep the gateway thread in the main thread (i think)
IApiService api = new ApiService(clientConfig.ApiEndpoint);
IGatewayService gateway = new GatewayService(clientConfig.GatewayEndpoint, api);
IApiService api = new ApiService($"{clientConfig.ServerUrl}/api");
IGatewayService gateway = new GatewayService($"{clientConfig.ServerUrl}/chat", api);
// ping api
var pingResult = await api.PingServerAsync();