Skip to content

Commit

Permalink
fix multiple connects (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrudd2 authored Oct 16, 2023
1 parent 82372f1 commit b9182f6
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class SaxiDriver implements Driver {

const websocketProtocol = document.location.protocol === "https:" ? "wss" : "ws";
this.socket = new WebSocket(`${websocketProtocol}://${document.location.host}/chat`);

this.socket.addEventListener("open", () => {
console.log(`Connected to EBB server.`);
this.connected = true;
Expand Down Expand Up @@ -1090,9 +1090,18 @@ function PortSelector({ driver, setDriver, hardware }: PortSelectorProps) {
}

function Root() {
const [driver, setDriver] = useState(
IS_WEB ? null as Driver | null : SaxiDriver.connect()
)
const [driver, setDriver] = useState<Driver | null>(null);
const [isDriverConnected, setIsDriverConnected] = useState(false);
useEffect(() => {
if (isDriverConnected) return
if (IS_WEB) {
setDriver(null as Driver);
} else {
setDriver(SaxiDriver.connect());
}
setIsDriverConnected(true);
}, [isDriverConnected]);

const [state, dispatch] = useReducer(reducer, initialState);
const { isPlanning, plan, setPlan } = usePlan(state.paths, state.planOptions);
const [isLoadingFile, setIsLoadingFile] = useState(false);
Expand Down Expand Up @@ -1164,7 +1173,7 @@ function Root() {
document.body.removeEventListener("dragleave", ondragleave);
document.removeEventListener("paste", onpaste);
};
});
}, []);

// Each time new motion is started, save the start time
const currentMotionStartedTime = useMemo(() => {
Expand Down

0 comments on commit b9182f6

Please sign in to comment.