websocket

package
v1.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2025 License: AGPL-3.0 Imports: 22 Imported by: 0

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(clientType string, ID, secret string, endpoint string, pingInterval time.Duration, pingTimeout time.Duration, opts ...ClientOption) (*Client, error)

NewClient creates a new websocket client

func (*Client) Close

func (c *Client) Close() error

Close closes the WebSocket connection gracefully

func (*Client) Connect

func (c *Client) Connect() error

Connect establishes the WebSocket connection

func (*Client) GetConfig

func (c *Client) GetConfig() *Config

func (*Client) GetServerVersion

func (c *Client) GetServerVersion() string

func (*Client) MetricsContext

func (c *Client) MetricsContext() context.Context

MetricsContext exposes the context used for telemetry emission when a connection is active.

func (*Client) OnConnect

func (c *Client) OnConnect(callback func() error)

func (*Client) OnTokenUpdate

func (c *Client) OnTokenUpdate(callback func(token string))

func (*Client) RegisterHandler

func (c *Client) RegisterHandler(messageType string, handler MessageHandler)

RegisterHandler registers a handler for a specific message type

func (*Client) SendMessage

func (c *Client) SendMessage(messageType string, data interface{}) error

SendMessage sends a message through the WebSocket connection

func (*Client) SendMessageInterval

func (c *Client) SendMessageInterval(messageType string, data interface{}, interval time.Duration) (stop func())

func (*Client) SendMessageNoLog

func (c *Client) SendMessageNoLog(messageType string, data interface{}) error

SendMessage sends a message through the WebSocket connection

type ClientOption

type ClientOption func(*Client)

func WithBaseURL

func WithBaseURL(url string) ClientOption

WithBaseURL sets the base URL for the client

func WithTLSConfig

func WithTLSConfig(config TLSConfig) ClientOption

WithTLSConfig sets the TLS configuration for the client

type Config

type Config struct {
	ID            string `json:"id"`
	Secret        string `json:"secret"`
	Endpoint      string `json:"endpoint"`
	TlsClientCert string `json:"tlsClientCert"`
}

type MessageHandler

type MessageHandler func(message WSMessage)

type TLSConfig

type TLSConfig struct {
	// New separate certificate support
	ClientCertFile string
	ClientKeyFile  string
	CAFiles        []string

	// Existing PKCS12 support (deprecated)
	PKCS12File string
}

TLSConfig holds TLS configuration options

type TokenResponse

type TokenResponse struct {
	Data struct {
		Token         string `json:"token"`
		ServerVersion string `json:"serverVersion"`
	} `json:"data"`
	Success bool   `json:"success"`
	Message string `json:"message"`
}

type WSMessage

type WSMessage struct {
	Type string      `json:"type"`
	Data interface{} `json:"data"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL