websocket alle Links

This commit is contained in:
Ismail Ali
2025-06-08 10:21:19 +02:00
parent db54cc7cca
commit fbffc82e1b
8 changed files with 2018 additions and 45 deletions

View File

@@ -801,7 +801,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
const params = new URLSearchParams(window.location.search);
const m = params.get("m");
const u = params.get("u");
const mode = process.env.NEXT_PUBLIC_USE_MOCKS === "true" ? "mock" : "prod";
const mode = process.env.NEXT_PUBLIC_USE_MOCKS === "true" ? "mock" : "live";
const socket = io({
query: { m, u, mode },
@@ -811,10 +811,26 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
console.log("🔗 WebSocket verbunden (Modus:", mode, ")");
});
socket.on("gisLinesStatusUpdated", data => {
socket.on("GisLinesStatusUpdated", data => {
dispatch(fetchGisLinesStatusThunk(data));
});
socket.on("GisStationsMeasurementsUpdated", data => {
dispatch(fetchGisStationsMeasurementsThunk(data));
});
socket.on("GisStationsStaticDistrictUpdated", data => {
dispatch(fetchGisStationsStaticDistrictThunk(data));
});
socket.on("GisStationsStatusDistrictUpdated", data => {
dispatch(fetchGisStationsStatusDistrictThunk(data));
});
socket.on("GisSystemStaticUpdated", data => {
dispatch(fetchGisSystemStaticThunk(data));
});
return () => {
socket.disconnect();
};

View File

@@ -1,2 +1,2 @@
// /config/appVersion
export const APP_VERSION = "1.1.246";
export const APP_VERSION = "1.1.247";

129
server.js
View File

@@ -1,9 +1,9 @@
// server.js
const { createServer } = require("http");
const next = require("next");
const { Server } = require("socket.io");
const fs = require("fs");
const path = require("path");
const { saveJsonIfChanged } = require("./utils/websocket/saveJsonIfChanged");
const fs = require("fs");
const fetch = (...args) => import("node-fetch").then(({ default: fetch }) => fetch(...args));
const dev = process.env.NODE_ENV !== "production";
@@ -11,6 +11,21 @@ const app = next({ dev });
const handle = app.getRequestHandler();
const PORT = 3000;
// Hilfsfunktion zum Schreiben von JSON-Dateien bei Änderung
const writeJsonFile = (filename, data) => {
const dir = path.join(process.cwd(), "websocketDump");
if (!fs.existsSync(dir)) fs.mkdirSync(dir);
const fullPath = path.join(dir, filename);
fs.writeFileSync(fullPath, JSON.stringify(data, null, 2), "utf-8");
};
// Extrahiert relevante Datenstruktur aus Antwort
const extractData = (json, name) => {
return (
json?.Statis || json?.Points || json?.Systems || json?.Rights || json?.[name] || json || []
);
};
app.prepare().then(() => {
const server = createServer((req, res) => {
handle(req, res);
@@ -19,53 +34,83 @@ app.prepare().then(() => {
const io = new Server(server);
io.on("connection", socket => {
const { m, mode } = socket.handshake.query;
const idMap = m;
const isLiveMode = mode === "live" || mode === "prod";
const { m: idMap, u: idUser, mode } = socket.handshake.query;
const isLiveMode = mode === "live";
console.log(`🔌 WebSocket verbunden (idMap=${idMap}, idUser=${idUser}, mode=${mode})`);
let lastStatis = [];
const endpoints = [
{
name: "GisLinesStatus",
getUrl: () => `WebServiceMap.asmx/GisLinesStatus?idMap=${idMap}`,
mock: "GisLinesStatus.json",
},
{
name: "GisStationsMeasurements",
getUrl: () => `WebServiceMap.asmx/GisStationsMeasurements?idMap=${idMap}`,
mock: "GisStationsMeasurements.json",
},
{
name: "GisStationsStaticDistrict",
getUrl: () =>
`WebServiceMap.asmx/GisStationsStaticDistrict?idMap=${idMap}&idUser=${idUser}`,
mock: "GisStationsStaticDistrict.json",
},
{
name: "GisStationsStatusDistrict",
getUrl: () =>
`WebServiceMap.asmx/GisStationsStatusDistrict?idMap=${idMap}&idUser=${idUser}`,
mock: "GisStationsStatusDistrict.json",
},
{
name: "GisSystemStatic",
getUrl: () => `WebServiceMap.asmx/GisSystemStatic?idMap=${idMap}&idUser=${idUser}`,
mock: "GisSystemStatic.json",
},
];
const lastDataMap = {};
const fetchData = async () => {
try {
let statis;
for (const { name, getUrl, mock } of endpoints) {
try {
let statis;
if (dev) {
const mockPath = path.join(process.cwd(), "mockData", "GisLinesStatus.json");
const jsonStr = fs.readFileSync(mockPath, "utf-8");
const json = JSON.parse(jsonStr);
statis = json?.Statis || [];
console.log("🧪 Mockdaten gelesen");
} else {
const fetchUrl = `http://localhost/talas5/ClientData/WebServiceMap.asmx/GisLinesStatus?idMap=${idMap}`;
const res = await fetch(fetchUrl);
const text = await res.text();
if (!text.startsWith("{")) {
console.error("❌ Webservice liefert kein valides JSON:", text.slice(0, 100));
return;
}
const json = JSON.parse(text);
statis = json?.Statis || [];
console.log("📡 Webservice-Daten empfangen");
//------------------------------------
// Änderung prüfen
const hasChanged = saveJsonIfChanged(json, lastStatis);
if (hasChanged) {
// socket.emit("gisLinesStatusUpdated", statis);
console.log("✅ Änderung erkannt und gesendet");
if (dev) {
const mockPath = path.join(process.cwd(), "mockData", mock);
const jsonStr = fs.readFileSync(mockPath, "utf-8");
const json = JSON.parse(jsonStr);
statis = extractData(json, name);
console.log(`🧪 [Mock] ${name}`);
} else {
console.log("🔁 Keine Änderung festgestellt");
const fetchUrl = `http://localhost/talas5/ClientData/${getUrl()}`;
const res = await fetch(fetchUrl);
const text = await res.text();
let json;
try {
json = JSON.parse(text);
} catch (err) {
console.error(`${name}: JSON Parsing fehlgeschlagen:`, err.message);
console.error(`🔍 Antwort war:`, text.slice(0, 300));
continue;
}
statis = extractData(json, name);
console.log(`📡 Webservice-Daten empfangen für ${name}`);
}
//------------------------------------
return;
const newDataStr = JSON.stringify(statis);
if (newDataStr !== lastDataMap[name]) {
lastDataMap[name] = newDataStr;
socket.emit(`${name}Updated`, statis);
console.log(`✅ Änderung bei ${name} erkannt → gesendet`);
writeJsonFile(`${name}.json`, statis);
} else {
console.log(`🔁 ${name}: Keine Änderung`);
}
} catch (error) {
console.error(`❌ Fehler bei ${name}:`, error.message);
}
// Nur bei Mockdaten: direkt senden
socket.emit("gisLinesStatusUpdated", statis);
} catch (error) {
console.error("❌ Fehler beim Datenabruf:", error.message);
}
};
@@ -80,6 +125,6 @@ app.prepare().then(() => {
});
server.listen(PORT, () => {
console.log(`🚀 App + Socket.io läuft auf http://localhost:${PORT}`);
console.log(`🚀 App + WebSocket läuft auf http://localhost:${PORT}`);
});
});

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,112 @@
[
{
"IdLD": 50937,
"IdL": 24101,
"IdDP": 3,
"Na": "FBT",
"Val": "6",
"Unit": "°C",
"Gr": "GMA",
"Area_Name": "Rastede"
},
{
"IdLD": 50937,
"IdL": 24101,
"IdDP": 10,
"Na": "GT",
"Val": "-2.14",
"Unit": "°C",
"Gr": "GMA",
"Area_Name": "Rastede"
},
{
"IdLD": 50937,
"IdL": 24101,
"IdDP": 2,
"Na": "LT",
"Val": "0.21",
"Unit": "°C",
"Gr": "GMA",
"Area_Name": "Rastede"
},
{
"IdLD": 50937,
"IdL": 24101,
"IdDP": 6,
"Na": "RLF",
"Val": "77.54",
"Unit": "%",
"Gr": "GMA",
"Area_Name": "Rastede"
},
{
"IdLD": 50937,
"IdL": 24101,
"IdDP": 4,
"Na": "RS",
"Val": "30.33",
"Unit": "%",
"Gr": "GMA",
"Area_Name": "Rastede"
},
{
"IdLD": 50937,
"IdL": 24101,
"IdDP": 11,
"Na": "TPT",
"Val": "2.99",
"Unit": "°C",
"Gr": "GMA",
"Area_Name": "Rastede"
},
{
"IdLD": 50937,
"IdL": 24101,
"IdDP": 12,
"Na": "TT1",
"Val": "0.1245",
"Unit": "°C",
"Gr": "GMA",
"Area_Name": "Rastede"
},
{
"IdLD": 50937,
"IdL": 24101,
"IdDP": 16,
"Na": "WFD",
"Val": "0.211",
"Unit": "mm",
"Gr": "GMA",
"Area_Name": "Rastede"
},
{
"IdLD": 50937,
"IdL": 24101,
"IdDP": 8,
"Na": "WGM",
"Val": "0.5",
"Unit": "m/s",
"Gr": "GMA",
"Area_Name": "Rastede"
},
{
"IdLD": 50937,
"IdL": 24101,
"IdDP": 9,
"Na": "WGS",
"Val": "0.75",
"Unit": "m/s",
"Gr": "GMA",
"Area_Name": "Rastede"
},
{
"IdLD": 50937,
"IdL": 24101,
"IdDP": 7,
"Na": "WR",
"Val": "180",
"Unit": "°",
"Gr": "GMA",
"Area_Name": "Rastede"
}
]

View File

@@ -0,0 +1,155 @@
[
{
"LD_Name": "CPL Ismael",
"IdLD": 50922,
"Device": "CPL V3.5 mit 24 Kü",
"Link": "cpl.aspx?ver=35&kue=24&id=50922",
"Location_Name": "Littwin",
"Location_Short": "LTW",
"IdLocation": 24101,
"Area_Name": "Rastede",
"Area_Short": "",
"IdArea": 20998,
"X": 53.243954,
"Y": 8.160439,
"Icon": 20,
"System": 1,
"Active": 1
},
{
"LD_Name": "LR 77 ISA",
"IdLD": 50935,
"Device": "LTE Modem LR77",
"Link": "lr77.aspx?ver=1&id=50935",
"Location_Name": "Littwin",
"Location_Short": "LTW",
"IdLocation": 24101,
"Area_Name": "Rastede",
"Area_Short": "",
"IdArea": 20998,
"X": 53.243954,
"Y": 8.160439,
"Icon": 12,
"System": 5,
"Active": 1
},
{
"LD_Name": "Cisco Router 1841",
"IdLD": 50936,
"Device": "Cisco 1841",
"Link": "cisco1841.aspx?ver=1&id=50936",
"Location_Name": "Littwin",
"Location_Short": "LTW",
"IdLocation": 24101,
"Area_Name": "Rastede",
"Area_Short": "",
"IdArea": 20998,
"X": 53.243954,
"Y": 8.160439,
"Icon": 21,
"System": 6,
"Active": 1
},
{
"LD_Name": "GMA Testgerät ISA",
"IdLD": 50937,
"Device": "Glättemeldeanlage",
"Link": "gma.aspx?ver=1&id=50937",
"Location_Name": "Littwin",
"Location_Short": "LTW",
"IdLocation": 24101,
"Area_Name": "Rastede",
"Area_Short": "",
"IdArea": 20998,
"X": 53.243954,
"Y": 8.160439,
"Icon": 1,
"System": 11,
"Active": 1
},
{
"LD_Name": "SMS-Funkmodem",
"IdLD": 50938,
"Device": "SMS Funkmodem",
"Link": "sms_modem.aspx?ver=1&id=50938",
"Location_Name": "Littwin",
"Location_Short": "LTW",
"IdLocation": 24101,
"Area_Name": "Rastede",
"Area_Short": "",
"IdArea": 20998,
"X": 53.243954,
"Y": 8.160439,
"Icon": 12,
"System": 111,
"Active": 1
},
{
"LD_Name": "TALAS Meldestationen ISA",
"IdLD": 50939,
"Device": "CPL V3.5 mit 16 Kü",
"Link": "cpl.aspx?ver=35&kue=16&id=50939",
"Location_Name": "Littwin",
"Location_Short": "LTW",
"IdLocation": 24101,
"Area_Name": "Rastede",
"Area_Short": "",
"IdArea": 20998,
"X": 53.243954,
"Y": 8.160439,
"Icon": 20,
"System": 1,
"Active": 1
},
{
"LD_Name": "WAGO Klemmen ISA",
"IdLD": 50941,
"Device": "WAGO 16 DE",
"Link": "wago.aspx?ver=1&DE=16&id=50941",
"Location_Name": "Littwin",
"Location_Short": "LTW",
"IdLocation": 24101,
"Area_Name": "Rastede",
"Area_Short": "",
"IdArea": 20998,
"X": 53.243954,
"Y": 8.160439,
"Icon": 9,
"System": 7,
"Active": 1
},
{
"LD_Name": "Cisco 1921",
"IdLD": 50942,
"Device": "Cisco 1921",
"Link": "cisco1921.aspx?ver=1&id=50942",
"Location_Name": "Littwin",
"Location_Short": "LTW",
"IdLocation": 24101,
"Area_Name": "Rastede",
"Area_Short": "",
"IdArea": 20998,
"X": 53.243954,
"Y": 8.160439,
"Icon": 21,
"System": 6,
"Active": 1
},
{
"LD_Name": "Cisco 8200",
"IdLD": 50943,
"Device": "Cisco 8200",
"Link": "cisco8200.aspx?ver=1&id=50943",
"Location_Name": "Littwin",
"Location_Short": "LTW",
"IdLocation": 24101,
"Area_Name": "Rastede",
"Area_Short": "",
"IdArea": 20998,
"X": 53.243954,
"Y": 8.160439,
"Icon": 21,
"System": 6,
"Active": 1
}
]

View File

@@ -0,0 +1,101 @@
[
{
"IdLD": 50922,
"Na": "system",
"Le": 4,
"Co": "#FF00FF",
"Me": "Eingang DE 01 kommend",
"Feld": 4,
"Icon": 0
},
{
"IdLD": 50922,
"Na": "system",
"Le": 4,
"Co": "#FF00FF",
"Me": "Eingang DE 05 kommend",
"Feld": 4,
"Icon": 0
},
{
"IdLD": 50922,
"Na": "system",
"Le": 4,
"Co": "#FF00FF",
"Me": "Eingang DE 17 kommend",
"Feld": 4,
"Icon": 0
},
{
"IdLD": 50922,
"Na": "system",
"Le": 4,
"Co": "#FF00FF",
"Me": "Eingang DE 31 kommend",
"Feld": 4,
"Icon": 0
},
{
"IdLD": 50922,
"Na": "system",
"Le": 4,
"Co": "#FF00FF",
"Me": "Eingang DE 32 kommend",
"Feld": 4,
"Icon": 0
},
{
"IdLD": 50922,
"Na": "system",
"Le": 4,
"Co": "#FF00FF",
"Me": "Station offline",
"Feld": 4,
"Icon": 0
},
{
"IdLD": 50922,
"Na": "minor",
"Le": 3,
"Co": "#FFFF00",
"Me": "Eingang DE 02 kommend",
"Feld": 4,
"Icon": 0
},
{
"IdLD": 50922,
"Na": "minor",
"Le": 3,
"Co": "#FFFF00",
"Me": "KÜG 08: Überspannung gehend",
"Feld": 4,
"Icon": 0
},
{
"IdLD": 50922,
"Na": "major",
"Le": 2,
"Co": "#FF9900",
"Me": "Eingang DE 03 kommend",
"Feld": 4,
"Icon": 0
},
{
"IdLD": 50922,
"Na": "critical",
"Le": 1,
"Co": "#FF0000",
"Me": "KÜG 02: Aderbruch kommend",
"Feld": 4,
"Icon": 0
},
{
"IdLD": 50922,
"Na": "critical",
"Le": 1,
"Co": "#FF0000",
"Me": "KÜG 03: Aderbruch kommend",
"Feld": 4,
"Icon": 0
}
]

View File

@@ -0,0 +1,114 @@
[
{
"IdSystem": 1,
"Name": "TALAS",
"Longname": "Talas Meldestationen",
"Allow": 1,
"Icon": 1
},
{
"IdSystem": 2,
"Name": "ECI",
"Longname": "ECI Geräte",
"Allow": 1,
"Icon": 2
},
{
"IdSystem": 3,
"Name": "ULAF",
"Longname": "ULAF Geräte",
"Allow": 0,
"Icon": 3
},
{
"IdSystem": 5,
"Name": "GSM Modem",
"Longname": "LR77 GSM Modems",
"Allow": 1,
"Icon": 5
},
{
"IdSystem": 6,
"Name": "Cisco Router",
"Longname": "Cisco Router",
"Allow": 1,
"Icon": 6
},
{
"IdSystem": 7,
"Name": "WAGO",
"Longname": "WAGO I/O Systeme",
"Allow": 1,
"Icon": 7
},
{
"IdSystem": 8,
"Name": "Siemens",
"Longname": "Siemens Notrufsysteme",
"Allow": 1,
"Icon": 8
},
{
"IdSystem": 9,
"Name": "OTDR",
"Longname": "Glasfaserüberwachung OTU",
"Allow": 1,
"Icon": 9
},
{
"IdSystem": 10,
"Name": "WDM",
"Longname": " Wavelength Division Multiplexing",
"Allow": 1,
"Icon": 10
},
{
"IdSystem": 11,
"Name": "GMA",
"Longname": "Glättemeldeanlagen",
"Allow": 1,
"Icon": 11
},
{
"IdSystem": 13,
"Name": "Messstellen",
"Longname": "Messstellen",
"Allow": 0,
"Icon": 13
},
{
"IdSystem": 30,
"Name": "TK-Komponenten",
"Longname": "TK-Komponenten",
"Allow": 1,
"Icon": 30
},
{
"IdSystem": 100,
"Name": "TALAS ICL",
"Longname": "Talas ICL Unterstationen",
"Allow": 1,
"Icon": 100
},
{
"IdSystem": 110,
"Name": "DAUZ",
"Longname": "Dauerzählstellen",
"Allow": 1,
"Icon": 110
},
{
"IdSystem": 111,
"Name": "SMS Modem",
"Longname": "SMS Modem",
"Allow": 1,
"Icon": 111
},
{
"IdSystem": 200,
"Name": "Sonstige",
"Longname": "Sonstige",
"Allow": 1,
"Icon": 200
}
]