From 6d8e0cec7026e7ddaa04fcaec7d59a0eb754c6ce Mon Sep 17 00:00:00 2001 From: Maciej Lenartowicz Date: Thu, 16 Jan 2020 10:27:30 +0100 Subject: [PATCH] Added controller ID filter to WebSocket hook. --- package-lock.json | 2 +- package.json | 2 +- src/webSockets/hooks.js | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 64c719c..64899fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "foris", - "version": "3.1.2", + "version": "3.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 682f730..1d40b81 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/webSockets/hooks.js b/src/webSockets/hooks.js index 7357ead..44f7e09 100644 --- a/src/webSockets/hooks.js +++ b/src/webSockets/hooks.js @@ -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]; }