Skip to content

Commit

Permalink
Makes sure to always announce all fabrics (#413)
Browse files Browse the repository at this point in the history
* Makes sure to always announce all fabrics

... else they would be expired which is wrong behaviour

* Update IntegrationTest.ts

* formatting
  • Loading branch information
Apollon77 authored Oct 19, 2023
1 parent e78c95d commit cd4ed84
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 35 deletions.
24 changes: 5 additions & 19 deletions packages/matter-node.js/test/IntegrationTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1505,29 +1505,15 @@ describe("Integration Test", () => {
});

after(async () => {
const promise = mdnsBroadcaster.expireAllAnnouncements(matterPort);

await MockTime.yield();
await MockTime.yield();
await MockTime.yield();
await MockTime.yield();
await MockTime.advance(150);
await MockTime.advance(150);
await MockTime.yield();

await MockTime.yield();
await MockTime.yield();
await MockTime.yield();
await MockTime.yield();
await MockTime.advance(150);
await MockTime.advance(150);
await MockTime.yield();

await promise;
// For closing all down we need to use the real Time implementation
const mockTimeInstance = Time.get();
Time.get = singleton(() => new TimeNode());

await matterServer.close();
await matterClient.close();
await fakeControllerStorage.close();
await fakeServerStorage.close();

Time.get = () => mockTimeInstance;
});
});
26 changes: 10 additions & 16 deletions packages/matter.js/src/MatterDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,29 +148,23 @@ export class MatterDevice {
}
const fabrics = this.fabricManager.getFabrics();
if (fabrics.length) {
const fabricsToAnnounce: Fabric[] = [];
let fabricsToAnnounce = 0;
for (const fabric of fabrics) {
const session = this.sessionManager.getSessionForNode(fabric, fabric.rootNodeId);
if (
session !== undefined &&
session.isSecure() &&
(session as SecureSession<this>).numberOfActiveSubscriptions > 0
session === undefined ||
!session.isSecure() ||
(session as SecureSession<this>).numberOfActiveSubscriptions === 0
) {
// We have a session, no need to re-announce
logger.debug(
"Skipping announce for fabric",
fabric.fabricId,
"because we have a session with active subscriptions",
session.getId(),
);
continue;
fabricsToAnnounce++;
logger.debug("Announcing", Logger.dict({ fabric: fabric.fabricId }));
}
logger.debug("Announcing", Logger.dict({ fabric: fabric.fabricId }));
fabricsToAnnounce.push(fabric);
}
for (const broadcaster of this.broadcasters) {
await broadcaster.setFabrics(fabricsToAnnounce);
await broadcaster.announce();
await broadcaster.setFabrics(fabrics);
if (fabricsToAnnounce > 0) {
await broadcaster.announce();
}
}
} else {
// No fabric paired yet, so announce as "ready for commissioning"
Expand Down

0 comments on commit cd4ed84

Please sign in to comment.