How to use jayson - 10 common examples

To help you get started, we’ve selected a few jayson 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 vitelabs / vite.js / test / RPC / bin / startRPC.js View on Github external
const jayson = require('jayson');

// create a server
const server = jayson.server({
    jsonrpcSuccess: function (args, callback) {
        callback(null, args[0] + args[1]);
    },
    jsonrpcError: function (args, callback) {
        callback({ code: 0, message: JSON.stringify(args) });
    },
    jsonrpcTimeoutSuccess: function (args, callback) {
        setTimeout(() => {
            callback(null, args[0] + args[1]);
        }, 100);
    },
    jsonrpcTimeoutError: function (args, callback) {
        setTimeout(() => {
            callback(null, args[0] + args[1]);
        }, 1000);
    }
github harpagon210 / steemsmartcontracts / plugins / JsonRPCServer.js View on Github external
function init(conf) {
  const {
    rpcNodePort,
  } = conf;

  serverRPC = express();
  serverRPC.use(cors({ methods: ['POST'] }));
  serverRPC.use(bodyParser.urlencoded({ extended: true }));
  serverRPC.use(bodyParser.json());
  serverRPC.set('trust proxy', true);
  serverRPC.set('trust proxy', 'loopback');
  serverRPC.post('/blockchain', jayson.server(blockchainRPC()).middleware());
  serverRPC.post('/contracts', jayson.server(contractsRPC()).middleware());

  http.createServer(serverRPC)
    .listen(rpcNodePort, () => {
      console.log(`RPC Node now listening on port ${rpcNodePort}`); // eslint-disable-line
    });
}
github harpagon210 / steemsmartcontracts / plugins / JsonRPCServer.js View on Github external
function init(conf) {
  const {
    rpcNodePort,
  } = conf;

  serverRPC = express();
  serverRPC.use(cors({ methods: ['POST'] }));
  serverRPC.use(bodyParser.urlencoded({ extended: true }));
  serverRPC.use(bodyParser.json());
  serverRPC.set('trust proxy', true);
  serverRPC.set('trust proxy', 'loopback');
  serverRPC.post('/blockchain', jayson.server(blockchainRPC()).middleware());
  serverRPC.post('/contracts', jayson.server(contractsRPC()).middleware());

  http.createServer(serverRPC)
    .listen(rpcNodePort, () => {
      console.log(`RPC Node now listening on port ${rpcNodePort}`); // eslint-disable-line
    });
}
github tiagovtristao / clipmir-desktop / src / server.js View on Github external
receivedConnections[uuid] = {};
  }

  return true;
}

function handleSetClipboardValueRequest({ uuid, value }) {
  console.log(Date.now(), `${processUUID} has new value '${value}' from ${uuid}`);

  clipboard.writeText(value);
  previousClipboardValue = value; // This avoids the just-received value from being sent out

  return true;
}

let jsonRpcServer = jayson.server({
  getName(args, callback) {
    callback(null, handleGetNameRequest());
  },
  connect(args, callback) {
    if (!objectHas(args, ['uuid'])) {
      callback(() => ({
        error: 'Invalid request',
      }));
    }
    else {
      callback(null, handleConnectRequest(args));
    }
  },
  setClipboardValue(args, callback) {
    if (!objectHas(args, ['uuid', 'value'])) {
      callback(() => ({
github yuchiu / Netflix-Clone / user-service / src / index.js View on Github external
import jayson from "jayson";

import models from "./models";
import RPCInterfaces from "./RPCInterfaces";
import { SERVICE_USER_PORT, NODE_ENV } from "./config/secrets";

// create a server
const server = jayson.server(RPCInterfaces);

models.sequelize.sync().then(() => {
  server
    .http()
    .listen(SERVICE_USER_PORT, () =>
      console.log(
        `  User Service listenning on port ${SERVICE_USER_PORT} in "${NODE_ENV}" mode`
      )
    );
});
github yuchiu / Netflix-Clone / movie-service / src / index.js View on Github external
import jayson from "jayson";
import { SERVICE_MOVIE_PORT, NODE_ENV } from "./config/secrets";
import ESClient from "./config/ESClient.config";
import RPCInterface from "./RPCInterfaces";

// create a server
const server = jayson.server(RPCInterface);

ESClient.ping({ requestTimeout: 30000 }, error => {
  if (error) {
    console.error(`Elasticsearch connection failed: ${error}`);
  } else {
    console.log("Elasticsearch connection success");
  }
});

server
  .http()
  .listen(SERVICE_MOVIE_PORT, () =>
    console.log(
      `  Movie Service listenning on port ${SERVICE_MOVIE_PORT} in "${NODE_ENV}" mode`
    )
  );
github 0xbitcoin / tokenpool / lib / peer-interface.js View on Github external
async initJSONRPCServer()
     {

       var self = this;

       console.log('listening on JSONRPC server localhost:8080')
         // create a server
         var server = jayson.server({
           ping: function(args, callback) {

               callback(null, 'pong');

           },

           getPoolProtocolVersion: function(args, callback) {

                return "1.02";

           },

           getPoolEthAddress: function(args, callback) {

               callback(null, self.getMintHelperAddress().toString() );
github cplusplus / LEWG / scripts / isocppIssues.js View on Github external
// Copyright 2015 Google Inc. All Rights Reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//     http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

"use strict";

var jsonrpc = require('jayson');
var client = jsonrpc.client.https('https://issues.isocpp.org/jsonrpc.cgi');
let ConcurrencyLimit = require('./concurrencyLimit').ConcurrencyLimit;

let requestLimit = new ConcurrencyLimit(5);

function pRequest(method, argument) {
  return requestLimit.whenReady(() =>
      new Promise(function(resolve, reject) {
        client.request(
            method, [argument],
            function(err, error, result) {
              if (err) reject(err);
              else resolve(result);
            });
      }));
};
github lbryio / lbry-desktop / app / main.js View on Github external
const {app, BrowserWindow, ipcMain} = require('electron');
const path = require('path');
const jayson = require('jayson');
// tree-kill has better cross-platform handling of
// killing a process.  child-process.kill was unreliable
const kill = require('tree-kill');
const child_process = require('child_process');
const assert = require('assert');


let client = jayson.client.http('http://localhost:5279/lbryapi');
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win;
// Also keep the daemon subprocess alive
let daemonSubprocess;

// This is set to true right before we try to shut the daemon subprocess --
// if it dies when we didn't ask it to shut down, we want to alert the user.
let daemonSubprocessKillRequested = false;

// When a quit is attempted, we cancel the quit, do some preparations, then
// this is set to true and app.quit() is called again to quit for real.
let readyToQuit = false;

/*
 * Replacement for Electron's shell.openItem. The Electron version doesn't
github sunshead / quibbler / web_server / server / rpc_client / rpc_client.js View on Github external
var jayson = require('jayson');

//backend_server/service.py
var client = jayson.client.http({
    port: 4040,
    hostname: 'localhost'
});

// Test RPC method
function add(a, b, callback) {
    client.request('add', [a, b], function(err, error, response) {
        if (err) throw err;
        console.log(response);
        callback(response);
    });
}

// Get news summaries for a user
function getNewsSummariesForUser(user_id, page_num, callback) {
    client.request('getNewsSummariesForUser', [user_id, page_num], function(err, error, response) {