From 2bab14fa3d218e42ea05af142ef1c1480b1aa059 Mon Sep 17 00:00:00 2001 From: sclausen Date: Wed, 5 Sep 2018 20:38:46 +0200 Subject: [PATCH] #112 Check if connectOnCreate in connect/reconnect handling. --- src/mqtt.service.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/mqtt.service.ts b/src/mqtt.service.ts index a252432..7c16e31 100644 --- a/src/mqtt.service.ts +++ b/src/mqtt.service.ts @@ -316,17 +316,21 @@ export class MqttService { } private _handleOnConnect = (e: IOnConnectEvent) => { - Object.keys(this.observables).forEach((filter: string) => { - this.client.subscribe(filter); - }); + if (this.options.connectOnCreate === true) { + Object.keys(this.observables).forEach((filter: string) => { + this.client.subscribe(filter); + }); + } this.state.next(MqttConnectionState.CONNECTED); this._onConnect.emit(e); } private _handleOnReconnect = () => { - Object.keys(this.observables).forEach((filter: string) => { - this.client.subscribe(filter); - }); + if (this.options.connectOnCreate === true) { + Object.keys(this.observables).forEach((filter: string) => { + this.client.subscribe(filter); + }); + } this.state.next(MqttConnectionState.CONNECTING); this._onReconnect.emit(); }