Upgrading to 5.0
All packages share one version. Upgrade the server, Redis instances, and clients together. The full list of changes is in the changelog.
Server registration
| 4.x | 5.0 |
|---|---|
services.AddDarkWsRedis(channel) | services.AddDarkWs().AddRedis(channel) |
Configuration.AddDarkWs(services) | services.AddDarkWs() |
Configuration.MapDarkWs(endpoints) | endpoints.MapDarkWs(pattern) |
RedisConfiguration.AddDarkWsRedis(...) | services.AddDarkWs().AddRedis(channel) |
Subclass of DarkWsMiddleware | Subclass of DarkWsConnectionHooks, registered with AddConnectionHooks<T>() |
Repeated AddAuthenticator calls | One call on the shared builder; a second call throws |
options.AuthenticationFailedError = … | Remove; failed text authentication always replies auth:failed |
Connection hooks are no longer found by assembly scanning; register each explicitly.
Broadcasts
PublishAsync with a BroadcastTarget replaces the old broadcast methods on
IBroadcaster and HandlerBase:
| 4.x | 5.0 |
|---|---|
BroadcastAsync(action, data) | PublishAsync(BroadcastTarget.All, action, data) |
BroadcastToConnectionAsync(id, action, data) | PublishAsync(BroadcastTarget.Connection(id), action, data) |
BroadcastToSessionAsync(id, action, data) | PublishAsync(BroadcastTarget.Session(id), action, data) |
BroadcastToGroupAsync(group, action, data) | PublishAsync(BroadcastTarget.Group(group), action, data) |
BroadcastToSelfAsync(action, data) | PublishAsync(Self, action, data) |
Pass a cancellation token positionally after the data. Custom IBroadcaster
implementations implement the two PublishAsync overloads that take a token.
Custom backplanes and tests rename DarkWsBroadcast to BroadcastMessage,
DarkWsTarget to BroadcastTargetType, and the envelope's Target/Groups to
TargetType/GroupNames, then recompile. The Redis wire format is unchanged, so 4.x
and 5.0 nodes still exchange single-target messages. Before using Groups or
exclusions, upgrade every node on the channel (see
Redis wire format).
Redis deliveries now run concurrently: do not rely on broadcast order on one connection.
Connections
ConnectionStorage is internal. Inject IDarkWsConnections:
| 4.x | 5.0 |
|---|---|
storage.Add(connection) after changing groups | connections.Refresh(connection) |
storage.GetByConnection(id) | connections.Find(id) |
| Fake recipients in tests | DarkWsTestHost.CreateConnection from DarkWS.Testing |
Custom IWebSocketConnection implementations remove WebSocket and
ReceiveMessageAsync, implement Abort(), and take ReadOnlyMemory<byte> in
SendAsync.
The wire envelope records (InputMessage, OkMessage, ErrorMessage, and others)
are internal. Code that serialized them should use its own records with the
documented id, action, data, and error fields.
Behavior changes
HttpContextafter shutdown. Handlers that keep running afterConnectionAbortedand then readHttpContext,Items, headers, orAspNetSessiongetObjectDisposedException. Copy the values first.Sessionis unaffected.- Busy connections. A connection that pipelines many slow requests can receive
darkws:error:busyafterRequestQueueTimeout(5 s). Retry, or raiseMaxConcurrentRequestsPerConnectionorRequestQueueTimeout, keeping the timeout below keep-alive and client pong timeouts. - Command flooding. Four queue places are reserved for
auth:/logout; a command that finds the queue full closes the connection with 1008. - Upgrade authentication errors return HTTP 401 instead of escaping as server
errors. Opt into
AcceptAnonymousOnUpgradeAuthenticationExceptionto accept anonymously instead.
Browser client
- Authentication and logout use
controlTimeout(30 s) instead ofrequestTimeout. SetcontrolTimeoutto your oldrequestTimeoutto keep the previous deadline. authenticate("")rejects withTypeError; calllogout()instead.- A socket that misses
pongfor 30 seconds is closed and reconnected. SetpongTimeout: 0for the old behavior, and renamepingTimeouttopingInterval. connect()no longer replaces an open socket; callclose()and thenconnect().- More than 256 simultaneous calls reject with
RangeError. RaisemaxPendingRequestsif you need more.
New in 5.0
- Group unions and exclusions:
BroadcastTarget.Groups,ExceptConnection,ExceptSession. - Action filters, request filters, and
DarkWsActionInfometadata. DarkWS.Testingfor testing handlers without sockets.AllowedOrigins,RunActionsOnThreadPool,AllowNullPayloads,KeepSessionOnFailedAuthentication, andAcceptAnonymousOnUpgradeAuthenticationException.- Browser:
authenticationToken,sessionRestoreFailed, retries,requestOptions,onAction,DarkWs.lazy(),isCurrentSocket, andreconnectOnVisible.