tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
ConnectionMappingHub.cs
Go to the documentation of this file.
1using System;
2using System.Threading.Tasks;
3
4using Microsoft.AspNetCore.Authorization;
5using Microsoft.AspNetCore.SignalR;
6
8
10{
16 [TgsAuthorize]
17 abstract class ConnectionMappingHub<TChildHub, THubMethods> : Hub<THubMethods>
18 where TChildHub : ConnectionMappingHub<TChildHub, THubMethods>
19 where THubMethods : class
20 {
25
30
39 {
40 this.connectionMapper = connectionMapper ?? throw new ArgumentNullException(nameof(connectionMapper));
41 this.authenticationContext = authenticationContext ?? throw new ArgumentNullException(nameof(authenticationContext));
42 }
43
45 public override async Task OnConnectedAsync()
46 {
47 await connectionMapper.UserConnected(authenticationContext, (TChildHub)this, Context.ConnectionAborted);
48 await base.OnConnectedAsync();
49 }
50
52 [AllowAnonymous]
53 public override Task OnDisconnectedAsync(Exception? exception)
54 {
55 connectionMapper.UserDisconnected(Context.ConnectionId);
56 return base.OnDisconnectedAsync(exception);
57 }
58 }
59}
Base class for Hub<T>s that want to map their connection IDs to Models.PermissionSets.
readonly IAuthenticationContext authenticationContext
The IAuthenticationContext for the ConnectionMappingHub<TChildHub, THubMethods>.
readonly IHubConnectionMapper< TChildHub, THubMethods > connectionMapper
The IHubConnectionMapper<THub, THubMethods> used to map connections.
ConnectionMappingHub(IHubConnectionMapper< TChildHub, THubMethods > connectionMapper, IAuthenticationContext authenticationContext)
Initializes a new instance of the ConnectionMappingHub<TParentHub, TClientMethods> class.
For creating and accessing authentication contexts.
Handles mapping connection IDs to Users for a given THub .
ValueTask UserConnected(IAuthenticationContext authenticationContext, THub hub, CancellationToken cancellationToken)
To be called when a hub connection is made.
void UserDisconnected(string connectionId)
To be called when a hub connection is terminated.