Skip to content

Instantly share code, notes, and snippets.

@kevinswiber
Created March 8, 2016 19:21
Show Gist options
  • Select an option

  • Save kevinswiber/11c69f5d5ca6a3c8166f to your computer and use it in GitHub Desktop.

Select an option

Save kevinswiber/11c69f5d5ca6a3c8166f to your computer and use it in GitHub Desktop.
Subscribing to every stream of every device of every peer via a Zetta client.
var zetta = require('zetta-client');
var server = zetta().connect('http://localhost:3003');
var allQuery = server
.from()
.where('where type is not missing');
server.observe(allQuery, function(device) {
var hubName = device._data.links
.filter(function(link) {
return link.rel.indexOf('up') !== -1;
})[0].title;
device._data.links
.filter(function(link) {
return link.rel.indexOf('http://rels.zettajs.io/object-stream') !== -1;
})
.map(function(link) {
return device.createReadStream(link.title);
})
.forEach(function(stream) {
stream.on('data', function(message) {
var datum = {
hub: hubName,
device: {
id: device.id,
type: device.type
},
timestamp: message.timestamp,
value: message.data
};
// do something with the data
console.log(datum);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment