mirror of
https://github.com/jech/galene.git
synced 2024-11-12 19:55:59 +01:00
Delete upstream connections on ICE failure.
This commit is contained in:
parent
92de141b97
commit
5205c0773b
2 changed files with 50 additions and 16 deletions
62
client.go
62
client.go
|
@ -281,6 +281,12 @@ func addUpConn(c *client, id string) (*upConnection, error) {
|
||||||
sendICE(c, id, candidate)
|
sendICE(c, id, candidate)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
pc.OnICEConnectionStateChange(func(state webrtc.ICEConnectionState) {
|
||||||
|
if state == webrtc.ICEConnectionStateFailed {
|
||||||
|
c.action(connectionFailedAction{id: id})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
go rtcpUpSender(c, conn)
|
go rtcpUpSender(c, conn)
|
||||||
|
|
||||||
pc.OnTrack(func(remote *webrtc.Track, receiver *webrtc.RTPReceiver) {
|
pc.OnTrack(func(remote *webrtc.Track, receiver *webrtc.RTPReceiver) {
|
||||||
|
@ -445,19 +451,17 @@ func rtcpUpSender(c *client, conn *upConnection) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func delUpConn(c *client, id string) {
|
func delUpConn(c *client, id string) bool {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
|
|
||||||
if c.up == nil {
|
if c.up == nil {
|
||||||
log.Printf("Deleting unknown connection")
|
return false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
conn := c.up[id]
|
conn := c.up[id]
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
log.Printf("Deleting unknown connection")
|
return false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type clientId struct {
|
type clientId struct {
|
||||||
|
@ -483,6 +487,7 @@ func delUpConn(c *client, id string) {
|
||||||
|
|
||||||
conn.pc.Close()
|
conn.pc.Close()
|
||||||
delete(c.up, id)
|
delete(c.up, id)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDownConn(c *client, id string) *downConnection {
|
func getDownConn(c *client, id string) *downConnection {
|
||||||
|
@ -513,6 +518,12 @@ func addDownConn(c *client, id string, remote *upConnection) (*downConnection, e
|
||||||
log.Printf("Got track on downstream connection")
|
log.Printf("Got track on downstream connection")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
pc.OnICEConnectionStateChange(func(state webrtc.ICEConnectionState) {
|
||||||
|
if state == webrtc.ICEConnectionStateFailed {
|
||||||
|
c.action(connectionFailedAction{id: id})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
if c.down == nil {
|
if c.down == nil {
|
||||||
c.down = make(map[string]*downConnection)
|
c.down = make(map[string]*downConnection)
|
||||||
}
|
}
|
||||||
|
@ -528,18 +539,16 @@ func addDownConn(c *client, id string, remote *upConnection) (*downConnection, e
|
||||||
return conn, nil
|
return conn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func delDownConn(c *client, id string) {
|
func delDownConn(c *client, id string) bool {
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
|
|
||||||
if c.down == nil {
|
if c.down == nil {
|
||||||
log.Printf("Deleting unknown connection")
|
return false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
conn := c.down[id]
|
conn := c.down[id]
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
log.Printf("Deleting unknown connection")
|
return false
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, track := range conn.tracks {
|
for _, track := range conn.tracks {
|
||||||
|
@ -551,6 +560,7 @@ func delDownConn(c *client, id string) {
|
||||||
}
|
}
|
||||||
conn.pc.Close()
|
conn.pc.Close()
|
||||||
delete(c.down, id)
|
delete(c.down, id)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func addDownTrack(c *client, id string, remoteTrack *upTrack, remoteConn *upConnection) (*downConnection, *webrtc.RTPSender, error) {
|
func addDownTrack(c *client, id string, remoteTrack *upTrack, remoteConn *upConnection) (*downConnection, *webrtc.RTPSender, error) {
|
||||||
|
@ -956,11 +966,13 @@ func clientLoop(c *client, conn *websocket.Conn) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case delConnAction:
|
case delConnAction:
|
||||||
c.write(clientMessage{
|
found := delDownConn(c, a.id)
|
||||||
Type: "close",
|
if found {
|
||||||
Id: a.id,
|
c.write(clientMessage{
|
||||||
})
|
Type: "close",
|
||||||
delDownConn(c, a.id)
|
Id: a.id,
|
||||||
|
})
|
||||||
|
}
|
||||||
case addLabelAction:
|
case addLabelAction:
|
||||||
c.write(clientMessage{
|
c.write(clientMessage{
|
||||||
Type: "label",
|
Type: "label",
|
||||||
|
@ -983,6 +995,21 @@ func clientLoop(c *client, conn *websocket.Conn) error {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case connectionFailedAction:
|
||||||
|
found := delUpConn(c, a.id)
|
||||||
|
if found {
|
||||||
|
c.write(clientMessage{
|
||||||
|
Type: "error",
|
||||||
|
Value: "connection failed",
|
||||||
|
})
|
||||||
|
c.write(clientMessage{
|
||||||
|
Type: "abort",
|
||||||
|
Id: a.id,
|
||||||
|
})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// What should we do if a downstream
|
||||||
|
// connection fails? Renegotiate?
|
||||||
case permissionsChangedAction:
|
case permissionsChangedAction:
|
||||||
c.write(clientMessage{
|
c.write(clientMessage{
|
||||||
Type: "permissions",
|
Type: "permissions",
|
||||||
|
@ -1048,7 +1075,10 @@ func handleClientMessage(c *client, m clientMessage) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case "close":
|
case "close":
|
||||||
delUpConn(c, m.Id)
|
found := delUpConn(c, m.Id)
|
||||||
|
if !found {
|
||||||
|
log.Printf("Deleting unknown up connection %v", m.Id)
|
||||||
|
}
|
||||||
case "ice":
|
case "ice":
|
||||||
if m.Candidate == nil {
|
if m.Candidate == nil {
|
||||||
return protocolError("null candidate")
|
return protocolError("null candidate")
|
||||||
|
|
4
group.go
4
group.go
|
@ -164,6 +164,10 @@ type pushTracksAction struct {
|
||||||
c *client
|
c *client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type connectionFailedAction struct {
|
||||||
|
id string
|
||||||
|
}
|
||||||
|
|
||||||
type permissionsChangedAction struct{}
|
type permissionsChangedAction struct{}
|
||||||
|
|
||||||
type kickAction struct{}
|
type kickAction struct{}
|
||||||
|
|
Loading…
Reference in a new issue