Skip to content

Commit

Permalink
WIP socket is closed and no data can be sent
Browse files Browse the repository at this point in the history
  • Loading branch information
timonmerk committed Oct 4, 2024
1 parent d835788 commit eb6241c
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 13 deletions.
Binary file modified gui_dev/bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions gui_dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@emotion/styled": "^11.13.0",
"@mui/icons-material": "latest",
"@mui/material": "latest",
"cbor-js": "^0.1.0",
"immer": "^10.1.1",
"plotly.js": "^2.35.2",
"plotly.js-basic-dist-min": "^2.35.2",
Expand Down
19 changes: 11 additions & 8 deletions gui_dev/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ export const App = () => {
const connectSocket = useSocketStore((state) => state.connectSocket);
const disconnectSocket = useSocketStore((state) => state.disconnectSocket);

useEffect(() => {
console.log("Connecting socket from App component...");
connectSocket();
return () => {
console.log("Disconnecting socket from App component...");
disconnectSocket();
};
}, [connectSocket, disconnectSocket]);
connectSocket();

// What does this effect do?
// useEffect(() => {
// console.log("Connecting socket from App component...");
// connectSocket();
// return () => {
// console.log("Disconnecting socket from App component...");
// disconnectSocket();
// };
// }, [connectSocket, disconnectSocket]);

return (
<ThemeProvider theme={theme}>
Expand Down
5 changes: 5 additions & 0 deletions gui_dev/src/pages/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ import { PSDGraph } from '@/components/PSDGraph';
import { HeatmapGraph } from '@/components/HeatmapGraph';
import { Box, Button } from '@mui/material';
import { useSessionStore } from "@/stores";
import { useSocketStore } from '@/stores';

export const Dashboard = () => {

// CHECK why websocket 1. closed and 2. how to open it again before stream is started
//const connectSocket = useSocketStore((state) => state.connectSocket);
//connectSocket();

const startStream = useSessionStore((state) => state.startStream);
const stopStream = useSessionStore((state) => state.stopStream);

Expand Down
2 changes: 1 addition & 1 deletion gui_dev/src/pages/SourceSelection/FileSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const FileSelector = () => {
);
const setSourceType = useSessionStore((state) => state.setSourceType);

const fileBrowserDirRef = useRef("C:/dev/");
const fileBrowserDirRef = useRef("C:\\code\\py_neuromodulation\\py_neuromodulation\\data\\sub-testsub\\ses-EphysMedOff\\ieeg\\sub-testsub_ses-EphysMedOff_task-gripforce_run-0_ieeg.vhdr");

const [isSelecting, setIsSelecting] = useState(false);
const [showFileBrowser, setShowFileBrowser] = useState(false);
Expand Down
2 changes: 2 additions & 0 deletions py_neuromodulation/gui/backend/app_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ async def handle_stream_control(data: dict):
self.logger.info(self.websocket_manager)
# TODO: I cannot interact with stream_state_queue,
# since the async function is really waiting until the stream finished
#await self.websocket_manager.connect(websocket)

asyncio.create_task(self.pynm_state.start_run_function(
#out_dir=data["out_dir"],
#experiment_name=data["experiment_name"],
Expand Down
5 changes: 3 additions & 2 deletions py_neuromodulation/gui/backend/app_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,9 @@ def launch(self) -> None:
target=run_backend,
kwargs={
"shutdown_event": self.shutdown_event,
"debug": self.debug,
"reload": self.dev,
"debug": self.debug,`
# Could the reload be responsible for closing the websocket?
"reload": False, # self.dev
},
name="Backend",
)
Expand Down
4 changes: 2 additions & 2 deletions py_neuromodulation/stream/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ async def run(
if websocket_featues is not None:
nm.logger.info("Sending message to Websocket")
#nm.logger.info(feature_dict)
await websocket_featues.send_cbor(feature_dict)
#await websocket_featues.send_message(feature_dict)
#await websocket_featues.send_cbor(feature_dict)
await websocket_featues.send_message(feature_dict)
self.batch_count += 1
if self.batch_count % self.save_interval == 0:
self.db.commit()
Expand Down

0 comments on commit eb6241c

Please sign in to comment.