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:
parent
e5cbbc9019
commit
6d8e0cec70
2
package-lock.json
generated
2
package-lock.json
generated
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "foris",
|
||||
"version": "3.1.2",
|
||||
"version": "3.2.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "foris",
|
||||
"version": "3.1.2",
|
||||
"version": "3.2.0",
|
||||
"description": "Set of components and utils for Foris and its plugins.",
|
||||
"author": "CZ.NIC, z.s.p.o.",
|
||||
"repository": {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
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);
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -16,8 +16,12 @@ export function useWSForisModule(ws, module, action = "update_settings") {
|
|||
// doesn't present any WS endpoint.
|
||||
if (!ws) return;
|
||||
|
||||
function callback(msg) {
|
||||
setData(msg.data);
|
||||
function callback(message) {
|
||||
// Accept only messages addressed to device with passed controller ID.
|
||||
if (controllerID !== undefined && controllerID !== message.controller_id) {
|
||||
return;
|
||||
}
|
||||
setData(message.data);
|
||||
}
|
||||
|
||||
ws.subscribe(module)
|
||||
|
@ -26,7 +30,7 @@ export function useWSForisModule(ws, module, action = "update_settings") {
|
|||
return () => {
|
||||
ws.unbind(module, action, callback);
|
||||
};
|
||||
}, [action, module, ws]);
|
||||
}, [action, module, ws, controllerID]);
|
||||
|
||||
return [data];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user