0.0.3 • Published 3 years ago

rpcsocketlib v0.0.3

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

rpcsocketlib

install

yarn add rpcsocketlib

server.js

const { socketServer } = require('rpcsocketlib');

(async () => {
  await socketServer(4001);
})();

provider.js

const { socketConsume } = require('rpcsocketlib');

socketConsume('http://localhost:4001', 'test-channel', async (body) => {
  console.log(body);
  return body;
});

consumer.js

const { socketRequest } = require('rpcsocketlib');

(async () => {
  const res = await socketRequest('http://localhost:4001', 'test-channel', { message: 'surprise motherfucker' });
  console.log(res);
})();

usage

socketRequest (uri, channel, body, config)

socketConsume (uri, channel, cb)

  • uri : socket server url, ex : http://localhost:4001
  • channel : incoming data channel
  • cb : callback, ex : cb(body) {}