Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool manages a group of websocket connections. It is responsible for upgrading connections of new clients, reading and serializing messages from them. It also allows to broadcast a message to the entire pool.
func (*Pool) AddToPool ¶
func (p *Pool) AddToPool(w http.ResponseWriter, r *http.Request, messageType int, initialMessages [][]byte)
AddToPool is the intended way to add a client to the pool. It can be used inside an http.HandlerFunc. initialMessages is the array of message bodies that are going to be sent to the client before every other update from the pool. messageType specifies the type of each one of the initial messages.
func (*Pool) CloseAll ¶
func (p *Pool) CloseAll()
CloseAll shuts down all the clients in the pool. Make sure to invoke it before deleting the pool, otherwise it will lead to goroutine leaks.
func (*Pool) ReadQueue ¶
ReadQueue returns the readQueue of the pool. To read a message use <-pool.ReadQueue(). The choice of returning the channel instead of waiting for the next message and returning it is motivated by the advantage in "select" statement of the former approach.
func (*Pool) SendMessageToAll ¶
SendMessageToAll broadcasts data to all the clients in the pool. messageType is the integer associated to the type of websocket message, an example value for messageType is websocket.TextMessage where websocket refers to github.com/gorilla/websocket package.