A simple, yet flexible, Node client library for MPD, the hackable headless audio playback server. As a bonus, it runs the same if you use it server-side or on the browser!
npm install komponist
Of course, before you go ahead and write any code - make sure you install MPD and start it up wherever you want to play your music from. You should probably get MPC (the simple CLI client) too.
With a small number of exceptions, komponist exposes all of the available commands as callback-style methods. For a full list check out the docs.
var komponist =var client = komponist;
If you prefer to just fire and forget, you can omit the callbacks.
// You can always omit the port/host if you're running// MPD locally and with the default settings.komponist;
There's also a general purpose
var client = komponist;
The client returned by
komponist.createConnection is just an extended TCP stream, so if you
like you can just pipe data around the Node way:
var fs =client = komponist// Pipe a list of commands to MPD from// a file, piping the raw response out to// stdout! (For kicks)fs
Watching for Changes
If you're building an interface-driven client for MPD, you're going to want to be able to listen for changes as they happen. This is all taken care of for you: just listen for the "changed" event for MPD updates.
var komponist =komponist;
According to the MPD protocol documentation, you can track changes to the following systems this way:
update: a database update has started or finished.
database: the song database has been modified after
stored_playlist: a stored playlist has been modified.
playlist: the current playlist has been modified.
player: the player has been started, stopped or seeked.
mixer: the volume has been changed.
output: an audio output has been enabled or disabled.
options: options like repeat, random, crossfade, replay gain.
sticker: the sticker database has been modified.
subscription: a client has subscribed or unsubscribed to a channel.
MPD has simple publish/subscribe support for communicating across multiple
clients. Using the
subscribe methods, you can send messages
to other subscribers across the network, e.g. for simple service discovery.
komponist;komponist;// Output:// Got message "message #1" on channel "hello"// Got message "message #2" on channel "world"
MPD stickers are a way for you to store arbitrary data in the MPD database,
associated with particular objects. Note that to enable stickers,
sticker_file ~/.mpd/mpd.stickers to your
If you're looking to use the command in the same style as above, it's still
Using Komponist in the Browser
// On the server:var http =komponist =var server = http;komponist;// And on the browser:var komponist = ;komponist;
There's a full example available in the Github repository.
The following methods are reserved for TCP sockets, and as such have been aliased:
closewill close the connection without issuing a command to MPD.
There's no support for
command_list_* commands right now.
You can still access them as normal through the
command method. If you come
across any other bugs or inconsistencies, you're more than welcome create an
issue or a pull request.