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.seq with every event, and channel.lastSeq holds the last one received.

Handle gaps

client.ts
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.
  }
});
GapMeansDo
{ from, to }Sequences from to to were not receivedFetch those events from your store
{ reset: true }The channel's counter restartedReload recent history

Duplicate events are dropped automatically. Presence changes and client events have no sequence, so they never cause a gap.