Skip to content

Commit

Permalink
feat: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hokamsingh committed Aug 30, 2024
1 parent 682584b commit 82c5abc
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions internal/core/websocket/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (c *Client) readPump() {
// Parse and handle different events
if bytes.HasPrefix(message, []byte("join_room:")) {
roomName := string(message[len("join_room:"):])
c.hub.handleJoinRoom(c, roomName)
c.hub.HandleJoinRoom(c, roomName)
// Send confirmation back to client
confirmationMessage := "join_room_success:" + roomName
c.send <- []byte(confirmationMessage)
Expand Down Expand Up @@ -234,26 +234,26 @@ func (h *Hub) joinRoom(client *Client, room string) {
}
}

func (h *Hub) leaveRoom(client *Client, room string) {
func (h *Hub) LeaveRoom(client *Client, room string) {
if _, exists := h.rooms[room]; exists {
delete(h.rooms[room], client)
}
}

func (h *Hub) broadcastToRoom(room string, message []byte) {
func (h *Hub) BroadcastToRoom(room string, message []byte) {
if clients, exists := h.rooms[room]; exists {
for client := range clients {
client.send <- message
}
}
}

func (c *Client) emit(event string, data []byte) {
func (c *Client) Emit(event string, data []byte) {
message := append([]byte(event+": "), data...)
c.send <- message
}

func (h *Hub) handleJoinRoom(client *Client, roomName string) {
func (h *Hub) HandleJoinRoom(client *Client, roomName string) {
h.createRoom(roomName)
h.joinRoom(client, roomName)
}
Expand All @@ -268,7 +268,7 @@ func newHub() *Hub {
}
}

func (h *Hub) run() {
func (h *Hub) Run() {
for {
select {
case client := <-h.register:
Expand Down Expand Up @@ -301,7 +301,7 @@ func (wss *WebSocketServer) NewWsServer(addr string) {
var _addr = flag.String("addr", ":8080", "http service address")
flag.Parse()
hub := newHub()
go hub.run()
go hub.Run()
http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
serveWs(hub, w, r)
})
Expand Down

0 comments on commit 82c5abc

Please sign in to comment.