add config for server transport type

This commit is contained in:
Stanley Dimant
2025-02-02 03:02:30 +01:00
parent 88d0ab2d99
commit 9af89200c8
4 changed files with 41 additions and 3 deletions

View File

@@ -57,13 +57,23 @@ public class HubFactory : MediatorSubscriberBase
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()
.WithUrl(_serverConfigurationManager.CurrentApiUrl + IMareHub.Path, options =>
{
options.AccessTokenProvider = () => _tokenProvider.GetOrUpdateToken(ct);
options.Transports = HttpTransportType.WebSockets | HttpTransportType.ServerSentEvents | HttpTransportType.LongPolling;
options.Transports = transportType;
})
.AddMessagePackProtocol(opt =>
{