fix(S2-b): use authenticated WSS on standard TLS port

This commit is contained in:
Brent Perteet
2026-08-20 15:43:42 -05:00
parent 71fcb9b63f
commit f9fb9f59f4
5 changed files with 17 additions and 6 deletions

View File

@@ -11,7 +11,10 @@ namespace FieldLogger.Sync;
public sealed record MqttBrokerConfig
{
public required string Host { get; init; }
public int Port { get; init; } = 8884;
public int Port { get; init; } = 443;
/// <summary>When set, use MQTT over secure WebSockets (normally
/// wss://dev.hub.umagul.net/mqtt) instead of raw MQTTS.</summary>
public string? WebSocketUri { get; init; }
public bool UseTls { get; init; } = true;
public required string ClientId { get; init; }
/// <summary>Interim credential (username = orgId, password = scoped per-org secret).
@@ -52,8 +55,13 @@ public sealed class MqttnetTransport : IMqttTransport, IAsyncDisposable
_ackTopic = ackTopic;
var options = new MqttClientOptionsBuilder()
.WithTcpServer(_config.Host, _config.Port)
var builder = new MqttClientOptionsBuilder();
if (string.IsNullOrWhiteSpace(_config.WebSocketUri))
builder.WithTcpServer(_config.Host, _config.Port);
else
builder.WithWebSocketServer(options => options.WithUri(_config.WebSocketUri));
var options = builder
.WithClientId(_config.ClientId)
.WithProtocolVersion(MQTTnet.Formatter.MqttProtocolVersion.V500)
.WithCleanSession(false) // persistent session (durable)