Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(cfg ClientConfig, opts ...ClientOption) (*Client, error)
NewClient initializes and returns a new WebSocket client.
func (*Client) ErrorCh ¶
ErrorCh returns a channel that is used to receive client errors asynchronously.
type ClientConfig ¶
type ClientConfig struct {
// URL specifies the WebSocket URL to connect to.
// Should start with either `ws://` or `wss://`.
URL string
// ConnID specifies the id of the connection to be used in case of
// reconnection. Should be left empty on initial connect.
ConnID string
// AuthToken specifies the token to be used to authenticate
// the connection.
AuthToken string
}
func (ClientConfig) IsValid ¶
func (c ClientConfig) IsValid() error
type ClientOption ¶
type Message ¶
type Message struct {
ClientID string
ConnID string
Type MessageType
Data []byte
}
Message defines the data to be sent to or received from a ws connection.
type MessageType ¶
type MessageType int
MessageType defines the type of message sent to or received from a ws connection.
const ( TextMessage MessageType = iota + 1 BinaryMessage OpenMessage CloseMessage )
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(cfg ServerConfig, log mlog.LoggerIFace, opts ...ServerOption) (*Server, error)
NewServer initializes and returns a new WebSocket server.
func (*Server) Close ¶
func (s *Server) Close()
Close stops the websocket server and closes all the ws connections. Must be called once all senders are done.
func (*Server) ReceiveCh ¶
ReceiveCh returns a channel that can be used to receive messages from ws connections.
type ServerConfig ¶
type ServerConfig struct {
// ReadBufferSize specifies the size of the internal buffer
// used to read from a ws connection.
ReadBufferSize int
// WriteBufferSize specifies the size of the internal buffer
// used to wirte to a ws connection.
WriteBufferSize int
// PingInterval specifies the interval at which the server should send ping
// messages to its connections. If the client doesn't respond in 2*PingInterval
// the server will consider the client as disconnected and drop the connection.
PingInterval time.Duration
}
func (ServerConfig) IsValid ¶
func (c ServerConfig) IsValid() error
type ServerOption ¶
func WithAuthCb ¶
func WithAuthCb(cb AuthCb) ServerOption
WithAuthCb lets the caller set an optional callback to be called prior to performing the WebSocket upgrade.