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

Merge branch 'controller-id-in-hook' into 'dev'

Added controller ID filter to WebSocket hook.

See merge request turris/reforis/foris-js!79
This commit is contained in:
Maciej Lenartowicz 2020-01-16 10:27:30 +01:00
commit 8679749e0f
3 changed files with 10 additions and 6 deletions

2
package-lock.json generated
View File

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

View File

@ -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": {

View File

@ -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];
}