-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plain js version? #1
Comments
Hey Tyler, If you install the package from npm, you will receive the compiled JS in the package. It can be used out-of-the-box with plain JavaScript, just install and do In the most basic example, we just create a new server and pipe an mp3 stream to it. If you have an existing express app, using EvenNicercast looks something like this: EvenNicercast = require('even-nicercast');
var app = express(); // your express app
var advertise = "http://your-domain-that-will-be-sent-in-the-playlist.com"
var port = 80; // probably 80 if you are using an existing express app,
// port should match the express app for advertising in the playlist
var server = new EvenNicercast {app, advertise, port};
app.use('/source', function(req, res, next) { // listen for your broadcast source to connect
req.pipe(server, {end: false}); // don't end the server stream when the source dies
// don't forget to unpipe on connection end
});
app.listen() This assumes you're encoding the mp3 stream before sending it to EvenNicercast. EvenNicercast doesn't re-encode the stream, so in theory it could pass through .ogg or other formats, but right now I only send the headers for |
I should mention, express does not do custom HTTP methods, and the common icecast source clients open with If you're using a client that does that, instead of a standard POST (or PUT or PATCH), then you'll have to intercept the server connection to grab the socket before express can process it. Here is such an implementation, though slightly outdated: server.on('connection', function (socket) {
var originalOnDataFunction = socket.ondata;
var newLineOffset;
var receiveBuffer = new Buffer(0);
socket.ondata = function (d, start, end) {
receiveBuffer = Buffer.concat([receiveBuffer, d.slice(start, end)]);
if ((newLineOffset = receiveBuffer.toString('ascii').indexOf('\n')) > -1) {
var firstLineParts = receiveBuffer.slice(0, newLineOffset).toString().split(' ');
firstLineParts[0] = firstLineParts[0].replace(/^SOURCE$/ig, 'PUT');
firstLineParts[2] = firstLineParts[2].replace(/^ICE\//ig, 'HTTP/');
receiveBuffer = Buffer.concat([
new Buffer(
firstLineParts.join(' ') + '\r\n' +
'Content-Length: 9007199254740992\r\n'
),
receiveBuffer.slice(newLineOffset +1)
]);
socket.ondata = originalOnDataFunction;
socket.ondata.apply(this, [receiveBuffer, 0, receiveBuffer.length]);
}
};
} |
Thank you! I'm going to mess around. This looks to be the missing puzzle piece. |
I think this is what I've been looking for.. I'm not a coffee master in the lang only in the brew.
I don't want to install icecast server. I want my broadcast to point to a nodejs express server instead.
Could you give me a 5 minute instructions or example of how to use this?
Sincerely yours,
Tyler
The text was updated successfully, but these errors were encountered: