2023-11-18 15:53:54 +00:00
|
|
|
import { settingsStore as settings } from "../store/settingsStore.js";
|
2023-11-09 18:46:29 +00:00
|
|
|
|
2023-11-18 15:53:54 +00:00
|
|
|
function buildURL(endpoint) {
|
|
|
|
const url =
|
|
|
|
"http://" + settings.local.host + ":" + settings.local.port + endpoint;
|
|
|
|
return url;
|
2023-11-09 18:46:29 +00:00
|
|
|
}
|
|
|
|
|
2023-11-18 15:53:54 +00:00
|
|
|
async function apiGet(endpoint) {
|
|
|
|
const response = await fetch(buildURL(endpoint));
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error(`REST response not ok: ${response.statusText}`);
|
|
|
|
}
|
|
|
|
const data = await response.json();
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function apiPost(endpoint, payload = {}) {
|
|
|
|
try {
|
|
|
|
const response = await fetch(buildURL(endpoint), {
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
},
|
|
|
|
body: JSON.stringify(payload),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error(`REST response not ok: ${response.statusText}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const data = await response.json();
|
|
|
|
return data;
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Error posting to REST:", error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-18 15:56:39 +00:00
|
|
|
export function getVersion() {
|
|
|
|
return apiGet("/version");
|
|
|
|
}
|
|
|
|
|
2023-11-18 15:53:54 +00:00
|
|
|
export function getConfig() {
|
|
|
|
return apiGet("/config");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setConfig(config) {
|
|
|
|
return apiPost("/config", config);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getAudioDevices() {
|
|
|
|
return apiGet("/devices/audio");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getSerialDevices() {
|
|
|
|
return apiGet("/devices/serial");
|
2023-11-09 18:46:29 +00:00
|
|
|
}
|
|
|
|
|
2023-11-18 15:56:39 +00:00
|
|
|
export function setModemBeacon(enabled = false) {
|
|
|
|
return apiPost("/modem/beacon", { enabled: enabled });
|
|
|
|
}
|
|
|
|
|
|
|
|
export function sendModemCQ() {
|
|
|
|
return apiPost("/modem/cqcqcq");
|
|
|
|
}
|
|
|
|
|
|
|
|
export function sendModemPing(dxcall) {
|
2023-11-18 17:14:23 +00:00
|
|
|
return apiPost("/modem/ping_ping", { dxcall: dxcall });
|
2023-11-18 15:56:39 +00:00
|
|
|
}
|
|
|
|
|
2023-11-09 21:11:53 +00:00
|
|
|
export function startModem() {
|
2023-11-18 15:53:54 +00:00
|
|
|
return apiPost("/modem/start");
|
2023-11-09 18:46:29 +00:00
|
|
|
}
|
|
|
|
|
2023-11-09 21:11:53 +00:00
|
|
|
export function stopModem() {
|
2023-11-18 15:53:54 +00:00
|
|
|
return apiPost("/modem/stop");
|
2023-11-09 18:46:29 +00:00
|
|
|
}
|
2023-11-13 17:50:46 +00:00
|
|
|
|
2023-11-18 16:10:01 +00:00
|
|
|
export function getModemState() {
|
2023-11-18 17:05:57 +00:00
|
|
|
return apiGet("/modem/state");
|
2023-11-17 21:36:37 +00:00
|
|
|
}
|