Skip to content

Commit a922b06

Browse files
Merge branch 'refactor/frontend'
2 parents aa2294d + efb6709 commit a922b06

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+4170
-3105
lines changed

assets/desktop-demo.png

-5.06 KB
Loading

docs/api.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,34 @@
1+
# API
2+
3+
## Example Responses
4+
5+
```json
6+
{
7+
"ok": true,
8+
"code": 200
9+
}
10+
```
11+
12+
```json
13+
{
14+
"ok": true,
15+
"code": 200,
16+
"result": {
17+
"uuid": "fb38cb47-a74b-42d5-bb9c-89dcc6a3d960"
18+
}
19+
}
20+
```
21+
22+
```json
23+
{
24+
"ok": false,
25+
"code": 404,
26+
"error": "radio not found"
27+
}
28+
```
29+
130
## Radio API
31+
232
### Discover radios
333

434
```
@@ -19,7 +49,7 @@ GET http://localhost:8080/v1/radio/:uuid
1949

2050
### Get radio state via websocket
2151

22-
Client must send `uuid` after they connect or specify it in the `GET` parameter in order to receive state. The first message sent to client is always the full state. After that, only state changes are sent to the client. The `uuid` is always sent to the client. The connection will terminate if the client sends an invalid `uuid`.
52+
Client must send `uuid` after they connect or specify it in the `GET` url parameter in order to start receiving state. The first message sent to client is always the full state. After that, only state changes are sent to the client. The `uuid` is always sent to the client in each message. The connection will terminate if the client sends an invalid `uuid`.
2353

2454
```
2555
GET ws://localhost:8080/v1/radio/ws?uuid=:uuid
@@ -53,6 +83,7 @@ POST http://localhost:8080/v1/radio/:uuid/volume
5383
```
5484
POST http://localhost:8080/v1/radio/:uuid
5585
```
86+
5687
## Preset API
5788

5889
### Get presets
@@ -78,4 +109,4 @@ content-type: application/json
78109
"newName": "Good Music"
79110
"newUrl" : "http://differentm3u.example.com/08.m3u"
80111
}
81-
```
112+
```

server/preset.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func handlePresetGet(presetStore core.PresetStore) gin.HandlerFunc {
2020
return
2121
}
2222

23-
c.JSON(http.StatusOK, preset)
23+
renderJSON(c, http.StatusOK, preset)
2424
}
2525
}
2626

@@ -33,7 +33,9 @@ func handlePresetList(presetStore core.PresetStore) gin.HandlerFunc {
3333
return
3434
}
3535

36-
c.JSON(http.StatusOK, presets)
36+
sortPresets(presets)
37+
38+
renderJSON(c, http.StatusOK, presets)
3739
}
3840
}
3941

@@ -56,7 +58,7 @@ func handlePresetUpdate(presetStore core.PresetStore) gin.HandlerFunc {
5658
return
5759
}
5860

59-
c.JSON(http.StatusOK, preset)
61+
renderJSON(c, http.StatusOK, preset)
6062
}
6163
}
6264

server/radio.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ func handleRadioGet() func(c *gin.Context) {
2222
}
2323

2424
// Return Radio
25-
c.JSON(http.StatusOK, state)
25+
renderJSON(c, http.StatusOK, state)
2626
}
2727
}
2828

2929
func handleRadioList(h *radio.Hub) func(c *gin.Context) {
3030
return func(c *gin.Context) {
31-
c.JSON(http.StatusOK, h.GetRadioStates(c))
31+
renderJSON(c, http.StatusOK, h.GetRadioStates(c))
3232
}
3333
}
3434

@@ -95,6 +95,8 @@ func handleRadioPatch() func(c *gin.Context) {
9595
return
9696
}
9797
}
98+
99+
renderJSON(c, http.StatusOK, nil)
98100
}
99101
}
100102

@@ -104,6 +106,8 @@ func handleRadioRefresh() func(c *gin.Context) {
104106
rd := c.MustGet("radio").(*radio.Radio)
105107

106108
rd.Refresh()
109+
110+
renderJSON(c, http.StatusOK, nil)
107111
}
108112
}
109113

@@ -117,6 +121,8 @@ func handleRadioVolumeRefresh() func(c *gin.Context) {
117121
renderError(c, http.StatusServiceUnavailable, err)
118122
return
119123
}
124+
125+
renderJSON(c, http.StatusOK, nil)
120126
}
121127
}
122128

@@ -126,5 +132,7 @@ func handleRadioDiscover(h *radio.Hub) func(c *gin.Context) {
126132
renderError(c, http.StatusConflict, err)
127133
return
128134
}
135+
136+
renderJSON(c, http.StatusOK, nil)
129137
}
130138
}

server/util.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,34 @@ package server
33
import (
44
"context"
55
"log"
6+
"sort"
7+
"strings"
68

79
"github.com/ItsNotGoodName/reciva-web-remote/core"
810
"github.com/gin-gonic/gin"
911
)
1012

13+
type RenderJSON struct {
14+
Ok bool `json:"ok"`
15+
Code int `json:"code"`
16+
Result interface{} `json:"result,omitempty"`
17+
Error string `json:"error,omitempty"`
18+
}
19+
1120
func renderError(c *gin.Context, code int, err error) {
12-
c.JSON(code, gin.H{"err": err.Error()})
21+
c.JSON(code, RenderJSON{
22+
Ok: false,
23+
Code: code,
24+
Error: err.Error(),
25+
})
26+
}
27+
28+
func renderJSON(c *gin.Context, code int, result interface{}) {
29+
c.JSON(code, RenderJSON{
30+
Ok: true,
31+
Code: code,
32+
Result: result,
33+
})
1334
}
1435

1536
// getPresetURLS returns all urls for presets.
@@ -26,3 +47,9 @@ func getPresetURLS(p core.PresetStore) []string {
2647

2748
return urls
2849
}
50+
51+
func sortPresets(presets []core.Preset) {
52+
sort.Slice(presets, func(i, j int) bool {
53+
return strings.Compare(presets[i].URL, presets[j].URL) < 0
54+
})
55+
}

web/index.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
<html lang="en">
33

44
<head>
5-
<meta charset="UTF-8" />
6-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7-
<title>Reciva Web Remote</title>
8-
<meta name="description" content="Control Reciva based radios">
9-
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
10-
<link rel="alternate icon" href="/favicon.ico" type="image/png" sizes="16x16">
11-
<link rel="apple-touch-icon" href="/apple-touch-icon.png" sizes="180x180">
12-
<link rel="mask-icon" href="/favicon.svg" color="#FFFFFF">
13-
<meta name="theme-color" content="#ffffff">
5+
<meta charset="UTF-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Reciva Web Remote</title>
8+
<meta name="description" content="Control your legacy Reciva based internet radios">
9+
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
10+
<link rel="alternate icon" href="/favicon.ico" type="image/png" sizes="16x16">
11+
<link rel="apple-touch-icon" href="/apple-touch-icon.png" sizes="180x180">
12+
<link rel="mask-icon" href="/favicon.svg" color="#FFFFFF">
13+
<meta name="theme-color" content="#ffffff">
1414
</head>
1515

16-
<body>
17-
<div id="app"></div>
18-
<script type="module" src="/src/main.js"></script>
16+
<body class="has-navbar-fixed-top has-navbar-fixed-bottom">
17+
<div id="app"></div>
18+
<script type="module" src="/src/main.js"></script>
1919
</body>
2020

2121
</html>

0 commit comments

Comments
 (0)