1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 12:33:01 +08:00

Expose Reconnect logic in HubClientConnector

This commit is contained in:
Dean Herbert 2022-05-26 18:02:50 +09:00
parent c524b665ad
commit 63dd9bd493
2 changed files with 26 additions and 13 deletions

View File

@ -64,9 +64,18 @@ namespace osu.Game.Online
this.preferMessagePack = preferMessagePack;
apiState.BindTo(api.State);
apiState.BindValueChanged(state =>
apiState.BindValueChanged(state => connectIfPossible(), true);
}
public void Reconnect()
{
switch (state.NewValue)
Logger.Log($"{clientName} reconnecting...", LoggingTarget.Network);
Task.Run(connectIfPossible);
}
private void connectIfPossible()
{
switch (apiState.Value)
{
case APIState.Failing:
case APIState.Offline:
@ -77,7 +86,6 @@ namespace osu.Game.Online
Task.Run(connect);
break;
}
}, true);
}
private async Task connect()

View File

@ -30,5 +30,10 @@ namespace osu.Game.Online
/// Invoked whenever a new hub connection is built, to configure it before it's started.
/// </summary>
public Action<HubConnection>? ConfigureConnection { get; set; }
/// <summary>
/// Reconnect if already connected.
/// </summary>
void Reconnect();
}
}