Documentation
¶
Index ¶
- Variables
- type BinaryEngineIOClient
- type BinaryParser
- type Client
- func (c *Client) Close() error
- func (c *Client) Connect(ctx context.Context, callbacks ...func(arg interface{})) error
- func (c *Client) Emit(event interface{}, args ...interface{}) error
- func (c *Client) On(event string, handler interface{})
- func (c *Client) OnAny(handler func(string, []interface{}))
- func (c *Client) SetHandshakeData(data map[string]interface{})
- type ClientOption
- func WithConnectTimeout(timeout time.Duration) ClientOption
- func WithDebugPayload(enabled bool) ClientOption
- func WithDefaultNamespace(ns string) ClientOption
- func WithEngineIOClient(engineIOClient EngineIOClient) ClientOption
- func WithLogger(logger Logger) ClientOption
- func WithMaxBinarySize(size int) ClientOption
- func WithParser(parser Parser) ClientOption
- func WithRawURL(rawUrl string) ClientOption
- func WithTimer(timer Timer) ClientOption
- func WithURL(url *url.URL) ClientOption
- type EngineIOClient
- type InitClient
- type Logger
- type Parser
- type Timer
Constants ¶
This section is empty.
Variables ¶
var ErrClientClosed = errors.New("socket.io: client is closed")
ErrClientClosed is returned when Connect is called after Close.
var ErrConnectAlreadyStarted = errors.New("socket.io: Connect has already been called")
ErrConnectAlreadyStarted is returned after the client's one public Connect call has started. Automatic reconnection continues within that session.
Functions ¶
This section is empty.
Types ¶
type BinaryEngineIOClient ¶ added in v0.2.0
type BinaryEngineIOClient interface {
// SendBinary delivers a raw binary attachment frame (the buffers that follow
// a binary event/ack header).
SendBinary(message []byte) error
}
BinaryEngineIOClient is implemented by transports that can send attachment frames. It is optional so existing EngineIOClient implementations remain valid.
type BinaryParser ¶ added in v0.2.0
type BinaryParser interface {
// HasBinary reports whether an event carries []byte payloads that must be
// sent as a binary packet (PacketBinaryEvent/PacketBinaryAck).
HasBinary(event *socketio_v5.Event) bool
// SerializeBinary encodes an event with binary payloads into a header packet
// plus the ordered binary attachments that follow it on the wire.
SerializeBinary(*socketio_v5.Message) (header []byte, attachments [][]byte, err error)
// ReconstructBinary substitutes collected binary attachments back into the
// placeholders of a parsed binary packet, exposing them as []byte.
ReconstructBinary(msg *socketio_v5.Message, attachments [][]byte) error
}
BinaryParser is an optional capability of parsers that use Socket.IO's separate binary attachment frames. Existing custom parsers keep control of their own wire format through Parser.Serialize.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(options ...ClientOption) (*Client, error)
func (*Client) SetHandshakeData ¶
SetHandshakeData stores a shallow copy of the provided map as the handshake payload. Top-level keys are detached from the caller's map, but nested maps/slices are still shared. Callers must not mutate nested values after calling SetHandshakeData, or supply only flat/JSON-primitive values.
type ClientOption ¶
type ClientOption func(*InitClient) error
func WithConnectTimeout ¶ added in v0.2.0
func WithConnectTimeout(timeout time.Duration) ClientOption
WithConnectTimeout limits the duration of the connection phase (transport dial and engine.io handshake) without limiting the session lifetime: with this option set, Connect() fails fast with context.DeadlineExceeded when the server is unreachable, while the context passed to Connect() still controls how long an established session lives.
The option configures the engine.io client built internally by NewClient, so it can't be combined with WithEngineIOClient — pass engineio_v4_client.WithConnectTimeout to your own engine.io client instead.
func WithDebugPayload ¶ added in v0.2.0
func WithDebugPayload(enabled bool) ClientOption
WithDebugPayload enables logging of raw payloads at debug level across the client and the default transports it builds. Disabled by default so production logs do not leak message contents (tokens, PII).
func WithDefaultNamespace ¶
func WithDefaultNamespace(ns string) ClientOption
func WithEngineIOClient ¶
func WithEngineIOClient(engineIOClient EngineIOClient) ClientOption
func WithLogger ¶
func WithLogger(logger Logger) ClientOption
func WithMaxBinarySize ¶ added in v0.2.0
func WithMaxBinarySize(size int) ClientOption
WithMaxBinarySize sets the maximum aggregate attachment bytes retained for a single inbound binary event or acknowledgement. The default is 64 MiB.
func WithParser ¶
func WithParser(parser Parser) ClientOption
func WithRawURL ¶
func WithRawURL(rawUrl string) ClientOption
func WithTimer ¶
func WithTimer(timer Timer) ClientOption
func WithURL ¶
func WithURL(url *url.URL) ClientOption
type EngineIOClient ¶
type EngineIOClient interface {
Connect(ctx context.Context) error
Send(message []byte) error
On(event string, handler func([]byte))
Close() error
}
EngineIOClient представляет интерфейс для клиента Engine.IO
type InitClient ¶
type InitClient struct {
*Client
// contains filtered or unexported fields
}
type Logger ¶
type Logger interface {
Debugf(format string, v ...any)
Infof(format string, v ...any)
Warnf(format string, v ...any)
Errorf(format string, v ...any)
}
Logger представляет интерфейс для логирования
type Parser ¶
type Parser interface {
WrapCallback(callback interface{}) func(in []interface{})
Parse([]byte) (*socketio_v5.Message, error)
Serialize(*socketio_v5.Message) ([]byte, error)
}