mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-07-02 01:51:38 +00:00
Fix frontend not working when MQTT broker is offline. https://github.com/nurikk/z2m-frontend/issues/589
This commit is contained in:
@@ -19,8 +19,8 @@ class Frontend extends Extension {
|
||||
this.onRequest = this.onRequest.bind(this);
|
||||
this.onUpgrade = this.onUpgrade.bind(this);
|
||||
this.mqttBaseTopic = settings.get().mqtt.base_topic;
|
||||
this.onMQTTPublishedMessage = this.onMQTTPublishedMessage.bind(this);
|
||||
this.mqtt.on('publishedMessage', this.onMQTTPublishedMessage);
|
||||
this.onMQTTPublishMessage = this.onMQTTPublishMessage.bind(this);
|
||||
this.mqtt.on('publishMessage', this.onMQTTPublishMessage);
|
||||
this.onWebSocketConnection = this.onWebSocketConnection.bind(this);
|
||||
this.server = http.createServer(this.onRequest);
|
||||
this.server.on('upgrade', this.onUpgrade);
|
||||
@@ -106,7 +106,7 @@ class Frontend extends Extension {
|
||||
}
|
||||
}
|
||||
|
||||
onMQTTPublishedMessage(data) {
|
||||
onMQTTPublishMessage(data) {
|
||||
let {topic, payload, options} = data;
|
||||
if (topic.startsWith(`${this.mqttBaseTopic}/`)) {
|
||||
// Send topic without base_topic
|
||||
|
||||
+2
-1
@@ -116,6 +116,8 @@ class MQTT extends events.EventEmitter {
|
||||
this.publishedTopics.add(topic);
|
||||
}
|
||||
|
||||
this.emit('publishMessage', {topic, payload, options});
|
||||
|
||||
if (!this.isConnected()) {
|
||||
if (!skipLog) {
|
||||
logger.error(`Not connected to MQTT server!`);
|
||||
@@ -135,7 +137,6 @@ class MQTT extends events.EventEmitter {
|
||||
|
||||
return new Promise((resolve) => {
|
||||
this.client.publish(topic, payload, actualOptions, () => {
|
||||
this.emit('publishedMessage', {topic, payload, options});
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user