npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fbp-client

v0.4.3

Published

Higher-level client library for the FBP protocol

Downloads

159

Readme

fbp-client

This library provides a higher level client for interacting with FBP Protocol runtimes. Underneath it utilizes the transport abstractions provided by fbp-protocol-client.

Features

  • Fully Promise-based API for interacting with the runtime
  • Responses to requests sent to runtime are handled via Promise resolving or rejection
  • Messages unrelated to current requests are provided via signal events
  • Protocol API is autogenerated from FBP Protocol JSON schemas, ensuring that it changes up to date with protocol features
  • All messages to and from runtime are validated against FBP Protocol specification

Installation

Install this library via NPM:

$ npm install fbp-client --save

Please note that this library is shipped as ES6 code and utilizes native JavaScript Promises. If needed, you can install a Promise polyfill and transpile the code to ES5.

Usage

Create a client instance for a FBP Protocol runtime definition with:

const fbpClient = require('fbp-client');

fbpClient({
  address: 'wss://localhost:3569',
  protocol: 'websocket',
  secret: 'keyboard-cat',
})
  .then((client) => {
    // Use this client instance for further interactions
  });

Connect to runtime:

client.connect()
  .then(() => {
    // Connected to runtime
  });

Send protocol messages:

client.protocol.runtime.packet({
  graph: 'some-graph-id',
  port: 'in',
  event: 'data',
  payload: 'Hello World!',
})
  .then(() => {
    // Packet was sent
  });

Signals

Events coming from the runtime that are not direct responses to requests made by user are considered to be "signals". To subscribe to all signals coming from the client, use:

client.on('signal', signal => console.log(signal));

You can also subscribe to signals for only one particular subprotocol with:

// Only listen to network protocol
client.on('network', signal => console.log(signal));

Messages sent as responses to a request are not emitted as signals.

Observers

It is also possible to work with signals in a promisifed way by using observers:

// Register observer for all network events
const observer client.observe(['network:*']);
// Start the network
client.protocol.network.start({
  graph: 'my-graph',
})
  .then(() => {
    // Receive all network signals on stopped, or failure with errors
    return observer.until(['network:stopped'], ['network:error', 'network:processerror']);
  });

Debugging

It is possible to see the internal workings of the library by setting the DEBUG environment variable to one or multiple of the following:

  • fbp-client:adapter:signal: Signals received by the runtime
  • fbp-client:adapter:request: Requests sent to the runtime
  • fbp-client:adapter:response: Responses received by the runtime
  • fbp-client:observer: Observer results
  • fbp-client:observer:ignored: Signals ignored by an observer

Changes

  • 0.4.3 (2020-10-02)
    • Updated fbp-protocol-client to include improved connection error handling
  • 0.4.2 (2020-09-29)
    • Updated fbp-protocol-client to include WebRTC support also on Node.js
  • 0.4.1 (2020-09-01)
    • Updated fbp-protocol schemas to the latest versions
  • 0.4.0 (2019-02-26)
    • graph.properties.project is no longer sent as the graph's "library identifier"
  • 0.3.3 (2018-04-06)
    • Ensured that connection failures are sent as Error objects instead of WebSocket error events
  • 0.3.2 (2018-03-29)
    • Schema validation can be disabled with skipValidation: true option. Validation failures still cause protocolError events to be emitted but not longer fail requests or observers
    • When sending graphs, the graph library property will be preferred as the library name
    • disconnected event will fire also if the connection is lost by other means that calling disconnect()
  • 0.3.1 (2018-03-26)
    • Added connected and disconnected events
  • 0.3.0 (2018-03-26)
    • Added support for checking capabilities.
    • Disallowed messages cause requests to be rejected
    • Disallowed signals trigger protocol error
    • Permission checking can be disabled with skipPermissions: true option
  • 0.2.2 (2018-03-24)
    • Fixed observer until failure handling on protocol validation errors
    • Improved test coverage
  • 0.2.1 (2018-03-23)
    • Observer until also fails on protocol validation errors
    • Clearer observer error messages on error packets
  • 0.2.0 (2018-03-23)
    • Added support for promisified signal observation
    • Added debugging support via the debug module
  • 0.1.0 (2018-03-22)
    • Initial version, support for FBP Protocol version 0.7 and earlier