onChanges method
Imports change blobs rebroadcast by the relay.
CRDTDocument.importChanges de-duplicates, so re-delivered blobs are
harmless.
A blob this client cannot read becomes a SyncFault.
Reported on CRDTSocketClient.faults, never thrown: this runs inside the
callback that reads the socket, where a throw reaches no catch and no
onError and ends up as an uncaught error in the zone.
A relay checks the protocol version and nothing else, so it is this path, not the CRDT-aware one, that meets unreadable state most often.
Implementation
void onChanges(RelayChangesMessage message) {
try {
document.importChanges([
for (final blob in message.changes)
Change.fromBytes(base64Decode(blob)),
]);
} catch (error, stackTrace) {
client.reportSyncFault(
SyncFault(
reason: 'Could not import ${message.changes.length} change blob(s) '
'the relay rebroadcast',
error: error,
stackTrace: stackTrace,
),
);
return;
}
_seqTracker.addRange(
from: message.seq - message.changes.length,
to: message.seq,
);
}