Merge pull request #1568 from seydx/ring

Ring: Fix snapshot producer MarshalJSON and prevent nil reference during stop
This commit is contained in:
Alex X
2025-02-17 17:08:26 +03:00
committed by GitHub
2 changed files with 5 additions and 8 deletions

View File

@@ -514,7 +514,6 @@ func (c *Client) Stop() error {
if c.prod != nil {
_ = c.prod.Stop()
c.prod = nil
}
if c.ws != nil {
@@ -537,6 +536,6 @@ func (c *Client) MarshalJSON() ([]byte, error) {
if webrtcProd, ok := c.prod.(*webrtc.Conn); ok {
return webrtcProd.MarshalJSON()
}
return nil, errors.New("ring: can't marshal")
return json.Marshal(c.prod)
}

View File

@@ -20,6 +20,7 @@ func NewSnapshotProducer(client *RingRestClient, camera *CameraData) *SnapshotPr
ID: core.NewID(),
FormatName: "ring/snapshot",
Protocol: "https",
RemoteAddr: "app-snaps.ring.com",
Medias: []*core.Media{
{
Kind: core.KindVideo,
@@ -43,7 +44,7 @@ func (p *SnapshotProducer) Start() error {
// Fetch snapshot
response, err := p.client.Request("GET", fmt.Sprintf("https://app-snaps.ring.com/snapshots/next/%d", int(p.camera.ID)), nil)
if err != nil {
return fmt.Errorf("failed to get snapshot: %w", err)
return err
}
pkt := &rtp.Packet{
@@ -51,10 +52,7 @@ func (p *SnapshotProducer) Start() error {
Payload: response,
}
// Send to all receivers
for _, receiver := range p.Receivers {
receiver.WriteRTP(pkt)
}
p.Receivers[0].WriteRTP(pkt)
return nil
}