Add websocket wifi updates
This commit is contained in:
parent
c443fce24f
commit
1477d909b0
11 changed files with 755 additions and 10 deletions
|
|
@ -12,6 +12,18 @@ import (
|
|||
"github.com/nemunaire/repeater/internal/wifi"
|
||||
)
|
||||
|
||||
// GetWiFiNetworks returns cached WiFi networks without scanning
|
||||
func GetWiFiNetworks(c *gin.Context) {
|
||||
networks, err := wifi.GetCachedNetworks()
|
||||
if err != nil {
|
||||
logging.AddLog("WiFi", "Erreur lors de la récupération des réseaux: "+err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Erreur lors de la récupération des réseaux"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, networks)
|
||||
}
|
||||
|
||||
// ScanWiFi handles WiFi network scanning
|
||||
func ScanWiFi(c *gin.Context) {
|
||||
networks, err := wifi.ScanNetworks()
|
||||
|
|
|
|||
30
internal/api/handlers/websocket_wifi.go
Normal file
30
internal/api/handlers/websocket_wifi.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/nemunaire/repeater/internal/wifi"
|
||||
)
|
||||
|
||||
// WebSocketWifi handles WebSocket connections for real-time WiFi events
|
||||
func WebSocketWifi(c *gin.Context) {
|
||||
conn, err := upgrader.Upgrade(c.Writer, c.Request, nil)
|
||||
if err != nil {
|
||||
log.Printf("Erreur WebSocket WiFi: %v", err)
|
||||
return
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
// Register client
|
||||
wifi.RegisterWebSocketClient(conn)
|
||||
defer wifi.UnregisterWebSocketClient(conn)
|
||||
|
||||
// Keep connection alive
|
||||
for {
|
||||
_, _, err := conn.ReadMessage()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -24,6 +24,7 @@ func SetupRouter(status *models.SystemStatus, cfg *config.Config, assets embed.F
|
|||
// WiFi endpoints
|
||||
wifi := api.Group("/wifi")
|
||||
{
|
||||
wifi.GET("/networks", handlers.GetWiFiNetworks)
|
||||
wifi.GET("/scan", handlers.ScanWiFi)
|
||||
wifi.POST("/connect", handlers.ConnectWiFi)
|
||||
wifi.POST("/disconnect", handlers.DisconnectWiFi)
|
||||
|
|
@ -53,8 +54,9 @@ func SetupRouter(status *models.SystemStatus, cfg *config.Config, assets embed.F
|
|||
api.DELETE("/logs", handlers.ClearLogs)
|
||||
}
|
||||
|
||||
// WebSocket endpoint
|
||||
// WebSocket endpoints
|
||||
r.GET("/ws/logs", handlers.WebSocketLogs)
|
||||
r.GET("/ws/wifi", handlers.WebSocketWifi)
|
||||
|
||||
// Serve static files
|
||||
sub, err := fs.Sub(assets, "static")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue