1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-10 02:35:58 +01:00

Fix closing of replaced connections.

This commit is contained in:
Juliusz Chroboczek 2021-02-04 23:51:51 +01:00
parent fe9b89257a
commit 66de0d16e7

View file

@ -831,23 +831,27 @@ func clientLoop(c *webClient, ws *websocket.Conn) error {
if g == nil || a.group != g { if g == nil || a.group != g {
return nil return nil
} }
if a.conn == nil { var tracks []conn.UpTrack
if a.conn != nil {
tracks = make([]conn.UpTrack,
0, len(a.tracks),
)
for _, t := range a.tracks {
if c.isRequested(t.Label()) {
tracks = append(
tracks, t,
)
}
}
}
if len(tracks) == 0 {
closeDownConn(c, a.id, "")
if a.replace != "" { if a.replace != "" {
closeDownConnection( closeDownConn(
c, a.replace, "", c, a.replace, "",
) )
} }
closeDownConnection(c, a.id, "")
continue
}
tracks := make([]conn.UpTrack, 0, len(a.tracks))
for _, t := range a.tracks {
if c.isRequested(t.Label()) {
tracks = append(tracks, t)
}
}
if len(tracks) == 0 {
closeDownConnection(c, a.id, "")
continue continue
} }
@ -859,6 +863,12 @@ func clientLoop(c *webClient, ws *websocket.Conn) error {
if err != nil { if err != nil {
return err return err
} }
if a.replace != "" {
err := delDownConn(c, a.replace)
if err != nil {
log.Printf("Replace: %v", err)
}
}
err = negotiate( err = negotiate(
c, down, false, a.replace, c, down, false, a.replace,
) )
@ -866,10 +876,8 @@ func clientLoop(c *webClient, ws *websocket.Conn) error {
log.Printf( log.Printf(
"Negotiation failed: %v", "Negotiation failed: %v",
err) err)
delDownConn(c, down.id) closeDownConn(c, down.id,
c.error(group.UserError( "negotiation failed")
"Negotiation failed",
))
continue continue
} }
case pushConnsAction: case pushConnsAction:
@ -1020,7 +1028,7 @@ func leaveGroup(c *webClient) {
c.group = nil c.group = nil
} }
func closeDownConnection(c *webClient, id string, message string) error { func closeDownConn(c *webClient, id string, message string) error {
err := delDownConn(c, id) err := delDownConn(c, id)
if err != nil && !os.IsNotExist(err) { if err != nil && !os.IsNotExist(err) {
log.Printf("Close down connection: %v", err) log.Printf("Close down connection: %v", err)
@ -1220,7 +1228,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
if err != ErrUnknownId { if err != ErrUnknownId {
message = "negotiation failed" message = "negotiation failed"
} }
return closeDownConnection(c, m.Id, message) return closeDownConn(c, m.Id, message)
} }
down := getDownConn(c, m.Id) down := getDownConn(c, m.Id)
if down.negotiationNeeded > negotiationUnneeded { if down.negotiationNeeded > negotiationUnneeded {
@ -1230,7 +1238,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
"", "",
) )
if err != nil { if err != nil {
return closeDownConnection( return closeDownConn(
c, m.Id, "negotiation failed", c, m.Id, "negotiation failed",
) )
} }
@ -1240,7 +1248,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
if down != nil { if down != nil {
err := negotiate(c, down, true, "") err := negotiate(c, down, true, "")
if err != nil { if err != nil {
return closeDownConnection( return closeDownConn(
c, m.Id, "renegotiation failed", c, m.Id, "renegotiation failed",
) )
} }
@ -1255,7 +1263,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
return nil return nil
} }
case "abort": case "abort":
return closeDownConnection(c, m.Id, "") return closeDownConn(c, m.Id, "")
case "ice": case "ice":
if m.Candidate == nil { if m.Candidate == nil {
return group.ProtocolError("null candidate") return group.ProtocolError("null candidate")