Realtime-csharp is written as a client library for supabase/realtime.
Documentation can be found here.
The bulk of this library is a translation and c-sharp-ification of the supabase/realtime-js library.
The Websocket-sharp implementation that Realtime-csharp is dependent on does not support TLS1.3
Care was had to make this API as easytm to interact with as possible. Connect()
and Subscribe()
have await
-able signatures
which allow Users to be assured that a connection exists prior to interacting with it.
var endpoint = "ws://localhost:3000";
client = Client.Initialize(endpoint);
await client.Connect();
var channel = client.Channel("realtime", "public", "users");
// Per Event Callbacks
channel.OnInsert += (sender, args) => Console.WriteLine("New item inserted: " + args.Response.Payload.Record);
channel.OnUpdate += (sender, args) => Console.WriteLine("Item updated: " + args.Response.Payload.Record);
channel.OnDelete += (sender, args) => Console.WriteLine("Item deleted");
// Callback for any event, INSERT, UPDATE, or DELETE
channel.OnMessage += (sender, args) => Debug.WriteLine(args.Message.Event);
await channel.Subscribe();
Leveraging Postgrest.BaseModel
s, one ought to be able to coerce SocketResponse Records into their associated models by calling:
// ...
var channel = client.Channel("realtime", "public", "users");
channel.OnInsert += (sender, args) => {
var model = args.Response.Model<User>();
};
await channel.Subscribe();
- Client Connects to Websocket
- Socket Event Handlers
- Open
- Close - when channel is explicitly closed by server or by calling
Channel.Unsubscribe()
- Error
- Realtime Event Handlers
-
INSERT
-
UPDATE
-
DELETE
-
*
-
- Join channels of format:
-
{database}
-
{database}:{schema}
-
{database}:{schema}:{table}
-
{database}:{schema}:{table}:{col}.eq.{val}
-
- Responses supply a Generically Typed Model derived from
BaseModel
- Ability to remove subscription to Realtime Events
- Ability to disconnect from socket.
- Socket reconnects when possible
- Unit Tests
- Documentation
- Nuget Release
Join the ranks! See a problem? Help fix it!
Made with contrib.rocks.
We are more than happy to have contributions! Please submit a PR.