- Alle Services (ae.js, de.js, da.js, kueData.js, Start.js, System.js, opcua.js) laden ihre Scripte abhängig von der Umgebung - Vermeidet unnötige globale Script-Ladung über loadWindowVariables.ts - Reduziert Netzwerklast und verbessert Modularität und Performance
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
// ✅ 1. Service: /services/fetchOpcUaSettings.ts
|
|
|
|
export const fetchOpcUaSettings = async () => {
|
|
try {
|
|
if (typeof window === "undefined") return null;
|
|
|
|
// ✅ opcua.js nur bei Bedarf nachladen (Pfad abhängig von Umgebung)
|
|
const scriptSrc =
|
|
process.env.NODE_ENV === "production"
|
|
? "/CPL?/CPL/SERVICE/opcua.js"
|
|
: "/CPLmockData/SERVICE/opcua.js";
|
|
|
|
await new Promise<void>((resolve, reject) => {
|
|
const script = document.createElement("script");
|
|
script.src = scriptSrc;
|
|
script.async = true;
|
|
script.onload = () => resolve();
|
|
script.onerror = () => reject("❌ Fehler beim Laden von opcua.js");
|
|
document.body.appendChild(script);
|
|
});
|
|
|
|
const win = window as any;
|
|
|
|
const data = {
|
|
zustand: win.win_opcUaZustand || "Offline",
|
|
encryption: win.win_opcUaEncryption || "None",
|
|
clientCount: win.win_opcUaActiveClientCount || 0,
|
|
nodesetName: win.win_opcUaNodesetName || "DefaultNodeset",
|
|
users: Array.isArray(win.win_opcUaUsers) ? win.win_opcUaUsers : [],
|
|
};
|
|
|
|
return data;
|
|
} catch (error) {
|
|
console.error("Fehler beim Laden der OPC UA Daten:", error);
|
|
return null;
|
|
}
|
|
};
|