mirror of
https://github.com/skidoodle/spotify-ws.git
synced 2025-02-15 06:09:14 +01:00
chore: Improve WebSocket configuration and error handling
This commit is contained in:
parent
d3d2cbd9d0
commit
bec030816a
1 changed files with 13 additions and 6 deletions
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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue