|
YAACC - UPNP Client and Server
|
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...

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). | |
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.
| de.yaacc.snapcast.control.SnapcastOperations.SnapcastOperations | ( | SnapcastCaller | caller, |
| SnapcastModelUpdater | updater ) |
| updater | the model to keep up to date with the answers and our own changes; null for none |
| 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.
id (its source) or stream_id (its documentation), both are read | SnapcastException | MALFORMED when the answer has neither |
Referenced by de.yaacc.snapcast.feed.SnapcastStreams.ensure().


| 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.

| 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.

| String de.yaacc.snapcast.control.SnapcastOperations.removeStream | ( | String | streamId | ) | throws SnapcastException |
Stream.RemoveStream.
Referenced by de.yaacc.snapcast.feed.SnapcastStreams.ensure(), and de.yaacc.snapcast.feed.SnapcastStreams.shutdown().


| SnapcastVolume de.yaacc.snapcast.control.SnapcastOperations.setClientVolume | ( | String | clientId, |
| SnapcastVolume | volume ) throws SnapcastException |
Client.SetVolume.
Referenced by de.yaacc.snapcast.ui.SnapcastControls.setClientVolume(), and de.yaacc.snapcast.control.SnapcastOperations.setGroupVolume().


| 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.
| IllegalArgumentException | for null, an empty list or an empty id |

| 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.
| current | the group as it is now; its clients are the ones that are set |
| startLevels | the levels the targets are calculated from, see GroupVolume#levels |

| 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.

| 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().

