1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-22 16:45:58 +01:00

Factor out handling actions.

This commit is contained in:
Juliusz Chroboczek 2021-02-14 16:34:43 +01:00
parent fa625c693e
commit 3b505a89fe

View file

@ -827,6 +827,30 @@ func clientLoop(c *webClient, ws *websocket.Conn) error {
return m
}
case a := <-c.actionCh:
err := handleAction(c, a)
if err != nil {
return err
}
case <-ticker.C:
if time.Since(readTime) > 75*time.Second {
return errors.New("client is dead")
}
// Some reverse proxies timeout connexions at 60
// seconds, make sure we generate some activity
// after 55s at most.
if time.Since(readTime) > 45*time.Second {
err := c.write(clientMessage{
Type: "ping",
})
if err != nil {
return err
}
}
}
}
}
func handleAction(c *webClient, a interface{}) error {
switch a := a.(type) {
case pushConnAction:
g := c.group
@ -854,7 +878,7 @@ func clientLoop(c *webClient, ws *websocket.Conn) error {
c, a.replace, "",
)
}
continue
return nil
}
down, _, err := addDownConn(c, a.conn)
@ -880,7 +904,6 @@ func clientLoop(c *webClient, ws *websocket.Conn) error {
err)
closeDownConn(c, down.id,
"negotiation failed")
continue
}
case pushConnsAction:
g := c.group
@ -975,23 +998,7 @@ func clientLoop(c *webClient, ws *websocket.Conn) error {
log.Printf("unexpected action %T", a)
return errors.New("unexpected action")
}
case <-ticker.C:
if time.Since(readTime) > 75*time.Second {
return errors.New("client is dead")
}
// Some reverse proxies timeout connexions at 60
// seconds, make sure we generate some activity
// after 55s at most.
if time.Since(readTime) > 45*time.Second {
err := c.write(clientMessage{
Type: "ping",
})
if err != nil {
return err
}
}
}
}
return nil
}
func failUpConnection(c *webClient, id string, message string) error {