mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-09-26 20:31:11 +08:00
Merge pull request #1568 from seydx/ring
Ring: Fix snapshot producer MarshalJSON and prevent nil reference during stop
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user