client

package
v1.0.0-rc.5 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Redact

func Redact(s string) string

Redact masks the values that must never reach a log: chat JWTs in authenticate and reauthenticate frames and the site's cookies in any header or error text. Everything else passes through unchanged.

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 New

func New(cfg Config) *Client

New builds a Client; call Run to start it.

func (*Client) Events

func (c *Client) Events() <-chan Event

Events returns the stream the UI should drain. It is closed when Run returns.

func (*Client) Run

func (c *Client) Run(ctx context.Context)

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) SendChat

func (c *Client) SendChat(text string) error

SendChat sends a chat line (or slash command) to the joined channel.

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.

type State

type State int

State describes the connection lifecycle for the UI.

const (
	StateConnecting State = iota
	StateOnline
	StateReconnecting
	StateStopped
)

Connection states.

Jump to

Keyboard shortcuts

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