Skip to content

Commit

Permalink
mqtt bugfix - connection check (tidalcycles#1282)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaxu authored Feb 7, 2025
1 parent cda79f3 commit cf8203a
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions packages/mqtt/mqtt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,10 @@ Pattern.prototype.mqtt = function (
add_meta = true,
) {
const key = host + '-' + client;
let connected = false;
let password_entered = false;

if (!client) {
client = 'strudel-' + String(Math.floor(Math.random() * 1000000));
}
function onConnect() {
console.log('Connected to mqtt broker');
connected = true;
if (password_entered) {
document.cookie = 'mqtt_pass=' + password;
}
Expand All @@ -56,6 +51,9 @@ Pattern.prototype.mqtt = function (
if (connections[key]) {
cx = connections[key];
} else {
if (!client) {
client = 'strudel-' + String(Math.floor(Math.random() * 1000000));
}
cx = new Paho.Client(host, client);
connections[key] = cx;
cx.onConnectionLost = onConnectionLost;
Expand Down Expand Up @@ -86,7 +84,7 @@ Pattern.prototype.mqtt = function (
return this.withHap((hap) => {
const onTrigger = (t_deprecate, hap, currentTime, cps, targetTime) => {
let msg_topic = topic;
if (!connected) {
if (!cx || !cx.isConnected()) {
return;
}
let message = '';
Expand Down

0 comments on commit cf8203a

Please sign in to comment.