Disable recws as it was causing problems
This commit is contained in:
parent
4487f18e83
commit
c1d9a76a7f
7
go.mod
7
go.mod
@ -4,10 +4,5 @@ go 1.19
|
||||
|
||||
require (
|
||||
github.com/google/go-querystring v1.1.0
|
||||
github.com/recws-org/recws v1.4.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/gorilla/websocket v1.4.2 // indirect
|
||||
github.com/jpillora/backoff v1.0.0 // indirect
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
)
|
||||
|
4
go.sum
4
go.sum
@ -4,8 +4,4 @@ github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD
|
||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
|
||||
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
|
||||
github.com/recws-org/recws v1.4.0 h1:y9LLddtAicjejikNZXiaY9DQjIwcAQ82acd1XU6n0lU=
|
||||
github.com/recws-org/recws v1.4.0/go.mod h1:7+NQkTmBdU98VSzkzq9/P7+X0xExioUVBx9OeRKQIkk=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
31
websocket.go
31
websocket.go
@ -6,9 +6,8 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/recws-org/recws"
|
||||
"github.com/gorilla/websocket"
|
||||
"go.arsenm.dev/go-lemmy/types"
|
||||
)
|
||||
|
||||
@ -17,7 +16,7 @@ type authData struct {
|
||||
}
|
||||
|
||||
type WSClient struct {
|
||||
conn *recws.RecConn
|
||||
conn *websocket.Conn
|
||||
baseURL *url.URL
|
||||
respCh chan types.LemmyWebSocketMsg
|
||||
errCh chan error
|
||||
@ -25,20 +24,19 @@ type WSClient struct {
|
||||
}
|
||||
|
||||
func NewWebSocket(baseURL string) (*WSClient, error) {
|
||||
ws := &recws.RecConn{
|
||||
KeepAliveTimeout: 10 * time.Second,
|
||||
}
|
||||
|
||||
u, err := url.Parse(baseURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
u = u.JoinPath("/api/v3")
|
||||
|
||||
ws.Dial(u.JoinPath("ws").String(), nil)
|
||||
conn, _, err := websocket.DefaultDialer.Dial(u.JoinPath("ws").String(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out := &WSClient{
|
||||
conn: ws,
|
||||
conn: conn,
|
||||
baseURL: u,
|
||||
respCh: make(chan types.LemmyWebSocketMsg, 10),
|
||||
errCh: make(chan error, 10),
|
||||
@ -47,7 +45,7 @@ func NewWebSocket(baseURL string) (*WSClient, error) {
|
||||
go func() {
|
||||
for {
|
||||
var msg types.LemmyWebSocketMsg
|
||||
err = ws.ReadJSON(&msg)
|
||||
err = conn.ReadJSON(&msg)
|
||||
if err != nil {
|
||||
out.errCh <- err
|
||||
continue
|
||||
@ -59,19 +57,6 @@ func NewWebSocket(baseURL string) (*WSClient, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// SetConnectHandler sets the connection handler function
|
||||
func (c *WSClient) SetConnectHandler(f func() error) {
|
||||
c.conn.SubscribeHandler = f
|
||||
}
|
||||
|
||||
// ConnectHandler invokes the connection handler function
|
||||
func (c *WSClient) ConnectHandler() error {
|
||||
if c.conn.SubscribeHandler == nil {
|
||||
return nil
|
||||
}
|
||||
return c.conn.SubscribeHandler()
|
||||
}
|
||||
|
||||
func (c *WSClient) Login(ctx context.Context, l types.Login) error {
|
||||
u := &url.URL{}
|
||||
*u = *c.baseURL
|
||||
|
Loading…
Reference in New Issue
Block a user