You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.3 KiB
58 lines
1.3 KiB
export async function fetchBikes() {
|
|
return await get("/bike");
|
|
}
|
|
|
|
export async function fetchPrograms() {
|
|
return await get("/program");
|
|
}
|
|
|
|
export async function fetchActiveWorkouts() {
|
|
return await get("/workout?active=true");
|
|
}
|
|
|
|
export async function createNewWorkout(bike, program) {
|
|
const bikeId = bike.id;
|
|
const programId = program.id;
|
|
|
|
return await post("/workout", {bikeId, programId});
|
|
}
|
|
|
|
export async function connectWorkout(workout) {
|
|
return await post(`/workout/${workout.id}/connect`);
|
|
}
|
|
|
|
export async function stopWorkout(workout) {
|
|
return await post(`/workout/${workout.id}/stop`);
|
|
}
|
|
|
|
export async function startWorkout(workout) {
|
|
return await post(`/workout/${workout.id}/start`);
|
|
}
|
|
|
|
export async function pauseWorkout(workout) {
|
|
return await post(`/workout/${workout.id}/pause`);
|
|
}
|
|
|
|
export function openWebsocket(workout) {
|
|
return new WebSocket(url(`/workout/${workout.id}/subscribe`, "ws"));
|
|
}
|
|
|
|
function get(path) {
|
|
return fetch(url(path), {
|
|
method: "GET",
|
|
}).then(r => r.json());
|
|
}
|
|
|
|
function post(path, data = {}) {
|
|
return fetch(url(path), {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(data)
|
|
}).then(r => r.json());
|
|
}
|
|
|
|
function url(path, prefix = "http") {
|
|
return `${prefix}://127.0.0.1:9999/api${path}`;
|
|
}
|