1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 14:17:26 +08:00

Fix chat connecting too early

This commit is contained in:
Dan Balasescu 2022-11-04 19:36:24 +09:00
parent 1d2818dc70
commit f12ada9d92
3 changed files with 17 additions and 1 deletions

View File

@ -111,6 +111,8 @@ namespace osu.Game.Online.Chat
} }
}); });
connector.Start();
apiState.BindTo(api.State); apiState.BindTo(api.State);
apiState.BindValueChanged(_ => performChatAckRequest(), true); apiState.BindValueChanged(_ => performChatAckRequest(), true);
} }

View File

@ -49,6 +49,9 @@ namespace osu.Game.Online
this.api = api; this.api = api;
this.versionHash = versionHash; this.versionHash = versionHash;
this.preferMessagePack = preferMessagePack; this.preferMessagePack = preferMessagePack;
// Automatically start these connections.
Start();
} }
protected override Task<PersistentEndpointClient> BuildConnectionAsync(CancellationToken cancellationToken) protected override Task<PersistentEndpointClient> BuildConnectionAsync(CancellationToken cancellationToken)

View File

@ -29,6 +29,7 @@ namespace osu.Game.Online
private readonly Bindable<bool> isConnected = new Bindable<bool>(); private readonly Bindable<bool> isConnected = new Bindable<bool>();
private readonly SemaphoreSlim connectionLock = new SemaphoreSlim(1); private readonly SemaphoreSlim connectionLock = new SemaphoreSlim(1);
private CancellationTokenSource connectCancelSource = new CancellationTokenSource(); private CancellationTokenSource connectCancelSource = new CancellationTokenSource();
private bool started;
/// <summary> /// <summary>
/// Constructs a new <see cref="PersistentEndpointClientConnector"/>. /// Constructs a new <see cref="PersistentEndpointClientConnector"/>.
@ -37,9 +38,19 @@ namespace osu.Game.Online
protected PersistentEndpointClientConnector(IAPIProvider api) protected PersistentEndpointClientConnector(IAPIProvider api)
{ {
API = api; API = api;
apiState.BindTo(api.State); apiState.BindTo(api.State);
}
/// <summary>
/// Attempts to connect and begins processing messages from the remote endpoint.
/// </summary>
public void Start()
{
if (started)
return;
apiState.BindValueChanged(_ => Task.Run(connectIfPossible), true); apiState.BindValueChanged(_ => Task.Run(connectIfPossible), true);
started = true;
} }
public Task Reconnect() public Task Reconnect()