mirror of
				https://gitlab.nic.cz/turris/reforis/foris-js.git
				synced 2025-11-03 23:00:31 +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:
		
							
								
								
									
										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];
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user