Singleton MQTTTransport that forwards calls to the transport passed to ESPRMNeoMqtt.initialize. Use with NodeMQTTOrchestrator as in the example below.

ESPRMNeoMqtt.initialize(mqttTransport);
NodeMQTTOrchestrator.initialize(ESPRMNeoMqtt.getInstance());

Implements

Methods

  • Registers a transport connection-status listener when the underlying adapter supports it; otherwise returns a no-op unsubscribe.

    Parameters

    • callback: (status: { connected: boolean }) => void

      Invoked with { connected } on status changes

    Returns () => void

    Unsubscribe function

  • Publish a message to a topic.

    Parameters

    • topic: string

      MQTT topic to publish to

    • payload: string | Buffer<ArrayBufferLike>

      Message payload to publish

    Returns Promise<void>

  • Subscribe to a topic with a message handler.

    Parameters

    • topic: string

      MQTT topic to subscribe to

    • handler: (topic: string, payload: Buffer) => void

      Callback invoked when a message is received on the topic

    Returns Promise<void>

  • Unsubscribe from a topic, optionally removing a specific handler.

    Parameters

    • topic: string

      MQTT topic to unsubscribe from

    • Optionalhandler: (topic: string, payload: Buffer) => void

      Callback that was used with ESPRMNeoMqtt.subscribe

    Returns Promise<void>

  • Initializes the singleton with an MQTT transport. Must be called before ESPRMNeoMqtt.getInstance.

    Parameters

    • adapter: MQTTTransport

      MQTTTransport implementation to delegate to.

    Returns void

    If already initialized. Call ESPRMNeoMqtt.clear first if you genuinely need to re-init (e.g. between test cases). A silent replacement is refused because in-flight subscriptions on the old adapter would be orphaned and messages would split between the two live transports.