Skip to content

Commit

Permalink
api/ws- make User.Conn private
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro committed Apr 17, 2022
1 parent c81a372 commit aa34e81
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/handler/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func Websocket(w http.ResponseWriter, r *http.Request) {
// message intake loop
for {
// Read message from browser
_, msg, err := wuser.Conn.ReadMessage()
_, msg, err := wuser.ReadMessage()
if err != nil {
break
}
Expand Down
12 changes: 8 additions & 4 deletions pkg/ws/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type User struct {
Conn *websocket.Conn
conn *websocket.Conn
User *db.User
}

Expand All @@ -21,20 +21,24 @@ func (u *User) Disconnect() {
"type": "user-disconnect",
"user": u.User.UUID,
})
u.Conn.Close()
u.conn.Close()
}
}

func (u *User) ReadMessage() (int, []byte, error) {
return u.conn.ReadMessage()
}

func (u *User) IsConnected() bool {
return store.This.ListHas(keyOnline, u.User.UUID.String())
}

func (u *User) SendWsMessage(msg map[string]interface{}) {
u.Conn.WriteJSON(msg)
u.conn.WriteJSON(msg)
}

func (u *User) SendWsMessageRaw(msg []byte) {
u.Conn.WriteMessage(websocket.TextMessage, msg)
u.conn.WriteMessage(websocket.TextMessage, msg)
}

func (u *User) SendMessage(in *db.Channel, msg string) {
Expand Down

0 comments on commit aa34e81

Please sign in to comment.