vrpc 3.5.0 → 3.5.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.
@@ -1 +1,10 @@
1
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
1
+ /*!
2
+ * The buffer module from node.js, for the browser.
3
+ *
4
+ * @author Feross Aboukhadijeh <https://feross.org>
5
+ * @license MIT
6
+ */
7
+
8
+ /*! https://mths.be/punycode v1.4.1 by @mathias */
9
+
10
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vrpc",
3
- "version": "3.5.0",
3
+ "version": "3.5.2",
4
4
  "description": "Variadic Remote Procedure Calls",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -73,7 +73,7 @@
73
73
  "buffer": "^6.0.3",
74
74
  "caller": "^1.1.0",
75
75
  "json-stringify-safe": "^5.0.1",
76
- "mqtt": "^5.14.1",
76
+ "mqtt": "^4.3.7",
77
77
  "nanoid": "^3.3.8",
78
78
  "process": "^0.11.10"
79
79
  },
@@ -547,11 +547,6 @@ class VrpcAdapter {
547
547
  return
548
548
  }
549
549
  const unwrapped = VrpcAdapter._unwrapArguments(json)
550
- if (!unwrapped) {
551
- // this call must be skipped (event emitter stuff)
552
- json.r = true
553
- return
554
- }
555
550
  // Check whether context is a registered class
556
551
  const entry = VrpcAdapter._functionRegistry.get(json.c)
557
552
  if (entry !== undefined) {
@@ -680,9 +675,6 @@ class VrpcAdapter {
680
675
  eventId: arg,
681
676
  event: args[0]
682
677
  })
683
- if (!listener) {
684
- return null // skip call as listener is already registered
685
- }
686
678
  unwrapped.push(listener)
687
679
  // event un-registration
688
680
  } else if (func === 'off' || func === 'removeListener') {
@@ -691,9 +683,6 @@ class VrpcAdapter {
691
683
  instanceId: context,
692
684
  eventId: arg
693
685
  })
694
- if (!listener) {
695
- return null // skip call as others are still interested
696
- }
697
686
  unwrapped.push(listener)
698
687
  } else {
699
688
  this._mustTrackClient = true
@@ -759,8 +748,6 @@ class VrpcAdapter {
759
748
  return VrpcAdapter._listeners[instanceId][eventId].listener
760
749
  }
761
750
  VrpcAdapter._listeners[instanceId][eventId].clients.push(clientId)
762
- // if "event" is defined we are calling against a plain EventEmitter and
763
- // have to skip this call as we have registered internally
764
751
  return VrpcAdapter._listeners[instanceId][eventId].listener
765
752
  }
766
753
 
@@ -135,6 +135,7 @@ class VrpcClient extends EventEmitter {
135
135
  this._cachedSubscriptions = {}
136
136
  this._proxies = {}
137
137
  this._callbackIds = new WeakMap()
138
+ this._emitterListener = new WeakMap()
138
139
  if (log === 'console') {
139
140
  this._log = console
140
141
  this._log.debug = () => {}
@@ -187,6 +188,11 @@ class VrpcClient extends EventEmitter {
187
188
  }
188
189
  if (username === undefined) delete options.username
189
190
  if (password === undefined) delete options.password
191
+
192
+ this.on('error', err => {
193
+ this._log.debug(`Encountered MQTT error: ${err.message}`)
194
+ })
195
+
190
196
  this._client = mqtt.connect(this._broker, options)
191
197
 
192
198
  // Persistent lifecycle handlers
@@ -210,10 +216,6 @@ class VrpcClient extends EventEmitter {
210
216
  this.emit('error', err)
211
217
  })
212
218
 
213
- this.on('error', err => {
214
- this._log.debug(`Encountered MQTT error: ${err.message}`)
215
- })
216
-
217
219
  this._client.on('connect', () => {
218
220
  // This will give us an overview of all remotely available classes
219
221
  const agent = this._agent === '*' ? '+' : this._agent
@@ -1222,12 +1224,24 @@ class VrpcClient extends EventEmitter {
1222
1224
  // special case of an EventEmitter provided as argument
1223
1225
  if (this._isEmitter(x)) {
1224
1226
  const { emitter, event } = x
1227
+ let callback = (...args) => emitter.emit(event, ...args)
1228
+ if (this._emitterListener.has(emitter)) {
1229
+ const eventMap = this._emitterListener.get(emitter)
1230
+ if (eventMap.has(event)) {
1231
+ callback = eventMap.get(event)
1232
+ } else {
1233
+ eventMap.set(event, callback)
1234
+ }
1235
+ } else {
1236
+ this._emitterListener.set(emitter, new Map([[event, callback]]))
1237
+ }
1238
+
1225
1239
  const id = this._onRemoteEvent({
1226
1240
  agent,
1227
1241
  className,
1228
1242
  instance,
1229
1243
  event,
1230
- callback: (...args) => emitter.emit(event, ...args)
1244
+ callback
1231
1245
  })
1232
1246
  wrapped.push(id)
1233
1247
  continue