pamoja for TypeScript - v0.1.17
    Preparing search index...

    Class MqttClient

    An MQTT client transport.

    Construct it with broker settings, connect, then publish, subscribe, and read inbound messages with recv or by iterating the client with for await.

    const client = new MqttClient({ clientId: 'sensor-1', host: 'localhost', port: 1883 })
    await client.connect()
    await client.subscribe('sensors/+/temperature')
    await client.publish('sensors/1/temperature', '21.5')
    for await (const message of client) {
    console.log(message.topic, message.payload.toString())
    }
    Index
    • Iterates incoming messages, so a client can be used with for await.

      Returns AsyncGenerator<MqttMessage, void, unknown>

    • Connects to the broker and starts the background event loop.

      Returns Promise<void>

      A promise that resolves once connected and rejects on failure.

    • Closes the connection and stops the background event loop.

      Returns Promise<void>

      A promise that resolves once the client has disconnected.

    • Reports whether the client currently holds an active connection.

      Returns Promise<boolean>

      A promise resolving to the connection state.

    • Yields messages from subscribed topics until the connection ends.

      Returns AsyncGenerator<MqttMessage, void, unknown>

      An async generator over incoming messages.

    • Publishes a payload to a topic.

      Parameters

      • topic: string

        The destination topic.

      • payload: string | Uint8Array<ArrayBufferLike>

        The message body; strings are encoded as UTF-8.

      Returns Promise<void>

      A promise that resolves once the payload is handed to the transport.

    • Subscribes to a topic filter.

      Parameters

      • topic: string

        The topic or wildcard filter to subscribe to.

      Returns Promise<void>

      A promise that resolves once the subscription is registered.