Skip to content
/ jsCast Public

📻 An Audio Streaming Application written in JavaScript

License

Notifications You must be signed in to change notification settings

ardean/jsCast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Aug 28, 2016
f3ff78d Â· Aug 28, 2016

History

5 Commits
Aug 27, 2016
Aug 28, 2016
Aug 28, 2016
Aug 28, 2016
Aug 28, 2016
Aug 27, 2016
Aug 28, 2016
Aug 28, 2016

Repository files navigation

jscast

NPM Version

A SHOUTcast Server/Library written in JavaScript

Installation

As dependency:

$ npm install jscast

For developing forks:

$ git clone https://github.com/BigTeri/jscast
$ cd jscast
$ npm i
$ npm start

For minimalists:

$ npm i -g jscast
$ jscast-server

Prerequisites

jscast uses fluent-ffmpeg so ffmpeg needs to be installed on your system.

Quick Start

Using cli

Install jscast globally:

$ npm i -g jscast

Use the new command to start a Server:

$ jscast-server

choose a different port with -p 8888

Using script

var Server = require("jscast").Server;

new Server().on("play", function (item, metadata) {
  console.log("playing " + metadata.options.StreamTitle);
}).start(8000, function (server) {
  console.log("jscast server is running on http://localhost:" + server.port);
  console.log("go to http://localhost:" + server.port + "/manage to manage your playlists");
});

Item Types

Built-in item types:

  • File gets audio files from the filesystem using the filename option
  • YouTube fetches the audio data and info from YouTube using an url option
  • Use Stream to hand over a Readable Stream object with the stream option

more item types

Storage Types

Built-in storage types:

  • JSON creates a folder with a json file per playlist, filename is the playlist id
  • Memory stores playlists in memory, so changes will be lost on shutdown

If thats not enough, you can create your own one

Examples

Custom Items

jscast has playlists with typed items. You can easily add your own item type:

var fs = require("fs");
var jscast = require("jscast");
var Item = jscast.Item;
var Server = jscast.Server;

function MyItemType() {
  this.streamNeedsPostProcessing = true; // indicates if stream should be post processed to mp3
}

MyItemType.prototype.getStream = function (item, done) {
  // get stream code...
  console.log(item.type); // MyItem
  done && done(err, stream);
};

MyItemType.prototype.getMetadata = function (item, done) {
  // get metadata code...
  console.log(item.options.myProp); // myValue
  done && done(err, {
    StreamTitle: "my title"
  });
};

Item.registerType("MyItem", new MyItemType());

new Server({
  storageType: "Memory",
  playlists: [{
    type: "MyItem",
    options: {
      myProp: "myValue"
    }
  }, {
    type: "YouTube",
    options: {
      url: "https://www.youtube.com/watch?v=hhHXAMpnUPM"
    }
  }, {
    type: "Stream",
    options: {
      title: "A cool audio stream!",
      stream: fs.creadReadStream("./sound.mp3")
    }
  }, {
    type: "File",
    options: {
      title: "NICE TRACK!",
      filename: "./myTrack.mp3"
    }
  }]
}).start();

Custom Storages

You can use the built-in storage types or create your own one:

var fs = require("fs");
var jscast = require("jscast");
var Storage = jscast.Storage;
var Server = jscast.Server;

function MyStorageType() {
  this.isFillable = true; // indicates that this type can be pre filled on init
}

MyStorageType.prototype.activate = function (options, done) {
  // initialize code...
  done && done(err);
};

MyStorageType.prototype.fill = function (playlists, done) {
  // fill storage from playlists option in Server and Station class
  done && done(err);
};

MyStorageType.prototype.findAll = function (done) {
  // findAll code...
  done && done(err, playlists);
};

MyStorageType.prototype.insert = function (playlist, done) {
  // insert code...
  done && done(err);
};

MyStorageType.prototype.update = function (playlist, done) {
  // update code...
  done && done(err);
};

MyStorageType.prototype.remove = function (playlistId, done) {
  // remove code...
  done && done(err);
};

Storage.registerType("MyStorage", new MyStorageType());

new Server({
  storageType: "MyStorage"
}).start();

API

TODO...

License

MIT