]> code.octet-stream.net Git - broadcaster/blobdiff - server/broadcaster.go
Allow web user to cancel transmission in progress
[broadcaster] / server / broadcaster.go
index 2e09249dfb40b64fe7f666fbe0ee9328bf00302f..e5f992243568cd09f3d0fb842029baf5b177c62e 100644 (file)
@@ -18,9 +18,6 @@ const formatString = "2006-01-02T15:04"
 
 var config ServerConfig = NewServerConfig()
 
-// Channel that will be closed and recreated every time the playlists change
-var playlistChangeWait = make(chan bool)
-
 func main() {
        configFlag := flag.String("c", "", "path to configuration file")
        // TODO: support this
@@ -36,6 +33,8 @@ func main() {
        InitDatabase()
        defer db.CloseDatabase()
 
+       InitCommandRouter()
+       InitPlaylists()
        InitAudioFiles(config.AudioFilesPath)
        InitServerStatus()
 
@@ -43,6 +42,7 @@ func main() {
        http.HandleFunc("/login", logInPage)
        http.HandleFunc("/logout", logOutPage)
        http.HandleFunc("/secret", secretPage)
+       http.HandleFunc("/stop", stopPage)
 
        http.HandleFunc("/playlist/", playlistSection)
        http.HandleFunc("/file/", fileSection)
@@ -288,8 +288,7 @@ func submitPlaylist(w http.ResponseWriter, r *http.Request) {
                }
                db.SetEntriesForPlaylist(cleanedEntries, id)
                // Notify connected radios
-               close(playlistChangeWait)
-               playlistChangeWait = make(chan bool)
+               playlists.NotifyChanges()
        }
        http.Redirect(w, r, "/playlist/", http.StatusFound)
 }
@@ -302,6 +301,7 @@ func deletePlaylist(w http.ResponseWriter, r *http.Request) {
                        return
                }
                db.DeletePlaylist(id)
+               playlists.NotifyChanges()
        }
        http.Redirect(w, r, "/playlist/", http.StatusFound)
 }
@@ -406,3 +406,19 @@ func logOutPage(w http.ResponseWriter, r *http.Request) {
        tmpl := template.Must(template.ParseFiles("templates/logout.html"))
        tmpl.Execute(w, nil)
 }
+
+func stopPage(w http.ResponseWriter, r *http.Request) {
+       _, err := currentUser(w, r)
+       if err != nil {
+               http.Redirect(w, r, "/login", http.StatusFound)
+               return
+       }
+       r.ParseForm()
+       radioId, err := strconv.Atoi(r.Form.Get("radioId"))
+       if err != nil {
+               http.NotFound(w, r)
+               return
+       }
+       commandRouter.Stop(radioId)
+       http.Redirect(w, r, "/", http.StatusFound)
+}