Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { *Options // contains filtered or unexported fields }
Client is a structure representing a client in a WebSocket communication setup. It contains options for configuration, channels for errors and messages, handlers for errors and messages, a map for managing active connections, and a Mutex for safe concurrent access.
func New ¶
New creates a new Client with the given options. It sets up channels for errors and messages, default handlers for errors and messages, and a map for active WebSocket connections.
func (*Client) Connect ¶ added in v0.10.0
Connect establishes a WebSocket connection to the given URL. It adds the new connection to the client's map of connections and starts listening on it.
func (*Client) HandleErrorFunc ¶ added in v0.5.0
HandleErrorFunc sets the function to be called when an error occurs. The function should take an error as its argument.
func (*Client) HandleMessageFunc ¶
HandleMessageFunc sets the function to be called when a message is received. The function should take a message as its argument.
func (*Client) Listen ¶ added in v0.5.0
Listen starts listening for errors and messages on the client's channels. When a message or an error is received, it calls the appropriate handler function in a new goroutine. The function returns when the provided context is done.
func (*Client) SendMessage ¶ added in v0.10.0
SendMessage sends the given message to all active WebSocket connections of the client. It first marshals the message into a byte slice. If an error occurs, it sends the error on the error channel.