Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
peter 3bd83611bd push 5 лет назад
src doc 5 лет назад
test test checkin docs 5 лет назад
.drone.yml push 5 лет назад
.gitignore automate documentation 5 лет назад
.npmignore fix 5 лет назад
README.md push 5 лет назад
package-lock.json test checkin docs 5 лет назад
package.json hide breadcrumbs 5 лет назад
tsconfig.json werks 5 лет назад

README.md

About

rpclibrary is a websocket on steroids!

How to install

npm i rpclibrary

Quickstart

import {Backend, Frontend} from 'rpclibrary'

const echo = (x) => x

const server = new Backend.RPCServer(20000, [{
    name: 'HelloWorldRPCGroup',
    exportRPCs: ()  => [
        echo, //named function variable
        function echof(x){ return x }, //named function
        {
            name: 'echoExplicit', //describing object
            call: async (x) => x
        }
    ]
}])

const client = new Frontend.RPCSocket(20000, 'localhost')

client.connect().then(async () => {
    const r0 = await client['HelloWorldRPCGroup'].echo('Hello')
    const r1 = await client['HelloWorldRPCGroup'].echof('World')
    const r2 = await client['HelloWorldRPCGroup'].echoExplicit('RPC!')

    console.log(r0,r1,r2) //Hello World RPC!
})

Using callbacks

rpclibrary offers a special type of call that can be used with callbacks

import {Backend, Frontend, Utils} from 'rpclibrary'

const callbacks:Function[] = []
const callbackserver = new Backend.RPCServer(20000, [{
    name: 'HelloWorldRPCGroup',
    exportRPCs: ()  => [
        function  triggerCallbacks(message){ callbacks.forEach(cb => cb(message)) },
        {
            name: 'subscribe',
            hook: async (callback) => {callbacks.push(callback); return Utils.makeSubResponse()}
        }
    ]
}])

const callbackclient = new Frontend.RPCSocket(20000, 'localhost')
callbackclient.connect().then(async () => {
    const r0 = await client['HelloWorldRPCGroup'].subscribe(console.log)
    console.log(r0)
    await client['HelloWorldRPCGroup'].triggerCallbacks("Hello!")
})

Documentation

[https://gitea.frontblock.me/fw-docs/rpclibrary]