client

package
v0.0.0-...-dd4be11 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package client manages websocket client connections and their lifecycle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ID

type ID = string

ID is a unique identifier for websocket clients.

type SocketUser

type SocketUser interface {
	SocketType() websocket_mod.ClientType
}

SocketUser represents a user that can connect via websocket.

type WsClient

type WsClient struct {
	Active atomic.Bool
	// contains filtered or unexported fields
}

WsClient represents a websocket client connection.

func NewClient

func NewClient(ctx context.Context, conn *websocket.Conn, socketUser SocketUser) *WsClient

NewClient creates a new websocket client instance.

func (*WsClient) AddSubscription

func (wsc *WsClient) AddSubscription(sub websocket_mod.Subscription)

AddSubscription adds a new subscription to the client.

func (*WsClient) ClientType

func (wsc *WsClient) ClientType() websocket_mod.ClientType

ClientType returns the type of this client (web or tower).

func (*WsClient) Disconnect

func (wsc *WsClient) Disconnect() error

Disconnect closes the websocket connection and marks the client as inactive.

func (*WsClient) Error

func (wsc *WsClient) Error(err error)

Error logs an error and sends it to the client.

func (*WsClient) GetClientID

func (wsc *WsClient) GetClientID() ID

GetClientID returns the unique identifier for this client.

func (*WsClient) GetInstance

func (wsc *WsClient) GetInstance() *tower_model.Instance

GetInstance returns the tower instance associated with this client connection.

func (*WsClient) GetShortID

func (wsc *WsClient) GetShortID() ID

GetShortID returns a shortened version of the client ID for display purposes.

func (*WsClient) GetSubscriptions

func (wsc *WsClient) GetSubscriptions() []websocket_mod.Subscription

GetSubscriptions returns an iterator over the client's current subscriptions.

func (*WsClient) GetUser

func (wsc *WsClient) GetUser() *user_model.User

GetUser returns the user associated with this client connection.

func (*WsClient) IsOpen

func (wsc *WsClient) IsOpen() bool

IsOpen returns whether the client connection is currently active.

func (*WsClient) Log

func (wsc *WsClient) Log() *zerolog.Logger

Log returns the logger instance for this client.

func (*WsClient) Raw

func (wsc *WsClient) Raw(msg any) error

Raw sends a raw message to the client without additional formatting.

func (*WsClient) ReadOne

func (wsc *WsClient) ReadOne() (int, []byte, error)

ReadOne reads a single message from the websocket connection.

func (*WsClient) RemoveSubscription

func (wsc *WsClient) RemoveSubscription(key string)

RemoveSubscription removes a subscription from the client by key.

func (*WsClient) Send

func (wsc *WsClient) Send(msg websocket_mod.WsResponseInfo) error

Send sends a websocket message to the client.

func (*WsClient) SubLock

func (wsc *WsClient) SubLock()

SubLock acquires the subscription mutex lock.

func (*WsClient) SubUnlock

func (wsc *WsClient) SubUnlock()

SubUnlock releases the subscription mutex lock.

Jump to

Keyboard shortcuts

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