Last active
September 25, 2019 00:14
-
-
Save akaron/06cd9d7f126f13c8c8fa6eac5bdb0bc3 to your computer and use it in GitHub Desktop.
streamr (read)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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