Documentation ¶
Index ¶
- type Conn
- func (c *Conn) AddCloseHandler(handler func())
- func (c *Conn) BroadcastMessage(msg []byte, room string)
- func (c *Conn) Close()
- func (c *Conn) JoinRoom(newRoom string)
- func (c *Conn) Room() string
- func (c *Conn) SendMessage(msg []byte)
- func (c *Conn) SetOfflineHandler(handler func())
- func (c *Conn) SetUserID(userID string)
- func (c *Conn) UserID() string
- type Hub
- type Response
- type Server
- type WebSocketConn
- type WebTransportConn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is a middleman between the connection and the hub.
func (*Conn) AddCloseHandler ¶
func (c *Conn) AddCloseHandler(handler func())
AddCloseHandler adds the close handler, they will be triggered when the conn was closed.
func (*Conn) BroadcastMessage ¶
BroadcastMessage broadcast the message to clients in the specified room.
func (*Conn) SendMessage ¶
SendMessage sends a message to current client.
func (*Conn) SetOfflineHandler ¶
func (c *Conn) SetOfflineHandler(handler func())
SetOfflineHandler sets the offline handler when will be triggered when the client is offline.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub maintains the set of active clients and broadcasts messages to the client connections.
type Response ¶
type Response struct { Success bool `json:"success"` Message string `json:"message"` Data interface{} `json:"data"` }
Response represents the response of REST API.
func NewErrorResponse ¶
NewErrorResponse creates an error response.
func NewSuccessResponse ¶
NewSuccessResponse creates a success response.
type Server ¶
type Server interface { // ListenAndServe listens on the specified address and serves the Presence Server. ListenAndServe(addr string, certFile string, keyFile string) error // SetReadMessageHandler sets the handler when receiving the messages. SetReadMessageHandler(handler func(c *Conn, msg []byte)) // BroadcastMessage broadcast the message to clients in the specified room. BroadcastMessage(msg []byte, room string) }
Server is an interface for Presence Server.
type WebSocketConn ¶
type WebSocketConn struct { *Conn // contains filtered or unexported fields }
WebSocketConn is a middleman between the websocket connection and the hub.
type WebTransportConn ¶
type WebTransportConn struct { *Conn // contains filtered or unexported fields }
WebTransportConn is a middleman between the webtransport connection and the hub.