How to use the @grpc/proto-loader.load function in @grpc/proto-loader

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 sourishkrout / nodevoto / services / nodevoto-gif / api.js View on Github external
module.exports.newGrpcServer = async (grpcServer, gif) => {
  const PROTO_PATH = path.join(__dirname + '../../../proto/Gif.proto');

  let descriptor = await protoLoader.load(
    PROTO_PATH,
    {
      keepCase: true,
      longs: String,
      enums: String,
      defaults: true,
      oneofs: true
    });

  let gifSvc = descriptor['nodevoto.v1.GifService'];
  let gifSrv = new GifServiceServer(gif);
  let implementations = gifSrv.mapRPC();

  grpcServer.addService(gifSvc, implementations);

  return implementations;
github sourishkrout / nodevoto / services / nodevoto-web / server.js View on Github external
async function createGrpcClient(proto, svc, host) {
  const PROTO_PATH = path.join(__dirname, proto);

  let descriptor = await protoLoader.load(
    PROTO_PATH,
    {
      keepCase: true,
      longs: String,
      enums: String,
      defaults: true,
      oneofs: true
    });

  let pkg = grpc.loadPackageDefinition(descriptor);
  let Service = pkg.nodevoto.v1[svc];

  let client = new Service(host, grpc.credentials.createInsecure());

  return client;
}
github sourishkrout / nodevoto / services / nodevoto-voting / api.js View on Github external
module.exports.newGrpcServer = async (grpcServer, poll) => {
  const PROTO_PATH = path.join(__dirname + '../../../proto/Voting.proto');

  let descriptor = await protoLoader.load(
    PROTO_PATH,
    {
      keepCase: true,
      longs: String,
      enums: String,
      defaults: true,
      oneofs: true
    });

  let votingSrv = descriptor['nodevoto.v1.VotingService'];
  let pollSrv = new PollServiceServer(poll);
  let implementations = pollSrv.mapRPC(votingSrv);

  grpcServer.addService(votingSrv, implementations);

  return implementations;

@grpc/proto-loader

gRPC utility library for loading .proto files

Apache-2.0
Latest version published 6 days ago

Package Health Score

100 / 100
Full package analysis

Popular @grpc/proto-loader functions

Similar packages