Snapcast.Session (Snapcast v0.3.2)

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 + CodecHeader and registers with Snapcast.Server (so the current stream starts feeding it). 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 codec header payload (e.g. the FLAC stream header) 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, payload)

Write a pre-built codec header payload (e.g. the FLAC stream header) 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)