Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/koorchik/node-mole-rpc-transport-eventemitter
Event Emitter Mole RPC (JSON RPC library) transport
https://github.com/koorchik/node-mole-rpc-transport-eventemitter
eventemitter json-rpc mole-rpc
Last synced: 4 days ago
JSON representation
Event Emitter Mole RPC (JSON RPC library) transport
- Host: GitHub
- URL: https://github.com/koorchik/node-mole-rpc-transport-eventemitter
- Owner: koorchik
- License: mit
- Created: 2018-12-05T23:32:15.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-11-26T19:29:04.000Z (almost 2 years ago)
- Last Synced: 2024-10-14T12:21:27.879Z (about 1 month ago)
- Topics: eventemitter, json-rpc, mole-rpc
- Language: JavaScript
- Size: 22.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-json-rpc - node-mole-rpc-transport-eventemitter - Event Emitter Mole RPC (JSON RPC library) transport (Libraries)
README
## Event Emitter Transport for Mole RPC (JSON RPC Library)
[![npm version](https://badge.fury.io/js/mole-rpc-transport-eventemitter.svg)](https://badge.fury.io/js/mole-rpc-transport-eventemitter)
[![Build Status](https://travis-ci.org/koorchik/node-mole-rpc-transport-eventemitter.svg?branch=master)](https://travis-ci.org/koorchik/node-mole-rpc-transport-eventemitter)
[![Known Vulnerabilities](https://snyk.io/test/github/koorchik/node-mole-rpc-transport-eventemitter/badge.svg?targetFile=package.json)](https://snyk.io/test/github/koorchik/node-mole-rpc-transport-eventemitter?targetFile=package.json)Mole-RPC is a tiny transport agnostic JSON-RPC 2.0 client and server which can work both in NodeJs, Browser, Electron etc.
This is EventEmitter based tranport but there are [many more transports](https://www.npmjs.com/search?q=keywords:mole-transport).
## Usage example
```js
const MoleClient = require('mole-rpc/MoleClient');
const MoleServer = require('mole-rpc/MoleServer');
const EventEmitterTransportClient = require('mole-rpc-transport-eventemitter/TransportClient');
const EventEmitterTransportServer = require('mole-rpc-transport-eventemitter/TransportServer');const EventEmitter = require('events');
async function main() {
const emitter = new EventEmitter();await runServer(emitter);
await runClients(emitter);
}async function runServer(emitter) {
const server = new MoleServer({
transports: [
new EventEmitterTransportServer({
emitter,
inTopic: 'fromClient1',
outTopic: 'toClient1'
}),
new EventEmitterTransportServer({
emitter,
inTopic: 'fromClient2',
outTopic: 'toClient2'
})
]
});server.expose({
getGreeting(name) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(`Hi, ${name}`);
}, 1000);
});
}
});
}async function runClients(emitter) {
const client1 = new MoleClient({
transport: new EventEmitterTransportClient({
emitter,
inTopic: 'toClient1',
outTopic: 'fromClient1'
})
});const client2 = new MoleClient({
transport: new EventEmitterTransportClient({
emitter,
inTopic: 'toClient2',
outTopic: 'fromClient2'
})
});console.log('FROM CLIENT 1', await client1.callMethod('getGreeting', 'User1'));
console.log('FROM CLIENT 2', await client2.callMethod('getGreeting', 'User2'));
}main();
```