1.1.0 • Published 7 years ago

grpc-bus v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

GRPC Bus codecov Build Status npm version dependencies Status devDependencies Status

GRPC-bus is a mechanism to call GRPC services from the browser using a Node.JS server as a proxy. The link between the browser and Node.JS is defined by the user, but could be something like a WebSocket.

The server and client are expected to share the same / similar protobuf tree. For example, the same result should come from the following code on both the client and server:

root.lookup("mynamespace.MyType");

In this way the client can implement the ProtoBuf.JS RPC interfaces in the browser. Then, the grpc-bus package does the following:

  • Keep track of connections to desired remote servers
  • Make service calls on behalf of the client
  • Keep track of streaming calls and pipe these back to the client accordingly.

Thus, we can call GRPC servers from the browser via a Node.JS websocket stream.

Example

First, create your client, and give it a way to communicate with the server:

var protoRoot = ProtobufJS.load('...');
var grpcBus = require('grpc-bus');

// MySendFunction takes a message object.
// This message should be passed to handleMessage on the server.
var client = new grpcBus.Client(protoTree, mySendFunction);

var tree = client.root;
tree.lookup('mynamespace.MyService')('localhost:3000').then(function(service) {
  service.MyMethod({hello: 'world'}, function(err, resp) {
    console.log(resp);
    service.end();
  });
});

You should always call service.end() when you are done with a service handle, so the server knows it's safe to dispose it.

You'll notice that inside the then block the API is exactly the same as the Node GRPC api.

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.2.4

7 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago