Documentation ¶
Index ¶
- type Client
- type ClientFn
- type Connections
- type Hub
- func (h *Hub) Accept(w http.ResponseWriter, r *http.Request) error
- func (h *Hub) Broadcast(msg []byte)
- func (h *Hub) BroadcastTo(msg []byte, filter func(Client) bool)
- func (h *Hub) Do(fn func(conns Connections))
- func (h *Hub) PingInterval() time.Duration
- func (h *Hub) ReadDeadline() time.Time
- func (h *Hub) ReadLimit() int64
- func (h *Hub) Remove(c Client)
- func (h *Hub) SetPongWait(d time.Duration)
- func (h *Hub) SetReadLimit(size int64)
- func (h *Hub) SetWriteWait(d time.Duration)
- func (h *Hub) Shutdown()
- func (h *Hub) WriteDeadline() time.Time
- type ReadFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { Write([]byte) Listen() Close() }
Client is interface for the client type
type Connections ¶
Connections is a map of Client interfaces to their corresponding WebSocket connection
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub is WebSocket hub instance
func New ¶
New returns a new websocket hub instance. NOTE: if fn is nil, the default Client will be used and the default read function will Broadcast the message to all connected users.
func (*Hub) Accept ¶
Accept starts the WebSocket connection and adds connection to the pool of clients.
func (*Hub) BroadcastTo ¶
BroadcastTo sends a message to the provided clients only
func (*Hub) Do ¶
func (h *Hub) Do(fn func(conns Connections))
Do executes the provided function in sequence and is thread safe. It allows external logic to be executed from within Hub.
func (*Hub) PingInterval ¶
PingInterval returns the ping interval for WebSocket ping-pong keepalives.
func (*Hub) ReadDeadline ¶
ReadDeadline returns the deadline for connection reads
func (*Hub) Remove ¶
Remove removes the provided client from the Hub NOTE: this does not close the connection on your behalf but rather just removes if from being tracked by the Hub, it is your own responsibility to close your own client, and is usually done within the Client's Close() function transparently.
func (*Hub) SetPongWait ¶
SetPongWait sets the pong wait timeout and automatically sets the ping period based off of the duration provided. The WebSocket's ReadDeadline will also be set to the same value.
func (*Hub) SetReadLimit ¶
SetReadLimit sets the limit, in bytes, for read operations
func (*Hub) SetWriteWait ¶
SetWriteWait sets the wait timeout for WebSocket writes.
func (*Hub) Shutdown ¶
func (h *Hub) Shutdown()
Shutdown finishes all actions queued prior to calling Shutdown, closes all client connections and then stops the Hub
func (*Hub) WriteDeadline ¶
WriteDeadline returns the deadline for connection writes