mqtt-plus 1.4.22 → 1.4.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mqtt-plus",
3
- "version": "1.4.22",
3
+ "version": "1.4.23",
4
4
  "description": "MQTT Communication Patterns",
5
5
  "keywords": [ "mqtt",
6
6
  "event", "emit",
@@ -28,6 +28,7 @@ import { type MqttClient,
28
28
  type IClientSubscribeOptions,
29
29
  type IClientPublishOptions,
30
30
  type IPublishPacket } from "mqtt"
31
+ import { nanoid } from "nanoid"
31
32
 
32
33
  /* internal requirements */
33
34
  import type { APISchema, Registration } from "./mqtt-plus-api"
@@ -79,6 +80,19 @@ export class BaseTrait<T extends APISchema = APISchema> extends TraceTrait<T> {
79
80
  /* store MQTT client */
80
81
  this.mqtt = mqtt
81
82
 
83
+ /* resolve the instance "id": if the user did not provide an
84
+ explicit one, fetch the "clientId" from the underlying MQTT
85
+ client, and only as a last resort fall back to a generated id
86
+ (e.g. for the fake proxy MQTT client without a real clientId) */
87
+ if (this.options.id === "") {
88
+ const clientId = (mqtt as any).isFakeProxy
89
+ ? undefined
90
+ : mqtt.options?.clientId
91
+ this.options.id = (typeof clientId === "string" && clientId !== "")
92
+ ? clientId
93
+ : nanoid()
94
+ }
95
+
82
96
  /* hook into the MQTT message processing */
83
97
  this.log("info", "hooking into MQTT client")
84
98
  this.messageHandler = (topic, message, packet) => {
@@ -22,9 +22,6 @@
22
22
  ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
24
 
25
- /* external requirements */
26
- import { nanoid } from "nanoid"
27
-
28
25
  /* internal requirements */
29
26
  import type { APISchema } from "./mqtt-plus-api"
30
27
 
@@ -55,7 +52,7 @@ export class OptionsTrait<_T extends APISchema = APISchema> {
55
52
  ) {
56
53
  /* determine options and provide defaults */
57
54
  this.options = {
58
- id: nanoid(),
55
+ id: "", /* intentionally resolved later in BaseTrait */
59
56
  codec: "cbor",
60
57
  timeout: 10 * 1000,
61
58
  share: "",