1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2024-11-14 17:35:35 +01:00

Added controller ID filter to WebSocket hook.

This commit is contained in:
Maciej Lenartowicz 2020-01-16 10:27:30 +01:00
parent e5cbbc9019
commit 6d8e0cec70
3 changed files with 10 additions and 6 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "foris", "name": "foris",
"version": "3.1.2", "version": "3.2.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "foris", "name": "foris",
"version": "3.1.2", "version": "3.2.0",
"description": "Set of components and utils for Foris and its plugins.", "description": "Set of components and utils for Foris and its plugins.",
"author": "CZ.NIC, z.s.p.o.", "author": "CZ.NIC, z.s.p.o.",
"repository": { "repository": {

View File

@ -7,7 +7,7 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
export function useWSForisModule(ws, module, action = "update_settings") { export function useWSForisModule(ws, module, action = "update_settings", controllerID) {
const [data, setData] = useState(null); const [data, setData] = useState(null);
useEffect(() => { useEffect(() => {
@ -16,8 +16,12 @@ export function useWSForisModule(ws, module, action = "update_settings") {
// doesn't present any WS endpoint. // doesn't present any WS endpoint.
if (!ws) return; if (!ws) return;
function callback(msg) { function callback(message) {
setData(msg.data); // Accept only messages addressed to device with passed controller ID.
if (controllerID !== undefined && controllerID !== message.controller_id) {
return;
}
setData(message.data);
} }
ws.subscribe(module) ws.subscribe(module)
@ -26,7 +30,7 @@ export function useWSForisModule(ws, module, action = "update_settings") {
return () => { return () => {
ws.unbind(module, action, callback); ws.unbind(module, action, callback);
}; };
}, [action, module, ws]); }, [action, module, ws, controllerID]);
return [data]; return [data];
} }