Commit 8399ee2c authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Implement group description.

parent 7183730a
...@@ -99,6 +99,8 @@ fields, all of which are optional. ...@@ -99,6 +99,8 @@ fields, all of which are optional.
respectively with operator privileges, with presenter privileges, and respectively with operator privileges, with presenter privileges, and
as passive listeners; as passive listeners;
- `public`: if true, then the group is visible on the landing page; - `public`: if true, then the group is visible on the landing page;
- `description`: a human-readable description of the group; this is
displayed on the landing page for public groups;
- `max-clients`: the maximum number of clients that may join the group at - `max-clients`: the maximum number of clients that may join the group at
a time; a time;
- `allow-recording`: if true, then recording is allowed in this group; - `allow-recording`: if true, then recording is allowed in this group;
......
...@@ -75,7 +75,7 @@ type Group struct { ...@@ -75,7 +75,7 @@ type Group struct {
name string name string
mu sync.Mutex mu sync.Mutex
description *groupDescription description *description
// indicates that the group no longer exists, but it still has clients // indicates that the group no longer exists, but it still has clients
dead bool dead bool
locked *string locked *string
...@@ -90,7 +90,7 @@ func (g *Group) Name() string { ...@@ -90,7 +90,7 @@ func (g *Group) Name() string {
func (g *Group) Locked() (bool, string) { func (g *Group) Locked() (bool, string) {
g.mu.Lock() g.mu.Lock()
defer g.mu.Unlock() defer g.mu.Unlock()
if(g.locked != nil) { if g.locked != nil {
return true, *g.locked return true, *g.locked
} else { } else {
return false, "" return false, ""
...@@ -135,7 +135,7 @@ func (g *Group) API() *webrtc.API { ...@@ -135,7 +135,7 @@ func (g *Group) API() *webrtc.API {
return groups.api return groups.api
} }
func Add(name string, desc *groupDescription) (*Group, error) { func Add(name string, desc *description) (*Group, error) {
groups.mu.Lock() groups.mu.Lock()
defer groups.mu.Unlock() defer groups.mu.Unlock()
...@@ -429,10 +429,11 @@ func matchUser(user ClientCredentials, users []ClientCredentials) (bool, bool) { ...@@ -429,10 +429,11 @@ func matchUser(user ClientCredentials, users []ClientCredentials) (bool, bool) {
return false, false return false, false
} }
type groupDescription struct { type description struct {
loadTime time.Time `json:"-"` loadTime time.Time `json:"-"`
modTime time.Time `json:"-"` modTime time.Time `json:"-"`
fileSize int64 `json:"-"` fileSize int64 `json:"-"`
Description string `json:"description,omitempty"`
Redirect string `json:"redirect,omitempty"` Redirect string `json:"redirect,omitempty"`
Public bool `json:"public,omitempty"` Public bool `json:"public,omitempty"`
MaxClients int `json:"max-clients,omitempty"` MaxClients int `json:"max-clients,omitempty"`
...@@ -443,7 +444,7 @@ type groupDescription struct { ...@@ -443,7 +444,7 @@ type groupDescription struct {
Other []ClientCredentials `json:"other,omitempty"` Other []ClientCredentials `json:"other,omitempty"`
} }
func descriptionChanged(name string, old *groupDescription) (bool, error) { func descriptionChanged(name string, old *description) (bool, error) {
fi, err := os.Stat(filepath.Join(Directory, name+".json")) fi, err := os.Stat(filepath.Join(Directory, name+".json"))
if err != nil { if err != nil {
return false, err return false, err
...@@ -454,14 +455,14 @@ func descriptionChanged(name string, old *groupDescription) (bool, error) { ...@@ -454,14 +455,14 @@ func descriptionChanged(name string, old *groupDescription) (bool, error) {
return false, err return false, err
} }
func GetDescription(name string) (*groupDescription, error) { func GetDescription(name string) (*description, error) {
r, err := os.Open(filepath.Join(Directory, name+".json")) r, err := os.Open(filepath.Join(Directory, name+".json"))
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer r.Close() defer r.Close()
var desc groupDescription var desc description
fi, err := r.Stat() fi, err := r.Stat()
if err != nil { if err != nil {
...@@ -479,7 +480,7 @@ func GetDescription(name string) (*groupDescription, error) { ...@@ -479,7 +480,7 @@ func GetDescription(name string) (*groupDescription, error) {
return &desc, nil return &desc, nil
} }
func (desc *groupDescription) GetPermission (creds ClientCredentials) (ClientPermissions, error) { func (desc *description) GetPermission(creds ClientCredentials) (ClientPermissions, error) {
var p ClientPermissions var p ClientPermissions
if !desc.AllowAnonymous && creds.Username == "" { if !desc.AllowAnonymous && creds.Username == "" {
return p, UserError("anonymous users not allowed in this group, please choose a username") return p, UserError("anonymous users not allowed in this group, please choose a username")
...@@ -513,6 +514,7 @@ func (desc *groupDescription) GetPermission (creds ClientCredentials) (ClientPer ...@@ -513,6 +514,7 @@ func (desc *groupDescription) GetPermission (creds ClientCredentials) (ClientPer
type Public struct { type Public struct {
Name string `json:"name"` Name string `json:"name"`
Description string `json:"description,omitempty"`
ClientCount int `json:"clientCount"` ClientCount int `json:"clientCount"`
} }
...@@ -522,6 +524,7 @@ func GetPublic() []Public { ...@@ -522,6 +524,7 @@ func GetPublic() []Public {
if g.Public() { if g.Public() {
gs = append(gs, Public{ gs = append(gs, Public{
Name: g.name, Name: g.name,
Description: g.description.Description,
ClientCount: len(g.clients), ClientCount: len(g.clients),
}) })
} }
......
...@@ -44,8 +44,12 @@ async function listPublicGroups() { ...@@ -44,8 +44,12 @@ async function listPublicGroups() {
td.appendChild(a); td.appendChild(a);
tr.appendChild(td); tr.appendChild(td);
let td2 = document.createElement('td'); let td2 = document.createElement('td');
td2.textContent = `(${group.clientCount} clients)`; if(group.description)
td2.textContent = group.description;
tr.appendChild(td2); tr.appendChild(td2);
let td3 = document.createElement('td');
td3.textContent = `(${group.clientCount} clients)`;
tr.appendChild(td3);
table.appendChild(tr); table.appendChild(tr);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment