24 lines
650 B
TypeScript
24 lines
650 B
TypeScript
interface RuntimeRepository {
|
|
openWebsocket(): WebSocket
|
|
}
|
|
|
|
export default function runtimeRepo(): RuntimeRepository {
|
|
switch (import.meta.env.VITE_MODE) {
|
|
case "webapp":
|
|
const port = window.location.port !== "5173" ? window.location.port : "8080";
|
|
return makeRuntimeRepo(`${window.location.hostname}:${port}`);
|
|
case "chrome-plugin":
|
|
return makeRuntimeRepo("127.0.0.1:9999");
|
|
default:
|
|
throw new Error("Not implemented");
|
|
}
|
|
}
|
|
|
|
function makeRuntimeRepo(host: string): RuntimeRepository {
|
|
return {
|
|
openWebsocket(): WebSocket {
|
|
return new WebSocket(`ws://${host}/api/workouts/active`);
|
|
},
|
|
};
|
|
}
|