Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MqttClientConnection

MQTT client connection

Hierarchy

Index

Constructors

constructor

Properties

Readonly client

client: MqttClient

The client that owns this connection

Optional Readonly tls_ctx

Static defaultMaxListeners

defaultMaxListeners: number

Methods

addListener

  • addListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

connect

  • connect(): Promise<boolean>
  • Open the actual connection to the server (async).

    Returns Promise<boolean>

    A Promise which completes whether the connection succeeds or fails. If connection fails, the Promise will reject with an exception. If connection succeeds, the Promise will return a boolean that is true for resuming an existing session, or false if the session is new

cork

  • cork(): void

disconnect

  • disconnect(): Promise<void>
  • Close the connection (async).

    Returns Promise<void>

    Promise which completes when the connection is closed.

emit

  • emit(event: EventKey, ...args: any[]): boolean
  • Synchronously calls each of the listeners registered for the event key supplied in registration order. If the BufferedEventEmitter is currently corked, the event will be buffered until BufferedEventEmitter.uncork is called.

    Parameters

    • event: EventKey

      The name of the event

    • Rest ...args: any[]

      Event payload

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>

getMaxListeners

  • getMaxListeners(): number

listenerCount

  • listenerCount(type: string | symbol): number

listeners

  • listeners(event: string | symbol): Function[]

off

  • off(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependListener

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

publish

  • Publish message (async). If the device is offline, the PUBLISH packet will be sent once the connection resumes.

    Parameters

    • topic: string

      Topic name

    • payload: Payload

      Contents of message

    • qos: QoS

      Quality of Service for delivering this message

    • Default value retain: boolean = false

      If true, the server will store the message and its QoS so that it can be delivered to future subscribers whose subscriptions match the topic name

    Returns Promise<MqttRequest>

    Promise which returns a MqttRequest which will contain the packet id of the PUBLISH packet.

    • For QoS 0, completes as soon as the packet is sent.
    • For QoS 1, completes when PUBACK is received.
    • For QoS 2, completes when PUBCOMP is received.

rawListeners

  • rawListeners(event: string | symbol): Function[]

reconnect

  • reconnect(): Promise<boolean>
  • The connection will automatically reconnect. To cease reconnection attempts, call disconnect. To resume the connection, call connect.

    deprecated

    Returns Promise<boolean>

removeAllListeners

  • removeAllListeners(event?: string | symbol): this

removeListener

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

setMaxListeners

  • setMaxListeners(n: number): this

subscribe

  • subscribe(topic: string, qos: QoS, on_message?: (topic: string, payload: ArrayBuffer) => void): Promise<MqttSubscribeRequest>
  • Subscribe to a topic filter (async). The client sends a SUBSCRIBE packet and the server responds with a SUBACK.

    subscribe() may be called while the device is offline, though the async operation cannot complete successfully until the connection resumes.

    Once subscribed, callback is invoked each time a message matching the topic is received. It is possible for such messages to arrive before the SUBACK is received.

    Parameters

    • topic: string

      Subscribe to this topic filter, which may include wildcards

    • qos: QoS

      Maximum requested QoS that server may use when sending messages to the client. The server may grant a lower QoS in the SUBACK

    • Optional on_message: (topic: string, payload: ArrayBuffer) => void

      Optional callback invoked when message received.

        • (topic: string, payload: ArrayBuffer): void
        • Parameters

          • topic: string
          • payload: ArrayBuffer

          Returns void

    Returns Promise<MqttSubscribeRequest>

    Promise which returns a MqttSubscribeRequest which will contain the result of the SUBSCRIBE. The Promise resolves when a SUBACK is returned from the server or is rejected when an exception occurs.

uncork

  • uncork(): void
  • Flushes all data buffered since BufferedEventEmitter.cork was called.

    NOTE: It is HIGHLY recommended that uncorking should always be done via process.nextTick, not during the EventEmitter.on() call.

    Returns void

unsubscribe

  • Unsubscribe from a topic filter (async). The client sends an UNSUBSCRIBE packet, and the server responds with an UNSUBACK.

    Parameters

    • topic: string

      The topic filter to unsubscribe from. May contain wildcards.

    Returns Promise<MqttRequest>

    Promise wihch returns a MqttRequest which will contain the packet id of the UNSUBSCRIBE packet being acknowledged. Promise is resolved when an UNSUBACK is received from the server or is rejected when an exception occurs.

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number

Generated using TypeDoc