mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-09-27 04:36:12 +08:00
refactor: remove logging from nest package
This commit is contained in:
@@ -184,16 +184,10 @@ func (a *API) ExchangeSDP(projectID, deviceID, offer string) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle 409 (Conflict) and 429 (Too Many Requests)
|
// Handle 409 (Conflict), 429 (Too Many Requests), and 401 (Unauthorized)
|
||||||
if res.StatusCode == 409 || res.StatusCode == 429 {
|
if res.StatusCode == 409 || res.StatusCode == 429 || res.StatusCode == 401 {
|
||||||
res.Body.Close()
|
res.Body.Close()
|
||||||
if attempt < maxRetries-1 {
|
if attempt < maxRetries-1 {
|
||||||
log.Info().
|
|
||||||
Int("status", res.StatusCode).
|
|
||||||
Float64("delay", retryDelay.Seconds()).
|
|
||||||
Int("attempt", attempt+1).
|
|
||||||
Int("max_retries", maxRetries-1).
|
|
||||||
Msg("API request failed, retrying")
|
|
||||||
// Get new token from Google
|
// Get new token from Google
|
||||||
if err := a.refreshToken(); err != nil {
|
if err := a.refreshToken(); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -471,20 +465,22 @@ type Device struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) StartExtendStreamTimer() {
|
func (a *API) StartExtendStreamTimer() {
|
||||||
// Calculate the duration until 30 seconds before the stream expires
|
if a.extendTimer != nil {
|
||||||
duration := time.Until(a.StreamExpiresAt.Add(-30 * time.Second))
|
return
|
||||||
a.extendTimer = time.AfterFunc(duration, func() {
|
}
|
||||||
|
|
||||||
|
a.extendTimer = time.NewTimer(time.Until(a.StreamExpiresAt) - time.Minute)
|
||||||
|
go func() {
|
||||||
|
<-a.extendTimer.C
|
||||||
if err := a.ExtendStream(); err != nil {
|
if err := a.ExtendStream(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
duration = time.Until(a.StreamExpiresAt.Add(-30 * time.Second))
|
}()
|
||||||
a.extendTimer.Reset(duration)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) StopExtendStreamTimer() {
|
func (a *API) StopExtendStreamTimer() {
|
||||||
if a.extendTimer == nil {
|
if a.extendTimer != nil {
|
||||||
return
|
a.extendTimer.Stop()
|
||||||
|
a.extendTimer = nil
|
||||||
}
|
}
|
||||||
a.extendTimer.Stop()
|
|
||||||
}
|
}
|
||||||
|
@@ -6,15 +6,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/AlexxIT/go2rtc/internal/app"
|
|
||||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||||
"github.com/AlexxIT/go2rtc/pkg/rtsp"
|
"github.com/AlexxIT/go2rtc/pkg/rtsp"
|
||||||
"github.com/AlexxIT/go2rtc/pkg/webrtc"
|
"github.com/AlexxIT/go2rtc/pkg/webrtc"
|
||||||
pion "github.com/pion/webrtc/v3"
|
pion "github.com/pion/webrtc/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = app.GetLogger("nest")
|
|
||||||
|
|
||||||
type WebRTCClient struct {
|
type WebRTCClient struct {
|
||||||
conn *webrtc.Conn
|
conn *webrtc.Conn
|
||||||
api *API
|
api *API
|
||||||
@@ -55,12 +52,6 @@ func Dial(rawURL string) (core.Producer, error) {
|
|||||||
}
|
}
|
||||||
lastErr = err
|
lastErr = err
|
||||||
if attempt < maxRetries-1 {
|
if attempt < maxRetries-1 {
|
||||||
log.Info().
|
|
||||||
Float64("delay", retryDelay.Seconds()).
|
|
||||||
Int("attempt", attempt+1).
|
|
||||||
Int("max_retries", maxRetries-1).
|
|
||||||
Err(err).
|
|
||||||
Msg("API initialization failed, retrying")
|
|
||||||
time.Sleep(retryDelay)
|
time.Sleep(retryDelay)
|
||||||
retryDelay *= 2 // exponential backoff
|
retryDelay *= 2 // exponential backoff
|
||||||
}
|
}
|
||||||
@@ -146,12 +137,6 @@ func rtcConn(nestAPI *API, rawURL, projectID, deviceID string) (*WebRTCClient, e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
lastErr = err
|
lastErr = err
|
||||||
if attempt < maxRetries-1 {
|
if attempt < maxRetries-1 {
|
||||||
log.Info().
|
|
||||||
Float64("delay", retryDelay.Seconds()).
|
|
||||||
Int("attempt", attempt+1).
|
|
||||||
Int("max_retries", maxRetries-1).
|
|
||||||
Err(err).
|
|
||||||
Msg("WebRTC connection setup failed, retrying")
|
|
||||||
time.Sleep(retryDelay)
|
time.Sleep(retryDelay)
|
||||||
retryDelay *= 2
|
retryDelay *= 2
|
||||||
continue
|
continue
|
||||||
|
Reference in New Issue
Block a user