forked from rfa/radioweb
better filter
This commit is contained in:
parent
acddde383b
commit
65be5202ed
42
main.go
42
main.go
@ -3,7 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"container/ring"
|
"container/ring"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
melody "gopkg.in/olahol/melody.v1"
|
melody "gopkg.in/olahol/melody.v1"
|
||||||
@ -16,6 +16,7 @@ func main() {
|
|||||||
m := melody.New()
|
m := melody.New()
|
||||||
|
|
||||||
history := ring.New(10)
|
history := ring.New(10)
|
||||||
|
pub := ring.New(10)
|
||||||
|
|
||||||
r.Static("/assets", "./assets")
|
r.Static("/assets", "./assets")
|
||||||
r.StaticFile("/", "./index.html")
|
r.StaticFile("/", "./index.html")
|
||||||
@ -31,35 +32,42 @@ func main() {
|
|||||||
"status": "ok",
|
"status": "ok",
|
||||||
})
|
})
|
||||||
|
|
||||||
go func() {
|
if metadata == "" {
|
||||||
if metadata == "" {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < history.Len(); i++ {
|
||||||
|
history = history.Next()
|
||||||
|
|
||||||
|
if history.Value == metadata {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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++ {
|
go func() {
|
||||||
history = history.Next()
|
time.Sleep(time.Second * 10)
|
||||||
if history.Value == metadata {
|
for i := 0; i < pub.Len(); i++ {
|
||||||
|
pub = pub.Next()
|
||||||
|
|
||||||
|
if pub.Value == metadata {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub.Value = metadata
|
||||||
history.Value = metadata
|
pub = pub.Next()
|
||||||
history = history.Next()
|
|
||||||
|
|
||||||
m.Broadcast([]byte(metadata))
|
m.Broadcast([]byte(metadata))
|
||||||
}()
|
}()
|
||||||
})
|
})
|
||||||
|
|
||||||
m.HandleConnect(func(s *melody.Session) {
|
m.HandleConnect(func(s *melody.Session) {
|
||||||
for i := 0; i < history.Len(); i++ {
|
for i := 0; i < pub.Len(); i++ {
|
||||||
if history.Value != nil {
|
if pub.Value != nil {
|
||||||
s.Write([]byte(history.Value.(string)))
|
s.Write([]byte(pub.Value.(string)))
|
||||||
}
|
}
|
||||||
history = history.Next()
|
pub = pub.Next()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user