Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions _examples/stress-test/broadcasting-1/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion room_chat.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package wolfsocket

import (
"errors"
"wolfsocket/stackexchange/protos"
)

Expand Down Expand Up @@ -54,6 +55,22 @@ func (rc *BaseRoomChat) Chat(messageData any) {
}
}

func Chat(server *Server, roomID string, messageData any) error {
if server == nil {
return errors.New("wsServer is nil")
}

if msg, ok := messageData.([]byte); ok {
return server.SBroadcast(getRoomChatChannel(roomID), protos.ServerMessage{
EventName: OnReceiveMsgChat,
ToClient: true,
Body: msg,
})
}

return nil
}

func (rc *BaseRoomChat) Subscribe() {
rc.conn.Subscribe(rc.getChannel())
}
Expand All @@ -71,10 +88,14 @@ func (rc *BaseRoomChat) RoomChatID() string {

// return channel pubsub chat room
func (rc *BaseRoomChat) getChannel() string {
return prefixRoomChat + rc.ID
return getRoomChatChannel(rc.ID)
}

// return channel type of this room
func (rc *BaseRoomChat) Channel() RoomChannel {
return rc.channel
}

func getRoomChatChannel(roomID string) string {
return prefixRoomChat + roomID
}