Skip to content

Commit

Permalink
bug: Fixed on disconnect issue
Browse files Browse the repository at this point in the history
  • Loading branch information
XxThunderBlastxX committed Mar 13, 2024
1 parent 29d33b2 commit bee6011
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
13 changes: 6 additions & 7 deletions api/api/controller/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package controller

import (
"encoding/json"
"fmt"

"github.com/gofiber/contrib/websocket"
"github.com/gofiber/fiber/v2"
Expand Down Expand Up @@ -38,16 +37,16 @@ func WebsocketRoute(hub *domain.Hub) fiber.Handler {
}()

for {

_, payLoad, _ := conn.ReadMessage()
messageType, payLoad, _ := conn.ReadMessage()

_ = json.Unmarshal(payLoad, &msg)

fmt.Println(msg)

// broadcasting message to all other clients in the same room
hub.Broadcast <- &msg
if messageType == 1 { // checking if the message is a text type message
hub.Broadcast <- &msg
} else {
break
}
}

})
}
7 changes: 0 additions & 7 deletions api/internal/domain/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ func (h *Hub) Run() {
Topic: newClient.Topic,
Clients: make(map[string]*Client),
}

h.Rooms[newClient.Topic].Clients[newClient.Id] = newClient

//if _, ok := h.Rooms[newClient.Topic].Clients[newClient.Id]; !ok {
// h.Rooms[newClient.Topic].Clients[newClient.Id] = newClient
//} else {
// h.Rooms[newClient.Topic].Clients[newClient.Id] = newClient
//}
} else {
h.Rooms[newClient.Topic].Clients[newClient.Id] = newClient
}
Expand Down

0 comments on commit bee6011

Please sign in to comment.