Realtime socket
Realtime socket in the .NET SDK.
| Symbol | Kind | Summary |
|---|---|---|
NexusRealtimeErrorEventArgs | class | Why a realtime connection failed or dropped. |
NexusRealtimeMessage | class | One message received from a realtime room. |
NexusRealtimeOptions | class | How the realtime connection behaves. |
NexusRealtimeSocket | class | A Socket.IO connection to the Nexus realtime plane, for receiving room traffic. |
NexusRealtimeErrorEventArgs
class Inverge.Nexus.Realtimeclass Inverge.Nexus.Realtime.NexusRealtimeErrorEventArgsWhy a realtime connection failed or dropped.
Exception
propertyException? Exception { get; }The underlying exception, when there was one.
IsBillingSuspended
propertybool IsBillingSuspended { get; }Whether the handshake was refused because the organisation's data plane is suspended for unpaid invoices.
The server reports this distinctly from a bad key precisely so a client can tell "pay the bill" apart from "fix your credentials" and stop retrying.
IsUnauthorized
propertybool IsUnauthorized { get; }Whether the API key was rejected.
Message
propertystring Message { get; }The server's message, or the transport's.
NexusRealtimeMessage
class Inverge.Nexus.Realtimeclass Inverge.Nexus.Realtime.NexusRealtimeMessageOne message received from a realtime room.
EventName
propertystring EventName { get; }The event name the message was emitted under.
Payload
propertyJsonNode? Payload { get; }The payload, as JSON. null when the emit carried none.
RawText
propertystring? RawText { get; }The raw frame text, for when the payload will not parse as expected.
As()
methodT? As<T>(JsonSerializerOptions? options = null)Deserializes the payload into T.
Reflection-based, so a trimmed or native-AOT host should read
Payload directly, or pass a options built
from a source-generated context.
Parameters
Prop
Type
Returns T?
NexusRealtimeOptions
class Inverge.Nexus.Realtimeclass Inverge.Nexus.Realtime.NexusRealtimeOptionsHow the realtime connection behaves.
NexusRealtimeOptions
constructornew NexusRealtimeOptions()AckTimeout
propertyTimeSpan AckTimeout { get; set; }How long to wait for a server acknowledgement of join, leave or emit.
ConnectionTimeout
propertyTimeSpan ConnectionTimeout { get; set; }How long to wait for the handshake.
DeviceKey
propertystring? DeviceKey { get; set; }The device key to correlate this connection with.
DistinctId
propertystring? DistinctId { get; set; }The identity to connect as, carried in the handshake.
Optional, and only used for the user-journey correlation of realtime traffic. Room membership does not depend on it.
ExtraHeaders
propertyIDictionary<string, string> ExtraHeaders { get; }Extra handshake headers.
PreferWebSocket
propertybool PreferWebSocket { get; set; }Connect over WebSocket immediately rather than upgrading from long-polling.
On by default: a server-side listener has no reason to start on polling, and skipping the upgrade removes a round trip and a class of proxy-breaks-the-upgrade failure.
Reconnection
propertybool Reconnection { get; set; }Reconnect automatically after a dropped connection.
ReconnectionAttempts
propertyint ReconnectionAttempts { get; set; }How many reconnect attempts before giving up.
ReconnectionDelayMax
propertyTimeSpan ReconnectionDelayMax { get; set; }Longest delay between reconnect attempts.
SessionKey
propertystring? SessionKey { get; set; }The session key to correlate this connection with.
StopOnBillingSuspended
propertybool StopOnBillingSuspended { get; set; }Stop reconnecting when the server refuses the handshake with
billing_suspended.
On by default, and worth leaving on. A suspension is resolved by paying an invoice, not by retrying: a client that keeps reconnecting hammers the server every few seconds for as long as the suspension lasts, and buries the one error message that would have explained it.
Url
propertystring? Url { get; set; }The Socket.IO origin. Defaults to the client's RealtimeUrl, or its API
origin.
NexusRealtimeSocket
class Inverge.Nexus.Realtimeclass Inverge.Nexus.Realtime.NexusRealtimeSocketA Socket.IO connection to the Nexus realtime plane, for receiving room traffic.
The core SDK's Realtime resource only emits. Use this when a .NET process
needs to listen — a worker reacting to room traffic, a bridge into
another system, a test harness.
Rooms are environment-scoped. The key you connect with must belong to the same environment that emits, or you will sit in silence that looks exactly like a bug in your handler.
Handlers registered before connecting are attached on connect, and joined rooms are re-joined after every reconnect — server-side membership does not survive one, so without that a reconnected socket goes quiet permanently.
NexusRealtimeSocket
constructornew NexusRealtimeSocket(INexusClient client, Action<NexusRealtimeOptions>? configure = null)Creates a socket from a configured client.
Parameters
Prop
Type
NexusRealtimeSocket
constructornew NexusRealtimeSocket(NexusOptions options, Action<NexusRealtimeOptions>? configure = null)Creates a socket from options.
Parameters
Prop
Type
IsConnected
propertybool IsConnected { get; }Whether the socket is currently connected.
Rooms
propertyIReadOnlyCollection<string> Rooms { get; }The rooms this socket believes it has joined.
SocketId
propertystring? SocketId { get; }The server's id for this socket, once connected.
Connected
eventevent EventHandler ConnectedRaised once the handshake succeeds, including after a reconnect.
Disconnected
eventevent EventHandler<string> DisconnectedRaised when the connection drops, carrying the reason.
Error
eventevent EventHandler<NexusRealtimeErrorEventArgs> ErrorRaised when the server refuses the connection or reports an error.
ConnectAsync()
methodTask ConnectAsync(CancellationToken cancellationToken = default)Opens the connection. Idempotent.
Parameters
Prop
Type
DisconnectAsync()
methodTask DisconnectAsync()Closes the connection.
DisposeAsync()
methodValueTask DisposeAsync()Returns ValueTask
EmitAsync()
methodTask<JsonNode?> EmitAsync(string room, string eventName, object? payload = null, CancellationToken cancellationToken = default)Emits over the socket.
From a server, the HTTP client.Realtime.EmitAsync is usually the better
choice: it needs no live connection and it is retried and reported like any
other API call.
Parameters
Prop
Type
Returns Task<JsonNode?>
JoinAsync()
methodTask<JsonNode?> JoinAsync(string room, CancellationToken cancellationToken = default)Joins a room. Idempotent, and re-applied automatically after a reconnect.
Parameters
Prop
Type
Returns Task<JsonNode?>
LeaveAsync()
methodTask<JsonNode?> LeaveAsync(string room, CancellationToken cancellationToken = default)Leaves a room, and stops re-joining it on reconnect.
Parameters
Prop
Type
Returns Task<JsonNode?>
Off()
methodvoid Off(string eventName)Removes every handler for an event name.
Parameters
Prop
Type
On()
methodvoid On(string eventName, Func<NexusRealtimeMessage, Task> handler)Registers an async handler for an event name. Several handlers per event are allowed.
Parameters
Prop
Type
On()
methodvoid On(string eventName, Action<NexusRealtimeMessage> handler)Registers a synchronous handler for an event name.
Parameters
Prop
Type
