Table of Contents

Class RealtimePresence<TPresenceModel>

Namespace
Supabase.Realtime
Assembly
Supabase.Realtime.dll

Represents a realtime presence client.

When a client subscribes to a channel, it will immediately receive the channel's latest state in a single message. Clients are free to come-and-go as they please, and as long as they are all subscribed to the same channel then they will all have the same Presence state as each other. If a client is suddenly disconnected (for example, they go offline), their state will be automatically removed from the shared state.

public class RealtimePresence<TPresenceModel> : IRealtimePresence where TPresenceModel : BasePresence

Type Parameters

TPresenceModel

A model representing expected payload.

Inheritance
RealtimePresence<TPresenceModel>
Implements
Inherited Members

Constructors

RealtimePresence(RealtimeChannel, PresenceOptions, JsonSerializerSettings)

Initializes a realtime presence helper class.

public RealtimePresence(RealtimeChannel channel, PresenceOptions options, JsonSerializerSettings serializerSettings)

Parameters

channel RealtimeChannel
options PresenceOptions
serializerSettings JsonSerializerSettings

Properties

CurrentState

The Current State of this Presence instance.

public Dictionary<string, List<TPresenceModel>> CurrentState { get; }

Property Value

Dictionary<string, List<TPresenceModel>>

LastState

The Last State of this Presence instance.

public Dictionary<string, List<TPresenceModel>> LastState { get; }

Property Value

Dictionary<string, List<TPresenceModel>>

Methods

AddPresenceEventHandler(EventType, PresenceEventHandler)

Add presence event handler for a given event type.

public void AddPresenceEventHandler(IRealtimePresence.EventType eventType, IRealtimePresence.PresenceEventHandler handler)

Parameters

eventType IRealtimePresence.EventType
handler IRealtimePresence.PresenceEventHandler

ClearPresenceEventHandlers(EventType?)

Clears all event handlers for a given type (if specified) or clears all handlers.

public void ClearPresenceEventHandlers(IRealtimePresence.EventType? eventType = null)

Parameters

eventType IRealtimePresence.EventType?

RemovePresenceEventHandlers(EventType, PresenceEventHandler)

Remove an event handler

public void RemovePresenceEventHandlers(IRealtimePresence.EventType eventType, IRealtimePresence.PresenceEventHandler handler)

Parameters

eventType IRealtimePresence.EventType
handler IRealtimePresence.PresenceEventHandler

Track(object?, int)

"Tracks" an event, used with Supabase.Realtime.Presence.

public Task<Push> Track(object? payload, int timeoutMs = 10000)

Parameters

payload object
timeoutMs int

Returns

Task<Push>

TriggerDiff(SocketResponse)

Triggers a diff comparison and emits events accordingly.

public void TriggerDiff(SocketResponse response)

Parameters

response SocketResponse

Exceptions

ArgumentException

TriggerSync(SocketResponse)

Called in two cases: - By RealtimeChannel when it receives a presence_state initializing message. - By RealtimeChannel When a diff has been received and a new response is saved.

public void TriggerSync(SocketResponse response)

Parameters

response SocketResponse

Untrack()

Untracks an event.

public Task<Push> Untrack()

Returns

Task<Push>