2.3.1 • Published 4 years ago

@kefir100/radio-engine v2.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

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

2.3.1

4 years ago

2.3.0

4 years ago

2.2.0

4 years ago

2.1.0

4 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago