vrpc 3.7.0 → 3.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +113 -37
- package/browser/vrpc.js +2 -2
- package/package.json +5 -5
- package/vrpc/VrpcAgent.js +17 -9
- package/vrpc/VrpcBrowserAgent.js +16 -8
- package/vrpc/VrpcClient.js +90 -23
- package/vrpc/VrpcPersistor.js +20 -3
package/README.md
CHANGED
|
@@ -1,50 +1,126 @@
|
|
|
1
|
-
# VRPC
|
|
1
|
+
# VRPC JavaScript / Node.js
|
|
2
2
|
|
|
3
|
-
[](https://github.com/heisenware/vrpc-js/tag)
|
|
6
|
-
[](http://github.com/heisenware/vrpc-js/issues)
|
|
7
|
-

|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
[](https://www.npmjs.com/package/vrpc)
|
|
8
5
|
|
|
9
|
-
|
|
6
|
+
**Stop writing API boilerplate.** VRPC (Variadic Remote Procedure Call) allows you to call Node.js, C++, Python, and Arduino classes across any network as if they were local objects. Perfect for microservices, IoT backends, and directly driving React frontends—without the need for REST, GraphQL, or WebSocket boilerplate.
|
|
10
7
|
|
|
11
|
-
|
|
8
|
+
This repository provides both the **Agent** (to expose your Node.js code) and the **Client** (to seamlessly control remote code from Node.js, the browser, or React/Vue applications).
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
(remote procedure calls) idea. Like RPC, it allows to directly call functions
|
|
15
|
-
written in any programming language by functions written in any other (or the
|
|
16
|
-
same) programming language. Unlike RPC, VRPC furthermore supports:
|
|
10
|
+
---
|
|
17
11
|
|
|
18
|
-
|
|
19
|
-
- remote function calls on many distributed receivers at the same time (one
|
|
20
|
-
client - multiple agents)
|
|
21
|
-
- service discovery
|
|
22
|
-
- outbound-connection-only network architecture (using MQTT technology)
|
|
23
|
-
- isolated (multi-tenant) and shared access modes to remote resources
|
|
24
|
-
- asynchronous language constructs (callbacks, promises, event-loops)
|
|
25
|
-
- OOP (classes, objects, member functions) and functional (lambda) patterns
|
|
26
|
-
- exception forwarding
|
|
12
|
+
## Why VRPC for JavaScript?
|
|
27
13
|
|
|
28
|
-
VRPC
|
|
29
|
-
|
|
14
|
+
- **Zero Boilerplate:** No Express routers, no OpenAPI schemas, and no payload parsing. Just register your ES6 class, and VRPC instantly makes its asynchronous methods remotely callable. Promises are handled natively!
|
|
15
|
+
- **Native Event Proxies:** Don't just fetch data—stream it. VRPC transparently proxies Node.js `EventEmitter` instances and standard callbacks across the network. When your backend emits an event, your React UI updates instantly.
|
|
16
|
+
- **MQTT-Powered NAT Traversal:** Built on top of robust MQTT, agents make outbound connections to your broker. No CORS headaches, no complex reverse proxies, and perfect resilience on unstable networks.
|
|
17
|
+
- **Universal Client:** The exact same client code works in Node.js microservices and in the browser. Easily build real-time dashboards that directly control distributed backend services.
|
|
30
18
|
|
|
31
|
-
|
|
32
|
-
foundation of complex digitization projects in the area of (I)IoT or
|
|
33
|
-
Cloud-Computing.
|
|
19
|
+
## Installation
|
|
34
20
|
|
|
35
|
-
|
|
21
|
+
Install VRPC via npm or yarn:
|
|
36
22
|
|
|
37
|
-
|
|
23
|
+
```bash
|
|
24
|
+
npm install vrpc
|
|
25
|
+
# or
|
|
26
|
+
yarn add vrpc
|
|
27
|
+
```
|
|
38
28
|
|
|
39
|
-
|
|
40
|
-
- [Client Example](examples/02-client/README.md)
|
|
41
|
-
- [Simple C++ Embedding Example](examples/03-native-simple/README.md)
|
|
42
|
-
- [Advanced C++ Embedding Example](examples/04-native-advanced/README.md)
|
|
29
|
+
## Quick Start
|
|
43
30
|
|
|
44
|
-
|
|
31
|
+
With VRPC, making a Node.js class remotely accessible and consuming it from a frontend requires almost zero API code.
|
|
45
32
|
|
|
46
|
-
|
|
47
|
-
- [RPC Protocol Details](docs/protocol.md)
|
|
33
|
+
### 1. Write and Expose your Backend Class (Agent)
|
|
48
34
|
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
```javascript
|
|
36
|
+
// backend.js
|
|
37
|
+
const { VrpcAdapter, VrpcAgent } = require('vrpc')
|
|
38
|
+
const EventEmitter = require('events')
|
|
39
|
+
|
|
40
|
+
// A standard ES6 Class using Promises and EventEmitters
|
|
41
|
+
class Sensor extends EventEmitter {
|
|
42
|
+
constructor(sensorId) {
|
|
43
|
+
super()
|
|
44
|
+
this.id = sensorId
|
|
45
|
+
|
|
46
|
+
// Simulate real-time data
|
|
47
|
+
setInterval(() => {
|
|
48
|
+
this.emit('data', { id: this.id, value: Math.random() })
|
|
49
|
+
}, 1000)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async calibrate() {
|
|
53
|
+
console.log(`Calibrating sensor ${this.id}...`)
|
|
54
|
+
return true
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 1. Register the class
|
|
59
|
+
VrpcAdapter.register(Sensor)
|
|
60
|
+
|
|
61
|
+
// 2. Start the Agent
|
|
62
|
+
const agent = new VrpcAgent({
|
|
63
|
+
domain: 'my_domain',
|
|
64
|
+
agent: 'sensor_backend',
|
|
65
|
+
broker: 'mqtts://broker.hivemq.com:8883'
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
agent.serve().then(() => console.log('Backend is online!'))
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 2. Control it from your Frontend / Microservice (Client)
|
|
72
|
+
|
|
73
|
+
Once your Node.js agent is running, you can interact with it transparently from any VRPC client (Browser or Node.js):
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
// frontend.js (or React component)
|
|
77
|
+
import { VrpcClient } from 'vrpc'
|
|
78
|
+
|
|
79
|
+
async function run() {
|
|
80
|
+
const client = new VrpcClient({
|
|
81
|
+
domain: 'my_domain',
|
|
82
|
+
broker: 'mqtts://broker.hivemq.com:8883'
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
await client.connect()
|
|
86
|
+
|
|
87
|
+
// Create a remote instance of your Node.js class
|
|
88
|
+
const sensor = await client.create({
|
|
89
|
+
agent: 'sensor_backend',
|
|
90
|
+
className: 'Sensor',
|
|
91
|
+
args: ['living-room-sensor']
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
// Call functions natively (Promises are automatically resolved)
|
|
95
|
+
const isCalibrated = await sensor.calibrate()
|
|
96
|
+
console.log(`Calibration successful: ${isCalibrated}`)
|
|
97
|
+
|
|
98
|
+
// Listen to remote EventEmitters across the network!
|
|
99
|
+
await sensor.on('data', reading => {
|
|
100
|
+
console.log(`New reading from ${reading.id}: ${reading.value}`)
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
run()
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## The VRPC Ecosystem
|
|
108
|
+
|
|
109
|
+
Write your performance-critical code in **C++**, your data-science scripts in **Python**, your business logic in **Node.js**, and your IoT firmware on **Arduino**. Call them all identically.
|
|
110
|
+
|
|
111
|
+
- [VRPC for C++](https://github.com/heisenware/vrpc-cpp)
|
|
112
|
+
- [VRPC for Python](https://github.com/heisenware/vrpc-py)
|
|
113
|
+
- [VRPC for Arduino / ESP32](https://github.com/heisenware/vrpc-arduino)
|
|
114
|
+
- [VRPC for React](https://github.com/heisenware/vrpc-react)
|
|
115
|
+
|
|
116
|
+
## Documentation
|
|
117
|
+
|
|
118
|
+
For detailed API references, React hooks (`react-vrpc`), advanced schema validation, and architecture overviews, please visit our official documentation at **[vrpc.io/docs](https://vrpc.io/docs)**.
|
|
119
|
+
|
|
120
|
+
## Contributing
|
|
121
|
+
|
|
122
|
+
Contributions are welcome! Whether it's reporting a bug, proposing a new feature, or submitting a pull request, we'd love your help to make VRPC even better. Please read our [Contributing Guidelines](CONTRIBUTING.md) to get started.
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
VRPC is released under the [MIT License](LICENSE).
|