node-red-contrib-aedes 1.1.0 → 1.2.0
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/CHANGELOG.md +4 -0
- package/README.md +3 -2
- package/aedes.html +15 -0
- package/aedes.js +296 -103
- package/locales/de/aedes.json +5 -1
- package/locales/en-US/aedes.json +5 -1
- package/package.json +1 -1
- package/test/aedes_persist_spec.js +777 -0
- package/test/aedes_qos_spec.js +5 -12
- package/test/aedes_retain_spec.js +5 -138
- package/test/aedes_spec.js +3 -6
- package/test/aedes_ws_spec.js +4 -9
package/test/aedes_qos_spec.js
CHANGED
|
@@ -5,6 +5,7 @@ const aedesNode = require('../aedes.js');
|
|
|
5
5
|
const mqttNode = require('../node_modules/node-red/node_modules/@node-red/nodes/core/network/10-mqtt.js');
|
|
6
6
|
const mqtt = require('mqtt');
|
|
7
7
|
const should = require('should');
|
|
8
|
+
const { logError } = require('./test-utils');
|
|
8
9
|
|
|
9
10
|
helper.init(require.resolve('node-red'));
|
|
10
11
|
|
|
@@ -55,16 +56,12 @@ describe('Aedes Broker QOS tests', function () {
|
|
|
55
56
|
const n1 = helper.getNode('n1');
|
|
56
57
|
n1._initPromise.then(function () {
|
|
57
58
|
const client1 = mqtt.connect('mqtt://localhost:1883', { clientId: 'client1' });
|
|
58
|
-
client1.on('error',
|
|
59
|
-
console.error('Error: ', err.toString());
|
|
60
|
-
});
|
|
59
|
+
client1.on('error', logError);
|
|
61
60
|
client1.on('connect', function () {
|
|
62
61
|
// console.log('External client1 connected');
|
|
63
62
|
});
|
|
64
63
|
const client2 = mqtt.connect('mqtt://localhost:1883', { clientId: 'client2', clean: false });
|
|
65
|
-
client2.on('error',
|
|
66
|
-
console.error('Error: ', err.toString());
|
|
67
|
-
});
|
|
64
|
+
client2.on('error', logError);
|
|
68
65
|
client2.on('connect', function () {
|
|
69
66
|
// console.log('External client2 connected');
|
|
70
67
|
client2.subscribe('test1883', { qos: 1 }, function (err, granted) {
|
|
@@ -124,16 +121,12 @@ describe('Aedes Broker QOS tests', function () {
|
|
|
124
121
|
const n1 = helper.getNode('n1');
|
|
125
122
|
n1._initPromise.then(function () {
|
|
126
123
|
const client1 = mqtt.connect('mqtt://localhost:1883', { clientId: 'client1' });
|
|
127
|
-
client1.on('error',
|
|
128
|
-
console.error('Error: ', err.toString());
|
|
129
|
-
});
|
|
124
|
+
client1.on('error', logError);
|
|
130
125
|
client1.on('connect', function () {
|
|
131
126
|
// console.log('External client1 connected');
|
|
132
127
|
});
|
|
133
128
|
const client2 = mqtt.connect('mqtt://localhost:1883', { clientId: 'client2', clean: false });
|
|
134
|
-
client2.on('error',
|
|
135
|
-
console.error('Error: ', err.toString());
|
|
136
|
-
});
|
|
129
|
+
client2.on('error', logError);
|
|
137
130
|
client2.on('connect', function () {
|
|
138
131
|
// console.log('External client2 connected');
|
|
139
132
|
client2.subscribe('test1883', { qos: 2 }, function (err, granted) {
|
|
@@ -5,6 +5,7 @@ const aedesNode = require('../aedes.js');
|
|
|
5
5
|
const mqttNode = require('../node_modules/node-red/node_modules/@node-red/nodes/core/network/10-mqtt.js');
|
|
6
6
|
const mqtt = require('mqtt');
|
|
7
7
|
const should = require('should');
|
|
8
|
+
const { logError } = require('./test-utils');
|
|
8
9
|
|
|
9
10
|
helper.init(require.resolve('node-red'));
|
|
10
11
|
|
|
@@ -56,12 +57,8 @@ describe('Aedes Broker retain tests', function () {
|
|
|
56
57
|
n1._initPromise.then(function () {
|
|
57
58
|
const client1 = mqtt.connect('mqtt://localhost:1883', { clientId: 'client1' });
|
|
58
59
|
const client2 = mqtt.connect('mqtt://localhost:1883', { clientId: 'client2' });
|
|
59
|
-
client1.on('error',
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
client2.on('error', function (err) {
|
|
63
|
-
console.error('Error: ', err.toString());
|
|
64
|
-
});
|
|
60
|
+
client1.on('error', logError);
|
|
61
|
+
client2.on('error', logError);
|
|
65
62
|
client1.on('connect', function () {
|
|
66
63
|
// console.log('External client1 connected');
|
|
67
64
|
client1.publish('test1883', 'test', { retain: true }, function () {
|
|
@@ -123,12 +120,8 @@ describe('Aedes Broker retain tests', function () {
|
|
|
123
120
|
n1._initPromise.then(function () {
|
|
124
121
|
const client1 = mqtt.connect('mqtt://localhost:1883', { clientId: 'client1' });
|
|
125
122
|
const client2 = mqtt.connect('mqtt://localhost:1883', { clientId: 'client2' });
|
|
126
|
-
client1.on('error',
|
|
127
|
-
|
|
128
|
-
});
|
|
129
|
-
client2.on('error', function (err) {
|
|
130
|
-
console.error('Error: ', err.toString());
|
|
131
|
-
});
|
|
123
|
+
client1.on('error', logError);
|
|
124
|
+
client2.on('error', logError);
|
|
132
125
|
client2.on('connect', function () {
|
|
133
126
|
// console.log('External client2 connected');
|
|
134
127
|
});
|
|
@@ -170,130 +163,4 @@ describe('Aedes Broker retain tests', function () {
|
|
|
170
163
|
});
|
|
171
164
|
});
|
|
172
165
|
});
|
|
173
|
-
|
|
174
|
-
/*
|
|
175
|
-
|
|
176
|
-
it('a publisher (retain = true) should send a message', function (done) {
|
|
177
|
-
this.timeout(10000); // have to wait for the inject with delay of 10 seconds
|
|
178
|
-
const flow = [
|
|
179
|
-
{
|
|
180
|
-
id: 'n1',
|
|
181
|
-
type: 'aedes broker',
|
|
182
|
-
mqtt_port: '1883',
|
|
183
|
-
persistence_bind: 'level',
|
|
184
|
-
name: 'Aedes 1883',
|
|
185
|
-
wires: [
|
|
186
|
-
['n2'], []
|
|
187
|
-
]
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
id: 'n2',
|
|
191
|
-
type: 'helper'
|
|
192
|
-
}
|
|
193
|
-
];
|
|
194
|
-
|
|
195
|
-
helper.load([aedesNode, mqttNode], flow, function () {
|
|
196
|
-
const client1 = mqtt.connect('mqtt://localhost:1883', { clientId: 'client1' });
|
|
197
|
-
client1.on('error', function (err) {
|
|
198
|
-
console.error('Error: ', err.toString());
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
client1.on('connect', function () {
|
|
202
|
-
// console.log('External client1 connected');
|
|
203
|
-
client1.subscribe('test1883', function (err, granted) {
|
|
204
|
-
// console.log('Subscription successful ' + JSON.stringify(granted));
|
|
205
|
-
if (err) {
|
|
206
|
-
console.error('Error subscribing');
|
|
207
|
-
done();
|
|
208
|
-
}
|
|
209
|
-
client1.publish('test1883', 'Retained Message', { retain: true }, function () {
|
|
210
|
-
// console.log('Published Retained Message');
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
const n2 = helper.getNode('n2');
|
|
214
|
-
let counter = 0;
|
|
215
|
-
n2.on('input', function (msg) {
|
|
216
|
-
// console.log('Broker received message topic: ' + msg.topic + ', clientid: ' + msg.payload.client.id);
|
|
217
|
-
if (msg.topic === 'subscribe') {
|
|
218
|
-
// console.log('Client ' + msg.payload.client.id + ' subscribed ' + JSON.stringify(msg.payload.client.subscriptions));
|
|
219
|
-
} else if (msg.topic === 'clientReady') {
|
|
220
|
-
// console.log('Client ' + msg.payload.client.id + ' connected with clean ' + msg.payload.client.clean);
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
client1.on('message', function (topic, message) {
|
|
224
|
-
if (counter === 0) {
|
|
225
|
-
counter++;
|
|
226
|
-
} else {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
console.log(message.toString());
|
|
230
|
-
should(topic.toString()).equal('test1883');
|
|
231
|
-
should(message.toString()).equal('Retained Message');
|
|
232
|
-
try {
|
|
233
|
-
client1.end(true, {}, function () {
|
|
234
|
-
done();
|
|
235
|
-
});
|
|
236
|
-
} catch (err) {
|
|
237
|
-
done(err);
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it('a subscriber (retain = true) should receive the last message on first subscribe after restart', function (done) {
|
|
245
|
-
this.timeout(10000); // have to wait for the inject with delay of 10 seconds
|
|
246
|
-
const flow = [
|
|
247
|
-
{
|
|
248
|
-
id: 'n1',
|
|
249
|
-
type: 'aedes broker',
|
|
250
|
-
mqtt_port: '1883',
|
|
251
|
-
persistence_bind: 'level',
|
|
252
|
-
name: 'Aedes 1883',
|
|
253
|
-
wires: [
|
|
254
|
-
['n2']
|
|
255
|
-
]
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
id: 'n2',
|
|
259
|
-
type: 'helper'
|
|
260
|
-
}
|
|
261
|
-
];
|
|
262
|
-
|
|
263
|
-
helper.load([aedesNode, mqttNode], flow, function () {
|
|
264
|
-
const client1 = mqtt.connect('mqtt://localhost:1883', { clientId: 'client1' });
|
|
265
|
-
client1.on('error', function (err) {
|
|
266
|
-
console.error('Error: ', err.toString());
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
client1.on('connect', function () {
|
|
270
|
-
// console.log('External client1 connected');
|
|
271
|
-
client1.subscribe('test1883', function (err, granted) {
|
|
272
|
-
// console.log('Subscription successful ' + JSON.stringify(granted));
|
|
273
|
-
if (err) {
|
|
274
|
-
console.error('Error subscribing');
|
|
275
|
-
done();
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
const n2 = helper.getNode('n2');
|
|
280
|
-
n2.on('input', function (msg) {
|
|
281
|
-
// console.log('Broker received message topic: ' + msg.topic + ', clientid: ' + msg.payload.client.id);
|
|
282
|
-
if (msg.topic === 'subscribe') {
|
|
283
|
-
// console.log('Client ' + msg.payload.client.id + ' subscribed ' + JSON.stringify(msg.payload.client.subscriptions));
|
|
284
|
-
} else if (msg.topic === 'clientReady') {
|
|
285
|
-
// console.log('Client ' + msg.payload.client.id + ' connected with clean ' + msg.payload.client.clean);
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
client1.on('message', function (topic, message) {
|
|
289
|
-
// console.log(message.toString());
|
|
290
|
-
should(topic.toString()).equal('test1883');
|
|
291
|
-
should(message.toString()).equal('Retained Message');
|
|
292
|
-
client1.end(true, {}, function () {
|
|
293
|
-
done();
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
*/
|
|
299
166
|
});
|
package/test/aedes_spec.js
CHANGED
|
@@ -5,6 +5,7 @@ const aedesNode = require('../aedes.js');
|
|
|
5
5
|
const mqttNode = require('../node_modules/node-red/node_modules/@node-red/nodes/core/network/10-mqtt.js');
|
|
6
6
|
const mqtt = require('mqtt');
|
|
7
7
|
const should = require('should');
|
|
8
|
+
const { logError } = require('./test-utils');
|
|
8
9
|
|
|
9
10
|
const credentialsOK = { n1: { username: 'test', password: 'test' }, b1: { user: 'test', password: 'test' } };
|
|
10
11
|
const credentialsMissing = { n1: { username: 'test', password: 'test' }, b1: { user: 'test' } };
|
|
@@ -354,9 +355,7 @@ describe('Aedes Broker TCP tests', function () {
|
|
|
354
355
|
const n1 = helper.getNode('n1');
|
|
355
356
|
n1._initPromise.then(function () {
|
|
356
357
|
const client = mqtt.connect('mqtt://localhost:1883', { clientId: 'client', resubscribe: false, reconnectPeriod: -1 });
|
|
357
|
-
client.on('error',
|
|
358
|
-
console.error('Error: ', err.toString());
|
|
359
|
-
});
|
|
358
|
+
client.on('error', logError);
|
|
360
359
|
client.on('connect', function () {
|
|
361
360
|
// console.log('External client connected');
|
|
362
361
|
});
|
|
@@ -410,9 +409,7 @@ describe('Aedes Broker TCP tests', function () {
|
|
|
410
409
|
const n1 = helper.getNode('n1');
|
|
411
410
|
n1._initPromise.then(function () {
|
|
412
411
|
const client = mqtt.connect('mqtt://localhost:1883', { clientId: 'client', resubscribe: false, reconnectPeriod: -1 });
|
|
413
|
-
client.on('error',
|
|
414
|
-
console.error('Error: ', err.toString());
|
|
415
|
-
});
|
|
412
|
+
client.on('error', logError);
|
|
416
413
|
client.on('connect', function () {
|
|
417
414
|
// console.log('External client connected');
|
|
418
415
|
});
|
package/test/aedes_ws_spec.js
CHANGED
|
@@ -4,6 +4,7 @@ const helper = require('node-red-node-test-helper');
|
|
|
4
4
|
const aedesNode = require('../aedes.js');
|
|
5
5
|
const mqttNode = require('../node_modules/node-red/node_modules/@node-red/nodes/core/network/10-mqtt.js');
|
|
6
6
|
const mqtt = require('mqtt');
|
|
7
|
+
const { logError } = require('./test-utils');
|
|
7
8
|
|
|
8
9
|
helper.init(require.resolve('node-red'));
|
|
9
10
|
|
|
@@ -41,9 +42,7 @@ describe('Aedes Broker Websocket tests', function () {
|
|
|
41
42
|
resubscribe: false,
|
|
42
43
|
reconnectPeriod: -1
|
|
43
44
|
});
|
|
44
|
-
client.on('error',
|
|
45
|
-
console.error('Error: ', err.toString());
|
|
46
|
-
});
|
|
45
|
+
client.on('error', logError);
|
|
47
46
|
const n2 = helper.getNode('n2');
|
|
48
47
|
n2.on('input', function (msg) {
|
|
49
48
|
if (msg.topic === 'clientReady') {
|
|
@@ -158,9 +157,7 @@ describe('Aedes Broker Websocket tests', function () {
|
|
|
158
157
|
const n1 = helper.getNode('n1');
|
|
159
158
|
n1._initPromise.then(function () {
|
|
160
159
|
const client = mqtt.connect('ws://localhost:8080', { clientId: 'client', resubscribe: false, reconnectPeriod: -1 });
|
|
161
|
-
client.on('error',
|
|
162
|
-
console.error('Error: ', err.toString());
|
|
163
|
-
});
|
|
160
|
+
client.on('error', logError);
|
|
164
161
|
client.on('connect', function () {
|
|
165
162
|
// console.log('External client connected');
|
|
166
163
|
});
|
|
@@ -224,9 +221,7 @@ describe('Aedes Broker Websocket tests', function () {
|
|
|
224
221
|
const n1 = helper.getNode('n1');
|
|
225
222
|
n1._initPromise.then(function () {
|
|
226
223
|
const client = mqtt.connect(helper.url().replace(/http/, 'ws') + '/mqtt', { clientId: 'client', resubscribe: false, reconnectPeriod: -1 });
|
|
227
|
-
client.on('error',
|
|
228
|
-
console.error('Client on error: ', err.toString());
|
|
229
|
-
});
|
|
224
|
+
client.on('error', logError);
|
|
230
225
|
client.on('connect', function () {
|
|
231
226
|
// console.log('External client connected');
|
|
232
227
|
});
|