Documentation
¶
Index ¶
- Variables
- func New(c *Config) *tinySSE
- type ChannelProvider
- type ClientConfig
- type Config
- type SSEClient
- type SSEMessage
- func (m *SSEMessage) DecodeFields(r model.FieldReader)
- func (m *SSEMessage) EncodeFields(w model.FieldWriter)
- func (m *SSEMessage) IsNil() bool
- func (m *SSEMessage) ModelName() string
- func (m *SSEMessage) Pointers() []any
- func (m *SSEMessage) Schema() []model.Field
- func (m *SSEMessage) Validate(action byte) error
- type SSEMessageList
- func (s *SSEMessageList) Append() model.Fielder
- func (s *SSEMessageList) At(i int) model.Fielder
- func (s *SSEMessageList) DecodeFields(_ model.FieldReader)
- func (s *SSEMessageList) EncodeFields(_ model.FieldWriter)
- func (s *SSEMessageList) IsNil() bool
- func (s *SSEMessageList) Len() int
- func (s *SSEMessageList) Pointers() []any
- func (s *SSEMessageList) Schema() []model.Field
- type SSEPublisher
- type ServerConfig
Constants ¶
This section is empty.
Variables ¶
Functions ¶
Types ¶
type ChannelProvider ¶ added in v0.0.15
type ChannelProvider interface {
// ResolveChannels extracts channels for an SSE connection.
// Called once when client connects.
//
// Parameters:
// - ctx: The router context (contains headers, path, cookies)
//
// Returns:
// - channels: List of channels to subscribe (e.g., ["all", "user:123", "role:admin"])
// - err: If non-nil, connection is rejected with 401/403
ResolveChannels(ctx router.Context) (channels []string, err error)
}
ChannelProvider resolves SSE channels for a connection. Implemented by external packages (e.g., crudp session handler).
type ClientConfig ¶
type ClientConfig struct {
// Endpoint is the SSE server URL.
Endpoint string
// RetryInterval in milliseconds for reconnection.
RetryInterval int
// MaxRetryDelay caps the exponential backoff.
MaxRetryDelay int
// MaxReconnectAttempts limits retry attempts. 0 = unlimited.
MaxReconnectAttempts int
}
ClientConfig holds configuration strictly for the Browser/WASM Client.
type Config ¶
type Config struct {
// Log is the centralized logger function.
// If nil, logging is disabled.
Log func(args ...any)
}
Config holds the shared configuration for both Server and Client.
type SSEClient ¶
type SSEClient struct {
// contains filtered or unexported fields
}
SSEClient is the SSE client for WASM.
func (*SSEClient) Connect ¶
func (c *SSEClient) Connect()
Connect establishes a connection to the SSE endpoint.
func (*SSEClient) OnMessage ¶
func (c *SSEClient) OnMessage(handler func(msg *SSEMessage))
OnMessage sets the handler for incoming messages.
type SSEMessage ¶
func (*SSEMessage) DecodeFields ¶ added in v0.0.14
func (m *SSEMessage) DecodeFields(r model.FieldReader)
func (*SSEMessage) EncodeFields ¶ added in v0.0.14
func (m *SSEMessage) EncodeFields(w model.FieldWriter)
func (*SSEMessage) IsNil ¶ added in v0.0.14
func (m *SSEMessage) IsNil() bool
func (*SSEMessage) ModelName ¶ added in v0.0.14
func (m *SSEMessage) ModelName() string
func (*SSEMessage) Pointers ¶ added in v0.0.14
func (m *SSEMessage) Pointers() []any
func (*SSEMessage) Schema ¶ added in v0.0.14
func (m *SSEMessage) Schema() []model.Field
func (*SSEMessage) Validate ¶ added in v0.0.15
func (m *SSEMessage) Validate(action byte) error
type SSEMessageList ¶ added in v0.0.14
type SSEMessageList []*SSEMessage
func (*SSEMessageList) Append ¶ added in v0.0.14
func (s *SSEMessageList) Append() model.Fielder
func (*SSEMessageList) DecodeFields ¶ added in v0.0.14
func (s *SSEMessageList) DecodeFields(_ model.FieldReader)
func (*SSEMessageList) EncodeFields ¶ added in v0.0.14
func (s *SSEMessageList) EncodeFields(_ model.FieldWriter)
func (*SSEMessageList) IsNil ¶ added in v0.0.14
func (s *SSEMessageList) IsNil() bool
func (*SSEMessageList) Len ¶ added in v0.0.14
func (s *SSEMessageList) Len() int
func (*SSEMessageList) Pointers ¶ added in v0.0.14
func (s *SSEMessageList) Pointers() []any
func (*SSEMessageList) Schema ¶ added in v0.0.14
func (s *SSEMessageList) Schema() []model.Field
type SSEPublisher ¶ added in v0.0.15
type SSEPublisher interface {
// Publish sends data to clients subscribed to the specified channels.
// Data can contain newlines - tinysse handles them internally.
Publish(data []byte, channels ...string)
// PublishEvent sends data with an event type for client-side routing.
PublishEvent(event string, data []byte, channels ...string)
}
SSEPublisher allows publishing messages to SSE clients. Implemented by sse.SSEServer.
type ServerConfig ¶ added in v0.0.15
type ServerConfig struct {
// ClientChannelBuffer prevents blocking on slow clients.
// Recommended: 10-100.
ClientChannelBuffer int
// HistoryReplayBuffer manages the "Last-Event-ID" replay history.
// Recommended: Depends on message frequency.
HistoryReplayBuffer int
// ReplayAllOnConnect replays the full history buffer to every new client
// on first connect (when no Last-Event-ID is provided).
// Useful for log viewers where clients may connect after events are published.
ReplayAllOnConnect bool
// ChannelProvider resolves channels for each SSE connection.
// If nil, a default provider is used that rejects all connections
// with error "channel provider not configured".
ChannelProvider ChannelProvider
}
ServerConfig holds configuration strictly for the SSE stream handler.
Click to show internal directories.
Click to hide internal directories.