realtime

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package realtime adapts authenticated Centrifugo subscriptions and publications to the generic lobby. It does not create membership on socket connection.

Index

Constants

View Source
const ProxySecretHeader = "X-Lobby-Proxy-Secret"
View Source
const RefreshPath = "/internal/lobby/centrifugo/sub-refresh"
View Source
const SubscribePath = "/internal/lobby/centrifugo/subscribe"

Variables

This section is empty.

Functions

This section is empty.

Types

type Authorizer

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

func NewAuthorizer

func NewAuthorizer(identities domain.IdentityStore, store domain.Store, clock domain.Clock, policy domain.Policy) (*Authorizer, error)

func (*Authorizer) AuthorizeSubscription

func (authorizer *Authorizer) AuthorizeSubscription(ctx context.Context, playerID, channelName string) (domain.SubscriptionAuthorization, error)

type ErrorReporter

type ErrorReporter func(context.Context, error)

ErrorReporter receives the error behind a proxy answer that leaves it out, such as a 503 for an unreachable store, so the host can log it with the request.

type Proxy

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

func NewProxy

func NewProxy(authorizer domain.SubscriptionAuthorizer, secret string, options ...ProxyOption) (*Proxy, error)

func (*Proxy) Register

func (proxy *Proxy) Register(router chi.Router)

Register deliberately bypasses public Huma registration: these are trusted Centrifugo protocol endpoints, not player command endpoints.

func (*Proxy) ServeHTTP

func (proxy *Proxy) ServeHTTP(response http.ResponseWriter, request *http.Request)

type ProxyOption

type ProxyOption func(*Proxy)

ProxyOption configures a Proxy.

func WithErrorReporter

func WithErrorReporter(report ErrorReporter) ProxyOption

WithErrorReporter passes the cause of each 503 to report.

type Publication

type Publication struct {
	Channel string
	Data    []byte
}

Publication is one message for one Centrifugo channel.

type Publisher

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

Publisher pushes straight to Centrifugo's HTTP API after a commit. It sends all of a call's commands in one API request and retries the failed ones briefly. What still fails is logged and returned; it never undoes the commit, and clients recover by re-reading their state over HTTP. Nothing is queued.

func NewPublisher

func NewPublisher(client *gocent.Client, logger *slog.Logger, retry PushRetry) (*Publisher, error)

func (*Publisher) Publish

func (publisher *Publisher) Publish(ctx context.Context, publications ...Publication) error

Publish delivers each publication to its channel. Games use it for their own events, such as a turn result on each player's personal channel.

func (*Publisher) PublishChange

func (publisher *Publisher) PublishChange(ctx context.Context, room domain.Lobby, change domain.Change, stillDue domain.RevocationCheck) error

PublishChange announces a committed room version to the room channel and unsubscribes each revoked player from it. Before every attempt, stillDue confirms each unsubscribe, which is skipped once the player has rejoined.

type PushRetry

type PushRetry struct {
	Attempts       int
	AttemptTimeout time.Duration
	// Pause precedes the second attempt and doubles before each later one.
	Pause time.Duration
}

PushRetry bounds the time a request spends pushing after its commit.

func DefaultPushRetry

func DefaultPushRetry() PushRetry

DefaultPushRetry makes three attempts within about a second.

Jump to

Keyboard shortcuts

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