attempt to gracefully reconnect, do not send notification for player on connect, do not check other players on framework update thread, delay palette+ sending data
This commit is contained in:
@@ -294,7 +294,7 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
|
||||
|
||||
foreach (var entry in await UserGetOnlinePairs().ConfigureAwait(false))
|
||||
{
|
||||
_pairManager.MarkPairOnline(entry, this, false);
|
||||
_pairManager.MarkPairOnline(entry, this, sendNotif: false);
|
||||
}
|
||||
|
||||
_healthCheckTokenSource?.Cancel();
|
||||
@@ -323,7 +323,7 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
|
||||
options.Headers.Add("Authorization", "Bearer " + _serverManager.GetToken());
|
||||
options.Transports = HttpTransportType.WebSockets | HttpTransportType.ServerSentEvents | HttpTransportType.LongPolling;
|
||||
})
|
||||
.WithAutomaticReconnect(new ForeverRetryPolicy())
|
||||
.WithAutomaticReconnect(new ForeverRetryPolicy(Mediator))
|
||||
.ConfigureLogging(a =>
|
||||
{
|
||||
a.ClearProviders().AddProvider(new DalamudLoggingProvider());
|
||||
@@ -347,15 +347,10 @@ public partial class ApiController : MediatorSubscriberBase, IDisposable, IMareH
|
||||
|
||||
private Task MareHubOnReconnecting(Exception? arg)
|
||||
{
|
||||
_connectionDto = null;
|
||||
_healthCheckTokenSource?.Cancel();
|
||||
ServerState = ServerState.Reconnecting;
|
||||
Mediator.Publish(new NotificationMessage("Connection lost", "Connection lost to " + _serverManager.CurrentServer!.ServerName, NotificationType.Error, 5000));
|
||||
Logger.Warn("Connection closed... Reconnecting");
|
||||
Logger.Warn(arg?.Message ?? string.Empty);
|
||||
Logger.Warn(arg?.StackTrace ?? string.Empty);
|
||||
Mediator.Publish(new DisconnectedMessage());
|
||||
_pairManager.ClearPairs();
|
||||
Mediator.Publish(new NotificationMessage("Connection lost", "Connection lost to " + _serverManager.CurrentServer!.ServerName, NotificationType.Warning, 5000));
|
||||
Logger.Warn("Connection closed... Reconnecting", arg);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,35 @@
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
using MareSynchronos.Mediator;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
|
||||
namespace MareSynchronos.WebAPI.Utils;
|
||||
|
||||
public class ForeverRetryPolicy : IRetryPolicy
|
||||
{
|
||||
private readonly MareMediator _mediator;
|
||||
private bool _sentDisconnected = false;
|
||||
|
||||
public ForeverRetryPolicy(MareMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
public TimeSpan? NextRetryDelay(RetryContext retryContext)
|
||||
{
|
||||
return TimeSpan.FromSeconds(new Random().Next(10, 20));
|
||||
TimeSpan timeToWait = TimeSpan.FromSeconds(new Random().Next(10, 20));
|
||||
if (retryContext.PreviousRetryCount == 0)
|
||||
{
|
||||
_sentDisconnected = false;
|
||||
timeToWait = TimeSpan.FromSeconds(1);
|
||||
}
|
||||
else if (retryContext.PreviousRetryCount == 1) timeToWait = TimeSpan.FromSeconds(2);
|
||||
else if (retryContext.PreviousRetryCount == 2) timeToWait = TimeSpan.FromSeconds(3);
|
||||
else
|
||||
{
|
||||
if (!_sentDisconnected)
|
||||
_mediator.Publish(new DisconnectedMessage());
|
||||
_sentDisconnected = true;
|
||||
}
|
||||
|
||||
return timeToWait;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user