chat

package
v0.0.0-...-c56bec8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// when new message is sent to the chat
	EventSendMessage = "send_message"
	EventNewMessage  = "new_message"
	EventChatChange  = "change_room"
)

Variables

This section is empty.

Functions

func ChatChangeHandler

func ChatChangeHandler(e Event, c *Client) error

func SendMessageHandler

func SendMessageHandler(e Event, c *Client) error

Types

type Client

type Client struct {
	Conn *websocket.Conn
	Hub  *Hub
	// contains filtered or unexported fields
}

func NewClient

func NewClient(c *websocket.Conn, h *Hub, chatroom string) *Client

type Event

type Event struct {
	Type    string          `json:"type"`
	Payload json.RawMessage `json:"payload"`
}

different types of messages sent over the websocket we can execute different actions according to the type

type Hub

type Hub struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewHub

func NewHub() *Hub

func (*Hub) AddClient

func (h *Hub) AddClient(client *Client)

func (*Hub) RemoveClient

func (h *Hub) RemoveClient(client *Client)

func (*Hub) ServeWS

func (h *Hub) ServeWS(w http.ResponseWriter, r *http.Request)

type NewMessage

type NewMessage struct {
	SendMessageEvent
	Sent time.Time `json:"sent"`
}

message to be broadcasted to clients

type SendMessageEvent

type SendMessageEvent struct {
	Message  string `json:"message"`
	Username string `json:"username"`
}

when payload is a message sent in chat from client

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL