Expand description
Snapcast server library — embeddable synchronized multiroom audio server.
See also: snapcast-client for the client library.
§Architecture
The server is built around a channel-based API matching snapcast-client:
SnapServeris the main entry pointServerEventflows from server → consumer (client connected, stream status, custom messages)ServerCommandflows from consumer → server (typed mutations, custom messages, stop)
§Example
use snapcast_server::{SnapServer, ServerConfig, ServerEvent, ServerCommand};
let config = ServerConfig::default();
let (mut server, mut events) = SnapServer::new(config);
let _audio_tx = server.add_stream("default");
let cmd = server.command_sender();
tokio::spawn(async move {
while let Some(event) = events.recv().await {
match event {
ServerEvent::ClientConnected { id, ref hello } => {
tracing::info!(id, name = hello.host_name, "Client connected");
}
_ => {}
}
}
});
server.run().await?;Modules§
- auth
- Streaming client authentication.
- status
- Re-exported from
snapcast_proto::status. - time
- Time utilities — server timestamp generation using monotonic clock.
Structs§
- Audio
Frame - A timestamped audio frame for server input.
- Client
Settings Update - Settings update pushed to a streaming client via binary protocol.
- Custom
Message - Custom message for application-defined protocol extensions (type 9+).
- F32Audio
Sender - Buffered sender for F32 audio that handles chunking, timestamping, and gap detection.
- Hello
- Hello message JSON payload.
- Sample
Format - Audio sample format: rate, bit depth, and channel count.
- Server
Config - Server configuration for the embeddable library.
- Snap
Server - The embeddable Snapcast server.
- Stream
Config - Per-stream configuration. If
None, inherits fromServerConfig. - Wire
Chunk Data - An encoded audio chunk ready to be sent to clients.
Enums§
- Audio
Data - Audio data pushed by the consumer — either f32 or raw PCM.
- Server
Command - Commands the consumer sends to the server.
- Server
Event - Events emitted by the server to the consumer.
Constants§
- DEFAULT_
ENCRYPTION_ PSK - Default pre-shared key for f32lz4e (encrypted f32lz4) codec.
- DEFAULT_
SAMPLE_ FORMAT - Default sample format: 48000 Hz, 16-bit, stereo.
- DEFAULT_
STREAM_ PORT - Default TCP port for binary protocol (streaming clients).