Documentation ¶
Overview ¶
Package connection implements a websocket connection wrapper with various helper functions.
Index ¶
- Constants
- type Connection
- func (connection *Connection) Close() error
- func (connection *Connection) GetNextInboundMessage() protocol.Message
- func (connection *Connection) GetNextOutboundMessage() protocol.Message
- func (connection *Connection) ReadMessage() error
- func (connection *Connection) SendMessage(message protocol.Message)
- func (connection *Connection) WriteMessage(message protocol.Message) error
Constants ¶
const (
// MessageBufferSize is the size of each clients message buffer (both directions).
MessageBufferSize = 32
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection struct { WS *websocket.Conn // The websocket connection itself. Joined time.Time // The time at which the connection was created. Latency time.Duration // The current latency of the connection. InboundMessageQueue chan protocol.Message // Inbound message queue - received messages are parked here until removed by a read pump. OutboundMessageQueue chan protocol.Message // Outbound message queue - messages to be sent are parked here until removed by a write pump. UUID xid.ID // A unique ID for this connection. // contains filtered or unexported fields }
Connection is a wrapper for a websocket connection.
func NewConnection ¶
func NewConnection(wsconn *websocket.Conn) *Connection
NewConnection creates a new connection.
func (*Connection) GetNextInboundMessage ¶
func (connection *Connection) GetNextInboundMessage() protocol.Message
GetNextInboundMessage gets the next message from the inbound message queue. Blocks when the queue is empty, so check the queue's length if you don't want to wait.
func (*Connection) GetNextOutboundMessage ¶
func (connection *Connection) GetNextOutboundMessage() protocol.Message
GetNextOutboundMessage gets the next message from the outbound message queue. Blocks when the queue is empty, so check the queue's length if you don't want to wait.
func (*Connection) ReadMessage ¶
func (connection *Connection) ReadMessage() error
ReadMessage synchronously retreives messages from the websocket.
func (*Connection) SendMessage ¶
func (connection *Connection) SendMessage(message protocol.Message)
SendMessage asynchronously sends a message down the websocket.
func (*Connection) WriteMessage ¶
func (connection *Connection) WriteMessage(message protocol.Message) error
WriteMessage synchronously sends messages down the websocket.