onWelcome method

Future<void> onWelcome(
  1. RelayWelcomeMessage message
)

Imports the room state of a welcome.

The state is merged (merge: true) into the document: on a reconnect the document already holds local state that must not be clobbered. History is kept (pruneHistory: false) so this client can later upload a snapshot covering it.

Unacknowledged local changes survived the reconnect in the queue and are re-pushed; peers de-duplicate re-delivered changes.

Implementation

Future<void> onWelcome(RelayWelcomeMessage message) async {
  document.import(
    snapshot: message.snapshot != null
        ? Snapshot.fromBytes(base64Decode(message.snapshot!))
        : null,
    changes: [
      for (final blob in message.changes)
        Change.fromBytes(base64Decode(blob)),
    ],
    merge: true,
    pruneHistory: false,
  );

  _seqTracker.markThrough(message.seq);
  _handshaken = true;
  _queue.resetInFlight();

  await flush();

  if (message.compact) {
    await uploadSnapshot(message.seq);
  }
}