Skip to content

Latest commit

 

History

History
156 lines (96 loc) · 4.92 KB

Client.md

File metadata and controls

156 lines (96 loc) · 4.92 KB

Client

new Client(aedes, stream, request)

  • aedes <Aedes>
  • stream: <net.Socket> | <stream.Duplex>
  • request: <http.IncomingMessage>
  • Returns: <Client>

client.conn

  • <net.Socket> | <stream.Duplex>

Client connection stream object.

In the case of net.createServer, conn passed to the connectionlistener function by node's net.createServer API.

In the case of websocket-stream, it's the stream argument passed to the websocket handle function in websocket-stream #on-the-server].

client.req

  • <http.IncomingMessage>

only for websocket-stream. It is a HTTP Websocket upgrade request object passed to websocket handle function in websocket-stream #on-the-server. It gives an option for accessing headers or cookies.

client.connecting

  • <boolean> Default: false

a read-only flag, it is true when Client is in CONNECT phase. Aedes emits connackSent event will not reset connecting to false until it received all its offline messagess to the Client.

client.connected

  • <boolean> Default: false

a read-only flag, it is true when connected event is emitted, and false when client is closed.

client.closed

  • <boolean> Default: false

a read-only flag indicates if client is closed or not.

client.id

  • <string> Default: aedes_${hyperid()}

Client unique identifier, specified by CONNECT packet.

It is available only after CONNACK (rc=0), otherwise it is null in cases:

  • in aedes.preConnect stage
  • after CONNACK (rc!=0) response
  • connectionError raised by aedes

client.clean

  • <boolean> Default: true

Client clean flag, set by clean flag in CONNECT packet.

client.version

  • <number> Default: null

Client version, set by protocol version in CONNECT packet when CONNACK (rc=0) returns.

Event: connected

Same as aedes clientReady but in client-wise.

Event: error

  • error <Error>

Emitted when an error occurs.

client.publish (packet, [callback])

  • packet <object> PUBLISH
  • callback <Function> (error) => void
    • error <Error> | null

Publish the given packet to this client. QoS 1 and 2 are fully supported, while the retained flag is not.

callback  will be invoked when the message has been sent, but not acked.

client.subscribe (subscriptions, [callback])

  • subscriptions <object>
  • callback <Function> (error) => void
    • error <Error> | null

Subscribe client to the list of topics.

subscriptions can be:

  1. a single object in the format { topic: topic, qos: qos }
  2. an array of the above
  3. a full SUBSCRIBE, specifying a messageId will send suback to the client.

callback  will be invoked when the subscription is completed.

client.unsubscribe (unsubscriptions, [callback])

  • unsubscriptions <object>
  • callback <Function> (error) => void
    • error <Error> | null

Unsubscribe client to the list of topics.

unsubscriptions can be:

  1. a single object in the format { topic: topic, qos: qos }
  2. an array of the above
  3. a full UNSUBSCRIBE

callback  will be invoked when the unsubscriptions are completed.

client.close ([callback])

Disconnect client

callback will be invoked when client is closed.

client.emptyOutgoingQueue ([callback])

Clear all outgoing messages (QoS > 1) related to this client from persistence

callback will be invoked when the operation ends.