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
)
const KeepAlive = time.Second * 25
type Conn struct {
streamer.Element
@@ -575,6 +577,7 @@ func (c *Conn) Handle() (err error) {
}()
//c.Fire(streamer.StatePlaying)
ts := time.Now().Add(KeepAlive)
for {
// we can read:
@@ -653,6 +656,17 @@ func (c *Conn) Handle() (err error) {
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)
}
}
}