mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-16 10:04:30 +01:00
chat backend
This commit is contained in:
@@ -44,16 +44,23 @@ void setup()
|
|||||||
webServerPlugin->server->serveStatic(PIXEL_CONFIG_FILE, SPIFFS, "pixelConfig.json");
|
webServerPlugin->server->serveStatic(PIXEL_CONFIG_FILE, SPIFFS, "pixelConfig.json");
|
||||||
webServerPlugin->server->serveStatic(MQTT_CONFIG_FILE, SPIFFS, "mqttConfig.json");
|
webServerPlugin->server->serveStatic(MQTT_CONFIG_FILE, SPIFFS, "mqttConfig.json");
|
||||||
|
|
||||||
const char* mqttChatTopic = (String(MQTT_ROOT_TOPIC) + "/out/chat/log").c_str();
|
const char* mqChatTopic = "wirelos/chat/log";
|
||||||
sprocket->subscribe("chat/log", [mqttChatTopic](String msg) {
|
const char* outChatTopic = "out/chat/log";
|
||||||
PRINT_MSG(Serial, "CHAT", msg.c_str());
|
const char* chatUser = "user";
|
||||||
});
|
|
||||||
sprocket->subscribe("mqtt/connect", [mqttChatTopic](String msg) {
|
sprocket->subscribe("mqtt/connect", [mqChatTopic, outChatTopic, chatUser](String msg) {
|
||||||
if (msg.length() > 0)
|
if (msg.length() > 0)
|
||||||
{
|
{
|
||||||
mqttPlugin->client->subscribe(mqttChatTopic);
|
mqttPlugin->client->subscribe(mqChatTopic);
|
||||||
sprocket->subscribe("/out/chat/log", [](String msg) {
|
sprocket->subscribe(mqChatTopic, [](String msg) {
|
||||||
PRINT_MSG(Serial, "CHAT", String("incoming: " + msg).c_str());
|
PRINT_MSG(Serial, "CHAT", String("incoming: " + msg).c_str());
|
||||||
|
webApiPlugin->ws->textAll(msg);
|
||||||
|
});
|
||||||
|
|
||||||
|
// send message from WS to this topic
|
||||||
|
sprocket->subscribe(outChatTopic, [mqChatTopic, chatUser](String msg) {
|
||||||
|
PRINT_MSG(Serial, "CHAT", msg.c_str());
|
||||||
|
mqttPlugin->client->publish(mqChatTopic, (String(chatUser) + ": " + msg).c_str());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user