Class Client
Singleton that represents a Client connection to a Realtime Server.
It maintains a singular Websocket with asynchronous listeners (RealtimeChannels).
public class Client : IRealtimeClient<RealtimeSocket, RealtimeChannel>, IGettableHeaders
- Inheritance
-
Client
- Implements
- Inherited Members
Examples
client = Client.Instance
Constructors
Client(string, ClientOptions?)
Initializes a Client instance, this method should be called prior to any other method.
public Client(string realtimeUrl, ClientOptions? options = null)
Parameters
realtimeUrl
stringThe connection url (ex: "ws://localhost:4000/socket" - no trailing slash required)
options
ClientOptions
Properties
GetHeaders
An executable Func
that returns a dictionary of headers to be appended onto a request.
public Func<Dictionary<string, string>>? GetHeaders { get; set; }
Property Value
Options
Client Options - most of which are regarding Socket connection Options
public ClientOptions Options { get; }
Property Value
SerializerSettings
Custom Serializer resolvers and converters that will be used for encoding and decoding Postgrest JSON responses.
By default, Postgrest seems to use a date format that C# and Newtonsoft do not like, so this initial configuration handles that.
public JsonSerializerSettings SerializerSettings { get; }
Property Value
- JsonSerializerSettings
Socket
The backing Socket class.
Most methods of the Client act as proxies to the Socket class.
public IRealtimeSocket? Socket { get; }
Property Value
Subscriptions
Exposes all Realtime RealtimeChannel Subscriptions for R/O public consumption
public ReadOnlyDictionary<string, RealtimeChannel> Subscriptions { get; }
Property Value
Methods
AddDebugHandler(DebugEventHandler)
Adds a debug handler, likely used within a logging solution of some kind.
public void AddDebugHandler(IRealtimeDebugger.DebugEventHandler handler)
Parameters
handler
IRealtimeDebugger.DebugEventHandler
AddStateChangedHandler(SocketStateEventHandler)
Adds a listener to be notified when the socket state changes.
public void AddStateChangedHandler(IRealtimeClient<RealtimeSocket, RealtimeChannel>.SocketStateEventHandler handler)
Parameters
Channel(string)
Adds a RealtimeChannel subscription - if a subscription exists with the same signature, the existing subscription will be returned.
public RealtimeChannel Channel(string channelName)
Parameters
channelName
stringThe name of the Channel to join (totally arbitrary)
Returns
Exceptions
Channel(string, string, string, string?, string?, Dictionary<string, string>?)
Adds a RealtimeChannel subscription - if a subscription exists with the same signature, the existing subscription will be returned.
public RealtimeChannel Channel(string database = "realtime", string schema = "public", string table = "*", string? column = null, string? value = null, Dictionary<string, string>? parameters = null)
Parameters
database
stringDatabase to connect to, with Supabase this will likely be
realtime
.schema
stringPostgres schema, usually
public
table
stringPostgres table name
column
stringPostgres column name
value
stringValue the specified column should have
parameters
Dictionary<string, string>
Returns
ClearDebugHandlers()
Clears debug handlers;
public void ClearDebugHandlers()
ClearStateChangedHandlers()
Clears all of the listeners from receiving socket state changes.
public void ClearStateChangedHandlers()
Connect(Action<IRealtimeClient<RealtimeSocket, RealtimeChannel>, RealtimeException?>?)
Attempts to connect to the socket.
Provides a callback for Task
driven returns.
[Obsolete("Please use ConnectAsync() instead.")]
public IRealtimeClient<RealtimeSocket, RealtimeChannel> Connect(Action<IRealtimeClient<RealtimeSocket, RealtimeChannel>, RealtimeException?>? callback = null)
Parameters
callback
Action<IRealtimeClient<RealtimeSocket, RealtimeChannel>, RealtimeException>
Returns
ConnectAsync()
Attempts to connect to the Socket.
Returns when socket has successfully connected.
public Task<IRealtimeClient<RealtimeSocket, RealtimeChannel>> ConnectAsync()
Returns
Disconnect(WebSocketCloseStatus, string)
Disconnects from the socket server (if connected).
public IRealtimeClient<RealtimeSocket, RealtimeChannel> Disconnect(WebSocketCloseStatus code = WebSocketCloseStatus.NormalClosure, string reason = "Programmatic Disconnect")
Parameters
code
WebSocketCloseStatusStatus Code
reason
stringReason for disconnect
Returns
Remove(RealtimeChannel)
Removes a channel subscription.
public void Remove(RealtimeChannel channel)
Parameters
channel
RealtimeChannel
RemoveDebugHandler(DebugEventHandler)
Removes a debug handler
public void RemoveDebugHandler(IRealtimeDebugger.DebugEventHandler handler)
Parameters
handler
IRealtimeDebugger.DebugEventHandler
RemoveStateChangedHandler(SocketStateEventHandler)
Removes a specified listener from socket state changes.
public void RemoveStateChangedHandler(IRealtimeClient<RealtimeSocket, RealtimeChannel>.SocketStateEventHandler handler)
Parameters
SetAuth(string)
Sets the JWT access token used for channel subscription authorization and Realtime RLS. Ref: https://github.com/supabase/realtime-js/pull/117 | https://github.com/supabase/realtime-js/pull/117
public void SetAuth(string jwt)
Parameters
jwt
string