update websocket
This commit is contained in:
parent
ae6fe0c83b
commit
6bf4195b3b
@ -171,20 +171,27 @@ fastify.register(async function (fastify) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Handle WebSocket messages
|
|
||||||
ws.on('message', function (data, flags) {
|
ws.on('message', function (data, flags) {
|
||||||
const stringData = data.toString('utf-8');
|
const stringData = data.toString('utf-8');
|
||||||
|
|
||||||
if (connection.socket.readyState === WebSocket.OPEN && !isSend) {
|
|
||||||
connection.socket.send(stringData);
|
try {
|
||||||
//console.log(stringData)
|
const jsonData = JSON.parse(stringData);
|
||||||
isSend = true
|
const bpData = jsonData.bp;
|
||||||
setTimeout(() => {
|
|
||||||
isSend = false}, 1000);
|
// Check if bpData is a number and not equal to zero
|
||||||
|
if (typeof bpData === 'number' && bpData !== 0) {
|
||||||
//wait(2000);
|
if (connection.socket.readyState === WebSocket.OPEN && !isSend) {
|
||||||
|
connection.socket.send(JSON.stringify({ bp: bpData }));
|
||||||
|
isSend = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
isSend = false;
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error parsing JSON:', error);
|
||||||
}
|
}
|
||||||
//wait(2000);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user