client

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 11 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

This section is empty.

Types

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
}

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
	// Err carries the terminal error when State is StateStopped.
	Err error
}

Event is what the UI consumes: a decoded protocol message, a state change, or a detected history gap after reconnecting.

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