vrpc 3.14.0 → 3.15.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2018 - 2022 Dr. Burkhard C. Heisen
3
+ Copyright (c) 2018 Dr. Burkhard C. Heisen
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,126 +1,149 @@
1
- # VRPC JavaScript / Node.js
1
+ # VRPC for JavaScript
2
2
 
3
3
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
4
  [![npm version](https://img.shields.io/npm/v/vrpc.svg)](https://www.npmjs.com/package/vrpc)
5
5
 
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.
7
-
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).
9
-
10
- ---
11
-
12
- ## Why VRPC for JavaScript?
13
-
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.
18
-
19
- ## Installation
20
-
21
- Install VRPC via npm or yarn:
6
+ **Call classes in other programs as if they were local.** VRPC (Variadic
7
+ Remote Procedure Call) makes the classes of a Node.js, C++, Python or
8
+ Arduino program callable from any other program - a backend service, a
9
+ browser, a device - across any network, without REST routes, schemas or
10
+ WebSocket plumbing.
11
+
12
+ This package is VRPC for JavaScript: the **agent** that offers your Node.js
13
+ or browser code, and the **client** that uses remote code from Node.js or
14
+ the browser.
15
+
16
+ ## Why VRPC
17
+
18
+ - **No API layer.** Register a class and its functions are callable
19
+ remotely: instances, static functions, promises, callbacks and errors work
20
+ as they do locally.
21
+ - **Events that scale.** Many clients can listen to the same events; the
22
+ agent calls your event function once, hands every event to every
23
+ listener, greets newcomers with the current state, and cleans up when the
24
+ last one leaves.
25
+ - **Reaches everything.** Built on MQTT: agents and clients only connect out
26
+ to a broker, so code behind firewalls and NATs is reachable, and
27
+ connections that break come back by themselves.
28
+ - **One protocol, several languages.** A browser can call a C++ agent; a
29
+ Python service can listen to a Node.js agent.
30
+
31
+ ## Install
22
32
 
23
33
  ```bash
24
34
  npm install vrpc
25
- # or
26
- yarn add vrpc
27
35
  ```
28
36
 
29
- ## Quick Start
30
-
31
- With VRPC, making a Node.js class remotely accessible and consuming it from a frontend requires almost zero API code.
37
+ ## Quick start
32
38
 
33
- ### 1. Write and Expose your Backend Class (Agent)
39
+ Offer a class from one program - the **agent**:
34
40
 
35
41
  ```javascript
36
- // backend.js
37
- const { VrpcAdapter, VrpcAgent } = require('vrpc')
42
+ // agent.js
38
43
  const EventEmitter = require('events')
44
+ const { VrpcAdapter, VrpcAgent } = require('vrpc')
39
45
 
40
- // A standard ES6 Class using Promises and EventEmitters
41
46
  class Sensor extends EventEmitter {
42
- constructor(sensorId) {
47
+ constructor (id) {
43
48
  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)
49
+ this._timer = setInterval(() => this.emit('data', { id, value: Math.random() }), 1000)
50
50
  }
51
51
 
52
- async calibrate() {
53
- console.log(`Calibrating sensor ${this.id}...`)
52
+ async calibrate () {
54
53
  return true
55
54
  }
55
+
56
+ [Symbol.dispose] () {
57
+ clearInterval(this._timer) // released when the instance is deleted
58
+ }
56
59
  }
57
60
 
58
- // 1. Register the class
59
61
  VrpcAdapter.register(Sensor)
60
62
 
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!'))
63
+ new VrpcAgent({ domain: 'my-domain', agent: 'sensors' })
64
+ .serve()
65
+ .then(() => console.log('Agent is serving'))
69
66
  ```
70
67
 
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):
68
+ Use it from another - the **client**, in Node.js or a browser:
74
69
 
75
70
  ```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
- })
71
+ // client.js
72
+ const { VrpcClient } = require('vrpc')
84
73
 
74
+ async function main () {
75
+ const client = new VrpcClient({ domain: 'my-domain' })
85
76
  await client.connect()
86
77
 
87
- // Create a remote instance of your Node.js class
88
78
  const sensor = await client.create({
89
- agent: 'sensor_backend',
79
+ agent: 'sensors',
90
80
  className: 'Sensor',
91
- args: ['living-room-sensor']
81
+ instance: 'living-room',
82
+ args: ['living-room']
92
83
  })
93
84
 
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
- })
85
+ console.log('calibrated:', await sensor.calibrate())
86
+ await sensor.on('data', ({ id, value }) => console.log(id, value))
102
87
  }
103
88
 
104
- run()
89
+ main()
105
90
  ```
106
91
 
107
- ## The VRPC Ecosystem
92
+ Both connect to a public test broker by default; use a domain of your own,
93
+ and your own broker for anything real. The
94
+ [tutorial](docs/getting-started.md) takes it further in ten minutes.
108
95
 
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.
96
+ ## Event functions
110
97
 
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)
98
+ A function that calls a handler again and again returns a **registration**
99
+ that tells the agent how to undo the call, and optionally how to greet a new
100
+ listener:
101
+
102
+ ```javascript
103
+ /**
104
+ * Calls back with every reading, beginning with the current one
105
+ * @param {Function} handler
106
+ * @returns {Registration}
107
+ */
108
+ onReading (handler) {
109
+ this._emitter.on('reading', handler)
110
+ return {
111
+ [Symbol.dispose]: () => this._emitter.off('reading', handler),
112
+ greet: greeting => greeting(this._reading)
113
+ }
114
+ }
115
+ ```
116
+
117
+ The agent calls it once, however many clients subscribe, and releases it
118
+ when the last one leaves. See [Events](docs/concepts/events.md) and
119
+ [Writing event functions](docs/guides/event-functions.md).
115
120
 
116
121
  ## Documentation
117
122
 
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)**.
123
+ - [Getting started](docs/getting-started.md) - a ten-minute tutorial
124
+ - [How VRPC works](docs/concepts/overview.md), [Instances](docs/concepts/instances.md),
125
+ [Calls](docs/concepts/calls.md), [Events](docs/concepts/events.md)
126
+ - Guides: [offering classes](docs/guides/expose-classes.md),
127
+ [the browser](docs/guides/browser-and-react.md),
128
+ [persistence](docs/guides/persistence.md),
129
+ [security](docs/guides/security.md), [production](docs/guides/production.md),
130
+ [troubleshooting](docs/guides/troubleshooting.md)
131
+ - [API reference](docs/reference/README.md)
132
+ - [Protocol specification](docs/spec/protocol.md), for every VRPC implementation
133
+ - [All documentation](docs/README.md), and [vrpc.io](https://vrpc.io)
134
+
135
+ ## The VRPC family
136
+
137
+ - [vrpc-hpp](https://github.com/heisenware/vrpc-hpp) - C++
138
+ - [vrpc-py](https://github.com/heisenware/vrpc-py) - Python
139
+ - [vrpc-arduino](https://github.com/heisenware/vrpc-arduino) - Arduino and ESP32
140
+ - [vrpc-react](https://github.com/heisenware/vrpc-react) - React hooks
119
141
 
120
- ## Contributing
142
+ ## Contributing and security
121
143
 
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.
144
+ Bug reports and small fixes are welcome; see [CONTRIBUTING.md](CONTRIBUTING.md).
145
+ Report security issues privately, as described in [SECURITY.md](SECURITY.md).
123
146
 
124
147
  ## License
125
148
 
126
- VRPC is released under the [MIT License](LICENSE).
149
+ [MIT](LICENSE)