This package has been deprecated

Author message:

Depreacted in favour of new package @fridgefm/radio-core

@kefir100/radio-engine
TypeScript icon, indicating that this package has built-in type declarations

2.3.1 • Public • Published

Radio engine for NodeJS

build coverage npm GitHub node

Usage

Simple lightweight package to start your own live radio station 📻 Just drop your mp3 files and broadcast them to the world 🌎Heavily inspired by Shoutcast and Icecast.

Setup

Installation

npm i @kefir100/radio-engine --save

Server

const { Station } = require('@kefir100/radio-engine');
const station = new Station();

station.addFolder('User/Music');

server.get('/stream', (req, res) => {
  station.connectListener(req, res);
});

station.start();

Client

<audio
    controls
    type='audio/mp3'
    src='/stream'
/>

Station methods

Public methods that should be exposed to users

connectListener connects real users to your station
response argument is required

station.connectListener(request, response, callback);

Private methods that should be used only by admins

addFolder adds track within a folder to the playlist

station.addFolder('User/Music');

start starts broadcasting

station.start();

next instantly switches track to the next one

station.next();

getPlaylist just returns you the entire playlist

station.getPlaylist();

shufflePlaylist shuffles playlist once
You may want to pass your own sorting function, defaults to random shuffle

station.shufflePlaylist(sortingFunction);

rearrangePlaylist just returns you the entire playlist

// the example moves the first track to the 5th position in playlist
station.rearrangePlaylist(0, 4);

Station events

nextTrack

event fires when track changes
useful for getting to know when exactly the track changed and what track that is

station.on('nextTrack', (track) => { console.log(track) });

start

event fires on station start

station.on('start', () => { console.log('Station started') });

restart

event fires on station restart (when playlist is drained and new one is created)
it might be a nice time to shuffle your playlist for example

station.on('restart', () => { station.shufflePlaylist() });

error

event fires when there is some error

station.on('error', (e) => { handleError(e) });

or just go to EXAMPLES

yarn build
node examples/server.js

OR

yarn build
node examples/server.js [path/to/your_mp3tracks]
# in this case it would take a little more time, just wait

Demo

Fully working demo is available on http://fridgefm.com

Package Sidebar

Install

npm i @kefir100/radio-engine

Weekly Downloads

1

Version

2.3.1

License

MIT

Unpacked Size

44.4 kB

Total Files

69

Last publish

Collaborators

  • kefir100