Skip to content

Commit 7bb51f3

Browse files
committed
fix(mqtt): allow optional uri in MQTT Server configuration
1 parent 861bcad commit 7bb51f3

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

packages/binding-mqtt/src/mqtt-broker-server.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default class MqttBrokerServer implements ProtocolServer {
6565
private port = -1;
6666
private address?: string = undefined;
6767

68-
private brokerURI: string;
68+
private brokerURI?: string;
6969

7070
private readonly things: Map<string, ExposedThing> = new Map();
7171

@@ -77,15 +77,14 @@ export default class MqttBrokerServer implements ProtocolServer {
7777
private hostedBroker?: net.Server;
7878

7979
constructor(config: MqttBrokerServerConfig) {
80-
this.config = config ?? this.defaults;
81-
this.config.uri = this.config.uri ?? this.defaults.uri;
82-
8380
// if there is a MQTT protocol indicator missing, add this
84-
if (config.uri.indexOf("://") === -1) {
81+
if (config.uri?.indexOf("://") === -1) {
8582
config.uri = this.scheme + "://" + config.uri;
8683
}
8784

8885
this.brokerURI = config.uri;
86+
this.config = config ?? this.defaults;
87+
this.config.uri = this.config.uri ?? this.defaults.uri;
8988
}
9089

9190
public async expose(thing: ExposedThing): Promise<void> {
@@ -446,6 +445,12 @@ export default class MqttBrokerServer implements ProtocolServer {
446445

447446
private async startBroker() {
448447
return new Promise<void>((resolve, reject) => {
448+
console.log("here mf");
449+
450+
if (this.brokerURI == null) {
451+
throw new Error("Unexpected configuration state broker was started even if brokerURI is null");
452+
}
453+
449454
this.hostedServer = Server({});
450455
let server: tls.Server | net.Server;
451456
if (this.config.key) {

packages/binding-mqtt/src/mqtt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export interface MqttClientConfig {
5151
}
5252

5353
export interface MqttBrokerServerConfig {
54-
uri: string;
54+
uri?: string;
5555
user?: string;
5656
psw?: string;
5757
clientId?: string;

0 commit comments

Comments
 (0)