mirror of
https://github.com/skidoodle/spotify-ws
synced 2025-10-09 05:22:43 +02:00
chore: Improve WebSocket configuration and error handling
This commit is contained in:
9
main.go
9
main.go
@@ -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
|
||||||
|
Reference in New Issue
Block a user