Network API¶
This page documents network classes and Engine connection operations. Network
transport is not an ActionRegistry category and does not define invented
network:* actions.
Engine integration¶
engine.connect(url) wires a PeerConnection to the game document through
the sync manager (ConsensusCore); with useWebRTC: true, it uses HybridPeerManager. The
transport exchanges Automerge sync messages, not game command histories.
Use engine.disconnect() before compact(), resume(), or other operations
that require a detached document.
Classes¶
PeerConnection(url, engine?, options?): WebSocket client withconnect(),disconnect(),sendToPeer(),broadcast(), peer IDs, and reconnect buffering.HybridPeerManager(options): WebSocket/WebRTC upgrade manager withconnect(),disconnect(),sendToPeer(),broadcast(),upgradeToWebRTC(peerId), and peer inspection methods.WebRTCConnection(remotePeerId, config?): one encoded DataChannel with offer/answer/ICE methods,send,close, and connection state.MessageCodec(config?): JSON or MessagePack encode/decode with optional compression. Encryption framing is reserved and currently unimplemented.SyncTransport: core-owned typed CRDT port.PeerConnectionandHybridPeerManagerimplement its peer-open, peer-close, frame, and accepted send operations; sync wire envelopes are V1 and are notnet:message.UniversalRelayServer(options?): stateless relay withstart(),stop(), room routing, health endpoints, and rate limiting.AuthoritativeServer(engine, options?): server-owned Engine and JSONdescribe/dispatch/historyprotocol.RoomAuthoritativeServerextends this model with room Engines.
All listed network classes are deep imports under network/; they are not
re-exported by core/index.ts.
Experimental relay admission¶
UniversalRelayServerOptions.admissionProvider?: RelayAdmissionProvider is an
experimental, generic extension seam. The provider signature is:
interface RelayAdmissionContext {
operation: "connect";
connectionId: string;
remoteAddress?: string;
}
interface RelayAdmissionDecision {
allowed: boolean;
reason?: string;
}
interface RelayAdmissionProvider {
authorize(
credential: unknown,
context: RelayAdmissionContext,
): Promise<RelayAdmissionDecision>;
}
PeerConnectionOptions.getAdmissionCredential?: () => Promise<unknown> and
EngineNetworkOptions.getAdmissionCredential obtain an opaque, fresh
credential for each socket open/reconnect. The client sends one encoded
{ type: "admission", credential } frame while admission is pending. A
configured provider must allow it before welcome, peer rosters, room
operations, routing, or WebRTC signaling; provider failures and timeouts fail
closed. The reserved frame is never relayed, even without a provider. Without
an admission provider, the relay remains exactly open legacy behavior; without
a client callback, no admission frame is sent.
This seam does not provide game-rule validation, player/human identity, peer-key or ECDH binding, secure transport or encrypted sync, room authorization, replay protection or key rotation, or fair play. TLS/WSS is a separate deployment concern. No external credential service or SDK integration is implied.