增加5分钟重连机制

This commit is contained in:
langhuihui
2020-07-12 09:49:42 +08:00
parent 2e9cf9a4ca
commit 8b1892209d

View File

@@ -275,34 +275,44 @@ func (client *RTSP) requestStream() (err error) {
} }
func (client *RTSP) startStream() { func (client *RTSP) startStream() {
//startTime := time.Now() startTime := time.Now()
//loggerTime := time.Now().Add(-10 * time.Second) //loggerTime := time.Now().Add(-10 * time.Second)
defer func() { defer func() {
if client.Err() == nil && config.Reconnect { if client.Err() == nil && config.Reconnect {
Printf("reconnecting:%s", client.URL) Printf("reconnecting:%s", client.URL)
client.RTSPClientInfo = RTSPClientInfo{} client.RTSPClientInfo = RTSPClientInfo{}
if err := client.requestStream(); err != nil { if err := client.requestStream(); err != nil {
Println(err) t := time.NewTicker(time.Second * 5)
client.Stop() for {
return Printf("reconnecting:%s in 5 seconds", client.URL)
select {
case <-client.Context.Done():
client.Stop()
return
case <-t.C:
if err = client.requestStream(); err == nil {
go client.startStream()
return
}
}
}
} else {
go client.startStream()
} }
go client.startStream()
} else { } else {
client.Stop() client.Stop()
} }
}() }()
for client.Err() == nil { for client.Err() == nil {
//if client.OptionIntervalMillis > 0 { if time.Since(startTime) > time.Minute {
// if time.Since(startTime) > time.Duration(client.OptionIntervalMillis)*time.Millisecond { startTime = time.Now()
// startTime = time.Now() headers := make(map[string]string)
// headers := make(map[string]string) headers["Require"] = "implicit-play"
// headers["Require"] = "implicit-play" // An OPTIONS request returns the request types the server will accept.
// // An OPTIONS request returns the request types the server will accept. if err := client.RequestNoResp("OPTIONS", headers); err != nil {
// if err := client.RequestNoResp("OPTIONS", headers); err != nil { // ignore...
// // ignore... }
// } }
// }
//}
b, err := client.connRW.ReadByte() b, err := client.connRW.ReadByte()
if err != nil { if err != nil {
Printf("client.connRW.ReadByte err:%v", err) Printf("client.connRW.ReadByte err:%v", err)