analuizaff
3 years ago
3 changed files with 70 additions and 5 deletions
-
45src/app/api/Websockets/SocketClient.js
-
4src/app/hooks/useFormsAswers.js
-
26src/app/screens/MapFeedScreen.js
@ -0,0 +1,45 @@ |
|||
import { useEffect, useState } from 'react'; |
|||
import { useFiltering } from '../../hooks/useFiltering'; |
|||
|
|||
function isRequestedValue(item, renderOptions) { |
|||
if ( |
|||
(item.name == "pluviometer" && renderOptions.citzen.pluviometer) || |
|||
(item.name == "officialPluviometer" && renderOptions.oficial.automaticPluviometer) || |
|||
(item.name == "rain" && renderOptions.citzen.rain) || |
|||
(item.name == "riverFlood" && renderOptions.citzen.riverFlood) || |
|||
(item.name == "floodZones" && renderOptions.citzen.floodRisk) |
|||
) { |
|||
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.citizen.map((e) => verify_existingSockets(e, dataOptionObject)); |
|||
data.oficial.map((e) => verify_existingSockets(e, dataOptionObject)); |
|||
|
|||
}, [dataOptionObject, focusChanged]); |
|||
|
|||
return data; |
|||
}; |
|||
|
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue