1
0
Fork 0
mirror of https://git.sr.ht/~ashkeel/strimertul synced 2024-09-20 02:00:49 +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) received := make(chan []byte)
wsErr := make(chan error) wsErr := make(chan error)
go func(recv chan<- []byte) { readFromWS := func(connection *websocket.Conn, recv chan<- []byte) {
for { for {
messageType, messageData, err := connection.ReadMessage() messageType, messageData, err := connection.ReadMessage()
if err != nil { if err != nil {
@ -36,7 +36,8 @@ func (c *Client) connectWebsocket(userClient *helix.Client) {
recv <- messageData recv <- messageData
} }
}(received) }
go readFromWS(connection, received)
for { for {
// Wait for next message or closing/error // Wait for next message or closing/error
@ -89,6 +90,7 @@ func (c *Client) connectWebsocket(userClient *helix.Client) {
break break
} else { } else {
_ = connection.Close() _ = connection.Close()
go readFromWS(newConnection, received)
connection = newConnection connection = newConnection
} }
case "notification": case "notification":