49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
|
import { RadioState } from '../../app/types';
|
||
|
|
||
|
export const requestToStart = async () => {
|
||
|
console.log("[REST] request to start");
|
||
|
|
||
|
let success = false;
|
||
|
|
||
|
try {
|
||
|
const startUrl = window.location.href + 'start';
|
||
|
const resp = await fetch(startUrl, {
|
||
|
method: 'POST',
|
||
|
body: JSON.stringify({ "change": true, "newState": RadioState.STARTED }),
|
||
|
});
|
||
|
|
||
|
if (resp.ok) {
|
||
|
console.log("[REST] Start: success");
|
||
|
success = true;
|
||
|
}
|
||
|
} catch (err) {
|
||
|
console.log("[REST] Start: failure: %s", err);
|
||
|
}
|
||
|
|
||
|
return success;
|
||
|
}
|
||
|
|
||
|
export const requestToStop = async () => {
|
||
|
console.log("[REST] request to stop");
|
||
|
|
||
|
let success = false;
|
||
|
|
||
|
try {
|
||
|
const stopUrl = window.location.href + 'stop';
|
||
|
const resp = await fetch(stopUrl, {
|
||
|
method: 'POST',
|
||
|
body: JSON.stringify({ "change": true, "newState": RadioState.STOPPED }),
|
||
|
});
|
||
|
|
||
|
if (resp.ok) {
|
||
|
console.log("[REST] Stop: success");
|
||
|
success = true;
|
||
|
}
|
||
|
} catch (err) {
|
||
|
console.log("[REST] Stop: failure: %s", err);
|
||
|
}
|
||
|
|
||
|
return success;
|
||
|
}
|
||
|
|