Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions packages/realtime_client/lib/src/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,39 @@ extension ToType on RealtimeListenTypes {
}
}

/// Configuration for broadcast replay feature.
/// Allows replaying broadcast messages from a specific timestamp.
class ReplayOption {
/// Unix timestamp (in milliseconds) from which to start replaying messages
final int since;

/// Optional limit on the number of messages to replay, maximum value of 25.
final int? limit;

const ReplayOption({
required this.since,
this.limit,
});

Map<String, dynamic> toMap() {
final map = <String, dynamic>{'since': since};
if (limit != null) {
map['limit'] = limit;
}
return map;
}
}

class RealtimeChannelConfig {
/// [ack] option instructs server to acknowlege that broadcast message was received
final bool ack;

/// [self] option enables client to receive message it broadcasted
final bool self;

/// [replay] enables **private** channels to access messages that were sent earlier. Only messages published via [Broadcast From the Database](https://supabase.com/docs/guides/realtime/broadcast#trigger-broadcast-messages-from-your-database) are available for replay.
final ReplayOption? replay;

/// [key] option is used to track presence payload across clients
final String key;

Expand All @@ -157,18 +183,24 @@ class RealtimeChannelConfig {
const RealtimeChannelConfig({
this.ack = false,
this.self = false,
this.replay,
this.key = '',
this.enabled = false,
this.private = false,
});

Map<String, dynamic> toMap() {
final broadcastConfig = <String, dynamic>{
'ack': ack,
'self': self,
};
if (replay != null) {
broadcastConfig['replay'] = replay!.toMap();
}

return {
'config': {
'broadcast': {
'ack': ack,
'self': self,
},
'broadcast': broadcastConfig,
'presence': {
'key': key,
'enabled': enabled,
Expand Down