Commit 4bdd7c76 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Implement group redirection.

parent c2b1723b
...@@ -75,7 +75,9 @@ fields, all of which are optional. ...@@ -75,7 +75,9 @@ fields, all of which are optional.
- `allow-recording`: if true, then recording is allowed in this group; - `allow-recording`: if true, then recording is allowed in this group;
- `allow-anonymous`: if true, then users may connect with an empty - `allow-anonymous`: if true, then users may connect with an empty
username; this is not recommended, since anonymous users are not username; this is not recommended, since anonymous users are not
allowed to participate in the chat. allowed to participate in the chat;
- `redirect`: if set, then attempts to join the group will be redirected
to the given URL; most other fields are ignored in this case.
A user definition is a dictionary with the following fields: A user definition is a dictionary with the following fields:
......
...@@ -334,6 +334,7 @@ type groupDescription struct { ...@@ -334,6 +334,7 @@ type groupDescription struct {
loadTime time.Time `json:"-"` loadTime time.Time `json:"-"`
modTime time.Time `json:"-"` modTime time.Time `json:"-"`
fileSize int64 `json:"-"` fileSize int64 `json:"-"`
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"`
AllowAnonymous bool `json:"allow-anonymous,omitempty"` AllowAnonymous bool `json:"allow-anonymous,omitempty"`
......
...@@ -709,6 +709,12 @@ func startClient(conn *websocket.Conn) (err error) { ...@@ -709,6 +709,12 @@ func startClient(conn *websocket.Conn) (err error) {
} }
return return
} }
if g.description.Redirect != "" {
// We normally redirect at the HTTP level, but the group
// description could have been edited in the meantime.
err = userError("group is now at " + g.description.Redirect)
return
}
c.group = g c.group = g
defer delClient(c) defer delClient(c)
......
...@@ -93,7 +93,7 @@ func groupHandler(w http.ResponseWriter, r *http.Request) { ...@@ -93,7 +93,7 @@ func groupHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
_, err := addGroup(name, nil) g, err := addGroup(name, nil)
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
http.NotFound(w, r) http.NotFound(w, r)
...@@ -104,6 +104,13 @@ func groupHandler(w http.ResponseWriter, r *http.Request) { ...@@ -104,6 +104,13 @@ func groupHandler(w http.ResponseWriter, r *http.Request) {
} }
return return
} }
if g.description.Redirect != "" {
http.Redirect(w, r, g.description.Redirect,
http.StatusPermanentRedirect)
return
}
http.ServeFile(w, r, filepath.Join(staticRoot, "sfu.html")) http.ServeFile(w, r, filepath.Join(staticRoot, "sfu.html"))
} }
......
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