mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-07 15:46:02 +02:00
deploy: 0105f798e0
This commit is contained in:
@@ -8,13 +8,13 @@ public class SignalRBroadcaster : IChatBroadcaster
|
||||
```
|
||||
|
||||
|
||||
Implements IChatBroadcaster to deliver chat events to SignalR-connected clients (via an `IHubContext<ChatHub, IEchoHubClient>`). Use this implementation when the application should push messages, presence updates, channel changes and moderation events to SignalR clients; it routes events to groups, specific clients, or all connected SignalR clients as appropriate.
|
||||
Broadcasts chat events to connected SignalR clients and adapts the generic [`IChatBroadcaster`](../../EchoHub.Core/Contracts/IChatBroadcaster.cs.md) contract to an `IHubContext<ChatHub, IEchoHubClient>`-backed implementation. Use `SignalRBroadcaster` when you need server-side broadcasting of messages, presence updates, channel lifecycle events and administrative actions to SignalR clients; the class centralizes SignalR-specific delivery details so callers can work with the [`IChatBroadcaster`](../../EchoHub.Core/Contracts/IChatBroadcaster.cs.md) abstraction.
|
||||
|
||||
## Remarks
|
||||
This class adapts the generic chat-broadcasting contract to SignalR: it resolves an IHubContext lazily from an IServiceProvider and uses the ChatHub/IEchoHubClient surface to send notifications. It cooperates with a PresenceTracker to map channel lists to active SignalR connection ids and intentionally filters out connections belonging to the IRC gateway. The implementation keeps broadcasting logic simple (group vs. all vs. specific clients) and relies on SignalR's client invocation Tasks for async behavior.
|
||||
`SignalRBroadcaster` resolves and caches an `IHubContext<ChatHub, IEchoHubClient>` lazily from the provided `IServiceProvider`, and uses a [`PresenceTracker`](PresenceTracker.cs.md) to map channels to live connection IDs. It implements the [`IChatBroadcaster`](../../EchoHub.Core/Contracts/IChatBroadcaster.cs.md) surface by translating high-level events (message send, user joined/left, status changes, channel updates, kicks/bans, deletes, nukes, errors, and forced disconnects) into SignalR calls on `Clients.Group`, `Clients.All`, `Clients.Clients` and `Clients.Client`. The implementation intentionally treats connection IDs that start with the `irc-` prefix as non-SignalR (they are handled by a separate IRC gateway), so several methods either filter those IDs out or no-op for them.
|
||||
|
||||
## Notes
|
||||
- The implementation treats connection IDs prefixed with "irc-" as non-SignalR (IRC gateway) and excludes or ignores those ids in several methods; callers must follow that convention if mixing IRC and SignalR connections.
|
||||
- SendMessageToChannelAsync intentionally ignores the excludeConnectionId parameter (comment: SignalR clients render their own message echo). For selective exclusion of a SignalR connection use SendUserJoinedAsync (which excludes non-IRC ids) or other targeted methods that call GroupExcept/Clients.
|
||||
- SendUserStatusChangedAsync will return Task.CompletedTask when no SignalR connections are found for the provided channels — callers should expect no-op behavior in that case.
|
||||
- HubContext is cached in a private field after first resolution from IServiceProvider; the lazy resolution avoids constructor-time resolution (useful to prevent dependency cycles) and subsequent accesses reuse the same IHubContext instance.
|
||||
- The `excludeConnectionId` parameter is ignored by `SendMessageToChannelAsync` (the comment in-source explains the IRC exclusion only applies to the IRC gateway because SignalR clients render their own broadcast echo). Callers expecting the exclude behavior for SignalR clients should not rely on it for this method.
|
||||
- Several methods filter out connection IDs that start with `irc-` (for example `SendUserStatusChangedAsync` and `ForceDisconnectUserAsync`); this convention must be followed by any component that produces or stores mixed connection IDs, otherwise intended recipients may be missed or IRC gateways may receive inappropriate signals.
|
||||
- `HubContext` is resolved once via `IServiceProvider.GetRequiredService<IHubContext<ChatHub, IEchoHubClient>>()` and cached in a private field. If the application's DI configuration does not provide that service the call will throw at first use; caching avoids repeated resolution but means any change in the resolved instance after first access will not be observed.
|
||||
- Methods return the `Task` returned by SignalR calls directly; any exceptions thrown by SignalR delivery will propagate to the caller of the [`IChatBroadcaster`](../../EchoHub.Core/Contracts/IChatBroadcaster.cs.md) method.
|
||||
Reference in New Issue
Block a user