Procházet zdrojové kódy

Expose decoder list API and populate UI

master
Jan Svabenik před 3 dny
rodič
revize
04ad3e2dd8
2 změnil soubory, kde provedl 39 přidání a 0 odebrání
  1. +16
    -0
      cmd/sdrd/main.go
  2. +23
    -0
      web/app.js

+ 16
- 0
cmd/sdrd/main.go Zobrazit soubor

@@ -9,6 +9,7 @@ import (
"os"
"os/signal"
"path/filepath"
"sort"
"strconv"
"strings"
"sync"
@@ -516,6 +517,11 @@ func main() {
_ = json.NewEncoder(w).Encode(sigSnap.get())
})

http.HandleFunc("/api/decoders", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(decoderKeys(cfgManager.Snapshot()))
})

http.HandleFunc("/api/recordings", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
@@ -825,6 +831,16 @@ func buildDecoderMap(cfg config.Config) map[string]string {
return out
}

func decoderKeys(cfg config.Config) []string {
m := buildDecoderMap(cfg)
keys := make([]string, 0, len(m))
for k := range m {
keys = append(keys, k)
}
sort.Strings(keys)
return keys
}

func parseSince(raw string) (time.Time, error) {
if raw == "" {
return time.Time{}, nil


+ 23
- 0
web/app.js Zobrazit soubor

@@ -1276,6 +1276,29 @@ window.addEventListener('keydown', (ev) => {
}
});

loadConfig();
loadStats();
loadGPU();
fetchEvents(true);
fetchRecordings();
loadDecoders();
connect();
requestAnimationFrame(renderLoop);
setInterval(loadStats, 1000);
setInterval(loadGPU, 1000);
setInterval(() => fetchEvents(false), 2000);
setInterval(fetchRecordings, 5000);
setInterval(loadSignals, 1500);
setInterval(loadDecoders, 10000);
lse if (ev.key === 'ArrowLeft') {
pan = Math.max(-0.5, pan - 0.04);
followLive = false;
} else if (ev.key === 'ArrowRight') {
pan = Math.min(0.5, pan + 0.04);
followLive = false;
}
});

loadConfig();
loadStats();
loadGPU();


Načítá se…
Zrušit
Uložit