How to use @grpc/proto-loader - 10 common examples

To help you get started, we’ve selected a few @grpc/proto-loader examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LN-Zap / zap-desktop / services / grpc / grpcService.js View on Github external
async establishConnection(options = {}) {
    const { version, useMacaroon, waitForMacaroon } = options
    const { host, cert, macaroon, protoPath } = this.lndConfig

    // Find the most recent rpc.proto file
    const versionToUse = version || (await lndgrpc.getLatestProtoVersion({ path: protoPath }))
    const filepath = join(protoPath, `${versionToUse}.proto`)
    grpcLog.info(`Establishing gRPC connection to ${this.serviceName} with proto file %s`, filepath)

    // Load gRPC package definition as a gRPC object hierarchy.
    const packageDefinition = await load(filepath, grpcOptions)
    const rpc = loadPackageDefinition(packageDefinition)

    // Create ssl credentials to use with the gRPC client.
    let creds = await createSslCreds(cert)

    // Add macaroon to crenentials if service requires macaroons.
    if (useMacaroon) {
      // If we are trying to connect to the internal lnd, wait up to 20 seconds for the macaroon to be generated.
      if (waitForMacaroon) {
        await waitForFile(macaroon, 20000)
      }
      const macaroonCreds = await createMacaroonCreds(macaroon)
      creds = credentials.combineChannelCredentials(creds, macaroonCreds)
    }

    // Create a new gRPC client instance.
github LN-Zap / zap-desktop / app / lib / lnd / walletUnlocker.js View on Github external
async establishConnection() {
    const { host, cert } = this.lndConfig

    // Find the most recent rpc.proto file
    const version = await lndgrpc.getLatestProtoVersion({ path: lndGpcProtoPath() })
    const filepath = join(lndGpcProtoPath(), `${version}.proto`)
    mainLog.debug('Establishing gRPC connection with proto file %s', filepath)

    // Load gRPC package definition as a gRPC object hierarchy.
    const packageDefinition = await load(filepath, grpcOptions)
    const rpc = loadPackageDefinition(packageDefinition)

    // Create ssl credentials to use with the gRPC client.
    const sslCreds = await createSslCreds(cert)

    // Create a new gRPC client instance.
    this.service = new rpc.lnrpc.WalletUnlocker(host, sslCreds)

    // Wait upto 20 seconds for the gRPC connection to be established.
    return new Promise((resolve, reject) => {
      this.service.waitForReady(getDeadline(20), err => {
        if (err) {
          this.service.close()
          return reject(err)
        }
        return resolve()
github giant-app / LiveWallpaperEngine / LiveWallpaperWebRender / src / index.js View on Github external
const { app, BrowserWindow } = require('electron')
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');

let protoFile = `${__dirname}\\..\\..\\Protos\\api.proto`;
protoLoader.load(protoFile).then(packageDefinition => {
  const proto = grpc.loadPackageDefinition(packageDefinition);

  let package = proto["LiveWallpaperEngine"];
  let client = new package["API"]("127.0.0.1:8080", grpc.credentials.createInsecure());
  let test = client["CloseWallpaper"]({
    "ScreenIndexs": [3, 2]
  }, (e1) => {
    console.log("success" + e1);
  });
});
const windows = []
console.error("test");
app.on('ready', () => {
  let window = new BrowserWindow({
    skipTaskbar: true,
    frame: false,
github benjsicam / node-graphql-microservices / graphql-gateway / src / services / posts / post.client.js View on Github external
import path from 'path'

import * as grpc from 'grpc'
import * as protoLoader from '@grpc/proto-loader'

const proto = protoLoader.loadSync(path.resolve(__dirname, '../../_proto/post.proto'), {
  enums: String,
  objects: true,
  arrays: true
})
const PostServiceClient = grpc.loadPackageDefinition(proto).post.PostService

export default PostServiceClient
github lightninglabs / lightning-app / public / grpc-client.js View on Github external
ipcMain.on('unlockInit', async event => {
    credentials = await getCredentials(lndSettingsDir);
    protoPath = path.join(__dirname, '..', 'assets', 'rpc.proto');
    const options = {
      keepCase: false,
      longs: Number,
      enums: String,
      defaults: true,
      oneofs: true,
    };
    const packageDef = protoLoader.loadSync(protoPath, options);
    lnrpc = grpc.loadPackageDefinition(packageDef).lnrpc;
    unlocker = new lnrpc.WalletUnlocker(`localhost:${lndPort}`, credentials);
    grpc.waitForClientReady(unlocker, Infinity, err => {
      event.sender.send('unlockReady', { err });
    });
  });
github angular / universal / modules / grpc-engine / spec / index.spec.ts View on Github external
function createClient() {
  const packageDefinition = loadSync('modules/grpc-engine/grpc-engine.proto', {});
  const grpcEngineProto = loadPackageDefinition(packageDefinition).grpcengine;

  const client = new grpcEngineProto.SSR('localhost:9090', credentials.createInsecure());
  return client;
}
github prisma / photonjs / examples / javascript / grpc / server / server.js View on Github external
const chalk = require('chalk')
const PROTO_PATH = __dirname + '/../service.proto'

const Photon = require('@generated/photon')
const photon = new Photon()

const grpc = require('grpc')
const protoLoader = require('@grpc/proto-loader')
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true,
})
const { blog } = grpc.loadPackageDefinition(packageDefinition)

async function post(call, callback) {
  const { id } = call.request
  const post = await photon.posts.findOne({
    where: {
      id,
    },
  })
  callback(null, post)
github YoshiyukiKato / grpc-kit / index.js View on Github external
function createClient({ protoPath, packageName, serviceName, options }, address, creds=grpc.credentials.createInsecure()){
  const pkgDef = grpc.loadPackageDefinition(protoLoader.loadSync(protoPath, options));
  const proto = getProtoFromPackageDefinition(pkgDef, packageName);
  return new proto[serviceName](address, creds);
}
github nguyenkha / forest.network / lib / server.js View on Github external
}
    } catch (err) {
      return { code: 1, log: err.toString() };
    }
  }
};

const options = {
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true,
};

const protoDefinition = protoLoader.loadSync(PROTO_PATH, options)['types.ABCIApplication'];

const server = new grpc.Server();

const services = {};

Object.keys(protoDefinition).forEach((k) => {
  const method = _.lowerFirst(k);
  if (app[method]) {
    services[method] = (call, callback) => {
      app[method](call.request).then(res => callback(null, res)).catch(callback);
    };
  } else {
    services[method] = (_call, callback) => {
      callback(null, {});
    };
  }

@grpc/proto-loader

gRPC utility library for loading .proto files

Apache-2.0
Latest version published 6 months ago

Package Health Score

98 / 100
Full package analysis

Popular @grpc/proto-loader functions

Similar packages