add config for server transport type
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
namespace MareSynchronos.MareConfiguration.Models;
|
using Microsoft.AspNetCore.Http.Connections;
|
||||||
|
|
||||||
|
namespace MareSynchronos.MareConfiguration.Models;
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class ServerStorage
|
public class ServerStorage
|
||||||
@@ -10,4 +12,5 @@ public class ServerStorage
|
|||||||
public string ServerUri { get; set; } = string.Empty;
|
public string ServerUri { get; set; } = string.Empty;
|
||||||
public bool UseOAuth2 { get; set; } = false;
|
public bool UseOAuth2 { get; set; } = false;
|
||||||
public string? OAuthToken { get; set; } = null;
|
public string? OAuthToken { get; set; } = null;
|
||||||
|
public HttpTransportType HttpTransportType { get; set; } = HttpTransportType.WebSockets;
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ using MareSynchronos.MareConfiguration;
|
|||||||
using MareSynchronos.MareConfiguration.Models;
|
using MareSynchronos.MareConfiguration.Models;
|
||||||
using MareSynchronos.Services.Mediator;
|
using MareSynchronos.Services.Mediator;
|
||||||
using MareSynchronos.WebAPI;
|
using MareSynchronos.WebAPI;
|
||||||
|
using Microsoft.AspNetCore.Http.Connections;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IdentityModel.Tokens.Jwt;
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
@@ -549,4 +550,15 @@ public class ServerConfigurationManager
|
|||||||
|
|
||||||
return discordToken;
|
return discordToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HttpTransportType GetTransport()
|
||||||
|
{
|
||||||
|
return CurrentServer.HttpTransportType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetTransportType(HttpTransportType httpTransportType)
|
||||||
|
{
|
||||||
|
CurrentServer.HttpTransportType = httpTransportType;
|
||||||
|
Save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,7 @@ using MareSynchronos.WebAPI;
|
|||||||
using MareSynchronos.WebAPI.Files;
|
using MareSynchronos.WebAPI.Files;
|
||||||
using MareSynchronos.WebAPI.Files.Models;
|
using MareSynchronos.WebAPI.Files.Models;
|
||||||
using MareSynchronos.WebAPI.SignalR.Utils;
|
using MareSynchronos.WebAPI.SignalR.Utils;
|
||||||
|
using Microsoft.AspNetCore.Http.Connections;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@@ -1649,6 +1650,17 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
|||||||
_uiShared.DrawHelpText("You cannot edit the name of the main service.");
|
_uiShared.DrawHelpText("You cannot edit the name of the main service.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui.SetNextItemWidth(200);
|
||||||
|
var serverTransport = _serverConfigurationManager.GetTransport();
|
||||||
|
_uiShared.DrawCombo("Server Transport Type", Enum.GetValues<HttpTransportType>().Where(t => t != HttpTransportType.None),
|
||||||
|
(v) => v.ToString(),
|
||||||
|
onSelected: (t) => _serverConfigurationManager.SetTransportType(t),
|
||||||
|
serverTransport);
|
||||||
|
_uiShared.DrawHelpText("You normally do not need to change this, if you don't know what this is or what it's for, keep it to WebSockets." + Environment.NewLine
|
||||||
|
+ "If you run into connection issues with e.g. VPNs, try ServerSentEvents first before trying out LongPolling." + UiSharedService.TooltipSeparator
|
||||||
|
+ "Note: if the server does not support a specific Transport Type it will fall through to the next automatically: WebSockets > ServerSentEvents > LongPolling");
|
||||||
|
|
||||||
|
|
||||||
if (ImGui.Checkbox("Use Discord OAuth2 Authentication", ref useOauth))
|
if (ImGui.Checkbox("Use Discord OAuth2 Authentication", ref useOauth))
|
||||||
{
|
{
|
||||||
selectedServer.UseOAuth2 = useOauth;
|
selectedServer.UseOAuth2 = useOauth;
|
||||||
@@ -1675,6 +1687,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
|
|||||||
}
|
}
|
||||||
_uiShared.DrawHelpText("Hold CTRL to delete this service");
|
_uiShared.DrawHelpText("Hold CTRL to delete this service");
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.EndTabItem();
|
ImGui.EndTabItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,13 +57,23 @@ public class HubFactory : MediatorSubscriberBase
|
|||||||
|
|
||||||
private HubConnection BuildHubConnection(CancellationToken ct)
|
private HubConnection BuildHubConnection(CancellationToken ct)
|
||||||
{
|
{
|
||||||
Logger.LogDebug("Building new HubConnection");
|
var transportType = _serverConfigurationManager.GetTransport() switch
|
||||||
|
{
|
||||||
|
HttpTransportType.None => HttpTransportType.WebSockets | HttpTransportType.ServerSentEvents | HttpTransportType.LongPolling,
|
||||||
|
HttpTransportType.WebSockets => HttpTransportType.WebSockets | HttpTransportType.ServerSentEvents | HttpTransportType.LongPolling,
|
||||||
|
HttpTransportType.ServerSentEvents => HttpTransportType.ServerSentEvents | HttpTransportType.LongPolling,
|
||||||
|
HttpTransportType.LongPolling => HttpTransportType.LongPolling,
|
||||||
|
_ => HttpTransportType.WebSockets | HttpTransportType.ServerSentEvents | HttpTransportType.LongPolling
|
||||||
|
};
|
||||||
|
|
||||||
|
var baseTransport = _serverConfigurationManager.GetTransport();
|
||||||
|
Logger.LogDebug("Building new HubConnection using transport {transport}", baseTransport);
|
||||||
|
|
||||||
_instance = new HubConnectionBuilder()
|
_instance = new HubConnectionBuilder()
|
||||||
.WithUrl(_serverConfigurationManager.CurrentApiUrl + IMareHub.Path, options =>
|
.WithUrl(_serverConfigurationManager.CurrentApiUrl + IMareHub.Path, options =>
|
||||||
{
|
{
|
||||||
options.AccessTokenProvider = () => _tokenProvider.GetOrUpdateToken(ct);
|
options.AccessTokenProvider = () => _tokenProvider.GetOrUpdateToken(ct);
|
||||||
options.Transports = HttpTransportType.WebSockets | HttpTransportType.ServerSentEvents | HttpTransportType.LongPolling;
|
options.Transports = transportType;
|
||||||
})
|
})
|
||||||
.AddMessagePackProtocol(opt =>
|
.AddMessagePackProtocol(opt =>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user