Documentation ¶
Index ¶
- func ToPayload(value interface{}) json.RawMessage
- type Client
- func (c *Client) BroadcastMsg(msg Message)
- func (c *Client) Get(key string) interface{}
- func (c *Client) Join(roomId string)
- func (c *Client) Leave(roomId string)
- func (c *Client) Off(event string, funcId string)
- func (c *Client) On(event string, funcId string, f func(json.RawMessage))
- func (c *Client) OnClose(f func(string))
- func (c *Client) RawMessage(payload interface{}) []byte
- func (c *Client) SendId()
- func (c *Client) SendMsg(message Message)
- func (c *Client) SendMsgExcept(roomId string, exclude_ids []string, message Message)
- func (c *Client) SendMsgToRoom(roomId string, message Message)
- func (c *Client) Set(key string, value interface{})
- type Hub
- type Message
- type ServerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ToPayload ¶ added in v1.0.11
func ToPayload(value interface{}) json.RawMessage
Types ¶
type Client ¶
type Client struct { // Identity ID string // contains filtered or unexported fields }
Client is a middleman between the websocket connection and the hub.
func (*Client) BroadcastMsg ¶
Send message to all active connection
func (*Client) On ¶
func (c *Client) On(event string, funcId string, f func(json.RawMessage))
Register handle func for an event
func (*Client) RawMessage ¶ added in v1.0.12
marshall message to json.RawMessage
func (*Client) SendMsgExcept ¶ added in v1.0.11
Send message to specific room except some client
func (*Client) SendMsgToRoom ¶
Send message to specific room
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub maintains the set of active clients and broadcasts messages to the clients.
func NewServer ¶
func NewServer(config *ServerConfig) *Hub
func (*Hub) BroadcastMsg ¶
func (*Hub) OnNewClient ¶
func (*Hub) SendMsgExcept ¶ added in v1.0.11
Send message to specific room except some client
func (*Hub) SendMsgToRoom ¶
Send message to specific room
type Message ¶
type Message struct { Event string `json:"event"` Payload json.RawMessage `json:"payload"` }
Client/Server message format
Click to show internal directories.
Click to hide internal directories.