handleUndecodable method
Called for an incoming data frame no codec could decode.
The default reports a SessionEventType.error event. Sessions may override it to answer the peer (for example, a relay session diagnoses a CRDT-aware sync client that connected to the wrong server).
Implementation
@override
void handleUndecodable(List<int> data) {
final type = Message.getTypeOrNull(data);
// Core-protocol frames (below the relay range) reaching a relay server are
// almost always a CRDT-aware sync client connected to the wrong server.
// The relay does not decode them (they carry no relay semantics), so they
// surface here as undecodable — answer with a diagnostic instead of a
// silent drop. Ping/pong/error decode fine and never reach this path.
if (type != null && type < RelayMessageType.relayHello.value) {
unawaited(
sendMessage(
Message.error(
documentId: _documentIdOf(data) ?? '',
code: Protocol.errorInvalidMessage,
message: 'This server runs the relay protocol: '
'the CRDT-aware sync protocol is not supported. '
'Connect with a relay client.',
),
),
);
return;
}
super.handleUndecodable(data);
}