Commit c540cad9 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Move pushClientConnection into its own function.

parent 24df0a8c
...@@ -954,68 +954,70 @@ func clientLoop(c *webClient, ws *websocket.Conn) error { ...@@ -954,68 +954,70 @@ func clientLoop(c *webClient, ws *websocket.Conn) error {
} }
} }
func handleAction(c *webClient, a interface{}) error { func pushDownConn(c *webClient, id string, up conn.Up, tracks []conn.UpTrack, replace string) error {
switch a := a.(type) { var requested []conn.UpTrack
case pushConnAction: if up != nil {
g := c.group var old *rtpDownConnection
if g == nil || a.group != g { if replace != "" {
return nil old = getDownConn(c, replace)
} else {
old = getDownConn(c, up.Id())
} }
var tracks []conn.UpTrack
var override []string var override []string
if a.conn != nil { if old != nil {
var old *rtpDownConnection override = old.requested
if a.replace != "" {
old = getDownConn(c, a.replace)
} else {
old = getDownConn(c, a.conn.Id())
}
if old != nil {
override = old.requested
}
tracks = requestedTracks(c, override, a.conn, a.tracks)
} }
requested = requestedTracks(c, override, up, tracks)
}
if a.replace != "" { if replace != "" {
err := delDownConn(c, a.replace) err := delDownConn(c, replace)
if err != nil { if err != nil {
log.Printf("Replace: %v", err) log.Printf("Replace: %v", err)
}
} }
}
if len(tracks) == 0 { // closes over replace, which will be modified below
closeDownConn(c, a.id, "") defer func() {
if a.replace != "" { if replace != "" {
closeDownConn(c, a.replace, "") closeDownConn(c, replace, "")
}
return nil
} }
}()
down, _, err := addDownConn(c, a.conn) if len(requested) == 0 {
if err != nil { closeDownConn(c, id, "")
if a.replace != "" { return nil
closeDownConn(c, a.replace, "") }
}
if err == os.ErrClosed { down, _, err := addDownConn(c, up)
return nil if err != nil {
} if err == os.ErrClosed {
return err return nil
}
done, err := replaceTracks(down, tracks, a.conn)
if err != nil || !done {
if a.replace != "" {
closeDownConn(c, a.replace, "")
}
return err
} }
err = negotiate(c, down, false, a.replace) return err
if err != nil { }
log.Printf("Negotiation failed: %v", err) done, err := replaceTracks(down, requested, up)
if a.replace != "" { if err != nil || !done {
closeDownConn(c, a.replace, "") return err
} }
closeDownConn(c, down.id, "negotiation failed") err = negotiate(c, down, false, replace)
if err != nil {
log.Printf("Negotiation failed: %v", err)
closeDownConn(c, down.id, "negotiation failed")
return err
}
replace = ""
return nil
}
func handleAction(c *webClient, a interface{}) error {
switch a := a.(type) {
case pushConnAction:
if c.group == nil || c.group != a.group {
log.Printf("Got connectsions for wrong group")
return nil
} }
return pushDownConn(c, a.id, a.conn, a.tracks, a.replace)
case requestConnsAction: case requestConnsAction:
g := c.group g := c.group
if g == nil || a.group != g { if g == nil || a.group != g {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment