Class RealtimeChannel
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
IRealtimeSocketchannelName
stringoptions
ChannelOptions
Fields
IsSubscribed
Flag stating if a channel is currently subscribed.
public bool IsSubscribed
Field Value
Properties
BroadcastOptions
The saved Broadcast Options, set in Register<TBroadcastResponse>(bool, bool)
public BroadcastOptions? BroadcastOptions { get; }
Property Value
HasJoinedOnce
Flag stating whether a channel has been joined once or not.
public bool HasJoinedOnce { get; }
Property Value
IsClosed
As to whether this Channel is Closed
public bool IsClosed { get; }
Property Value
IsErrored
As to if this Channel has Errored
public bool IsErrored { get; }
Property Value
IsJoined
As to if this Channel is currently Joined
public bool IsJoined { get; }
Property Value
IsJoining
As to if this Channel is currently Joining
public bool IsJoining { get; }
Property Value
IsLeaving
As to if this channel is currently leaving
public bool IsLeaving { get; }
Property Value
Options
Options passed to this channel instance.
public ChannelOptions Options { get; }
Property Value
PostgresChangesOptions
The saved Postgres Changes Options, set in Register(PostgresChangesOptions)
public List<PostgresChangesOptions> PostgresChangesOptions { get; }
Property Value
PresenceOptions
The saved Presence Options, set in Register<TPresenceResponse>(string)
public PresenceOptions? PresenceOptions { get; }
Property Value
State
The Channel's current state.
public Constants.ChannelState State { get; }
Property Value
Topic
The channel's topic (identifier)
public string Topic { get; }
Property Value
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.ListenTypeThe 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
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
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
Returns
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
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
boolenables client to receive message it has broadcast
broadcastAck
boolinstructs server to acknowledge that broadcast message was received
Returns
- RealtimeBroadcast<TBroadcastResponse>
Type Parameters
TBroadcastResponse
Exceptions
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
stringused 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
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.ListenTypeThe 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.ChannelEventNametype
stringpayload
objecttimeoutMs
int
Returns
Subscribe(int)
Subscribes to the channel given supplied Options/params.
public Task<IRealtimeChannel> Subscribe(int timeoutMs = 10000)
Parameters
timeoutMs
int
Returns
Unsubscribe()
Unsubscribes from the channel.
public IRealtimeChannel Unsubscribe()