group

package
v0.0.0-...-841d95d Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LowBitrate = 100 * 1024
	MinBitrate = LowBitrate * 2
	MaxBitrate = 1024 * 1024 * 1024
)
View Source
const DefaultMaxHistoryAge = 4 * time.Hour

Variables

View Source
var Directory, DataDirectory string
View Source
var ErrAnonymousNotAuthorised = &NotAuthorisedError{
	err: errors.New("anonymous users not authorised in this group"),
}
View Source
var ErrDescriptionsNotWritable = &NotAuthorisedError{}
View Source
var ErrDuplicateUsername = &NotAuthorisedError{
	errors.New("this username is taken"),
}
View Source
var ErrTagMismatch = errors.New("tag mismatch")
View Source
var UDPMin, UDPMax uint16
View Source
var UseMDNS bool

Functions

func APIFromCodecs

func APIFromCodecs(codecs []webrtc.RTPCodecParameters) (*webrtc.API, error)

func APIFromNames

func APIFromNames(names []string) (*webrtc.API, error)

func CodecPayloadType

func CodecPayloadType(codec webrtc.RTPCodecCapability) (webrtc.PayloadType, error)

func DelClient

func DelClient(c Client)

func Delete

func Delete(name string) bool

func DeleteDescription

func DeleteDescription(name, etag string) error

DeleteDescription deletes a description (and therefore persistently deletes a group) but only if it matches a given ETag.

func DeleteUser

func DeleteUser(group, username, etag string) error

func GetDescriptionNames

func GetDescriptionNames() ([]string, error)

func GetDescriptionTag

func GetDescriptionTag(name string) (string, error)

GetDescriptionTag returns an ETag for a description.

func GetNames

func GetNames() []string

func GetUserTag

func GetUserTag(group, username string) (string, error)

func GetUsers

func GetUsers(group string) ([]string, string, error)

func Range

func Range(f func(g *Group) bool)

func SetFallbackUsers

func SetFallbackUsers(group string, users []UserDescription) error

func SetKeys

func SetKeys(group string, keys []map[string]any) error

func SetUserPassword

func SetUserPassword(group, username string, pw Password) error

func Shutdown

func Shutdown(message string)

func Update

func Update()

Update checks that all in-memory groups are up-to-date and updates the list of public groups. It also removes from memory any non-public groups that haven't been accessed in maxHistoryAge.

func UpdateDescription

func UpdateDescription(name, etag string, desc *Description) error

UpdateDescription overwrites a description if it matches a given ETag. In order to create a new group, pass an empty ETag.

func UpdateUser

func UpdateUser(group, username, etag string, user *UserDescription) error

Types

type ChatHistoryEntry

type ChatHistoryEntry struct {
	Id    string
	User  *string
	Time  time.Time
	Kind  string
	Value interface{}
}

type Client

type Client interface {
	Group() *Group
	Id() string
	Username() string
	SetUsername(string)
	Permissions() []string
	SetPermissions([]string)
	Data() map[string]interface{}
	PushConn(g *Group, id string, conn conn.Up, tracks []conn.UpTrack, replace string) error
	RequestConns(target Client, g *Group, id string) error
	Joined(group, kind string) error
	PushClient(group, kind, id, username string, perms []string, data map[string]interface{}) error
	Kick(id string, user *string, message string) error
}

type ClientCredentials

type ClientCredentials struct {
	System   bool
	Username *string
	Password string
	Token    string
}

type ClientPattern

type ClientPattern struct {
	Username string    `json:"username,omitempty"`
	Password *Password `json:"password,omitempty"`
}

type Configuration

type Configuration struct {
	PublicServer   bool   `json:"publicServer"`
	CanonicalHost  string `json:"canonicalHost"`
	ProxyURL       string `json:"proxyURL"`
	WritableGroups bool   `json:"writableGroups"`
	Users          map[string]UserDescription

	// obsolete fields
	Admin []ClientPattern `json:"admin"`
	// contains filtered or unexported fields
}

Configuration represents the contents of the data/config.json file.

func GetConfiguration

func GetConfiguration() (*Configuration, error)

func (Configuration) Zero

func (conf Configuration) Zero() bool

type Description

type Description struct {
	// The file this was deserialised from.  This is not necessarily
	// the name of the group, for example in case of a subgroup.
	FileName string `json:"-"`

	// The user-friendly group name
	DisplayName string `json:"displayName,omitempty"`

	// A user-readable description of the group.
	Description string `json:"description,omitempty"`

	// A user-readable contact, typically an e-mail address.
	Contact string `json:"contact,omitempty"`

	// A user-readable comment.  Ignored by the server.
	Comment string `json:"comment,omitempty"`

	// Whether to display the group on the landing page.
	Public bool `json:"public,omitempty"`

	// A URL to redirect the group to.  If this is not empty, most
	// other fields are ignored.
	Redirect string `json:"redirect,omitempty"`

	// The maximum number of simultaneous clients.  Unlimited if 0.
	MaxClients int `json:"max-clients,omitempty"`

	// The time for which history entries are kept.
	MaxHistoryAge int `json:"max-history-age,omitempty"`

	// Time after which joining is no longer allowed
	Expires *time.Time `json:"expires,omitempty"`

	// Time before which joining is not allowed
	NotBefore *time.Time `json:"not-before,omitempty"`

	// Whether recording is allowed.
	AllowRecording bool `json:"allow-recording,omitempty"`

	// Whether creating tokens is allowed
	UnrestrictedTokens bool `json:"unrestricted-tokens,omitempty"`

	// Whether subgroups are created on the fly.
	AutoSubgroups bool `json:"auto-subgroups,omitempty"`

	// Whether to lock the group when the last op logs out.
	Autolock bool `json:"autolock,omitempty"`

	// Whether to kick all users when the last op logs out.
	Autokick bool `json:"autokick,omitempty"`

	// Users allowed to login
	Users map[string]UserDescription `json:"users,omitempty"`

	// Credentials for users with arbitrary username
	FallbackUsers []UserDescription `json:"fallback-users,omitempty"`

	// The (public) keys used for token authentication.
	AuthKeys []map[string]interface{} `json:"authKeys,omitempty"`

	// The URL of the authentication server, if any.
	AuthServer string `json:"authServer,omitempty"`

	// The URL of the authentication portal, if any.
	AuthPortal string `json:"authPortal,omitempty"`

	// Codec preferences.  If empty, a suitable default is chosen in
	// the APIFromNames function.
	Codecs []string `json:"codecs,omitempty"`

	// Obsolete fields
	Op             []ClientPattern `json:"op,omitempty"`
	Presenter      []ClientPattern `json:"presenter,omitempty"`
	Other          []ClientPattern `json:"other,omitempty"`
	AllowSubgroups bool            `json:"allow-subgroups,omitempty"`
	AllowAnonymous bool            `json:"allow-anonymous,omitempty"`
	// contains filtered or unexported fields
}

Description represents a group description together with some metadata about the JSON file it was deserialised from.

func GetDescription

func GetDescription(name string) (*Description, error)

GetDescription gets a group description, either from cache or from disk

func GetSanitisedDescription

func GetSanitisedDescription(name string) (*Description, string, error)

GetSanitisedDescription returns the subset of the description that is published on the web interface together with a suitable ETag.

type Group

type Group struct {
	// contains filtered or unexported fields
}

func Add

func Add(name string, desc *Description) (*Group, error)

func AddClient

func AddClient(group string, c Client, creds ClientCredentials) (*Group, error)

func Get

func Get(name string) *Group

func (*Group) API

func (g *Group) API() (*webrtc.API, error)

func (*Group) AddToChatHistory

func (g *Group) AddToChatHistory(id string, user *string, time time.Time, kind string, value interface{})

func (*Group) ClearChatHistory

func (g *Group) ClearChatHistory()

func (*Group) ClientCount

func (g *Group) ClientCount() int

func (*Group) Data

func (g *Group) Data() map[string]interface{}

func (*Group) Description

func (g *Group) Description() *Description

func (*Group) GetChatHistory

func (g *Group) GetChatHistory() []ChatHistoryEntry

func (*Group) GetClient

func (g *Group) GetClient(id string) Client

func (*Group) GetClients

func (g *Group) GetClients(except Client) []Client

func (*Group) GetPermission

func (g *Group) GetPermission(creds ClientCredentials) (string, []string, error)

func (*Group) Locked

func (g *Group) Locked() (bool, string)

func (*Group) Name

func (g *Group) Name() string

func (*Group) Range

func (g *Group) Range(f func(c Client) bool)

func (*Group) SetLocked

func (g *Group) SetLocked(locked bool, message string)

func (*Group) Status

func (g *Group) Status(authentified bool, base *url.URL) Status

Status returns a group's status. Base is the base URL for groups; if omitted, then both the Location and Endpoint members are omitted from the result.

func (*Group) UpdateData

func (g *Group) UpdateData(d map[string]interface{})

func (*Group) UserExists

func (g *Group) UserExists(username string) bool

Return true if there is a user entry with the given username. Always return false for an empty username.

func (*Group) WallOps

func (g *Group) WallOps(message string)

type KickError

type KickError struct {
	Id       string
	Username *string
	Message  string
}

func (KickError) Error

func (err KickError) Error() string

type NotAuthorisedError

type NotAuthorisedError struct {
	// contains filtered or unexported fields
}

func (*NotAuthorisedError) Error

func (err *NotAuthorisedError) Error() string

func (*NotAuthorisedError) Unwrap

func (err *NotAuthorisedError) Unwrap() error

type Password

type Password RawPassword

func (Password) MarshalJSON

func (p Password) MarshalJSON() ([]byte, error)

func (Password) Match

func (p Password) Match(pw string) (bool, error)

func (*Password) UnmarshalJSON

func (p *Password) UnmarshalJSON(b []byte) error

type Permissions

type Permissions struct {
	// contains filtered or unexported fields
}

func NewPermissions

func NewPermissions(name string) (Permissions, error)

func (Permissions) MarshalJSON

func (p Permissions) MarshalJSON() ([]byte, error)

func (Permissions) Permissions

func (p Permissions) Permissions(desc *Description) []string

func (*Permissions) UnmarshalJSON

func (p *Permissions) UnmarshalJSON(b []byte) error

type ProtocolError

type ProtocolError string

func (ProtocolError) Error

func (err ProtocolError) Error() string

type RawPassword

type RawPassword struct {
	Type       string  `json:"type,omitempty"`
	Hash       string  `json:"hash,omitempty"`
	Key        *string `json:"key,omitempty"`
	Salt       string  `json:"salt,omitempty"`
	Iterations int     `json:"iterations,omitempty"`
}

type Status

type Status struct {
	Name              string `json:"name"`
	Redirect          string `json:"redirect,omitempty"`
	Location          string `json:"location,omitempty"`
	Endpoint          string `json:"endpoint,omitempty"`
	DisplayName       string `json:"displayName,omitempty"`
	Description       string `json:"description,omitempty"`
	AuthServer        string `json:"authServer,omitempty"`
	AuthPortal        string `json:"authPortal,omitempty"`
	Locked            bool   `json:"locked,omitempty"`
	ClientCount       *int   `json:"clientCount,omitempty"`
	CanChangePassword bool   `json:"canChangePassword,omitempty"`
}

func GetPublic

func GetPublic(base *url.URL) []Status

type SubGroup

type SubGroup struct {
	Name    string
	Clients int
}

func GetSubGroups

func GetSubGroups(parent string) []SubGroup

type UserDescription

type UserDescription struct {
	Password    Password    `json:"password"`
	Permissions Permissions `json:"permissions"`
}

func GetSanitisedUser

func GetSanitisedUser(group, username string) (UserDescription, string, error)

func (UserDescription) MarshalJSON

func (u UserDescription) MarshalJSON() ([]byte, error)

Custom MarshalJSON in order to omit ompty fields

type UserError

type UserError string

func (UserError) Error

func (err UserError) Error() string

Jump to

Keyboard shortcuts

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