Documentation
¶
Overview ¶
Package client maintains the NG Chat WebSocket session: mint → dial → authenticate → resolve channel → subscribe, plus the heartbeat the server requires and the reconnect/dedupe logic that makes the hourly JWT-expiry disconnect invisible to the UI.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AccessDenied ¶
type AccessDenied struct {
Message string
}
AccessDenied is the cause of a stop when the server refuses the first authenticate outright (not a supporter, under 18, e-mail not validated, banned from the server) or refuses the subscribe (banned from the channel, alt of a banned account). The site minted the token, so the account is not signed out; nothing in the client can change the answer, so it is final. Message is server-authored HTML (the supporter notice carries a link), so a consumer renders it as markup.
func (*AccessDenied) Error ¶
func (e *AccessDenied) Error() string
type BackfillDone ¶
type BackfillDone struct{}
BackfillDone is emitted as Event.Msg once every message from a subscribe's backfill buffer has been replayed, so the UI can place anything that belongs after the history (the MOTD) at the bottom.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client runs one chat session with automatic reconnect.
func (*Client) Events ¶
Events returns the stream the UI should drain. It is closed when Run returns.
func (*Client) Run ¶
Run connects and keeps the session alive until ctx is canceled or the server sends a do-not-reconnect close ("client close", "server close", "idle timeout") or a hard auth rejection.
func (*Client) SendTyping ¶
func (c *Client) SendTyping()
SendTyping signals composing; errors are ignorable.
type Config ¶
type Config struct {
WSURL string
Channel string
Minter auth.Minter
// Cookie is an extra Cookie header sent on the WS upgrade (dev
// proxy routing).
Cookie string
// Log, when set, receives every frame (see Redact), state transition
// and mint outcome. Heartbeat pings and pongs are skipped so an hour
// of log stays readable. nil disables logging.
Log *slog.Logger
}
Config wires a Client.
type Event ¶
type Event struct {
// Msg is a decoded protocol value (protocol.Message etc.) or nil
// for pure state changes.
Msg any
// State is the connection state as of this event.
State State
// Gap is true when a reconnect's backfill did not overlap
// already-seen messages — history was lost and cannot be fetched.
Gap bool
// Backfill marks a Msg replayed from the subscribe buffer rather than
// received live, so the UI can show it without treating it as news
// (no bell for an old mention on every reconnect).
Backfill bool
// Err carries the terminal error when State is StateStopped, or the
// reason the last session ended when State is StateReconnecting.
Err error
}
Event is what the UI consumes: a decoded protocol message, a state change, or a detected history gap after reconnecting.
type RenewalFailed ¶
type RenewalFailed struct {
Err error
}
RenewalFailed is emitted as Event.Msg when the client could not answer a server Revalidate (the re-mint failed). It is informational: the server's close timer is still armed, and the ordinary reconnect path takes over at expiry.