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:
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:
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.