Table of Contents

Class RealtimeChannel

Namespace
Supabase.Realtime
Assembly
Supabase.Realtime.dll

Class representation of a channel subscription

public class RealtimeChannel : IRealtimeChannel
Inheritance
RealtimeChannel
Implements
Inherited Members

Constructors

RealtimeChannel(IRealtimeSocket, string, ChannelOptions)

Initializes a Channel - must call Subscribe() to receive events.

public RealtimeChannel(IRealtimeSocket socket, string channelName, ChannelOptions options)

Parameters

socket IRealtimeSocket
channelName string
options ChannelOptions

Fields

IsSubscribed

Flag stating if a channel is currently subscribed.

public bool IsSubscribed

Field Value

bool

Properties

BroadcastOptions

The saved Broadcast Options, set in Register<TBroadcastResponse>(bool, bool)

public BroadcastOptions? BroadcastOptions { get; }

Property Value

BroadcastOptions

HasJoinedOnce

Flag stating whether a channel has been joined once or not.

public bool HasJoinedOnce { get; }

Property Value

bool

IsClosed

As to whether this Channel is Closed

public bool IsClosed { get; }

Property Value

bool

IsErrored

As to if this Channel has Errored

public bool IsErrored { get; }

Property Value

bool

IsJoined

As to if this Channel is currently Joined

public bool IsJoined { get; }

Property Value

bool

IsJoining

As to if this Channel is currently Joining

public bool IsJoining { get; }

Property Value

bool

IsLeaving

As to if this channel is currently leaving

public bool IsLeaving { get; }

Property Value

bool

Options

Options passed to this channel instance.

public ChannelOptions Options { get; }

Property Value

ChannelOptions

PostgresChangesOptions

The saved Postgres Changes Options, set in Register(PostgresChangesOptions)

public List<PostgresChangesOptions> PostgresChangesOptions { get; }

Property Value

List<PostgresChangesOptions>

PresenceOptions

The saved Presence Options, set in Register<TPresenceResponse>(string)

public PresenceOptions? PresenceOptions { get; }

Property Value

PresenceOptions

State

The Channel's current state.

public Constants.ChannelState State { get; }

Property Value

Constants.ChannelState

Topic

The channel's topic (identifier)

public string Topic { get; }

Property Value

string

Methods

AddErrorHandler(ErrorEventHandler)

Adds an error event handler.

public void AddErrorHandler(IRealtimeChannel.ErrorEventHandler handler)

Parameters

handler IRealtimeChannel.ErrorEventHandler

AddMessageReceivedHandler(MessageReceivedHandler)

Registers a message received listener, called when a socket message is received for this channel.

public void AddMessageReceivedHandler(IRealtimeChannel.MessageReceivedHandler messageReceivedHandler)

Parameters

messageReceivedHandler IRealtimeChannel.MessageReceivedHandler

AddPostgresChangeHandler(ListenType, PostgresChangesHandler)

Add a postgres changes listener. Should be paired with Register(PostgresChangesOptions).

public void AddPostgresChangeHandler(PostgresChangesOptions.ListenType listenType, IRealtimeChannel.PostgresChangesHandler postgresChangeHandler)

Parameters

listenType PostgresChangesOptions.ListenType

The type of event this callback should process.

postgresChangeHandler IRealtimeChannel.PostgresChangesHandler

AddStateChangedHandler(StateChangedHandler)

Registers a state changed listener relative to this channel. Called when channel state changes.

public void AddStateChangedHandler(IRealtimeChannel.StateChangedHandler stateChangedHandler)

Parameters

stateChangedHandler IRealtimeChannel.StateChangedHandler

Broadcast()

Returns the IRealtimeBroadcast instance.

public IRealtimeBroadcast? Broadcast()

Returns

IRealtimeBroadcast

Broadcast<TBroadcastModel>()

Returns a typed RealtimeBroadcast<TBroadcastModel> instance.

public RealtimeBroadcast<TBroadcastModel>? Broadcast<TBroadcastModel>() where TBroadcastModel : BaseBroadcast

Returns

RealtimeBroadcast<TBroadcastModel>

Type Parameters

TBroadcastModel

ClearErrorHandlers()

Clears Error Event Handlers

public void ClearErrorHandlers()

ClearMessageReceivedHandlers()

Clears message received listeners.

public void ClearMessageReceivedHandlers()

ClearPostgresChangeHandlers()

Clears all postgres changes listeners.

public void ClearPostgresChangeHandlers()

ClearStateChangedHandlers()

Clears all channel state changed listeners

public void ClearStateChangedHandlers()

Presence()

Returns the IRealtimePresence instance.

public IRealtimePresence? Presence()

Returns

IRealtimePresence

Presence<TPresenceModel>()

Returns a typed RealtimePresence<TPresenceModel> instance.

public RealtimePresence<TPresenceModel>? Presence<TPresenceModel>() where TPresenceModel : BasePresence

Returns

RealtimePresence<TPresenceModel>

Type Parameters

TPresenceModel

Model representing a Presence payload

Push(string, string?, object?, int)

Sends a Push request under this channel.

Maintains a buffer in the event push is called prior to the channel being joined.

public Push Push(string eventName, string? type = null, object? payload = null, int timeoutMs = 10000)

Parameters

eventName string
type string
payload object
timeoutMs int

Returns

Push

Register(PostgresChangesOptions)

Registers postgres_changes options, can be called multiple times.

Should be paired with AddPostgresChangeHandler(ListenType, PostgresChangesHandler)

public IRealtimeChannel Register(PostgresChangesOptions postgresChangesOptions)

Parameters

postgresChangesOptions PostgresChangesOptions

Returns

IRealtimeChannel

Register<TBroadcastResponse>(bool, bool)

Registers a RealtimeBroadcast<TBroadcastModel> instance - allowing broadcast responses to be parsed.

public RealtimeBroadcast<TBroadcastResponse> Register<TBroadcastResponse>(bool broadcastSelf = false, bool broadcastAck = false) where TBroadcastResponse : BaseBroadcast

Parameters

broadcastSelf bool

enables client to receive message it has broadcast

broadcastAck bool

instructs server to acknowledge that broadcast message was received

Returns

RealtimeBroadcast<TBroadcastResponse>

Type Parameters

TBroadcastResponse

Exceptions

InvalidOperationException

Register<TPresenceResponse>(string)

Registers a RealtimePresence<TPresenceModel> instance - allowing presence responses to be parsed and state to be tracked.

public RealtimePresence<TPresenceResponse> Register<TPresenceResponse>(string presenceKey) where TPresenceResponse : BasePresence

Parameters

presenceKey string

used to track presence payload across clients

Returns

RealtimePresence<TPresenceResponse>

Type Parameters

TPresenceResponse

The model representing a presence payload.

Exceptions

InvalidOperationException

Thrown if called multiple times.

Rejoin(int)

Rejoins the channel.

public void Rejoin(int timeoutMs = 10000)

Parameters

timeoutMs int

RemoveErrorHandler(ErrorEventHandler)

Removes an error event handler

public void RemoveErrorHandler(IRealtimeChannel.ErrorEventHandler handler)

Parameters

handler IRealtimeChannel.ErrorEventHandler

Exceptions

NotImplementedException

RemoveMessageReceivedHandler(MessageReceivedHandler)

Removes a message received listener.

public void RemoveMessageReceivedHandler(IRealtimeChannel.MessageReceivedHandler messageReceivedHandler)

Parameters

messageReceivedHandler IRealtimeChannel.MessageReceivedHandler

RemovePostgresChangeHandler(ListenType, PostgresChangesHandler)

Removes a postgres changes listener.

public void RemovePostgresChangeHandler(PostgresChangesOptions.ListenType listenType, IRealtimeChannel.PostgresChangesHandler postgresChangeHandler)

Parameters

listenType PostgresChangesOptions.ListenType

The type of event this callback was registered to process.

postgresChangeHandler IRealtimeChannel.PostgresChangesHandler

RemoveStateChangedHandler(StateChangedHandler)

Removes a channel state changed listener

public void RemoveStateChangedHandler(IRealtimeChannel.StateChangedHandler stateChangedHandler)

Parameters

stateChangedHandler IRealtimeChannel.StateChangedHandler

Send(ChannelEventName, string?, object, int)

Sends an arbitrary payload with a given payload type (Constants.ChannelEventName)

public Task<bool> Send(Constants.ChannelEventName eventName, string? type, object payload, int timeoutMs = 10000)

Parameters

eventName Constants.ChannelEventName
type string
payload object
timeoutMs int

Returns

Task<bool>

Subscribe(int)

Subscribes to the channel given supplied Options/params.

public Task<IRealtimeChannel> Subscribe(int timeoutMs = 10000)

Parameters

timeoutMs int

Returns

Task<IRealtimeChannel>

Unsubscribe()

Unsubscribes from the channel.

public IRealtimeChannel Unsubscribe()

Returns

IRealtimeChannel