refactor: Naming-Konventionen für digitaleEingaenge umgesetzt
- digitaleEingaengeMockData.js = strukturierte Datenbasis für Development - digitaleEingaengeAPIHandler.ts = API-Endpunkt zur Auslieferung im Dev - fetchDigitaleEingaengeService.ts = Service zur Umwandlung von window-Variablen - Naming-Schema sorgt für klare Struktur und gute Lernbarkeit
This commit is contained in:
37
services/fetchOpcUaSettingsService.ts
Normal file
37
services/fetchOpcUaSettingsService.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
// ✅ 1. Service: /services/fetchOpcUaSettingsService.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.NEXT_PUBLIC_NODE_ENV === "production"
|
||||
? "/CPL?/CPL/SERVICE/opcua.js"
|
||||
: "/apiMockData/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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user