client

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package client implements the GoSpeak client networking.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeyNameToVK

func KeyNameToVK(name string) int

KeyNameToVK is a no-op on non-Windows.

Types

type Bookmark

type Bookmark struct {
	Name        string `yaml:"name"`
	ControlAddr string `yaml:"control_addr"`
	VoiceAddr   string `yaml:"voice_addr"`
	Username    string `yaml:"username"`
	Token       string `yaml:"token"`
}

Bookmark represents a saved server connection.

type BookmarkStore

type BookmarkStore struct {
	Bookmarks []Bookmark `yaml:"bookmarks"`
	// contains filtered or unexported fields
}

BookmarkStore manages server bookmarks stored next to the binary.

func NewBookmarkStore

func NewBookmarkStore() *BookmarkStore

NewBookmarkStore creates a bookmark store using a file next to the executable.

func (*BookmarkStore) Add

func (bs *BookmarkStore) Add(b Bookmark) bool

Add adds or updates a bookmark. Returns true if it was a new entry.

func (*BookmarkStore) FindByAddr

func (bs *BookmarkStore) FindByAddr(controlAddr string) *Bookmark

FindByAddr returns a bookmark matching the given control address, or nil.

func (*BookmarkStore) Load

func (bs *BookmarkStore) Load() error

Load reads bookmarks from disk. Returns empty list if file doesn't exist.

func (*BookmarkStore) Save

func (bs *BookmarkStore) Save() error

Save writes bookmarks to disk.

type ControlClient

type ControlClient struct {
	// contains filtered or unexported fields
}

ControlClient manages the TCP/TLS control plane connection.

func NewControlClient

func NewControlClient(addr string) (*ControlClient, error)

NewControlClient connects to the server's control plane via TLS.

func (*ControlClient) Authenticate

func (c *ControlClient) Authenticate(token, username string) (*pb.AuthResponse, error)

Authenticate sends an auth request and returns the auth response.

func (*ControlClient) Close

func (c *ControlClient) Close() error

Close closes the control connection.

func (*ControlClient) Done

func (c *ControlClient) Done() <-chan struct{}

Done returns a channel that's closed when the connection is lost.

func (*ControlClient) Send

func (c *ControlClient) Send(msg *pb.ControlMessage) error

Send sends a control message to the server.

func (*ControlClient) SetEventHandler

func (c *ControlClient) SetEventHandler(handler EventHandler)

SetEventHandler sets the callback for incoming control messages.

func (*ControlClient) StartReceiving

func (c *ControlClient) StartReceiving()

StartReceiving starts a goroutine that reads incoming control messages and dispatches them to the event handler.

type Engine

type Engine struct {

	// Callbacks for UI updates
	OnStateChange    func(state State)
	OnChannelsUpdate func(channels []pb.ChannelInfo)
	OnError          func(err error)
	OnVoiceActivity  func(active bool)
	OnRMSLevel       func(level float64)
	OnDisconnect     func(reason string)
	OnChatMessage    func(channelID int64, sender, text string, ts int64)
	OnTokenCreated   func(token string)
	OnRoleChanged    func(success bool, message string)
	OnAutoToken      func(token string) // called when server auto-generates a token for this user
	OnExportData     func(dataType, data string)
	OnImportResult   func(success bool, message string)
	// contains filtered or unexported fields
}

Engine is the main client engine that wires together audio, networking, and state.

func NewEngine

func NewEngine() *Engine

NewEngine creates a new client engine.

func (*Engine) BanUser

func (e *Engine) BanUser(userID int64, reason string, durationSeconds int64) error

BanUser sends a ban request (admin only).

func (*Engine) Connect

func (e *Engine) Connect(controlAddr, voiceAddr, token, username string) error

Connect authenticates to the server and starts audio/voice pipelines.

func (*Engine) CreateChannel

func (e *Engine) CreateChannel(name, description string, maxUsers int) error

CreateChannel sends a create channel request (admin only).

func (*Engine) CreateChannelAdvanced

func (e *Engine) CreateChannelAdvanced(name, description string, maxUsers int, parentID int64, isTemp bool, allowSubChannels bool) error

CreateChannelAdvanced sends a create channel request with all options.

func (*Engine) CreateSubChannel

func (e *Engine) CreateSubChannel(parentID int64, name string) error

CreateSubChannel creates a temporary sub-channel under a parent.

func (*Engine) CreateToken

func (e *Engine) CreateToken(role string, maxUses int, expiresInSeconds int64) error

CreateToken sends a create token request (admin only).

func (*Engine) DeleteChannel

func (e *Engine) DeleteChannel(channelID int64) error

DeleteChannel sends a delete channel request (admin only).

func (*Engine) Disconnect

func (e *Engine) Disconnect()

Disconnect disconnects from the server.

func (*Engine) ExportData

func (e *Engine) ExportData(dataType string) error

ExportData requests the server to export data ("channels" or "users") as YAML.

func (*Engine) GetChannels

func (e *Engine) GetChannels() []pb.ChannelInfo

GetChannels returns the current channel list.

func (*Engine) GetRole

func (e *Engine) GetRole() string

GetRole returns the user's role.

func (*Engine) GetState

func (e *Engine) GetState() State

GetState returns the current connection state.

func (*Engine) GetUsername

func (e *Engine) GetUsername() string

GetUsername returns the authenticated username.

func (*Engine) ImportChannels

func (e *Engine) ImportChannels(yamlData string) error

ImportChannels sends a YAML blob for the server to import as channels.

func (*Engine) IsDeafened

func (e *Engine) IsDeafened() bool

IsDeafened returns whether the client is deafened.

func (*Engine) IsMuted

func (e *Engine) IsMuted() bool

IsMuted returns whether the client is muted.

func (*Engine) JoinChannel

func (e *Engine) JoinChannel(channelID int64) error

JoinChannel sends a request to join a channel.

func (*Engine) KickUser

func (e *Engine) KickUser(userID int64, reason string) error

KickUser sends a kick request (admin/mod only).

func (*Engine) LeaveChannel

func (e *Engine) LeaveChannel() error

LeaveChannel sends a request to leave the current channel.

func (*Engine) SendChat

func (e *Engine) SendChat(text string) error

SendChat sends a text message to the current channel.

func (*Engine) SetDeafened

func (e *Engine) SetDeafened(deafened bool)

SetDeafened toggles deafen state.

func (*Engine) SetMuted

func (e *Engine) SetMuted(muted bool)

SetMuted toggles mute state.

func (*Engine) SetUserRole

func (e *Engine) SetUserRole(targetUserID int64, newRole string) error

SetUserRole sends a role change request (admin only).

func (*Engine) SetVADThreshold

func (e *Engine) SetVADThreshold(threshold float64)

SetVADThreshold updates the VAD sensitivity.

type EventHandler

type EventHandler func(msg *pb.ControlMessage)

EventHandler is a callback for incoming control events.

type GlobalHotkeys

type GlobalHotkeys struct {
	OnMuteToggle   func()
	OnDeafenToggle func()
}

GlobalHotkeys is a no-op on non-Windows platforms. Users can still use the mute/deafen buttons in the UI.

func NewGlobalHotkeys

func NewGlobalHotkeys() *GlobalHotkeys

NewGlobalHotkeys creates a new GlobalHotkeys instance (no-op on non-Windows).

func (*GlobalHotkeys) SetKeys

func (g *GlobalHotkeys) SetKeys(muteKey, deafenKey string)

SetKeys is a no-op on non-Windows.

func (*GlobalHotkeys) Start

func (g *GlobalHotkeys) Start()

Start is a no-op on non-Windows.

func (*GlobalHotkeys) Stop

func (g *GlobalHotkeys) Stop()

Stop is a no-op on non-Windows.

type JitterBuffer

type JitterBuffer struct {
	// contains filtered or unexported fields
}

JitterBuffer orders incoming voice packets and handles packet loss.

func NewJitterBuffer

func NewJitterBuffer() *JitterBuffer

NewJitterBuffer creates a new jitter buffer.

func (*JitterBuffer) Pop

func (jb *JitterBuffer) Pop() ([]byte, uint32, bool)

Pop returns the next frame in sequence order. Returns (payload, seqNum, ok). If the next frame isn't available, checks if we should skip it (lost packet).

func (*JitterBuffer) Push

func (jb *JitterBuffer) Push(seqNum uint32, payload []byte)

Push adds a packet to the jitter buffer.

func (*JitterBuffer) Reset

func (jb *JitterBuffer) Reset()

Reset clears the jitter buffer.

type Settings

type Settings struct {
	MuteKey      string  `yaml:"mute_key"`
	DeafenKey    string  `yaml:"deafen_key"`
	VADThreshold float64 `yaml:"vad_threshold"`
	AudioInput   string  `yaml:"audio_input,omitempty"`
	AudioOutput  string  `yaml:"audio_output,omitempty"`
}

Settings stores user preferences persisted as YAML next to the binary.

func DefaultSettings

func DefaultSettings() *Settings

DefaultSettings returns default settings.

func LoadSettings

func LoadSettings() *Settings

LoadSettings loads settings from YAML or returns defaults.

func (*Settings) Save

func (s *Settings) Save() error

Save writes settings to YAML.

type State

type State int

State represents the client's connection state.

const (
	StateDisconnected State = iota
	StateConnecting
	StateConnected
)

type VoiceClient

type VoiceClient struct {

	// Incoming voice packets are sent here
	IncomingPackets chan *protocol.VoicePacket
	// contains filtered or unexported fields
}

VoiceClient manages the UDP voice connection.

func NewVoiceClient

func NewVoiceClient(serverAddr string, sessionID uint32, encKey []byte) (*VoiceClient, error)

NewVoiceClient creates a new UDP voice client.

func (*VoiceClient) Close

func (v *VoiceClient) Close() error

Close closes the voice connection.

func (*VoiceClient) SendVoice

func (v *VoiceClient) SendVoice(opusData []byte, timestamp uint32) error

SendVoice encrypts and sends an Opus frame over UDP.

func (*VoiceClient) SetChannel

func (v *VoiceClient) SetChannel(channelID int64)

SetChannel sets the current channel ID for outgoing packets.

func (*VoiceClient) StartReceiving

func (v *VoiceClient) StartReceiving()

StartReceiving starts listening for incoming voice packets.

Jump to

Keyboard shortcuts

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