common

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package common provides shared types and utilities for server implementations.

Package common provides shared types and utilities for server implementations.

Package common provides shared types and utilities for server implementations.

Package common provides shared types and utilities for server implementations.

Index

Constants

View Source
const (
	// WriteWait is time allowed to write a message to the peer.
	WriteWait = 15 * time.Second

	// PongWait is time allowed to read the next pong message from the peer.
	// Increased from 60s to 90s for better mobile network tolerance.
	PongWait = 90 * time.Second

	// PingPeriod is the interval for sending pings. Must be less than PongWait.
	PingPeriod = (PongWait * 9) / 10 // 81 seconds

	// MaxMessageSize is the maximum message size allowed from peer.
	// Must be larger than max_file_size_kb (10MB) to support file transfers.
	MaxMessageSize = 12 * 1024 * 1024 // 12MB (allows 10MB files + JSON overhead)

	// SendBufferSize is the send buffer size per client.
	// Increased from 256 to 1024 for handling burst events.
	SendBufferSize = 1024

	// HeartbeatInterval is the application-level heartbeat interval.
	HeartbeatInterval = 30 * time.Second
)

WebSocket timing constants. These are tuned for mobile network tolerance.

Variables

View Source
var ErrBufferFull = errors.New("send buffer full")

ErrBufferFull is returned when the send buffer is full.

View Source
var ErrClosed = errors.New("closed")

ErrClosed is returned when operations are attempted on a closed resource.

Functions

func EventNotificationMethod

func EventNotificationMethod(eventType events.EventType) string

EventNotificationMethod returns the JSON-RPC method name for an event type.

func EventToJSONRPCNotification

func EventToJSONRPCNotification(event events.Event) ([]byte, error)

EventToJSONRPCNotification converts a domain event to a JSON-RPC notification. This is used to send events to JSON-RPC clients.

func ExtractEventPayload

func ExtractEventPayload(eventJSON []byte) (interface{}, error)

ExtractEventPayload extracts the payload field from event JSON.

Types

type Client

type Client interface {
	// ID returns the unique client identifier.
	ID() string

	Sender
	Closer
}

Client combines common client capabilities.

type Closer

type Closer interface {
	// Close closes the resource.
	Close() error

	// Done returns a channel that's closed when the resource is closed.
	Done() <-chan struct{}
}

Closer is an interface for closable resources.

type SendBuffer

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

SendBuffer provides a thread-safe buffered channel for sending messages. It's designed for high-throughput scenarios like WebSocket message delivery.

func NewSendBuffer

func NewSendBuffer(id string, capacity int) *SendBuffer

NewSendBuffer creates a new send buffer with the specified capacity.

func (*SendBuffer) Channel

func (b *SendBuffer) Channel() <-chan []byte

Channel returns the underlying channel for reading.

func (*SendBuffer) Close

func (b *SendBuffer) Close()

Close closes the send buffer.

func (*SendBuffer) Done

func (b *SendBuffer) Done() <-chan struct{}

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

func (*SendBuffer) IsClosed

func (b *SendBuffer) IsClosed() bool

IsClosed returns true if the buffer is closed.

func (*SendBuffer) Send

func (b *SendBuffer) Send(data []byte) error

Send queues data for sending. Returns ErrBufferFull if the buffer is full, or ErrClosed if the buffer has been closed.

type Sender

type Sender interface {
	// SendRaw sends raw bytes to the client.
	SendRaw(data []byte) error
}

Sender is an interface for sending raw bytes.

type StatusProvider

type StatusProvider interface {
	// GetAgentStatus returns the current agent status (e.g., "idle", "running").
	GetAgentStatus() string

	// GetUptimeSeconds returns the server uptime in seconds.
	GetUptimeSeconds() int64
}

StatusProvider provides status information for heartbeat events. This interface is implemented by the application to provide runtime status.

Jump to

Keyboard shortcuts

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