Documentation
¶
Index ¶
- func Broadcast(event events.OutboundEvent) error
- func DisconnectUser(userID string)
- func GetChatHistory() []events.UserMessageEvent
- func GetChatModerationHistory() []events.UserMessageEvent
- func HandleClientConnection(w http.ResponseWriter, r *http.Request)
- func SaveUserMessage(event events.UserMessageEvent)
- func SendAllWelcomeMessage()
- func SendSystemAction(text string, ephemeral bool) error
- func SendSystemMessage(text string, ephemeral bool) error
- func SendSystemMessageToClient(clientID uint, text string)
- func SetMessageVisibilityForUserID(userID string, visible bool) error
- func SetMessagesVisibility(messageIDs []string, visibility bool) error
- func Start(getStatusFunc func() models.Status) error
- type Client
- type Server
- func (s *Server) Addclient(conn *websocket.Conn, user *user.User, accessToken string, userAgent string, ...) *Client
- func (s *Server) Broadcast(payload events.EventPayload) error
- func (s *Server) ClientClosed(c *Client)
- func (s *Server) DisconnectUser(userID string)
- func (s *Server) HandleClientConnection(w http.ResponseWriter, r *http.Request)
- func (s *Server) Run()
- func (s *Server) Send(payload events.EventPayload, client *Client)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Broadcast ¶
func Broadcast(event events.OutboundEvent) error
Broadcast will send all connected clients the outbound object provided.
func DisconnectUser ¶
func DisconnectUser(userID string)
DisconnectUser will forcefully disconnect all clients belonging to a user by ID.
func GetChatHistory ¶
func GetChatHistory() []events.UserMessageEvent
GetChatHistory will return all the chat messages suitable for returning as user-facing chat history.
func GetChatModerationHistory ¶
func GetChatModerationHistory() []events.UserMessageEvent
GetChatModerationHistory will return all the chat messages suitable for moderation purposes.
func HandleClientConnection ¶
func HandleClientConnection(w http.ResponseWriter, r *http.Request)
HandleClientConnection handles a single inbound websocket connection.
func SaveUserMessage ¶
func SaveUserMessage(event events.UserMessageEvent)
SaveUserMessage will save a single chat event to the messages database.
func SendAllWelcomeMessage ¶
func SendAllWelcomeMessage()
SendAllWelcomeMessage will send the chat message to all connected clients.
func SendSystemAction ¶
SendSystemAction will send a system action string as an action event to all clients.
func SendSystemMessage ¶
SendSystemMessage will send a message string as a system message to all clients.
func SendSystemMessageToClient ¶
SendSystemMessageToClient will send a single message to a single connected chat client.
func SetMessageVisibilityForUserID ¶
SetMessageVisibilityForUserID will bulk change the visibility of messages for a user and then send out visibility changed events to chat clients.
func SetMessagesVisibility ¶
SetMessagesVisibility will set the visibility of multiple messages by ID.
Types ¶
type Client ¶
type Client struct { User *user.User `json:"user"` Geo *geoip.GeoDetails `json:"geo"` MessageCount int `json:"messageCount"` UserAgent string `json:"userAgent"` ConnectedAt time.Time `json:"connectedAt"` // contains filtered or unexported fields }
Client represents a single chat client.
func FindClientByID ¶
FindClientByID will return a single connected client by ID.
func GetClients ¶
func GetClients() []*Client
GetClients will return all the current chat clients connected.
func GetClientsForUser ¶
GetClientsForUser will return chat connections that are owned by a specific user.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents an instance of the chat server.
func (*Server) Addclient ¶
func (s *Server) Addclient(conn *websocket.Conn, user *user.User, accessToken string, userAgent string, ipAddress string) *Client
Addclient registers new connection as a User.
func (*Server) Broadcast ¶
func (s *Server) Broadcast(payload events.EventPayload) error
Broadcast sends message to all connected clients.
func (*Server) ClientClosed ¶
ClientClosed is fired when a client disconnects or connection is dropped.
func (*Server) DisconnectUser ¶
DisconnectUser will forcefully disconnect all clients belonging to a user by ID.
func (*Server) HandleClientConnection ¶
func (s *Server) HandleClientConnection(w http.ResponseWriter, r *http.Request)
HandleClientConnection is fired when a single client connects to the websocket.