update ticks are started at startup and when a new stream is added
This commit is contained in:
parent
863d9e3577
commit
40fafe91e5
2 changed files with 12 additions and 4 deletions
7
main.go
7
main.go
|
@ -31,6 +31,7 @@ func (server Server) index(w http.ResponseWriter, r *http.Request) {
|
||||||
if !exists {
|
if !exists {
|
||||||
stream = NewStream(URL)
|
stream = NewStream(URL)
|
||||||
server.Streams[URL] = stream
|
server.Streams[URL] = stream
|
||||||
|
go stream.Update()
|
||||||
}
|
}
|
||||||
streamTemplate, err := template.ParseFiles(filepath.Join("templates", "stream.html"))
|
streamTemplate, err := template.ParseFiles(filepath.Join("templates", "stream.html"))
|
||||||
|
|
||||||
|
@ -48,8 +49,10 @@ func (server Server) stream(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "image/jpeg")
|
w.Header().Set("Content-Type", "image/jpeg")
|
||||||
URL := r.FormValue("URL")
|
URL := r.FormValue("URL")
|
||||||
|
|
||||||
stream := NewStream(URL)
|
stream, exists := server.Streams[URL]
|
||||||
stream.WriteStreamJSON()
|
if !exists {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
img := stream.GetStreamInstant(URL)
|
img := stream.GetStreamInstant(URL)
|
||||||
mat, err := gocv.IMDecode(img, gocv.IMReadGrayScale)
|
mat, err := gocv.IMDecode(img, gocv.IMReadGrayScale)
|
||||||
|
|
|
@ -22,16 +22,21 @@ type Stream struct {
|
||||||
// NewStream creates a new Stream Object
|
// NewStream creates a new Stream Object
|
||||||
func NewStream(URL string) Stream {
|
func NewStream(URL string) Stream {
|
||||||
base64 := URLToBase64(URL)
|
base64 := URLToBase64(URL)
|
||||||
return Stream{
|
|
||||||
|
stream := Stream{
|
||||||
URL: URL,
|
URL: URL,
|
||||||
Base64: base64,
|
Base64: base64,
|
||||||
Interval: 5000,
|
Interval: 5000,
|
||||||
}
|
}
|
||||||
|
os.MkdirAll(stream.GetStreamStoreDirPath(), os.ModePerm)
|
||||||
|
stream.WriteStreamJSON()
|
||||||
|
return stream
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update calls itself every Interval milliseconds
|
// Update calls itself every Interval milliseconds
|
||||||
func (s Stream) Update() {
|
func (s Stream) Update() { // TODO make this not overflow, other thing calls this ?
|
||||||
log.Print("Update:", s.URL)
|
log.Print("Update:", s.URL)
|
||||||
|
// TODO make func that does getstreaminstant and savestreaminstant
|
||||||
time.Sleep(time.Duration(s.Interval) * time.Millisecond)
|
time.Sleep(time.Duration(s.Interval) * time.Millisecond)
|
||||||
go s.Update()
|
go s.Update()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue