399b015c9fafe5e8dba8f68f9b3c7bb38ed6acc5b4d2ddc9451181cfc7b5266f80b3cdeb84ed89077957aee7113691699acb21e4edc46290c0bf381a1da76d 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import { MqttClient } from './client'
  2. import { Store } from './store'
  3. import { ClientOptions } from 'ws'
  4. import { ClientRequestArgs } from 'http'
  5. import { QoS, UserProperties } from 'mqtt-packet'
  6. import { IMessageIdProvider } from './message-id-provider'
  7. export declare type StorePutCallback = () => void
  8. export interface IClientOptions extends ISecureClientOptions {
  9. port?: number // port is made into a number subsequently
  10. host?: string // host does NOT include port
  11. hostname?: string
  12. path?: string
  13. protocol?: 'wss' | 'ws' | 'mqtt' | 'mqtts' | 'tcp' | 'ssl' | 'wx' | 'wxs'
  14. wsOptions?: ClientOptions | ClientRequestArgs
  15. /**
  16. * 10 seconds, set to 0 to disable
  17. */
  18. keepalive?: number
  19. /**
  20. * 'mqttjs_' + Math.random().toString(16).substr(2, 8)
  21. */
  22. clientId?: string
  23. /**
  24. * 'MQTT'
  25. */
  26. protocolId?: string
  27. /**
  28. * 4
  29. */
  30. protocolVersion?: number
  31. /**
  32. * true, set to false to receive QoS 1 and 2 messages while offline
  33. */
  34. clean?: boolean
  35. /**
  36. * 1000 milliseconds, interval between two reconnections
  37. */
  38. reconnectPeriod?: number
  39. /**
  40. * 30 * 1000 milliseconds, time to wait before a CONNACK is received
  41. */
  42. connectTimeout?: number
  43. /**
  44. * the username required by your broker, if any
  45. */
  46. username?: string
  47. /**
  48. * the password required by your broker, if any
  49. */
  50. password?: string
  51. /**
  52. * a Store for the incoming packets
  53. */
  54. incomingStore?: Store
  55. /**
  56. * a Store for the outgoing packets
  57. */
  58. outgoingStore?: Store
  59. queueQoSZero?: boolean
  60. reschedulePings?: boolean
  61. servers?: Array<{
  62. host: string
  63. port: number
  64. protocol?: 'wss' | 'ws' | 'mqtt' | 'mqtts' | 'tcp' | 'ssl' | 'wx' | 'wxs'
  65. }>
  66. /**
  67. * true, set to false to disable re-subscribe functionality
  68. */
  69. resubscribe?: boolean
  70. /**
  71. * a message that will sent by the broker automatically when the client disconnect badly.
  72. */
  73. will?: {
  74. /**
  75. * the topic to publish
  76. */
  77. topic: string
  78. /**
  79. * the message to publish
  80. */
  81. payload: Buffer | string
  82. /**
  83. * the QoS
  84. */
  85. qos: QoS
  86. /**
  87. * the retain flag
  88. */
  89. retain: boolean,
  90. /*
  91. * properies object of will
  92. * */
  93. properties?: {
  94. willDelayInterval?: number,
  95. payloadFormatIndicator?: boolean,
  96. messageExpiryInterval?: number,
  97. contentType?: string,
  98. responseTopic?: string,
  99. correlationData?: Buffer,
  100. userProperties?: UserProperties
  101. }
  102. }
  103. transformWsUrl?: (url: string, options: IClientOptions, client: MqttClient) => string,
  104. properties?: {
  105. sessionExpiryInterval?: number,
  106. receiveMaximum?: number,
  107. maximumPacketSize?: number,
  108. topicAliasMaximum?: number,
  109. requestResponseInformation?: boolean,
  110. requestProblemInformation?: boolean,
  111. userProperties?: UserProperties,
  112. authenticationMethod?: string,
  113. authenticationData?: Buffer
  114. },
  115. messageIdProvider?: IMessageIdProvider
  116. }
  117. export interface ISecureClientOptions {
  118. /**
  119. * optional private keys in PEM format
  120. */
  121. key?: string | string[] | Buffer | Buffer[] | Object[]
  122. /**
  123. * optional cert chains in PEM format
  124. */
  125. cert?: string | string[] | Buffer | Buffer[]
  126. /**
  127. * Optionally override the trusted CA certificates in PEM format
  128. */
  129. ca?: string | string[] | Buffer | Buffer[]
  130. rejectUnauthorized?: boolean
  131. /**
  132. * optional alpn's
  133. */
  134. ALPNProtocols?: string[] | Buffer[] | Uint8Array[] | Buffer | Uint8Array
  135. }
  136. export interface IClientPublishOptions {
  137. /**
  138. * the QoS
  139. */
  140. qos?: QoS
  141. /**
  142. * the retain flag
  143. */
  144. retain?: boolean
  145. /**
  146. * whether or not mark a message as duplicate
  147. */
  148. dup?: boolean
  149. /*
  150. * MQTT 5.0 properties object
  151. */
  152. properties?: {
  153. payloadFormatIndicator?: boolean,
  154. messageExpiryInterval?: number,
  155. topicAlias?: number,
  156. responseTopic?: string,
  157. correlationData?: Buffer,
  158. userProperties?: UserProperties,
  159. subscriptionIdentifier?: number,
  160. contentType?: string
  161. }
  162. /**
  163. * callback called when message is put into `outgoingStore`
  164. */
  165. cbStorePut?: StorePutCallback
  166. }
  167. export interface IClientSubscribeOptions {
  168. /**
  169. * the QoS
  170. */
  171. qos: QoS,
  172. /*
  173. * no local flag
  174. * */
  175. nl?: boolean,
  176. /*
  177. * Retain As Published flag
  178. * */
  179. rap?: boolean,
  180. /*
  181. * Retain Handling option
  182. * */
  183. rh?: number,
  184. /*
  185. * MQTT 5.0 properies object of subscribe
  186. * */
  187. properties?: {
  188. subscriptionIdentifier?: number,
  189. userProperties?: UserProperties
  190. }
  191. }
  192. export interface IClientReconnectOptions {
  193. /**
  194. * a Store for the incoming packets
  195. */
  196. incomingStore?: Store
  197. /**
  198. * a Store for the outgoing packets
  199. */
  200. outgoingStore?: Store
  201. }