Class Client | realtime-csharp (original) (raw)
Namespace
Assembly
Supabase.Realtime.dll
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
IGettableHeaders
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
string
The connection url (ex: "ws://localhost:4000/socket" - no trailing slash required)
options
ClientOptions
Properties
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
Func<Dictionary<string, string>>
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
ReadOnlyDictionary<string, RealtimeChannel>
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
handler
IRealtimeClient<RealtimeSocket, RealtimeChannel>.SocketStateEventHandler
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
string
The 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
string
Database to connect to, with Supabase this will likely be realtime
.
schema
string
Postgres schema, usually public
table
string
Postgres table name
column
string
Postgres column name
value
string
Value 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
IRealtimeClient<RealtimeSocket, RealtimeChannel>
ConnectAsync()
Attempts to connect to the Socket.
Returns when socket has successfully connected.
public Task<IRealtimeClient<RealtimeSocket, RealtimeChannel>> ConnectAsync()
Returns
Task<IRealtimeClient<RealtimeSocket, RealtimeChannel>>
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
WebSocketCloseStatus
Status Code
reason
string
Reason for disconnect
Returns
IRealtimeClient<RealtimeSocket, RealtimeChannel>
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
handler
IRealtimeClient<RealtimeSocket, RealtimeChannel>.SocketStateEventHandler
SetAuth(string)
public void SetAuth(string jwt)
Parameters
jwt
string