Documentation
¶
Index ¶
- func DefaultUpgrader() websocket.Upgrader
- func Encode(subject string, msg interface{}) ([]byte, error)
- func ServeWs(hub IHub, w http.ResponseWriter, r *http.Request, ...)
- type Client
- func (c *Client) Close()
- func (c *Client) DecodeMessage(data []byte) (*MessageIn, error)
- func (c *Client) Encode(subject string, msg interface{}) []byte
- func (c *Client) EncodeMessage(msg interface{}) []byte
- func (c *Client) GetClient() *Client
- func (c *Client) GetProps() map[string]interface{}
- func (c *Client) Hub() IHub
- func (c *Client) NewClientMessage(data []byte) (*ClientMessage, error)
- func (c *Client) ReadPump()
- func (c *Client) SendChan() chan []byte
- func (c *Client) WritePump()
- type ClientMessage
- type Conf
- type Filter
- type Handler
- type HandlerWs
- type Hub
- func (h *Hub) AfterJoin(callback func(client IClient))
- func (h *Hub) AfterLeave(callback func(client IClient))
- func (h *Hub) BeforeJoin(callback func(client IClient) error)
- func (h *Hub) BeforeLeave(callback func(client IClient))
- func (h *Hub) BeforeWsMsg(callback func(msg *ClientMessage) bool)
- func (h *Hub) ClientList() []IClient
- func (h *Hub) Clients() map[IClient]bool
- func (h *Hub) Close()
- func (h *Hub) CloseChan() chan struct{}
- func (h *Hub) EchoWs(msg *ClientMessage)
- func (h *Hub) GetSeconds() int
- func (h *Hub) Id() interface{}
- func (h *Hub) MessageChan() chan *ClientMessage
- func (h *Hub) Off(subject string, handler Handler)
- func (h *Hub) OffWs(subject string, handler HandlerWs)
- func (h *Hub) On(subject string, handler Handler)
- func (h *Hub) OnTick(cb func(int))
- func (h *Hub) OnWs(subject string, handler HandlerWs)
- func (h *Hub) RegisterChan() chan IClient
- func (h *Hub) ResetRedis() error
- func (h *Hub) Run()
- func (h *Hub) SendRedis(subject string, data interface{})
- func (h *Hub) SendRedisRaw(msg *MessageIn)
- func (h *Hub) SendWs(subject string, message interface{}, receivers ...IClient)
- func (h *Hub) SendWsAll(subject string, message interface{})
- func (h *Hub) SendWsBytes(client IClient, bs []byte)
- func (h *Hub) SendWsClient(client IClient, subject string, message interface{})
- func (h *Hub) UnregisterChan() chan IClient
- type IClient
- type IFilters
- type IHub
- type IRoute
- type MessageIn
- type MessageLocal
- type MessageOut
- type User
- type WsConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultUpgrader ¶
Types ¶
type Client ¶
type Client struct {
// props sync.Map
Props map[string]interface{}
// contains filtered or unexported fields
}
Client is a middleman between the websocket connection and the hub.
func (*Client) Close ¶
func (c *Client) Close()
Close client ,in message loop should in go client.Close()
func (*Client) EncodeMessage ¶
func (*Client) NewClientMessage ¶
func (c *Client) NewClientMessage(data []byte) (*ClientMessage, error)
func (*Client) ReadPump ¶
func (c *Client) ReadPump()
readPump pumps messages from the websocket connection to the hub.
The application runs readPump in a per-connection goroutine. The application ensures that there is at most one reader on a connection by executing all reads from this goroutine.
func (*Client) SendChan ¶
func (c *Client) Send(subject string, msg interface{}) {
c.send <- c.Encode(subject, msg)
}
func (*Client) WritePump ¶
func (c *Client) WritePump()
writePump pumps messages from the hub to the websocket connection.
A goroutine running writePump is started for each connection. The application ensures that there is at most one writer to a connection by executing all writes from this goroutine.
type ClientMessage ¶
type RedisHubMessage struct {
*MessageIn
}
func NewMessage ¶
func NewMessage(subject string, data interface{}, client IClient) *ClientMessage
type HandlerWs ¶
type HandlerWs func(message *ClientMessage)
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
hub maintains the set of active clients and broadcasts messages to the clients.
func (*Hub) AfterLeave ¶
func (*Hub) BeforeJoin ¶
func (*Hub) BeforeLeave ¶
func (*Hub) BeforeWsMsg ¶
func (h *Hub) BeforeWsMsg(callback func(msg *ClientMessage) bool)
func (*Hub) ClientList ¶
func (*Hub) CloseChan ¶
func (h *Hub) CloseChan() chan struct{}
func (h *Hub) SetSelf(self IHub) {
h.self = self
}
func (*Hub) EchoWs ¶
func (h *Hub) EchoWs(msg *ClientMessage)
func (*Hub) GetSeconds ¶
func (*Hub) MessageChan ¶
func (h *Hub) MessageChan() chan *ClientMessage
RegisterChan() chan *Client
func (*Hub) RegisterChan ¶
func (*Hub) ResetRedis ¶
func (*Hub) SendRedisRaw ¶
func (*Hub) SendWsBytes ¶
func (*Hub) SendWsClient ¶
func (*Hub) UnregisterChan ¶
type IClient ¶
type IClient interface {
Close()
// Send() chan []byte
SendChan() chan []byte
// Send(subject string, msg interface{})
Hub() IHub
WritePump()
ReadPump()
GetProps() map[string]interface{}
// Get(key interface{}) interface{}
// Set(key, value interface{})
NewClientMessage(data []byte) (*ClientMessage, error)
GetClient() *Client
}
type IHub ¶
type IHub interface {
//Get hub's id
Id() interface{}
//before new client join
BeforeJoin(callback func(client IClient) error)
AfterJoin(callback func(client IClient))
//On client leave
BeforeLeave(callback func(client IClient))
AfterLeave(callback func(client IClient))
BeforeWsMsg(callback func(msg *ClientMessage) bool)
//Add filter
// Use(filter Filter)
// Attach an event handler function
On(subject string, handler Handler)
OnWs(subject string, handler HandlerWs)
// OnLocal(subject string, handler HandlerLocal)
//simulate client send msg
// Emit(msg *ClientMessage)
//Dettach an event handler function
Off(subject string, handler Handler)
OffWs(subject string, handler HandlerWs)
SendRedisRaw(msg *MessageIn)
SendRedis(subject string, data interface{})
//Send message to all clients
SendWsAll(subject string, message interface{})
SendWs(subject string, message interface{}, receivers ...IClient)
EchoWs(msg *ClientMessage)
Close()
// CloseMessageLoop()
// SetSelf(self IHub)
Run()
UnregisterChan() chan IClient
RegisterChan() chan IClient
MessageChan() chan *ClientMessage
// MessageLocalChan() chan<- MessageLocal
CloseChan() chan struct{}
Clients() map[IClient]bool
OnTick(func(int))
GetSeconds() int
SendWsClient(client IClient, subject string, message interface{})
SendWsBytes(client IClient, bs []byte)
}
IHub like chat room
type IRoute ¶
type IRoute interface {
Route(subject string) []Handler
// Attach an event handler function
On(subject string, handler Handler)
//Dettach an event handler function
Off(subject string, handler Handler)
}
find callbacks in hub
type MessageLocal ¶
type MessageOut ¶
type MessageOut struct {
Subject string
Data interface{}
}
send Message should have this format
func (MessageOut) Encode ¶
func (m MessageOut) Encode() ([]byte, error)