How to use streamr-client - 7 common examples

To help you get started, we’ve selected a few streamr-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fluencelabs / fluence / fluence-js / src / examples / fluence-streamr / index.js View on Github external
import StreamrClient from 'streamr-client'
import * as fluence from "fluence"

const streamrClient = new StreamrClient();
const fluenceSession = fluence.directConnect("localhost", 29057);

const createTableQuery = "CREATE TABLE polution_uusimaa(id varchar(128), location varchar(128), parameter varchar(128), " +
    "value double, unit varchar(128), country varchar(128), city varchar(128), latitude double, " +
    "longitude double, local varchar(128), utc varchar(128))";

const deleteQuery = "DELETE FROM polution_uusimaa";

fluenceSession.invoke(deleteQuery).result().then((r) => console.log(r.asString()));

fluenceSession.invoke(createTableQuery)
    .result() // to return promise and wait for result we need to call `result()` function
    .then((r) => console.log(r.asString())); // `asString()` decodes bytes format to string

function insertQuery(data) {
    const query = `INSERT INTO polution_uusimaa VALUES ('${data.id}', '${data.location}', '${data.parameter}', ${data.value}, ` +
github streamr-dev / streamr-platform / app / src / editor / shared / components / Client.jsx View on Github external
export function createClient(apiKey) {
    return new StreamrClient({
        url: process.env.STREAMR_WS_URL,
        restUrl: process.env.STREAMR_API_URL,
        auth: {
            apiKey, // assume this won't change for now
        },
        autoConnect: true,
        autoDisconnect: false,
    })
}
github streamr-dev / streamr-client-javascript / examples / webpack / src / index.js View on Github external
import StreamrClient from 'streamr-client'

const log = (msg) => {
    const elem = document.createElement('p')
    elem.innerHTML = msg
    document.body.appendChild(elem)
}

// Create the client with default options
const client = new StreamrClient()

document.getElementById('subscribe').addEventListener('click', () => {
    // Subscribe to a stream
    const subscription = client.subscribe({
        stream: '7wa7APtlTq6EC5iTCBy6dw',
        // Resend the last 10 messages on connect
        resend: {
            last: 10,
        },
    }, (message) => {
        // Handle the messages in this stream
        log(JSON.stringify(message))
    })

    // Event binding examples
    client.on('connected', () => {
github streamr-dev / streamr-platform / app / src / userpages / components / StreamrClientProvider / index.jsx View on Github external
function initClient(keyId: ?string) {
    if (!keyId) {
        return
    }

    return new StreamrClient({
        url: process.env.STREAMR_WS_URL,
        restUrl: process.env.STREAMR_API_URL,
        auth: {
            apiKey: keyId,
        },
        autoConnect: true,
        autoDisconnect: false,
    })
}
github streamr-dev / streamr-platform / app / src / userpages / components / StreamrClientProvider / index.jsx View on Github external
function initClient(keyId: ?string) {
    if (!keyId) {
        return
    }

    return new StreamrClient({
        url: config.wsUrl,
        authKey: keyId,
        autoconnect: true,
        autoDisconnect: false,
    })
}
github streamr-dev / streamr-platform / src / components / StreamLivePreview / index.jsx View on Github external
createClient = (apiKey: ?ApiKey): ?StreamrClient => {
        if (!cachedClient || (apiKey && cachedClient.options.apiKey !== apiKey.id)) {
            cachedClient = new StreamrClient({
                url: process.env.STREAMR_WS_URL,
                apiKey: (apiKey && apiKey.id) || undefined,
                autoconnect: true,
                autoDisconnect: false,
            })
        }
        return cachedClient
    }
github streamr-dev / streamr-platform / app / src / auth / utils / getSessionToken.js View on Github external
export default async (auth: Object): Promise => (
    new StreamrClient({
        restUrl: process.env.STREAMR_API_URL,
        auth,
    }).session.getSessionToken()
)

streamr-client

JavaScript client library for Streamr

Apache-2.0
Latest version published 10 months ago

Package Health Score

74 / 100
Full package analysis

Popular streamr-client functions

Similar packages