Comparing version 0.0.1 to 0.0.2
130
index.js
@@ -5,2 +5,4 @@ var express = require('express'); | ||
var lame = require('lame'); | ||
var Throttle = require('throttle'); | ||
var ip = require('ip'); | ||
@@ -11,81 +13,89 @@ var SAMPLE_SIZE = 16 // 16-bit samples, Little-Endian, Signed | ||
// If we're getting raw PCM data as expected, calculate the number of bytes | ||
// that need to be read for `1 Second` of audio data. | ||
var BLOCK_ALIGN = SAMPLE_SIZE / 8 * CHANNELS // Number of 'Bytes per Sample' | ||
, BYTES_PER_SECOND = SAMPLE_RATE * BLOCK_ALIGN; | ||
var Server = function(inStream, opts) { | ||
var app = express(); | ||
app.disable('x-powered-by'); | ||
var app = express(); | ||
var serverPort = false; | ||
app.disable('x-powered-by'); | ||
// stream playlist (points to other endpoint) | ||
app.get('/listen.m3u', function(req, res) { | ||
opts.name = opts.name || 'Nicercast'; | ||
var ip = req.headers['x-forwarded-for'] || | ||
req.connection.remoteAddress || | ||
req.socket.remoteAddress || | ||
req.connection.socket.remoteAddress; | ||
var throttleStream = new Throttle(BYTES_PER_SECOND); | ||
inStream.pipe(throttleStream); | ||
res.status(200); | ||
res.set('Content-Type', 'audio/x-mpegurl'); | ||
res.send('http://' + ip + '/stream'); | ||
}); | ||
// stream playlist (points to other endpoint) | ||
app.get('/listen.m3u', function(req, res) { | ||
app.get('/listen', function(req, res, next) { | ||
var addr = ip.address(); | ||
var acceptsMetadata = req.headers['icy-metadata'] == 1; | ||
var parsed = require('url').parse(req.url, true); | ||
res.status(200); | ||
res.set('Content-Type', 'audio/x-mpegurl'); | ||
res.send('http://' + addr + ':' + serverPort + '/listen'); | ||
}); | ||
// generate response header | ||
var headers = { | ||
"Content-Type": 'audio/mpeg', | ||
"Connection" : 'close' | ||
}; | ||
if (acceptsMetadata) { | ||
headers['icy-name'] = 'Best'; | ||
headers['icy-metaint'] = 8192; | ||
} | ||
res.writeHead(200, headers); | ||
app.get('/listen', function(req, res, next) { | ||
var acceptsMetadata = req.headers['icy-metadata'] == 1; | ||
var parsed = require('url').parse(req.url, true); | ||
// setup metadata transport | ||
if (acceptsMetadata) { | ||
res = new icecast.IcecastWriteStack(res, 8192); | ||
res.queueMetadata('the best track'); | ||
} | ||
// generate response header | ||
var headers = { | ||
"Content-Type": 'audio/mpeg', | ||
"Connection" : 'close' | ||
}; | ||
if (acceptsMetadata) { | ||
headers['icy-metaint'] = 8192; | ||
} | ||
res.writeHead(200, headers); | ||
// setup encodervar lame = require('lame'); | ||
// setup metadata transport | ||
if (acceptsMetadata) { | ||
res = new icecast.IcecastWriteStack(res, 8192); | ||
res.queueMetadata(opts.name); | ||
} | ||
// create the Encoder instance | ||
var encoder = new lame.Encoder({ | ||
channels: 2, // 2 channels (left and right) | ||
bitDepth: 16, // 16-bit samples | ||
sampleRate: 44100 // 44,100 Hz sample rate | ||
}); | ||
// setup encodervar lame = require('lame'); | ||
encoder.on("data", function(chunk) { | ||
res.write(chunk); | ||
}); | ||
// create the Encoder instance | ||
var encoder = new lame.Encoder({ | ||
channels: 2, // 2 channels (left and right) | ||
bitDepth: 16, // 16-bit samples | ||
sampleRate: 44100 // 44,100 Hz sample rate | ||
}); | ||
/* | ||
// burst on connect data | ||
for (var i = 0, l = exports.bocData.length; i < l; i++) { | ||
encoder.stdin.write(exports.bocData[i]); | ||
} | ||
*/ | ||
encoder.on("data", function(chunk) { | ||
res.write(chunk); | ||
}); | ||
var callback = function(chunk) { | ||
encoder.write(chunk); | ||
} | ||
/* | ||
// burst on connect data | ||
for (var i = 0, l = exports.bocData.length; i < l; i++) { | ||
encoder.stdin.write(exports.bocData[i]); | ||
} | ||
*/ | ||
inStream.on("data", callback); | ||
req.connection.on("close", function() { | ||
var callback = function(chunk) { | ||
encoder.write(chunk); | ||
} | ||
// This occurs when the HTTP client closes the connection. | ||
encoder.end(); | ||
inStream.removeListener("data", callback); | ||
}); | ||
}); | ||
throttleStream.on("data", callback); | ||
req.connection.on("close", function() { | ||
// server methods | ||
Server.prototype.start = function(port) { | ||
app.listen(port || 8001); | ||
} | ||
// This occurs when the HTTP client closes the connection. | ||
encoder.end(); | ||
throttleStream.removeListener("data", callback); | ||
}); | ||
}); | ||
// server methods | ||
Server.prototype.start = function(port) { | ||
serverPort = port || 8001; | ||
app.listen(serverPort); | ||
} | ||
} | ||
module.exports = Server; |
{ | ||
"name": "nicercast", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "simple icecast compliant streaming server", | ||
@@ -29,4 +29,6 @@ "main": "index.js", | ||
"icecast-stack": "~0.3.0", | ||
"lame": "~1.0.3" | ||
"lame": "~1.0.3", | ||
"throttle": "~1.0.3", | ||
"ip": "~0.3.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5504
6
90
5
+ Addedip@~0.3.0
+ Addedthrottle@~1.0.3
+ Addeddebug@2.6.9(transitive)
+ Addedip@0.3.3(transitive)
+ Addedms@2.0.0(transitive)
+ Addedstream-parser@0.3.1(transitive)
+ Addedthrottle@1.0.3(transitive)