VictorHAS / mqtt-react-hooks

ReactJS library for Pub/Sub communication with an MQTT broker using Hooks
MIT License
91 stars 28 forks source link

Stuck in connection state, multiple websocket connections openned. #46

Open yoanncatalabt opened 2 years ago

yoanncatalabt commented 2 years ago

Hello everyone, I am stuck using this package, which by the way seems to be nice and easy to use. I am not able to connect to my broker using it.

imageThe client state is null The connectionStatus is stuck in "Connecting" Moreover, in the network tab, 3 WS connections are initiated (101 Switching protocols) to my broker. Why are 3 connection openned ? I logged how many renders occurs, and there is only one render.

I tried to reproduce this package using plain JS with the same code, and i can tell that the problem seemed to by related to the mountedRef ref, which happen to never be equal to true when entering in all listeners (on.connect , on.reconnect, on.error , etc. ) and so, never setting up the client or updating the connectionStatus. Maybe my issue is related to the ref.

By the way, the broker is fully working, as I was previously using plain mqtt package without no issues. Tested also with public mqtt brokers, same results.

If someone has an idea ? Thanks a lot !