Expand description
Client-side half of the naia real-time entity replication and messaging library.
The central type is Client<E>, which connects to a naia server,
maintains a local mirror of replicated entities, and sends client
messages and (optionally) client-authoritative entity mutations.
Runs natively (UDP) and in the browser (WebRTC via
wasm32-unknown-unknown). The same application logic compiles for both
targets; only the Socket implementation differs.
§Connection setup
// Optional: include an auth message in the handshake.
// client.auth(MyAuthMessage { token: "…".into() });
client.connect(socket); // begin handshake; loop until ConnectionEvent fires§Main loop
loop {
client.receive_all_packets(); // 1. read from socket
client.process_all_packets(world, &now); // 2. decode + apply
let events: Events<E> = client.take_world_events(); // 3. drain events
let ticks: TickEvents = client.take_tick_events(&now); // 4. tick clock
// 5. apply prediction / interpolation here
client.send_all_packets(world); // 6. flush outbound
}§Key types
| Type | Purpose |
|---|---|
Client<E> | Main entry point |
EntityMut | Builder for client-authoritative entities |
EntityRef | Read-only entity handle |
Publicity | The three visibility states (Private / Public / Delegated) |
CommandHistory | Rollback buffer for client-prediction |
ConnectionStatus | Lifecycle state |
Modules§
- counters
- Internal e2e-debug atomic counters used by the test harness.
- shared
- Re-exports of commonly-used
naia_sharedtypes, scoped for client consumers. - transport
- Transport-layer socket abstractions (UDP, WebRTC, local in-process).
Structs§
- Client
- The naia client — connects to a server, receives replicated entities, and sends client-authoritative mutations and messages.
- Client
Config - Contains Config properties which will be used by a Server or Client
- Client
Tick Event - Fired each client-side simulation tick; iterate via
tick_events.read::<ClientTickEvent>(). - Command
History - Ring buffer of (tick, command) pairs for client-prediction rollback; old entries are pruned when the server acknowledges a tick.
- Connect
Event - Fires when the client successfully establishes a connection to the server; yields the server’s
SocketAddr. - Connection
Stats - Snapshot of per-connection network diagnostics.
- Despawn
Entity Event - Fires when the server despawns a previously replicated entity; yields the world entity
E. - Disconnect
Event - Fires when the connection to the server is lost; yields the server address and the
DisconnectReason. - Entity
Auth Denied Event - Fires when the server denies this client’s authority request for a delegated entity.
- Entity
Auth Granted Event - Fires when the server grants this client authority over a delegated entity.
- Entity
Auth Reset Event - Fires when the server reclaims authority over an entity that was previously delegated to this client.
- Entity
Mut - Scoped mutable handle for a client-owned entity.
- Entity
Priority Mut - Mutable handle for reading and setting an entity’s priority in one priority layer. Lazy-creates a state entry on first write so set-and-forget works even before the entity enters scope for that user.
- Entity
Priority Ref - Read-only view of an entity’s priority state in one priority layer
(global OR per-user). Acquired via the corresponding
*_priority()method onWorldServer,Client, or their Bevy-adapter equivalents. - Entity
Ref - Scoped read-only handle for a client entity.
- Error
Event - Fires when a transport or protocol error occurs; yields a
NaiaClientError. - Events
- All events produced in one frame: connections, entity lifecycle, component changes, messages, and errors.
- Insert
Component Event - Fires when component
Cis inserted on a replicated entity; yields the world entityE. - Message
Event - Fires when a message of type
Marrives on channelC; yields the decodedMvalue. - Publish
Entity Event - Fires when an entity transitions to the
Publicvisibility state and becomes visible to all users. - Reject
Event - Fires when the server explicitly rejects the connection; yields the server address and the
RejectReason. - Remove
Component Event - Fires when component
Cis removed from a replicated entity; yields(E, C)with the last value of the component. - Request
Event - Fires when a request of type
Qarrives on channelC; yields a(ResponseSendKey, Q)pair. - Server
Tick Event - Fired each time the server’s authoritative tick advances; iterate via
tick_events.read::<ServerTickEvent>(). - Spawn
Entity Event - Fires when the server spawns a new replicated entity on this client; yields the world entity
E. - Tick
Events - Collects client and server tick events emitted during a single frame for typed iteration.
- Unpublish
Entity Event - Fires when an entity’s visibility is retracted from the
Publicstate. - Update
Component Event - Fires when component
Con a replicated entity is mutated; yields(Tick, E).
Enums§
- Connection
Status - The lifecycle state of the client’s connection to the server.
- Disconnect
Reason - Why a connection was terminated.
- Entity
Owner - The authority origin of a client-tracked entity.
- Jitter
Buffer Type - Configuration type for jitter buffer behavior
- Naia
Client Error - Errors that can be returned by the naia client.
- Publicity
- Publication visibility of an entity — the shared axis used on both sides of the connection.
Traits§
- Tick
Event - Type-indexed tick event; implemented by
ClientTickEventandServerTickEvent. - World
Event - Type-indexed world event; each concrete type selects one category from
Events.