npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

working-mpd-client

v1.0.2

Published

An MPD client

Downloads

10

Readme

WorkingMpdClient

An MPD client

yarn add working-mpd-client

Features

  • working-mpd-client supports the command sending
  • working-mpd-client allows subscribing on the server events (i.e. status updates)
  • working-mpd-client attempts to reconnect if the connection has been interrupted

Example

const mpdClient = new MpdClient({
  connectOptions: {
    host: 'localhost',
    port: 6600
  },
  reconnectOptions: {
    isUse: true,
    reconnectDelay: 2000
  }
}).on('error', console.error)
  .on('changed', (name) => {
    if (name === 'playlist') printPlaylist()
  })
  .on('ready', printPlaylist)
  .init()

function printPlaylist() {
  mpdClient.sendCommand('playlist', (err, result) => {
    if (err) {
      console.error(err)
    } else {
      console.log('\nnew playlist:\n' + result)
    }
  })
}

Information events

  • warn - a channel to notify about maintainable problems. Example: a connection has been interrupted but an attempt to reconnect will be performed. Another example: a server responded with an error to a command that did not register a callback.
  • error - a channel to notify about critical problems. Example: a connection has been interrupted and a reconnect attempt won't be performed.

Connection events

  • ready - a connection has been established
  • disconnected - a connection has been interrupted due to a problem or as the result of a destroy method call
  • reconnecting - an attempt to recconect is in progress
  • reconnected - an attempt to reconnect succeed
  • destroyed - a client has been destroyed

Server events

  • changed - a server reported a change

Known changes

  • options - an option has been changed (the repeat option or the random option for example)
  • output - an audio channel has been changed
  • mixer - the volume level has been changed
  • player - the playback has been paused, resumed, or stoped
  • playlist - the playlist has been changed
  • update - a database update has been started or completed
  • database - the track database has been updated

Methods

  • init - establish a connection; ready event follows a method call
  • destroy - closes a connection and rejects all the callbacks left in the callbacks queue; disconnected and destroyed events follow a method call
  • sendCommand - sends a command to a server and calls a callback when the server responds to the command
  • sendCommandList - sends a list of commands to a server and calls a callback when the server responds to all the commands

Ways to send a command

mpdClient
	.sendCommand('status')
	.sendCommand('status', someHandler)
	.sendCommand({
		cmd: 'add',
		args: 'somePath'
	})
	.sendCommand({
		cmd: 'add',
		args: ['somePath', 'anotherSomePath']
	}, someHandler)
	.sendCommandList([{
		cmd: 'add',
		args: 'somePath'
	}, 'play'])

MPD documention

http://www.musicpd.org/doc/protocol/