diff --git a/Shogi.UI/Pages/Home/Account/AccountManager.cs b/Shogi.UI/Pages/Home/Account/AccountManager.cs index 9ec7ec6..ea24f26 100644 --- a/Shogi.UI/Pages/Home/Account/AccountManager.cs +++ b/Shogi.UI/Pages/Home/Account/AccountManager.cs @@ -112,16 +112,17 @@ public class AccountManager public async Task LogoutAsync() { - await accountState.SetUser(null); var platform = await localStorage.GetAccountPlatform(); await localStorage.DeleteAccountPlatform(); if (platform == WhichAccountPlatform.Guest) { await shogiApi.GuestLogout(); + await accountState.SetUser(null); } else if (platform == WhichAccountPlatform.Microsoft) { + await accountState.SetUser(null); navigation.NavigateToLogout("authentication/logout"); } } diff --git a/Shogi.UI/Shared/ShogiSocket.cs b/Shogi.UI/Shared/ShogiSocket.cs index ef42795..0bc6459 100644 --- a/Shogi.UI/Shared/ShogiSocket.cs +++ b/Shogi.UI/Shared/ShogiSocket.cs @@ -32,10 +32,14 @@ public class ShogiSocket : IDisposable public async Task OpenAsync(string token) { - uriBuilder.Query = new QueryBuilder - { - { "token", token } - }.ToQueryString().Value; + if (this.socket.State == WebSocketState.Open) + { + await this.socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Closing before opening a new connection.", CancellationToken.None); + } + + uriBuilder.Query = new QueryBuilder { { "token", token } }.ToQueryString().Value; + + Console.WriteLine("ShogiSocket.OpenAsync socket state is {0}", this.socket.State.ToString()); await socket.ConnectAsync(this.uriBuilder.Uri, cancelToken.Token); // Fire and forget! I'm way too lazy to write my own javascript interop to a web worker. Nooo thanks. @@ -102,8 +106,8 @@ public class ShogiSocket : IDisposable { if (disposing) { + //socket.Dispose(); // This is handled by the DI container. cancelToken.Cancel(); - socket.Dispose(); memoryOwner.Dispose(); } disposedValue = true;