vrpc 3.7.0 → 3.8.0

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 CHANGED
@@ -1,50 +1,126 @@
1
- # VRPC - Variadic Remote Procedure Calls
1
+ # VRPC JavaScript / Node.js
2
2
 
3
- [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/heisenware/vrpc-js/master/LICENSE)
4
- [![Semver](https://img.shields.io/badge/semver-2.0.0-blue)](https://semver.org/spec/v2.0.0.html)
5
- [![GitHub Releases](https://img.shields.io/github/tag/heisenware/vrpc-js.svg)](https://github.com/heisenware/vrpc-js/tag)
6
- [![GitHub Issues](https://img.shields.io/github/issues/heisenware/vrpc-js.svg)](http://github.com/heisenware/vrpc-js/issues)
7
- ![ci](https://github.com/heisenware/vrpc-js/actions/workflows/ci.yml/badge.svg)
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+ [![npm version](https://img.shields.io/npm/v/vrpc.svg)](https://www.npmjs.com/package/vrpc)
8
5
 
9
- ## Visit our website: [vrpc.io](https://vrpc.io)
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
- ## What is VRPC?
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
- VRPC - Variadic Remote Procedure Calls - is an enhancement of the old RPC
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
- - non-intrusive adaption of existing code, making it callable remotely
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 is available for an entire spectrum of programming technologies including
29
- embedded, data-science, and web technologies.
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
- As a robust and highly performing communication system, it can build the
32
- foundation of complex digitization projects in the area of (I)IoT or
33
- Cloud-Computing.
19
+ ## Installation
34
20
 
35
- ## This is VRPC for Javascript (Node.js and Browser)
21
+ Install VRPC via npm or yarn:
36
22
 
37
- Understand how to use it by looking at the examples:
23
+ ```bash
24
+ npm install vrpc
25
+ # or
26
+ yarn add vrpc
27
+ ```
38
28
 
39
- - [Agent Example](examples/01-agent/README.md)
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
- Get all the details by reading the documentation:
31
+ With VRPC, making a Node.js class remotely accessible and consuming it from a frontend requires almost zero API code.
45
32
 
46
- - [API Reference](docs/api.md)
47
- - [RPC Protocol Details](docs/protocol.md)
33
+ ### 1. Write and Expose your Backend Class (Agent)
48
34
 
49
- > This open-source project is professionally managed and supported by
50
- > [Heisenware GmbH](https://heisenware.com).
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).