Missed messages
Thunderclap doesn't store messages: your app keeps its own history. Instead, every event carries a sequence number, and when a client may have missed events (for example after being offline), the channel reports a gap so you can fetch them from your own backend.
Sequence numbers
A sequence is [epoch, n]. n grows by one with each event published on the channel. The epoch changes when the channel's counter restarts, which happens rarely.
- Your server gets each event's sequence back from
publish: store it with the message. - Clients get it as
meta.seqwith every event, andchannel.lastSeqholds the last one received.
Handle gaps
room.onGap((gap) => {
if (gap.reset) {
// The channel restarted: reload recent history from your API.
} else {
// Events gap.from to gap.to (inclusive) were missed: fetch them from your API.
}
});| Gap | Means | Do |
|---|---|---|
{ from, to } | Sequences from to to were not received | Fetch those events from your store |
{ reset: true } | The channel's counter restarted | Reload recent history |
Duplicate events are dropped automatically. Presence changes and client events have no sequence, so they never cause a gap.