@kefir100/radio-engine v2.3.1
Radio engine for NodeJS
Usage
Simple lightweight package to start your own
liveradio station 📻 Just drop yourmp3files and broadcast them to the world 🌎Heavily inspired by Shoutcast and Icecast.
Setup
Installation
npm i @kefir100/radio-engine --saveServer
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.jsOR
yarn build
node examples/server.js [path/to/your_mp3tracks]
# in this case it would take a little more time, just waitDemo
Fully working demo is available on http://fridgefm.com
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago