Documentation
¶
Index ¶
Constants ¶
View Source
const ( // TextMessage denotes a text data message. The text message payload is // interpreted as UTF-8 encoded text data. TextMessage = 1 // BinaryMessage denotes a binary data message. BinaryMessage = 2 // CloseMessage denotes a close control message. The optional message // payload contains a numeric code and text. Use the FormatCloseMessage // function to format a close message payload. CloseMessage = 8 // PingMessage denotes a ping control message. The optional message payload // is UTF-8 encoded text. PingMessage = 9 // PongMessage denotes a pong control message. The optional message payload // is UTF-8 encoded text. PongMessage = 10 )
The message types are defined in RFC 6455, section 11.8.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { // a channel which is closed when the websocket client is disconnected. ExitSignal chan struct{} // channel of inbound messages. // this will be created by the user if receiving messages is needed. ReceiveChan chan *WebsocketMsg // FilterCallback is used to filter messages to clients on BroadcastMsg FilterCallback func(c *Client, data interface{}) bool // contains filtered or unexported fields }
Client is a middleman between the node and the websocket connection.
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) BroadcastMsg ¶
BroadcastMsg sends a message to all clients.
func (*Hub) ServeWebsocket ¶
func (h *Hub) ServeWebsocket(w http.ResponseWriter, r *http.Request, onCreate func(client *Client), onConnect func(client *Client))
ServeWebsocket handles websocket requests from the peer. onCreate gets called when the client is created. onConnect gets called when the client was registered.
type WebsocketMsg ¶
type WebsocketMsg struct { // MsgType is the type of the message based on RFC 6455. MsgType int // Data is the received data of the message. Data []byte }
WebsocketMsg is a message received via websocket.
Click to show internal directories.
Click to hide internal directories.