packet.js 919 B

123456789101112131415161718192021222324
  1. 'use strict'
  2. function Packet (original, broker) {
  3. if (Object.prototype.hasOwnProperty.call(original, 'clientId')) this.clientId = original.clientId
  4. if (Object.prototype.hasOwnProperty.call(original, 'nl')) this.nl = original.nl
  5. this.cmd = original.cmd || 'publish'
  6. this.brokerId = original.brokerId || (broker && broker.id)
  7. this.brokerCounter = original.brokerCounter || (broker ? (++broker.counter) : 0)
  8. this.topic = original.topic
  9. this.payload = original.payload || Buffer.alloc(0)
  10. this.qos = original.qos || 0
  11. this.retain = original.retain || false
  12. this.dup = original.dup || false
  13. // [MQTT-2.3.1-5]
  14. if (this.qos > 0 || this.cmd !== 'publish') {
  15. // [MQTT-2.3.1-1]
  16. // This is packet identifier uniquely identifies a message as it flows between
  17. // client and broker. It is only relevant for QoS levels greater than 0
  18. this.messageId = undefined
  19. }
  20. }
  21. module.exports = Packet