[Major, New] Channel.PostgresChanges event will receive the wildcard * changes event, not Channel.OnMessage.
[Major] Channel.OnInsert, Channel.OnUpdate, and Channel.OnDelete now conform to the server's payload of Response.Payload.**Data**
[Major] Channel.OnInsert, Channel.OnUpdate, and Channel.OnDelete now return PostgresChangesEventArgs
[Minor] Rename Channel to RealtimeChannel
Supports better handling of disconnects in RealtimeSocket and adds a Client.OnReconnect event.
[Minor] Moves ChannelOptions to Channel.ChannelOptions
[Minor] Moves ChannelStateChangedEventArgs to Channel.ChannelStateChangedEventArgs
[Minor] Moves Push to Channel.Push
[Minor] Moves Channel.ChannelState to Constants.ChannelState
[Minor] Moves SocketResponse, SocketRequest, SocketResponsePayload, SocketResponseEventArgs, and SocketStateChangedEventArgs to Socket namespace.
[New] Adds RealtimeBroadcast
[New] Adds RealtimePresence
Broadcast:
Given the following model (CursorBroadcast):
class MouseBroadcast : BaseBroadcast<MouseStatus> { }
class MouseStatus
{
[JsonProperty("mouseX")]
public float MouseX { get; set; }
[JsonProperty("mouseY")]
public float MouseY { get; set; }
[JsonProperty("userId")]
public string UserId { get; set; }
}
Listen for typed broadcast events:
var channel = supabase.Realtime.Channel("cursor");
var broadcast = channel.Register<MouseBroadcast>(false, true);
broadcast<MouseBroadcast>().OnBroadcast += (sender, args) =>
{
var state = broadcast.Current();
Debug.WriteLine($"{state.Payload}: {state.Payload.MouseX}:{state.Payload.MouseY}");
};
await channel.Subscribe();
Broadcast an event:
var channel = supabase.Realtime.Channel("cursor");
var data = new CursorBroadcast { Event = "cursor", Payload = new MouseStatus { MouseX = 123, MouseY = 456 } };
channel.Send(ChannelType.Broadcast, data);
Presence:
Given the following model: (UserPresence)
class UserPresence: BasePresence
{
[JsonProperty("lastSeen")]
public DateTime LastSeen { get; set; }
}
Listen for typed presence events:
var presenceId = Guid.NewGuid().ToString();
var channel = supabase.Realtime.Channel("last-seen");
var presence = channel.Register<UserPresence>(presenceId);
presence.OnSync += (sender, args) =>
{
foreach (var state in presence.CurrentState)
{
var userId = state.Key;
var lastSeen = state.Value.First().LastSeen;
Debug.WriteLine($"{userId}: {lastSeen}");
}
};
await channel.Subscribe();
Track a user presence event:
var presenceId = Guid.NewGuid().ToString();
var channel = supabase.Realtime.Channel("last-seen");
var presence = channel.Register<UserPresence>(presenceId);
presence.Track(new UserPresence { LastSeen = DateTime.Now });
Postgres Changes
Using the new Register method:
var channel = supabase.Realtime.Channel("public-users");
channel.Register(new PostgresChangesOptions("public", "users"));
channel.PostgresChanges += (sender, args) =>
{
switch (args.Response.Data.Type)
{
case EventType.Insert:
// Handle user created
break;
case EventType.Update:
// Handle user updated
break;
case EventType.Delete:
// Handle user deleted
break;
}
};
await channel.Subscribe();
Using the previous shorthand (backwards compat):
var channel = supabase.Realtime.Channel("realtime", "public", "users");
channel.PostgresChanges+= (sender, args) =>
{
switch (args.Response.Data.Type)
{
case EventType.Insert:
// Handle user created
break;
case EventType.Update:
// Handle user updated
break;
case EventType.Delete:
// Handle user deleted
break;
}
};
await channel.Subscribe();
Todo:
broadcast
Send
presence
LastState
andCurrentState
Track
eventspostgres_changes
Changes:
Channel.PostgresChanges
event will receive the wildcard*
changes event, notChannel.OnMessage
.Channel.OnInsert
,Channel.OnUpdate
, andChannel.OnDelete
now conform to the server's payload ofResponse.Payload.**Data**
Channel.OnInsert
,Channel.OnUpdate
, andChannel.OnDelete
now returnPostgresChangesEventArgs
Channel
toRealtimeChannel
RealtimeSocket
and adds aClient.OnReconnect
event.ChannelOptions
toChannel.ChannelOptions
ChannelStateChangedEventArgs
toChannel.ChannelStateChangedEventArgs
Push
toChannel.Push
Channel.ChannelState
toConstants.ChannelState
SocketResponse
,SocketRequest
,SocketResponsePayload
,SocketResponseEventArgs
, andSocketStateChangedEventArgs
toSocket
namespace.RealtimeBroadcast
RealtimePresence
Broadcast:
Given the following model (
CursorBroadcast
):Listen for typed broadcast events:
Broadcast an event:
Presence:
Given the following model: (
UserPresence
)Listen for typed presence events:
Track a user presence event:
Postgres Changes
Using the new
Register
method:Using the previous shorthand (backwards compat):