| 272 | } |
| 273 | |
| 274 | void CrossPointWebServer::handleClient() { |
| 275 | static unsigned long lastDebugPrint = 0; |
| 276 | |
| 277 | // Check running flag FIRST before accessing server |
| 278 | if (!running) { |
| 279 | return; |
| 280 | } |
| 281 | |
| 282 | // Double-check server pointer is valid |
| 283 | if (!server) { |
| 284 | LOG_DBG("WEB", "WARNING: handleClient called with null server!"); |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | // Print debug every 10 seconds to confirm handleClient is being called |
| 289 | if (millis() - lastDebugPrint > 10000) { |
| 290 | LOG_DBG("WEB", "handleClient active, server running on port %d", port); |
| 291 | lastDebugPrint = millis(); |
| 292 | } |
| 293 | |
| 294 | server->handleClient(); |
| 295 | |
| 296 | // Handle WebSocket events |
| 297 | if (wsServer) { |
| 298 | wsServer->loop(); |
| 299 | } |
| 300 | |
| 301 | // Respond to discovery broadcasts |
| 302 | if (udpActive) { |
| 303 | int packetSize = udp.parsePacket(); |
| 304 | if (packetSize > 0) { |
| 305 | char buffer[16]; |
| 306 | int len = udp.read(buffer, sizeof(buffer) - 1); |
| 307 | if (len > 0) { |
| 308 | buffer[len] = '\0'; |
| 309 | if (strcmp(buffer, "hello") == 0) { |
| 310 | String hostname = WiFi.getHostname(); |
| 311 | if (hostname.isEmpty()) { |
| 312 | hostname = "crosspoint"; |
| 313 | } |
| 314 | String message = "crosspoint (on " + hostname + ");" + String(wsPort); |
| 315 | udp.beginPacket(udp.remoteIP(), udp.remotePort()); |
| 316 | udp.write(reinterpret_cast<const uint8_t*>(message.c_str()), message.length()); |
| 317 | udp.endPacket(); |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | CrossPointWebServer::WsUploadStatus CrossPointWebServer::getWsUploadStatus() const { |
| 325 | WsUploadStatus status; |