How to implement mqtt over websockets in browser clients?

426 views Asked by At

I'm trying to use mqtt over websocket in my web application using the Paho JS library to implement notifications. I need to use persistent connection(to receive any pending messages) and for that a unique client id is a must.

Problem 1: Multiple tabs acting as a mqtt client using the same client id and hence disconnecting and connecting in infinite loop(as I've set reconnect to true)

I solved the above problem using Shared Worker which is now using only one connection for all the tabs which is great. But now I've run into another problem.

Problem 2: When I open my application in two different browsers say, Chrome and Firefox, I get different shared workers and hence again two clients using the same clientId resulting in connect/disconnect loop.

Any suggestion would be highly appreciated.

0

There are 0 answers