Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MqttClient

Hierarchy

  • EventEmitter
    • MqttClient

Index

Constructors

constructor

Properties

connected

connected: boolean

disconnected

disconnected: boolean

disconnecting

disconnecting: boolean

incomingStore

incomingStore: any

options

options: any

outgoingStore

outgoingStore: any

queueQoSZero

queueQoSZero: boolean

reconnecting

reconnecting: boolean

Static defaultMaxListeners

defaultMaxListeners: number

Static Readonly errorMonitor

errorMonitor: unique symbol

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

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

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

end

  • end(force?: boolean, cb?: any): this

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

getLastMessageId

  • getLastMessageId(): number

getMaxListeners

  • getMaxListeners(): number

handleMessage

  • handleMessage(packet: any, callback: any): void

listenerCount

  • listenerCount(event: string | symbol): number
  • Parameters

    • event: string | symbol

    Returns number

listeners

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

    • event: string | symbol

    Returns 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

on

  • on(event: "message", cb: any): this
  • on(event: "packetsend" | "packetreceive", cb: any): this
  • on(event: "error", cb: any): this
  • on(event: string, cb: Function): this

once

  • once(event: "message", cb: any): this
  • once(event: "packetsend" | "packetreceive", cb: any): this
  • once(event: "error", cb: any): this
  • once(event: string, cb: Function): 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(topic: string, message: string | Buffer, opts: any, callback?: any): this
  • publish(topic: string, message: string | Buffer, callback?: any): this

rawListeners

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

reconnect

  • reconnect(opts?: any): this

removeAllListeners

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

    • Optional event: string | symbol

    Returns 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

removeOutgoingMessage

  • removeOutgoingMessage(mid: number): this
  • removeOutgoingMessage - remove a message in outgoing store the outgoing callback will be called withe Error('Message removed') if the message is removed

    api

    public

    example

    client.removeOutgoingMessage(client.getLastMessageId());

    Parameters

    • mid: number

      messageId to remove message

    Returns this

    this - for chaining

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

subscribe

  • subscribe(topic: string | string[], opts: any, callback?: any): this
  • subscribe(topic: string | string[] | any, callback?: any): this
  • subscribe - subscribe to

    api

    public

    example

    client.subscribe('topic')

    example

    client.subscribe('topic', {qos: 1})

    example

    client.subscribe({'topic': 0, 'topic2': 1}, console.log)

    example

    client.subscribe('topic', console.log)

    Parameters

    • topic: string | string[]

      topic(s) to subscribe to, supports objects in the form {'topic': qos}

    • opts: any
    • Optional callback: any

    Returns this

    this - for chaining

  • Parameters

    • topic: string | string[] | any
    • Optional callback: any

    Returns this

unsubscribe

  • unsubscribe(topic: string | string[], callback?: any): this
  • unsubscribe - unsubscribe from topic(s)

    api

    public

    example

    client.unsubscribe('topic')

    example

    client.unsubscribe('topic', console.log)

    Parameters

    • topic: string | string[]

      topics to unsubscribe from

    • Optional callback: any

    Returns this

    this - for chaining

Static listenerCount

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

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Generated using TypeDoc