ClientSocket
Inherits IDisposable
Public Member Functions
void
Releases the resources used by this instance.
bool
Checks whether the current JWT token is valid based on its structure and expiration time. if the current token is valid; otherwise, .
void
Opens the WebSocket connection.
void
Closes the WebSocket connection and disposes of the client.
Task
Requests an application auth code from the service. A task that resolves to the received ApplicationAuthCode.
Task
Extends the validity period of the current user token. if the token was successfully extended; otherwise, . This method requires the functionality to be enabled for the application on the Crowd Control service. If the application is not authorized to extend tokens, this method will always return false. Please contact Crowd Control support for more information.
Task
Redeems an application auth code for a user token and decodes the user information. if the auth code was redeemed successfully; otherwise, .
string?
Gets the Crowd Control interact page link for the current user. The interact page URL for the current user, or if no user is available.
Task
Subscribes to one or more PubSub topics. if the subscription message was sent successfully; otherwise, .
Task
Subscribes to one or more PubSub topics. if the subscription message was sent successfully; otherwise, .
void
Timer callback that attempts to restart the session when reconnect conditions are met.
Task
Checks the connection and session status, and attempts to restart the session if the connection was lost but auto-reconnect is enabled. A task that completes when the reconnection attempt, if any, has finished.
Task
Restarts the current game session by resubscribing to the necessary PubSub topics. if the session was successfully restarted; otherwise, .
Task
Starts a game session for the configured game pack. if the session was successfully started; otherwise, .
Task
Stops the current game session. if the session was successfully stopped; otherwise, .
Task
Loads a set of custom effects to the service for the current game pack. if the effects were successfully loaded; otherwise, .
Task
Removes custom effects from the service by their effect IDs. A task that resolves to true when the removal request completes successfully; otherwise false.
Task
Removes custom effects from the service by their effect IDs. A task that resolves to true when the removal request completes successfully; otherwise false.
Task
Sends a ping message to the service and waits for a pong response to verify connectivity. if a pong response was received within the timeout period; otherwise, .
Task
Sends an RPC message with the specified method and payload. if the message was sent successfully; otherwise, .
Task
Sends message data by wrapping it into a local message payload. if the message was sent successfully; otherwise, .
Task
Sends a raw JSON message over the WebSocket connection. if the message was sent successfully; otherwise, .
Task
Sends a raw JSON message over the WebSocket connection. if the message was sent successfully; otherwise, .
Task
Sends an RPC call with the specified method and arguments. if the message was sent successfully; otherwise, .
Task
Sends an RPC call with the specified method and arguments. if the message was sent successfully; otherwise, .
void
Sends an effect response back to the service.
void
Sends an effect response back to the service.
void
Sends an effect response back to the service.
void
Sends an effect response back to the service.
void
Sends an effect response back to the service.
void
Sends a metadata update message for the current game pack.
void
Sends a metadata update message for the current game pack.
Public Static Functions
bool
Checks whether a given JWT token is valid based on its structure and expiration time. if the token is valid; otherwise, .
bool
Decodes the payload of a JWT token into a User object. if the token was successfully decoded; otherwise, .
Private Functions
void
Task
void
Handles the WebSocket open event.
void
Handles the WebSocket close event.
void
Handles the WebSocket error event.
void
Handles incoming WebSocket messages and routes them based on payload type.
void
Timer callback that sends a keepalive ping so the service does not close the connection for inactivity.
bool
Processes an authentication response to extract and decode the user token. if a valid token was extracted and decoded; otherwise, .
void
Reports status for one effect by id.
void
Reports status for multiple effects by id.
void
Subscribes to PubSub topics using the current token.
void
Subscribes to PubSub topics using the current token.
Protected Functions
void
Releases the resources used by this instance.
Private Attributes
WebSocketSharp.CustomHeaders.WebSocket
m_ws
Underlying WebSocket connection to the PubSub service.
HttpClient
m_http
HTTP client for REST API calls.
ApplicationAuthCodeRedeemed
m_lastApplicationAuthCodeRedeemed
The most recent application auth code redemption payload received from the service.
string?
m_jwt
The current JWT token.
string?
m_authCodeVerifier
The PKCE verifier for the active application auth-code attempt.
User?
m_localUser
The local user information.
List
m_subscribedTopics
Set of currently subscribed topics.
string
m_sessionID
The current game session ID.
SITimeSpan
PING_TIMEOUT
TimeSpan
PING_INTERVAL
Interval between keepalive pings. The service closes connections after 10 minutes of inactivity, so pings must be sent at least every 9 minutes.
TimeSpan
TOKEN_REFRESH_TIME
TimeSpan
TOKEN_REFRESH_MARGIN
TimeSpan
RECONNECT_TIME
ServerMessage
EMPTY_PONG
Represents a static server message instance for a direct 'pong' response. This instance is used to avoid instantiating multiple identical 'pong' messages.
Timer?
m_tokenRefreshTimer
Timer?
m_reconnectTimer
Timer?
m_pingTimer
Properties
bool
Connected
[get, ]
Gets whether the WebSocket is connected.
string
GameID
[get, ]
The game identifier used when connecting to the Crowd Control service.
string
ApplicationID
[get, ]
The application identifier used for authentication with the Crowd Control service.
bool
IsDisposed
[get, set]
Gets a value indicating whether this instance has been disposed.
bool
AutoReconnect
[get, set]
Gets or sets a value indicating whether the client should automatically reconnect after an unexpected disconnect.
bool
IsActiveSession
[get, ]
Gets a value indicating whether the client is connected, has a session identifier, and has a valid token.
Events
Action<ApplicationAuthCode>?
ApplicationAuthCodeReceived
Raised when an application auth code is received from the Crowd Control API.
Action<ApplicationAuthCodeRedeemed>?
ApplicationAuthCodeRedeemedReceived
Raised when an application auth code has been redeemed.
Action<ApplicationAuthCodeError>?
ApplicationAuthCodeErrorReceived
Raised when an error occurs during the auth code flow.
Action<string>?
JwtTokenReceived
Raised when a new JWT token is obtained, either through redeeming an auth code or extending an existing token.
Action?
SessionReady
Raised when the client has successfully started a game session and is ready to receive effect requests.
Action?
SessionEnded
Raised when the current game session has been stopped and the client will no longer receive effect requests until a new session is started.
Action<Pong>?
PongReceived
Raised when a pong response is received from the Crowd Control API.
Action<EffectRequest>?
EffectRequestReceived
Raised when an effect request is received from the Crowd Control API.
Action<EffectRequest, Common.EffectResponse>?
EffectResponseSent
Raised when an effect request response is sent to the Crowd Control API.
Action<EffectReport>?
EffectReportSent
Raised when an effect class report is sent to the Crowd Control API.
