feat: WebSocket durch Socket.io

This commit is contained in:
Ismail Ali
2025-06-07 07:32:14 +02:00
parent 368f1ae095
commit a55b5b0189
5 changed files with 587 additions and 317 deletions

View File

@@ -81,6 +81,7 @@ import { cleanupPolylinesForMemory } from "@/utils/polylines/cleanupPolylinesFor
import { cleanupMarkers } from "@/utils/common/cleanupMarkers";
import { monitorHeapAndReload } from "@/utils/common/monitorMemory";
import { monitorHeapWithRedux } from "@/utils/common/monitorMemory";
import { io } from "socket.io-client";
//-----------------------------------------------------------------------------------------------------
const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
//-------------------------------
@@ -795,17 +796,25 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
return () => clearInterval(interval);
}, []);
//--------------------------------------------
const socket = new WebSocket("ws://localhost:3000");
socket.addEventListener("open", () => {
console.log("🟢 WebSocket verbunden");
socket.send(JSON.stringify({ event: "ping", page: window.location.pathname }));
});
useEffect(() => {
const socket = io();
socket.addEventListener("message", event => {
console.log("📨 Nachricht vom Server (Text):", event.data); // kein JSON.parse
});
socket.on("connect", () => {
console.log("🔗 Verbunden mit dem Socket.io Server");
});
socket.on("message", data => {
console.log("📨 Nachricht vom Server:", data);
});
socket.emit("message", { event: "ping", page: window.location.pathname });
return () => {
socket.disconnect();
console.log("🔌 Verbindung getrennt");
};
}, []);
//---------------------------------------------
//--------------------------------------------
return (