Skip to content

Instantly share code, notes, and snippets.

@stepanmracek
Created March 28, 2019 14:02
Show Gist options
  • Save stepanmracek/9b6d4a6ee9ef9d4d6efe738c069a9577 to your computer and use it in GitHub Desktop.
Save stepanmracek/9b6d4a6ee9ef9d4d6efe738c069a9577 to your computer and use it in GitHub Desktop.
Mosquitto bug report: Unable to connect over webockets with TLS (wss) from Firefox
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>MQTT client</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.js" type="text/javascript"></script>
<script type="text/javascript">
client = new Paho.MQTT.Client("localhost", Number(9001), "/mqtt", "paho-client-" + Math.random().toString(36).substring(2));
console.log(client)
// set callback handlers
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
// connect the client
client.connect({
useSSL: true,
onSuccess: onConnect,
onFailure: onFailure,
userName: 'stepo',
password: 'Some-Password'
});
// called when the client connects
function onConnect() {
// Once a connection has been made, make a subscription and send a message.
console.log("onConnect");
client.subscribe("topic");
message = new Paho.MQTT.Message(client.clientId);
message.destinationName = "topic";
client.send(message);
}
function onFailure(error) {
console.log("connect failed", error);
}
// called when the client loses its connection
function onConnectionLost(responseObject) {
if (responseObject.errorCode !== 0) {
console.log("onConnectionLost: "+responseObject.errorMessage);
}
}
// called when a message arrives
function onMessageArrived(message) {
console.log("onMessageArrived: "+message.payloadString);
}
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment