libshout-js
Native Node.js Libshout bindings for libshout 2.4.1 (latest).
Libshout is a C library for streaming audio to icecast or shoutcast-compatible servers. It supports four audio formats and four protocols. It handles the networking and communication to the server, allowing users to focus on programmatic control.
More information: http://icecast.org
Usage
To use libshout-js, you must first install the libshout library. Consult your OS documentation on how to install libshout, for example:
yum install libshout
apt-get install libshout
brew install libshout
Install nodeshout with yarn or npm:
yarn install libshout-js
Use as follows:
// Import const Libshout = // Create the instance. Specify path to the .so/.dll/.dylib file. // If no path is set, it will attempt to load the standard dll locations. const ls = 'path/to/libshout.so' // Configure the connection const ls = '/usr/local/lib/libls' ls ls ls ls ls // Set stream metadata ls // Some constants are defined for you. ls // ls.setAudioInfo('bitrate', '192') // ls.setAudioInfo('samplerate', '44100') // ls.setAudioInfo('channels', '2') ls
Open the connection.
try ls catch err console
If connection is successful, .open()
will return string SHOUT_ERR_SUCCESS
, otherwise it will throw an error. After successful connection, you can pipe audio data through the provided writeStream
stream, or manually send data.
const fileStream = 'song.mp3' fileStream lswriteStream // or, ls
If sending data manually, there are two ways to synchronize it.
.sync()
will block the thread until ready.
.getDelay()
will return the time in ms you should wait before sending the next chunk.
Metadata
Icecast only supports track metadata for MP3 streams. Vorbis streams are expected to embed metadata as vorbis comments in the audio stream.
// Create a metadata instanceconst metadata = Libshout // Set the metadata within the object. Supported values are defined in constants.metadata // Then, you must apply the metadata to the server connection object.ls;
More information
The C code is heavily documented in the comments for constants.js
and bindings.js
. Look there for more Libshout specific information.