Rand Stats



Actions Status


Net::Snapcast - Control Snapcast audio players


use Net::Snapcast;

my $sc = Net::Snapcast.new(:$host, :port(1705));

# list clients attached to snapcast
my @clients = $sc.list-clients;

# change volume on a client
$sc.set-volume(@clients[0].id, 100);

# get a supply of events (from other clients only)
# see documentation at https://github.com/badaix/snapcast/blob/master/doc/json_rpc_api/control.md#notifications
$sc.notifications.tap(-> $e {
    say "event type $e<method>: $e<params>";


Net::Snapcast is an interface for controlling players connected to a Snapcast server. Snapcast is a client/server system for building a multiroom audio system. The server consumes audio from one or more sources, controls which client receives which audio stream, and manages latency to keep audio playback synchronized. See https://github.com/badaix/snapcast for more details on Snapcast.

This module implements the control interface to Snapcast, allowing you to manage the various players. You can programmatically control what client is connected to which stream, change the volume, and receive notifications of changes made by other clients.

This module does not implement any audio sending or receiving. In snapcast terms, this implements the "Control API" (on port 1705 by default).

This module is currently tested with a Snapcast server running 0.25.0.


new(:$host, :$port)

Connects to the given Snapcast server and synchronizes the state.


Re-sync cached snapcast data. This is called automatically as needed and should not need to be invoked manually.


Returns a Supply that receives events from other clients. If this client makes an RPC call (e.g. set-volume), then this Supply will not receive an event.

Events are documented at https://github.com/badaix/snapcast/blob/master/doc/json_rpc_api/control.md#notifications and may vary depending on the Snapcast server.


Returns a list of clients. See the Net::Snapcast::Snapclient class below for the included attributes.

set-volume($id, $volume)

Sets the volume level of the provided client.


Snapclient - details about a connected client

This class is returned from list-clients. This is called "snapclient" after the snapcast player command's name. All attributes should be considered read-only.

Client Attributes


https://github.com/badaix/snapcast - snapcast repo

https://github.com/badaix/snapcast/blob/master/doc/json_rpc_api/control.md - documentation for control protocol


Adrian Kreher avuserow@gmail.com


Copyright 2022 Adrian Kreher

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.