WebSocket transport¶
PeerConnection provides the baseline transport. A connection receives a
relay-assigned peer ID, emits net:ready, and routes application messages as
{ type: "p2p", targetPeerId, payload }. The receiver removes the transport
wrapper and emits the flat payload through net:message, adding the local
transport's fromPeerId.
CRDT synchronization uses a separate typed port. Its V1 payload is
{ version: 1, kind: "sync", data } inside the p2p wrapper. JSON transports
encode data as canonical, strict base64; MessagePack transports encode it as
bytes. The adapter validates this envelope, normalizes data to a non-empty
Uint8Array, and delivers it only for the currently open opaque peer
reference. Sync envelopes are never emitted through net:message.
MessageCodec defaults to MessagePack with compression for payloads above its
threshold. JSON is available as a compatibility format. Binary frames use a
flags byte followed by the payload; the compressed bit is implemented.
The encrypted bit is reserved. MessageCodec throws if it receives that bit;
general codec/network encryption is not wired. The standalone
E2EEncryption implementation is exercised by retained Cuttle crypto tests,
but is not imported into the active Cuttle multiplayer or general peer paths.