Skip to content

Commit a88cc63

Browse files
authored
MQTT fixes and improvements via aws-crt update (#135)
Update brings: - **IMPROVEMENT**: The MQTT `on_message` event, and the topic-specific callback passed to `subscribe()`, have added `dup`, `qos`, and `retain` params. - **IMPROVEMENT**: Outgoing MQTT `Payload` type now accepts `ArrayBuffer` and any `ArrayBufferView` (ex: `Uint8Array`) type. - **BUGFIX**: `on_message` payload typescript signature changed from `Buffer` to `ArrayBuffer`. - This is a semi-breaking change. There were two callback passing payloads, one signature claimed to pass `ArrayBuffer` payloads and the other claimed to pass `Buffer` payloads. In reality the node implementation always passed `ArrayBuffer` and the browser implementation always passed `Buffer`. Now, both callbacks share a signature, they both claim to pass `ArrayBuffer` and both the node and browser implementations **actually do** pass `ArrayBuffer` - **BUGFIX**: browser MQTT `publish()` no longer tries to turn everything to strings. `ArrayBuffer` and `ArrayBufferView` types will pass their bytes straight through. - **BUGFIX**: browser MQTT `unsubscribe()`
1 parent 6f896f4 commit a88cc63

File tree

7 files changed

+546
-462
lines changed

7 files changed

+546
-462
lines changed

package-lock.json

Lines changed: 198 additions & 149 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
"typescript": "^3.9.7"
3131
},
3232
"dependencies": {
33-
"aws-crt": "1.3.8"
33+
"aws-crt": "1.5.1"
3434
}
3535
}

samples/node/basic_discovery/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ async function execute_session(connection: mqtt.MqttClientConnection, argv: Args
147147
try {
148148
const decoder = new TextDecoder('utf8');
149149
if (argv.mode == 'both' || argv.mode == 'subscribe') {
150-
const on_publish = (topic: string, payload: ArrayBuffer) => {
150+
const on_publish = (topic: string, payload: ArrayBuffer, dup: boolean, qos: mqtt.QoS, retain: boolean) => {
151151
const json = decoder.decode(payload);
152-
console.log(`Publish received on topic ${topic}`);
152+
console.log(`Publish received. topic:"${topic}" dup:${dup} qos:${qos} retain:${retain}`);
153153
console.log(json);
154154
const message = JSON.parse(json);
155155
if (message.sequence == argv.max_pub_ops) {

samples/node/basic_discovery/package-lock.json

Lines changed: 96 additions & 83 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/node/fleet_provisioning/package-lock.json

Lines changed: 154 additions & 145 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/node/pub_sub/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ async function execute_session(connection: mqtt.MqttClientConnection, argv: Args
108108
return new Promise(async (resolve, reject) => {
109109
try {
110110
const decoder = new TextDecoder('utf8');
111-
const on_publish = async (topic: string, payload: ArrayBuffer) => {
111+
const on_publish = async (topic: string, payload: ArrayBuffer, dup: boolean, qos: mqtt.QoS, retain: boolean) => {
112112
const json = decoder.decode(payload);
113-
console.log(`Publish received on topic ${topic}`);
113+
console.log(`Publish received. topic:"${topic}" dup:${dup} qos:${qos} retain:${retain}`);
114114
console.log(json);
115115
const message = JSON.parse(json);
116116
if (message.sequence == argv.count) {

samples/node/pub_sub/package-lock.json

Lines changed: 93 additions & 80 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)