Skip to content

Commit

Permalink
renamed connected to status
Browse files Browse the repository at this point in the history
  • Loading branch information
Syleron committed Jan 25, 2021
1 parent 081f5a7 commit d455b0f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 5 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ import (

type Client struct {
Username string `json:"username"`
connections map[string]*Connection `json:connections` // Indexed by UUID
connections map[string]*Connection `json:"connections"` // Indexed by UUID
sync.Mutex
}

type Connection struct {
//UUID string `json:"uuid"`
Conn *websocket.Conn
Connected bool `json:"connected"`
Room *Room `json:"room"`
Conn *websocket.Conn
Status bool `json:"status"`
Room *Room `json:"room"`
}

func (c *Connection) pongHandler() {
ticker := time.NewTicker(pingPeriod)

defer func() {
// Set our connection state
c.Connected = false
c.Status = false
// Stop our ticker
ticker.Stop()
// Close our connection
Expand Down Expand Up @@ -77,8 +77,6 @@ func (c *Client) addConnection(newConnection *Connection) string {
}
// Generate an unique ID
uuid := xid.New().String()
// Set our connection state
newConnection.Connected = true
// Start our pong handler
go newConnection.pongHandler()
// Append our connection
Expand Down
2 changes: 2 additions & 0 deletions sockets.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func (s *Sockets) HandleConnection(w http.ResponseWriter, r *http.Request) error
client = s.Clients[jwt.Username]
uuid = client.addConnection(&Connection{
Conn: ws,
Status: true,
Room: &Room{
Name: "",
Channel: "",
Expand All @@ -178,6 +179,7 @@ func (s *Sockets) HandleConnection(w http.ResponseWriter, r *http.Request) error
client = &Client{}
uuid = client.addConnection(&Connection{
Conn: ws,
Status: true,
Room: &Room{
Name: "",
Channel: "",
Expand Down

0 comments on commit d455b0f

Please sign in to comment.