1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 08:43:20 +08:00

Replace nullable API with null connector instead

This commit is contained in:
Salman Ahmed 2021-02-11 12:32:54 +03:00
parent 18acd7f080
commit d3c1b47592
4 changed files with 53 additions and 62 deletions

View File

@ -244,11 +244,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{
}
protected override HubClientConnector CreateConnector(string name, string endpoint, IAPIProvider api)
{
// do not pass API to prevent attempting failing connections on an actual hub.
return base.CreateConnector(name, endpoint, null);
}
protected override HubClientConnector CreateConnector(string name, string endpoint, IAPIProvider api) => null;
public void StartPlay(int beatmapId)
{

View File

@ -106,11 +106,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
this.totalUsers = totalUsers;
}
protected override HubClientConnector CreateConnector(string name, string endpoint, IAPIProvider api)
{
// do not pass API to prevent attempting failing connections on an actual hub.
return base.CreateConnector(name, endpoint, null);
}
protected override HubClientConnector CreateConnector(string name, string endpoint, IAPIProvider api) => null;
public void Start(int beatmapId)
{

View File

@ -29,7 +29,7 @@ namespace osu.Game.Online
private readonly string clientName;
private readonly string endpoint;
private readonly IAPIProvider? api;
private readonly IAPIProvider api;
/// <summary>
/// The current connection opened by this connector.
@ -52,16 +52,13 @@ namespace osu.Game.Online
/// </summary>
/// <param name="clientName">The name of the client this connector connects for, used for logging.</param>
/// <param name="endpoint">The endpoint to the hub.</param>
/// <param name="api"> An API provider used to react to connection state changes, or null to not establish connection at all (for testing purposes).</param>
public HubClientConnector(string clientName, string endpoint, IAPIProvider? api)
/// <param name="api"> An API provider used to react to connection state changes.</param>
public HubClientConnector(string clientName, string endpoint, IAPIProvider api)
{
this.clientName = clientName;
this.endpoint = endpoint;
this.api = api;
if (api != null)
{
apiState.BindTo(api.State);
apiState.BindValueChanged(state =>
{
@ -78,7 +75,6 @@ namespace osu.Game.Online
}
}, true);
}
}
private async Task connect()
{
@ -136,8 +132,6 @@ namespace osu.Game.Online
private HubConnection buildConnection(CancellationToken cancellationToken)
{
Debug.Assert(api != null);
var builder = new HubConnectionBuilder()
.WithUrl(endpoint, options => { options.Headers.Add("Authorization", $"Bearer {api.AccessToken}"); });

View File

@ -32,11 +32,12 @@ namespace osu.Game.Online.Spectator
private readonly string endpoint;
[CanBeNull]
private HubClientConnector connector;
private readonly IBindable<bool> isConnected = new BindableBool();
private HubConnection connection => connector.CurrentConnection;
private HubConnection connection => connector?.CurrentConnection;
private readonly List<int> watchingUsers = new List<int>();
@ -86,6 +87,9 @@ namespace osu.Game.Online.Spectator
private void load(IAPIProvider api)
{
connector = CreateConnector(nameof(SpectatorStreamingClient), endpoint, api);
if (connector != null)
{
connector.ConfigureConnection = connection =>
{
// until strong typed client support is added, each method must be manually bound
@ -123,6 +127,7 @@ namespace osu.Game.Online.Spectator
}
}, true);
}
}
protected virtual HubClientConnector CreateConnector(string name, string endpoint, IAPIProvider api) => new HubClientConnector(name, endpoint, api);