@vita-mojo/mqtt 1.0.26 → 1.0.28
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/client.cjs.js +19 -1
- package/client.esm.js +19 -1
- package/package.json +1 -1
package/client.cjs.js
CHANGED
|
@@ -173,7 +173,7 @@ function MqttTopic({
|
|
|
173
173
|
}
|
|
174
174
|
});
|
|
175
175
|
const handler = (msgTopic, message) => {
|
|
176
|
-
if (msgTopic
|
|
176
|
+
if (!isTopicMatch(topic, msgTopic)) return;
|
|
177
177
|
try {
|
|
178
178
|
const payload = JSON.parse(message.toString());
|
|
179
179
|
onChange === null || onChange === void 0 ? void 0 : onChange(payload);
|
|
@@ -195,6 +195,24 @@ function MqttTopic({
|
|
|
195
195
|
}, [mqttClient, onChange, qos, topic]);
|
|
196
196
|
return null;
|
|
197
197
|
}
|
|
198
|
+
function isTopicMatch(filter, topic) {
|
|
199
|
+
const filterParts = filter.split('/');
|
|
200
|
+
const topicParts = topic.split('/');
|
|
201
|
+
for (let i = 0; i < filterParts.length; i++) {
|
|
202
|
+
const filterPart = filterParts[i];
|
|
203
|
+
const topicPart = topicParts[i];
|
|
204
|
+
if (filterPart === '#') {
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
if (filterPart === '+') {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
if (filterPart !== topicPart) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return filterParts.length === topicParts.length;
|
|
215
|
+
}
|
|
198
216
|
|
|
199
217
|
exports.MQTTReconnect = MQTTReconnect;
|
|
200
218
|
exports.MqttProvider = MqttProvider;
|
package/client.esm.js
CHANGED
|
@@ -165,7 +165,7 @@ function MqttTopic({
|
|
|
165
165
|
}
|
|
166
166
|
});
|
|
167
167
|
const handler = (msgTopic, message) => {
|
|
168
|
-
if (msgTopic
|
|
168
|
+
if (!isTopicMatch(topic, msgTopic)) return;
|
|
169
169
|
try {
|
|
170
170
|
const payload = JSON.parse(message.toString());
|
|
171
171
|
onChange === null || onChange === void 0 ? void 0 : onChange(payload);
|
|
@@ -187,5 +187,23 @@ function MqttTopic({
|
|
|
187
187
|
}, [mqttClient, onChange, qos, topic]);
|
|
188
188
|
return null;
|
|
189
189
|
}
|
|
190
|
+
function isTopicMatch(filter, topic) {
|
|
191
|
+
const filterParts = filter.split('/');
|
|
192
|
+
const topicParts = topic.split('/');
|
|
193
|
+
for (let i = 0; i < filterParts.length; i++) {
|
|
194
|
+
const filterPart = filterParts[i];
|
|
195
|
+
const topicPart = topicParts[i];
|
|
196
|
+
if (filterPart === '#') {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
if (filterPart === '+') {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
if (filterPart !== topicPart) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return filterParts.length === topicParts.length;
|
|
207
|
+
}
|
|
190
208
|
|
|
191
209
|
export { MQTTReconnect, MqttProvider, MqttTopic, useMqtt };
|