1
0
Fork 0
mirror of https://git.sr.ht/~ashkeel/strimertul synced 2024-09-18 01:50:50 +00:00

fix: handle websocket references a bit nicer

This commit is contained in:
Ash Keel 2023-02-15 10:45:14 +01:00
parent d931690802
commit 6f6883886f
No known key found for this signature in database
GPG key ID: BAD8D93E7314ED3E

View file

@ -22,7 +22,7 @@ func (c *Client) connectWebsocket(userClient *helix.Client) {
received := make(chan []byte)
wsErr := make(chan error)
go func(recv chan<- []byte) {
readFromWS := func(connection *websocket.Conn, recv chan<- []byte) {
for {
messageType, messageData, err := connection.ReadMessage()
if err != nil {
@ -36,7 +36,8 @@ func (c *Client) connectWebsocket(userClient *helix.Client) {
recv <- messageData
}
}(received)
}
go readFromWS(connection, received)
for {
// Wait for next message or closing/error
@ -89,6 +90,7 @@ func (c *Client) connectWebsocket(userClient *helix.Client) {
break
} else {
_ = connection.Close()
go readFromWS(newConnection, received)
connection = newConnection
}
case "notification":