sen-ether-client 0.2.2 → 0.2.3

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/lib/client.js CHANGED
@@ -1501,7 +1501,27 @@ export class EtherClient extends EventEmitter {
1501
1501
  const busMessage = decodeBusMessage(frame.message);
1502
1502
  this.emit('busFrame', { ...frame, busMessage, remote, multicast: true });
1503
1503
  if (busMessage.categoryName === 'controlMessage') {
1504
- this.emit('busControlMessage', { ...frame, control: busMessage.control, remote, multicast: true });
1504
+ const control = busMessage.control;
1505
+ this.emit('busControlMessage', { ...frame, control, remote, multicast: true });
1506
+ switch (control.type) {
1507
+ case 'ObjectsPublished':
1508
+ this.emit('objectsPublished', { bus: busState, remote, multicast: true, ...control.value });
1509
+ break;
1510
+ case 'ObjectsRemoved':
1511
+ this.emit('objectsRemoved', { bus: busState, remote, multicast: true, ...control.value });
1512
+ break;
1513
+ case 'ObjectsStateResponse':
1514
+ this.emit('objectsStateResponse', { bus: busState, remote, multicast: true, ...control.value });
1515
+ break;
1516
+ case 'TypesInfoResponse':
1517
+ this.emit('typesInfoResponse', { bus: busState, remote, multicast: true, ...control.value });
1518
+ break;
1519
+ case 'TypesInfoRejection':
1520
+ this.emit('typesInfoRejection', { bus: busState, remote, multicast: true, ...control.value });
1521
+ break;
1522
+ default:
1523
+ break;
1524
+ }
1505
1525
  return;
1506
1526
  }
1507
1527
  this.emit(busMessage.categoryName, { ...frame, ...busMessage, remote, multicast: true });
package/lib/sen.js CHANGED
@@ -1229,6 +1229,7 @@ export class SenBus extends EventEmitter {
1229
1229
  this.id = id;
1230
1230
  this.objectsById = new Map();
1231
1231
  this.typeRegistry = new Map();
1232
+ this.typeRegistryByHash = new Map();
1232
1233
  this.requestedTypeHashes = new Set();
1233
1234
  this.stateRequestedObjectIds = new Set();
1234
1235
  this.stateResyncTimers = new Set();
@@ -1289,6 +1290,7 @@ export class SenBus extends EventEmitter {
1289
1290
  }
1290
1291
  this.objectsById.clear();
1291
1292
  this.typeRegistry.clear();
1293
+ this.typeRegistryByHash.clear();
1292
1294
  this.requestedTypeHashes.clear();
1293
1295
  this.stateRequestedObjectIds.clear();
1294
1296
  this.#clearStateResyncTimers();
@@ -1362,9 +1364,7 @@ export class SenBus extends EventEmitter {
1362
1364
  }
1363
1365
  this.#attachKnownType(object);
1364
1366
  interest?.objectsById.set(object.key, object);
1365
- if (info.state?.length) {
1366
- object.applyState(info.state, 'published', info.time, { interestId: discovery.interestId });
1367
- }
1367
+ object.applyState(info.state?.length ? info.state : Buffer.alloc(0), 'state', info.time, { interestId: discovery.interestId });
1368
1368
  if (!this.requestedTypeHashes.has(info.typeHash)) {
1369
1369
  this.requestedTypeHashes.add(info.typeHash);
1370
1370
  newTypeHashes.add(info.typeHash);
@@ -1499,6 +1499,7 @@ export class SenBus extends EventEmitter {
1499
1499
  for (const type of event.types ?? []) {
1500
1500
  this.typeRegistry.set(type.spec.qualifiedName, type.spec);
1501
1501
  if (type.classHash !== undefined) {
1502
+ this.typeRegistryByHash.set(type.classHash >>> 0, type.spec);
1502
1503
  for (const object of this.objectsById.values()) {
1503
1504
  if (object.typeHash === type.classHash) {
1504
1505
  object.spec = type.spec;
@@ -1699,6 +1700,12 @@ export class SenBus extends EventEmitter {
1699
1700
  if (object.spec) {
1700
1701
  return;
1701
1702
  }
1703
+ const specByHash = this.typeRegistryByHash.get(object.typeHash >>> 0);
1704
+ if (specByHash) {
1705
+ object.spec = specByHash;
1706
+ object.emit('type', specByHash);
1707
+ return;
1708
+ }
1702
1709
  for (const spec of this.typeRegistry.values()) {
1703
1710
  const hash = crc32(spec?.qualifiedName ?? spec?.name ?? '');
1704
1711
  if (hash === object.typeHash) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sen-ether-client",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Pure JavaScript SEN client for existing kernels over ether",
5
5
  "senCompatibility": {
6
6
  "kernelProtocolVersion": 9,