How to prevent duplicate connect when reload browser #2029
Closed
vanminhquangtri
started this conversation in
Show and tell
Replies: 2 comments
-
|
Your question isn't very clear to me. When a website is reloaded, if you inited your MQTT client on JS side, it would of course close your client socket and disconnect the client and it will be inited again on reconnection, there is no way to prevent this. If you want a persistent connection you should consider moving the client to a web worker. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
thanks @robertsLando |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
My website integrate MQTT.js version 5.14.0, using socket protocol wss://my.domain.
Assume clientid AAA is already connected and subscribed, then reload website. clientId after reload is still AAA because we use tabid as client id.
My problem is, the connection and subscription will be run again, although the same client id. And on my emqx server, it has disconnect action as well. This will cause serve is spamed or D-DOS because of reloading browser, that will have many connect/disconnect/subscribe of the same client id.
So I have 2 questions:
1/ Is there any function method of mqtt.js library to know that whether this client id is already connected?
2/ In case the answer is yes, I will not call function client.connect() again after reload. But if not not call function client.connect(), can we still subscribe/pubslish/unscribe.
I would be gratefull for any advice for this case. Thank you.
Beta Was this translation helpful? Give feedback.
All reactions