mirror of
https://github.com/jech/galene.git
synced 2024-11-22 16:45:58 +01:00
Don't disconnect clients when negotiation fails.
This may happen if we receive an answer for a connection that has been closed in the meantime.
This commit is contained in:
parent
9ce591e4c5
commit
13d6b7ad1f
1 changed files with 34 additions and 7 deletions
|
@ -486,10 +486,12 @@ func gotOffer(c *webClient, id string, offer webrtc.SessionDescription, renegoti
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ErrUnknownId = errors.New("unknown id")
|
||||||
|
|
||||||
func gotAnswer(c *webClient, id string, answer webrtc.SessionDescription) error {
|
func gotAnswer(c *webClient, id string, answer webrtc.SessionDescription) error {
|
||||||
down := getDownConn(c, id)
|
down := getDownConn(c, id)
|
||||||
if down == nil {
|
if down == nil {
|
||||||
return group.ProtocolError("unknown id in answer")
|
return ErrUnknownId
|
||||||
}
|
}
|
||||||
err := down.pc.SetRemoteDescription(answer)
|
err := down.pc.SetRemoteDescription(answer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -790,7 +792,7 @@ func clientLoop(c *webClient, ws *websocket.Conn) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Negotiate: %v", err)
|
log.Printf("Negotiate: %v", err)
|
||||||
delDownConn(c, down.id)
|
delDownConn(c, down.id)
|
||||||
err = failConnection(
|
err = failUpConnection(
|
||||||
c, down.id,
|
c, down.id,
|
||||||
"negotiation failed",
|
"negotiation failed",
|
||||||
)
|
)
|
||||||
|
@ -851,7 +853,7 @@ func clientLoop(c *webClient, ws *websocket.Conn) error {
|
||||||
for _, u := range up {
|
for _, u := range up {
|
||||||
found := delUpConn(c, u.id)
|
found := delUpConn(c, u.id)
|
||||||
if found {
|
if found {
|
||||||
failConnection(
|
failUpConnection(
|
||||||
c, u.id,
|
c, u.id,
|
||||||
"permission denied",
|
"permission denied",
|
||||||
)
|
)
|
||||||
|
@ -880,7 +882,7 @@ func clientLoop(c *webClient, ws *websocket.Conn) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func failConnection(c *webClient, id string, message string) error {
|
func failUpConnection(c *webClient, id string, message string) error {
|
||||||
if id != "" {
|
if id != "" {
|
||||||
err := c.write(clientMessage{
|
err := c.write(clientMessage{
|
||||||
Type: "abort",
|
Type: "abort",
|
||||||
|
@ -899,6 +901,25 @@ func failConnection(c *webClient, id string, message string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func failDownConnection(c *webClient, id string, message string) error {
|
||||||
|
if id != "" {
|
||||||
|
err := c.write(clientMessage{
|
||||||
|
Type: "close",
|
||||||
|
Id: id,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if message != "" {
|
||||||
|
err := c.error(group.UserError(message))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func setPermissions(g *group.Group, id string, perm string) error {
|
func setPermissions(g *group.Group, id string, perm string) error {
|
||||||
client := g.GetClient(id)
|
client := g.GetClient(id)
|
||||||
if client == nil {
|
if client == nil {
|
||||||
|
@ -970,7 +991,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("gotOffer: %v", err)
|
log.Printf("gotOffer: %v", err)
|
||||||
return failConnection(c, m.Id, "negotiation failed")
|
return failUpConnection(c, m.Id, "negotiation failed")
|
||||||
}
|
}
|
||||||
case "answer":
|
case "answer":
|
||||||
if m.Answer == nil {
|
if m.Answer == nil {
|
||||||
|
@ -978,14 +999,20 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||||
}
|
}
|
||||||
err := gotAnswer(c, m.Id, *m.Answer)
|
err := gotAnswer(c, m.Id, *m.Answer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
log.Printf("gotAnswer: %v", err)
|
||||||
|
message := ""
|
||||||
|
if err != ErrUnknownId {
|
||||||
|
message = "negotiation failed"
|
||||||
|
}
|
||||||
|
return failDownConnection(c, m.Id, message)
|
||||||
}
|
}
|
||||||
case "renegotiate":
|
case "renegotiate":
|
||||||
down := getDownConn(c, m.Id)
|
down := getDownConn(c, m.Id)
|
||||||
if down != nil {
|
if down != nil {
|
||||||
err := negotiate(c, down, true, true)
|
err := negotiate(c, down, true, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return failDownConnection(c, m.Id,
|
||||||
|
"renegotiation failed")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Trying to renegotiate unknown connection")
|
log.Printf("Trying to renegotiate unknown connection")
|
||||||
|
|
Loading…
Reference in a new issue