Skip to content

Commit

Permalink
Enhance WebSocketProvider to include REFRESH_NEEDED and RESTART_NEEDE…
Browse files Browse the repository at this point in the history
…D states
  • Loading branch information
Luligu committed Dec 31, 2024
1 parent ebec632 commit e05d20e
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 12 deletions.
6 changes: 3 additions & 3 deletions frontend/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"files": {
"main.css": "./static/css/main.2196886d.css",
"main.js": "./static/js/main.7b39120b.js",
"main.js": "./static/js/main.95e4564e.js",
"static/js/453.abd36b29.chunk.js": "./static/js/453.abd36b29.chunk.js",
"static/media/roboto-latin-700-normal.woff2": "./static/media/roboto-latin-700-normal.4535474e1cf8598695ad.woff2",
"static/media/roboto-latin-500-normal.woff2": "./static/media/roboto-latin-500-normal.7077203b1982951ecf76.woff2",
Expand Down Expand Up @@ -61,11 +61,11 @@
"static/media/roboto-greek-ext-400-normal.woff": "./static/media/roboto-greek-ext-400-normal.16eb83b4a3b1ea994243.woff",
"index.html": "./index.html",
"main.2196886d.css.map": "./static/css/main.2196886d.css.map",
"main.7b39120b.js.map": "./static/js/main.7b39120b.js.map",
"main.95e4564e.js.map": "./static/js/main.95e4564e.js.map",
"453.abd36b29.chunk.js.map": "./static/js/453.abd36b29.chunk.js.map"
},
"entrypoints": [
"static/css/main.2196886d.css",
"static/js/main.7b39120b.js"
"static/js/main.95e4564e.js"
]
}
2 changes: 1 addition & 1 deletion frontend/build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><base href="./"><link rel="icon" href="./matterbridge 32x32.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>Matterbridge</title><link rel="manifest" href="./manifest.json"/><script defer="defer" src="./static/js/main.7b39120b.js"></script><link href="./static/css/main.2196886d.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><base href="./"><link rel="icon" href="./matterbridge 32x32.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>Matterbridge</title><link rel="manifest" href="./manifest.json"/><script defer="defer" src="./static/js/main.95e4564e.js"></script><link href="./static/css/main.2196886d.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
1 change: 0 additions & 1 deletion frontend/build/static/js/main.7b39120b.js.map

This file was deleted.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions frontend/build/static/js/main.95e4564e.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion frontend/src/components/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function Home() {
// Clear the interval when the component is unmounted
return () => clearInterval(intervalId);

}, []); // The empty array causes this effect to run only once
}, []);

// Function to reload settings on demand
const reloadSettings = () => {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/WebSocketProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import WebSocketUse from './WebSocketUse';
export const WebSocketContext = createContext();

export function WebSocketProvider({ children }) {
const { messages, sendMessage, logMessage, setLogFilters, ws } = WebSocketUse();
const { messages, sendMessage, logMessage, setLogFilters, ws, REFRESH_NEEDED, RESTART_NEEDED } = WebSocketUse();
// console.log(`WebSocketProvider: wssHost: ${wssHost} messages ${messages.length}`);

return (
<WebSocketContext.Provider value={{ messages, sendMessage, logMessage, setLogFilters, ws }}>
<WebSocketContext.Provider value={{ messages, sendMessage, logMessage, setLogFilters, ws, REFRESH_NEEDED, RESTART_NEEDED }}>
{children}
</WebSocketContext.Provider>
);
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/components/WebSocketUse.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ function WebSocketUse() {
const [messages, setMessages] = useState([]);
const wssHost = window.location.href.replace(/^http/, 'ws'); // Replace "http" or "https" with "ws" or "wss"
const ws = useRef(null);
const REFRESH_NEEDED = useRef(0);
const RESTART_NEEDED = useRef(0);
const retryCountRef = useRef(1);
const maxMessages = 1000;
const maxRetries = 10;
Expand Down Expand Up @@ -74,11 +76,13 @@ function WebSocketUse() {
try {
const msg = JSON.parse(event.data);
if(msg.id===WS_ID_REFRESH_NEEDED) {
REFRESH_NEEDED.current ++;
// logMessage('WebSocket', `WebSocket WS_ID_REFRESH_NEEDED message`);
console.log(`WebSocket WS_ID_REFRESH_NEEDED message:`, msg);
return;
}
if(msg.id===WS_ID_RESTART_NEEDED) {
RESTART_NEEDED.current ++;
// logMessage('WebSocket', `WebSocket WS_ID_RESTART_NEEDED message`);
console.log(`WebSocket WS_ID_RESTART_NEEDED message:`, msg);
return;
Expand Down Expand Up @@ -177,7 +181,7 @@ function WebSocketUse() {
};
}, [connectWebSocket]);

return { messages, sendMessage, logMessage, setLogFilters, ws };
return { messages, sendMessage, logMessage, setLogFilters, ws, REFRESH_NEEDED, RESTART_NEEDED };
}

export default WebSocketUse;

0 comments on commit e05d20e

Please sign in to comment.