mirror of
https://github.com/jech/galene.git
synced 2024-11-22 16:45:58 +01:00
Implement autolock.
This commit is contained in:
parent
bd287dbb0c
commit
6098d4af9d
5 changed files with 48 additions and 18 deletions
2
README
2
README
|
@ -235,6 +235,8 @@ the group.
|
||||||
- `allow-anonymous`: if true, then users may connect with an empty username;
|
- `allow-anonymous`: if true, then users may connect with an empty username;
|
||||||
- `allow-subgroups`: if true, then subgroups of the form `group/subgroup`
|
- `allow-subgroups`: if true, then subgroups of the form `group/subgroup`
|
||||||
are automatically created when first accessed;
|
are automatically created when first accessed;
|
||||||
|
- `autolock`: if true, the group will start locked and become locked
|
||||||
|
whenever there are no clients with operator privileges;
|
||||||
- `redirect`: if set, then attempts to join the group will be redirected
|
- `redirect`: if set, then attempts to join the group will be redirected
|
||||||
to the given URL; most other fields are ignored in this case;
|
to the given URL; most other fields are ignored in this case;
|
||||||
- `codecs`: this is a list of codecs allowed in this group. The default
|
- `codecs`: this is a list of codecs allowed in this group. The default
|
||||||
|
|
|
@ -67,6 +67,10 @@ func (client *Client) SetPermissions(perms group.ClientPermissions) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (client *Client) Permissions() group.ClientPermissions {
|
||||||
|
return group.ClientPermissions{}
|
||||||
|
}
|
||||||
|
|
||||||
func (client *Client) PushClient(id, username string, add bool) error {
|
func (client *Client) PushClient(id, username string, add bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,7 @@ type Client interface {
|
||||||
Group() *Group
|
Group() *Group
|
||||||
Id() string
|
Id() string
|
||||||
Challengeable
|
Challengeable
|
||||||
|
Permissions() ClientPermissions
|
||||||
SetPermissions(ClientPermissions)
|
SetPermissions(ClientPermissions)
|
||||||
OverridePermissions(*Group) bool
|
OverridePermissions(*Group) bool
|
||||||
PushConn(g *Group, id string, conn conn.Up, tracks []conn.UpTrack) error
|
PushConn(g *Group, id string, conn conn.Up, tracks []conn.UpTrack) error
|
||||||
|
|
|
@ -293,6 +293,7 @@ func Add(name string, desc *description) (*Group, error) {
|
||||||
timestamp: time.Now(),
|
timestamp: time.Now(),
|
||||||
api: APIFromNames(desc.Codecs),
|
api: APIFromNames(desc.Codecs),
|
||||||
}
|
}
|
||||||
|
autolock(g, g.getClientsUnlocked(nil))
|
||||||
groups.groups[name] = g
|
groups.groups[name] = g
|
||||||
return g, nil
|
return g, nil
|
||||||
}
|
}
|
||||||
|
@ -302,27 +303,24 @@ func Add(name string, desc *description) (*Group, error) {
|
||||||
|
|
||||||
if desc != nil {
|
if desc != nil {
|
||||||
g.description = desc
|
g.description = desc
|
||||||
g.api = APIFromNames(desc.Codecs)
|
} else if time.Since(g.description.loadTime) < 5*time.Second {
|
||||||
|
return g, nil
|
||||||
|
} else if !descriptionChanged(name, g.description) {
|
||||||
|
g.description.loadTime = time.Now()
|
||||||
return g, nil
|
return g, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if time.Since(g.description.loadTime) > 5*time.Second {
|
desc, err = GetDescription(name)
|
||||||
if descriptionChanged(name, g.description) {
|
if err != nil {
|
||||||
desc, err := GetDescription(name)
|
if !os.IsNotExist(err) {
|
||||||
if err != nil {
|
log.Printf("Reading group %v: %v", name, err)
|
||||||
if !os.IsNotExist(err) {
|
|
||||||
log.Printf("Reading group %v: %v",
|
|
||||||
name, err)
|
|
||||||
}
|
|
||||||
deleteUnlocked(g)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
g.description = desc
|
|
||||||
g.api = APIFromNames(desc.Codecs)
|
|
||||||
} else {
|
|
||||||
g.description.loadTime = time.Now()
|
|
||||||
}
|
}
|
||||||
|
deleteUnlocked(g)
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
g.description = desc
|
||||||
|
g.api = APIFromNames(desc.Codecs)
|
||||||
|
autolock(g, g.getClientsUnlocked(nil))
|
||||||
|
|
||||||
return g, nil
|
return g, nil
|
||||||
}
|
}
|
||||||
|
@ -451,7 +449,7 @@ func AddClient(group string, c Client) (*Group, error) {
|
||||||
if !perms.Op && g.locked != nil {
|
if !perms.Op && g.locked != nil {
|
||||||
m := *g.locked
|
m := *g.locked
|
||||||
if m == "" {
|
if m == "" {
|
||||||
m = "group is locked"
|
m = "this group is locked"
|
||||||
}
|
}
|
||||||
return nil, UserError(m)
|
return nil, UserError(m)
|
||||||
}
|
}
|
||||||
|
@ -483,6 +481,22 @@ func AddClient(group string, c Client) (*Group, error) {
|
||||||
return g, nil
|
return g, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// called locked
|
||||||
|
func autolock(g *Group, clients []Client) {
|
||||||
|
if g.locked == nil && g.description.Autolock {
|
||||||
|
lock := true
|
||||||
|
for _, c := range clients {
|
||||||
|
if c.Permissions().Op {
|
||||||
|
lock = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if lock {
|
||||||
|
m := "this group is locked"
|
||||||
|
g.locked = &m
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func DelClient(c Client) {
|
func DelClient(c Client) {
|
||||||
g := c.Group()
|
g := c.Group()
|
||||||
if g == nil {
|
if g == nil {
|
||||||
|
@ -498,11 +512,15 @@ func DelClient(c Client) {
|
||||||
delete(g.clients, c.Id())
|
delete(g.clients, c.Id())
|
||||||
g.timestamp = time.Now()
|
g.timestamp = time.Now()
|
||||||
|
|
||||||
|
clients := g.getClientsUnlocked(nil)
|
||||||
|
|
||||||
go func(clients []Client) {
|
go func(clients []Client) {
|
||||||
for _, cc := range clients {
|
for _, cc := range clients {
|
||||||
cc.PushClient(c.Id(), c.Username(), false)
|
cc.PushClient(c.Id(), c.Username(), false)
|
||||||
}
|
}
|
||||||
}(g.getClientsUnlocked(nil))
|
}(clients)
|
||||||
|
|
||||||
|
autolock(g, clients)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Group) GetClients(except Client) []Client {
|
func (g *Group) GetClients(except Client) []Client {
|
||||||
|
@ -668,6 +686,7 @@ type description struct {
|
||||||
AllowAnonymous bool `json:"allow-anonymous,omitempty"`
|
AllowAnonymous bool `json:"allow-anonymous,omitempty"`
|
||||||
AllowRecording bool `json:"allow-recording,omitempty"`
|
AllowRecording bool `json:"allow-recording,omitempty"`
|
||||||
AllowSubgroups bool `json:"allow-subgroups,omitempty"`
|
AllowSubgroups bool `json:"allow-subgroups,omitempty"`
|
||||||
|
Autolock bool `json:"autolock,omitempty"`
|
||||||
Op []ClientCredentials `json:"op,omitempty"`
|
Op []ClientCredentials `json:"op,omitempty"`
|
||||||
Presenter []ClientCredentials `json:"presenter,omitempty"`
|
Presenter []ClientCredentials `json:"presenter,omitempty"`
|
||||||
Other []ClientCredentials `json:"other,omitempty"`
|
Other []ClientCredentials `json:"other,omitempty"`
|
||||||
|
|
|
@ -93,6 +93,10 @@ func (c *webClient) Challenge(group string, creds group.ClientCredentials) bool
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *webClient) Permissions() group.ClientPermissions {
|
||||||
|
return c.permissions
|
||||||
|
}
|
||||||
|
|
||||||
func (c *webClient) SetPermissions(perms group.ClientPermissions) {
|
func (c *webClient) SetPermissions(perms group.ClientPermissions) {
|
||||||
c.permissions = perms
|
c.permissions = perms
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue