botclient

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: AGPL-3.0 Imports: 11 Imported by: 1 module, 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 botclient is the signaling side of the server-side helpers (echo, player, and the bots of the kunveno-notes and kunveno-recorder add-ons): join a room in a helper role and answer the server's offers on a pion peer connection, and (Rooms) keep a helper in every room the server lists on a control endpoint. It is public so that helpers built in other modules can use it; keep its API stable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dial

func Dial(ctx context.Context, url string, insecure bool) (*websocket.Conn, error)

Dial opens the signaling WebSocket.

func ListRooms added in v0.4.3

func ListRooms(ctx context.Context, client *http.Client, url string) (map[string]bool, error)

ListRooms asks a control endpoint which rooms want the helper.

func Serve

func Serve(ctx context.Context, conn *websocket.Conn, pc *webrtc.PeerConnection, room, name, role string, onJoined func(send func(any) error)) error

Serve joins room as a helper (role "echo", "player", "camera", "notes", "recorder" or "facilitator") and answers every offer on pc until the connection or ctx ends. onJoined (may be nil) runs once the server has admitted us and gets a function for sending further messages.

func ServeWith

func ServeWith(ctx context.Context, conn *websocket.Conn, pc *webrtc.PeerConnection, room, name, role string, o Options) error

ServeWith is Serve with every callback.

Types

type Options

type Options struct {
	// OnJoined runs once the server has admitted us, with a function for sending further messages.
	// The function is safe for concurrent use.
	OnJoined func(send func(any) error)
	// OnJoinedFrame, when set, gets the raw joined frame before OnJoined runs; the recorder
	// reads the meeting start from it.
	OnJoinedFrame func(data []byte)
	// OnMessage gets every server message other than joined, error and offer: its type and the
	// raw frame. It runs on the read loop and must not block.
	OnMessage func(typ string, data []byte)
}

Options are the optional callbacks of ServeWith.

type Rooms added in v0.4.3

type Rooms struct {
	Control string        // the control endpoint
	Client  *http.Client  // for the polls; nil means one with a 3 s timeout
	Poll    time.Duration // between polls
	Retry   time.Duration // Stay: the wait before a rejoin
	Log     *slog.Logger

	// Serve keeps the helper in one room until it is done there; the room can start again at a later
	// poll after Serve returns. ctx ends when Run's context ends, and also when the room leaves the
	// list if CancelUnlisted is set.
	Serve func(ctx context.Context, slug string)
	// CancelUnlisted ends a room's context as soon as a poll no longer lists it (the echo). Without
	// it a room ends on its own, typically when the server tells the helper to stop, and Wanted says
	// whether the room still asks for it.
	CancelUnlisted bool
	// Listed, when set, sees every successful poll's answer before any room starts and may delete
	// slugs from it: a deleted slug is neither started nor Wanted.
	Listed func(ctx context.Context, want map[string]bool)
	// OnRejoin, when set, runs before each rejoin in Stay.
	OnRejoin func(slug string)
	// contains filtered or unexported fields
}

Rooms keeps a helper in every room the server lists on a control endpoint: GET returns a JSON array of room slugs (/internal/echo, /internal/notes, /internal/recording; loopback only). Run polls the endpoint and runs Serve in a goroutine of its own for every listed room that has none; Stay is the usual body of Serve: join, and rejoin after a drop while the room still wants the helper.

Set the fields before Run and do not change them afterwards.

func (*Rooms) Run added in v0.4.3

func (r *Rooms) Run(ctx context.Context)

Run polls the control endpoint until ctx ends, then waits for every room's Serve to return.

func (*Rooms) Running added in v0.4.3

func (r *Rooms) Running(slug string) bool

Running reports whether the room's Serve is running.

func (*Rooms) Stay added in v0.4.3

func (r *Rooms) Stay(ctx context.Context, slug string, log *slog.Logger, session func(ctx context.Context) (done bool, err error))

Stay runs session in the room until it reports the helper is done there (the server's stop) or ctx ends. After any other return it rejoins once Retry has passed, unless the room no longer wants the helper.

func (*Rooms) Update added in v0.4.3

func (r *Rooms) Update(ctx context.Context, want map[string]bool)

Update applies one answer of the control endpoint: it starts the listed rooms that have no goroutine and, with CancelUnlisted, ends the rooms no longer listed. Run calls it after every successful poll; call it directly only while Run is not running, as tests do.

func (*Rooms) Wanted added in v0.4.3

func (r *Rooms) Wanted(slug string) bool

Wanted reports whether the last poll listed the room.

Jump to

Keyboard shortcuts

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