Class RustPlusFcmSocket
- Namespace
- RustPlusApi.Fcm
- Assembly
- RustPlusApi.Fcm.dll
Represents a RustPlus FCM listener client for handling FCM connections and notifications.
public abstract class RustPlusFcmSocket : IRustPlusFcmSocket, IDisposable, IAsyncDisposable
- Inheritance
-
RustPlusFcmSocket
- Implements
- Derived
- Inherited Members
Constructors
RustPlusFcmSocket(Credentials, ICollection<string>?, RustPlusFcmSocketOptions?, ILoggerFactory?)
Represents a RustPlus FCM listener client for handling FCM connections and notifications.
protected RustPlusFcmSocket(Credentials credentials, ICollection<string>? persistentIds = null, RustPlusFcmSocketOptions? options = null, ILoggerFactory? loggerFactory = null)
Parameters
credentialsCredentialsThe Credentials used for authentication.
persistentIdsICollection<string>The collection of persistent IDs as ICollection<T> of string.
optionsRustPlusFcmSocketOptionsTuning options (heartbeat interval, inactivity timeout); defaults are used when null.
loggerFactoryILoggerFactoryRoutes the client's diagnostics into your logging stack; logging is disabled (a no-op
NullLogger) when null.
Methods
ConnectAsync(CancellationToken)
Connects to the FCM MCS server over TLS, performs the MCS login handshake, and starts the background message-receive loop. On failure, ErrorOccurred is raised, the partial transport is released (so the instance can retry), and the exception is rethrown to the caller. Instances are single-connection: after Disconnect() or disposal, create a new instance to reconnect.
[ExcludeFromCodeCoverage]
public Task ConnectAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenA token to cancel the connection attempt (TLS connect on net10.0+).
Returns
Remarks
Excluded from coverage: live TLS connection to mtalk.google.com:5228;
the MCS pipeline it drives is exercised offline via the RunReceiveLoopOverStreamAsync seam.
Exceptions
- InvalidOperationException
Thrown when the socket is already connected, or was closed by Disconnect()/disposal.
Disconnect()
Disconnects the client from the FCM server and releases associated resources.
public void Disconnect()
Remarks
Invokes the Disconnecting and Disconnected events.
Dispose()
Releases resources used by the RustPlusFcmSocket.
public void Dispose()
Dispose(bool)
Releases the resources used by the RustPlusFcmSocket.
protected virtual void Dispose(bool disposing)
Parameters
disposingbooltrue to release both managed and unmanaged resources; false to release only unmanaged resources.
DisposeAsync()
Asynchronously disposes the socket: cancels background work, unblocks the in-progress read by tearing down the transport, then awaits the tracked receive loop (bounded by RustPlusApi.Fcm.RustPlusFcmSocket.TeardownTimeout) before releasing remaining resources. Prefer this over Dispose() so teardown deterministically drains the receive loop instead of abandoning it.
public ValueTask DisposeAsync()
Returns
DisposeCoreAsync()
Cancels the instance token, tears down the transport to unblock the synchronous read, awaits the tracked receive loop (bounded), then disposes remaining resources. Override to extend async teardown.
protected virtual ValueTask DisposeCoreAsync()
Returns
ParseNotification(FcmMessage)
Parses an incoming FcmMessage notification. Override this method in a derived class to handle specific notification logic.
protected virtual void ParseNotification(FcmMessage message)
Parameters
messageFcmMessageThe FcmMessage to parse.
Events
Connected
Occurs when the client has successfully connected to the FCM server.
public event EventHandler? Connected
Event Type
Connecting
Occurs when the client is starting to connect to the FCM server.
public event EventHandler? Connecting
Event Type
Disconnected
Occurs when the client has disconnected from the FCM server.
public event EventHandler? Disconnected
Event Type
Disconnecting
Occurs when the client is disconnecting from the FCM server.
public event EventHandler? Disconnecting
Event Type
ErrorOccurred
Occurs when an error is encountered.
public event EventHandler<Exception>? ErrorOccurred
Event Type
Remarks
The event data is the Exception that was thrown.
NotificationReceived
Occurs when a notification is received.
public event EventHandler<string>? NotificationReceived
Event Type
Remarks
The event data is the notification as a string.
SocketClosed
Occurs when the socket is closed.
public event EventHandler? SocketClosed