You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

45 lines
1.3 KiB

import { useEffect, useState } from 'react';
import { useFiltering } from '../../hooks/useFiltering';
function isRequestedValue(item, renderOptions) {
if (
(item.name == "pluviometer" && renderOptions.citzen.pluviometer) ||
/*(item.name == "automaticPluviometer" &&
renderOptions.oficial.automaticPluviometer) ||*/
(item.name == "rain" && renderOptions.citzen.rain) ||
(item.name == "riverFlood" && renderOptions.citzen.riverFlood) ||
(item.name == "floodZones" && renderOptions.citzen.floodRisk) ||
(item.name == "susceptibilityAreas" && renderOptions.oficial.susceptibilityAreas)
) {
return true;
}
}
function verify_existingSockets(formType, renderOptions) {
if (formType.response == null && isRequestedValue(formType, renderOptions)) {
// console.log("Resposta é null");
const socket = new WebSocket("wss://waterproofing.geog.uni-heidelberg.de/wss/hot/data?" + formType.endpoint);
socket.onmessage = ({ data }) => {
formType.response = data;
}
}
/* else {
console.log("\nresposta preenchida");
}*/
}
export default function SocketClient(dataOptionObject, focusChanged) {
const [data, setData] = useState(useFiltering());
useEffect(() => {
data.forms.map((e) => verify_existingSockets(e, dataOptionObject));
}, [dataOptionObject, focusChanged]);
return data;
};