Skip to content

Commit 334cd2b

Browse files
grdsdevclaude
andauthored
feat: add support for broadcast replay configuration (#1242)
* feat: add support for broadcast replay configuration Added ReplayOption class and replay field to RealtimeChannelConfig to support configuring broadcast replay with 'since' timestamp and optional 'limit' parameter. Broadcast callbacks will automatically receive meta field with replayed status and message id when replay is enabled. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * docs: improve docs for broadcast replay --------- Co-authored-by: Claude <[email protected]>
1 parent 06c35ba commit 334cd2b

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

packages/realtime_client/lib/src/types.dart

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,39 @@ extension ToType on RealtimeListenTypes {
138138
}
139139
}
140140

141+
/// Configuration for broadcast replay feature.
142+
/// Allows replaying broadcast messages from a specific timestamp.
143+
class ReplayOption {
144+
/// Unix timestamp (in milliseconds) from which to start replaying messages
145+
final int since;
146+
147+
/// Optional limit on the number of messages to replay, maximum value of 25.
148+
final int? limit;
149+
150+
const ReplayOption({
151+
required this.since,
152+
this.limit,
153+
});
154+
155+
Map<String, dynamic> toMap() {
156+
final map = <String, dynamic>{'since': since};
157+
if (limit != null) {
158+
map['limit'] = limit;
159+
}
160+
return map;
161+
}
162+
}
163+
141164
class RealtimeChannelConfig {
142165
/// [ack] option instructs server to acknowlege that broadcast message was received
143166
final bool ack;
144167

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

171+
/// [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.
172+
final ReplayOption? replay;
173+
148174
/// [key] option is used to track presence payload across clients
149175
final String key;
150176

@@ -157,18 +183,24 @@ class RealtimeChannelConfig {
157183
const RealtimeChannelConfig({
158184
this.ack = false,
159185
this.self = false,
186+
this.replay,
160187
this.key = '',
161188
this.enabled = false,
162189
this.private = false,
163190
});
164191

165192
Map<String, dynamic> toMap() {
193+
final broadcastConfig = <String, dynamic>{
194+
'ack': ack,
195+
'self': self,
196+
};
197+
if (replay != null) {
198+
broadcastConfig['replay'] = replay!.toMap();
199+
}
200+
166201
return {
167202
'config': {
168-
'broadcast': {
169-
'ack': ack,
170-
'self': self,
171-
},
203+
'broadcast': broadcastConfig,
172204
'presence': {
173205
'key': key,
174206
'enabled': enabled,

0 commit comments

Comments
 (0)