tommy44458 / mqtt-vue-hook

Mqtt-Vue-hook is a TypeScript library that makes it easy to connect to an MQTT broker (supports v5) and manages callback functions for various topics.
https://www.npmjs.com/package/mqtt-vue-hook
MIT License
24 stars 3 forks source link

Client Connection Status #3

Closed donniekerr closed 2 years ago

donniekerr commented 2 years ago

@tommy44458 I see the connection status in the console but how do I access it? I need to update UI when client connects, disconnects, or has an error.

tommy44458 commented 2 years ago

Hi Donnie,

Good question! In the next version, I’ll release the feature that can allow users to register connected/disconnected/excepted event.

tommy44458 commented 2 years ago

Hi @donniekerr,

I've released the new version 1.2.14 that can register events to listen mqtt status.

For example:

mqttHook.registerEvent(
    'on-connect', // mqtt status: on-connect, on-reconnect, on-disconnect, on-connect-fail
        (topic: string, message: string) => {
            console.log('mqtt connected')
        },
        'string_key',
)

mqttHook.unRegisterEvent('on-connect', 'string_key')
donniekerr commented 2 years ago

Awesome! Thanks @tommy44458 much appreciated. It will be useful to others as well.