mirror of
https://github.com/jech/galene.git
synced 2024-11-10 02:35:58 +01:00
Improve error handling on join failure.
Solves the issue of groups with a name ending in "/".
This commit is contained in:
parent
e3098899e1
commit
b134bfcf13
4 changed files with 74 additions and 46 deletions
|
@ -159,6 +159,10 @@ func (g *Group) API() *webrtc.API {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Add(name string, desc *description) (*Group, error) {
|
func Add(name string, desc *description) (*Group, error) {
|
||||||
|
if name == "" || strings.HasSuffix(name, "/") {
|
||||||
|
return nil, UserError("illegal group name")
|
||||||
|
}
|
||||||
|
|
||||||
groups.mu.Lock()
|
groups.mu.Lock()
|
||||||
defer groups.mu.Unlock()
|
defer groups.mu.Unlock()
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,11 @@ package rtpconn
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
|
@ -1031,13 +1031,18 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||||
c.password = m.Password
|
c.password = m.Password
|
||||||
g, err := group.AddClient(m.Group, c)
|
g, err := group.AddClient(m.Group, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
var s string
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return c.error(
|
s = "group does not exist"
|
||||||
group.UserError("group does not exist"),
|
|
||||||
)
|
|
||||||
} else if err == group.ErrNotAuthorised {
|
} else if err == group.ErrNotAuthorised {
|
||||||
|
s = "not authorised"
|
||||||
time.Sleep(200 * time.Millisecond)
|
time.Sleep(200 * time.Millisecond)
|
||||||
s := "not authorised"
|
} else if e, ok := err.(group.UserError); ok {
|
||||||
|
s = string(e)
|
||||||
|
} else {
|
||||||
|
s = "internal server error"
|
||||||
|
log.Printf("Join group: %v")
|
||||||
|
}
|
||||||
return c.write(clientMessage{
|
return c.write(clientMessage{
|
||||||
Type: "joined",
|
Type: "joined",
|
||||||
Kind: "fail",
|
Kind: "fail",
|
||||||
|
@ -1046,14 +1051,16 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||||
Value: &s,
|
Value: &s,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return err
|
|
||||||
}
|
|
||||||
if redirect := g.Redirect(); redirect != "" {
|
if redirect := g.Redirect(); redirect != "" {
|
||||||
// We normally redirect at the HTTP level, but the group
|
// We normally redirect at the HTTP level, but the group
|
||||||
// description could have been edited in the meantime.
|
// description could have been edited in the meantime.
|
||||||
return c.error(
|
return c.write(clientMessage{
|
||||||
group.UserError("group is now at " + redirect),
|
Type: "joined",
|
||||||
)
|
Kind: "redirect",
|
||||||
|
Group: m.Group,
|
||||||
|
Permissions: &group.ClientPermissions{},
|
||||||
|
Value: &redirect,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
c.group = g
|
c.group = g
|
||||||
perms := c.permissions
|
perms := c.permissions
|
||||||
|
|
|
@ -271,7 +271,7 @@ function setConnected(connected) {
|
||||||
userpass ? userpass.password : '';
|
userpass ? userpass.password : '';
|
||||||
userbox.classList.add('invisible');
|
userbox.classList.add('invisible');
|
||||||
connectionbox.classList.remove('invisible');
|
connectionbox.classList.remove('invisible');
|
||||||
displayError("Disconnected!", "error");
|
displayError('Disconnected', 'error');
|
||||||
hideVideo();
|
hideVideo();
|
||||||
closeVideoControls();
|
closeVideoControls();
|
||||||
}
|
}
|
||||||
|
@ -1425,25 +1425,39 @@ let presentRequested = null;
|
||||||
* @param {Object<string,boolean>} perms
|
* @param {Object<string,boolean>} perms
|
||||||
*/
|
*/
|
||||||
async function gotJoined(kind, group, perms, message) {
|
async function gotJoined(kind, group, perms, message) {
|
||||||
if(kind === 'fail') {
|
let present = presentRequested;
|
||||||
|
presentRequested = null;
|
||||||
|
|
||||||
|
switch(kind) {
|
||||||
|
case 'fail':
|
||||||
displayError('The server said: ' + message);
|
displayError('The server said: ' + message);
|
||||||
this.close();
|
this.close();
|
||||||
return;
|
return;
|
||||||
|
case 'redirect':
|
||||||
|
this.close();
|
||||||
|
document.location = message;
|
||||||
|
return;
|
||||||
|
case 'leave':
|
||||||
|
this.close();
|
||||||
|
return;
|
||||||
|
case 'join':
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
displayError('Unknown join message');
|
||||||
|
this.close();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
displayUsername();
|
displayUsername();
|
||||||
setButtonsVisibility();
|
setButtonsVisibility();
|
||||||
|
|
||||||
if(kind !== 'leave')
|
|
||||||
this.request(getSettings().request);
|
this.request(getSettings().request);
|
||||||
|
|
||||||
try {
|
if(serverConnection.permissions.present && !findUpMedia('local')) {
|
||||||
if(kind === 'join' &&
|
if(present) {
|
||||||
serverConnection.permissions.present && !findUpMedia('local')) {
|
if(present === 'mike')
|
||||||
if(presentRequested) {
|
|
||||||
if(presentRequested === 'mike')
|
|
||||||
updateSettings({video: ''});
|
updateSettings({video: ''});
|
||||||
else if(presentRequested === 'both')
|
else if(present === 'both')
|
||||||
delSetting('video');
|
delSetting('video');
|
||||||
reflectSettings();
|
reflectSettings();
|
||||||
|
|
||||||
|
@ -1456,13 +1470,10 @@ async function gotJoined(kind, group, perms, message) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
displayMessage(
|
displayMessage(
|
||||||
"Press Present to enable your camera or microphone"
|
"Press Ready to enable your camera or microphone"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
presentRequested = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const urlRegexp = /https?:\/\/[-a-zA-Z0-9@:%/._\\+~#&()=?]+[-a-zA-Z0-9@:%/_\\+~#&()=]/g;
|
const urlRegexp = /https?:\/\/[-a-zA-Z0-9@:%/._\\+~#&()=?]+[-a-zA-Z0-9@:%/_\\+~#&()=]/g;
|
||||||
|
|
|
@ -243,6 +243,12 @@ func groupHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.HasSuffix(r.URL.Path, "/") {
|
||||||
|
http.Redirect(w, r, r.URL.Path[:len(r.URL.Path)-1],
|
||||||
|
http.StatusPermanentRedirect)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
g, err := group.Add(name, nil)
|
g, err := group.Add(name, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
|
|
Loading…
Reference in a new issue