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

react-native-ssb-client

v7.1.0

Published

Secure Scuttlebutt client-side API for React Native apps

Downloads

28

Readme

SSB Client for React Native apps

Similar to ssb-client, but for React Native apps that run ssb-server using nodejs-mobile-react-native.

Install

Prerequisites:

  • React Native 0.60 or higher
    • React Native 0.59 and lower are supported only in react-native-ssb-client version 5.0.0
  • nodejs-mobile-react-native as a dependency in your React Native project
  • react-native-ssb-shims as a dependency in your React Native project
npm install --save react-native-ssb-client

Use

In your backend code (your nodejs-mobile project), make sure that you have ssb-server or secret-stack installed, and add the following configurations set up:

 const SecretStack = require('secret-stack');
 const ssbKeys = require('ssb-keys');
+const rnBridge = require('rn-bridge');
+const rnChannelPlugin = require('multiserver-rn-channel');
+const NoauthTransformPlugin = require('multiserver/plugins/noauth');

 const config = makeConfig('ssb', {
   connections: {
     incoming: {
       net: [{scope: 'private', transform: 'shs', port: 26831}],
+      channel: [{scope: 'device', transform: 'noauth'}],
     },
     outgoing: {
       net: [{transform: 'shs'}],
     },
   },
 });

+function rnChannelTransport(ssb: any) {
+  ssb.multiserver.transport({
+    name: 'channel',
+    create: () => rnChannelPlugin(rnBridge.channel),
+  });
+}

+function noAuthTransform(ssb: any, cfg: any) {
+  ssb.multiserver.transform({
+    name: 'noauth',
+    create: () =>
+      NoauthTransformPlugin({
+        keys: {publicKey: Buffer.from(cfg.keys.public, 'base64')},
+      }),
+  });
+}

 SecretStack({appKey: require('ssb-caps').shs})
   .use(require('ssb-db'))
+  .use(noAuthTransform)
+  .use(rnChannelTransport)
   .use(require('ssb-master'))
   .use(require('ssb-conn'))
   .use(require('ssb-blobs'))
   .use(require('ssb-ebt'))
   .call(null, config);

In your frontend code we assume you have access to the muxrpc manifest object. Then, in your frontend code you import this library:

import ssbClient from 'react-native-ssb-client'

// ...

ssbClient(manifest)
  .use(somePlugin) // optional
  .call(null, (err, ssb) => {
    // You can now use `ssb` with all the muxrpc APIs from the backend
  })

NOTE! This library does not start the backend, you have to do that yourself by important nodejs-mobile-react-native and calling nodejs.start() or startProject().

API

  • ssbClient(manifest): this configures your muxrpc client, where manifest is an object describing the muxrpc APIs we want
  • .use(plugin): call this to attach a client-side plugin to your final muxrpc object. Plugins are {name, init} objects, where name is a string, and init(ssb): void is a function; much like secret-stack plugins are
  • .call(null, cb): call this to start using the muxrpc, it will be provided to you in the callback cb
  • .callPromise(): as an alternative to the above, you can call this to get a Promise that resolves with the muxrpc ssb object

Plugins

When setting up the client, you can register plugins. These look and feel like ssb-server or secret-stack plugins, in fact, in many cases they are so similar that a plugin intended for ssb-server might work just fine for react-native-ssb-client!

You can use client-side plugins when you are sure you don't want to run this code in the backend. For instance, a client-side plugin is the perfect place to put a light cache, in order to avoid a request to the backend. See e.g. ssb-cached-about.

Below is a simple plugin that just publishes a greeting message in the DB:

const greeterPlugin = {
  name: 'greetings',

  init: function (ssb) {
    return {
      greet: (cb) => {
        ssb.publish({type: 'post', text: 'Hello world!'}, cb)
      },
    }
  }
}

To install it:

 ssbClient(manifest)
+  .use(greeterPlugin)
   .call(null, (err, ssb) => {

   })

To use it:

 ssbClient(manifest)
   .use(greeterPlugin)
   .call(null, (err, ssb) => {
+    // Will publish a message on our feed:
+    ssb.greetings.greet((err, val) => { /* ... */ })
   })

Note

Some dependencies, such as events and assert, are in this library just to polyfill necessary Node.js utilities that are used in muxrpc and multiserver — important dependencies of this library.

License

MIT