Skip to content

Commit

Permalink
fix: remove extraneous WebSocket connections (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrudd2 authored Oct 26, 2023
1 parent 6c9b463 commit 6923fe9
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 @@ -240,7 +240,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 @@ -1043,9 +1043,18 @@ function PortSelector({driver, setDriver}: {driver: Driver; setDriver: (d: Drive
}

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 @@ -1117,7 +1126,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 6923fe9

Please sign in to comment.