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

@matejdr/react-native-grpc-client

v0.2.2

Published

A gRPC client for React Native, which uses the native gRPC bridge.

Downloads

7

Readme

react-native-grpc-client

gRPC client for React Native. A bridge to use the native gRPC in React Native apps.

Installation

npm install @matejdr/react-native-grpc-client

Node version

nvm install

or

nvm use

Install npm packages

yarn install

Usage

import { GrpcClientImpl, GrpcConfig, GrpcMetadata, GrpcMethodType } from '@matejdr/react-native-grpc-client';

const grpcConfig: GrpcConfig = {
  host: '<your gRPC host>',
  isInsecure: true,
};
const grpcMethod = `/<your gRPC service name>/<your gRPC method name>`;
const headers: GrpcMetadata = {};
const methodType = 'bidiStreaming';

const call = GrpcClientImpl.startCall(
  grpcConfig,
  grpcMethod,
  headers,
  methodType
);

call.headers
  .then((headers) => {
    console.log('NativeGRPC.headers', headers);
  })
  .catch((error) => {
    console.log('NativeGRPC.headers.error', error);
  });

call.responses.on('data', (data) => {
  console.log('NativeGRPC.data', data);
});

call.responses.on('complete', () => {
  console.log('NativeGRPC.complete');
});

call.responses.on('error', (reason) => {
  console.log('NativeGRPC.error', reason);
});

// send your message
const msgBytes: Uint8Array = []

call
  .sendMessage(msgBytes)
  .then((response) => {
    console.log('NativeGRPC.sendMessage', response, methodType);
    // finish sending messages for server and unary calls
    if (
      response &&
      ['unary', 'serverStreaming'].indexOf(methodType) !== -1
    ) {
      call.finishSendMessage();
    }
  })
  .catch((error) => {
    console.log('NativeGRPC.sendMessage error', error);
  });

// cancel ccall after 10 seconds - for demo purposes
setTimeout(() => {
  call.cancel();
}, 10000)

Running a docker Server for example app

There is an envoy proxy in front of go server.

cd server
docker-compose up --build server envoy

Running a gRPC Server manually

You can also run the grpc server manually using the following instructions.

Install protoc

Install for go

go get -u google.golang.org/grpc
go get -u github.com/golang/protobuf/proto
go install github.com/golang/protobuf/protoc-gen-go@latest
export PATH=$HOME/go/bin:$PATH

Generate stubs for js and go

protoc \
  --proto_path=server/proto \
  --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \
  --js_out=import_style=commonjs:example/src/api \
  --ts_out=example/src/api \
  echo.proto
protoc \
  --proto_path=server/proto \
  --go_out=plugins=grpc:server/echoserver/echo \
  --go_opt=paths=source_relative \
  echo.proto

Running a server

cd server/echoserver
go run main.go

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT