Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Queuing mechanism implemented for post req

  • Loading branch information...
commit 6acb9f34375f23c00e2d81dd79f52087aafc5204 1 parent d7c731f
Balaji dbalaji authored
BIN  external/wami/Wami.swf
Binary file not shown
8 lib/NodeIcecast.js
@@ -8,6 +8,8 @@ var fs = require('fs.extra'),
8 8 util = require('util'),
9 9 EventEmitter = require('events').EventEmitter ;
10 10
  11 +var ReqQueue= require('./ReqQueue.js');
  12 +
11 13 var DEFAULT_INACTIVITY_TIMEOUT= 5*60; // 5 minutes
12 14
13 15 var NodeIcecast= function(id, config_dir, options){
@@ -67,6 +69,7 @@ NodeIcecast.prototype._spawnProcesses= function(){
67 69 self._ogg_header= data;
68 70 });
69 71 this._encoder= encoder;
  72 + this._reqq= new ReqQueue(encoder.stdin);
70 73 if (this._savefile){
71 74 var f= fs.createWriteStream(this._savefile, { flags: 'w', encoding: "binary", mode: 0666 });
72 75 this._encoder.stdout.pipe(f, {end: false});
@@ -79,6 +82,11 @@ NodeIcecast.prototype.pipe= function(stream){
79 82 stream.pipe(this._encoder.stdin, {end: false});
80 83 };
81 84
  85 +NodeIcecast.prototype.addReq= function(req, index){
  86 + this._last_activity_ts= Date.now();
  87 + this._reqq.add(req, index);
  88 +};
  89 +
82 90 NodeIcecast.prototype.write= function(buffer){
83 91 this._last_activity_ts= Date.now();
84 92 this._encoder.stdin.write(buffer);
46 lib/ReqQueue.js
... ... @@ -0,0 +1,46 @@
  1 +/**
  2 + * @description: Implements a Post Request Queue. Buffers the post data and outputs in order.
  3 + *
  4 + */
  5 +
  6 +var util = require('util'),
  7 + EventEmitter = require('events').EventEmitter ;
  8 +
  9 +var ReqQueue= function(writestream){
  10 + EventEmitter.call(this);
  11 + this._q= [];
  12 + this._writestream= writestream;
  13 +};
  14 +
  15 +util.inherits(ReqQueue, EventEmitter);
  16 +
  17 +ReqQueue.prototype.add= function(req, index){
  18 + var self= this;
  19 + var pkt= {complete: false, index: index, data: []};
  20 + this._q.push(pkt);
  21 + req.on("data", function(data){
  22 + pkt.data.push(data);
  23 + });
  24 + req.on("end", function(){
  25 + pkt.complete= true;
  26 + self.flush();
  27 + });
  28 +};
  29 +
  30 +ReqQueue.prototype.flush= function(){
  31 + while(this._q.length){
  32 + var pkt= this._q[0];
  33 + if (pkt.complete){
  34 + //console.log("Writing packet -- "+pkt.index);
  35 + for (var i=0, count= pkt.data.length; i< count; i++){
  36 + this._writestream.write(pkt.data[i]);
  37 + }
  38 + this._q.shift();
  39 + }
  40 + else {
  41 + break;
  42 + }
  43 + }
  44 +};
  45 +
  46 +module.exports= ReqQueue;
11 lib/js-cast.js
@@ -92,16 +92,11 @@ JSCast.prototype.configure= function(app, config){
92 92 require('bufferjs/add-chunk');
93 93 app.post('/js-cast/stream', function(req, res, next){
94 94 var client= self._clients[req.query.id];
95   - var buffer= new Buffer(8820, 'binary');
  95 + var packet_no= req.query.chunk;
  96 + //console.log("packet no :"+ packet_no+" received at " + new Date());
96 97 if (client){
97   - //console.log("START WAMI post at "+new Date());
98   - req.on("data", function(data){
99   - buffer.addChunk(data);
100   - })
101   - //client.pipe(req);
  98 + client.addReq(req, packet_no);
102 99 req.on("end", function() {
103   - //console.log("END WAMI post at "+ new Date());
104   - client.write(buffer);
105 100 self._send200(res);
106 101 });
107 102 }
2  package.json
... ... @@ -1,7 +1,7 @@
1 1 {
2 2 "name": "js-cast",
3 3 "description": "Voice Streaming from client Browser using icecast server",
4   - "version": "0.0.12",
  4 + "version": "0.0.13",
5 5 "author": {
6 6 "name": "D Balaji",
7 7 "email": "balaji@ariemtech.com"

0 comments on commit 6acb9f3

Please sign in to comment.
Something went wrong with that request. Please try again.