mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-14 17:35:22 +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(MQTT_CONFIG_FILE, SPIFFS, "mqttConfig.json");
|
||||
|
||||
const char* mqttChatTopic = (String(MQTT_ROOT_TOPIC) + "/out/chat/log").c_str();
|
||||
sprocket->subscribe("chat/log", [mqttChatTopic](String msg) {
|
||||
PRINT_MSG(Serial, "CHAT", msg.c_str());
|
||||
});
|
||||
sprocket->subscribe("mqtt/connect", [mqttChatTopic](String msg) {
|
||||
const char* mqChatTopic = "wirelos/chat/log";
|
||||
const char* outChatTopic = "out/chat/log";
|
||||
const char* chatUser = "user";
|
||||
|
||||
sprocket->subscribe("mqtt/connect", [mqChatTopic, outChatTopic, chatUser](String msg) {
|
||||
if (msg.length() > 0)
|
||||
{
|
||||
mqttPlugin->client->subscribe(mqttChatTopic);
|
||||
sprocket->subscribe("/out/chat/log", [](String msg) {
|
||||
mqttPlugin->client->subscribe(mqChatTopic);
|
||||
sprocket->subscribe(mqChatTopic, [](String msg) {
|
||||
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