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 ¶
- func Dial(ctx context.Context, url string, insecure bool) (*websocket.Conn, error)
- func ListRooms(ctx context.Context, client *http.Client, url string) (map[string]bool, error)
- func Serve(ctx context.Context, conn *websocket.Conn, pc *webrtc.PeerConnection, ...) error
- func ServeWith(ctx context.Context, conn *websocket.Conn, pc *webrtc.PeerConnection, ...) error
- type Options
- type Rooms
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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.
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
Run polls the control endpoint until ctx ends, then waits for every room's Serve to return.
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
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.