This commit is contained in:
Captain Nick Lucifer* 2023-03-12 12:24:20 +05:45
parent 1f09275d2e
commit 01236ad8fb
3 changed files with 70 additions and 0 deletions

14
.gitignore vendored
View file

@ -130,3 +130,17 @@ dist
.yarn/install-state.gz
.pnp.*
# Keys
*.crt
*.cer
*.pem
*.pfx
*.key
*.pub
*.p7s
*.p7b
*.p8
*.p12
*pub*
*sec*

32
index.html Normal file
View file

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Testing</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://unpkg.com/mqtt@4.3.7/dist/mqtt.min.js"></script> <!-- Load client mqtt via CDN. -->
</head>
<body>
<script type="module">
const mqtt = require('mqtt')
const client = mqtt.connect('mqtt://mosquitto.domain.tld') // testoo
client.on('connect', function () {
client.subscribe('presence', function (err) {
if (!err) {
client.publish('presence', 'Hello mqtt')
}
})
})
client.on('message', function (topic, message) {
// message is Buffer
console.log(message.toString())
client.end()
})
</script>
</body>
</html>

24
index.js Normal file
View file

@ -0,0 +1,24 @@
var fs = require('fs');
var mqttServer = require('mqtt-server');
// TODO: impl. custom/own ports/etc..
var servers = mqttServer({
mqtt: 'tcp://localhost:1883',
mqtts: 'ssl://localhost:8883',
mqttws: 'ws://localhost:1884',
mqtwss: 'wss://localhost:8884'
}, {
ssl: {
key: fs.readFileSync('./server.key'), // sec.pk-gen script TODO.
cert: fs.readFileSync('./server.crt')
},
emitEvents: true // default
}, function(client) {
client.connack({
returnCode: 0
});
});
servers.listen(function() {
console.log('listening!');
});