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:
parent
d931690802
commit
6f6883886f
1 changed files with 4 additions and 2 deletions
|
@ -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":
|
||||||
|
|
Loading…
Reference in a new issue