mirror of
https://github.com/osukey/osukey.git
synced 2025-07-23 19:30:06 +09:00
Rename some members and extract connection closure to separate method
This commit is contained in:
@ -25,7 +25,7 @@ namespace osu.Game.Online
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked whenever a new hub connection is built.
|
/// Invoked whenever a new hub connection is built.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Action<HubConnection>? OnNewConnection;
|
public Action<HubConnection>? ConfigureConnection;
|
||||||
|
|
||||||
private readonly string clientName;
|
private readonly string clientName;
|
||||||
private readonly string endpoint;
|
private readonly string endpoint;
|
||||||
@ -106,7 +106,7 @@ namespace osu.Game.Online
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// importantly, rebuild the connection each attempt to get an updated access token.
|
// importantly, rebuild the connection each attempt to get an updated access token.
|
||||||
CurrentConnection = createConnection(cancellationToken);
|
CurrentConnection = buildConnection(cancellationToken);
|
||||||
|
|
||||||
await CurrentConnection.StartAsync(cancellationToken);
|
await CurrentConnection.StartAsync(cancellationToken);
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ namespace osu.Game.Online
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private HubConnection createConnection(CancellationToken cancellationToken)
|
private HubConnection buildConnection(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
Debug.Assert(api != null);
|
Debug.Assert(api != null);
|
||||||
|
|
||||||
@ -152,24 +152,25 @@ namespace osu.Game.Online
|
|||||||
|
|
||||||
var newConnection = builder.Build();
|
var newConnection = builder.Build();
|
||||||
|
|
||||||
OnNewConnection?.Invoke(newConnection);
|
ConfigureConnection?.Invoke(newConnection);
|
||||||
|
|
||||||
newConnection.Closed += ex =>
|
|
||||||
{
|
|
||||||
isConnected.Value = false;
|
|
||||||
|
|
||||||
Logger.Log(ex != null ? $"{clientName} lost connection: {ex}" : $"{clientName} disconnected", LoggingTarget.Network);
|
|
||||||
|
|
||||||
// make sure a disconnect wasn't triggered (and this is still the active connection).
|
|
||||||
if (!cancellationToken.IsCancellationRequested)
|
|
||||||
Task.Run(connect, default);
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
newConnection.Closed += ex => onConnectionClosed(ex, cancellationToken);
|
||||||
return newConnection;
|
return newConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Task onConnectionClosed(Exception? ex, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
isConnected.Value = false;
|
||||||
|
|
||||||
|
Logger.Log(ex != null ? $"{clientName} lost connection: {ex}" : $"{clientName} disconnected", LoggingTarget.Network);
|
||||||
|
|
||||||
|
// make sure a disconnect wasn't triggered (and this is still the active connection).
|
||||||
|
if (!cancellationToken.IsCancellationRequested)
|
||||||
|
Task.Run(connect, default);
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
private async Task disconnect(bool takeLock)
|
private async Task disconnect(bool takeLock)
|
||||||
{
|
{
|
||||||
cancelExistingConnect();
|
cancelExistingConnect();
|
||||||
|
@ -33,7 +33,7 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
{
|
{
|
||||||
connector = new HubClientConnector(nameof(MultiplayerClient), endpoint, api)
|
connector = new HubClientConnector(nameof(MultiplayerClient), endpoint, api)
|
||||||
{
|
{
|
||||||
OnNewConnection = connection =>
|
ConfigureConnection = connection =>
|
||||||
{
|
{
|
||||||
// this is kind of SILLY
|
// this is kind of SILLY
|
||||||
// https://github.com/dotnet/aspnetcore/issues/15198
|
// https://github.com/dotnet/aspnetcore/issues/15198
|
||||||
|
@ -86,7 +86,7 @@ namespace osu.Game.Online.Spectator
|
|||||||
private void load(IAPIProvider api)
|
private void load(IAPIProvider api)
|
||||||
{
|
{
|
||||||
connector = CreateConnector(nameof(SpectatorStreamingClient), endpoint, api);
|
connector = CreateConnector(nameof(SpectatorStreamingClient), endpoint, api);
|
||||||
connector.OnNewConnection = connection =>
|
connector.ConfigureConnection = connection =>
|
||||||
{
|
{
|
||||||
// until strong typed client support is added, each method must be manually bound
|
// until strong typed client support is added, each method must be manually bound
|
||||||
// (see https://github.com/dotnet/aspnetcore/issues/15198)
|
// (see https://github.com/dotnet/aspnetcore/issues/15198)
|
||||||
|
Reference in New Issue
Block a user