Options
All
  • Public
  • Public/Protected
  • All
Menu

Implements the PulseAudio client.

example
import PulseAudio, { Sink } from '@tmigone/pulseaudio'

(async () => {
// Connect using tcp socket
const client: PulseAudio = new PulseAudio('tcp:192.168.1.10:4317')
await client.connect()

// Set volume of all sinks to 50%
const sinks: Sink[] = await client.getSinkList()
for (const sink of sinks) {
await client.setSinkVolume(sink.index, 50)
}

// Close connection
client.disconnect()
})()

Hierarchy

  • EventEmitter
    • PulseAudio

Index

PulseAudio

  • new PulseAudio(address: string, cookie?: string): PulseAudio
  • Instantiate a PulseAudio client by providing the server address. PulseAudio server defaults to the following:

    • UNIX socket: /run/user/<user_id>/pulse/native
    • TCP port: 4317
    // Using UNIX socket
    const client: PulseAudio = new PulseAudio('unix:/run/user/1001/pulse/native')

    // Using TCP socket
    const client: PulseAudio = new PulseAudio('tcp:localhost:4317')
    category

    PulseAudio

    Parameters

    • address: string

      The address of the PulseAudio server. Can be either the path to a UNIX domain socket or the network address of the server. For UNIX sockets prepend unix: to the path. For TCP sockets the format is tcp:<host>:<port>.

    • Optional cookie: string

      The path to the cookie to use when authenticating with the server. Typically located at ~/.config/pulse/cookie.

    Returns PulseAudio

client

  • Connects the client to the PulseAudio server. Won't retry if the server is not reachable or the connection attempt is refused. Times out after 5 seconds.

    Returns Promise<AuthInfo>

  • disconnect(): void
  • Disconnect the client from the PulseAudio server. Waits for the server to close the connection.

    Returns void

  • setClientName(clientName?: string): Promise<ClientInfo>
  • Specify the client name passed to the server when connecting.

    Parameters

    • clientName: string = 'paclient'

      The client name. Defaults to paclient.

    Returns Promise<ClientInfo>

module

  • getModule(module: number): Promise<Module>
  • Gets details for the module instance identified by the specified numeric index.

    Parameters

    • module: number

      The numerical index of the module instance to get details for.

    Returns Promise<Module>

  • getModuleList(): Promise<Module[]>
  • Gets details for all loaded module instances.

    Returns Promise<Module[]>

  • loadModule(name: string, argument: string): Promise<Module>
  • Load the specified module with the specified arguments into the running sound server. Prints the numeric index of the module just loaded to STDOUT. You can use it to unload the module later.

    example
    const moduleIndex = await client.loadModule('module-loopback', 'source=alsa_output.dac.stereo-fallback.monitor sink=app-output')
    console.log(moduleIndex) // moduleIndex: 27

    Parameters

    • name: string

      The name of the module to load.

    • argument: string

      Space separated list of arguments to pass to the module.

    Returns Promise<Module>

  • unloadModule(module: number): Promise<Module>
  • Unload the module instance identified by the specified numeric index.

    Parameters

    • module: number

      The numeric index of the module to unload.

    Returns Promise<Module>

public

connected: boolean = false
cookie: Buffer = ...
protocol: number = 0

server

  • Gets PulseAudio server information.

    Returns Promise<ServerInfo>

  • Subscribe to PulseAudio server events.

    Returns Promise<SubscribeInfo>

sink

  • getSink(sink: string | number): Promise<Sink>
  • Gets details for the sink instance identified by the specified symbolic name or numeric index.

    Parameters

    • sink: string | number

      The symbolic name or numerical index of the sink instance to get details for.

    Returns Promise<Sink>

  • getSinkList(): Promise<Sink[]>
  • Gets details for all sink instances.

    Returns Promise<Sink[]>

  • setSinkVolume(sink: string | number, volume: number): Promise<VolumeInfo>
  • Sets the volume of the specified sink (identified by its symbolic name or numerical index).

    Parameters

    • sink: string | number

      The symbolic name or numerical index of the sink to set the volume of.

    • volume: number

      The volume to set the source to in percentage (0% - 100%).

    Returns Promise<VolumeInfo>

sinkInput

  • getSinkInput(sinkInput: string | number): Promise<SinkInput>
  • Gets details for the sink input instance identified by the specified symbolic name or numeric index.

    Parameters

    • sinkInput: string | number

      The symbolic name or numerical index of the sink input instance to get details for.

    Returns Promise<SinkInput>

  • getSinkInputList(): Promise<Sink[]>
  • Gets details for all sink input instances.

    Returns Promise<Sink[]>

  • moveSinkInput(sinkInput: number, sink: number): Promise<any>
  • Move the specified playback stream (identified by its numerical index) to the specified sink (identified by its numerical index).

    Parameters

    • sinkInput: number

      The numerical index of the playback stream to move.

    • sink: number

      The numerical index of the sink to move the playback stream to.

    Returns Promise<any>

source

  • getSource(source: string | number): Promise<Source>
  • Gets details for the source instance identified by the specified symbolic name or numeric index.

    Parameters

    • source: string | number

      The symbolic name or numerical index of the source instance to get details for.

    Returns Promise<Source>

  • getSourceList(): Promise<Source[]>
  • Gets details for all source instances.

    Returns Promise<Source[]>

  • setSourceVolume(source: string | number, volume: number): Promise<Source>
  • Sets the volume of the specified source (identified by its symbolic name or numerical index).

    Parameters

    • source: string | number

      The symbolic name or numerical index of the source to set the volume of.

    • volume: number

      The volume to set the source to in percentage (0% - 100%).

    Returns Promise<Source>

sourceOutput

  • getSourceOutput(sourceOutput: string | number): Promise<SourceOutput>
  • Gets details for the source output instance identified by the specified numeric index.

    Parameters

    • sourceOutput: string | number

      The numerical index of the source output instance to get details for.

    Returns Promise<SourceOutput>

  • Gets details for all source output instances.

    Returns Promise<SourceOutput[]>

  • moveSourceOutput(sourceOutput: number, source: number): Promise<SourceOutput>
  • Move the specified recording stream (identified by its numerical index) to the specified source (identified by its numerical index).

    Parameters

    • sourceOutput: number

      The numerical index of the recording stream to move.

    • source: number

      The numerical index of the source to move the recording stream to.

    Returns Promise<SourceOutput>

Generated using TypeDoc