vrpc 3.0.0-alpha.2 → 3.0.2
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/CHANGELOG.md +60 -0
- package/LICENSE +1 -1
- package/README.md +12 -15
- package/browser/vrpc.js +1 -1
- package/package.json +8 -5
- package/vrpc/VrpcAdapter.js +229 -171
- package/vrpc/VrpcAgent.js +22 -22
- package/vrpc/VrpcClient.js +305 -289
- package/vrpc/VrpcNative.js +25 -2
- package/vrpc/adapter.hpp +4 -2
- package/vrpc/addon.cpp +1 -1
- package/vrpc/vrpc-agent-js +1 -1
package/vrpc/VrpcAgent.js
CHANGED
|
@@ -48,7 +48,7 @@ class VrpcAgent extends EventEmitter {
|
|
|
48
48
|
})
|
|
49
49
|
parser.add_argument('-d', '--domain', {
|
|
50
50
|
help: 'Domain name',
|
|
51
|
-
default: domain || '
|
|
51
|
+
default: domain || 'vrpc'
|
|
52
52
|
})
|
|
53
53
|
parser.add_argument('-t', '--token', {
|
|
54
54
|
help: 'access token',
|
|
@@ -95,7 +95,7 @@ class VrpcAgent extends EventEmitter {
|
|
|
95
95
|
* @param {String} [obj.username] MQTT username (if no token is used)
|
|
96
96
|
* @param {String} [obj.password] MQTT password (if no token is provided)
|
|
97
97
|
* @param {String} [obj.token] Access token as generated by: https://app.vrpc.io (only optional when using default domain and broker)
|
|
98
|
-
* @param {String} [obj.domain='
|
|
98
|
+
* @param {String} [obj.domain='vrpc'] The domain under which the agent-provided code is reachable
|
|
99
99
|
* @param {String} [obj.agent='<user>-<pathId>@<hostname>-<platform>-js'] This agent's name
|
|
100
100
|
* @param {String} [obj.broker='mqtts://vrpc.io:8883'] Broker url in form: `<scheme>://<host>:<port>`
|
|
101
101
|
* @param {Object} [obj.log=console] Log object (must support debug, info, warn, and error level)
|
|
@@ -104,7 +104,7 @@ class VrpcAgent extends EventEmitter {
|
|
|
104
104
|
*
|
|
105
105
|
* @example
|
|
106
106
|
* const agent = new Agent({
|
|
107
|
-
* domain: '
|
|
107
|
+
* domain: 'vrpc'
|
|
108
108
|
* agent: 'myAgent'
|
|
109
109
|
* })
|
|
110
110
|
*/
|
|
@@ -112,7 +112,7 @@ class VrpcAgent extends EventEmitter {
|
|
|
112
112
|
username,
|
|
113
113
|
password,
|
|
114
114
|
token,
|
|
115
|
-
domain = '
|
|
115
|
+
domain = 'vrpc',
|
|
116
116
|
agent = VrpcAgent._generateAgentName(),
|
|
117
117
|
broker = 'mqtts://vrpc.io:8883',
|
|
118
118
|
log = 'console',
|
|
@@ -173,7 +173,6 @@ class VrpcAgent extends EventEmitter {
|
|
|
173
173
|
let username = this._username
|
|
174
174
|
let password = this._password
|
|
175
175
|
if (this._token) {
|
|
176
|
-
username = '__token__'
|
|
177
176
|
password = this._token
|
|
178
177
|
}
|
|
179
178
|
this._options = {
|
|
@@ -346,23 +345,23 @@ class VrpcAgent extends EventEmitter {
|
|
|
346
345
|
}
|
|
347
346
|
|
|
348
347
|
_getClasses () {
|
|
349
|
-
return VrpcAdapter.
|
|
348
|
+
return VrpcAdapter._getClassesArray()
|
|
350
349
|
}
|
|
351
350
|
|
|
352
351
|
_getInstances (className) {
|
|
353
|
-
return VrpcAdapter.
|
|
352
|
+
return VrpcAdapter._getInstancesArray(className)
|
|
354
353
|
}
|
|
355
354
|
|
|
356
355
|
_getMemberFunctions (className) {
|
|
357
|
-
return VrpcAdapter.
|
|
356
|
+
return VrpcAdapter._getMemberFunctionsArray(className)
|
|
358
357
|
}
|
|
359
358
|
|
|
360
359
|
_getStaticFunctions (className) {
|
|
361
|
-
return VrpcAdapter.
|
|
360
|
+
return VrpcAdapter._getStaticFunctionsArray(className)
|
|
362
361
|
}
|
|
363
362
|
|
|
364
363
|
_getMetaData (className) {
|
|
365
|
-
return VrpcAdapter.
|
|
364
|
+
return VrpcAdapter._getMetaData(className)
|
|
366
365
|
}
|
|
367
366
|
|
|
368
367
|
async _ensureConnected () {
|
|
@@ -376,14 +375,18 @@ class VrpcAgent extends EventEmitter {
|
|
|
376
375
|
}
|
|
377
376
|
|
|
378
377
|
_handleVrpcCallback (json) {
|
|
379
|
-
const { s } = json
|
|
378
|
+
const { s, i, r, e, a } = json
|
|
379
|
+
const topic = i.startsWith('__e__') ? i.slice(5) : s
|
|
380
380
|
try {
|
|
381
|
-
this._log.debug(`Forwarding callback to: ${
|
|
382
|
-
this._mqttPublish(
|
|
381
|
+
this._log.debug(`Forwarding callback to: ${topic} with payload:`, json)
|
|
382
|
+
this._mqttPublish(
|
|
383
|
+
topic,
|
|
384
|
+
VrpcAgent._stringifySafely({ a, r, e, i, v: VRPC_PROTOCOL_VERSION })
|
|
385
|
+
)
|
|
383
386
|
} catch (err) {
|
|
384
387
|
this._log.warn(
|
|
385
388
|
err,
|
|
386
|
-
`Problem publishing vrpc callback to ${
|
|
389
|
+
`Problem publishing vrpc callback to ${topic} because of: ${err.message}`
|
|
387
390
|
)
|
|
388
391
|
}
|
|
389
392
|
}
|
|
@@ -549,7 +552,9 @@ class VrpcAgent extends EventEmitter {
|
|
|
549
552
|
break
|
|
550
553
|
}
|
|
551
554
|
}
|
|
552
|
-
|
|
555
|
+
const { a, r, e, i, v } = json
|
|
556
|
+
const res = e ? { a, r, e, i, v } : { a, r, i, v }
|
|
557
|
+
this._mqttPublish(json.s, VrpcAgent._stringifySafely(res))
|
|
553
558
|
} catch (err) {
|
|
554
559
|
this._log.error(
|
|
555
560
|
err,
|
|
@@ -562,19 +567,17 @@ class VrpcAgent extends EventEmitter {
|
|
|
562
567
|
// Client went offline
|
|
563
568
|
const clientId = topic.slice(0, -15) // /__clientInfo__ = 15
|
|
564
569
|
if (json.status === 'offline') {
|
|
570
|
+
VrpcAdapter._unregisterClient(clientId)
|
|
565
571
|
const entry = this._isolatedInstances.get(clientId)
|
|
566
572
|
if (entry) {
|
|
567
|
-
// anonymous
|
|
568
573
|
entry.forEach(instanceId => {
|
|
569
574
|
const json = { f: '__delete__', a: [instanceId], r: null }
|
|
570
|
-
// TODO Do not mutate!
|
|
571
575
|
VrpcAdapter._call(json)
|
|
572
576
|
if (json.r) {
|
|
573
577
|
this._log.debug(`Auto-deleted isolated instance: ${instanceId}`)
|
|
574
578
|
}
|
|
575
579
|
})
|
|
576
580
|
}
|
|
577
|
-
VrpcAdapter._unregisterEventListeners(clientId)
|
|
578
581
|
this._mqttUnsubscribe(`${clientId}/__clientInfo__`)
|
|
579
582
|
this.emit('clientGone', clientId)
|
|
580
583
|
}
|
|
@@ -620,7 +623,6 @@ class VrpcAgent extends EventEmitter {
|
|
|
620
623
|
_unregisterInstance (instanceId, clientId) {
|
|
621
624
|
const entryIsolated = this._isolatedInstances.get(clientId)
|
|
622
625
|
if (entryIsolated && entryIsolated.has(instanceId)) {
|
|
623
|
-
VrpcAdapter._unregisterEventListenersOfInstance(instanceId)
|
|
624
626
|
entryIsolated.delete(instanceId)
|
|
625
627
|
if (entryIsolated.length === 0) {
|
|
626
628
|
this._isolatedInstances.delete(clientId)
|
|
@@ -633,7 +635,6 @@ class VrpcAgent extends EventEmitter {
|
|
|
633
635
|
this._sharedInstances.forEach(async v => {
|
|
634
636
|
if (v.has(instanceId)) {
|
|
635
637
|
found = true
|
|
636
|
-
VrpcAdapter._unregisterEventListenersOfInstance(instanceId)
|
|
637
638
|
v.delete(instanceId)
|
|
638
639
|
if (v.length === 0) {
|
|
639
640
|
this._sharedInstances.delete(clientId)
|
|
@@ -748,8 +749,7 @@ class VrpcAgent extends EventEmitter {
|
|
|
748
749
|
/**
|
|
749
750
|
* Event 'clientGone'
|
|
750
751
|
*
|
|
751
|
-
* Emitted when a VRPC client exited
|
|
752
|
-
* an anonymous or named instance).
|
|
752
|
+
* Emitted when a tracked VRPC client exited.
|
|
753
753
|
*
|
|
754
754
|
* @event VrpcAgent#clientGone
|
|
755
755
|
* @type {String} clientId
|