-
Notifications
You must be signed in to change notification settings - Fork 114
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
Websocket streams #243
Websocket streams #243
Conversation
… parsing functionality.
… StreamTopic class which is returned in callback.
…er uses calypso-memory to for topic queries.
… stream message. Fixed tests accordingly.
Currently this branch will not allow you to subscribe to |
…nect events to be listened for.
Fixt ^^ |
}, | ||
{ | ||
rel: [rels.events], | ||
href: env.helpers.url.path('/events').replace(/^http/, 'ws') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few things to watch out for when building these URLs, such as... is there a forwarded protocol? Is this an HTTP client connection or a SPDY client connection? See here:
zetta/lib/api_formats/siren/server.siren.js
Lines 10 to 15 in 3a7eb1d
var isForwardedProtocol = context.env.request.headers.hasOwnProperty('x-forwarded-proto') && | |
['http', 'https'].indexOf(context.env.request.headers['x-forwarded-proto']) !== -1; | |
var isSpdy = !!context.env.request.isSpdy && !isForwardedProtocol; | |
var rootPath = env.helpers.url.path(loader.path); | |
var eventPath = isSpdy ? rootPath + '/events' : rootPath.replace(/^http/, 'ws') + '/events'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. Added a test case for this, and functionality to properly calculate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talked with @AdamMagaluk thinking that we actually remove this link for SPDY responses entirely. Currently this feature is only really going to work over websockets.
This is really cool stuff. Is any of this functionality exposed to the Zetta runtime or is it all C2Z/Z2Z API? To enable this inside apps and scouts, we could probably do something like: module.exports = function(server) {
var stream = server.createReadStream('*/led/*/state', { limit: 100 });
stream.on('data', function(msg) {
// awesome!
});
}; |
…d test to confirm appropriate API functionality.
@kevinswiber Currently no, this PR just focuses on the ws side of things. But yes that would be great in the app. |
Adding a websocket link that conforms to the multiplex websocket protocol detailed here:
https://docs.google.com/document/d/1-vkl6o5PjdgsPACXEo80-sF9gPkK9JNIGKxZ8G-2rtM