Open thedracle opened 11 years ago
Interesting. This is because we auto close the response I guess.
The challenge would be figuring out an API which is still simple for the standard use case, but allows you to do advanced stuff like this.
I just set a variable on response, and have the router code check if it exists, or if it is false, before doing anything to the response:
https://github.com/thedracle/meteor-router/commit/6eacd7d30ad80013daf212109106189e3b522cfe
Not the most elegant solution, but it works-- and I can stream audio now :) Thanks for your tip.
I'm attempting to stream an audio feed using a server side GET route:
Meteor.Router.add('/audio/:id.ogg', 'GET', function(id) { if(channel) { this.response.writeHead(200, OGG_HTTP_HEADERS); encoder.stdout.pipe(this.response, {end: false}); } });
Where encoder's stdout is outputing a stream of ogg bytes.
Even if I do encoder.stdout.on('data', function(data){ response.write(data); });
While confirming every write occurs, I still only get 4096 bytes when I try to access the URL via GET:
http://127.0.0.1:3000/audio/45f1088b-1a43-437c-abd9-f990d876e63c.ogg Connecting to 127.0.0.1:3000... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [application/ogg] Saving to: `45f1088b-1a43-437c-abd9-f990d876e63c.ogg'
ls -la 45f1088b-1a43-437c-abd9-f990d876e63c.ogg -rw-rw-r-- 1 jthomas jthomas 4096 Jul 10 23:01 45f1088b-1a43-437c-abd9-f990d876e63c.ogg