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 { if c.prod != nil {
_ = c.prod.Stop() _ = c.prod.Stop()
c.prod = nil
} }
if c.ws != nil { if c.ws != nil {
@@ -538,5 +537,5 @@ func (c *Client) MarshalJSON() ([]byte, error) {
return webrtcProd.MarshalJSON() 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(), ID: core.NewID(),
FormatName: "ring/snapshot", FormatName: "ring/snapshot",
Protocol: "https", Protocol: "https",
RemoteAddr: "app-snaps.ring.com",
Medias: []*core.Media{ Medias: []*core.Media{
{ {
Kind: core.KindVideo, Kind: core.KindVideo,
@@ -43,7 +44,7 @@ func (p *SnapshotProducer) Start() error {
// Fetch snapshot // Fetch snapshot
response, err := p.client.Request("GET", fmt.Sprintf("https://app-snaps.ring.com/snapshots/next/%d", int(p.camera.ID)), nil) response, err := p.client.Request("GET", fmt.Sprintf("https://app-snaps.ring.com/snapshots/next/%d", int(p.camera.ID)), nil)
if err != nil { if err != nil {
return fmt.Errorf("failed to get snapshot: %w", err) return err
} }
pkt := &rtp.Packet{ pkt := &rtp.Packet{
@@ -51,10 +52,7 @@ func (p *SnapshotProducer) Start() error {
Payload: response, Payload: response,
} }
// Send to all receivers p.Receivers[0].WriteRTP(pkt)
for _, receiver := range p.Receivers {
receiver.WriteRTP(pkt)
}
return nil return nil
} }