How to use the @grpc/grpc-js.loadPackageDefinition function in @grpc/grpc-js

To help you get started, we’ve selected a few @grpc/grpc-js 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 GoogleCloudPlatform / esp-v2 / tests / endpoints / bookstore_grpc / grpc_server.js View on Github external
// This port is used by the backend settings in envoy.yaml
var PORT = 8082;
const path = require('path');
const PROTO_PATH = path.join(__dirname, '/proto/bookstore.proto');

var packageDefinition = protoLoader.loadSync(PROTO_PATH, {
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true,
});

var bookstore_proto =
    grpc.loadPackageDefinition(packageDefinition).endpoints.examples.bookstore;

// The bookstore example uses a simple, in-memory database
// for illustrative purposes only.
var bookstoreDatabase = {
  100: {id: 100, theme: 'Kids', books: {1001: {id: 1001, title: 'Alphabet'}}},
  200: {
    id: 200,
    theme: 'Classic',
    books: {2001: {id: 2001, title: 'Hamlet', author: 'Shakspeare'}}
  }
};

function listShelves(call, callback) {
  console.log(call.metadata);
  var found = [];
  for (var key in bookstoreDatabase) {
github LN-Zap / node-lnd-grpc / src / service.js View on Github external
connectionOptions,
      version,
    } = opts

    try {
      // Find the most recent proto file for this service if a specific version was not requested.
      this.version = version || getLatestProtoVersion()

      const serviceDefinition = registry[this.version].services.find(s => s.name === this.serviceName)
      const [protoPackage, protoFile] = serviceDefinition.proto.split('/')
      const filepath = join(protoDir || getProtoDir(), this.version, protoPackage, protoFile)
      this.debug(`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)

      // Wait for the cert to exist (this can take some time immediately after starting lnd).
      if (waitForCert) {
        const waitTime = Number.isFinite(waitForCert) ? waitForCert : FILE_WAIT_TIMEOUT
        await waitForFile(cert, waitTime)
      }

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

      // Add macaroon to credentials if service requires macaroons.
      if (this.useMacaroon && macaroon) {
        // Wait for the macaroon to exist (this can take some time immediately after Initializing a wallet).
        if (waitForMacaroon) {
          const waitTime = Number.isFinite(waitForMacaroon) ? waitForMacaroon : FILE_WAIT_TIMEOUT
          await waitForFile(macaroon, waitTime)
github JustinBeckwith / cloudcats / web / catrelay.js View on Github external
'use strict';

const grpc = require('@grpc/grpc-js');
const loader = require('@grpc/proto-loader');
const logger = require('./logger');

const packageDef = loader.loadSync('cloudcats.proto');
const proto = grpc.loadPackageDefinition(packageDef).cloudcats;

const apiEndpoint = process.env.WORKER_ENDPOINT || '0.0.0.0:8081';

// Create the subscription, and forward messages to the browser
const listen = io => {
	// Listen to socket.io for a new run request from the browser
	io.on('connection', socket => {
		socket.on('start', () => {
			makeRequest(socket);
		});
	});
};

// Create a new gRPC client.  Connect to the worker, and
// analyze the stream of responses.
function makeRequest(socket) {
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 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.
    this.service = new rpc.lnrpc[this.serviceName](host, creds)
github giant-app / LiveWallpaperEngine / LiveWallpaperWebRender / src / index.js View on Github external
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 = []
github grpc / grpc-web / net / grpc / gateway / examples / echo / node-server / server.js View on Github external
var PROTO_PATH = __dirname + '/../echo.proto';

var assert = require('assert');
var async = require('async');
var _ = require('lodash');
var grpc = require('@grpc/grpc-js');
var protoLoader = require('@grpc/proto-loader');
var packageDefinition = protoLoader.loadSync(
    PROTO_PATH,
    {keepCase: true,
     longs: String,
     enums: String,
     defaults: true,
     oneofs: true
    });
var protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
var echo = protoDescriptor.grpc.gateway.testing;

/**
 * @param {!Object} call
 * @return {!Object} metadata
 */
function copyMetadata(call) {
  var metadata = call.metadata.getMap();
  var response_metadata = new grpc.Metadata();
  for (var key in metadata) {
    response_metadata.set(key, metadata[key]);
  }
  return response_metadata;
}

/**
github depscloud / depscloud / packages / depscloud-api-nodejs / index.js View on Github external
const packageDefinition = protoLoader.loadSync(
    filenames,
    {
        keepCase: true,
        longs: String,
        enums: String,
        defaults: true,
        oneofs: true,
        includeDirs: [
            __dirname,
        ]
    }
);

const descriptor = grpc.loadPackageDefinition(packageDefinition);

module.exports = descriptor.cloud.deps.api;
github googleforgames / agones / sdks / nodejs / src / agonesSDK.js View on Github external
constructor() {
		const services = grpc.loadPackageDefinition(servicesPackageDefinition);
		const address = `localhost:${this.port}`;
		const credentials = grpc.credentials.createInsecure();
		this.client = new services.agones.dev.sdk.SDK(address, credentials);
		this.healthStream = undefined;
		this.streams = [];
		this.alpha = new Alpha(address, credentials);
	}