chore: Improve WebSocket configuration and error handling

This commit is contained in:
skidoodle 2024-05-28 13:16:40 +02:00
parent d3d2cbd9d0
commit bec030816a

View file

@ -17,7 +17,14 @@ var (
clients = make(map[*websocket.Conn]bool) // Map to keep track of connected clients clients = make(map[*websocket.Conn]bool) // Map to keep track of connected clients
broadcast = make(chan *spotify.CurrentlyPlaying) // Channel for broadcasting currently playing track broadcast = make(chan *spotify.CurrentlyPlaying) // Channel for broadcasting currently playing track
upgrader = websocket.Upgrader{ upgrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool { return true }, CheckOrigin: func(r *http.Request) bool { return true }, // Allow all origins
HandshakeTimeout: 10 * time.Second, // Timeout for WebSocket handshake
ReadBufferSize: 1024, // Buffer size for reading incoming messages
WriteBufferSize: 1024, // Buffer size for writing outgoing messages
Subprotocols: []string{"binary"}, // Supported subprotocols
Error: func(w http.ResponseWriter, r *http.Request, status int, reason error) {
log.Printf("Error upgrading WebSocket connection: %v", reason)
},
} }
spotifyClient spotify.Client // Spotify API client spotifyClient spotify.Client // Spotify API client
tokenSource oauth2.TokenSource // OAuth2 token source tokenSource oauth2.TokenSource // OAuth2 token source