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

Merge branch 'socket-client' into websocket-chat-2

This commit is contained in:
Dan Balasescu 2022-11-02 11:49:57 +09:00
commit 3816152c9d
6 changed files with 12 additions and 12 deletions

View File

@ -7,7 +7,7 @@ using Microsoft.AspNetCore.SignalR.Client;
namespace osu.Game.Online namespace osu.Game.Online
{ {
public class HubClient : SocketClient public class HubClient : PersistentEndpointClient
{ {
public readonly HubConnection Connection; public readonly HubConnection Connection;

View File

@ -14,7 +14,7 @@ using osu.Game.Online.API;
namespace osu.Game.Online namespace osu.Game.Online
{ {
public class HubClientConnector : SocketClientConnector, IHubClientConnector public class HubClientConnector : PersistentEndpointClientConnector, IHubClientConnector
{ {
public const string SERVER_SHUTDOWN_MESSAGE = "Server is shutting down."; public const string SERVER_SHUTDOWN_MESSAGE = "Server is shutting down.";
@ -51,7 +51,7 @@ namespace osu.Game.Online
this.preferMessagePack = preferMessagePack; this.preferMessagePack = preferMessagePack;
} }
protected override Task<SocketClient> BuildConnectionAsync(CancellationToken cancellationToken) protected override Task<PersistentEndpointClient> BuildConnectionAsync(CancellationToken cancellationToken)
{ {
var builder = new HubConnectionBuilder() var builder = new HubConnectionBuilder()
.WithUrl(endpoint, options => .WithUrl(endpoint, options =>
@ -91,7 +91,7 @@ namespace osu.Game.Online
ConfigureConnection?.Invoke(newConnection); ConfigureConnection?.Invoke(newConnection);
return Task.FromResult((SocketClient)new HubClient(newConnection)); return Task.FromResult((PersistentEndpointClient)new HubClient(newConnection));
} }
protected override string ClientName { get; } protected override string ClientName { get; }

View File

@ -15,7 +15,7 @@ namespace osu.Game.Online.Notifications
/// <summary> /// <summary>
/// An abstract client which receives notification-related events (chat/notifications). /// An abstract client which receives notification-related events (chat/notifications).
/// </summary> /// </summary>
public abstract class NotificationsClient : SocketClient public abstract class NotificationsClient : PersistentEndpointClient
{ {
public Action<Channel>? ChannelJoined; public Action<Channel>? ChannelJoined;
public Action<List<Message>>? NewMessages; public Action<List<Message>>? NewMessages;

View File

@ -13,7 +13,7 @@ namespace osu.Game.Online.Notifications
/// <summary> /// <summary>
/// An abstract connector or <see cref="NotificationsClient"/>s. /// An abstract connector or <see cref="NotificationsClient"/>s.
/// </summary> /// </summary>
public abstract class NotificationsClientConnector : SocketClientConnector public abstract class NotificationsClientConnector : PersistentEndpointClientConnector
{ {
public event Action<Channel>? ChannelJoined; public event Action<Channel>? ChannelJoined;
public event Action<List<Message>>? NewMessages; public event Action<List<Message>>? NewMessages;
@ -34,7 +34,7 @@ namespace osu.Game.Online.Notifications
client.EnableChat = true; client.EnableChat = true;
} }
protected sealed override async Task<SocketClient> BuildConnectionAsync(CancellationToken cancellationToken) protected sealed override async Task<PersistentEndpointClient> BuildConnectionAsync(CancellationToken cancellationToken)
{ {
var client = await BuildNotificationClientAsync(cancellationToken); var client = await BuildNotificationClientAsync(cancellationToken);

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace osu.Game.Online namespace osu.Game.Online
{ {
public abstract class SocketClient : IAsyncDisposable public abstract class PersistentEndpointClient : IAsyncDisposable
{ {
public event Func<Exception?, Task>? Closed; public event Func<Exception?, Task>? Closed;

View File

@ -11,7 +11,7 @@ using osu.Game.Online.API;
namespace osu.Game.Online namespace osu.Game.Online
{ {
public abstract class SocketClientConnector : IDisposable public abstract class PersistentEndpointClientConnector : IDisposable
{ {
/// <summary> /// <summary>
/// Whether this is connected to the hub, use <see cref="CurrentConnection"/> to access the connection, if this is <c>true</c>. /// Whether this is connected to the hub, use <see cref="CurrentConnection"/> to access the connection, if this is <c>true</c>.
@ -21,7 +21,7 @@ namespace osu.Game.Online
/// <summary> /// <summary>
/// The current connection opened by this connector. /// The current connection opened by this connector.
/// </summary> /// </summary>
public SocketClient? CurrentConnection { get; private set; } public PersistentEndpointClient? CurrentConnection { get; private set; }
protected readonly IAPIProvider API; protected readonly IAPIProvider API;
@ -34,7 +34,7 @@ namespace osu.Game.Online
/// Constructs a new <see cref="HubClientConnector"/>. /// Constructs a new <see cref="HubClientConnector"/>.
/// </summary> /// </summary>
/// <param name="api"> An API provider used to react to connection state changes.</param> /// <param name="api"> An API provider used to react to connection state changes.</param>
protected SocketClientConnector(IAPIProvider api) protected PersistentEndpointClientConnector(IAPIProvider api)
{ {
API = api; API = api;
@ -126,7 +126,7 @@ namespace osu.Game.Online
await Task.Delay(5000, cancellationToken).ConfigureAwait(false); await Task.Delay(5000, cancellationToken).ConfigureAwait(false);
} }
protected abstract Task<SocketClient> BuildConnectionAsync(CancellationToken cancellationToken); protected abstract Task<PersistentEndpointClient> BuildConnectionAsync(CancellationToken cancellationToken);
private async Task onConnectionClosed(Exception? ex, CancellationToken cancellationToken) private async Task onConnectionClosed(Exception? ex, CancellationToken cancellationToken)
{ {