vrpc 3.0.0-alpha.3 → 3.0.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/vrpc/VrpcAgent.js CHANGED
@@ -346,23 +346,23 @@ class VrpcAgent extends EventEmitter {
346
346
  }
347
347
 
348
348
  _getClasses () {
349
- return VrpcAdapter.getAvailableClasses()
349
+ return VrpcAdapter._getClassesArray()
350
350
  }
351
351
 
352
352
  _getInstances (className) {
353
- return VrpcAdapter.getAvailableInstances(className)
353
+ return VrpcAdapter._getInstancesArray(className)
354
354
  }
355
355
 
356
356
  _getMemberFunctions (className) {
357
- return VrpcAdapter.getAvailableMemberFunctions(className)
357
+ return VrpcAdapter._getMemberFunctionsArray(className)
358
358
  }
359
359
 
360
360
  _getStaticFunctions (className) {
361
- return VrpcAdapter.getAvailableStaticFunctions(className)
361
+ return VrpcAdapter._getStaticFunctionsArray(className)
362
362
  }
363
363
 
364
364
  _getMetaData (className) {
365
- return VrpcAdapter.getAvailableMetaData(className)
365
+ return VrpcAdapter._getMetaData(className)
366
366
  }
367
367
 
368
368
  async _ensureConnected () {
@@ -376,14 +376,18 @@ class VrpcAgent extends EventEmitter {
376
376
  }
377
377
 
378
378
  _handleVrpcCallback (json) {
379
- const { s } = json
379
+ const { s, i, r, e, a } = json
380
+ const topic = i.startsWith('__e__') ? i.slice(5) : s
380
381
  try {
381
- this._log.debug(`Forwarding callback to: ${s} with payload:`, json)
382
- this._mqttPublish(s, VrpcAgent._stringifySafely(json))
382
+ this._log.debug(`Forwarding callback to: ${topic} with payload:`, json)
383
+ this._mqttPublish(
384
+ topic,
385
+ VrpcAgent._stringifySafely({ a, r, e, i, v: VRPC_PROTOCOL_VERSION })
386
+ )
383
387
  } catch (err) {
384
388
  this._log.warn(
385
389
  err,
386
- `Problem publishing vrpc callback to ${sender} because of: ${err.message}`
390
+ `Problem publishing vrpc callback to ${topic} because of: ${err.message}`
387
391
  )
388
392
  }
389
393
  }
@@ -549,7 +553,9 @@ class VrpcAgent extends EventEmitter {
549
553
  break
550
554
  }
551
555
  }
552
- this._mqttPublish(json.s, VrpcAgent._stringifySafely(json))
556
+ const { a, r, e, i, v } = json
557
+ const res = e ? { a, r, e, i, v } : { a, r, i, v }
558
+ this._mqttPublish(json.s, VrpcAgent._stringifySafely(res))
553
559
  } catch (err) {
554
560
  this._log.error(
555
561
  err,
@@ -562,19 +568,17 @@ class VrpcAgent extends EventEmitter {
562
568
  // Client went offline
563
569
  const clientId = topic.slice(0, -15) // /__clientInfo__ = 15
564
570
  if (json.status === 'offline') {
571
+ VrpcAdapter._unregisterClient(clientId)
565
572
  const entry = this._isolatedInstances.get(clientId)
566
573
  if (entry) {
567
- // anonymous
568
574
  entry.forEach(instanceId => {
569
575
  const json = { f: '__delete__', a: [instanceId], r: null }
570
- // TODO Do not mutate!
571
576
  VrpcAdapter._call(json)
572
577
  if (json.r) {
573
578
  this._log.debug(`Auto-deleted isolated instance: ${instanceId}`)
574
579
  }
575
580
  })
576
581
  }
577
- VrpcAdapter._unregisterEventListeners(clientId)
578
582
  this._mqttUnsubscribe(`${clientId}/__clientInfo__`)
579
583
  this.emit('clientGone', clientId)
580
584
  }
@@ -620,7 +624,6 @@ class VrpcAgent extends EventEmitter {
620
624
  _unregisterInstance (instanceId, clientId) {
621
625
  const entryIsolated = this._isolatedInstances.get(clientId)
622
626
  if (entryIsolated && entryIsolated.has(instanceId)) {
623
- VrpcAdapter._unregisterEventListenersOfInstance(instanceId)
624
627
  entryIsolated.delete(instanceId)
625
628
  if (entryIsolated.length === 0) {
626
629
  this._isolatedInstances.delete(clientId)
@@ -633,7 +636,6 @@ class VrpcAgent extends EventEmitter {
633
636
  this._sharedInstances.forEach(async v => {
634
637
  if (v.has(instanceId)) {
635
638
  found = true
636
- VrpcAdapter._unregisterEventListenersOfInstance(instanceId)
637
639
  v.delete(instanceId)
638
640
  if (v.length === 0) {
639
641
  this._sharedInstances.delete(clientId)
@@ -748,8 +750,7 @@ class VrpcAgent extends EventEmitter {
748
750
  /**
749
751
  * Event 'clientGone'
750
752
  *
751
- * Emitted when a VRPC client exited that before produced state (e.g. created
752
- * an anonymous or named instance).
753
+ * Emitted when a tracked VRPC client exited.
753
754
  *
754
755
  * @event VrpcAgent#clientGone
755
756
  * @type {String} clientId