Add option to disable the console broadcasts
This commit is contained in:
@@ -386,8 +386,13 @@ var clients = make(map[string]map[*websocket.Conn]bool)
|
||||
var mu sync.Mutex
|
||||
|
||||
func handleWebSocket(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println(config.EnableConsole)
|
||||
if !config.EnableConsole {
|
||||
http.Error(w, "Console output is disabled", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
filename := r.URL.Query().Get("filename")
|
||||
fmt.Println("Filename:", filename)
|
||||
if filename == "" {
|
||||
http.Error(w, "Filename is required", http.StatusBadRequest)
|
||||
return
|
||||
@@ -423,11 +428,13 @@ func handleWebSocket(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func broadcast(filename string, message []byte) {
|
||||
if !config.EnableConsole {
|
||||
return
|
||||
}
|
||||
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
logger.LogInfo("Broadcast", fmt.Sprintf("Broadcasting message for filename: %s", filename))
|
||||
|
||||
for client := range clients[filename] {
|
||||
if err := client.WriteMessage(websocket.TextMessage, message); err != nil {
|
||||
client.Close()
|
||||
|
Reference in New Issue
Block a user