Skip to content
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

Server Side GET stream data. #107

Open
thedracle opened this issue Jul 11, 2013 · 2 comments
Open

Server Side GET stream data. #107

thedracle opened this issue Jul 11, 2013 · 2 comments

Comments

@thedracle
Copy link

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'

[  <=>                                  ] 4,096       --.-K/s              
[   <=>                                 ] 4,096       --.-K/s

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

@tmeasday
Copy link
Owner

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.

@thedracle
Copy link
Author

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:

thedracle@6eacd7d

Not the most elegant solution, but it works-- and I can stream audio now :) Thanks for your tip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants