Documentation
¶
Overview ¶
Package collab tracks who is connected to each terminal, what each participant may do, and announces presence and permission changes.
Index ¶
- Constants
- Variables
- type Action
- type Config
- type Event
- type Hub
- func (h *Hub) Close()
- func (h *Hub) EndTerminal(terminalID string)
- func (h *Hub) GrantsRevoked(terminalID string, grantIDs []string, reason string)
- func (h *Hub) Join(req JoinRequest) (*Participant, error)
- func (h *Hub) ParticipantCount(terminalID string) int
- func (h *Hub) Reserve(req JoinRequest) (*Participant, error)
- func (h *Hub) SessionRevoked(sessionID int64, reason string)
- func (h *Hub) Stats() Stats
- type JoinRequest
- type Observer
- type Participant
- type ParticipantInfo
- type Permissions
- type RevokedError
- type Role
- type Stats
- type Timer
Constants ¶
const ( EventPresenceSnapshot = "presence_snapshot" EventParticipantJoined = "participant_joined" EventParticipantLeft = "participant_left" EventPermissionChanged = "permission_changed" )
Server event types.
const ( ReasonDisconnected = "disconnected" ReasonSlowConsumer = "slow_consumer" ReasonExpired = "expired" )
Participant-left reasons besides revocation reasons.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Now func() time.Time
AfterFunc func(time.Duration, func()) Timer
// QueueLimit bounds the events waiting for one participant; a
// participant that falls further behind is dropped.
QueueLimit int
// MaxParticipants bounds the participants of one terminal.
MaxParticipants int
// Observer, if set, is told about every join, leave, and permission
// change.
Observer Observer
}
Config tunes a Hub. Zero fields receive defaults.
type Event ¶
type Event struct {
Type string `json:"type"`
Version uint64 `json:"version"`
Self string `json:"self,omitempty"`
Participants []ParticipantInfo `json:"participants,omitempty"`
Participant *ParticipantInfo `json:"participant,omitempty"`
Permissions *Permissions `json:"permissions,omitempty"`
Reason string `json:"reason,omitempty"`
}
Event is a presence or permission message. Version increases with every change to a terminal's participants, so all participants observe changes in the same order.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub holds the live participants of every terminal.
func (*Hub) Close ¶
func (h *Hub) Close()
Close ends every participant with ErrClosed and rejects later joins. It is idempotent.
func (*Hub) EndTerminal ¶
EndTerminal forgets a terminal whose session ended. Its participants are detached silently; their connections end with the session.
func (*Hub) GrantsRevoked ¶
GrantsRevoked removes the terminal's participants admitted by grantIDs.
func (*Hub) Join ¶
func (h *Hub) Join(req JoinRequest) (*Participant, error)
Join adds a participant at once: Reserve followed by Activate.
func (*Hub) ParticipantCount ¶
ParticipantCount reports how many announced participants terminalID has now; reservations are not counted.
func (*Hub) Reserve ¶
func (h *Hub) Reserve(req JoinRequest) (*Participant, error)
Reserve holds a place for a participant without announcing it. The reservation counts toward the participant limit and can be revoked or expire, but nobody, observers included, learns about it until Activate. Leave abandons it without a trace.
func (*Hub) SessionRevoked ¶
SessionRevoked removes every participant admitted by the access session.
type JoinRequest ¶
type JoinRequest struct {
TerminalID string
Role Role
GrantID string
SessionID int64
ExpiresAt time.Time
}
JoinRequest identifies a connecting participant. GrantID and SessionID tie a guest to its capability so revocations can find it; a zero ExpiresAt never expires.
type Observer ¶
Observer receives presence changes in the order participants see them. It is called with the hub's lock held, so it must return without blocking and must not call back into the hub.
type Participant ¶
type Participant struct {
// contains filtered or unexported fields
}
Participant is one connection's presence in a terminal.
func (*Participant) Activate ¶
func (p *Participant) Activate() error
Activate announces a reserved participant: it first receives a presence snapshot, then everyone else is told it joined. It returns the *RevokedError of a reservation revoked or expired meanwhile, and ErrClosed once the hub is closed. A reservation whose terminal ended stays detached and Activate does nothing; its connection ends with the session.
func (*Participant) Allowed ¶
func (p *Participant) Allowed(action Action) bool
Allowed reports whether the participant may take action now. Revocation and expiry take effect here immediately, independently of event delivery.
func (*Participant) ID ¶
func (p *Participant) ID() string
ID is the participant's public, non-secret identifier.
func (*Participant) Leave ¶
func (p *Participant) Leave()
Leave removes the participant and tells the others it disconnected. It is idempotent.
type ParticipantInfo ¶
ParticipantInfo is the public identity of a participant. It never carries credentials or network addresses.
type Permissions ¶
Permissions are the actions a participant may currently take.
type RevokedError ¶
type RevokedError struct{ Reason string }
RevokedError reports why a participant lost access. It matches ErrRevoked.
func (*RevokedError) Error ¶
func (e *RevokedError) Error() string
func (*RevokedError) Is ¶
func (e *RevokedError) Is(target error) bool