Documentation ¶
Index ¶
- Constants
- type BodyMessage
- type BodyMessageRead
- type Client
- func (c *Client) AddListener(eventName string, f ListenerFunc)
- func (c *Client) Close() (err error)
- func (c *Client) DelListener(eventName string)
- func (c *Client) Dial(addr string) error
- func (c *Client) DialWithHeaders(addr string, h http.Header) (err error)
- func (c *Client) HandlePing() error
- func (c *Client) Read() (err error)
- func (c *Client) SetListener(eventName string, f ListenerFunc)
- func (c *Client) Write(eventName string, payload interface{}) (err error)
- type ClientAdapter
- type ClientConfiguration
- type ListenerFunc
- type Manager
- func (m *Manager) AutoRegisterClient(c *Client)
- func (m *Manager) Client(k interface{}) (c *Client, ok bool)
- func (m *Manager) Clients(fn func(k interface{}, c *Client) error)
- func (m *Manager) Close() error
- func (m *Manager) CountClients() int
- func (m *Manager) Loop(fn func(k interface{}, c *Client))
- func (m *Manager) RegisterClient(k interface{}, c *Client)
- func (m *Manager) ServeHTTP(w http.ResponseWriter, r *http.Request, a ClientAdapter) (err error)
- func (m *Manager) UnregisterClient(k interface{})
- type ManagerConfiguration
Constants ¶
const ( EventNameDisconnect = "astiws.disconnect" PingPeriod = (pingWait * 9) / 10 )
Constants
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BodyMessage ¶
type BodyMessage struct { EventName string `json:"event_name"` Payload interface{} `json:"payload"` }
BodyMessage represents the body of a message
type BodyMessageRead ¶
type BodyMessageRead struct { BodyMessage Payload json.RawMessage `json:"payload"` }
BodyMessageRead represents the body of a message for read purposes Indeed when reading the body, we need the payload to be a json.RawMessage
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a hub client
func (*Client) AddListener ¶
func (c *Client) AddListener(eventName string, f ListenerFunc)
AddListener adds a listener
func (*Client) DelListener ¶
DelListener deletes a listener
func (*Client) DialWithHeaders ¶
DialWithHeader dials an addr with specific headers
func (*Client) SetListener ¶
func (c *Client) SetListener(eventName string, f ListenerFunc)
SetListener sets a listener
type ClientAdapter ¶
type ClientAdapter func(c *Client)
ClientAdapter represents a client adapter func
type ClientConfiguration ¶
type ClientConfiguration struct {
MaxMessageSize int `toml:"max_message_size"`
}
ClientConfiguration represents a client configuration
type ListenerFunc ¶
type ListenerFunc func(c *Client, eventName string, payload json.RawMessage) error
ListenerFunc represents a listener callback
type Manager ¶
Manager represents a websocket manager
func (*Manager) AutoRegisterClient ¶
AutoRegisterClient auto registers a new client
func (*Manager) Clients ¶
Clients executes a function on every client. It stops if an error is returned.
func (*Manager) CountClients ¶
CountClients returns the number of connected clients
func (*Manager) RegisterClient ¶
RegisterClient registers a new client
func (*Manager) ServeHTTP ¶
func (m *Manager) ServeHTTP(w http.ResponseWriter, r *http.Request, a ClientAdapter) (err error)
ServeHTTP handles an HTTP request and returns an error unlike an http.Handler We don't want to register the client yet, since we may want to index the map of clients with an information we don't have yet
func (*Manager) UnregisterClient ¶
func (m *Manager) UnregisterClient(k interface{})
UnregisterClient unregisters a client astiws.disconnected event is a good place to call this function