Mqtt.js: [Browser] client on connect handler triggered continuously

Created on 2 May 2019  路  4Comments  路  Source: mqttjs/MQTT.js

I have a browser application with the following code:

const client = mqtt.connect(options);

    client.on('connect', e => {
        client.publish(`events/${clientId}/service/up`, JSON.stringify({
            action: 'up',
            client: clientId,
            timestamp: Math.floor(Date.now() / 1000)
        }));
    });

The connect handler seems to be called continuously:

{
  "cmd": "connack",
  "retain": false,
  "qos": 0,
  "dup": false,
  "length": 2,
  "topic": null,
  "payload": null,
  "sessionPresent": false,
  "returnCode": 0
}

Output from subscribing to events/#:

{"action":"up","client":"web-client-jv665k8a","timestamp":1556772528}
{"action":"up","client":"web-client-jv665k8a","timestamp":1556772530}
{"action":"up","client":"web-client-jv665k8a","timestamp":1556772533}
{"action":"up","client":"web-client-jv665k8a","timestamp":1556772536}
{"action":"up","client":"web-client-jv665k8a","timestamp":1556772539}
{"action":"up","client":"web-client-jv665k8a","timestamp":1556772542}
{"action":"up","client":"web-client-jv665k8a","timestamp":1556772545}
{"action":"up","client":"web-client-jv665k8a","timestamp":1556772548}
{"action":"up","client":"web-client-jv665k8a","timestamp":1556772551}
{"action":"up","client":"web-client-jv665k8a","timestamp":1556772554}
{"action":"up","client":"web-client-jv665k8a","timestamp":1556772557}
{"action":"up","client":"web-client-jv665k8a","timestamp":1556772560}
{"action":"up","client":"web-client-jv665k8a","timestamp":1556772563}
{"action":"up","client":"web-client-jv665k8a","timestamp":1556772566}
{"action":"up","client":"web-client-jv665k8a","timestamp":1556772568}

This only happens when the client is not busy sending/receiving messages.

What could explain this behavior?

All 4 comments

@goliatone Were you able to solve this issue?
I am also facing this issue in browser.

Tested ./example/client/simple-publish.js
The connect handler seems to be called continuously:

Screenshot from 2019-06-10 17-41-43

@abhinav-juneja the behavior seems to be intermittent, I have not been able to understand the issue behind

I have the same problem

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bicccio picture bicccio  路  3Comments

jeffdare picture jeffdare  路  9Comments

ferm10n picture ferm10n  路  5Comments

amerllica picture amerllica  路  3Comments

jingzhaoou picture jingzhaoou  路  4Comments