diff --git a/QtCNETAPI/Services/GatewayService/GatewayService.cs b/QtCNETAPI/Services/GatewayService/GatewayService.cs index 8c1d637..660d88b 100644 --- a/QtCNETAPI/Services/GatewayService/GatewayService.cs +++ b/QtCNETAPI/Services/GatewayService/GatewayService.cs @@ -36,9 +36,6 @@ namespace QtCNETAPI.Services.GatewayService public async Task StartAsync() { - // just to be safe (it doesn't load the server since it shouldn't request a new one unless its actually expired) - await _apiService.RefreshSessionIfInvalid(); - // build connection var gwConBuilder = new HubConnectionBuilder() .WithAutomaticReconnect() @@ -51,7 +48,12 @@ namespace QtCNETAPI.Services.GatewayService }) .WithUrl(gwBaseUri, options => { - options.AccessTokenProvider = () => Task.FromResult(_apiService.SessionToken); + options.AccessTokenProvider = async () => + { + // this should hopefully refresh the session every time the gateway connection is used to prevent connection aborts + await _apiService.RefreshSessionIfInvalid(); + return _apiService.SessionToken; + }; }); HubConnection = gwConBuilder.Build(); @@ -119,8 +121,6 @@ namespace QtCNETAPI.Services.GatewayService public async Task JoinLobbyAsync() { - await _apiService.RefreshSessionIfInvalid(); - if (HubConnection == null || HubConnection.State != HubConnectionState.Connected) throw new InvalidOperationException("Function was called before connection was made."); await HubConnection.SendAsync("JoinLobby", _apiService.CurrentUser); @@ -130,8 +130,6 @@ namespace QtCNETAPI.Services.GatewayService public async Task JoinRoomAsync(Room room) { - await _apiService.RefreshSessionIfInvalid(); - if (HubConnection == null || HubConnection.State != HubConnectionState.Connected) throw new InvalidOperationException("Function was called before connection was made."); if (InLobby == true) @@ -150,8 +148,6 @@ namespace QtCNETAPI.Services.GatewayService public async Task LeaveRoomAsync() { - await _apiService.RefreshSessionIfInvalid(); - if (HubConnection == null || HubConnection.State != HubConnectionState.Connected) throw new InvalidOperationException("Function was called before connection was made."); if (InLobby) @@ -168,8 +164,6 @@ namespace QtCNETAPI.Services.GatewayService public async Task PostMessageAsync(Message message) { - await _apiService.RefreshSessionIfInvalid(); - if (HubConnection == null || HubConnection.State != HubConnectionState.Connected) throw new InvalidOperationException("Function was called before connection was made."); await HubConnection.SendAsync("SendMessage", _apiService.CurrentUser, message, InLobby, CurrentRoom); @@ -186,8 +180,6 @@ namespace QtCNETAPI.Services.GatewayService public async Task UpdateStatus(int status) { - await _apiService.RefreshSessionIfInvalid(); - if (HubConnection == null || HubConnection.State != HubConnectionState.Connected) throw new InvalidOperationException("Function was called before connection was made."); await HubConnection.SendAsync("UpdateStatus", _apiService.CurrentUser, status);