Versions in this module Expand all Collapse all v0 v0.1.0 May 14, 2026 Changes in this version + const DefaultAuthTimeout + const DefaultHeartbeatInterval + const DefaultMaxConnections + const DefaultPongTimeout + const DefaultPresenceTTL + const DefaultReadLimit + const DefaultSendQueueSize + const DefaultShutdownTimeout + const DefaultWriteTimeout + var ErrAlreadyStarted = errors.New("realtime: already started") + var ErrBackpressure = errors.New("realtime: send queue full") + var ErrConnectionLimit = errors.New("realtime: connection limit reached") + var ErrInvalidBrokerMessage = errors.New("realtime: invalid broker message") + var ErrInvalidOption = errors.New("realtime: invalid option") + var ErrRealtimeClosed = errors.New("realtime: shutdown in progress") + var ErrSessionClosed = errors.New("realtime: session closed") + var ErrUnauthorized = errors.New("realtime: unauthorized") + var ErrUnknownRoute = errors.New("realtime: unknown route") + type AnonymousAuthenticator struct + func (AnonymousAuthenticator) Authenticate(ctx context.Context, r *http.Request) (*Identity, error) + type Authenticator interface + Authenticate func(ctx context.Context, r *http.Request) (*Identity, error) + type BackpressurePolicy int + const CloseOnBackpressure + const DropNewest + const DropOldest + type Broker interface + Close func() error + Publish func(ctx context.Context, topic string, msg []byte) error + Subscribe func(ctx context.Context, topic string, handler BrokerHandler) (Subscription, error) + type BrokerHandler func(ctx context.Context, msg BrokerMessage) error + type BrokerMessage struct + Data []byte + SourceNode string + Topic string + type Codec interface + Marshal func(v any) ([]byte, error) + Unmarshal func(data []byte, v any) error + type Config struct + AuthTimeout time.Duration + Backpressure BackpressurePolicy + Debug bool + DisableAuthTimeout bool + DisableHeartbeat bool + DisableMaxConnections bool + DisablePongTimeout bool + DisablePresenceTTL bool + DisableShutdownTimeout bool + DisableWriteTimeout bool + HeartbeatInterval time.Duration + InsecureOrigins bool + MaxConnections int + NodeID string + OriginPatterns []string + PongTimeout time.Duration + PresenceTTL time.Duration + ReadLimit int64 + SendQueueSize int + ShutdownTimeout time.Duration + WriteTimeout time.Duration + type DisconnectHandler func(ctx context.Context, s *Session, info DisconnectInfo) + type DisconnectInfo struct + At time.Time + Code int + Err error + Expected bool + Initiator DisconnectInitiator + Reason string + type DisconnectInitiator string + const DisconnectByBackpressure + const DisconnectByClient + const DisconnectByError + const DisconnectByServer + const DisconnectByShutdown + type HandlerFunc func(ctx context.Context, s *Session, msg *Message) error + type Identity struct + Claims map[string]any + ID string + Roles []string + TenantID string + func (i Identity) Clone() Identity + type LogSink interface + Printf func(format string, args ...any) + type Message struct + Data json.RawMessage + ID string + Metadata map[string]string + Route string + func NewMessage(route string, data any) (*Message, error) + func (m *Message) Clone() *Message + func (m *Message) Decode(v any) error + type Middleware func(HandlerFunc) HandlerFunc + func Logger() Middleware + func Recovery() Middleware + func Timeout(timeout time.Duration) Middleware + type Option func(*Options) + func WithAuthTimeout(timeout time.Duration) Option + func WithAuthenticator(a Authenticator) Option + func WithBackpressure(policy BackpressurePolicy) Option + func WithBroker(b Broker) Option + func WithCodec(c Codec) Option + func WithConfig(cfg Config) Option + func WithDebug(enabled bool) Option + func WithHeartbeat(interval time.Duration) Option + func WithInsecureOrigins() Option + func WithLogger(l LogSink) Option + func WithMaxConnections(max int) Option + func WithOriginPatterns(patterns ...string) Option + func WithPresence(p Presence) Option + func WithReadLimit(limit int64) Option + func WithSendQueueSize(size int) Option + func WithWriteTimeout(timeout time.Duration) Option + type Options struct + Authenticator Authenticator + Broker Broker + Codec Codec + Logger LogSink + Presence Presence + type Presence interface + GetIdentitySessions func(ctx context.Context, tenantID, identityID string) ([]SessionInfo, error) + IsOnline func(ctx context.Context, tenantID, identityID string) (bool, error) + Register func(ctx context.Context, session *SessionInfo) error + Unregister func(ctx context.Context, sessionID string) error + type Realtime struct + func New(options ...Option) *Realtime + func (r *Realtime) Broadcast(ctx context.Context, route string, data any) error + func (r *Realtime) GetIdentitySessions(ctx context.Context, tenantID, identityID string) ([]SessionInfo, error) + func (r *Realtime) Handle(route string, h HandlerFunc) + func (r *Realtime) HandlePrefix(prefix string, h HandlerFunc) + func (r *Realtime) IsOnline(ctx context.Context, tenantID, identityID string) (bool, error) + func (r *Realtime) OnConnect(h func(context.Context, *Session) error) + func (r *Realtime) OnDisconnect(h DisconnectHandler) + func (r *Realtime) OnError(h func(context.Context, error)) + func (r *Realtime) OnMessage(h HandlerFunc) + func (r *Realtime) SendToIdentity(ctx context.Context, tenantID, identityID, route string, data any) error + func (r *Realtime) ServeHTTP(w http.ResponseWriter, req *http.Request) + func (r *Realtime) Shutdown(ctx context.Context) error + func (r *Realtime) Start(ctx context.Context) error + func (r *Realtime) Use(middleware ...Middleware) + type Session struct + func (s *Session) Close(code int, reason string) error + func (s *Session) CloseInfo() DisconnectInfo + func (s *Session) Closed() bool + func (s *Session) ConnectedAt() time.Time + func (s *Session) Context() context.Context + func (s *Session) ID() string + func (s *Session) Identity() Identity + func (s *Session) RemoteAddr() string + func (s *Session) Send(ctx context.Context, route string, data any) error + func (s *Session) SendMessage(ctx context.Context, msg *Message) error + type SessionInfo struct + ConnectedAt time.Time + ExpiresAt time.Time + IdentityID string + NodeID string + RemoteAddr string + SessionID string + TenantID string + type StaticTokenAuthenticator struct + Identity Identity + Token string + func (a StaticTokenAuthenticator) Authenticate(ctx context.Context, r *http.Request) (*Identity, error) + type Subscription interface + Close func() error