feat: WebSocket durch Socket.io
This commit is contained in:
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user