using Microsoft.AspNetCore.SignalR.Client; namespace AyCode.Services.SignalRs; /// /// Extension methods for applying to /// a client . /// public static class AcSignalRConnectionExtensions { /// /// Applies to the builder: /// WithUrl (with HttpConnectionOptions), keep-alive, server timeout, /// WithAutomaticReconnect, WithStatefulReconnect. /// /// Nullable properties are skipped when null — the underlying SignalR default is kept. /// Combine freely with any other builder extensions before or after this call; the ordering /// follows the fluent chain (last write wins for a given setting). /// /// public static IHubConnectionBuilder AddAcConnection( this IHubConnectionBuilder builder, AcHubConnectionOptions options) { if (options is null) throw new ArgumentNullException(nameof(options)); if (string.IsNullOrWhiteSpace(options.Url)) throw new ArgumentException("AcHubConnectionOptions.Url must be set.", nameof(options)); builder.WithUrl(options.Url, http => { if (options.Transports.HasValue) http.Transports = options.Transports.Value; if (options.TransportMaxBufferSize.HasValue) http.TransportMaxBufferSize = options.TransportMaxBufferSize.Value; if (options.ApplicationMaxBufferSize.HasValue) http.ApplicationMaxBufferSize = options.ApplicationMaxBufferSize.Value; if (options.CloseTimeout.HasValue) http.CloseTimeout = options.CloseTimeout.Value; if (options.SkipNegotiation.HasValue) http.SkipNegotiation = options.SkipNegotiation.Value; }); if (options.KeepAliveInterval.HasValue) builder.WithKeepAliveInterval(options.KeepAliveInterval.Value); if (options.ServerTimeout.HasValue) builder.WithServerTimeout(options.ServerTimeout.Value); if (options.UseAutomaticReconnect) builder.WithAutomaticReconnect(); if (options.UseStatefulReconnect) builder.WithStatefulReconnect(); return builder; } }