Snapcast.Session (Snapcast v0.4.6)

Copy Markdown View Source

One connected snapclient. Owns the TCP socket, speaks the snapcast protocol, and writes the audio chunks the stream hands it.

On Hello it replies with ServerSettings and registers with Snapcast.Server. The server then assigns the active stream and sends that stream's CodecHeader exactly once (PCM via set_format/3, FLAC via the stream's attach) — the equivalent of snapserver's send(stream->getHeader()). A connecting client therefore receives one codec header for the stream it will play (or none while idle), not a default header followed by the real one. It answers Time requests for clock sync and tracks the client's volume/mute from ClientInfo.

Summary

Functions

Start reading from the socket (after the acceptor transfers ownership).

Returns a specification to start this module under a supervisor.

Write a pre-built CodecHeader frame (FLAC or Opus, framed by the stream) to the client.

Hand a framed message to this session to write to its socket.

Re-send ServerSettings (format-scaled bufferMs) for the next stream, plus — for the :pcm transport — the matching PCM CodecHeader. The :flac transport sends its CodecHeader from the stream via send_codec_header/2 once it has been parsed.

Set this client's playback volume (0-100) via a fresh ServerSettings.

Functions

activate(pid)

Start reading from the socket (after the acceptor transfers ownership).

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

send_codec_header(pid, frame)

Write a pre-built CodecHeader frame (FLAC or Opus, framed by the stream) to the client.

send_frame(pid, frame)

Hand a framed message to this session to write to its socket.

set_format(pid, format, codec \\ :pcm)

Re-send ServerSettings (format-scaled bufferMs) for the next stream, plus — for the :pcm transport — the matching PCM CodecHeader. The :flac transport sends its CodecHeader from the stream via send_codec_header/2 once it has been parsed.

set_volume(pid, volume)

Set this client's playback volume (0-100) via a fresh ServerSettings.

start_link(opts)