mirror of
https://github.com/jech/galene.git
synced 2024-11-14 04:35:57 +01:00
Fix closing of replaced connections.
This commit is contained in:
parent
f63ecb3078
commit
36d6845dc1
1 changed files with 22 additions and 26 deletions
|
@ -249,43 +249,44 @@ func addUpConn(c *webClient, id string, labels map[string]string, offer string)
|
||||||
|
|
||||||
var ErrUserMismatch = errors.New("user id mismatch")
|
var ErrUserMismatch = errors.New("user id mismatch")
|
||||||
|
|
||||||
func delUpConn(c *webClient, id string, userId string) (string, error) {
|
// delUpConn deletes an up connection. If push is closed, the close is
|
||||||
|
// pushed to all corresponding down connections.
|
||||||
|
func delUpConn(c *webClient, id string, userId string, push bool) error {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
if c.up == nil {
|
if c.up == nil {
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
return "", os.ErrNotExist
|
return os.ErrNotExist
|
||||||
}
|
}
|
||||||
conn := c.up[id]
|
conn := c.up[id]
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
return "", os.ErrNotExist
|
return os.ErrNotExist
|
||||||
}
|
}
|
||||||
if userId != "" && conn.userId != userId {
|
if userId != "" && conn.userId != userId {
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
return "", ErrUserMismatch
|
return ErrUserMismatch
|
||||||
}
|
}
|
||||||
|
|
||||||
replace := conn.getReplace(true)
|
replace := conn.getReplace(true)
|
||||||
|
|
||||||
delete(c.up, id)
|
delete(c.up, id)
|
||||||
|
g := c.group
|
||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
|
|
||||||
g := c.group
|
conn.pc.Close()
|
||||||
if g != nil {
|
|
||||||
|
if push && g != nil {
|
||||||
go func(clients []group.Client) {
|
go func(clients []group.Client) {
|
||||||
for _, c := range clients {
|
for _, c := range clients {
|
||||||
err := c.PushConn(g, conn.id, nil, nil, replace)
|
err := c.PushConn(g, id, nil, nil, replace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("PushConn: %v", err)
|
log.Printf("PushConn: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(g.GetClients(c))
|
}(g.GetClients(c))
|
||||||
} else {
|
|
||||||
log.Printf("Deleting connection for client with no group")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.pc.Close()
|
return nil
|
||||||
return conn.replace, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDownConn(c *webClient, id string) *rtpDownConnection {
|
func getDownConn(c *webClient, id string) *rtpDownConnection {
|
||||||
|
@ -513,7 +514,10 @@ func gotOffer(c *webClient, id string, sdp string, labels map[string]string, rep
|
||||||
|
|
||||||
up.userId = c.Id()
|
up.userId = c.Id()
|
||||||
up.username = c.Username()
|
up.username = c.Username()
|
||||||
|
if replace != "" {
|
||||||
up.replace = replace
|
up.replace = replace
|
||||||
|
delUpConn(c, replace, c.Id(), false)
|
||||||
|
}
|
||||||
|
|
||||||
err = up.pc.SetRemoteDescription(webrtc.SessionDescription{
|
err = up.pc.SetRemoteDescription(webrtc.SessionDescription{
|
||||||
Type: webrtc.SDPTypeOffer,
|
Type: webrtc.SDPTypeOffer,
|
||||||
|
@ -922,12 +926,10 @@ func clientLoop(c *webClient, ws *websocket.Conn) error {
|
||||||
if !c.permissions.Present {
|
if !c.permissions.Present {
|
||||||
up := getUpConns(c)
|
up := getUpConns(c)
|
||||||
for _, u := range up {
|
for _, u := range up {
|
||||||
replace, err :=
|
err := delUpConn(
|
||||||
delUpConn(c, u.id, c.id)
|
c, u.id, c.id, true,
|
||||||
|
)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if replace != "" {
|
|
||||||
delUpConn(c, replace, c.id)
|
|
||||||
}
|
|
||||||
failUpConnection(
|
failUpConnection(
|
||||||
c, u.id,
|
c, u.id,
|
||||||
"permission denied",
|
"permission denied",
|
||||||
|
@ -989,7 +991,7 @@ func leaveGroup(c *webClient) {
|
||||||
c.setRequested(map[string]uint32{})
|
c.setRequested(map[string]uint32{})
|
||||||
if c.up != nil {
|
if c.up != nil {
|
||||||
for id := range c.up {
|
for id := range c.up {
|
||||||
delUpConn(c, id, c.id)
|
delUpConn(c, id, c.id, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1173,7 +1175,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||||
case "offer":
|
case "offer":
|
||||||
if !c.permissions.Present {
|
if !c.permissions.Present {
|
||||||
if m.Replace != "" {
|
if m.Replace != "" {
|
||||||
delUpConn(c, m.Replace, c.id)
|
delUpConn(c, m.Replace, c.id, true)
|
||||||
}
|
}
|
||||||
c.write(clientMessage{
|
c.write(clientMessage{
|
||||||
Type: "abort",
|
Type: "abort",
|
||||||
|
@ -1222,18 +1224,12 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
||||||
log.Printf("Trying to renegotiate unknown connection")
|
log.Printf("Trying to renegotiate unknown connection")
|
||||||
}
|
}
|
||||||
case "close":
|
case "close":
|
||||||
replace, err := delUpConn(c, m.Id, c.id)
|
err := delUpConn(c, m.Id, c.id, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Deleting up connection %v: %v",
|
log.Printf("Deleting up connection %v: %v",
|
||||||
m.Id, err)
|
m.Id, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if replace != "" {
|
|
||||||
_, err := delUpConn(c, replace, c.id)
|
|
||||||
if err != nil && !os.IsNotExist(err) {
|
|
||||||
log.Printf("Replace up connection: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "abort":
|
case "abort":
|
||||||
err := delDownConn(c, m.Id)
|
err := delDownConn(c, m.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue