forked from rfa/radioweb
serve assets, tweaks
This commit is contained in:
parent
2741a55e04
commit
a5f489691d
30
index.html
30
index.html
@ -34,10 +34,7 @@ var player = document.getElementById('player');
|
|||||||
var rng = Math.floor(Math.random() * 10000);
|
var rng = Math.floor(Math.random() * 10000);
|
||||||
player.src = player.src + '?nocache=' + rng;
|
player.src = player.src + '?nocache=' + rng;
|
||||||
|
|
||||||
var url = 'wss://radio.anarchyplanet.org/ws';
|
function update(msg) {
|
||||||
var ws = new WebSocket(url);
|
|
||||||
|
|
||||||
ws.onmessage = function(msg){
|
|
||||||
document.title = msg.data + " - APR";
|
document.title = msg.data + " - APR";
|
||||||
|
|
||||||
var hist = document.getElementById("history");
|
var hist = document.getElementById("history");
|
||||||
@ -47,8 +44,33 @@ ws.onmessage = function(msg){
|
|||||||
if(hist.childElementCount >= 10) {
|
if(hist.childElementCount >= 10) {
|
||||||
hist.removeChild(hist.lastChild);
|
hist.removeChild(hist.lastChild);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function connect() {
|
||||||
|
console.log('connecting');
|
||||||
|
|
||||||
|
var url = 'wss://radio.anarchyplanet.org/ws';
|
||||||
|
var ws = new WebSocket(url);
|
||||||
|
|
||||||
|
ws.onmessage = function(e) {
|
||||||
|
update(e);
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.onclose = function(e) {
|
||||||
|
setTimeout(connect, 1000);
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.onerror = function(e) {
|
||||||
|
ws.close();
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(ws);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connect();
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<noscript>Please enable javascript to use the audio player.</noscript>
|
<noscript>Please enable javascript to use the audio player.</noscript>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
44
main.go
44
main.go
@ -17,9 +17,8 @@ func main() {
|
|||||||
|
|
||||||
history := ring.New(10)
|
history := ring.New(10)
|
||||||
|
|
||||||
r.GET("/", func(c *gin.Context) {
|
r.Static("/assets", "./assets")
|
||||||
http.ServeFile(c.Writer, c.Request, "index.html")
|
r.StaticFile("/", "./index.html")
|
||||||
})
|
|
||||||
|
|
||||||
r.GET("/ws", func(c *gin.Context) {
|
r.GET("/ws", func(c *gin.Context) {
|
||||||
m.HandleRequest(c.Writer, c.Request)
|
m.HandleRequest(c.Writer, c.Request)
|
||||||
@ -28,32 +27,31 @@ func main() {
|
|||||||
r.POST("/update", func(c *gin.Context) {
|
r.POST("/update", func(c *gin.Context) {
|
||||||
metadata := c.PostForm("metadata")
|
metadata := c.PostForm("metadata")
|
||||||
|
|
||||||
if strings.HasPrefix(metadata, "/srv/audio/") {
|
|
||||||
metadata = strings.Replace(metadata, "/srv/audio/", "", 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if metadata == "" {
|
|
||||||
c.JSON(http.StatusBadRequest, gin.H{
|
|
||||||
"status": "failure",
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"status": "success",
|
"status": "ok",
|
||||||
})
|
})
|
||||||
|
|
||||||
for j := 0; j < 10; j++ {
|
go func() {
|
||||||
if history.Value == metadata {
|
if metadata == "" {
|
||||||
history = history.Next()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
history = history.Next()
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Broadcast([]byte(metadata))
|
if strings.HasPrefix(metadata, "/srv/audio/") {
|
||||||
history.Value = metadata
|
metadata = strings.Replace(metadata, "/srv/audio/", "", 1)
|
||||||
history = history.Next()
|
}
|
||||||
|
|
||||||
|
for i := 0; i < history.Len(); i++ {
|
||||||
|
history = history.Next()
|
||||||
|
if history.Value == metadata {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Broadcast([]byte(metadata))
|
||||||
|
|
||||||
|
history.Value = metadata
|
||||||
|
history = history.Next()
|
||||||
|
}()
|
||||||
})
|
})
|
||||||
|
|
||||||
m.HandleConnect(func(s *melody.Session) {
|
m.HandleConnect(func(s *melody.Session) {
|
||||||
|
Loading…
Reference in New Issue
Block a user