-
Notifications
You must be signed in to change notification settings - Fork 315
WebSockets API Reference
The most used API transport in Volumio2 is its Websockets API as it allows almost real time communication with multiple clients. Volumio's WebUI gets and sends data (almost) exclusively via WS. Volumio's WS layer is powered by Socket.io.
Websocket communication in Volumio is identifiable in the most basic server/client architecture. The Server is Volumio itself (aka the host where Volumio is running), the client can be one or more WebUIs or other consumers (Apps and so on). In some cases, Volumio hosts can also act as client, to communicate with other hosts on the same network.
Socket.io allows to invoke events triggered by other events, emit and receive communications (on its most basic implementation). As an example, defining which event should be invoked on a client connection looks like:
self.libSocketIO.on('connection', function (connWebSocket) {
// use connWebSocket here
});
This way, we can define what event should be triggered when a particular message is received:
connWebSocket.on('bringmepizza', function () {
givehimpizza();
});
Play: play Pause: pause Stop: stop Previous: previous Next: next Seek seek N (N is the time in seconds that the playback will keep)
GetState
Reply:
{"status":"play",
"position":"0",
"title":"Macaco",
"artist":Paolo Conte,
"album":Paolo Conte,
"albumart":http://img2-ak.lst.fm/i/u/300x300/1b82dd5e54554209bf2326ffb76f6814.png,
"seek":25390,
"duration":146,
"samplerate":44100,
"bitdepth":16,
"channels":2,
"volume":100,
"mute":false,
"service":mpd}
Where
- status is the status of the player
- position is the position in the play queue of current playing track (if any)
- title is the item's title
- artist is the item's artist
- album is the item's album
- albumart the URL of AlbumArt (via last.fm APIs)
- seek is the item's current elapsed time
- duration is the item's duration, if any
- samplerate current samplerate
- bitdepth bitdepth
- channels mono or stereo
- volume current Volume
- mute if true, Volumio is muted
- service current playback service (mpd, spop...)
volume VolumeInteger
Where VolumeInteger
is a numeric (0-100) volume level
To mute/unmute
volume mute
volume unmute
When Volume is already muted, sending another "mute" emit will result in Volume being unmuted
browseLibrary objBrowseParameters
Where objBrowseParameters
are the parameters we want to dig into. This returns the desired level in the music library along with navigation and pagination informations.
{
navigation: {
prev: {
uri: ''
},
list: [
{service: 'mpd', type: 'song', title: 'track a', artist: 'artist a', album: 'album', icon: 'music' uri: 'uri'},
{type: 'folder', title: 'folder a', icon: 'folder-open-o' uri: 'uri'},
{type: 'folder', title: 'folder b', image: '//ip/image' uri: 'uri2'},
{type: 'playlist', title: 'playlist', icon: 'bars' uri: 'uri4'}
]
}
}
The browsable items can be;
- Track
- Folder (can also be a category)
- Playlist
Their parameters are:
- Type: track, folder, category
- Title: If this is a song: title, if folder or category is their name.
- Artist and Album: used only if the type is song
- Icon or image: Select the icon to display (naming of Font-Awesome ) , or image (URL served by Volumio Backend or external service)
- Uri: Uri
getBrowseFilters
This returns available filters (browse by)
{name:'Genres by Name', index: 'index:Genres by Name'},
{name:'Artists by Name', index: 'index:Artists by Name'},
{name:'Albums by Name', index: 'index:Albums by Name'},
{name:'Albums by Artist', index: 'index:Albums by Artist'},
{name:'Tracks by Name', index: 'index:Tracks by Name'}
getBrowseSources
This returns a list of available Music Sources
{name:'USB', uri: 'usb'},
{name:'NAS', uri: 'nas'},
{name:'Web Radio', uri: 'web-radio'},
{name:'Spotify', uri: 'spotify'}
GetQueue
The queue is a json object:
[ { uri: 'NAS/Flac/Paolo Conte - 1984 - Paolo Conte [1995 Reissue]/10 - Macaco.flac',
service: 'mpd',
name: 'Macaco',
artist: 'Paolo Conte',
album: 'Paolo Conte',
type: 'track',
tracknumber: '0',
albumart: 'http://img2-ak.lst.fm/i/u/300x300/1b82dd5e54554209bf2326ffb76f6814.png' },
{ uri: 'NAS/Flac/Paolo Conte - 1984 - Paolo Conte [1995 Reissue]/01 - Sparring Partner.flac',
service: 'mpd',
name: 'Sparring partner',
artist: 'Paolo Conte',
album: 'Paolo Conte',
type: 'track',
tracknumber: '1',
albumart: 'http://img2-ak.lst.fm/i/u/300x300/1b82dd5e54554209bf2326ffb76f6814.png' }]
removeFromQueue N
where N
is the track number in the queue, 0 for the first, 9 for the tenth and so on
addToQueue {'uri:uri'}
where uri
is the uri of the item we want to add
createPlaylist
deletePlaylist
addToPlaylist
removeFromPlaylist
playPlaylist
enqueue
This method creates a new playlist
Input:
{
"name":"myplaylist"
}
Output:
{
"success":true|false
"reason":"failure details"
}
The reason field is set only if success is false
This method deletes a playlist
Input:
{
"name":"myplaylist"
}
Output:
{
"success":true|false
"reason":"failure details"
}
The reason field is set only if success is false
This method adds a song to an existing playlist
Input:
{
"name":"my playlist",
"uri":"USB/..."
}
Output:
{
"success":true|false
"reason":"failure details"
}
The reason field is set only if success is false
This method removes all occurrences of a song from an existing playlist
Input:
{
"name":"my playlist",
"uri":"USB/..."
}
Output:
{
"success":true|false
"reason":"failure details"
}
The reason field is set only if success is false
This method clears the queue, adds the playlist and play
Input:
{
"name":"my playlist"
}
Output:
{
"success":true|false
"reason":"failure details"
}
The reason field is set only if success is false
This method enqueue all songs of a playlist
Input:
{
"name":"my playlist"
}
Output:
{
"success":true|false
"reason":"failure details"
}
The reason field is set only if success is false
Each method of a plugin can be execute through a websocket call. As of now there's no ACL or any security feature but thi s will change in the future. To execute a method the following socket.io command shall be issued:
callMethod
The payload shall be a json with the following structure:
{
"endpoint":"category/name",
"method":"methodName",
"data": {}
}
where:
- endpoint is a string used to target the plugin. Its structure is a linux path like string containing the plugin category, a slash and the plugin name. An example: endpoint:'music_service/spop'.
- method is a string containing the name of the method to be executed.
- data is a complex value (can be a string or a Json) and is passed as is to the method.
IMPORTANT: There should be no "-" in this call, due to FE parsing method (it converts / to -). So plugins and functions should not contain "-".
Once the method returns, the result is pushed back to the client with the event 'pushMethod'.