ngx-mqtt icon indicating copy to clipboard operation
ngx-mqtt copied to clipboard

Check if connect() connects succesfully or not

Open felipeb95 opened this issue 3 years ago • 1 comments

  • [ X ] I have searched for similar issues in this repository, but couldn't find one.
  • [ X ] I have read the README and have a basic understanding how angular works.

I'm submitting a...

  • [ ] Regression (a behavior that used to work and stopped working in a new release)
  • [ ] Bug report  
  • [ X ] Feature request

Current behavior

Is there a way to check if the function _mqttService.connect() connects successfully or not?

Expected behavior

I'm seeking for a way to call this function and check if my connection works or no. I have an array of credentials for mqtt and I have to try one by one until one of them works.

Minimal working example of the problem with instructions

Code: MQTT_SERVICE_OPTIONS.push({ hostname: env.mqtt.server, port: env.mqtt.port, protocol: (env.mqtt.protocol === "wss") ? "wss" : "ws", path: '', username: env.mqtt.username, password: env.mqtt.password, clientId: this.clientId }); this._mqttService.connect(MQTT_SERVICE_OPTIONS[0]);

What is the motivation / use case for changing the behavior?

I want to try different credentials (The user will receive a list of credentials in a webservice, and if the first doesn't work of stop working I'll have to connect to the second one

Environment


ngx-mqtt version: 9.0.5


- Broker 

Others:

felipeb95 avatar Sep 15 '21 13:09 felipeb95

Isn’t the state Subject on the MqttService what you want?

sclausen avatar Sep 15 '21 16:09 sclausen