'use strict'; var exampleSocket; var SelBranchVal = ""; var connectedToServer = false; var assetType = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]; // Todo Eintraege beim fuellen erstellen. var buildingsArr = []; var assetsArrBsm = []; var assetsArrBcu = []; var assetsArrIpsIn = []; var assetsArrIpsOut = []; var assetsArrCameraIn = []; var assetsArrCameraOut = []; var assetsArrMdu = []; var assetsArrEgcu = []; var assetsArrAnnouncements = []; var assetsArrBuildingNetworkSwitch = []; var mountPointArr = []; var objectArr = []; var buildingId = -1; var tempType = 1; var collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" }); function sortEntries(a, b) { return collator.compare(a.designation, b.designation); } function WebSocketTest() { if ("WebSocket" in window) { { var ipadresse = document.getElementById("ipadresse").value; exampleSocket = new WebSocket("ws://" + ipadresse); connectedToServer = true; } exampleSocket.onopen = function () { document.getElementById("Serverconnect").innerHTML = "Server: connected"; document.getElementById("Serverconnect").style.color = "green" document.getElementById('selectAsset').value = 1; }; //wird immer aufgerufen wenn der Socket eine Nachricht vom Server empfängt exampleSocket.onmessage = function (event) { var msg = JSON.parse(event.data); console.log (JSON.stringify(msg)); console.log (JSON.stringify(event)); switch (msg.type) { case "plannedMountings": var planNames = []; msg.data.forEach(element => { planNames.push(element.designation); }); document.getElementById("planList").innerHTML = planNames.join(", "); document.getElementById("planRawData").innerHTML = event.data; break; case "essentials": var typeNames = []; msg.data.assetTypes.forEach(element => { typeNames.push(element.designation); }); document.getElementById("typeList").innerHTML = typeNames.join(", "); var buildingNetworkSwitchCount = 0; msg.data.mountingPoints.forEach(mountingPoint => { mountingPoint.supportedAssetTypeIds.forEach(typeId => { if (typeId == 14) ++buildingNetworkSwitch; }); }); document.getElementById("buildingNetworkSwitchCount").innerHTML = buildingNetworkSwitchCount; document.getElementById("essentialsRawData").innerHTML = event.data; case "assets": var buildingNetworkSwitchAssetCount = 0; msg.data.forEach(asset => { if (asset.assetTypeId == 14) ++buildingNetworkSwitchAssetCount; }); document.getElementById("buildingNetworkSwitchAssetCount").innerHTML = buildingNetworkSwitchAssetCount; document.getElementById("assetRawData").innerHTML = event.data; default: break; } }; exampleSocket.onclose = function () { // websocket is closed. document.getElementById("Serverconnect").innerHTML = "Server: not connected"; document.getElementById("Serverconnect").style.color = "grey"; document.getElementById("Wlsconnect").innerHTML = "Wls: not connected"; document.getElementById("Wlsconnect").style.color = "red"; connectedToServer = false; alert("Connection to Server closed."); }; } else { // The browser doesn't support WebSocket alert("WebSocket is NOT supported by your Browser!"); } } function checkedBuilding(rObj) { //array der radiobuttons abfragen clearAssetArrays(); setBuilding(rObj.value); return false; } function findIdByDesignation(arr, designation) { for (var i = 0; i < arr.length; i++) { if (designation == arr[i].designation) { return arr[i].id; } } return -1; } async function setBuilding(building) { buildingId = findIdByDesignation(objectArr, building); document.getElementById("BuildingTable").innerHTML = building; sendGetAssets();//schickt anfragen an den Server sendGetEssentials(); sendGetBuildingState(); show('mountAssets'); } function sendMount() { var mountingPointId = String(mount_mountingPointId.value); var assetId = String(mount_assetId.value); if (mountingPointId.length == 0) mountingPointId = null; else mountingPointId = Number(mountingPointId); if (assetId.length == 0) assetId = null; else assetId = Number(assetId); message = JSON.stringify({ type: "mount", uuid: "UUID", data: { mountingPointId: mountingPointId, assetId: assetId } }); exampleSocket.send(message); sendGetAssets(); sendGetBuildingState(); sendGetEssentials(); } function sendGetPlannedMountings() { exampleSocket.send(JSON.stringify({ type: "getPlannedMountings", uuid: "UUID_GET_PLANNED_MOUNTINGS", data: null })); } function sendMountTag() { //console.log("sendMountTag "); var mountingPointTag = String(mountTag_mountingPointTag.value); //console.log(mountTag_mountingPointTag.value); if (mountingPointTag.length == 0) mountingPointTag = null; var assetTag = String(mountTag_assetTag.value); if (assetTag.length == 0) assetTag = null; exampleSocket.send(JSON.stringify({ type: "mountTag", uuid: "UUID", data: { mountingPointTag: mountingPointTag, assetTag: assetTag } })); } function sendUnmountAsset() { //console.log("sendUnmountAsset "); exampleSocket.send(JSON.stringify({ type: "unmountAsset", uuid: "UUID", data: { assetId: Number(unmountAsset_assetId.value) } })); sendGetEssentials(); sendGetBuildingState(); sendGetAssets(); } function sendUnmountMountingPoint() { //console.log("sendUnmountMountingPoint "); exampleSocket.send(JSON.stringify({ type: "unmountMountingPoint", uuid: "UUID", data: { mountingPointId: Number(unmountMountingPoint_mountingPointId.value) } })); sendGetEssentials(); sendGetBuildingState(); sendGetAssets(); } //---------noch nicht funktionsfähig/getestet----------// function sendUnmountObject() { //console.log("sendUnmountObject ");js/infrastructure.js:219 exampleSocket.send(JSON.stringify({ type: "unmountObject", uuid: "UUID", data: { objectId: Number(unmountObject_objectId.value) } })); } function sendUnmountArea() { //console.log("sendUnmountArea "); exampleSocket.send(JSON.stringify({ type: "unmountArea", uuid: "UUID", data: { areaId: Number(unmountArea_areaId.value) } })); } function sendObjectMountingReady() { //console.log("sendObjectMountingReady "); exampleSocket.send(JSON.stringify({ type: "objectMountingReady", uuid: "UUID", data: { plannedMountingId: Number(objectMountingReady_plannedMountingId.value), objectId: Number(objectMountingReady_objectId.value) } })); } function sendGetAssetState() { var assetTag = String(getAssetState_assetTag.value); if (assetTag.length == 0) assetTag = null; exampleSocket.send(JSON.stringify({ type: "getAssetState", uuid: "UUID", data: { assetId: Number(getAssetState_assetId.value), assetTag: assetTag } })); } function sendGetBuildingStateManually() { //console.log("sendGetBuildingState "); exampleSocket.send(JSON.stringify({ type: "getBuildingState", uuid: "UUID", data: { buildingId: Number(getBuildingState_buildingId.value) } })); } function sendGetBuildingState() { exampleSocket.send(JSON.stringify({ type: "getBuildingState", uuid: "UUID", data: { buildingId: buildingId } })); } //--------------------------------------------------------// function sendGetAssets() { //exampleSocket schickt eine Abfrage an den Server //liefert das asset mit der TypId zurück // BSM exampleSocket.send(JSON.stringify({ type: "getAssets", uuid: "UUID", data: { assetTypeId: [14] } })); } function sendGetEssentials() { exampleSocket.send(JSON.stringify({ type: "getEssentials", uuid: "UUID" })); } async function sendUnmountAssetById(id) { exampleSocket.send(JSON.stringify({ type: "unmountAsset", uuid: "UUID", data: { assetId: id } })); sendGetEssentials(); sendGetBuildingState(); sendGetAssets(); } function show(id) { if (document.getElementById) { var mydiv = document.getElementById(id); mydiv.style.display = "block"; } } function toggle(id) { if (document.getElementById) { var mydiv = document.getElementById(id); mydiv.style.display = (mydiv.style.display == 'block' ? 'none' : 'block'); } }