refactor(dvrip): simplify broadcast loop structure
- replace traditional for loop with range-based for loop for clarity
refactor(ffmpeg): simplify cut function loop
- utilize range-based for loop instead of traditional for loop
refactor(ring): update API response mapping type
- change map type from `interface{}` to `any` for better type safety
refactor(stream): handle nil source in NewStream
- add nil check for source elements before processing
refactor(webrtc): unify payload handling in GetToken
- change map type from `interface{}` to `any` for consistency
refactor(ascii): optimize nested loops in Write function
- replace traditional for loops with range-based for loops for readability
refactor(bits): enhance readability in Reader methods
- replace traditional for loops with range-based for loops in Read functions
refactor(h264): modernize loop structures in DecodeConfig
- switch to range-based for loops for cleaner code
refactor(h265): streamline profile_tier_level loops
- utilize range-based for loops instead of traditional for loops
chore(core): remove commented-out test function for clarity
refactor(core): simplify RandString function loop
- change traditional for loop to range-based for loop
refactor(flvt): optimize timestamp handling in TestTimeToRTP
- switch to range-based for loop for iterating frames
refactor(nest): improve error handling in ExchangeSDP
- format error message with printf-style formatting for clarity
refactor(tapo): enhance securityEncode function
- change traditional for loop to range-based for loop for readability
fix(tcp): correct masking in websocket Write method
- replace traditional for loop with range-based for loop
refactor(tutk): modernize encoding loops in crypto functions
- utilize range-based for loops for better readability
refactor(tuya): unify data types in MQTT message struct
- change map type from `interface{}` to `any` for consistency
refactor(webrtc): standardize codec registration
- change map type from `interface{}` to `any` for type safety
refactor(yaml): simplify Unmarshal function signature
- update parameter type from `interface{}` to `any` for better clarity
This commit is contained in:
+14
-14
@@ -71,7 +71,7 @@ type RingApi struct {
|
||||
Using2FA bool
|
||||
PromptFor2FA string
|
||||
RefreshToken string
|
||||
auth interface{} // EmailAuth or RefreshTokenAuth
|
||||
auth any // EmailAuth or RefreshTokenAuth
|
||||
onTokenRefresh func(string)
|
||||
authMutex sync.Mutex
|
||||
session *SessionResponse
|
||||
@@ -93,12 +93,12 @@ type CameraData struct {
|
||||
type RingDeviceType string
|
||||
|
||||
type RingDevicesResponse struct {
|
||||
Doorbots []CameraData `json:"doorbots"`
|
||||
AuthorizedDoorbots []CameraData `json:"authorized_doorbots"`
|
||||
StickupCams []CameraData `json:"stickup_cams"`
|
||||
AllCameras []CameraData `json:"all_cameras"`
|
||||
Chimes []CameraData `json:"chimes"`
|
||||
Other []map[string]interface{} `json:"other"`
|
||||
Doorbots []CameraData `json:"doorbots"`
|
||||
AuthorizedDoorbots []CameraData `json:"authorized_doorbots"`
|
||||
StickupCams []CameraData `json:"stickup_cams"`
|
||||
AllCameras []CameraData `json:"all_cameras"`
|
||||
Chimes []CameraData `json:"chimes"`
|
||||
Other []map[string]any `json:"other"`
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -153,7 +153,7 @@ const (
|
||||
sessionValidTime = 12 * time.Hour
|
||||
)
|
||||
|
||||
func NewRestClient(auth interface{}, onTokenRefresh func(string)) (*RingApi, error) {
|
||||
func NewRestClient(auth any, onTokenRefresh func(string)) (*RingApi, error) {
|
||||
var cacheKey string
|
||||
|
||||
// Create cache key based on auth data
|
||||
@@ -400,7 +400,7 @@ func (c *RingApi) GetSocketTicket() (*SocketTicketResponse, error) {
|
||||
return &ticket, nil
|
||||
}
|
||||
|
||||
func (c *RingApi) Request(method, url string, body interface{}) ([]byte, error) {
|
||||
func (c *RingApi) Request(method, url string, body any) ([]byte, error) {
|
||||
// Ensure we have a valid session
|
||||
if err := c.ensureSession(); err != nil {
|
||||
return nil, fmt.Errorf("session validation failed: %w", err)
|
||||
@@ -476,7 +476,7 @@ func (c *RingApi) Request(method, url string, body interface{}) ([]byte, error)
|
||||
|
||||
// Handle 404 error with hardware_id reference - session issue
|
||||
if resp.StatusCode == 404 && strings.Contains(url, clientAPIBaseURL) {
|
||||
var errorBody map[string]interface{}
|
||||
var errorBody map[string]any
|
||||
if err := json.Unmarshal(responseBody, &errorBody); err == nil {
|
||||
if errorStr, ok := errorBody["error"].(string); ok && strings.Contains(errorStr, c.hardwareID) {
|
||||
// Session with hardware_id not found, refresh session
|
||||
@@ -523,10 +523,10 @@ func (c *RingApi) ensureSession() error {
|
||||
return fmt.Errorf("authentication failed while creating session: %w", err)
|
||||
}
|
||||
|
||||
sessionPayload := map[string]interface{}{
|
||||
"device": map[string]interface{}{
|
||||
sessionPayload := map[string]any{
|
||||
"device": map[string]any{
|
||||
"hardware_id": c.hardwareID,
|
||||
"metadata": map[string]interface{}{
|
||||
"metadata": map[string]any{
|
||||
"api_version": apiVersion,
|
||||
"device_model": "ring-client-go",
|
||||
},
|
||||
@@ -686,7 +686,7 @@ func generateHardwareID() string {
|
||||
return hex.EncodeToString(h.Sum(nil)[:16])
|
||||
}
|
||||
|
||||
func interfaceSlice(slice interface{}) []CameraData {
|
||||
func interfaceSlice(slice any) []CameraData {
|
||||
s := reflect.ValueOf(slice)
|
||||
if s.Kind() != reflect.Slice {
|
||||
return nil
|
||||
|
||||
+3
-3
@@ -140,7 +140,7 @@ func Dial(rawURL string) (*Client, error) {
|
||||
return
|
||||
}
|
||||
|
||||
icePayload := map[string]interface{}{
|
||||
icePayload := map[string]any{
|
||||
"ice": iceCandidate.Candidate,
|
||||
"mlineindex": iceCandidate.SDPMLineIndex,
|
||||
}
|
||||
@@ -200,7 +200,7 @@ func Dial(rawURL string) (*Client, error) {
|
||||
}
|
||||
|
||||
// Send offer
|
||||
offerPayload := map[string]interface{}{
|
||||
offerPayload := map[string]any{
|
||||
"stream_options": map[string]bool{
|
||||
"audio_enabled": true,
|
||||
"video_enabled": true,
|
||||
@@ -317,7 +317,7 @@ func (c *Client) AddTrack(media *core.Media, codec *core.Codec, track *core.Rece
|
||||
if webrtcProd, ok := c.prod.(*webrtc.Conn); ok {
|
||||
if media.Kind == core.KindAudio {
|
||||
// Enable speaker
|
||||
speakerPayload := map[string]interface{}{
|
||||
speakerPayload := map[string]any{
|
||||
"stealth_mode": false,
|
||||
}
|
||||
_ = c.wsClient.sendSessionMessage("camera_options", speakerPayload)
|
||||
|
||||
+6
-6
@@ -142,8 +142,8 @@ func (c *WSClient) Close() error {
|
||||
close(c.closed)
|
||||
}
|
||||
|
||||
closePayload := map[string]interface{}{
|
||||
"reason": map[string]interface{}{
|
||||
closePayload := map[string]any{
|
||||
"reason": map[string]any{
|
||||
"code": CloseReasonNormalClose,
|
||||
"text": "",
|
||||
},
|
||||
@@ -198,7 +198,7 @@ func (c *WSClient) activateSession() error {
|
||||
return err
|
||||
}
|
||||
|
||||
streamPayload := map[string]interface{}{
|
||||
streamPayload := map[string]any{
|
||||
"audio_enabled": true,
|
||||
"video_enabled": true,
|
||||
}
|
||||
@@ -210,7 +210,7 @@ func (c *WSClient) activateSession() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *WSClient) sendSessionMessage(method string, payload map[string]interface{}) error {
|
||||
func (c *WSClient) sendSessionMessage(method string, payload map[string]any) error {
|
||||
select {
|
||||
case <-c.closed:
|
||||
return nil
|
||||
@@ -222,7 +222,7 @@ func (c *WSClient) sendSessionMessage(method string, payload map[string]interfac
|
||||
defer c.wsMutex.Unlock()
|
||||
|
||||
if payload == nil {
|
||||
payload = make(map[string]interface{})
|
||||
payload = make(map[string]any)
|
||||
}
|
||||
|
||||
payload["doorbot_id"] = c.cameraID
|
||||
@@ -230,7 +230,7 @@ func (c *WSClient) sendSessionMessage(method string, payload map[string]interfac
|
||||
payload["session_id"] = c.sessionID
|
||||
}
|
||||
|
||||
msg := map[string]interface{}{
|
||||
msg := map[string]any{
|
||||
"method": method,
|
||||
"dialog_id": c.dialogID,
|
||||
"body": payload,
|
||||
|
||||
Reference in New Issue
Block a user