Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rawr (a.k.a. RAWRpc)

NPM

CircleCI

Coverage Status

Remote Procedure Calls (JSON-RPC) sent over any EventEmitter-based transport. WebWorkers, WebSockets, MQTT, and more!

RAWRpc

Installation

npm install rawr

Using the RPC client

Every rawr client can act as both a client and a server, and make RPC calls in either direction.

For example, if we want to use rawr to make calls to a webworker:

import rawr from 'rawr';
import { dom } from 'rawr/tansports/worker';

const myWorker = new Worker('/my-worker.js');

const peer = rawr({transport: dom(myWorker)});

const result = await peer.methods.doSomething('lots of data');

Our WebWorker code might look something like:

import rawr from 'rawr';
import { worker } from 'rawr/tansports/worker';

const peer = rawr({transport: worker(), handlers: {doSomething}});

function doSomething(inputData) {
  // do some heavy lifting in this thread
  // return a result
}

We could even to this type of call to a remote server such as a websocket. Simply use a differnt transport:

import rawr from 'rawr';
import wsTransport from 'rawr/tansports/websocket';

const ws = new WebSocket('ws://localhost:8080');

ws.onopen = (event) => {
  // create the rawr peer
  const peer = rawr({transport: wsTransport(ws)});
};

The websocket server could even make arbitrary calls to the client!

socketServer.on('connection', (socket) => {
  const peer = rawr({ transport: wsTransport(socket) })

  const val = await peer.methods.doSomethingOnClient();
  
});

Handling Notifications

Peers can also send each other notifications:

peer.notifiers.saySomething('hello');

Receiving those notifications is just as simple:

peer.onNotification('saySomething', (words) => {
  console.log(words); //hellow
});

About

Remote Procedure Calls overs any EventEmitter transport

Resources

Stars

24 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages