mirror of
https://gitlab.nic.cz/turris/reforis/foris-js.git
synced 2025-07-31 19:53:28 +02:00
Format all files with Prettier
This commit is contained in:
@@ -22,7 +22,9 @@ export class WebSockets {
|
||||
this.ws = new WebSocket(URL);
|
||||
this.ws.onerror = (e) => {
|
||||
if (window.location.pathname !== ForisURLs.login) {
|
||||
console.error("WS: Error observed, you aren't logged probably.");
|
||||
console.error(
|
||||
"WS: Error observed, you aren't logged probably."
|
||||
);
|
||||
window.location.replace(ForisURLs.login);
|
||||
}
|
||||
console.error(`WS: Error: ${e}`);
|
||||
@@ -111,7 +113,9 @@ export class WebSockets {
|
||||
chain = this.callbacks[json.module][json.action];
|
||||
} catch (error) {
|
||||
if (error instanceof TypeError) {
|
||||
console.warn(`Callback for this message wasn't found:${error.data}`);
|
||||
console.warn(
|
||||
`Callback for this message wasn't found:${error.data}`
|
||||
);
|
||||
} else throw error;
|
||||
}
|
||||
|
||||
|
@@ -7,7 +7,12 @@
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export function useWSForisModule(ws, module, action = "update_settings", controllerID) {
|
||||
export function useWSForisModule(
|
||||
ws,
|
||||
module,
|
||||
action = "update_settings",
|
||||
controllerID
|
||||
) {
|
||||
const [data, setData] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -18,14 +23,16 @@ export function useWSForisModule(ws, module, action = "update_settings", control
|
||||
|
||||
function callback(message) {
|
||||
// Accept only messages addressed to device with passed controller ID.
|
||||
if (controllerID !== undefined && controllerID !== message.controller_id) {
|
||||
if (
|
||||
controllerID !== undefined &&
|
||||
controllerID !== message.controller_id
|
||||
) {
|
||||
return;
|
||||
}
|
||||
setData(message.data);
|
||||
}
|
||||
|
||||
ws.subscribe(module)
|
||||
.bind(module, action, callback);
|
||||
ws.subscribe(module).bind(module, action, callback);
|
||||
|
||||
return () => {
|
||||
ws.unbind(module, action, callback);
|
||||
|
Reference in New Issue
Block a user