@genee/json-rpc
TypeScript icon, indicating that this package has built-in type declarations

1.10.4 • Public • Published

json-rpc

Installation

yarn add git+https://github.com/iamfat/json-rpc.git

Usage

General

import JsonRPC from '@genee/json-rpc'

const rpc = new JsonRPC(data => {
    // send your data with your customized function
}, {
    // logger?: console // you may customize your own logger 
})

rpc.receive(data) // process the data you received

rpc.on('xxx', () => {})
await rpc.call('xxx', params)
await rpc.notify('xxx', params)

rpc.setReady(false); 
rpc.setReady(true);

// get referenced functions and objects
const { functions, objects } = rpc.stat();

SmartRPC

import JsonRPC, { Smartify } from '@genee/json-rpc';

const SmartRPC = Smaritfy(JsonRPC);
const rpc = new SmartRPC(data => {
    // do your sending
})

rpc.setReady(false);
rpc.setReady(true);

rpc.whenReady(() => {
    // DO SOMEHTING WHEN RPC READY
});

rpc.whenNotReady(() => {
    // DO SOMEHTING WHEN RPC NOT READY
})

rpc.receive(data); // process data you received

await rpc.Namespace1.Namespace2.Method1('hello'); // == rpc.call('Namespace1.Namespace2.Method1', ['hello'])

Readme

Keywords

none

Package Sidebar

Install

npm i @genee/json-rpc

Weekly Downloads

43

Version

1.10.4

License

MIT

Unpacked Size

104 kB

Total Files

14

Last publish

Collaborators

  • iamfat