Documentation
¶
Index ¶
- type Client
- func (c *Client) Close()
- func (c *Client) HasChannel(channelID string) bool
- func (c *Client) JoinChannel(host, channelID string, headers http.Header, params map[string]string) error
- func (c *Client) LeaveChannel(channelID string, headers http.Header)
- func (c *Client) Publish(req sockets.Request) error
- func (c *Client) RegisterListener(msgType string, fn sockets.HandlerFunc)
- func (c *Client) WithChannelClosedListener(l sockets.HandlerFunc) *Client
- func (c *Client) WithChannelExpiredListener(l sockets.HandlerFunc) *Client
- func (c *Client) WithErrorHandler(e sockets.ClientErrorHandlerFunc) *Client
- func (c *Client) WithJoinRoomFailedListener(l sockets.HandlerFunc) *Client
- func (c *Client) WithJoinRoomSuccessListener(l sockets.HandlerFunc) *Client
- func (c *Client) WithMiddleware(mws ...sockets.MiddlewareFunc) *Client
- func (c *Client) WithServerErrorHandler(e sockets.ClientErrorMsgHandlerFunc) *Client
- type OptFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client contains a socket client which connects to one or many servers and channels on those servers.
func New ¶
New will setup a new websocket client which will connect to the server at the provided uri.
func (*Client) Close ¶
func (c *Client) Close()
Close will ensure the client is gracefully shut down.
func (*Client) HasChannel ¶
HasChannel will check to see if a client is connected to a channel.
func (*Client) JoinChannel ¶
func (c *Client) JoinChannel(host, channelID string, headers http.Header, params map[string]string) error
JoinChannel will connect the client to the supplied host and channelID, returning an error if it cannot connect.
If you need to authenticate with the server or send meta, add header/s.
func (*Client) LeaveChannel ¶
LeaveChannel will disconnect a client from a channel.
func (*Client) RegisterListener ¶
func (c *Client) RegisterListener(msgType string, fn sockets.HandlerFunc)
RegisterListener will add a new listener to the client.
func (*Client) WithChannelClosedListener ¶
func (c *Client) WithChannelClosedListener(l sockets.HandlerFunc) *Client
WithChannelClosedListener will replace the default channel closed handler which simply prints a debug message. This is raised when the server explicitly closes a channel.
By adding your own you can handle the channel close in a custom manner.
func (*Client) WithChannelExpiredListener ¶
func (c *Client) WithChannelExpiredListener(l sockets.HandlerFunc) *Client
WithChannelExpiredListener will replace the default channel expired handler which simply prints a debug message.
By adding your own you can handle the channel expiry in a custom manner.
func (*Client) WithErrorHandler ¶
func (c *Client) WithErrorHandler(e sockets.ClientErrorHandlerFunc) *Client
WithErrorHandler allows a user to overwrite the default error handler.
func (*Client) WithJoinRoomFailedListener ¶
func (c *Client) WithJoinRoomFailedListener(l sockets.HandlerFunc) *Client
WithJoinRoomFailedListener will replace the default room join failed handler with a custom one. This will allow the implementor to define their own logic after a room is joined.
func (*Client) WithJoinRoomSuccessListener ¶
func (c *Client) WithJoinRoomSuccessListener(l sockets.HandlerFunc) *Client
WithJoinRoomSuccessListener will replace the default room join success handler with a custom one. This will allow the implementor to define their own logic after a room is joined.
func (*Client) WithMiddleware ¶
func (c *Client) WithMiddleware(mws ...sockets.MiddlewareFunc) *Client
WithMiddleware will append the middleware funcs to any already registered middleware functions. When adding middleware, it is recommended to always add a PanicHandler first as this will ensure your application has the best chance of recovering. There is a default panic handler available under sockets.PanicHandler.
func (*Client) WithServerErrorHandler ¶
func (c *Client) WithServerErrorHandler(e sockets.ClientErrorMsgHandlerFunc) *Client
WithServerErrorHandler allows a user to overwrite the default server error handler.
This handles ErrorMessage responses from a server in response to a client send.
type OptFunc ¶
type OptFunc func(c *opts)
OptFunc defines a functional option to pass to the client at setup time.
func WithInfiniteReconnect ¶
func WithInfiniteReconnect() OptFunc
WithInfiniteReconnect will make the client listen forever for the server to reconnect in the event of a connection loss.
func WithMaxMessageSize ¶
WithMaxMessageSize defines the maximum message size in bytes that the client will accept. Default is 512 bytes.
func WithPongTimeout ¶
WithPongTimeout defines the wait time the client will wait for a pong response from the server. Default is 60 seconds.
func WithReconnect ¶
func WithReconnect() OptFunc
WithReconnect will enable reconnects from a client, in the event of a connection loss with a server the client will attempt to reconnect.
Default values are to retry 3 times with a 30 second wait between retry.
func WithReconnectAttempts ¶
WithReconnectAttempts will overwrite the default connection attempts of 3 with value attempts, when this value is exceeded the connection will cease to re-connect and exit.
func WithReconnectTimeout ¶
WithReconnectTimeout will overwrite the default timeout between reconnect attempts of 30 seconds with value t.
func WithWriteTimeout ¶
WithWriteTimeout defines the timeout length that the client will wait before failing the write. Default is 60 seconds.