Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MqttClient

Hierarchy

Index

Constructors

constructor

  • new MqttClient(streamBuilder: function, options: any): MqttClient

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

Methods

end

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

    api

    public

    Parameters

    • Optional force: boolean

      do not wait for all in-flight messages to be acked

    • Optional cb: any

      called when the client has been closed

    Returns this

    this - for chaining

getLastMessageId

  • getLastMessageId(): number

handleMessage

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

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

publish

  • publish(topic: string, message: string | Buffer, opts: any, callback?: any): this
  • publish(topic: string, message: string | Buffer, callback?: any): this
  • publish - publish to

    api

    public

    example

    client.publish('topic', 'message')

    example
    client.publish('topic', 'message', {qos: 1, retain: true})
    example

    client.publish('topic', 'message', console.log)

    Parameters

    • topic: string

      topic to publish to

    • message: string | Buffer

      message to publish

    • opts: any
    • Optional callback: any

    Returns this

    this - for chaining

  • Parameters

    • topic: string
    • message: string | Buffer
    • Optional callback: any

    Returns this

reconnect

  • reconnect(opts?: any): 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

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

Generated using TypeDoc