Skip to content

Network actions

This page documents Engine/network operational APIs, not ActionRegistry categories or invented action names. There is no built-in network:* action family in engine/actions.ts.

Engine connection controls

engine.connect("ws://localhost:3000");
// ... use the session while connected
engine.disconnect();

Engine.connect(url) creates a PeerConnection, or a HybridPeerManager when the Engine was constructed with useWebRTC: true, and wires it to ConsensusCore. disconnect() removes the network/sync attachment. Network events are forwarded through the Engine emitter, including net:connected, net:ready, net:message, net:error, and reconnect events.

Transport classes

  • PeerConnection provides WebSocket transport, connect(), disconnect(), sendToPeer(peerId, payload), broadcast(type, payload?), and reconnect configuration.
  • HybridPeerManager starts with WebSocket signaling, can upgrade peers to WebRTC with upgradeToWebRTC(peerId), and falls back to WebSocket.
  • MessageCodec encodes JSON or MessagePack and can compress binary payloads. Its encrypted flag is reserved; setting it currently throws “Encryption not yet implemented”.
  • UniversalRelayServer is a stateless WebSocket relay. It routes peer messages/signaling and optionally multiplexes rooms; it does not own game state.
  • AuthoritativeServer owns an Engine and exposes a separate JSON command protocol for clients. RoomAuthoritativeServer adds one Engine per room.

The network layer transports CRDT sync blobs for peer synchronization; it is not a second command-dispatch implementation. Authoritative servers may accept a wire dispatch command, but that is server protocol handling, not a network:* registry category.