heisenware/vrpc-js
حول
Remote objects over MQTT: call classes in other programs as if they were local - Node.js, browser, C++, Python, Arduino
الأنظمة والبنية التحتيةالنمو المقاس للنجوم
- خلال 24 ساعة
- جارٍ جمع السجل
- خلال 7 أيام
- جارٍ جمع السجل
- خلال 15 يومًا
- جارٍ جمع السجل
- خلال شهر
- جارٍ جمع السجل
تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.
README.md
الأصلVRPC for JavaScript
Call classes in other programs as if they were local. VRPC (Variadic Remote Procedure Call) makes the classes of a Node.js, C++, Python or Arduino program callable from any other program - a backend service, a browser, a device - across any network, without REST routes, schemas or WebSocket plumbing.
This package is VRPC for JavaScript: the agent that offers your Node.js or browser code, and the client that uses remote code from Node.js or the browser.
Why VRPC
- No API layer. Register a class and its functions are callable remotely: instances, static functions, promises, callbacks and errors work as they do locally.
- Events that scale. Many clients can listen to the same events; the agent calls your event function once, hands every event to every listener, greets newcomers with the current state, and cleans up when the last one leaves.
- Reaches everything. Built on MQTT: agents and clients only connect out to a broker, so code behind firewalls and NATs is reachable, and connections that break come back by themselves.
- One protocol, several languages. A browser can call a C++ agent; a Python service can listen to a Node.js agent.
Install
npm install vrpc
Node.js 18 or newer, or any current browser. VRPC is free and open source; all it needs is an MQTT broker.
Quick start
Offer a class from one program - the agent:
// agent.js
const EventEmitter = require('events')
const { VrpcAdapter, VrpcAgent } = require('vrpc')
class Sensor extends EventEmitter {
constructor (id) {
super()
this._timer = setInterval(() => this.emit('data', { id, value: Math.random() }), 1000)
}
async calibrate () {
return true
}
[Symbol.dispose] () {
clearInterval(this._timer) // released when the instance is deleted
}
}
VrpcAdapter.register(Sensor)
new VrpcAgent({ domain: 'my-domain', agent: 'sensors' })
.serve()
.then(() => console.log('Agent is serving'))
Use it from another - the client, in Node.js or a browser:
// client.js
const { VrpcClient } = require('vrpc')
async function main () {
const client = new VrpcClient({ domain: 'my-domain' })
await client.connect()
const sensor = await client.create({
agent: 'sensors',
className: 'Sensor',
instance: 'living-room',
args: ['living-room']
})
console.log('calibrated:', await sensor.calibrate())
await sensor.on('data', ({ id, value }) => console.log(id, value))
}
main()
Both connect to a public test broker by default; use a domain of your own, and your own broker for anything real. The tutorial takes it further in ten minutes.
Event functions
A function that calls a handler again and again returns a registration that tells the agent how to undo the call, and optionally how to greet a new listener:
/**
* Calls back with every reading, beginning with the current one
* @param {Function} handler
* @returns {Registration}
*/
onReading (handler) {
this._emitter.on('reading', handler)
return {
[Symbol.dispose]: () => this._emitter.off('reading', handler),
greet: greeting => greeting(this._reading)
}
}
The agent calls it once, however many clients subscribe, and releases it when the last one leaves. See Events and Writing event functions.
Documentation
- Getting started - a ten-minute tutorial
- How VRPC works, Instances, Calls, Events
- Guides: offering classes, the browser, persistence, security, production, troubleshooting
- API reference
- Protocol specification, for every VRPC implementation
- All documentation, and vrpc.io
- llms.txt - the documentation's index for AI coding assistants; every page is also served as Markdown
The VRPC family
- vrpc-hpp - C++
- vrpc-py - Python
- vrpc-arduino - Arduino and ESP32
- vrpc-react - React hooks
Contributing and security
Bug reports and small fixes are welcome; see CONTRIBUTING.md and the code of conduct. Report security issues privately, as described in SECURITY.md.
License
استكشف مشاريع مشابهة ومرتبطة
جارٍ التحميل…