1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 21:07:33 +08:00

Move poll allowance logic based on signalr connection inside polling component

This commit is contained in:
Dean Herbert 2021-08-17 17:16:21 +09:00
parent 8a1651e830
commit 9eb16fa61d

View File

@ -25,19 +25,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
[Resolved] [Resolved]
private MultiplayerClient client { get; set; } private MultiplayerClient client { get; set; }
private MultiplayerListingPollingComponent multiplayerListingPollingComponent => (MultiplayerListingPollingComponent)ListingPollingComponent;
private readonly IBindable<bool> isConnected = new Bindable<bool>();
protected override void LoadComplete()
{
base.LoadComplete();
isConnected.BindTo(client.IsConnected);
isConnected.BindValueChanged(c => Scheduler.AddOnce(() => multiplayerListingPollingComponent.AllowPolling = c.NewValue));
multiplayerListingPollingComponent.AllowPolling = isConnected.Value;
}
public override void OnResuming(IScreen last) public override void OnResuming(IScreen last)
{ {
base.OnResuming(last); base.OnResuming(last);
@ -47,7 +34,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
if (last is MultiplayerMatchSubScreen match) if (last is MultiplayerMatchSubScreen match)
{ {
RoomManager.RemoveRoom(match.Room); RoomManager.RemoveRoom(match.Room);
multiplayerListingPollingComponent.PollImmediately(); ListingPollingComponent.PollImmediately();
} }
} }
@ -84,27 +71,29 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
private class MultiplayerListingPollingComponent : ListingPollingComponent private class MultiplayerListingPollingComponent : ListingPollingComponent
{ {
private bool allowPolling; [Resolved]
private MultiplayerClient client { get; set; }
public bool AllowPolling private readonly IBindable<bool> isConnected = new Bindable<bool>();
[BackgroundDependencyLoader]
private void load()
{ {
get => allowPolling; isConnected.BindTo(client.IsConnected);
set isConnected.BindValueChanged(c => Scheduler.AddOnce(() =>
{ {
if (allowPolling == value) if (isConnected.Value && IsLoaded)
return;
allowPolling = value;
if (!allowPolling)
return;
if (IsLoaded)
PollImmediately(); PollImmediately();
} }), true);
} }
protected override Task Poll() => AllowPolling ? base.Poll() : Task.CompletedTask; protected override Task Poll()
{
if (!isConnected.Value)
return Task.CompletedTask;
return base.Poll();
}
} }
} }
} }