Skip to content

Commit

Permalink
fix: services are now saved to networkServices before an EventMDNSSer…
Browse files Browse the repository at this point in the history
…vice is dispatched
  • Loading branch information
amydevs committed Oct 16, 2023
1 parent f805fcd commit 1e520af
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/MDNS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ class MDNS {
advertise?: boolean;
id?: number;
}): Promise<void> {
this.logger.info(`Start ${this.constructor.name}`);

if (!utils.isPort(port)) {
throw new RangeError('Port must be between 0 and 65535');
}
Expand Down Expand Up @@ -266,8 +268,6 @@ class MDNS {
}
}

this.logger.info(`Start ${this.constructor.name}`);

const socketHosts: Array<[Host, 'udp4' | 'udp6', string, number?]> = [];
// When binding to wild card
// We explicitly find out all the interfaces we are going to bind to
Expand Down Expand Up @@ -454,6 +454,7 @@ class MDNS {

// We have to figure out 1 socket at a time
// And we have to decide what we are doing here
this.logger.info(`Started ${this.constructor.name}`);
}

protected advertise(
Expand Down Expand Up @@ -939,10 +940,10 @@ class MDNS {
}
// We check if the service has been entirely built before dispatching the event that it has been created
if (utils.isService(partialService)) {
this._networkServices.set(dirtiedServiceFdqn, partialService);
this.dispatchEvent(
new events.EventMDNSService({ detail: partialService }),
);
this._networkServices.set(dirtiedServiceFdqn, partialService);
}
allRemainingQuestions.push(...remainingQuestions.values());
}
Expand Down Expand Up @@ -1060,6 +1061,8 @@ class MDNS {
* This will close all sockets.
*/
public async stop(): Promise<void> {
this.logger.info(`Stop ${this.constructor.name}`);

// Cancel Queries and Advertisements
for (const query of this.queries.values()) {
query.cancel();
Expand Down Expand Up @@ -1121,6 +1124,8 @@ class MDNS {
}
this.socketHostTable.clearTable();
this.sockets = [];

this.logger.info(`Stopped ${this.constructor.name}`);
}

/**
Expand Down

0 comments on commit 1e520af

Please sign in to comment.