- added new websocket implementation

This commit is contained in:
2025-11-21 11:41:42 +00:00
parent 8284b1dd11
commit 4f13ed104d
6 changed files with 77 additions and 6 deletions

View File

@@ -0,0 +1,23 @@
import { createContext, useContext } from "react";
import { ReadyState } from "react-use-websocket";
import type { InfoBarData } from "../../types/types";
type InfoSocketState = {
data: InfoBarData | null;
readyState: ReadyState;
sendJson: (msg: unknown) => void;
};
export type WebSocketConextValue = {
info: InfoSocketState;
};
export const WebsocketContext = createContext<WebSocketConextValue | null>(null);
const useWebSocketContext = () => {
const ctx = useContext(WebsocketContext);
if (!ctx) throw new Error("useWebSocketContext must be used inside <WebSocketConext.Provider>");
return ctx;
};
export const useInfoSocket = () => useWebSocketContext().info;