mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 15:33:05 +08:00
Expose Reconnect
logic in HubClientConnector
This commit is contained in:
parent
c524b665ad
commit
63dd9bd493
@ -64,20 +64,28 @@ namespace osu.Game.Online
|
|||||||
this.preferMessagePack = preferMessagePack;
|
this.preferMessagePack = preferMessagePack;
|
||||||
|
|
||||||
apiState.BindTo(api.State);
|
apiState.BindTo(api.State);
|
||||||
apiState.BindValueChanged(state =>
|
apiState.BindValueChanged(state => connectIfPossible(), true);
|
||||||
{
|
}
|
||||||
switch (state.NewValue)
|
|
||||||
{
|
|
||||||
case APIState.Failing:
|
|
||||||
case APIState.Offline:
|
|
||||||
Task.Run(() => disconnect(true));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case APIState.Online:
|
public void Reconnect()
|
||||||
Task.Run(connect);
|
{
|
||||||
break;
|
Logger.Log($"{clientName} reconnecting...", LoggingTarget.Network);
|
||||||
}
|
Task.Run(connectIfPossible);
|
||||||
}, true);
|
}
|
||||||
|
|
||||||
|
private void connectIfPossible()
|
||||||
|
{
|
||||||
|
switch (apiState.Value)
|
||||||
|
{
|
||||||
|
case APIState.Failing:
|
||||||
|
case APIState.Offline:
|
||||||
|
Task.Run(() => disconnect(true));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case APIState.Online:
|
||||||
|
Task.Run(connect);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task connect()
|
private async Task connect()
|
||||||
|
@ -30,5 +30,10 @@ namespace osu.Game.Online
|
|||||||
/// Invoked whenever a new hub connection is built, to configure it before it's started.
|
/// Invoked whenever a new hub connection is built, to configure it before it's started.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Action<HubConnection>? ConfigureConnection { get; set; }
|
public Action<HubConnection>? ConfigureConnection { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reconnect if already connected.
|
||||||
|
/// </summary>
|
||||||
|
void Reconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user