mirror of
https://codeberg.org/Far-Open-Auth.en-soln/mqttcsimpl/
synced 2024-08-14 23:53:51 +00:00
.
This commit is contained in:
parent
1f09275d2e
commit
01236ad8fb
3 changed files with 70 additions and 0 deletions
14
.gitignore
vendored
14
.gitignore
vendored
|
@ -130,3 +130,17 @@ dist
|
||||||
.yarn/install-state.gz
|
.yarn/install-state.gz
|
||||||
.pnp.*
|
.pnp.*
|
||||||
|
|
||||||
|
|
||||||
|
# Keys
|
||||||
|
*.crt
|
||||||
|
*.cer
|
||||||
|
*.pem
|
||||||
|
*.pfx
|
||||||
|
*.key
|
||||||
|
*.pub
|
||||||
|
*.p7s
|
||||||
|
*.p7b
|
||||||
|
*.p8
|
||||||
|
*.p12
|
||||||
|
*pub*
|
||||||
|
*sec*
|
||||||
|
|
32
index.html
Normal file
32
index.html
Normal 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
24
index.js
Normal 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!');
|
||||||
|
});
|
Loading…
Reference in a new issue