Table of Contents

Class RealtimeBroadcast<TBroadcastModel>

Namespace
Supabase.Realtime
Assembly
Supabase.Realtime.dll

Represents a realtime broadcast client.

Broadcast follows the publish-subscribe pattern where a client publishes messages to a channel with a unique identifier. Other clients can elect to receive the message in real-time by subscribing to the channel with the same unique identifier. If these clients are online and subscribed then they will receive the message.

Broadcast works by connecting your client to the nearest Realtime server, which will communicate with other servers to relay messages to other clients. A common use-case is sharing a user's cursor position with other clients in an online game.

public class RealtimeBroadcast<TBroadcastModel> : IRealtimeBroadcast where TBroadcastModel : BaseBroadcast

Type Parameters

TBroadcastModel

A model representing expected payload.

Inheritance
RealtimeBroadcast<TBroadcastModel>
Implements
Inherited Members

Constructors

RealtimeBroadcast(RealtimeChannel, BroadcastOptions, JsonSerializerSettings)

Initializes a realtime broadcast helper class.

public RealtimeBroadcast(RealtimeChannel channel, BroadcastOptions options, JsonSerializerSettings serializerSettings)

Parameters

channel RealtimeChannel
options BroadcastOptions
serializerSettings JsonSerializerSettings

Methods

AddBroadcastEventHandler(BroadcastEventHandler)

Adds a broadcast event listener.

public void AddBroadcastEventHandler(IRealtimeBroadcast.BroadcastEventHandler broadcastEventHandler)

Parameters

broadcastEventHandler IRealtimeBroadcast.BroadcastEventHandler

ClearBroadcastEventHandlers()

Clears all broadcast event listeners

public void ClearBroadcastEventHandlers()

Current()

The last received broadcast.

public TBroadcastModel? Current()

Returns

TBroadcastModel

RemoveBroadcastEventHandler(BroadcastEventHandler)

Removes a broadcast event listener.

public void RemoveBroadcastEventHandler(IRealtimeBroadcast.BroadcastEventHandler broadcastEventHandler)

Parameters

broadcastEventHandler IRealtimeBroadcast.BroadcastEventHandler

Send(string?, object, int)

Broadcasts an arbitrary payload

public Task<bool> Send(string? broadcastEventName, object payload, int timeoutMs = 10000)

Parameters

broadcastEventName string
payload object
timeoutMs int

Returns

Task<bool>

TriggerReceived(SocketResponse)

Called by RealtimeChannel when a broadcast event is received, then parsed/typed here.

public void TriggerReceived(SocketResponse response)

Parameters

response SocketResponse

Exceptions

ArgumentException