@faybl/client 4.1.2 → 4.1.4
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/README.md +6 -2
- package/package.json +1 -1
- package/src/auth.js +2 -3
- package/src/mqttUtils.js +10 -3
package/README.md
CHANGED
|
@@ -98,7 +98,9 @@ Changes are published on the bus as they happen:
|
|
|
98
98
|
gets `{ entity, operation, rid, record }`, where `record` is the whole record as read after the
|
|
99
99
|
change, or `{}` for a delete.
|
|
100
100
|
- `conf.subscribeWithAck(...)` takes the same and returns `{ ready, unsubscribe }`; `ready` resolves
|
|
101
|
-
once the broker has acknowledged the subscription, and rejects if
|
|
101
|
+
once the broker has acknowledged the subscription, and rejects only if the broker refused it. A
|
|
102
|
+
connection that closes first is waited out: the subscription is asked for again on the
|
|
103
|
+
reconnect.
|
|
102
104
|
- `conf.unsubscribe({ entity, operation, rid, callback })`. Without a callback it removes every
|
|
103
105
|
callback on that subscription.
|
|
104
106
|
|
|
@@ -174,7 +176,9 @@ subscription may be a filter with wildcards.
|
|
|
174
176
|
- `mqttClient.subscribe(topic, callback, { qos })` returns the function that undoes it. The
|
|
175
177
|
callback gets `{ topic, data }`, with `data` parsed from JSON.
|
|
176
178
|
- `mqttClient.subscribeWithAck(topic, callback, { qos })` returns `{ ready, unsubscribe }`; `ready`
|
|
177
|
-
resolves once the broker has granted the QoS asked for, 0 by default
|
|
179
|
+
resolves once the broker has granted the QoS asked for, 0 by default, and rejects only if it
|
|
180
|
+
refused, as above. Several subscriptions to one topic share one acknowledgement, and the topic
|
|
181
|
+
keeps the strictest QoS asked for.
|
|
178
182
|
- `mqttClient.unsubscribe(topic, callback)`. Without a callback it removes every callback on the
|
|
179
183
|
topic.
|
|
180
184
|
|
package/package.json
CHANGED
package/src/auth.js
CHANGED
|
@@ -5,9 +5,8 @@ export const getAuthApi = (authenticatorUrl, http) => {
|
|
|
5
5
|
if (!authenticatorUrl) return missingEndpoint('authenticatorUrl');
|
|
6
6
|
return fetchCheckedJson(
|
|
7
7
|
`${authenticatorUrl}/getUserInfo`,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
},
|
|
8
|
+
// The request is JSON, so it carries a body even without arguments.
|
|
9
|
+
{ method: 'POST', body: JSON.stringify({}) },
|
|
11
10
|
http,
|
|
12
11
|
);
|
|
13
12
|
};
|
package/src/mqttUtils.js
CHANGED
|
@@ -103,13 +103,20 @@ export const createMqttHandler = (client, { report = () => undefined } = {}) =>
|
|
|
103
103
|
return () => unsubscribe(topic, callback);
|
|
104
104
|
};
|
|
105
105
|
|
|
106
|
+
// Only the broker can refuse a subscription. An error instead of a SUBACK means the connection
|
|
107
|
+
// closed first, so the request is made again once it reconnects, rather than failing. A client
|
|
108
|
+
// that is being closed rejects. MQTT.js counts the topic as held from the first attempt and would
|
|
109
|
+
// answer a plain retry at once with no grants; `resubscribe`, the flag it uses for its own
|
|
110
|
+
// resubscriptions, makes it send the SUBSCRIBE so the retry waits for the broker's answer.
|
|
106
111
|
const requestAcknowledgement = (topic, qos) =>
|
|
107
112
|
new Promise((resolve, reject) => {
|
|
108
|
-
|
|
109
|
-
if (error) return reject(error);
|
|
113
|
+
const answer = (error, granted) => {
|
|
114
|
+
if (error) return client.disconnecting ? reject(error) : client.once('connect', retry);
|
|
110
115
|
const refusal = subscriptionRefusal(topic, qos, grantedQos(granted, topic));
|
|
111
116
|
return refusal ? reject(refusal) : resolve();
|
|
112
|
-
}
|
|
117
|
+
};
|
|
118
|
+
const retry = () => client.subscribe({ [topic]: { qos }, resubscribe: true }, answer);
|
|
119
|
+
client.subscribe(topic, { qos }, answer);
|
|
113
120
|
});
|
|
114
121
|
|
|
115
122
|
const acknowledgementFor = (topic, qos) => {
|