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

@interactivefitness/paclient

v0.0.14

Published

PulseAudio client written in pure JavaScript for node.js

Downloads

2

Readme

Description

A PulseAudio client written in pure JavaScript for node.js.

Currently most commands are implemented. SHM/MemFD-related commands are not supported.

Table of Contents

Requirements

Installation

npm install paclient

Examples

Subscribe to all server events

const PAClient = require('paclient');

const pa = new PAClient();
pa.on('ready', () => {
  console.log('Ready');
  pa.subscribe('all');
}).on('close', () => {
  console.log('Connection closed');
}).on('new', (type, index) => {
  pa[getFnFromType(type)](index, (err, info) => {
    if (err) {
      console.log(`Could not fetch ${type}, index ${index}: ${err.message}`);
      return;
    }
    var name = info.name || info.description || '<unknown>';
    console.log(`"${name}" (${type}) added`);
  });
}).on('change', (type, index) => {
  pa[getFnFromType(type)](index, (err, info) => {
    if (err) {
      console.log(`Could not fetch ${type}, index ${index}: ${err.message}`);
      return;
    }
    var name = info.name || info.description || '<unknown>';
    console.log(`"${name}" (${type}) changed`);
  });
}).on('remove', (type, index) => {
  console.log(`Removed ${type}, index #${index}`);
});

pa.connect();

function getFnFromType(type) {
  var fn;
  switch (type) {
    case 'sink':
    case 'card':
    case 'source': fn = type; break;
    case 'sinkInput':
    case 'sourceOutput':
    case 'client':
    case 'module': fn = `${type}ByIndex`; break;
    default:
      throw new Error('Unexpected type: ' + type);
  }
  return 'get' + fn[0].toUpperCase() + fn.slice(1);
}

API

Client

Client events

  • ready() - A successful, authenticated connection has been made.

  • close() - The connection to the server has been closed.

  • new(< string >type, < integer >index) - A new entity has been added.

  • change(< string >type, < integer >index) - An existing entity has changed.

  • remove(< string >type, < integer >index) - An existing entity has been removed.

Client methods

  • (constructor)() - Creates and returns a new Client instance.

  • connect([< object >config]) - (void) - Attempts a connection to a server using the information given in config. If no path or host are supplied then connection details are autodetected using the same algorithm as the official PulseAudio client library. Valid config options are:

    • path - string - Path to a UNIX socket of the server. Default: Autodetected

    • host - string - Hostname or IP address of the server. Default: Autodetected

    • port - integer - Port number of the server. Default: 4713

    • serverString - string - Server string in PULSE_SERVER syntax. Default: Autodetected

    • cookie - mixed - An explicit cookie value to use when authenticating with the server. This can either be a Buffer or a hex string of the appropriate length. Default: Autodetected

    • properties - object - A set of properties to associate with the client on the server. These can be seen by other clients. Default: { application: { name: 'paclient.js' } }

  • end() - (void) - If connected, this will close the connection to the server.

  • getModules(< function >callback) - (void) - Retrieves a list of loaded modules. callback has 2 parameters: < Error >err, < array >modules.

  • getClients(< function >callback) - (void) - Retrieves a list of connected clients. callback has 2 parameters: < Error >err, < array >clients.

  • getSinks(< function >callback) - (void) - Retrieves a list of available sinks (outputs). callback has 2 parameters: < Error >err, < array >sinks.

  • getSources(< function >callback) - (void) - Retrieves a list of available sources (inputs). callback has 2 parameters: < Error >err, < array >sources.

  • getSinkInputs(< function >callback) - (void) - Retrieves a list of available sink inputs (streams connected to outputs). callback has 2 parameters: < Error >err, < array >sinkInputs.

  • getSourceOutputs(< function >callback) - (void) - Retrieves a list of available source outputs (streams connected to inputs). callback has 2 parameters: < Error >err, < array >sourceOutputs.

  • getCards(< function >callback) - (void) - Retrieves a list of available cards (hardware devices that usually combine a single source (for recording) and a single sink (for playback)). callback has 2 parameters: < Error >err, < array >cards.

  • getServerInfo(< function >callback) - (void) - Retrieves information about the server. callback has 2 parameters: < Error >err, < object >info.

  • getModuleByIndex(< integer >index, < function >callback) - (void) - Retrieves a module by its index. callback has 2 parameters: < Error >err, < object >module.

  • getClientByIndex(< integer >index, < function >callback) - (void) - Retrieves a client by its index. callback has 2 parameters: < Error >err, < object >client.

  • getSink(< mixed >criteria, < function >callback) - (void) - Retrieves a sink by either its index (integer) or its name (string). callback has 2 parameters: < Error >err, < object >sink.

  • getSource(< mixed >criteria, < function >callback) - (void) - Retrieves a source by either its index (integer) or its name (string). callback has 2 parameters: < Error >err, < object >source.

  • getSinkInputByIndex(< integer >index, < function >callback) - (void) - Retrieves a sink input by its index. callback has 2 parameters: < Error >err, < object >sinkInput.

  • getSourceOutputByIndex(< integer >index, < function >callback) - (void) - Retrieves a source output by its index. callback has 2 parameters: < Error >err, < object >sourceOutput.

  • getCard(< mixed >criteria, < function >callback) - (void) - Retrieves a card by either its index (integer) or its name (string). callback has 2 parameters: < Error >err, < object >card.

  • getSinkIndexByName(< string >name, < function >callback) - (void) - Retrieves the index for a sink given its name. callback has 2 parameters: < Error >err, < integer >index.

  • getSourceIndexByName(< string >name, < function >callback) - (void) - Retrieves the index for a source given its name. callback has 2 parameters: < Error >err, < integer >index.

  • setSinkVolumes(< mixed >criteria, < array >volumes, < function >callback) - (void) - Sets the volumes for each of a sink's channels. criteria can be an index (integer) or a name (string). callback has 1 parameter: < Error >err.

  • setSourceVolumes(< mixed >criteria, < array >volumes, < function >callback) - (void) - Sets the volumes for each of a source's channels. criteria can be an index (integer) or a name (string). callback has 1 parameter: < Error >err.

  • setSinkInputVolumesByIndex(< integer >index, < array >volumes, < function >callback) - (void) - Sets the volumes for each of a sink input's channels. callback has 1 parameter: < Error >err.

  • setSourceOutputVolumesByIndex(< integer >index, < array >volumes, < function >callback) - (void) - Sets the volumes for each of a source output's channels. callback has 1 parameter: < Error >err.

  • setSinkMute(< mixed >criteria, < boolean >muted, < function >callback) - (void) - Sets the muted status for a sink by either its index (integer) or its name (string). callback has 1 parameter: < Error >err.

  • setSourceMute(< mixed >criteria, < boolean >muted, < function >callback) - (void) - Sets the muted status for a source by either its index (integer) or its name (string). callback has 1 parameter: < Error >err.

  • setSinkInputMuteByIndex(< integer >index, < boolean >muted, < function >callback) - (void) - Sets the muted status for a sink input. callback has 1 parameter: < Error >err.

  • setSourceOutputMuteByIndex(< integer >index, < boolean >muted, < function >callback) - (void) - Sets the muted status for a source output. callback has 1 parameter: < Error >err.

  • setSinkSuspend(< mixed >criteria, < boolean >suspended, < function >callback) - (void) - Sets the suspended status for a sink by either its index (integer) or its name (string). callback has 1 parameter: < Error >err.

  • setSourceSuspend(< mixed >criteria, < boolean >suspended, < function >callback) - (void) - Sets the suspended status for a source by either its index (integer) or its name (string). callback has 1 parameter: < Error >err.

  • setDefaultSinkByName(< string >name, < function >callback) - (void) - Sets the default sink. callback has 1 parameter: < Error >err.

  • setDefaultSourceByName(< string >name, < function >callback) - (void) - Sets the default source. callback has 1 parameter: < Error >err.

  • killClientByIndex(< integer >index, < function >callback) - (void) - Terminates the connection of the specified client. callback has 1 parameter: < Error >err.

  • killSinkInputByIndex(< integer >index, < function >callback) - (void) - Terminates a sink input. callback has 1 parameter: < Error >err.

  • killSourceOutputByIndex(< integer >index, < function >callback) - (void) - Terminates a source output. callback has 1 parameter: < Error >err.

  • loadModule(< string >moduleName, < string >argument, < function >callback) - (void) - Load a module. callback has 1 parameter: < Error >err.

  • unloadModuleByIndex(< integer >moduleIndex, < function >callback) - (void) - Unload a module. callback has 1 parameter: < Error >err.

  • moveSinkInput(< integer >index, < mixed >destSink, < function >callback) - (void) - Moves a sink input to a different sink identified by either its index (integer) or its name (string). callback has 1 parameter: < Error >err.

  • moveSourceOutput(< integer >index, < mixed >destSink, < function >callback) - (void) - Moves a source output to a different source identified by either its index (integer) or its name (string). callback has 1 parameter: < Error >err.

  • setSinkPort(< mixed >criteria, < string >portName, < function >callback) - (void) - Sets the port for a sink identified by either its index (integer) or its name (string). callback has 1 parameter: < Error >err.

  • setSourcePort(< mixed >criteria, < string >portName, < function >callback) - (void) - Sets the port for a source identified by either its index (integer) or its name (string). callback has 1 parameter: < Error >err.

  • setCardProfile(< mixed >criteria, < string >profileName, < function >callback) - (void) - Sets the profile for a card identified by either its index (integer) or its name (string). callback has 1 parameter: < Error >err.

  • updateClientProperties(< object >properties, < string >mode, < function >callback) - (void) - Updates this client's server-side properties. The update behavior is governed by mode which can be one of: 'set' (any/all old properties are removed), 'update' (only add properties that do not already exist), or 'replace' (only overwrite property values for existing properties). callback has 1 parameter: < Error >err.

  • removeClientProperties(< array >propertyNames, < function >callback) - (void) - Removes specified properties from this client's server-side properties. callback has 1 parameter: < Error >err.

  • subscribe(< mixed >events, < function >callback) - (void) - Sets the event subscription for events emitted by the server. events can either be a string or array of strings containing one or more of: 'none', 'all', 'sink', 'source', 'sinkInput', 'sourceOutput', 'module', 'client', 'sampleCache', 'global', or 'card'. callback has 1 parameter: < Error >err.