Permalink
Browse files

Removed ezstream and icecast references, req q is also cleaned.

  • Loading branch information...
1 parent 6acb9f3 commit f33d8f65b352a2c1d2d2fb2b38bcdae484736149 Balaji committed Oct 18, 2012
Showing with 137 additions and 155 deletions.
  1. +6 −7 example/package.json
  2. +1 −14 example/public/main.js
  3. +9 −13 example/server.js
  4. +12 −18 lib/NodeIcecast.js
  5. +16 −4 lib/ReqQueue.js
  6. +88 −92 lib/js-cast.js
  7. +5 −7 package.json
View
@@ -1,24 +1,23 @@
{
"name": "js-cast-example",
- "description": "Voice Streaming from client Browser using icecast server",
- "version": "0.0.4",
+ "description": "js-cast simple example",
+ "private": true,
+ "version": "0.0.5",
"author": {
"name": "D Balaji",
"email": "balaji@ariemtech.com"
},
"dependencies": {
- "js-cast": "0.0.5",
+ "js-cast": "0.0.x",
"ejs":"0.8.3",
"express":"3.0.0rc4"
},
"keywords": [
- "icecast",
"voice",
- "broadcast",
+ "record",
"stream",
"wami",
- "html5",
- "ezstream"
+ "html5"
],
"repository": {
"type": "git",
View
@@ -1,8 +1,6 @@
$(document).ready(function(){
- var using_node_icecast= true;
-
function loadChannelList(){
$.ajax({
url: '/channels',
@@ -22,12 +20,6 @@ $(document).ready(function(){
var url= $(this).attr("href");
$("#audio_player").attr("src", url);
});
- if (!using_node_icecast){
- if (data.length >0){ //play the first channel available
- console.warn("About to play");
- $("#audio_player").attr("src", data[0].url);
- }
- }
}
});
}
@@ -116,19 +108,14 @@ $(document).ready(function(){
});
JSCast.on("opened", function(stream_url){
//do any initialization required such as sending url to the listeners.
- if (using_node_icecast){
- $("#audio_player").attr("src", stream_url);
- }
+ $("#audio_player").attr("src", stream_url);
JSCast.start();
});
JSCast.on("start", function(){
broadcasting= true;
$("#start_time").text("Started at "+new Date().toString());
$("#dialog").hide();
$("#create_new_button").text("Stop Your Channel");
- if (!using_node_icecast){
- setTimeout(loadChannelList, 14000);
- }
});
JSCast.on("end", function(){
broadcasting= false;
View
@@ -1,15 +1,6 @@
-var jscast = require("js-cast");
var express = require('express');
-
-//NOTE: update below icecast details to suit ur server configuration.
-var options = {
- icecast: {
- server: "http://localhost:8000/",
- sourcepassword: "hackme"
- },
- use_node_icecast: true
-};
+var jscast = require("js-cast");
var app = express();
@@ -46,13 +37,18 @@ app.get('/index.html', function(req, res){
app.get("/channels", function(req, res){
//This is not made part of /jscast/channels as there may be a need to hide active channels from client.
- //send json response containing all the urls and names the active clients
- var channels = jscast.getActiveClients();
+ var channels = jscast.getActiveChannels();
res.contentType('json');
res.send(channels);
});
-jscast.configure(app, options);
+jscast.configure(app);
+jscast.on("data", function(data){
+ console.log(data);
+});
+jscast.on("error", function(data){
+ console.log(data);
+});
app.listen(3000);
console.log("Server listening on port 3000");
View
@@ -10,11 +10,10 @@ var fs = require('fs.extra'),
var ReqQueue= require('./ReqQueue.js');
-var DEFAULT_INACTIVITY_TIMEOUT= 5*60; // 5 minutes
-
var NodeIcecast= function(id, config_dir, options){
- var self= this;
+ EventEmitter.call(this);
+ var self= this;
this._id= id;
this._listeners= new Array();
this._last_activity_ts= Date.now();
@@ -27,11 +26,11 @@ var NodeIcecast= function(id, config_dir, options){
this._description= options.info.description;
this._encoder_bin= options.encoder;
this._encoder_args= options.encoder_args;
- this._inactivity_timeout= (options.inactivity_timeout || DEFAULT_INACTIVITY_TIMEOUT)*1000;
- this._inactivity_timer= setInterval(this.handleInactivityTimer.bind(this), 5000);//5s
- EventEmitter.call(this);
+ if (options.inactivity_timeout){
+ this._inactivity_timeout= options.inactivity_timeout * 1000;
+ this._inactivity_timer= setInterval(this.handleInactivityTimer.bind(this), 5000);//5s
+ }
};
-
util.inherits(NodeIcecast, EventEmitter);
NodeIcecast.prototype.getUrl= function(){
@@ -58,6 +57,7 @@ NodeIcecast.prototype._spawnProcesses= function(){
var self= this;
var encoder= spawn(self._encoder_bin, self._encoder_args.split(" "));
encoder.on('exit', function(){
+ self._reqq.empty();
self._encoder= null;
for (var listener= self._listeners.pop(); listener; listener= self._listeners.pop()){
listener.end();
@@ -69,30 +69,24 @@ NodeIcecast.prototype._spawnProcesses= function(){
self._ogg_header= data;
});
this._encoder= encoder;
- this._reqq= new ReqQueue(encoder.stdin);
+ this._reqq= new ReqQueue(encoder.stdin, this.req_q_min_threshold, this.req_q_max_threshold);
+ this._reqq.on("data", function(data){
+ self.emit("data", data);
+ });
if (this._savefile){
var f= fs.createWriteStream(this._savefile, { flags: 'w', encoding: "binary", mode: 0666 });
this._encoder.stdout.pipe(f, {end: false});
}
this.emit("start");
};
-NodeIcecast.prototype.pipe= function(stream){
- this._last_activity_ts= Date.now();
- stream.pipe(this._encoder.stdin, {end: false});
-};
-
NodeIcecast.prototype.addReq= function(req, index){
this._last_activity_ts= Date.now();
this._reqq.add(req, index);
};
-NodeIcecast.prototype.write= function(buffer){
- this._last_activity_ts= Date.now();
- this._encoder.stdin.write(buffer);
-};
-
NodeIcecast.prototype.destroy= function(){
+ this._reqq.empty();
this._encoder.kill('SIGKILL');
this._encoder= null;
clearInterval(this._inactivity_timer);
View
@@ -4,11 +4,13 @@
*/
var util = require('util'),
- EventEmitter = require('events').EventEmitter ;
-
-var ReqQueue= function(writestream){
+ EventEmitter = require('events').EventEmitter;
+
+var ReqQueue= function(writestream, min, max){
EventEmitter.call(this);
this._q= [];
+ this.MIN_THRESHOLD= min;
+ this.MAX_THRESHOLD= max;
this._writestream= writestream;
};
@@ -25,6 +27,13 @@ ReqQueue.prototype.add= function(req, index){
pkt.complete= true;
self.flush();
});
+ if (this._q.length > this.MAX_THRESHOLD){
+ self.emit("error", "Q exceeded MAX THRESHOLD("+this.MAX_THRESHOLD+").");
+ }
+};
+
+ReqQueue.prototype.empty= function(){
+ this._q= [];
};
ReqQueue.prototype.flush= function(){
@@ -41,6 +50,9 @@ ReqQueue.prototype.flush= function(){
break;
}
}
+ if (this._q.length < this.MIN_THRESHOLD){
+ self.emit("data", "Q Dropped below MIN THRESHOLD("+this.MIN_THRESHOLD+").");
+ }
};
-module.exports= ReqQueue;
+module.exports= ReqQueue;
Oops, something went wrong.

0 comments on commit f33d8f6

Please sign in to comment.