Skip to content

Instantly share code, notes, and snippets.

@akaron
Last active September 25, 2019 00:14
Show Gist options
  • Save akaron/06cd9d7f126f13c8c8fa6eac5bdb0bc3 to your computer and use it in GitHub Desktop.
Save akaron/06cd9d7f126f13c8c8fa6eac5bdb0bc3 to your computer and use it in GitHub Desktop.
streamr (read)
'use strict'
const StreamrClient = require('streamr-client');
const apiKey = '' // read-only key created via streamr.network/stream
// Create the client using api key
const client = new StreamrClient({
auth: {
apiKey: apiKey
}
})
// subscribe to receive messages published by other clients
var count = 0;
console.log(`stop feteching stream after there are 5 data (or press CTRL-C)...`)
const sub = client.subscribe(
{
stream: '31lQzneQQwicPuy_obROdg', // test stream
resend: {
last: 5
}
},
// The "message" variable includes the "content" plus other metadata information
(content, message) => {
console.log(content)
count += 1;
if (count >= 5) client.unsubscribe(sub);
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment