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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@fonoster/streams

v0.17.1

Published

Core support for Fonoster Streams

Readme

streams

Streams Version Downloads/week License

This is a NodeJS implementation of the AudioSocket protocol, which is a simple protocol for accessing bidirectional audio streams from Asterisk.

Installation

$ npm install --save @fonoster/streams

Example

While the AudioSocket is a utility for Fonoster Streams, it can be used as a standalone module. To use this library with Asterisk, you must configure your dialplan to use the AudioSocket application. Here is an example of how to use the AudioSocket with Asterisk:

exten = 100,1,Verbose("Call to AudioSocket via Dialplan Application")
 same = n,Answer()
 same = n,AudioSocket(40325ec2-5efd-4bd3-805f-53576e581d13,server.example.com:9092)
 same = n,Hangup()

Or with the Dial application:

exten = 100,1,Verbose("Call to AudioSocket via Dialplan Application")
 same = n,Answer()
 same = n,Dial(SIP/100,30,A(AudioSocket(40325ec2-5efd-4bd3-805f-53576e581d13,server.example.com:9092)))
 same = n,Hangup()

Connecting to the AudioSocket server using ARI with the externalMedia endpoint is also possible. You must ensure you set the transport to TCP the UUID in the data field.

Currently, the payload towards Asterisk is limited to signed linear, 16-bit, 8kHz, mono PCM (little-endian). However, the payload from Asterisk can be changed with the format parameter when using ARI. Please see the AudioSocket Server implementation, for interesting notes about AudioSocket.

Once Asterisk is configured, you can use the AudioSocket class to create a server that listens for connections. Here is an example of how to use the AudioSocket class:

const { AudioSocket } = require("@fonoster/streams");

const audioSocket = new AudioSocket();

audioSocket.onConnection(async (req, res) => {
  console.log("new connection from:", req.ref);

  res.on("data", (data) => {
     // Do something with the audio data
  );

  res.on("end", () => {
     // Do something when the stream ends
  });

  res.on("error", (err) => {
     // Do something when an error occurs
  });

  // Utility for playing audio files
  await res.play("/path/to/audio/file");
});

audioSocket.listen(9092, () => {
  console.log("server listening on port 9092");
});

APIs

AudioSocket

A NodeJS implementation of the AudioSocket protocol. The AudioSocket protocol is a simple protocol for streaming audio from Asterisk to a NodeJS application. The protocol is based on the I/O multiplexing model and uses

Kind: global class
See: AudioStream

new AudioSocket()

Constructs a new AudioSocket instance.

Example

const { AudioSocket } = require("@fonoster/streams");

const audioSocket = new AudioSocket();

audioSocket.onConnection(async (req, res) => {
  console.log("new connection from:", req.ref);

  res.on("data", (data) => {
     // Do something with the audio data
  );

  res.on("end", () => {
     // Do something when the stream ends
  });

  res.on("error", (err) => {
     // Do something when an error occurs
  });

  // Utility for playing audio files
  await res.play("/path/to/audio/file");
});

audioSocket.listen(9092, () => {
  console.log("server listening on port 9092");
});

audioSocket.onConnection(handler)

Sets the handler to be called when a new connection is established.

Kind: instance method of AudioSocket

| Param | Type | Description | | --- | --- | --- | | handler | function | The handler to call when a new connection is established |

Example

audioSocket.onConnection(async (req, res) => {
  console.log("new connection from:", req.ref);

  await res.play("/path/to/audio/file");
});

audioSocket.close()

Closes the server and stops listening for connections.

Kind: instance method of AudioSocket

AudioStream

Object representing a stream of bidirectional audio data and control messages.

Kind: global class

new AudioStream(stream, socket)

Creates a new AudioStream.

| Param | Type | Description | | --- | --- | --- | | stream | Readable | A readable stream | | socket | net.Socket | A TCP socket |

audioStream.write(data)

Writes media data to the stream.

Kind: instance method of AudioStream

| Param | Type | Description | | --- | --- | --- | | data | Buffer | The data to write |

audioStream.hangup()

Sends a hangup message to the stream and closes the connection.

Kind: instance method of AudioStream

audioStream.play(filePath) ⇒ Promise.<void>

Utility for playing audio files.

Kind: instance method of AudioStream

| Param | Type | Description | | --- | --- | --- | | filePath | string | The path to the audio file |

audioStream.onData(callback) ⇒ AudioStream

Adds a listener for the data event.

Kind: instance method of AudioStream
Returns: AudioStream - The AudioStream instance
See: EventType.DATA

| Param | Type | Description | | --- | --- | --- | | callback | function | The callback to be executed |

audioStream.onClose(callback) ⇒ AudioStream

Adds a listener for the end event.

Kind: instance method of AudioStream
Returns: AudioStream - The AudioStream instance
See: EventType.END

| Param | Type | Description | | --- | --- | --- | | callback | function | The callback to be executed |

audioStream.onError(callback) ⇒ AudioStream

Adds a listener for the error event.

Kind: instance method of AudioStream
Returns: AudioStream - The AudioStream instance
See: EventType.ERROR

| Param | Type | Description | | --- | --- | --- | | callback | function | The callback to be executed |