Refresh Session Everytime Gateway Connection Is Used To Prevent The Server From Aborting Requests
This commit is contained in:
parent
c7137e4c7e
commit
72d9b99c4c
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user