Adds keep-alive to RTSP connection

This commit is contained in:
Alexey Khit
2022-08-22 06:54:58 +03:00
parent 46f6a5d8e1
commit 26b5745f0a
+14
View File
@@ -43,6 +43,8 @@ const (
ModeServerConsumer ModeServerConsumer
) )
const KeepAlive = time.Second * 25
type Conn struct { type Conn struct {
streamer.Element streamer.Element
@@ -575,6 +577,7 @@ func (c *Conn) Handle() (err error) {
}() }()
//c.Fire(streamer.StatePlaying) //c.Fire(streamer.StatePlaying)
ts := time.Now().Add(KeepAlive)
for { for {
// we can read: // we can read:
@@ -653,6 +656,17 @@ func (c *Conn) Handle() (err error) {
c.Fire(msg) c.Fire(msg)
} }
// keep-alive
now := time.Now()
if now.After(ts) {
req := &tcp.Request{Method: MethodOptions, URL: c.URL}
// don't need to wait respose on this request
if err = c.Request(req); err != nil {
return err
}
ts = now.Add(KeepAlive)
}
} }
} }