From ca1a9ee3dec28a117d4bf23ceac4885284adf09a Mon Sep 17 00:00:00 2001 From: ni00 Date: Thu, 28 Sep 2023 14:45:22 +0800 Subject: [PATCH 1/2] fix(cli):fix topic-alias-maximum error in cli connect --- cli/src/utils/parse.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cli/src/utils/parse.ts b/cli/src/utils/parse.ts index aa7cbbc48..4c2f3e08e 100644 --- a/cli/src/utils/parse.ts +++ b/cli/src/utils/parse.ts @@ -247,7 +247,7 @@ const parseConnectOptions = ( Object.entries(willProperties).filter(([_, v]) => v !== null && v !== undefined), )) } - + let optionsTempWorkAround if (mqttVersion === 3) { connectOptions.protocolId = 'MQIsdp' } else if (mqttVersion === 5) { @@ -274,9 +274,15 @@ const parseConnectOptions = ( connectOptions.properties = Object.fromEntries( Object.entries(properties).filter(([_, v]) => v !== null && v !== undefined), ) + // Map options.properties.topicAliasMaximum to options.topicAliasMaximum, as that is where MQTT.js looks for it. + // TODO: remove after bug fixed in MQTT.js v5. + optionsTempWorkAround = Object.assign( + { topicAliasMaximum: connectOptions.properties ? connectOptions.properties.topicAliasMaximum : undefined }, + connectOptions, + ) } - return connectOptions + return optionsTempWorkAround || connectOptions } const parsePublishOptions = (options: PublishOptions) => { From f41502a447a0a104634ce7c088e377e35b66d511 Mon Sep 17 00:00:00 2001 From: ni00 Date: Thu, 28 Sep 2023 15:11:36 +0800 Subject: [PATCH 2/2] fix(cli):multisend only send topic once when topic-alias is exist --- cli/src/lib/pub.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cli/src/lib/pub.ts b/cli/src/lib/pub.ts index 6b106209b..cfd1689ab 100644 --- a/cli/src/lib/pub.ts +++ b/cli/src/lib/pub.ts @@ -95,10 +95,13 @@ const multisend = ( const sender = new Writable({ objectMode: true, }) + let count = 0 sender._write = (line, _enc, cb) => { const { topic, opts, protobufPath, protobufMessageName, format } = pubOpts + count++ + let omitTopic = opts.properties?.topicAlias && count >= 2 const publishMessage = processPublishMessage(line.trim(), protobufPath, protobufMessageName, format) - client.publish(topic, publishMessage, opts, cb) + client.publish(omitTopic ? '' : topic, publishMessage, opts, cb) } client.on('connect', () => {