tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
Subscription.cs
Go to the documentation of this file.
1using System;
2using System.Threading;
3using System.Threading.Tasks;
4
5using HotChocolate;
6using HotChocolate.Execution;
7using HotChocolate.Subscriptions;
8using HotChocolate.Types;
9
12
14{
19 [GraphQLDescription(GraphQLDescription)]
20 public sealed class Subscription
21 {
25 public const string GraphQLDescription = "Root Subscription type. Note that subscriptions are performed over Server Sent events.";
26
32 public static string SessionInvalidatedTopic(IAuthenticationContext authenticationContext)
33 {
34 ArgumentNullException.ThrowIfNull(authenticationContext);
35 return $"SessionInvalidated.{authenticationContext.SessionId}";
36 }
37
46 public ValueTask<ISourceStream<SessionInvalidationReason>> SessionInvalidatedStream(
47 [Service] HotChocolate.Subscriptions.ITopicEventReceiver receiver, // Intentionally not using our override here, topic callers are built to explicitly handle cases of server shutdown
48 [Service] ISessionInvalidationTracker invalidationTracker,
49 [Service] IAuthenticationContext authenticationContext,
50 CancellationToken cancellationToken)
51 {
52 ArgumentNullException.ThrowIfNull(receiver);
53 ArgumentNullException.ThrowIfNull(invalidationTracker);
54
55 var subscription = receiver.SubscribeAsync<SessionInvalidationReason>(SessionInvalidatedTopic(authenticationContext), cancellationToken);
56 invalidationTracker.TrackSession(authenticationContext);
57 return subscription;
58 }
59
65 [Subscribe(With = nameof(SessionInvalidatedStream))]
66 [TgsGraphQLAuthorize]
67 public SessionInvalidationReason SessionInvalidated([EventMessage] SessionInvalidationReason sessionInvalidationReason)
68 => sessionInvalidationReason;
69 }
70}
Root type for GraphQL subscriptions.
const string GraphQLDescription
Description to show on the Subscription type.
ValueTask< ISourceStream< SessionInvalidationReason > > SessionInvalidatedStream([Service] HotChocolate.Subscriptions.ITopicEventReceiver receiver, [Service] ISessionInvalidationTracker invalidationTracker, [Service] IAuthenticationContext authenticationContext, CancellationToken cancellationToken)
ISourceStream for SessionInvalidated(SessionInvalidationReason).
static string SessionInvalidatedTopic(IAuthenticationContext authenticationContext)
Gets the topic name for the login session represented by a given authenticationContext .
SessionInvalidationReason SessionInvalidated([EventMessage] SessionInvalidationReason sessionInvalidationReason)
Receive a SessionInvalidationReason immediately before the current login session is invalidated.
For creating and accessing authentication contexts.
SessionInvalidationReason
Reasons TGS may invalidate a user's login session.