docs(wss): more ws stuff
This commit is contained in:
41
frontend/src/WebSocketTest.tsx
Normal file
41
frontend/src/WebSocketTest.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
const WebSocketViewer = () => {
|
||||
const ws = useRef<any>(null);
|
||||
|
||||
useEffect(() => {
|
||||
// Connect to your Go backend WebSocket endpoint
|
||||
ws.current = new WebSocket(
|
||||
(window.location.protocol === "https:" ? "wss://" : "ws://") +
|
||||
window.location.host +
|
||||
"/lst/api/logger/logs"
|
||||
);
|
||||
|
||||
ws.current.onopen = () => {
|
||||
console.log("[WebSocket] Connected");
|
||||
};
|
||||
|
||||
ws.current.onmessage = (event: any) => {
|
||||
console.log("[WebSocket] Message received:", event.data);
|
||||
};
|
||||
|
||||
ws.current.onerror = (error: any) => {
|
||||
console.error("[WebSocket] Error:", error);
|
||||
};
|
||||
|
||||
ws.current.onclose = () => {
|
||||
console.log("[WebSocket] Disconnected");
|
||||
};
|
||||
|
||||
// Cleanup on unmount
|
||||
return () => {
|
||||
if (ws.current) {
|
||||
ws.current.close();
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
return <div>Check the console for WebSocket messages</div>;
|
||||
};
|
||||
|
||||
export default WebSocketViewer;
|
||||
Reference in New Issue
Block a user