sen-ether-client 0.2.2 → 0.2.4
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 +21 -1
- package/lib/sen.js +26 -7
- package/package.json +1 -1
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
|
-
|
|
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
|
@@ -657,7 +657,8 @@ export class Sen extends EventEmitter {
|
|
|
657
657
|
await session.connect({
|
|
658
658
|
...baseConfig,
|
|
659
659
|
session: sessionName,
|
|
660
|
-
target
|
|
660
|
+
target,
|
|
661
|
+
rediscoverTargetOnReconnect: true
|
|
661
662
|
});
|
|
662
663
|
} catch (error) {
|
|
663
664
|
this.sessions.delete(sessionName);
|
|
@@ -921,6 +922,9 @@ export class Sen extends EventEmitter {
|
|
|
921
922
|
}
|
|
922
923
|
|
|
923
924
|
async #reconnectTarget(options) {
|
|
925
|
+
if (options.rediscoverTargetOnReconnect) {
|
|
926
|
+
return await this.#discoverTarget({ ...options, target: undefined });
|
|
927
|
+
}
|
|
924
928
|
if (options.tcpHub || !options.target) {
|
|
925
929
|
return await this.#discoverTarget(options);
|
|
926
930
|
}
|
|
@@ -1229,6 +1233,7 @@ export class SenBus extends EventEmitter {
|
|
|
1229
1233
|
this.id = id;
|
|
1230
1234
|
this.objectsById = new Map();
|
|
1231
1235
|
this.typeRegistry = new Map();
|
|
1236
|
+
this.typeRegistryByHash = new Map();
|
|
1232
1237
|
this.requestedTypeHashes = new Set();
|
|
1233
1238
|
this.stateRequestedObjectIds = new Set();
|
|
1234
1239
|
this.stateResyncTimers = new Set();
|
|
@@ -1236,6 +1241,7 @@ export class SenBus extends EventEmitter {
|
|
|
1236
1241
|
this.interests = new Map();
|
|
1237
1242
|
this.pendingCalls = new Map();
|
|
1238
1243
|
this.nextTicketId = 1;
|
|
1244
|
+
this.reconnectPrepared = false;
|
|
1239
1245
|
}
|
|
1240
1246
|
|
|
1241
1247
|
startInterest(query, options = {}) {
|
|
@@ -1278,24 +1284,31 @@ export class SenBus extends EventEmitter {
|
|
|
1278
1284
|
}
|
|
1279
1285
|
|
|
1280
1286
|
prepareReconnect() {
|
|
1287
|
+
if (this.reconnectPrepared) {
|
|
1288
|
+
return;
|
|
1289
|
+
}
|
|
1290
|
+
this.reconnectPrepared = true;
|
|
1291
|
+
const detail = { reason: 'reconnect' };
|
|
1281
1292
|
for (const call of this.pendingCalls.values()) {
|
|
1282
1293
|
clearTimeout(call.timeout);
|
|
1283
1294
|
call.reject(new Error('SEN connection closed before method response'));
|
|
1284
1295
|
}
|
|
1285
1296
|
this.pendingCalls.clear();
|
|
1286
|
-
for (const object of this.objectsById.values()) {
|
|
1297
|
+
for (const object of [...this.objectsById.values()]) {
|
|
1287
1298
|
object.stale = true;
|
|
1288
|
-
object.emit('stale');
|
|
1299
|
+
object.emit('stale', detail);
|
|
1300
|
+
this.#removeObjectFromAllInterests(object, detail);
|
|
1289
1301
|
}
|
|
1290
1302
|
this.objectsById.clear();
|
|
1291
1303
|
this.typeRegistry.clear();
|
|
1304
|
+
this.typeRegistryByHash.clear();
|
|
1292
1305
|
this.requestedTypeHashes.clear();
|
|
1293
1306
|
this.stateRequestedObjectIds.clear();
|
|
1294
1307
|
this.#clearStateResyncTimers();
|
|
1295
1308
|
for (const interest of this.interests.values()) {
|
|
1296
1309
|
interest.closeLocal();
|
|
1297
1310
|
interest.objectsById.clear();
|
|
1298
|
-
interest.emit('stale');
|
|
1311
|
+
interest.emit('stale', detail);
|
|
1299
1312
|
}
|
|
1300
1313
|
}
|
|
1301
1314
|
|
|
@@ -1306,6 +1319,7 @@ export class SenBus extends EventEmitter {
|
|
|
1306
1319
|
});
|
|
1307
1320
|
const joined = await this.sen.client.joinBus(this.name);
|
|
1308
1321
|
this.id = joined.busId;
|
|
1322
|
+
this.reconnectPrepared = false;
|
|
1309
1323
|
const participantReadyTimeoutMs = Math.min(timeoutMs, this.sen.options.participantReadyTimeoutMs ?? 1000);
|
|
1310
1324
|
await waitForEvent(this.sen.client, 'busParticipantReady', participantReadyTimeoutMs).catch(error => {
|
|
1311
1325
|
this.sen.emit('warning', error);
|
|
@@ -1362,9 +1376,7 @@ export class SenBus extends EventEmitter {
|
|
|
1362
1376
|
}
|
|
1363
1377
|
this.#attachKnownType(object);
|
|
1364
1378
|
interest?.objectsById.set(object.key, object);
|
|
1365
|
-
|
|
1366
|
-
object.applyState(info.state, 'published', info.time, { interestId: discovery.interestId });
|
|
1367
|
-
}
|
|
1379
|
+
object.applyState(info.state?.length ? info.state : Buffer.alloc(0), 'state', info.time, { interestId: discovery.interestId });
|
|
1368
1380
|
if (!this.requestedTypeHashes.has(info.typeHash)) {
|
|
1369
1381
|
this.requestedTypeHashes.add(info.typeHash);
|
|
1370
1382
|
newTypeHashes.add(info.typeHash);
|
|
@@ -1499,6 +1511,7 @@ export class SenBus extends EventEmitter {
|
|
|
1499
1511
|
for (const type of event.types ?? []) {
|
|
1500
1512
|
this.typeRegistry.set(type.spec.qualifiedName, type.spec);
|
|
1501
1513
|
if (type.classHash !== undefined) {
|
|
1514
|
+
this.typeRegistryByHash.set(type.classHash >>> 0, type.spec);
|
|
1502
1515
|
for (const object of this.objectsById.values()) {
|
|
1503
1516
|
if (object.typeHash === type.classHash) {
|
|
1504
1517
|
object.spec = type.spec;
|
|
@@ -1699,6 +1712,12 @@ export class SenBus extends EventEmitter {
|
|
|
1699
1712
|
if (object.spec) {
|
|
1700
1713
|
return;
|
|
1701
1714
|
}
|
|
1715
|
+
const specByHash = this.typeRegistryByHash.get(object.typeHash >>> 0);
|
|
1716
|
+
if (specByHash) {
|
|
1717
|
+
object.spec = specByHash;
|
|
1718
|
+
object.emit('type', specByHash);
|
|
1719
|
+
return;
|
|
1720
|
+
}
|
|
1702
1721
|
for (const spec of this.typeRegistry.values()) {
|
|
1703
1722
|
const hash = crc32(spec?.qualifiedName ?? spec?.name ?? '');
|
|
1704
1723
|
if (hash === object.typeHash) {
|