我正在尝试让 Aedes 充当 MQTT 代理和 Websocket 服务器。根据该文档:https ://github.com/moscajs/aedes/blob/master/docs/Examples.md 我想了解的内容。理想情况下,无论是 websocket 客户端还是 mqtt 客户端,我都希望监听器启动。
是否可以执行以下操作:
server.broadcast('foo/bar', {data:''})
并且所有客户端、websockets 和 mqtt 都会收到消息?该文档不是很清楚,我对使用 websocket-stream 感到非常惊讶。lvl很低吧?
这里有一些服务器端代码:
const port = 1883
const aedes = require('aedes')({
persistence: mongoPersistence({
url: 'mongodb://127.0.0.1/aedes-test',
// Optional ttl settings
ttl: {
packets: 300, // Number of seconds
subscriptions: 300
}
}),
authenticate: (client, username, password, callback) => {
},
authorizePublish: (client, packet, callback) => {
},
authorizeSubscribe: (client, packet, callback) => {
}
});
//const server = require('net').createServer(aedes.handle);
const httpServer = require('http').createServer()
const ws = require('websocket-stream')
ws.createServer({ server: httpServer }, aedes.handle)
httpServer.listen(port, function () {
Logger.debug('Aedes listening on port: ' + port)
aedes.publish({ topic: 'aedes/hello', payload: "I'm broker " + aedes.id })
});