YAACC - UPNP Client and Server
Loading...
Searching...
No Matches
de.yaacc.snapcast.control.SnapcastOperations Class Reference

The control calls of a Snapcast server with the parameters of the JSON-RPC API (doc/json_rpc_api/control.md of Snapcast): volume, mute, latency and name of clients, mute, stream, members and name of groups, adding and removing streams, and the status. More...

Collaboration diagram for de.yaacc.snapcast.control.SnapcastOperations:
Collaboration graph

Public Member Functions

 SnapcastOperations (SnapcastCaller caller)
 Operations that do not keep a model.
 
 SnapcastOperations (SnapcastCaller caller, SnapcastModelUpdater updater)
 
SnapcastServerStatus getStatus () throws SnapcastException
 Server.GetStatus: the whole state of the server.
 
SnapcastServerStatus freshStatusOrModel ()
 The status as fresh as the rate limit of the model allows: a full Server.GetStatus when the limit grants a read (it becomes the model), otherwise the model as it is.
 
SnapcastVolume setClientVolume (String clientId, SnapcastVolume volume) throws SnapcastException
 Client.SetVolume.
 
void setClientLatency (String clientId, int latencyMs) throws SnapcastException
 Client.SetLatency; the latency is clamped into 0..10,000 ms.
 
void setClientName (String clientId, String name) throws SnapcastException
 Client.SetName.
 
void setGroupMute (String groupId, boolean muted) throws SnapcastException
 Group.SetMute.
 
void setGroupStream (String groupId, String streamId) throws SnapcastException
 Group.SetStream: the group plays this stream.
 
SnapcastServerStatus setGroupClients (String groupId, List< String > clientIds) throws SnapcastException
 Group.SetClients: the group gets exactly these members.
 
SnapcastServerStatus deleteClient (String clientId) throws SnapcastException
 Server.DeleteClient ({"id": <client id>}): the server forgets a client it knows.
 
void setGroupName (String groupId, String name) throws SnapcastException
 Group.SetName.
 
String addStream (String streamUri) throws SnapcastException
 Stream.AddStream.
 
String removeStream (String streamId) throws SnapcastException
 Stream.RemoveStream.
 
Map< String, Integer > setGroupVolume (SnapcastGroup group, int percent) throws SnapcastException
 Sets the volume of a group (the server has none) from one snapshot: the start and the current levels are the levels of group.
 
Map< String, Integer > setGroupVolume (SnapcastGroup current, Map< String, Integer > startLevels, int percent) throws SnapcastException
 Sets the volume of a group (the server has none): the connected members move by the same number of points so that their average becomes percent, see GroupVolume.
 
Map< String, Integer > setGroupVolume (SnapcastGroup current, Map< String, Integer > startLevels, int percent, long budgetMillis) throws SnapcastException
 As setGroupVolume(SnapcastGroup, Map, int), with an overall time budget for the whole gesture: once budgetMillis have passed, no further member is called and the call ends with a TIMEOUT (a server that answers each of up to 256 calls just before its 10 s deadline can not keep the caller for ever).
 

Detailed Description

The control calls of a Snapcast server with the parameters of the JSON-RPC API (doc/json_rpc_api/control.md of Snapcast): volume, mute, latency and name of clients, mute, stream, members and name of groups, adding and removing streams, and the status.

The calls block (they are made on the worker of the server, never on the main thread).

A wrong argument of the caller (a missing id) is an IllegalArgumentException; everything the server does is a SnapcastException. A call that changes the model, and getStatus(), throws an IllegalStateException when it is made from inside a delivery of the listeners (a notification handler, a re-read requester): the call would wait for the thread it blocks. Ids that are handed in come from the model (they were truncated when parsed); names are cut at SnapcastLimits#MAX_STRING_LENGTH characters before they are sent.

The model. With a SnapcastModelUpdater the status that a call returns, and every change of our own, are applied to the model through SnapcastCaller#callOrdered, so in the order of the lines of the connection. That is needed: the server tells every connection about a change except the one that made it, so without it the model would not show what we just did. A stream that was added or removed can not be patched; it asks for a re-read. A failed call changes nothing.

For the code that uses this (Group 3). Give SnapcastRpc a listener executor of its own, used for nothing but the deliveries: a task of anything else on the same single thread blocks the delivery that a callOrdered waits for, and the call ends in TIMEOUT after its deadline. The re-read requester of the SnapcastModelUpdater runs on that thread: it must only hand the read to a worker, never call getStatus() itself. Read a fresh status (on a worker) in onConnected, and repeat a re-read that failed. Do not call SnapcastRpc#reconnect() or SnapcastRpc#retry() in an automatic loop: both reset the failure count, so the ceiling of the reconnects is gone. A single call that takes the whole deadline (10 s) while the server sends nothing else (an AddStream of a slow process:// source) drops the connection: prefer sources that answer at once, or give such a call a longer deadline.

Constructor & Destructor Documentation

◆ SnapcastOperations()

de.yaacc.snapcast.control.SnapcastOperations.SnapcastOperations ( SnapcastCaller caller,
SnapcastModelUpdater updater )
Parameters
updaterthe model to keep up to date with the answers and our own changes; null for none

Member Function Documentation

◆ addStream()

String de.yaacc.snapcast.control.SnapcastOperations.addStream ( String streamUri) throws SnapcastException

Stream.AddStream.

The URI is sent as given: the server may accept any scheme (the documented restriction was not found in its sources), so a caller builds only tcp sources it controls and never passes a URI taken from server data. The control connection has no TLS and no authentication.

Returns
the id of the new stream; the server answers id (its source) or stream_id (its documentation), both are read
Exceptions
SnapcastExceptionMALFORMED when the answer has neither

Referenced by de.yaacc.snapcast.feed.SnapcastStreams.ensure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deleteClient()

SnapcastServerStatus de.yaacc.snapcast.control.SnapcastOperations.deleteClient ( String clientId) throws SnapcastException

Server.DeleteClient ({"id": <client id>}): the server forgets a client it knows.

The answer is the status of the server afterwards (as for Group.SetClients) and becomes the model. A server that answers without one has done it all the same: the model is then read again and the result is null.

Whether the server refuses a client that is connected is not settled by its documentation: the caller decides that from a fresh status (see SnapcastClientRemoval), this method sends what it is told.

Returns
the status after the call, or null when the answer had none
Here is the call graph for this function:

◆ freshStatusOrModel()

SnapcastServerStatus de.yaacc.snapcast.control.SnapcastOperations.freshStatusOrModel ( )

The status as fresh as the rate limit of the model allows: a full Server.GetStatus when the limit grants a read (it becomes the model), otherwise the model as it is.

For a change that is destructive by protocol (Group.SetClients removes every client that is not in the list), so that it is computed from what the server has now and not from a model that a notification has not reached yet. A read that fails also gives the model. Blocks like every call: never on the main thread, never inside a delivery of the listeners.

Returns
the status, or null when there is neither a fresh read nor a model
Here is the call graph for this function:

◆ removeStream()

String de.yaacc.snapcast.control.SnapcastOperations.removeStream ( String streamId) throws SnapcastException

Stream.RemoveStream.

Returns
the id the server answered, or the requested id if the answer has none

Referenced by de.yaacc.snapcast.feed.SnapcastStreams.ensure(), and de.yaacc.snapcast.feed.SnapcastStreams.shutdown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setClientVolume()

SnapcastVolume de.yaacc.snapcast.control.SnapcastOperations.setClientVolume ( String clientId,
SnapcastVolume volume ) throws SnapcastException

Client.SetVolume.

Returns
the volume the server answered, or the requested one if the answer has none

Referenced by de.yaacc.snapcast.ui.SnapcastControls.setClientVolume(), and de.yaacc.snapcast.control.SnapcastOperations.setGroupVolume().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setGroupClients()

SnapcastServerStatus de.yaacc.snapcast.control.SnapcastOperations.setGroupClients ( String groupId,
List< String > clientIds ) throws SnapcastException

Group.SetClients: the group gets exactly these members.

Clients of the group that are not in the list leave it (each gets a group of its own), the others are moved in. So the list must be the full wanted membership; one that exceeds SnapcastLimits#MAX_CLIENTS_PER_GROUP is refused, not cut (a cut list would remove members). An empty list would dissolve the group and is refused too.

Returns
the status the server answered with (it is also the new model)
Exceptions
IllegalArgumentExceptionfor null, an empty list or an empty id
Here is the call graph for this function:

◆ setGroupVolume() [1/3]

Map< String, Integer > de.yaacc.snapcast.control.SnapcastOperations.setGroupVolume ( SnapcastGroup current,
Map< String, Integer > startLevels,
int percent ) throws SnapcastException

Sets the volume of a group (the server has none): the connected members move by the same number of points so that their average becomes percent, see GroupVolume.

A muted member gets its new level and stays muted. A member whose level does not change gets no call. Every member is tried; if a call fails, the first failure is thrown after the others were sent (the members that were set are in the model already).

For a drag, pass the levels from the start of the drag as startLevels and the group as it is now (the model) as current: the targets come from the start levels, so the steps do not add up and a member whose target is back at its start level gets that level again.

Parameters
currentthe group as it is now; its clients are the ones that are set
startLevelsthe levels the targets are calculated from, see GroupVolume#levels
Returns
the new level of every member that was changed, by client id
Here is the call graph for this function:

◆ setGroupVolume() [2/3]

Map< String, Integer > de.yaacc.snapcast.control.SnapcastOperations.setGroupVolume ( SnapcastGroup current,
Map< String, Integer > startLevels,
int percent,
long budgetMillis ) throws SnapcastException

As setGroupVolume(SnapcastGroup, Map, int), with an overall time budget for the whole gesture: once budgetMillis have passed, no further member is called and the call ends with a TIMEOUT (a server that answers each of up to 256 calls just before its 10 s deadline can not keep the caller for ever).

The members that were set stay set.

Here is the call graph for this function:

◆ setGroupVolume() [3/3]

Map< String, Integer > de.yaacc.snapcast.control.SnapcastOperations.setGroupVolume ( SnapcastGroup group,
int percent ) throws SnapcastException

Sets the volume of a group (the server has none) from one snapshot: the start and the current levels are the levels of group.

Fine for a single step; a drag uses setGroupVolume(SnapcastGroup, Map, int).

Referenced by de.yaacc.snapcast.control.SnapcastOperations.setGroupVolume(), and de.yaacc.snapcast.control.SnapcastOperations.setGroupVolume().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following file: