vrpc 2.6.0 → 3.0.0-alpha.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/CHANGELOG.md +29 -0
- package/README.md +33 -56
- package/binding.gyp.no-auto +4 -26
- package/browser/vrpc.js +1 -1
- package/index.js +2 -2
- package/package.json +11 -15
- package/vrpc/VrpcAdapter.js +95 -173
- package/vrpc/VrpcAgent.js +77 -77
- package/vrpc/{VrpcRemote.js → VrpcClient.js} +98 -152
- package/vrpc/VrpcNative.js +307 -0
- package/vrpc/{vrpc.hpp → adapter.hpp} +1000 -1114
- package/vrpc/addon.cpp +5 -5
- package/vrpc/json.hpp +1769 -870
- package/vrpc/vrpc-agent-js +4 -4
- package/README.rst +0 -18
- package/third_party/include/catch.hpp +0 -12749
- package/third_party/install.sh +0 -22
- package/vrpc/VrpcLocal.js +0 -269
- package/vrpc/VrpcLocal.py +0 -171
- package/vrpc/__init__.py +0 -1
- package/vrpc/module.cpp +0 -183
|
@@ -10,9 +10,9 @@ __\/\\\_______\/\\\__/\\\///////\\\___\/\\\/////////\\\____/\\\////////__
|
|
|
10
10
|
________\///________\///________\///__\///___________________\/////////__
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
Non-intrusively
|
|
13
|
+
Non-intrusively adapts code and provides access in form of asynchronous remote
|
|
14
14
|
procedure calls (RPC).
|
|
15
|
-
Author: Dr. Burkhard C. Heisen (https://github.com/
|
|
15
|
+
Author: Dr. Burkhard C. Heisen (https://github.com/heisenware/vrpc)
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
|
@@ -39,16 +39,19 @@ SOFTWARE.
|
|
|
39
39
|
|
|
40
40
|
const os = require('os')
|
|
41
41
|
const crypto = require('crypto')
|
|
42
|
+
const { nanoid } = require('nanoid')
|
|
42
43
|
const mqtt = require('mqtt')
|
|
43
44
|
const EventEmitter = require('events')
|
|
44
45
|
|
|
46
|
+
const VRPC_PROTOCOL_VERSION = 3
|
|
47
|
+
|
|
45
48
|
/**
|
|
46
49
|
* Client capable of creating proxy objects and remotely calling
|
|
47
50
|
* functions as provided through one or more (distributed) agents.
|
|
48
51
|
*
|
|
49
52
|
* @extends EventEmitter
|
|
50
53
|
*/
|
|
51
|
-
class
|
|
54
|
+
class VrpcClient extends EventEmitter {
|
|
52
55
|
/**
|
|
53
56
|
* Constructs a remote client, able to communicate with any distributed agents
|
|
54
57
|
*
|
|
@@ -66,7 +69,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
66
69
|
* @param {Object} [options.log=console] Log object (must support debug, info, warn, and error level)
|
|
67
70
|
* @param {Boolean} [options.bestEffort=false] If true, message will be sent with best effort, i.e. no caching if offline
|
|
68
71
|
* @example
|
|
69
|
-
* const client = new
|
|
72
|
+
* const client = new VrpcClient({
|
|
70
73
|
* domain: 'public.vrpc',
|
|
71
74
|
* broker: 'mqtt://vrpc.io'
|
|
72
75
|
* })
|
|
@@ -105,7 +108,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
105
108
|
this._timeout = timeout
|
|
106
109
|
this._qos = this._qos = bestEffort ? 0 : 1
|
|
107
110
|
|
|
108
|
-
this._instance =
|
|
111
|
+
this._instance = nanoid(8)
|
|
109
112
|
this._mqttClientId = this._createMqttClientId()
|
|
110
113
|
this._vrpcClientId = this._createVrpcClientId()
|
|
111
114
|
this._agents = {}
|
|
@@ -123,6 +126,15 @@ class VrpcRemote extends EventEmitter {
|
|
|
123
126
|
}
|
|
124
127
|
}
|
|
125
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Provides a unique id for this client instance
|
|
131
|
+
*
|
|
132
|
+
* @returns {String} clientId
|
|
133
|
+
*/
|
|
134
|
+
getClientId () {
|
|
135
|
+
return this._vrpcClientId
|
|
136
|
+
}
|
|
137
|
+
|
|
126
138
|
/**
|
|
127
139
|
* Actually connects to the MQTT broker.
|
|
128
140
|
*
|
|
@@ -232,8 +244,8 @@ class VrpcRemote extends EventEmitter {
|
|
|
232
244
|
})
|
|
233
245
|
// RPC message
|
|
234
246
|
} else {
|
|
235
|
-
const {
|
|
236
|
-
this._eventEmitter.emit(
|
|
247
|
+
const { i, a, e, r } = JSON.parse(message.toString())
|
|
248
|
+
this._eventEmitter.emit(i, { a, e, r })
|
|
237
249
|
}
|
|
238
250
|
})
|
|
239
251
|
await new Promise((resolve, reject) => {
|
|
@@ -247,13 +259,6 @@ class VrpcRemote extends EventEmitter {
|
|
|
247
259
|
})
|
|
248
260
|
}
|
|
249
261
|
|
|
250
|
-
async connected () {
|
|
251
|
-
this._indicateDeprecation(
|
|
252
|
-
'VrpcRemote.connected(): This API usage is deprecated, use `connect()` instead.'
|
|
253
|
-
)
|
|
254
|
-
return this.connect()
|
|
255
|
-
}
|
|
256
|
-
|
|
257
262
|
/**
|
|
258
263
|
* Creates a new remote instance and provides a proxy to it.
|
|
259
264
|
*
|
|
@@ -302,23 +307,20 @@ class VrpcRemote extends EventEmitter {
|
|
|
302
307
|
*/
|
|
303
308
|
async create ({
|
|
304
309
|
className,
|
|
305
|
-
instance,
|
|
310
|
+
instance = nanoid(8),
|
|
306
311
|
args = [],
|
|
307
312
|
agent = this._agent,
|
|
308
|
-
cacheProxy = false
|
|
313
|
+
cacheProxy = false,
|
|
314
|
+
isIsolated = false
|
|
309
315
|
} = {}) {
|
|
310
316
|
if (agent === '*') throw new Error('Agent must be specified')
|
|
311
|
-
const data = instance ? { _1: instance } : {}
|
|
312
|
-
const offset = instance ? 2 : 1
|
|
313
|
-
args.forEach((value, index) => {
|
|
314
|
-
data[`_${index + offset}`] = value
|
|
315
|
-
})
|
|
316
317
|
const json = {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
318
|
+
c: className,
|
|
319
|
+
f: isIsolated ? '__createIsolated__' : '__createShared__',
|
|
320
|
+
i: `${this._instance}-${this._invokeId++ % Number.MAX_SAFE_INTEGER}`,
|
|
321
|
+
s: `${this._domain}/${os.hostname()}/${this._instance}`,
|
|
322
|
+
a: [instance, ...args],
|
|
323
|
+
v: VRPC_PROTOCOL_VERSION
|
|
322
324
|
}
|
|
323
325
|
const proxy = await this._getProxy(agent, className, json)
|
|
324
326
|
if (instance && cacheProxy) this._proxies[instance] = proxy
|
|
@@ -351,7 +353,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
351
353
|
} else {
|
|
352
354
|
// deprecate this
|
|
353
355
|
this._indicateDeprecation(
|
|
354
|
-
'
|
|
356
|
+
'VrpcClient.getInstance(): ' +
|
|
355
357
|
'Using an object as single argument is deprecated, ' +
|
|
356
358
|
'use "getInstance(instance, options)" instead.'
|
|
357
359
|
)
|
|
@@ -387,7 +389,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
387
389
|
} else {
|
|
388
390
|
// deprecate this
|
|
389
391
|
this._indicateDeprecation(
|
|
390
|
-
'
|
|
392
|
+
'VrpcClient.delete(): ' +
|
|
391
393
|
'Using an object as single argument is deprecated, ' +
|
|
392
394
|
'use "delete(instance, options)" instead.'
|
|
393
395
|
)
|
|
@@ -395,11 +397,12 @@ class VrpcRemote extends EventEmitter {
|
|
|
395
397
|
}
|
|
396
398
|
const { agent, className, instance: instanceString } = instanceData
|
|
397
399
|
const json = {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
400
|
+
c: className,
|
|
401
|
+
f: '__delete__',
|
|
402
|
+
i: `${this._instance}-${this._invokeId++ % Number.MAX_SAFE_INTEGER}`,
|
|
403
|
+
s: `${this._domain}/${os.hostname()}/${this._instance}`,
|
|
404
|
+
a: [instanceString],
|
|
405
|
+
v: VRPC_PROTOCOL_VERSION
|
|
403
406
|
}
|
|
404
407
|
const topic = `${this._domain}/${agent}/${className}/__static__/__delete__`
|
|
405
408
|
this._mqttPublish(topic, JSON.stringify(json))
|
|
@@ -426,11 +429,12 @@ class VrpcRemote extends EventEmitter {
|
|
|
426
429
|
const wrapped = this._wrapArguments(className, functionName, ...args)
|
|
427
430
|
if (!wrapped) return // Skipping remote call -> handled locally
|
|
428
431
|
const json = {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
432
|
+
c: className,
|
|
433
|
+
f: functionName,
|
|
434
|
+
i: `${this._instance}-${this._invokeId++ % Number.MAX_SAFE_INTEGER}`,
|
|
435
|
+
s: this._vrpcClientId,
|
|
436
|
+
a: wrapped,
|
|
437
|
+
v: VRPC_PROTOCOL_VERSION
|
|
434
438
|
}
|
|
435
439
|
const topic = `${this._domain}/${agent}/${className}/__static__/${functionName}`
|
|
436
440
|
await this._waitUntilClassIsOnline(agent, className)
|
|
@@ -465,10 +469,12 @@ class VrpcRemote extends EventEmitter {
|
|
|
465
469
|
agent = this._agent
|
|
466
470
|
} = {}) {
|
|
467
471
|
const json = {
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
+
c: className,
|
|
473
|
+
f: functionName,
|
|
474
|
+
i: `${this._instance}-${this._invokeId++ % Number.MAX_SAFE_INTEGER}`,
|
|
475
|
+
s: this._vrpcClientId,
|
|
476
|
+
a: [],
|
|
477
|
+
v: VRPC_PROTOCOL_VERSION
|
|
472
478
|
}
|
|
473
479
|
if (agent === '*') {
|
|
474
480
|
const result = []
|
|
@@ -481,7 +487,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
481
487
|
...args
|
|
482
488
|
)
|
|
483
489
|
if (!wrapped) continue // using cache
|
|
484
|
-
json.
|
|
490
|
+
json.a = [functionName, ...wrapped]
|
|
485
491
|
await this._waitUntilClassIsOnline(x, className)
|
|
486
492
|
this._mqttPublish(topic, JSON.stringify(json))
|
|
487
493
|
const tmp = await this._handleAgentAnswer(json)
|
|
@@ -496,38 +502,12 @@ class VrpcRemote extends EventEmitter {
|
|
|
496
502
|
...args
|
|
497
503
|
)
|
|
498
504
|
if (!wrapped) return // using cache
|
|
499
|
-
json.
|
|
505
|
+
json.a = [functionName, ...wrapped]
|
|
500
506
|
await this._waitUntilClassIsOnline(agent, className)
|
|
501
507
|
this._mqttPublish(topic, JSON.stringify(json))
|
|
502
508
|
return this._handleAgentAnswer(json)
|
|
503
509
|
}
|
|
504
510
|
|
|
505
|
-
/**
|
|
506
|
-
* Retrieves all agents, instances, classes, member and static
|
|
507
|
-
* functions potentially available for remote control.
|
|
508
|
-
* @deprecated
|
|
509
|
-
* @returns {Object} SystemInformation
|
|
510
|
-
* ```ts
|
|
511
|
-
* type SystemInformation = {
|
|
512
|
-
* [domain].agents[agent].status: string, // 'offline' or 'online'
|
|
513
|
-
* [domain].agents[agent].hostname: string,
|
|
514
|
-
* [domain].agents[agent].version: string,
|
|
515
|
-
* [domain].agents[agent].classes[className].instances: string[],
|
|
516
|
-
* [domain].agents[agent].classes[className].memberFunctions: string[],
|
|
517
|
-
* [domain].agents[agent].classes[className].staticFunctions: string[],
|
|
518
|
-
* [domain].agents[agent].classes[className].meta?: MetaData
|
|
519
|
-
* }
|
|
520
|
-
* ```
|
|
521
|
-
*/
|
|
522
|
-
getAvailabilities () {
|
|
523
|
-
this._indicateDeprecation(
|
|
524
|
-
'VrpcRemote.getAvailabilities(): ' +
|
|
525
|
-
'This function is deprecated and will be removed soon, ' +
|
|
526
|
-
'use `getSystemInformation()` instead.'
|
|
527
|
-
)
|
|
528
|
-
return { [this._domain]: { agents: this._agents } }
|
|
529
|
-
}
|
|
530
|
-
|
|
531
511
|
/**
|
|
532
512
|
* Retrieves all information about the currently available components.
|
|
533
513
|
*
|
|
@@ -548,21 +528,6 @@ class VrpcRemote extends EventEmitter {
|
|
|
548
528
|
return this._agents
|
|
549
529
|
}
|
|
550
530
|
|
|
551
|
-
/**
|
|
552
|
-
* Retrieves all domains on which agents can be remote controlled
|
|
553
|
-
*
|
|
554
|
-
* @deprecated
|
|
555
|
-
* @returns {Array} Array of domain names
|
|
556
|
-
*/
|
|
557
|
-
getAvailableDomains () {
|
|
558
|
-
this._indicateDeprecation(
|
|
559
|
-
'VrpcRemote.getAvailableDomains(): ' +
|
|
560
|
-
'this function will be removed in the next major release, as the client' +
|
|
561
|
-
'works with a single domain anyways'
|
|
562
|
-
)
|
|
563
|
-
return [this._domain]
|
|
564
|
-
}
|
|
565
|
-
|
|
566
531
|
/**
|
|
567
532
|
* Retrieves all available agents.
|
|
568
533
|
*
|
|
@@ -575,7 +540,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
575
540
|
// `options = {}` was `domain = this._domain` before
|
|
576
541
|
if (typeof options === 'string') {
|
|
577
542
|
this._indicateDeprecation(
|
|
578
|
-
'
|
|
543
|
+
'VrpcClient.getAvailableAgents(): ' +
|
|
579
544
|
'Providing a domain here has no effect and will be an error in future.'
|
|
580
545
|
)
|
|
581
546
|
options = { mustBeOnline: true }
|
|
@@ -613,7 +578,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
613
578
|
// `options = {}` was `agent = this._agent` before
|
|
614
579
|
if (typeof options === 'string') {
|
|
615
580
|
this._indicateDeprecation(
|
|
616
|
-
'
|
|
581
|
+
'VrpcClient.getAvailableClasses(): ' +
|
|
617
582
|
'setting the agent as string argument is deprecated.`' +
|
|
618
583
|
'Use `{ agent: <myAgent> }` instead.'
|
|
619
584
|
)
|
|
@@ -625,7 +590,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
625
590
|
// was `domain = this._domain` before
|
|
626
591
|
if (domain) {
|
|
627
592
|
this._indicateDeprecation(
|
|
628
|
-
'
|
|
593
|
+
'VrpcClient.getAvailableClasses(): ' +
|
|
629
594
|
'Providing a domain here has no effect and will be an error in future.'
|
|
630
595
|
)
|
|
631
596
|
}
|
|
@@ -658,7 +623,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
658
623
|
// `options = {}` was `agent = this._agent` before
|
|
659
624
|
if (typeof options === 'string') {
|
|
660
625
|
this._indicateDeprecation(
|
|
661
|
-
'
|
|
626
|
+
'VrpcClient.getAvailableInstances(): ' +
|
|
662
627
|
'Setting the agent as string argument is deprecated.`' +
|
|
663
628
|
'Use `{ agent: <myAgent> }` instead.'
|
|
664
629
|
)
|
|
@@ -670,7 +635,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
670
635
|
// was `domain = this._domain` before
|
|
671
636
|
if (domain) {
|
|
672
637
|
this._indicateDeprecation(
|
|
673
|
-
'
|
|
638
|
+
'VrpcClient.getAvailableInstances(): ' +
|
|
674
639
|
'Providing a domain here has no effect and will be an error in future.'
|
|
675
640
|
)
|
|
676
641
|
}
|
|
@@ -703,7 +668,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
703
668
|
// `options = {}` was `agent = this._agent` before
|
|
704
669
|
if (typeof options === 'string') {
|
|
705
670
|
this._indicateDeprecation(
|
|
706
|
-
'
|
|
671
|
+
'VrpcClient.getAvailableMemberFunctions(): ' +
|
|
707
672
|
'Setting the agent as string argument is deprecated.`' +
|
|
708
673
|
'Use `{ agent: <myAgent> }` instead.'
|
|
709
674
|
)
|
|
@@ -715,7 +680,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
715
680
|
// was `domain = this._domain` before
|
|
716
681
|
if (domain) {
|
|
717
682
|
this._indicateDeprecation(
|
|
718
|
-
'
|
|
683
|
+
'VrpcClient.getAvailableMemberFunctions(): ' +
|
|
719
684
|
'Providing a domain here has no effect and will be an error in future.'
|
|
720
685
|
)
|
|
721
686
|
}
|
|
@@ -750,7 +715,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
750
715
|
// `options = {}` was `agent = this._agent` before
|
|
751
716
|
if (typeof options === 'string') {
|
|
752
717
|
this._indicateDeprecation(
|
|
753
|
-
'
|
|
718
|
+
'VrpcClient.getAvailableStaticFunctions(): ' +
|
|
754
719
|
'Setting the agent as string argument is deprecated.`' +
|
|
755
720
|
'Use `{ agent: <myAgent> }` instead.'
|
|
756
721
|
)
|
|
@@ -762,7 +727,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
762
727
|
// was `domain = this._domain` before
|
|
763
728
|
if (domain) {
|
|
764
729
|
this._indicateDeprecation(
|
|
765
|
-
'
|
|
730
|
+
'VrpcClient.getAvailableStaticFunctions(): ' +
|
|
766
731
|
'Providing a domain here has no effect and will be an error in future.'
|
|
767
732
|
)
|
|
768
733
|
}
|
|
@@ -824,7 +789,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
824
789
|
async end () {
|
|
825
790
|
this._mqttPublish(
|
|
826
791
|
`${this._vrpcClientId}/__clientInfo__`,
|
|
827
|
-
JSON.stringify({ status: 'offline' })
|
|
792
|
+
JSON.stringify({ status: 'offline', v: VRPC_PROTOCOL_VERSION })
|
|
828
793
|
)
|
|
829
794
|
return new Promise(resolve => this._client.end(false, {}, resolve))
|
|
830
795
|
}
|
|
@@ -847,7 +812,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
847
812
|
.digest('hex')
|
|
848
813
|
.substr(0, 13)
|
|
849
814
|
// FIXME (3.x): use vrpcp -> vrpcc
|
|
850
|
-
return `
|
|
815
|
+
return `vc${this._instance}${md5}` // 2 + 8 + 13 = 23 (max clientId)
|
|
851
816
|
}
|
|
852
817
|
|
|
853
818
|
_createVrpcClientId () {
|
|
@@ -904,22 +869,22 @@ class VrpcRemote extends EventEmitter {
|
|
|
904
869
|
}
|
|
905
870
|
|
|
906
871
|
async _getProxy (agent, className, json) {
|
|
907
|
-
const {
|
|
908
|
-
const topic = `${this._domain}/${agent}/${className}/__static__/${
|
|
872
|
+
const { f, i } = json
|
|
873
|
+
const topic = `${this._domain}/${agent}/${className}/__static__/${f}`
|
|
909
874
|
await this._waitUntilClassIsOnline(agent, className)
|
|
910
875
|
this._mqttPublish(topic, JSON.stringify(json))
|
|
911
876
|
return new Promise((resolve, reject) => {
|
|
912
877
|
const msg = `Proxy creation for class "${className}" on agent "${agent}" and domain "${this._domain}" timed out (> ${this._timeout} ms)`
|
|
913
878
|
const timer = setTimeout(() => {
|
|
914
|
-
this._eventEmitter.removeAllListeners(
|
|
879
|
+
this._eventEmitter.removeAllListeners(i)
|
|
915
880
|
reject(new Error(msg))
|
|
916
881
|
}, this._timeout)
|
|
917
|
-
this._eventEmitter.once(
|
|
882
|
+
this._eventEmitter.once(i, ({ e, r }) => {
|
|
918
883
|
clearTimeout(timer)
|
|
919
|
-
if (
|
|
920
|
-
reject(new Error(
|
|
884
|
+
if (e) {
|
|
885
|
+
reject(new Error(e))
|
|
921
886
|
} else {
|
|
922
|
-
const proxy = this._createProxy(agent, className,
|
|
887
|
+
const proxy = this._createProxy(agent, className, r)
|
|
923
888
|
resolve(proxy)
|
|
924
889
|
}
|
|
925
890
|
})
|
|
@@ -961,8 +926,9 @@ class VrpcRemote extends EventEmitter {
|
|
|
961
926
|
const targetTopic = `${this._domain}/${agent}/${className}/${instance}`
|
|
962
927
|
const proxyId = `${this._instance}-${this._proxyId++}`
|
|
963
928
|
const proxy = {
|
|
964
|
-
|
|
965
|
-
|
|
929
|
+
vrpcClientId: this._vrpcClientId,
|
|
930
|
+
vrpcInstanceId: instance,
|
|
931
|
+
vrpcProxyId: proxyId
|
|
966
932
|
}
|
|
967
933
|
let functions = this._agents[agent].classes[className].memberFunctions
|
|
968
934
|
// Strip off argument signature
|
|
@@ -980,12 +946,12 @@ class VrpcRemote extends EventEmitter {
|
|
|
980
946
|
if (!wrapped) return // Skipping remote call -> handled locally
|
|
981
947
|
try {
|
|
982
948
|
const json = {
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
949
|
+
c: instance,
|
|
950
|
+
f: name,
|
|
951
|
+
i: `${this._instance}-${this._invokeId++ % Number.MAX_SAFE_INTEGER}`,
|
|
952
|
+
s: this._vrpcClientId,
|
|
953
|
+
a: wrapped,
|
|
954
|
+
v: VRPC_PROTOCOL_VERSION
|
|
989
955
|
}
|
|
990
956
|
this._mqttPublish(`${targetTopic}/${name}`, JSON.stringify(json))
|
|
991
957
|
return this._handleAgentAnswer(json)
|
|
@@ -999,14 +965,14 @@ class VrpcRemote extends EventEmitter {
|
|
|
999
965
|
return proxy
|
|
1000
966
|
}
|
|
1001
967
|
|
|
1002
|
-
async _handleAgentAnswer ({
|
|
968
|
+
async _handleAgentAnswer ({ i, c, f }) {
|
|
1003
969
|
return new Promise((resolve, reject) => {
|
|
1004
|
-
const msg = `Function call "${
|
|
970
|
+
const msg = `Function call "${c}::${f}()" timed out (> ${this._timeout} ms)`
|
|
1005
971
|
const timer = setTimeout(() => {
|
|
1006
|
-
this._eventEmitter.removeAllListeners(
|
|
972
|
+
this._eventEmitter.removeAllListeners(i)
|
|
1007
973
|
reject(new Error(msg))
|
|
1008
974
|
}, this._timeout)
|
|
1009
|
-
this._eventEmitter.once(
|
|
975
|
+
this._eventEmitter.once(i, data => {
|
|
1010
976
|
clearTimeout(timer)
|
|
1011
977
|
if (data.e) {
|
|
1012
978
|
reject(new Error(data.e))
|
|
@@ -1074,24 +1040,16 @@ class VrpcRemote extends EventEmitter {
|
|
|
1074
1040
|
const id = `__f__${remoteId}-${functionName}-${i}-${this._invokeId++ %
|
|
1075
1041
|
Number.MAX_SAFE_INTEGER}`
|
|
1076
1042
|
wrapped.push(id)
|
|
1077
|
-
this._eventEmitter.once(id,
|
|
1078
|
-
|
|
1079
|
-
.sort()
|
|
1080
|
-
.filter(x => x[0] === '_')
|
|
1081
|
-
.map(x => data[x])
|
|
1082
|
-
x.apply(null, args) // This is the actual function call
|
|
1043
|
+
this._eventEmitter.once(id, ({ a }) => {
|
|
1044
|
+
x.apply(null, a) // This is the actual function call
|
|
1083
1045
|
})
|
|
1084
1046
|
}
|
|
1085
1047
|
} else if (this._isEmitter(x)) {
|
|
1086
1048
|
const { emitter, event } = x
|
|
1087
1049
|
const id = `__f__${remoteId}-${functionName}-${i}-${event}`
|
|
1088
1050
|
wrapped.push(id)
|
|
1089
|
-
this._eventEmitter.on(id,
|
|
1090
|
-
|
|
1091
|
-
.sort()
|
|
1092
|
-
.filter(x => x[0] === '_')
|
|
1093
|
-
.map(x => data[x])
|
|
1094
|
-
emitter.emit(event, ...args)
|
|
1051
|
+
this._eventEmitter.on(id, ({ a }) => {
|
|
1052
|
+
emitter.emit(event, ...a)
|
|
1095
1053
|
})
|
|
1096
1054
|
} else {
|
|
1097
1055
|
wrapped.push(x)
|
|
@@ -1110,12 +1068,8 @@ class VrpcRemote extends EventEmitter {
|
|
|
1110
1068
|
const emitter = new EventEmitter()
|
|
1111
1069
|
emitter.on(id, callback)
|
|
1112
1070
|
this._cachedSubscriptions.set(id, emitter)
|
|
1113
|
-
this._eventEmitter.on(id,
|
|
1114
|
-
|
|
1115
|
-
.sort()
|
|
1116
|
-
.filter(x => x[0] === '_')
|
|
1117
|
-
.map(x => data[x])
|
|
1118
|
-
emitter.emit(id, ...args)
|
|
1071
|
+
this._eventEmitter.on(id, ({ a }) => {
|
|
1072
|
+
emitter.emit(id, ...a)
|
|
1119
1073
|
})
|
|
1120
1074
|
return id
|
|
1121
1075
|
}
|
|
@@ -1194,14 +1148,6 @@ class VrpcRemote extends EventEmitter {
|
|
|
1194
1148
|
this._log.warn('DEPRECATED ', msg)
|
|
1195
1149
|
}
|
|
1196
1150
|
}
|
|
1197
|
-
|
|
1198
|
-
static _argsArrayToObject (args) {
|
|
1199
|
-
const obj = {}
|
|
1200
|
-
args.forEach((x, i) => {
|
|
1201
|
-
obj[`_${i + 1}`] = x
|
|
1202
|
-
})
|
|
1203
|
-
return obj
|
|
1204
|
-
}
|
|
1205
1151
|
}
|
|
1206
1152
|
|
|
1207
1153
|
/**
|
|
@@ -1210,7 +1156,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
1210
1156
|
* This event is fired whenever an agent is added or removed, or whenever
|
|
1211
1157
|
* an agent changes its status (switches between online or offline).
|
|
1212
1158
|
*
|
|
1213
|
-
* @event
|
|
1159
|
+
* @event VrpcClient#agent
|
|
1214
1160
|
* @param {Object} info
|
|
1215
1161
|
* @param {String} info.domain - Domain name
|
|
1216
1162
|
* @param {String} info.agent - Agent name
|
|
@@ -1225,7 +1171,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
1225
1171
|
* Emitted whenever a class is added or removed, or when instances
|
|
1226
1172
|
* or functions of this class have changed.
|
|
1227
1173
|
*
|
|
1228
|
-
* @event
|
|
1174
|
+
* @event VrpcClient#class
|
|
1229
1175
|
* @param {Object} info
|
|
1230
1176
|
* @param {String} info.domain - Domain name
|
|
1231
1177
|
* @param {String} info.agent - Agent name
|
|
@@ -1241,7 +1187,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
1241
1187
|
*
|
|
1242
1188
|
* Emitted whenever a new instance was created.
|
|
1243
1189
|
*
|
|
1244
|
-
* @event
|
|
1190
|
+
* @event VrpcClient#instanceNew
|
|
1245
1191
|
*
|
|
1246
1192
|
* @param {Array.<String>} addedInstances - An array of newly added instances
|
|
1247
1193
|
* @param {Object} info
|
|
@@ -1255,7 +1201,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
1255
1201
|
*
|
|
1256
1202
|
* Emitted whenever a new instance was removed.
|
|
1257
1203
|
*
|
|
1258
|
-
* @event
|
|
1204
|
+
* @event VrpcClient#instanceGone
|
|
1259
1205
|
*
|
|
1260
1206
|
* @param {Array.<String>} removedInstances - An array of removed instances
|
|
1261
1207
|
* @param {Object} info
|
|
@@ -1269,7 +1215,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
1269
1215
|
*
|
|
1270
1216
|
* Emitted on successful (re)connection (i.e. connack rc=0).
|
|
1271
1217
|
*
|
|
1272
|
-
* @event
|
|
1218
|
+
* @event VrpcClient#connect
|
|
1273
1219
|
* @type {Object}
|
|
1274
1220
|
* @property {Boolean} sessionPresent - A session from a previous connection is already present
|
|
1275
1221
|
*/
|
|
@@ -1279,7 +1225,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
1279
1225
|
*
|
|
1280
1226
|
* Emitted when a reconnect starts.
|
|
1281
1227
|
*
|
|
1282
|
-
* @event
|
|
1228
|
+
* @event VrpcClient#reconnect
|
|
1283
1229
|
*/
|
|
1284
1230
|
|
|
1285
1231
|
/**
|
|
@@ -1287,7 +1233,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
1287
1233
|
*
|
|
1288
1234
|
* Emitted after a disconnection.
|
|
1289
1235
|
*
|
|
1290
|
-
* @event
|
|
1236
|
+
* @event VrpcClient#close
|
|
1291
1237
|
*/
|
|
1292
1238
|
|
|
1293
1239
|
/**
|
|
@@ -1295,7 +1241,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
1295
1241
|
*
|
|
1296
1242
|
* Emitted when the client goes offline.
|
|
1297
1243
|
*
|
|
1298
|
-
* @event
|
|
1244
|
+
* @event VrpcClient#offline
|
|
1299
1245
|
*/
|
|
1300
1246
|
|
|
1301
1247
|
/**
|
|
@@ -1310,7 +1256,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
1310
1256
|
* - EADDRINUSE
|
|
1311
1257
|
* - ENOTFOUND
|
|
1312
1258
|
*
|
|
1313
|
-
* @event
|
|
1259
|
+
* @event VrpcClient#error
|
|
1314
1260
|
* @type {Object} Error
|
|
1315
1261
|
*/
|
|
1316
1262
|
|
|
@@ -1320,7 +1266,7 @@ class VrpcRemote extends EventEmitter {
|
|
|
1320
1266
|
* Emitted when mqtt.Client#end() is called. If a callback was passed to
|
|
1321
1267
|
* mqtt.Client#end(), this event is emitted once the callback returns.
|
|
1322
1268
|
*
|
|
1323
|
-
* @event
|
|
1269
|
+
* @event VrpcClient#end
|
|
1324
1270
|
*/
|
|
1325
1271
|
|
|
1326
|
-
module.exports =
|
|
1272
|
+
module.exports = VrpcClient
|