/
stream.go
81 lines (54 loc) · 1.56 KB
/
stream.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package web
import (
"errors"
"net/http"
"broadcastle.co/code/icii/pkg/ice"
"github.com/labstack/echo"
)
func streamPost(c echo.Context) error {
return errors.New("nothing in web.streamPost")
}
func streamUpdate(c echo.Context) error {
// Add auth check.
var update ice.Stream
if err := c.Bind(&update); err != nil {
return c.JSON(http.StatusInternalServerError, err)
}
stream := ice.InitStream()
if err := ice.Echo(c, stream); err != nil {
return c.JSON(http.StatusInternalServerError, err)
}
if err := ice.Update(stream, update); err != nil {
return c.JSON(http.StatusMethodNotAllowed, err)
}
return c.JSON(http.StatusOK, stream)
}
func streamGet(c echo.Context) error {
// Add auth check.
stream := ice.InitStream()
if err := ice.Echo(c, stream); err != nil {
return c.JSON(http.StatusInternalServerError, err)
}
return c.JSON(http.StatusOK, stream)
}
func streamDelete(c echo.Context) error {
stream := ice.InitStream()
if err := ice.Echo(c, stream); err != nil {
return c.JSON(http.StatusInternalServerError, err)
}
if err := ice.Remove(stream); err != nil {
return c.JSON(http.StatusMethodNotAllowed, err)
}
return c.JSON(http.StatusOK, "success")
}
func streamPlayTrack(c echo.Context) error {
stream := ice.InitStream()
track := ice.InitTrack()
if err := ice.Echo(c, stream, track); err != nil {
return c.JSON(http.StatusInternalServerError, err)
}
if err := stream.(*ice.Stream).Play(*track.(*ice.Track)); err != nil {
return c.JSON(http.StatusMethodNotAllowed, err)
}
return c.JSON(http.StatusOK, "success")
}