JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 28
  • Score
    100M100P100Q70104F
  • License MIT

internet radio engine made on NodeJS platform

Package Exports

  • @fridgefm/radio-core

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@fridgefm/radio-core) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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 @fridgefm/radio-engine --save

Server

const { Station } = require('@fridgefm/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