-
Notifications
You must be signed in to change notification settings - Fork 0
/
broker.js
44 lines (35 loc) · 1.08 KB
/
broker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict'
const aedes = require('aedes')();
const server = require('net').createServer(aedes.handle);
const httpServer = require('http').createServer();
const ws = require('websocket-stream');
const port = 1883;
const wsPort = 8080;
server.listen(port, function () {
console.log('server listening on port', port);
})
ws.createServer({
server: httpServer
}, aedes.handle)
httpServer.listen(wsPort, function () {
console.log('websocket server listening on port', wsPort);
})
aedes.on('clientError', function (client, err) {
console.log('client error', client.id, err.message, err.stack);
})
aedes.on('connectionError', function (client, err) {
console.log('client error', client, err.message, err.stack);
})
aedes.on('publish', function (packet, client) {
if (client) {
console.log('message from client', client.id);
}
})
aedes.on('subscribe', function (subscriptions, client) {
if (client) {
console.log('subscribe from client', subscriptions, client.id);
}
})
aedes.on('client', function (client) {
console.log('new client', client.id);
})