A SHOUTcast Server/Library written in JavaScript
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
jscast uses fluent-ffmpeg so ffmpeg needs to be installed on your system.
Install jscast globally:
$ npm i -g jscast
Use the new command to start a Server:
$ jscast-server
choose a different port with -p 8888
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");
});
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
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
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();
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();
TODO...
MIT