Skip to content

Commit

Permalink
Merge pull request #1568 from seydx/ring
Browse files Browse the repository at this point in the history
Ring: Fix snapshot producer MarshalJSON and prevent nil reference during stop
  • Loading branch information
AlexxIT authored Feb 17, 2025
2 parents be2864c + 1703380 commit 0e9009b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
5 changes: 2 additions & 3 deletions pkg/ring/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ func (c *Client) Stop() error {

if c.prod != nil {
_ = c.prod.Stop()
c.prod = nil
}

if c.ws != nil {
Expand All @@ -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)
}
8 changes: 3 additions & 5 deletions pkg/ring/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -43,18 +44,15 @@ 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{
Header: rtp.Header{Timestamp: core.Now90000()},
Payload: response,
}

// Send to all receivers
for _, receiver := range p.Receivers {
receiver.WriteRTP(pkt)
}
p.Receivers[0].WriteRTP(pkt)

return nil
}
Expand Down

0 comments on commit 0e9009b

Please sign in to comment.