mirror of
https://gitlab.nic.cz/turris/reforis/foris-js.git
synced 2025-07-31 19:53:28 +02:00
Fix lint.
This commit is contained in:
@@ -5,7 +5,9 @@
|
||||
* See /LICENSE for more information.
|
||||
*/
|
||||
|
||||
import { ForisUrls } from "forisUrls";
|
||||
/* eslint no-console: "off" */
|
||||
|
||||
import { ForisURLs } from "forisUrls";
|
||||
|
||||
const PROTOCOL = window.location.protocol === "http:" ? "ws" : "wss";
|
||||
|
||||
@@ -15,13 +17,13 @@ const URL = process.env.LIGHTTPD
|
||||
|
||||
const WAITING_FOR_CONNECTION_TIMEOUT = 500;
|
||||
|
||||
export class WebSockets {
|
||||
export default class WebSockets {
|
||||
constructor() {
|
||||
this.ws = new WebSocket(URL);
|
||||
this.ws.onerror = (e) => {
|
||||
if (window.location.pathname !== ForisUrls.login) {
|
||||
if (window.location.pathname !== ForisURLs.login) {
|
||||
console.error("WS: Error observed, you aren't logged probably.");
|
||||
window.location.replace(ForisUrls.login);
|
||||
window.location.replace(ForisURLs.login);
|
||||
}
|
||||
console.log(`WS: Error: ${e}`);
|
||||
};
|
||||
|
@@ -7,14 +7,15 @@
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export function useWSForisModule(ws, module, action = "update_settings") {
|
||||
export default function useWSForisModule(ws, module, action = "update_settings") {
|
||||
const [data, setData] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (ws && module) {
|
||||
ws.subscribe(module).bind(module, action, (msg) => {
|
||||
setData(msg.data);
|
||||
});
|
||||
ws.subscribe(module)
|
||||
.bind(module, action, (msg) => {
|
||||
setData(msg.data);
|
||||
});
|
||||
}
|
||||
}, [action, module, ws]);
|
||||
|
||||
|
Reference in New Issue
Block a user