Documentation
¶
Overview ¶
Package websocket provides a cross-platform WebSocket client implementation. On native, it uses github.com/gorilla/websocket. On web, it uses the browser's built-in WebSocket support via syscall/js.
The API is consistent across platforms, so low level details are not exposed. Use Connect to make a Client.
Index ¶
- type Client
- type MessageTypes
- func (i MessageTypes) Desc() string
- func (i MessageTypes) Int64() int64
- func (i MessageTypes) MarshalText() ([]byte, error)
- func (i *MessageTypes) SetInt64(in int64)
- func (i *MessageTypes) SetString(s string) error
- func (i MessageTypes) String() string
- func (i *MessageTypes) UnmarshalText(text []byte) error
- func (i MessageTypes) Values() []enums.Enum
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
}
Client represents a WebSocket client connection. You can use Connect to create a new Client.
func (*Client) Close ¶
Close cleanly closes the WebSocket connection. It does not directly trigger Client.OnClose, but once the connection is closed, Client.OnMessage will trigger it.
func (*Client) OnClose ¶
func (c *Client) OnClose(f func())
OnClose sets a callback function to be called when the connection is closed. This function can only be called once.
func (*Client) OnMessage ¶
func (c *Client) OnMessage(f func(typ MessageTypes, msg []byte))
OnMessage sets a callback function to be called when a message is received. This function can only be called once.
type MessageTypes ¶
type MessageTypes int32 //enums:enum
MessageTypes are the types of messages that can be sent or received.
const ( // TextMessage is a text message (string). // Equivalent to [websocket.TextMessage]. TextMessage MessageTypes = iota + 1 // BinaryMessage is a binary data message ([]byte). // Equivalent to [websocket.BinaryMessage]. BinaryMessage )
const MessageTypesN MessageTypes = 3
MessageTypesN is the highest valid value for type MessageTypes, plus one.
func MessageTypesValues ¶
func MessageTypesValues() []MessageTypes
MessageTypesValues returns all possible values for the type MessageTypes.
func (MessageTypes) Desc ¶
func (i MessageTypes) Desc() string
Desc returns the description of the MessageTypes value.
func (MessageTypes) Int64 ¶
func (i MessageTypes) Int64() int64
Int64 returns the MessageTypes value as an int64.
func (MessageTypes) MarshalText ¶
func (i MessageTypes) MarshalText() ([]byte, error)
MarshalText implements the encoding.TextMarshaler interface.
func (*MessageTypes) SetInt64 ¶
func (i *MessageTypes) SetInt64(in int64)
SetInt64 sets the MessageTypes value from an int64.
func (*MessageTypes) SetString ¶
func (i *MessageTypes) SetString(s string) error
SetString sets the MessageTypes value from its string representation, and returns an error if the string is invalid.
func (MessageTypes) String ¶
func (i MessageTypes) String() string
String returns the string representation of this MessageTypes value.
func (*MessageTypes) UnmarshalText ¶
func (i *MessageTypes) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface.
func (MessageTypes) Values ¶
func (i MessageTypes) Values() []enums.Enum
Values returns all possible values for the type MessageTypes.